Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp244720rwl; Thu, 30 Mar 2023 15:23:27 -0700 (PDT) X-Google-Smtp-Source: AKy350bBWAAEfuuND5xx3B9f43OiKyWPUs9PSGydGCzHD+1IFeqfi4UtESJdzwyd+aDRDcvYtpCw X-Received: by 2002:a17:906:15c:b0:8f5:14ab:94bc with SMTP id 28-20020a170906015c00b008f514ab94bcmr21538176ejh.6.1680215007686; Thu, 30 Mar 2023 15:23:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680215007; cv=none; d=google.com; s=arc-20160816; b=0KdzQP2p3QaoxriRJPAboOfOlNcXOjQaxs7IYn1niv7SfZsAI8JIRCk3OljPCx6eoB T9YRlhZcJM1hUzV5aN94XyEunh7W6tWQgyPOvxrd2Lp9rY7aEqzrrCPvofrn0Mw3g9Kk QihRNWlls4akCFA6K1acmvKWRJguMCbLdQBH8VttGY0HOh+EpFDd3ZWhfVso3eWmMV4T Cl/DIRIgPEF0TbPc+1w1SqdQVHS8OzKvMTGyAt5pYBm8WkQI9ocpYvQ9N+kqShOIN/jR 5FBUHW7s9D9i/n2O7LjFtPfLNYdMUUXC6KUWlu4wt5ZKRkQ9My5pV79uyLbPHMQCknds Gkeg== 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=ugtukTfVbDV/8BLzVhb0qFtwrdmFXjkERveHQp9G65k=; b=YHIve2i0/R44TwZpwvX2AqAELdhZhZOL2SiPBz/8PoCAke2+xxrFtrqhVUQ7vlYILe uOsZCo5jGKOfvk5LWAzBqzy8Qo8oSa8MCxNqvMfTp/i+Y3e2tc1I7cs/lOX9/X+gMYAA 8aQHxvCxmMU+yLNBEb7FvxxAh6JOihOxnAI5tG09aFVq9epxccIA5S+DRpu76K6MfbSJ bG5jF+q3Q9mqOkpv35HzrQ58qGJQPp2Mj74N21yReg09BR/KiGn8V3tPWENlvtwfLCpW JpZ2tlmz2vguCoVYg8iYz9Uf7kvoiuCWJebGPkptY/wggSEs8F2GynOyp25443hQdX+1 ahig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=QZW1GJVA; 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 j26-20020aa7ca5a000000b005002cb238e1si772193edt.350.2023.03.30.15.23.02; Thu, 30 Mar 2023 15:23:27 -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=QZW1GJVA; 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 S230255AbjC3WVK (ORCPT + 99 others); Thu, 30 Mar 2023 18:21:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229914AbjC3WVJ (ORCPT ); Thu, 30 Mar 2023 18:21:09 -0400 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80F54B761 for ; Thu, 30 Mar 2023 15:21:04 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id qe8-20020a17090b4f8800b0023f07253a2cso21317372pjb.3 for ; Thu, 30 Mar 2023 15:21:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680214864; 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=ugtukTfVbDV/8BLzVhb0qFtwrdmFXjkERveHQp9G65k=; b=QZW1GJVAmZz3qfIMiei04YZkmBfPBmo9pjKDJ0qIuljXSgJnrQfiMXpSTDlZ3uIfCK cjDiVcujfjVO0lTG8UoYtP3BX8zbOy24sgjzQhp4lxBlv/vjHz2NGjgLsiu3amflo2Wi iU39U0/7TViaKVt3ek+fdn1/FrYJLAGPyPBStfAtvbZuwl6j9tq7rYpkhxbGKvSGuJio DxX2qWP+h93Bw2S7dLJi4JPrX5xg+AitcnTeK6DuJ9B+uDWpBPfDtsOrhEj+vqav3nAQ AD34aKGZzXypuB5br7F2mU7PW1XxsQl0l2wfI84qTJfb18gZO2Auel2N2sEsfv6SeZM/ IPuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680214864; 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=ugtukTfVbDV/8BLzVhb0qFtwrdmFXjkERveHQp9G65k=; b=Q8Q+HaaYleqNQXy+MIOHwAViFipJ9epnLHQ6QMcHInRIcfecCxudfTvoLBXNIb9CZG VTb70lENplT22oxIL3K0b6MAGXcOH7IW37ib8Bm57GP4j4Ii2Zw2C1kHkNR8a1CrtcyU dM4UdFXPc6EWWlH7g/o889dqBLY8w3VdLYQ94ytoxzk3ZUl10VfucJsnLK4vmn8tWTFw kc7jKqYBx16QmzXDQq8Ht+ooyf58TIvg/SJbRr5Vuoify1nvX4Rs3mUjOHcNjoDZZGMJ 7Ds1H4Dx7g3oT90WUqX9nP4RETP9rmnr5iGqVdtr25nIRUkcTYrvb2KEDYC+jXHIxyE3 fIcg== X-Gm-Message-State: AAQBX9c7ttem9GVYB+O08dMiPK6YfM9MYzielK21PArnZ1LaSTEt3wTP B1LxicUj+4Qu5RxDIy9m9SHW9JIudkYgY6aPdnfYRA== X-Received: by 2002:a17:902:ea0c:b0:1a0:527b:9189 with SMTP id s12-20020a170902ea0c00b001a0527b9189mr9224011plg.11.1680214863803; Thu, 30 Mar 2023 15:21:03 -0700 (PDT) MIME-Version: 1.0 References: <20230330220506.1399796-1-rmoar@google.com> In-Reply-To: <20230330220506.1399796-1-rmoar@google.com> From: Daniel Latypov Date: Thu, 30 Mar 2023 15:20:52 -0700 Message-ID: Subject: Re: [PATCH v1] 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 I've got a few minor comments below, but this otherwise looks good. I like the idea of testing knuit_fail_current_test(). On Thu, Mar 30, 2023 at 3:05=E2=80=AFPM Rae Moar wrote: > > +static void kunit_current_kunit_test_field(struct kunit *test) > +{ > + struct kunit *current_test; > + > + /* Check to ensure the result of current->kunit_test > + * is equivalent to current test. > + */ > + current_test =3D current->kunit_test; > + KUNIT_EXPECT_PTR_EQ(test, test, current_test); Perhaps we can combine this and the next test case down to static void kunit_current_test(struct kunit *test) { /* There are two different ways of getting the 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_get_current_test(struct kunit *test) > +{ > + struct kunit *current_test1, *current_test2; > + > + /* Check to ensure the result of kunit_get_current_test() > + * is equivalent to current test. > + */ > + current_test1 =3D kunit_get_current_test(); > + KUNIT_EXPECT_PTR_EQ(test, test, current_test1); > + > + /* Check to ensure the result of kunit_get_current_test() > + * is equivalent to current->kunit_test. > + */ > + current_test2 =3D current->kunit_test; > + KUNIT_EXPECT_PTR_EQ(test, current_test1, current_test2); > +} > + > +static void kunit_current_fail_current_test(struct kunit *test) > +{ > + struct kunit fake; > + > + /* Initialize fake test and set as current->kunit_test. */ Nit: I think the code is self-explanatory enough that we can drop this comm= ent. > + kunit_init_test(&fake, "fake test", NULL); > + KUNIT_EXPECT_EQ(test, fake.status, KUNIT_SUCCESS); > + current->kunit_test =3D &fake; > + > + /* Fail current test and expect status of fake test to be failed.= */ Nit: I think this comment could also be dropped or maybe shortened to kunit_fail_current_test("This should make `fake` fail"); or /* Now kunit_fail_current_test() should modify `fake`, not `test` */ kunit_fail_current_test("This should make `fake` fail"); > + kunit_fail_current_test("This test is supposed to fail."); > + KUNIT_EXPECT_EQ(test, fake.status, (enum kunit_status)KUNIT_FAILU= RE); > + Hmm, should we try calling kunit_cleanup(&fake); ? Right now this does resource cleanups, but we might have other state to cleanup for our `fake` test object in the future. Daniel