Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp5697667pxb; Mon, 28 Mar 2022 16:21:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyaRX9sj7LRXUrZAO4XDH3OR14YgFT//sLM843W7oHaulBP7z85x1aBPyuLeNsnVU/rAedZ X-Received: by 2002:a05:6830:44a3:b0:5cd:a76c:2cb3 with SMTP id r35-20020a05683044a300b005cda76c2cb3mr11041502otv.79.1648509691001; Mon, 28 Mar 2022 16:21:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648509690; cv=none; d=google.com; s=arc-20160816; b=J/SUwKKp4neHEsJhMo6uaT6aDP9q75CfQU1my+jSX9NuduSvuGfwPLq87L6NMTPlCr 12af9eX44TcapPWkFENuFXYLfdWijVvl8hG8GcVrDdTPT9di1Gx0mC78euCN432XU/ok mEDDoJGm6If7NGs5GP+1cxYcM8j57uTifeKS3ByWMFW+pYp4rIXIDGLzVOzn2K/gBN17 a4fWoZc90TUwe6CtJ1aAOnpXhmYAdFIEwuTdSoPNeA+f3fFceS/wwTaCQnenlVyz26dF onloUhz0pIkgg4MaVGzKVr+ikgYi8A69W7KnR+8EynWlk8TeAGhq2gHAgu9InXa4i7Wz bMqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=koFN17ulxhdVtMhymKzO/TIc0UlPzvBHq58ZjJYY7jM=; b=MvWVyQ4El/zobHOje3/p0UJXoqEQ3wlrWCSrzNW4HnnAOt6+BlIkChuHLk6C4WT4Hb fWb77d5G9dmkWS2p97P/uC+yycVfep9i8y8FrkvNlqOPykFLEgCnHqK6yk3cCjFxH51V hI3fvVKogDGoEG3WCMJJUXQdePS4kPxm0Qb/EnTKV57HAd6j7BWxc4aVQP8N8aPBT5nw VsWcF6SLMlROsCF1hZ/uud0TD8SuTgQ874Po0c7k0uORZ1E54a8SAi8B6UUY+O+0uYDh Y0uAJ2M1linM61pt9bCvfvoLdttv8gtQ/l5CHTeGVDXmfuoVn9tX8bfmZDsjO5WqtRG2 xsRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=AIfvTei1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id f22-20020a9d7b56000000b005cb2fc13863si12348916oto.223.2022.03.28.16.21.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Mar 2022 16:21:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=AIfvTei1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DFD2F49693; Mon, 28 Mar 2022 15:37:48 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229837AbiC1WjZ (ORCPT + 99 others); Mon, 28 Mar 2022 18:39:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229934AbiC1WjX (ORCPT ); Mon, 28 Mar 2022 18:39:23 -0400 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37AD94925F for ; Mon, 28 Mar 2022 15:37:41 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id h1so18658550edj.1 for ; Mon, 28 Mar 2022 15:37:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=koFN17ulxhdVtMhymKzO/TIc0UlPzvBHq58ZjJYY7jM=; b=AIfvTei1IeVbt+Bk9bsDu8i0OAjWtkFUIv7yu6nVy8c08SnnefFP7cH85NLEj/wNCw i2/jbg5t6KzHaYJu21vb1zZZOPfSMKIAjkR+wE9H95LVEpePX5UnIgZg54doj1ggCPBc +E5bTjIsBu2ynhVqQIXJaZyKH5zDOCTzn7NjYEQi1hJkAah/ZByHz5rUdih+9IMXoZKn kj1nSrlWjgLfiTlk1zuDCj6eG9iDc1KzyG+e9pGVIJXj8bktP0wojYEZJz2sgMCIF8R4 iQhNT1pJbGBi/pDON8VfwJv3viJtAZLBCCh4o1dGEvU7Ij2Ep6L7qPMlleiNsd5gbyl1 8vAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=koFN17ulxhdVtMhymKzO/TIc0UlPzvBHq58ZjJYY7jM=; b=q1aDl5aD1XQE0ApOQIkfxr7pyd+Dzz/Lc0QCJg66fqf57dcwEBnNN6HFgfk+Qsx6A1 +zbTNqEphTrgpzu7UiOqSEwldSLiF0WPMO6W+PojZ6EuZLMsb80DSEUwaCUFjzLg1iF8 dfmbCwXr97Xw9eJoD7unSU4gcQhCPwJvACM/Gv4SJ05TJ5eGd38U+6bATysKtQVWYVUc 9RGFn/Bfo3jZaKPE8c77IxLorbbnIkekujMfhP8a85a7RFO2YV/BMervPWEsBb7BikFo fNpFS1BJNq6tyB9ndun2ONG5NUkn+Zbl60mI25y1K2L0WgA8pQuSeOejS7yob+hWYw+W 6qNg== X-Gm-Message-State: AOAM531wZH7NjGodWh50aYCUAgEtesYeJsNR5MDdl/B4FiVRVrIy2RZ3 2DULgpLYisP5ndEmnV/aTQmsPIxca4H3LrX6bK2aoQ== X-Received: by 2002:a50:c307:0:b0:418:ec3b:2242 with SMTP id a7-20020a50c307000000b00418ec3b2242mr147905edb.229.1648507059439; Mon, 28 Mar 2022 15:37:39 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Daniel Latypov Date: Mon, 28 Mar 2022 17:37:28 -0500 Message-ID: Subject: Re: [PATCH] Documentation: dev-tools: Add a section for static analysis tools To: Marcelo Schmitt Cc: corbet@lwn.net, mchehab+huawei@kernel.org, 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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no 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, Mar 28, 2022 at 4:20 PM 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 Nice! This is definitely worth including, but I'm out of my depth here. Some ideas below in case they're helpful. Acked-by: Daniel Latypov > 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 Coming from a place of ignorance, when should I use sparse vs smatch? Is there an existing consensus on this, or is that a controversial question? I assume other newcomers like me will have the same question and be unsure if they should spend time learning about sparse. In general, I think the main point of this page is to explain both what the tools do and give an idea of _why_ someone might want to consider using them. > +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 > +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. Personal preference: I'd personally put this up before we go into details about each tool. E.g. perhaps like In addition to testing a running kernel, one can also analyze kernel source code directly (the whole tree or specific files) using **static analysis** tools. Some tools commonly used in the kernel are ... > -- > 2.35.1 >