Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp330583pxb; Tue, 29 Mar 2022 04:47:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy4A4Ih1K9jaLS7oImCL/3d/sBDAalDV0Uqu294wzmQZyyCTDUlu+fGn/DYssFSG+9huqVp X-Received: by 2002:a17:907:168b:b0:6df:f4e8:f58d with SMTP id hc11-20020a170907168b00b006dff4e8f58dmr33174577ejc.747.1648554420657; Tue, 29 Mar 2022 04:47:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648554420; cv=none; d=google.com; s=arc-20160816; b=fGvi70affResJe7XoumZpzBRzhfUunb7qvPkr9XgWxH6IB9ejtpfttUze7O9IfkRRI KWVa8NPxo0o8ve2ERy/0MpIkAMrWQZkGdxZ5K5uTyTHjx2iIwxyIADWSftkATOMeBGmS 7qSpH95B29dMIov2rbcagb3wiJO+RnSEfj1xJuPsL9oml67vvoSZGK/QqJWv+HnHQOo0 V9gx7YvvgJpe5Es82+iQZZNjR0YmARX/YHoknazbtQS3fqTSnty9sMfQ4s/Ya10pzCmA pT5z/oHRiWAxiJ3NCPOlFC/hFzH+RHJ7dFNxDdTmEehChS4tSHhH0ClW5Y8kTe4vD1oo 4pNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:message-id :in-reply-to:subject:cc:to:from:date:dkim-signature; bh=uV1VsQUw8/hiJShCoBLImE1CgcmlK7TI/+2RTAssHxE=; b=gxQziHu9cEkBNxSSXFiVZSqoRwon/smJgltOCG44k4oJiYUVUEpDSw448OnThMdVZL Xr4AhHbGQLWyltxSuhW6dBzYd9O+CAQ/ucfH870ZQwzVmg6LWN5GCwHFO/ixnaTXKPY2 Xf3ijYYFEoqKjRM17hyJVbyo4+PUJmBdMvH3WkXSoaxFMm4JQfCUKrnFQpVXaWBv83j/ ROQPcDFWIFRPF40ynkgMtFuOFVrYueDWeRbcjXurvniHcp3wdxjI/I7cI46ucqgOlAQs LGRce85Nguz+PQWhwC9otLeppGtiQSCQQOpG/3wNxEw6wqJoSNhObIiQoUPqaDneF0v1 tZzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b=pWF2BclK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=inria.fr Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t26-20020aa7db1a000000b00418c2b5bf6dsi16744148eds.591.2022.03.29.04.46.34; Tue, 29 Mar 2022 04:47:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b=pWF2BclK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=inria.fr Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231820AbiC2HdG (ORCPT + 99 others); Tue, 29 Mar 2022 03:33:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229502AbiC2HdE (ORCPT ); Tue, 29 Mar 2022 03:33:04 -0400 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D77F5FF14; Tue, 29 Mar 2022 00:31:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=inria.fr; s=dc; h=date:from:to:cc:subject:in-reply-to:message-id: references:mime-version; bh=uV1VsQUw8/hiJShCoBLImE1CgcmlK7TI/+2RTAssHxE=; b=pWF2BclKX/C60nBjhnp7BY3ojf7Bj8gCjD0KsAkW3M75KWt6DOHtHz63 T2mHrMchZWaIiZ1OyW0aAiO0s47R+o1nCk5KBZdNFFt/s8eHkbr1BH/2u JemIQfwLeMQcrrPBmKogPoqGFZcTGrfBVET5bOZ5MkdiH3YRJ7LgoZUAa A=; Authentication-Results: mail2-relais-roc.national.inria.fr; dkim=none (message not signed) header.i=none; spf=SoftFail smtp.mailfrom=julia.lawall@inria.fr; dmarc=fail (p=none dis=none) d=inria.fr X-IronPort-AV: E=Sophos;i="5.90,219,1643670000"; d="scan'208";a="28814500" Received: from 203.107.68.85.rev.sfr.net (HELO hadrien) ([85.68.107.203]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Mar 2022 09:31:17 +0200 Date: Tue, 29 Mar 2022 09:31:17 +0200 (CEST) From: Julia Lawall X-X-Sender: jll@hadrien To: Marcelo Schmitt cc: corbet@lwn.net, mchehab+huawei@kernel.org, dlatypov@google.com, davidgow@google.com, linux-doc@vger.kernel.org, linux-sparse@vger.kernel.org, cocci@inria.fr, smatch@vger.kernel.org, linux-kernel@vger.kernel.org, skhan@linuxfoundation.org Subject: Re: [cocci] [PATCH] Documentation: dev-tools: Add a section for static analysis tools In-Reply-To: Message-ID: References: User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 28 Mar 2022, Marcelo Schmitt wrote: > Complement the Kernel Testing Guide documentation page by adding a > section about static analysis tools. > > Signed-off-by: Marcelo Schmitt > --- > Hey everyone, > > I think this patch can be a good addition to the documentation as > discussed in the thread for the testing guide documentation page: > Link: https://lore.kernel.org/linux-doc/CABVgOS=2iYtqTVdxwH=mcFpcSuLP4cpJ4s6PKP4Gc-SH6jidgQ@mail.gmail.com/ > > If you think it would be worth it, I can try making something more > elaborated. Maybe provide some guidance on when to use each tool. > I've been studying how Linux device drivers are tested. > Here's a post I wrote talking about some testing tools. > Link: https://marcelosc.gitlab.io/how-is-linux-tested/ > > Best regards, > Marcelo > > Documentation/dev-tools/testing-overview.rst | 29 ++++++++++++++++++++ > 1 file changed, 29 insertions(+) > > diff --git a/Documentation/dev-tools/testing-overview.rst b/Documentation/dev-tools/testing-overview.rst > index 65feb81edb14..b00511109a9d 100644 > --- a/Documentation/dev-tools/testing-overview.rst > +++ b/Documentation/dev-tools/testing-overview.rst > @@ -115,3 +115,32 @@ that none of these errors are occurring during the test. > Some of these tools integrate with KUnit or kselftest and will > automatically fail tests if an issue is detected. > > +Static Analysis Tools > +====================== > + > +In addition to testing a running kernel, one may also scout for bugs by > +analyzing the source code semantics. Three tools are well known for serving this > +purpose. > + > +Sparse can help test the kernel by performing type-checking, lock checking, > +value range checking, in addition to reporting various errors and warnings while > +examining the code. See the Documentation/dev-tools/sparse.rst documentation > +page for details on how to use it. > + > +Smatch extends Sparse and provides additional checks for programming logic > +mistakes such as missing breaks in switch statements, unused return values on > +error checking, forgetting to set an error code in the return of an error path, > +etc. Smatch also has tests against more serious issues such as integer > +overflows, null pointer dereferences, and memory leaks. See the project page at > +http://smatch.sourceforge.net/. > + > +We also have Coccinelle as an option within static analyzers. Coccinelle is > +often used to aid collateral evolution of source code, but it can also help to > +avoid certain bugs that have been expressed semantically. The types of tests "avoid certain bugs that have been expressed semantically" would be better as something like "avoid certain bugs that occur in common patterns" julia > +available include API tests, tests for correct usage of kernel iterators, checks > +for the soundness of free operations, analysis of locking behavior, and further > +tests known to help keep consistent kernel usage. See the > +Documentation/dev-tools/coccinelle.rst documentation page for details. > + > +These static analysis tools support running tests on the whole source tree or > +over a specific file or directory. > -- > 2.35.1 > >