Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp6523040rwr; Mon, 24 Apr 2023 22:55:11 -0700 (PDT) X-Google-Smtp-Source: AKy350bOmdmDqfxIjQLk2R2ZAIWJPDyI20BH6VRpEIxJU1/7XIaSK8uaB4qDWcbMagohTQSUFxCE X-Received: by 2002:a05:6a20:42a3:b0:ef:6883:cfc3 with SMTP id o35-20020a056a2042a300b000ef6883cfc3mr19265713pzj.58.1682402111026; Mon, 24 Apr 2023 22:55:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682402111; cv=none; d=google.com; s=arc-20160816; b=SmEgHpgA8SkszYK1VZRutoiLci3mR/P3cncE7wUnykYMZui04gEJ5NDifDFxERcxCD 3Z7LU+dwK3Jn5erA+gVmTgXLLu52cleyzAYivk+UPE5bWV/9TNIoqpicisiGmOJiz+qR 9ABS08rupeVUi7TuBxXKK7bn3y1sX6u+F9Q4Uh/MWR4Hcg4Ri0C6FF9aA7G1vWdixdvS apEBCyYDHTz9bkSG1VWeNc5Nz+doxvuQQH01+Llsk4dpawe2gUgsqpHNaFV8ohl7tShe PUU70KSKoDHt4JQwkxhfAaP3Yrv6eqqvY+mDi4mQml2GFF9r/bIsr0Z99EEpg7Hk351Z parA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=skAOStOjSkbytxKLF9Zg4CyWjog+NUMJCRRfuuj2XtM=; b=IyJyeazISP1UgZQ4Rfne1xDVxWNLwwoWPD8UMQIpeX5iZh9qhmKryLbEyBhgV4qzYN kHb1CO5Bt4IyqbolX9KSBL1PGG8OwK6Udrh9rYxbq6SV2IrNkb1I5Fcfr0sbpv7nsrCY 2Jn2IXfbgIwvJtIrSTGF3c39RRPgJMXbRouN2M4/e1iV7tn0/l80r6ZobujFDjkvA9pV 0/H28K6Qq9geRy7iQXW+b432Y4btJl/qSU5i1aHuwumCU/iGdkNLvj838NRluSkSjCTJ 4eX4fTFUAQKlVEThhcrU1CVQbZCd229FVr1rbzPzD6znkZNShJ0gFAOyOGcBljCBY1xu qZNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=hoj3WaRZ; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t71-20020a63814a000000b00524da606619si9598186pgd.235.2023.04.24.22.54.58; Mon, 24 Apr 2023 22:55:10 -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=@google.com header.s=20221208 header.b=hoj3WaRZ; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231137AbjDYFsR (ORCPT + 99 others); Tue, 25 Apr 2023 01:48:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230195AbjDYFsP (ORCPT ); Tue, 25 Apr 2023 01:48:15 -0400 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60865269E for ; Mon, 24 Apr 2023 22:48:14 -0700 (PDT) Received: by mail-pj1-x102c.google.com with SMTP id 98e67ed59e1d1-2470e93ea71so3957865a91.0 for ; Mon, 24 Apr 2023 22:48:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682401693; x=1684993693; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=skAOStOjSkbytxKLF9Zg4CyWjog+NUMJCRRfuuj2XtM=; b=hoj3WaRZOHUueEDpaU6cueGgjDKhz9oqitzETCkETB/tb7vh4YluPdKV6eNX4mzIfn xTs+y+67ovbFD4r8v0B5gnXq8/hZR3GuDecfMrxIlPSDWv3ZSOm9PP/RmQJVXBT/yaSA e/V99oLyJJJo1GBg9tyu1dLyJJex7mkYPH8C18OUCHsvoSmtWIFi5OhQWIswBrENLR9V 9nMLf/1gvMCF7PCwu+IozBp8SnC50xOyiT2ftsr8kzx3o9F/2Wd3Km3mQpUuqrGMCySC 5JN0Pb5g5MzM6SSUw8Kro7fEB4DNSL8nyKF0n3DYiOo0VXHG9MeMuNl1vS4yLPK2LGMx TUaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682401693; x=1684993693; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=skAOStOjSkbytxKLF9Zg4CyWjog+NUMJCRRfuuj2XtM=; b=aTGLNyti7H8uSlvTK3za118js1Vf5HHQ8K4/XfSlhbzuE4wWK7iYSfMDrpqkG6rGwX Ec0LxIbnGyPgu4HR+n5Xq1bXKj6tMP0hA1BmzZ+6wqdVOqNge38LwZOoCkVQHN45Rb6f 9Rpd7K9465gKs+peAQorDqFSoQL8z74zL1/CkuJRg2OvO6P/EmTX07UuTB1i2ah9/R/R /xskardVID/xRzUt85qGWz8YNx5B9Bdls+L5/EZNRp4hvZOb4tB3BKiflIUYy8F1Akep SFOXUBYuAWGlJoshKJ1KWZ43CGFR+OiGgQ+9hHTc8SyX53x66KhMsRfSBNLcdck5w/FJ lqkA== X-Gm-Message-State: AAQBX9cnXhlECMoA4L3NLio/V/1oB7at27IqWBHFKG62orWftGRznRL1 bYX1QnChTvkk0pcFFljvUUqS++km0Qz8xJxbJpL8Rg== X-Received: by 2002:a17:90b:4ac9:b0:234:ba34:71bf with SMTP id mh9-20020a17090b4ac900b00234ba3471bfmr16050177pjb.1.1682401693373; Mon, 24 Apr 2023 22:48:13 -0700 (PDT) MIME-Version: 1.0 References: <20230421040218.2156548-1-davidgow@google.com> <20230421040218.2156548-3-davidgow@google.com> In-Reply-To: <20230421040218.2156548-3-davidgow@google.com> From: Sadiya Kazi Date: Tue, 25 Apr 2023 11:18:02 +0530 Message-ID: Subject: Re: [PATCH v3 3/4] Documentation: kunit: Warn that exit functions run even if init fails To: David Gow Cc: Benjamin Berg , Brendan Higgins , Shuah Khan , Rae Moar , Daniel Latypov , maxime@cerno.tech, Stephen Boyd , kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 Fri, Apr 21, 2023 at 9:32=E2=80=AFAM David Gow wro= te: > > KUnit's exit functions will run even if the corresponding init function > fails. It's easy, when writing an exit function, to assume the init > function succeeded, and (for example) access uninitialised memory or > dereference NULL pointers. > > Note that this case exists and should be handled in the documentation. > > Suggested-by: Benjamin Berg > Link: https://lore.kernel.org/linux-kselftest/a39af0400abedb2e9b31d84c375= 51cecc3eed0e1.camel@sipsolutions.net/ > Signed-off-by: David Gow > --- Thank you, David. Except for a spelling error, this looks fine to me. Reviewed-by: Sadiya Kazi Regards, Sadiya > > No changes since v2: > https://lore.kernel.org/linux-kselftest/20230419085426.1671703-3-davidgow= @google.com/ > > This patch was introduced in v2. > > --- > Documentation/dev-tools/kunit/usage.rst | 12 ++++++++++-- > include/kunit/test.h | 3 +++ > 2 files changed, 13 insertions(+), 2 deletions(-) > > diff --git a/Documentation/dev-tools/kunit/usage.rst b/Documentation/dev-= tools/kunit/usage.rst > index 9f720f1317d3..f6d6c9a9ff54 100644 > --- a/Documentation/dev-tools/kunit/usage.rst > +++ b/Documentation/dev-tools/kunit/usage.rst > @@ -166,7 +166,12 @@ many similar tests. In order to reduce duplication i= n these closely related > tests, most unit testing frameworks (including KUnit) provide the concep= t of a > *test suite*. A test suite is a collection of test cases for a unit of c= ode > with optional setup and teardown functions that run before/after the who= le > -suite and/or every test case. For example: > +suite and/or every test case. > + > +.. note:: > + A test case will only run if it is associated with a test suite. > + > +For example: > > .. code-block:: c > > @@ -196,7 +201,10 @@ after everything else. ``kunit_test_suite(example_te= st_suite)`` registers the > test suite with the KUnit test framework. > > .. note:: > - A test case will only run if it is associated with a test suite. > + The ``exit`` and ``suite_exit`` functions will run even if ``init`` o= r > + ``suite_init`` fail. Make sure that they can handle any inconsistent > + state which may result from ``init`` or ``suite_init`` encoutering er= rors Nit: Spelling of "encountering" > + or exiting early. > > ``kunit_test_suite(...)`` is a macro which tells the linker to put the > specified test suite in a special linker section so that it can be run b= y KUnit > diff --git a/include/kunit/test.h b/include/kunit/test.h > index 57b309c6ca27..3028a1a3fcad 100644 > --- a/include/kunit/test.h > +++ b/include/kunit/test.h > @@ -168,6 +168,9 @@ static inline char *kunit_status_to_ok_not_ok(enum ku= nit_status status) > * test case, similar to the notion of a *test fixture* or a *test class= * > * in other unit testing frameworks like JUnit or Googletest. > * > + * Note that @exit and @suite_exit will run even if @init or @suite_init > + * fail: make sure they can handle any inconsistent state which may resu= lt. > + * > * Every &struct kunit_case must be associated with a kunit_suite for KU= nit > * to run it. > */ > -- > 2.40.0.634.g4ca3ef3211-goog >