Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp1058936pxx; Tue, 27 Oct 2020 07:21:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxWy92QHnxEIiY5+iHEha/FWX9S91g4+4jCYU0tNsxkpvlwh9NB6859w2ShLLt58vBoEm+t X-Received: by 2002:a50:f785:: with SMTP id h5mr2407441edn.249.1603808470013; Tue, 27 Oct 2020 07:21:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603808470; cv=none; d=google.com; s=arc-20160816; b=cnzDFU2NuSjU/tdw040o1chKCGn+c5iKFCR3sLkcUKNBOSKF9pgz3xkHpGyloohu08 Jj6E5BGIFzgrJJFT30uAUb9+cQodff0HfyS+3UG9c7H9ulpAm4VVEPjRFYQgTTbkIGQB RM1OmzNtvgiBFuEVh3lAgLMsHLR41ZfquR4NMmJW7jTI6TBJTQsOClQ2I7//oCznduCe BDDQya6w8ysxQupCQmnvyYn/78qqiPilek40MYNSnrs2QBhZs/UnG/cdvoNLx2ck8BCx Z0Xlj0A9hw2ZawfEojIsM3F4NIsKTTHY8JYdJOz/Xz3YEjwqKIXKzGXTPA+nzdO/nM7d ihHQ== 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=mMR/HImx8HeIWOB1IW4d4ooUwHbJnSc4ChopXkol+tY=; b=mGpj6L3BUcyayFVGa3QZaGj703i6g7Fqput75jbspFKJ2I5fb80W88L4mnF1484hLH upxvTXI0aW5BixfANT1Z8c/S8jszl/aF0NI8H8nLwcToDEA83L9vpMIokYfC1CPow4lN FDhCHVwYwzJzsWOcJjK3Hq4z1N2d7arhLV0m1QnG4jonCoG1YW48teJvon1XIsLLPv4p njBeULX/RXFTfRgLMREI7v1oMGpu+Y/O2XTN54wPbrz5wrbIdAT7qsL9iZ5KzOb4EBZH 9iK+9jAag2qY/j/rRptwtEpWcRiG3kHGx8ZjcRfVvs9WfoQTUQNpuiEE8Ilh2I1Abzj7 hJOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Xg2AvIHd; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qq21si1052484ejb.11.2020.10.27.07.20.45; Tue, 27 Oct 2020 07:21:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Xg2AvIHd; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-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 S2895298AbgJ0JD5 (ORCPT + 99 others); Tue, 27 Oct 2020 05:03:57 -0400 Received: from mail-ot1-f66.google.com ([209.85.210.66]:38203 "EHLO mail-ot1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2895296AbgJ0JD4 (ORCPT ); Tue, 27 Oct 2020 05:03:56 -0400 Received: by mail-ot1-f66.google.com with SMTP id b2so494747ots.5 for ; Tue, 27 Oct 2020 02:03:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=mMR/HImx8HeIWOB1IW4d4ooUwHbJnSc4ChopXkol+tY=; b=Xg2AvIHdQY3taxJqct+JFiPWoBWewED7SFBkf4BNfR8mWwmjMyETCb7JSxfSEs0hPf rbB3JqF2ytHB7sdY7A0nMedrzTQKTen4NmuBvIyzFus5llPQA6pXSCAMQ6+FEMJnwbUL PzDkMEmWnJC0dpKvP6NgS3wIU8J9wM0m/dPRroMHL7iVwBQl+PQAGqm0EpGAahxKp7IT 3lZ7zIO+ZPxfVkt6qx7UGfvOKrzzXSobfGAmI3qvkLKVUx5TeFmMPl7c6SP19c22VBea TxQrpdjd1oQGrZUd8t3wEaghVw5V369fiJkpMO3fMWc+z2zqZvioeorot5DL4qZrwbz7 6Q5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=mMR/HImx8HeIWOB1IW4d4ooUwHbJnSc4ChopXkol+tY=; b=e0KAadNOM08vRcd8CMbWyhGYPNnK2Rs5B/mdjuQhCusJhOiNo5j+T27/UC0KPWd5Gp +dY2lD9mgkLUZetJ7hd70x70Q3Xx0bBqDDYCCa6C5+OdZXV5nnXD+ts9sMCIlHBRwb3r 1etXKkz3rtDGcxHluMU2tCv8f+aM22OlI06PzPncph4iUKuV4MchbxXcpEzqSDXri+XI whilo7klOB2Io1CTAOuwmh5mT6FXBkD/leQc+PZaUVCKCCKpkK9oUMJMZixgn4hhTtaC 1Viy+M2WPZEGc7CfCVE5jqug6tLlBCVxSm/jGKnFVbycHv/qwqhi5I45+oic+pFYI9fF bDpg== X-Gm-Message-State: AOAM5331ls8asLQXxUrBGDhczMbXbU5wi3t6QPLuqY+Ui40M1x/zt2AD 74CBDtOvWME2cNuYjxe2XQzcYaWu1iC0Kf2+2E2yKg== X-Received: by 2002:a9d:3a65:: with SMTP id j92mr811798otc.17.1603789435179; Tue, 27 Oct 2020 02:03:55 -0700 (PDT) MIME-Version: 1.0 References: <20201026183523.82749-1-98.arpi@gmail.com> In-Reply-To: <20201026183523.82749-1-98.arpi@gmail.com> From: Marco Elver Date: Tue, 27 Oct 2020 10:03:43 +0100 Message-ID: Subject: Re: [PATCH v3 1/2] kunit: Support for Parameterized Testing To: Arpitha Raghunandan <98.arpi@gmail.com> Cc: Brendan Higgins , skhan@linuxfoundation.org, Iurii Zaikin , "Theodore Ts'o" , Andreas Dilger , "open list:KERNEL SELFTEST FRAMEWORK" , KUnit Development , LKML , linux-kernel-mentees@lists.linuxfoundation.org, linux-ext4@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org I just tried to give this a spin on some of my tests and noticed some more things (apologies for the multiple rounds of comments): On Mon, 26 Oct 2020 at 19:36, Arpitha Raghunandan <98.arpi@gmail.com> wrote: [...] > /** > * struct kunit_suite - describes a related collection of &struct kunit_case > @@ -208,6 +217,15 @@ struct kunit { > const char *name; /* Read only after initialization! */ > char *log; /* Points at case log after initialization */ > struct kunit_try_catch try_catch; > + /* param_values points to test case parameters in parameterized tests */ > + void *param_values; This should be singular, i.e. "param_value", since the generator only generates 1 value for each test. Whether or not that value is a pointer that points to more than 1 value or is an integer etc. is entirely test-dependent. > + /* > + * current_param stores the index of the parameter in > + * the array of parameters in parameterized tests. > + * current_param + 1 is printed to indicate the parameter > + * that causes the test to fail in case of test failure. > + */ > + int current_param; I think, per your comment above, this should be named "param_index". Also, I would suggest removing the mention of "array" in the comment, because the parameters aren't dependent on use of an array. > /* > * success starts as true, and may only be set to false during a > * test case; thus, it is safe to update this across multiple > @@ -1742,4 +1760,18 @@ do { \ > fmt, \ > ##__VA_ARGS__) > > +/** > + * KUNIT_PARAM_GENERATOR() - Helper method for test parameter generators > + * required in parameterized tests. > + * @name: prefix of the name for the test parameter generator function. > + * @prev: a pointer to the previous test parameter, NULL for first parameter. > + * @array: a user-supplied pointer to an array of test parameters. > + */ > +#define KUNIT_PARAM_GENERATOR(name, array) \ > + static void *name##_gen_params(void *prev) \ > + { \ > + typeof((array)[0]) * __next = prev ? ((typeof(__next)) prev) + 1 : (array); \ > + return __next - (array) < ARRAY_SIZE((array)) ? __next : NULL; \ > + } > + > #endif /* _KUNIT_TEST_H */ > diff --git a/lib/kunit/test.c b/lib/kunit/test.c > index 750704abe89a..b70ab9b12f3b 100644 > --- a/lib/kunit/test.c > +++ b/lib/kunit/test.c > @@ -127,6 +127,11 @@ unsigned int kunit_test_case_num(struct kunit_suite *suite, > } > EXPORT_SYMBOL_GPL(kunit_test_case_num); > > +static void kunit_print_failed_param(struct kunit *test) > +{ > + kunit_err(test, "\n\tTest failed at parameter: %d\n", test->current_param + 1); > +} Is this the only place where the param index is used? It might be helpful to show the index together with the test-case name, otherwise we get a series of test cases in the output which are all named the same which can be confusing. > static void kunit_print_string_stream(struct kunit *test, > struct string_stream *stream) > { > @@ -168,6 +173,8 @@ static void kunit_fail(struct kunit *test, struct kunit_assert *assert) > assert->format(assert, stream); > > kunit_print_string_stream(test, stream); > + if (test->param_values) > + kunit_print_failed_param(test); > > WARN_ON(string_stream_destroy(stream)); > } > @@ -239,7 +246,18 @@ static void kunit_run_case_internal(struct kunit *test, > } > } > > - test_case->run_case(test); > + if (!test_case->generate_params) { > + test_case->run_case(test); > + } else { > + test->param_values = test_case->generate_params(NULL); > + test->current_param = 0; > + > + while (test->param_values) { > + test_case->run_case(test); > + test->param_values = test_case->generate_params(test->param_values); > + test->current_param++; > + } > + } > } Looking forward to v4. :-) Thanks, -- Marco