Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp5209297rwl; Mon, 3 Apr 2023 16:29:36 -0700 (PDT) X-Google-Smtp-Source: AKy350axaj30bF1VmxRcIBhCi/zA4U7JJ8Ao4POFs1sSbIW1ti6jKwr3Iq66ubhK8lqTcEccYx8+ X-Received: by 2002:a17:907:988e:b0:947:bd54:cb8e with SMTP id ja14-20020a170907988e00b00947bd54cb8emr735815ejc.10.1680564576651; Mon, 03 Apr 2023 16:29:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680564576; cv=none; d=google.com; s=arc-20160816; b=MZKCwxYdxo3fA4BF2iN3glG1uVHYwfEIQyKA0LeF9LMe0C9EFxlbvP8kPoARZnrBb4 +5ZnAEITaKRyG0hz+qhlevBUF7adilI/TgKgQcmEJ4Awhve114Y3UHQ4fSvN0BVpqRpA VNEApphFk0aVuo4TFTyPzQE/la+jgrFP4wort9utdiYcgd0liOMbRUeIt1O2Y7UEpdM3 fYjwYbug0BklVUMWAHLu66hqSdDdwi4IG71UTisr8U5rsMvbKTaFRrsCkWlgurRO5HdN IzznBNfFJIedrxaIIKjMlINGYGj5dNCgNCLFO/ERIlCeHdROgViFegl9686c6ZO3w0+o abdA== 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=fL5aL7ueJMbZFfg2C1YEce55qF2blBEt+U5Y2R4F0x8=; b=cfo72ULDVzl8pXwF1Bk6JD7FkwIrapvLurmYkRpx3WwfHiIudbyUzFnsxJdIGdA65Q vC1uJvMaKKS5ItFQHW5RkMhAyTU2F5P9SRlUPVCD/QPGB8XDzqd8AQuwC+JXHLrxZAIT B7dSNI+eNpytC6bfy+VqQT7HWet7r2HiQx1FhWyZGXn8H430xesknwIeqkF8FndaUjDU leTPeMzOCEWyu35sUOaa7aArmbOKJxLiAbv0ar3LyPicyzd7litel3VjE1GJOktsZKD0 oFo/U1ABz5h4Po1sy071VUg0MKUD9sRJAB4B8vVjKbylDYmn/Z/2OOxaiHFUHZE59aYk S8yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=heQGaq5J; 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 d3-20020a170906304300b009334dc89725si7795741ejd.145.2023.04.03.16.29.06; Mon, 03 Apr 2023 16:29:36 -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=20210112 header.b=heQGaq5J; 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 S233591AbjDCXRn (ORCPT + 99 others); Mon, 3 Apr 2023 19:17:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233752AbjDCXRl (ORCPT ); Mon, 3 Apr 2023 19:17:41 -0400 Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F189AD7 for ; Mon, 3 Apr 2023 16:17:40 -0700 (PDT) Received: by mail-pg1-x535.google.com with SMTP id 185so7372471pgc.10 for ; Mon, 03 Apr 2023 16:17:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680563860; 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=fL5aL7ueJMbZFfg2C1YEce55qF2blBEt+U5Y2R4F0x8=; b=heQGaq5JSUiONOze0+sgMt3BY4yh1MXR60iNGsJnSnCwUPz3PGzvkoSTCovdOnIanZ Qv5+kttSgXzH/C+6iNGQyhvFen9aa8LT2KHMP7p8elo5gq4sDqoV5wGjjC6X72L385d4 KCGXmhKMTjpK75uOwiAmI0M6yd8H4qpM9tapP70G1dQ6avtihVJNYxggCYLGTtIhhdBO yUIaEPWOxdV+43VRFix1Mgb/qMZs/5LvtCunIK5hCLor2bwMMQgXfL1k1N3T3T1h3a5Z 4/ZANM55rgv7h1LkUFTu0n0j0iO5fL4ULCQLzTBuJGVXO1im1LTC1mYHpMSaEwPnuxnr d/Zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680563860; 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=fL5aL7ueJMbZFfg2C1YEce55qF2blBEt+U5Y2R4F0x8=; b=kSxd3txs9JMOxaWlF8hAeDLlj1PFIn1WRlrH37IxFHwgHGJekqL5nX/dbXfLSTmIgK WjmM0aiu6WVZnkhDSCSPufZIXDmed+TqgrRPrytcH7ul76g8PaiTKU5u1S4iWV3LcXbM aCNH5EQcm72x3XJphcQtxTNUsMhsC2pDUqvycrENzyqbl58KFVVB7FoDCGEb6B9dW8j+ KUzZ3suBrhn5sWtHqUIaOU91BRzVCrkvxCVxp9qo5QrVQXBmzcrqJezvndEOlzVYV2jg 1Q1TLbPYf05fzgwfBjtCCZ0uWgUlWHETiw2xLGPIvSiUoPth7F2yr96qmW7sJk6I8y/m mxSw== X-Gm-Message-State: AAQBX9c/tWHl1V1cTy3hVPcSgDxk1duMD4h1jvkZLQ5GULYKF7sIA8NX xmih1/VyR6BtV0yhmCJHuBQi57XPErkZYQ06plj0Aw== X-Received: by 2002:a63:eb50:0:b0:509:4ac5:7f44 with SMTP id b16-20020a63eb50000000b005094ac57f44mr88131pgk.2.1680563860189; Mon, 03 Apr 2023 16:17:40 -0700 (PDT) MIME-Version: 1.0 References: <20230403201930.2019419-1-rmoar@google.com> In-Reply-To: <20230403201930.2019419-1-rmoar@google.com> From: Daniel Latypov Date: Mon, 3 Apr 2023 16:17:29 -0700 Message-ID: Subject: Re: [PATCH v2] kunit: add tests for using current KUnit test field To: Rae Moar Cc: brendanhiggins@google.com, davidgow@google.com, skhan@linuxfoundation.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-15.7 required=5.0 tests=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,USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL autolearn=unavailable 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, Apr 3, 2023 at 1:19=E2=80=AFPM Rae Moar wrote: > > Create test suite called "kunit_current" to add test coverage for the use > of current->kunit_test, which returns the current KUnit test. > > Add two test cases: > - kunit_current_test to test current->kunit_test and the method > kunit_get_current_test(), which utilizes current->kunit_test. > > - kunit_current_fail_test to test the method > kunit_fail_current_test(), which utilizes current->kunit_test. > > Signed-off-by: Rae Moar Reviewed-by: Daniel Latypov Looks good and runs well here. It's nice to have a test for this given kunit_fail_current_test() went from a simple function call to now using `kunit_hooks` to do an indirect call and relying on the `kunit_running` static key. > --- > > Changes from v1->v2: > - Combine two test cases to test both ways of getting current test in > kunit_current_test. > - Changes to comments. > - Add kunit_cleanup to kunit_current_fail_test. > > lib/kunit/kunit-test.c | 42 +++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 41 insertions(+), 1 deletion(-) > > diff --git a/lib/kunit/kunit-test.c b/lib/kunit/kunit-test.c > index b63595d3e241..42e44caa1bdd 100644 > --- a/lib/kunit/kunit-test.c > +++ b/lib/kunit/kunit-test.c > @@ -6,6 +6,7 @@ > * Author: Brendan Higgins > */ > #include > +#include > > #include "try-catch-impl.h" > > @@ -532,7 +533,46 @@ static struct kunit_suite kunit_status_test_suite = =3D { > .test_cases =3D kunit_status_test_cases, > }; > > +static void kunit_current_test(struct kunit *test) > +{ > + /* Check results of both current->kunit_test and > + * kunit_get_current_test() are equivalent to current test. > + */ > + KUNIT_EXPECT_PTR_EQ(test, test, current->kunit_test); > + KUNIT_EXPECT_PTR_EQ(test, test, kunit_get_current_test()); > +} > + > +static void kunit_current_fail_test(struct kunit *test) > +{ > + struct kunit fake; > + > + kunit_init_test(&fake, "fake test", NULL); > + KUNIT_EXPECT_EQ(test, fake.status, KUNIT_SUCCESS); > + > + /* Set current->kunit_test to fake test. */ > + current->kunit_test =3D &fake; > + > + kunit_fail_current_test("This should make `fake` test fail."); > + KUNIT_EXPECT_EQ(test, fake.status, (enum kunit_status)KUNIT_FAILU= RE); > + kunit_cleanup(&fake); > + > + /* Reset current->kunit_test to current test. */ > + current->kunit_test =3D test; > +} > + > +static struct kunit_case kunit_current_test_cases[] =3D { > + KUNIT_CASE(kunit_current_test), > + KUNIT_CASE(kunit_current_fail_test), > + {} > +}; > + > +static struct kunit_suite kunit_current_test_suite =3D { > + .name =3D "kunit_current", > + .test_cases =3D kunit_current_test_cases, > +}; > + > kunit_test_suites(&kunit_try_catch_test_suite, &kunit_resource_test_suit= e, > - &kunit_log_test_suite, &kunit_status_test_suite); > + &kunit_log_test_suite, &kunit_status_test_suite, > + &kunit_current_test_suite); > > MODULE_LICENSE("GPL v2"); > > base-commit: 7232282dd47cce6a780c9414bd9baccf232c7686 > -- > 2.40.0.348.gf938b09366-goog >