Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp130463rwb; Wed, 9 Nov 2022 21:25:19 -0800 (PST) X-Google-Smtp-Source: AMsMyM5VbYEIh1N7E6SrA76qyDfrinee1fflR/4yOx4o4zylTzRWP7FHRdgn3E/oQP0T1buiQHb7 X-Received: by 2002:a17:903:2305:b0:186:ed93:fc3f with SMTP id d5-20020a170903230500b00186ed93fc3fmr63913035plh.15.1668057919540; Wed, 09 Nov 2022 21:25:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668057919; cv=none; d=google.com; s=arc-20160816; b=sH6C31jmO5H53XLj6PPtyzOhwfUKf+dRMZ58bccR3WGn+5F7m9cL3mC0bDu4TM+/RK YNMqbvAmG19Gdlq439qGpFWFVzGLmYZHD/2114Zd/byZsTlDX4B/N/B99GxcdcJMdhiq kly72zc8IGaL/m8D/65OoC+gGczXXqwKEU7qh5VAFsICPE4A3Ngv/RjnWn8Qey6Yd6F4 M0MI6o2ze6WH3NatjLdUq4pGN3HvLxBYFdkqBQ1WGPfIq99FsijVoTkLk7yCVuzzK6YN s82TOVmxhF8psopY8YE3umY7G8DsbOD1Je/I5I7bDNwByM7mZTxbbH7UJfNnZWSaD19N 9YnQ== 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=sj8wNl0C9PC/zOv2XJt8nA/5SMVTgoTRqXcZ5Z4tzIk=; b=PP1KG4Xr6KwamlITIIUGiNjrVLlpj0/DHVo2UMGepPtMsaXujMQeuJ0Vvmj6wUrjqN LdedM/NOoXg1f9B97BkGiqws3iPaXF23fCpf1fTmsHiDbTdMmgKfjyoWuMUB9DyqUcN7 S5yoGzWgpanwgjoPkGw4U8E2b2BiixWDH40yUCLOy8Qde0REqx+MYOcmTWQelGUC3E0n H4fgNEOTTsqm0n60n9SdyEcLW5nXbfCbqmx9gQdRauIrLHTUSsCz//zYKo1kf2Py/zsS v9g9c5Exu7XLYFDl51VKScfxQbUckqZsmrcRw8yWmPAGDz0Eo3ktae56Z2gkGZxJ3989 jkmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Gh8kF88u; 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 l125-20020a632583000000b0046fbe60adc5si20325852pgl.510.2022.11.09.21.25.08; Wed, 09 Nov 2022 21:25:19 -0800 (PST) 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=Gh8kF88u; 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 S231185AbiKJErn (ORCPT + 93 others); Wed, 9 Nov 2022 23:47:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232107AbiKJErk (ORCPT ); Wed, 9 Nov 2022 23:47:40 -0500 Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68E9626487 for ; Wed, 9 Nov 2022 20:47:38 -0800 (PST) Received: by mail-pg1-x530.google.com with SMTP id 78so649065pgb.13 for ; Wed, 09 Nov 2022 20:47:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=sj8wNl0C9PC/zOv2XJt8nA/5SMVTgoTRqXcZ5Z4tzIk=; b=Gh8kF88uBhB9HnMImspkPpjsknFP9/ULBYIRZrBVgNeLP52LCYRPyQqxCqQOCwZYlC YALYtdSgRJ0qAVlU+fCj7rNgKmgqHN359Me6Xrb/g3AdKzC5gdLr2klBeJG/gP2UXl8Q sf/LSGN/sLnyc1p8CjugPgtCPZrldgiVo7hhI5VH77b3e2jHq0K/q7XsboB4zS9fSujO 2I9VnKtPW1MIBGpb+fvE+sCEeIyC7GtAuithJcXjngPwURBbLqew3DoOHOhOK59p/Yc1 7EUKj2ReFEhp2NclJa9Rc4p1HStOZ4UTD2L8LQtspvSW4dJihG0FdA/jM3MvuezCU7bz Evyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=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=sj8wNl0C9PC/zOv2XJt8nA/5SMVTgoTRqXcZ5Z4tzIk=; b=uHgN50mOj2yosk9cfevgJZ5axScYYn7huIXYdKip6Ah1CiCPrOwTq6aIzQnhT5oYHB vn27p1BB6nrJyEU57pZY5PMu9bEM0Y233PMGGMY2/1p3gYXHwYEGrSXQKHJtt0cEYsNs MM1+yLarhOWp+NWk+C5CnBlCtuItwn1KsuFdhcrMEwpqJlQsRpMpOEwhDs5PiaI2Ekx6 VV+a50HHZd8nOhWPr6I5wSCEuSaCfyKOZAbUMTx+crwb9mgqXMSqMrrz2xq6nALifxFo nZMjMoS8yon+DLRCE5oXKt2zZ2BTFvLMEJ15T6CShsSL/VI081cyAIFDIIs78+/BQMAn iRjA== X-Gm-Message-State: ACrzQf2W+KNF2UG+cO1N/jNG7zqXEQChacdSV0XYmYBktKOPOsIJCX61 7ZiU7f1NF6CdGWUTSFz1defdrlAQS4NdzEeNEcogGA== X-Received: by 2002:a63:d44c:0:b0:470:1a08:248d with SMTP id i12-20020a63d44c000000b004701a08248dmr1588270pgj.393.1668055657785; Wed, 09 Nov 2022 20:47:37 -0800 (PST) MIME-Version: 1.0 References: <20221109003618.3784591-1-dlatypov@google.com> In-Reply-To: <20221109003618.3784591-1-dlatypov@google.com> From: Sadiya Kazi Date: Thu, 10 Nov 2022 10:17:26 +0530 Message-ID: Subject: Re: [PATCH v2 1/3] Documentation: KUnit: make usage.rst a superset of tips.rst, remove duplication To: Daniel Latypov Cc: brendanhiggins@google.com, davidgow@google.com, rmoar@google.com, linux-kernel@vger.kernel.org, kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, skhan@linuxfoundation.org Content-Type: text/plain; charset="UTF-8" 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, 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 Wed, Nov 9, 2022 at 6:06 AM 'Daniel Latypov' via KUnit Development wrote: > > usage.rst had most of the content of the tips.rst page copied over. > But it's missing https://www.kernel.org/doc/html/v6.0/dev-tools/kunit/tips.html#customizing-error-messages > Copy it over so we can retire tips.rst w/o losing content. > > And in that process, it also gained a duplicate section about how > KUNIT_ASSERT_*() exit the test case early. Remove that. > > Signed-off-by: Daniel Latypov > --- Thanks Daniel. This looks fine to me. Reviewed-by: Sadiya Kazi Best Regards, Sadiya > Documentation/dev-tools/kunit/usage.rst | 49 ++++++++++++++++--------- > 1 file changed, 31 insertions(+), 18 deletions(-) > > diff --git a/Documentation/dev-tools/kunit/usage.rst b/Documentation/dev-tools/kunit/usage.rst > index 2737863ef365..b0a6c3bc0eeb 100644 > --- a/Documentation/dev-tools/kunit/usage.rst > +++ b/Documentation/dev-tools/kunit/usage.rst > @@ -118,6 +118,37 @@ expectation could crash the test case. `ASSERT_NOT_ERR_OR_NULL(...)` allows us > to bail out of the test case if the appropriate conditions are not satisfied to > complete the test. > > +Customizing error messages > +-------------------------- > + > +Each of the ``KUNIT_EXPECT`` and ``KUNIT_ASSERT`` macros have a ``_MSG`` > +variant. These take a format string and arguments to provide additional > +context to the automatically generated error messages. > + > +.. code-block:: c > + > + char some_str[41]; > + generate_sha1_hex_string(some_str); > + > + /* Before. Not easy to tell why the test failed. */ > + KUNIT_EXPECT_EQ(test, strlen(some_str), 40); > + > + /* After. Now we see the offending string. */ > + KUNIT_EXPECT_EQ_MSG(test, strlen(some_str), 40, "some_str='%s'", some_str); > + > +Alternatively, one can take full control over the error message by using > +``KUNIT_FAIL()``, e.g. > + > +.. code-block:: c > + > + /* Before */ > + KUNIT_EXPECT_EQ(test, some_setup_function(), 0); > + > + /* After: full control over the failure message. */ > + if (some_setup_function()) > + KUNIT_FAIL(test, "Failed to setup thing for testing"); > + > + > Test Suites > ~~~~~~~~~~~ > > @@ -546,24 +577,6 @@ By reusing the same ``cases`` array from above, we can write the test as a > {} > }; > > -Exiting Early on Failed Expectations > ------------------------------------- > - > -We can use ``KUNIT_EXPECT_EQ`` to mark the test as failed and continue > -execution. In some cases, it is unsafe to continue. We can use the > -``KUNIT_ASSERT`` variant to exit on failure. > - > -.. code-block:: c > - > - void example_test_user_alloc_function(struct kunit *test) > - { > - void *object = alloc_some_object_for_me(); > - > - /* Make sure we got a valid pointer back. */ > - KUNIT_ASSERT_NOT_ERR_OR_NULL(test, object); > - do_something_with_object(object); > - } > - > Allocating Memory > ----------------- > > > base-commit: 6fe1ad4a156095859721fef85073df3ed43081d4 > -- > 2.38.1.431.g37b22c650d-goog > > -- > 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/msgid/kunit-dev/20221109003618.3784591-1-dlatypov%40google.com.