Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp4994429rwl; Mon, 3 Apr 2023 12:42:35 -0700 (PDT) X-Google-Smtp-Source: AKy350ajaSpYkPkOIJQFK13b8ohxcRAAHIYhNTnAHZobaoTi3BSTwjPpdYsiNpADnTQJ6ijtsemI X-Received: by 2002:a17:907:1707:b0:922:ae30:3c23 with SMTP id le7-20020a170907170700b00922ae303c23mr36826972ejc.18.1680550955232; Mon, 03 Apr 2023 12:42:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680550955; cv=none; d=google.com; s=arc-20160816; b=TXjVUc5OUGXS7N5inwGZLtD3Id9bJVvI5z2kwQdi9Wt3aHjdCrgz3KLThzxMsXZG7C z/qE1TrkdfaohrCP201ET9dQOBmpkrhQ7do30zOMuC9ytPw4rI2ujTdfZbQQ4J6D3s2v 1CSy67JjsyX3lAe3JWJfkzk/u6jzcShVTL3qo1a21jvKxLGKfOb8+2JxTgW2UrEpqqUv /N7pio7jQK53wjxUEekZYmqkWBRx+aah9kA941xV3jTpw7X3GXT/56FFcH6C311E3vG/ v5zdrd2jZkAt8iBKDDeEU+hNEO4V+q088nLz7ZcIjtniy/EE7Z2Qj9S5uu8JNTgp+gMK wpBw== 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=G4Sb4aNB4Tm57pBv/LH7p9W/GH8iszsqK1rV9TrOUZc=; b=FSxZbAWgXjaRENyCe5gGdkHUqF/PoqoL05rYHKNJfK1jq1oft+Cn6rStuV2VYZCCq0 NhTVw6bmvd/fGuVhv2vUmrWOL/B9cgQwQok2SlN3G2HXWqBqn/eodmdG3bhjiSKDwkEn clJ2C7Ccaeje1Vt5/tXTo/K2L/CmFm1QCUBLrKR9GVQne2ZhHf5Lz8gRau1PLGkBGN/N ccfuM+B0n5ZJvM3686cPz9NSaYZJOPSe/Iow8Z3wCWQclOzv0yQdiZ6nIclcXR3I3f/7 S26oEDWCSIGkdGHnIQ5xxDeBNqjpSE17feTjBkzectEQyep08lg8+G14oSd2cuZBtlcY GG3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=nYYDFFKA; 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 h19-20020a50ed93000000b004ad0c88b55csi5155830edr.401.2023.04.03.12.42.03; Mon, 03 Apr 2023 12:42:35 -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=nYYDFFKA; 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 S231906AbjDCTbW (ORCPT + 99 others); Mon, 3 Apr 2023 15:31:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231538AbjDCTbV (ORCPT ); Mon, 3 Apr 2023 15:31:21 -0400 Received: from mail-yb1-xb33.google.com (mail-yb1-xb33.google.com [IPv6:2607:f8b0:4864:20::b33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E588610D8 for ; Mon, 3 Apr 2023 12:31:19 -0700 (PDT) Received: by mail-yb1-xb33.google.com with SMTP id z83so36159390ybb.2 for ; Mon, 03 Apr 2023 12:31:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680550279; 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=G4Sb4aNB4Tm57pBv/LH7p9W/GH8iszsqK1rV9TrOUZc=; b=nYYDFFKAXmmdC1bVg5DC83TMEBHx4jZsXCuTbeSRd8ZjWy7iLQuvcjEfL7ofTaEL8/ YjElsr+7BynO6vwxnqa6LDCIkwnoID+0edRZfbXJ6xQ9PikFF/p9v9zH4SMjPHdSZhHR PteRSNhbrK1xsTF/haX4qChzd9AKqn283LYh2DbsCVlOSt4ToBEgeRUmxAeuiepQd0ON AUvIS8eAhyWe8MfEi9yDqJQgx/5HZPhgk7PRr/wBgGHTRAxgVcm+aRcIKIEv2uRmFXHx dZTrQrRkPbB/gusO/u2KCC3MIytz+zDdRjvmVaq4WjXlQurWo+RcHLvuOVDEvPGTZjq+ UYrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680550279; 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=G4Sb4aNB4Tm57pBv/LH7p9W/GH8iszsqK1rV9TrOUZc=; b=f0LEvKZbJBRyeqv/TV3uwFBgtx8HaVMOsQ6/SllFjo2xzPRMW8uJIA2bhnsvvlkQbf jzT7X4gJ/m3Ju8v1fqrxZw2eA5ndUQxwTJwUN6NTvwHMC/YCIkvdawBfnIQCQq/sWMjx xxUjND+oeht1lSINe4ga+mAs0Hei6pa5tAOVsU/so9tolniWjKZfj8laTwWv3cn3Nlon MOsvgbc8Kfnx+VLOakXHJU04nySWBFCDg6ETJV2rCd3kw0CXKODL5m3Fd8HD618kPRI7 BCgotTSIZ7RUb3dcSicUnWa/Nlnn2zlOCpFwosI8Mr4IyFY4aoZvV+SiJelxD/k4beLZ cn4g== X-Gm-Message-State: AAQBX9ffUyXd+bpJZNHJ0DqyayrVoNUYmN4zj5b2/gomwvc9eH0Jqnpe x3T2O5kzFxWXegD10w9RRXgNKjiQp0iscXFQltvDAg== X-Received: by 2002:a25:3141:0:b0:b73:caa7:f06f with SMTP id x62-20020a253141000000b00b73caa7f06fmr224227ybx.5.1680550279039; Mon, 03 Apr 2023 12:31:19 -0700 (PDT) MIME-Version: 1.0 References: <20230330220506.1399796-1-rmoar@google.com> In-Reply-To: From: Rae Moar Date: Mon, 3 Apr 2023 15:31:04 -0400 Message-ID: Subject: Re: [PATCH v1] kunit: add tests for using current KUnit test field To: Daniel Latypov 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 Thu, Mar 30, 2023 at 6:21=E2=80=AFPM 'Daniel Latypov' via KUnit Developm= ent wrote: > > 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()); > } > ? Hi Daniel! Yes, I would be happy to combine these for v2. I might want to alter that proposed comment slightly. "Two different ways" seems a bit unclear to me. Maybe: Check results of both current->kunit_test and kunit_get_current_test() are equivalent to current test. What do you think? I might send out a v2 with a proposed comment. > > > +} > > + > > +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 co= mment. > I agree the "initialize fake test" comment is self-explanatory. But if we keep the comment regarding resetting the current test, I think we should mark when we set the test as a fake with a comment as well. > > + 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 faile= d. */ > > Nit: I think this comment could also be dropped or maybe shortened to > kunit_fail_current_test("This should make `fake` fail"); > This first option seems good to me. > 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_FAI= LURE); > > + > > 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. > I would be fine to add this here if it is wanted. Thanks Daniel for the comments! Rae > Daniel > > -- > You received this message because you are subscribed to the Google Groups= "KUnit Development" group. > To unsubscribe from this group and stop receiving emails from it, send an= email to kunit-dev+unsubscribe@googlegroups.com. > To view this discussion on the web visit https://groups.google.com/d/msgi= d/kunit-dev/CAGS_qxqNwVcymkG6-8Kv72oZc9aDqjFjBBmjr%2Bf%2BmOVKT1bGvA%40mail.= gmail.com.