Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp4388591pxb; Tue, 10 Nov 2020 15:29:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJyspGkFqjsoTOJ3/ujT3mkZ3CZA4PFkgnBHDyqRmEsjxzjrvJnhMJ39ihKNI+rkAuL/WwOP X-Received: by 2002:a50:cd0a:: with SMTP id z10mr5470517edi.223.1605050984259; Tue, 10 Nov 2020 15:29:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605050984; cv=none; d=google.com; s=arc-20160816; b=JiprL23692bbU/9i7Xxd4iBHSN5yG2X5kgiEYLpO0QaJo+82c620Dt/m62Hr/7+IOw YsYVYj/1yaokT+l8Ux1NX2Ri1g9phCOyLhXgbCP9bPVumjFxuW18FAdfTXTnDDfaDv12 FhzbV/Z77tvHBbE9+kcpCHPub0Rhpb38Ki94DNGW4Mt4XZra8usmQVjpLCW5mp1JYnRO sQuRu9BB1JpQM1aGq2s7lOlY6QiD1WDQUoZ1gbCQjjwOuLAH5IUduO2TvAV72qoNCsNF M1j+1IuA/EjKdavWEaTKyY5Vad8gtuyfD+WOlidE6m4f7Q/DOYJcO5MH0+klJKugkCaE QxvA== 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=Or4R009+0xAwqncSLQ7leMAU40PnO86t6CdPE9/qh4k=; b=A0HJMLwt4CJa4N8gCNUON9QodYGw8CUFpdSHhp5g2ya5tkGheRaWlhcXQbapASfIC/ Z9TwVpxTl36xvDiFhTHYnXa1nxO9uDrQcoNo6OFKabNcEjQu9G9fGDMyF9Gx4VAyg4pw /RNCUI5tB6RgCRSC+5Wzrs3tQfolGUGGKQTDcXkkEzokvs+yVrgubgu2Y9aday+o6NAG m3UhB7DkFdNYPiNDHZwSx3JLfirIw27Zt6fgq1ifQ9JYWd9o9RfeDOCv1VqVGEeVGNtv ph9dvGnC30Ryd31RpT6Bm66GkTboiiwWqDK2I66WksEMMZHiK+e1LXtH6rZhe2r8awwL lniQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="k/ezgD1o"; 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 bd28si168539edb.329.2020.11.10.15.28.39; Tue, 10 Nov 2020 15:29:44 -0800 (PST) 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="k/ezgD1o"; 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 S1732240AbgKJX2J (ORCPT + 99 others); Tue, 10 Nov 2020 18:28:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726737AbgKJX2J (ORCPT ); Tue, 10 Nov 2020 18:28:09 -0500 Received: from mail-lf1-x142.google.com (mail-lf1-x142.google.com [IPv6:2a00:1450:4864:20::142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A536C0613D1 for ; Tue, 10 Nov 2020 15:28:05 -0800 (PST) Received: by mail-lf1-x142.google.com with SMTP id l2so631645lfk.0 for ; Tue, 10 Nov 2020 15:28:05 -0800 (PST) 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:content-transfer-encoding; bh=Or4R009+0xAwqncSLQ7leMAU40PnO86t6CdPE9/qh4k=; b=k/ezgD1o5+lqyyRN7hCLyW1xEKOHNTrZVXwF41loyBKssVhhOET5jjIhJfWfjMs7lv QdHT0tEKUZI0oIx7b/CwtdUluWv+IHZsNVB+ABWidOCCuzpEhpkjzuk3UQXjnewPl3bj unyMB60kskOiW3clwYUe4h7D7MERHxolHPSaFlIqDFG+ENasTAkeJly5JnzFZR9lGDoL f9ylzx75yHTLO61Z5S+LLkuNm8AgQ/728yCd6icXO1U5GzyyBz/V95CqO3j9NNT1g8Lm S2T1jh7116EB1g5MkjgcWsIzeC9yM9F5dvaeucEFIC/mLthOm3xDDSG7DTQWCkqX3bQJ JrMw== 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:content-transfer-encoding; bh=Or4R009+0xAwqncSLQ7leMAU40PnO86t6CdPE9/qh4k=; b=WuCQDnFqbeIiWgdGPT+7jPahOh78ILu3AwA8WLanpjbg4BwWyUFhzoQ56IPBwOVjJZ wJK+WOXMUtEUomkeVC6KBydHhpWMj5ywMoOAjkpeHQcf/3BNXSbqv0Td3G5we+h3eHkw GNr4PmnneHuV4x9+h7g5IOW+en3LZ4zNinjgDq1Jkv66l9m1HokCWVHhKbXv3NO1Pj7E NjAPefTTR+0vNWk1IGP0FiyXet0xtq+Uk1vUgreG9nSxxK2KIWeoA8GYiQdacbGHarjf xvCVMQXwkJFt3RNHOeip+cvtsuwGnX6B2CBeP/dsHzLz/WNwwNi3VmvYux7pcMK4VDby 2s4Q== X-Gm-Message-State: AOAM531nCFgGueVwaeUJ6N2Qn2rM0fNCrfYs8vEmjInakQKxYdGfYqSd RDfIJ0c7rEDUSjJVj68zHcT4SlMo43I7cVjxmd6TTA== X-Received: by 2002:ac2:59db:: with SMTP id x27mr5394024lfn.34.1605050875512; Tue, 10 Nov 2020 15:27:55 -0800 (PST) MIME-Version: 1.0 References: <20201106192154.51514-1-98.arpi@gmail.com> <47a05c5a-485d-026b-c1c3-476ed1a97856@gmail.com> In-Reply-To: From: David Gow Date: Wed, 11 Nov 2020 07:27:43 +0800 Message-ID: Subject: Re: [PATCH v6 1/2] kunit: Support for Parameterized Testing To: "Bird, Tim" Cc: Arpitha Raghunandan <98.arpi@gmail.com>, Marco Elver , Brendan Higgins , Shuah Khan , Iurii Zaikin , "Theodore Ts'o" , Andreas Dilger , "open list:KERNEL SELFTEST FRAMEWORK" , KUnit Development , Linux Kernel Mailing List , "linux-kernel-mentees@lists.linuxfoundation.org" , "linux-ext4@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Wed, Nov 11, 2020 at 1:02 AM Bird, Tim wrote: > > > > > -----Original Message----- > > From: David Gow > > > > On Mon, Nov 9, 2020 at 2:49 PM Arpitha Raghunandan <98.arpi@gmail.com> = wrote: > > > > > > On 07/11/20 3:36 pm, Marco Elver wrote: > > > > On Sat, 7 Nov 2020 at 05:58, David Gow wrote: > > > >> On Sat, Nov 7, 2020 at 3:22 AM Arpitha Raghunandan <98.arpi@gmail.= com> wrote: > > > >>> > > > >>> Implementation of support for parameterized testing in KUnit. > > > >>> This approach requires the creation of a test case using the > > > >>> KUNIT_CASE_PARAM macro that accepts a generator function as input= . > > > >>> This generator function should return the next parameter given th= e > > > >>> previous parameter in parameterized tests. It also provides > > > >>> a macro to generate common-case generators. > > > >>> > > > >>> Signed-off-by: Arpitha Raghunandan <98.arpi@gmail.com> > > > >>> Co-developed-by: Marco Elver > > > >>> Signed-off-by: Marco Elver > > > >>> --- > > > >> > > > >> This looks good to me! A couple of minor thoughts about the output > > > >> format below, but I'm quite happy to have this as-is regardless. > > > >> > > > >> Reviewed-by: David Gow > > > >> > > > >> Cheers, > > > >> -- David > > > >> > > > >>> Changes v5->v6: > > > >>> - Fix alignment to maintain consistency > > > >>> Changes v4->v5: > > > >>> - Update kernel-doc comments. > > > >>> - Use const void* for generator return and prev value types. > > > >>> - Add kernel-doc comment for KUNIT_ARRAY_PARAM. > > > >>> - Rework parameterized test case execution strategy: each paramet= er is executed > > > >>> as if it was its own test case, with its own test initializatio= n and cleanup > > > >>> (init and exit are called, etc.). However, we cannot add new te= st cases per TAP > > > >>> protocol once we have already started execution. Instead, log t= he result of > > > >>> each parameter run as a diagnostic comment. > > > >>> Changes v3->v4: > > > >>> - Rename kunit variables > > > >>> - Rename generator function helper macro > > > >>> - Add documentation for generator approach > > > >>> - Display test case name in case of failure along with param inde= x > > > >>> Changes v2->v3: > > > >>> - Modifictaion of generator macro and method > > > >>> Changes v1->v2: > > > >>> - Use of a generator method to access test case parameters > > > >>> > > > >>> include/kunit/test.h | 36 ++++++++++++++++++++++++++++++++++ > > > >>> lib/kunit/test.c | 46 +++++++++++++++++++++++++++++++-------= ------ > > > >>> 2 files changed, 69 insertions(+), 13 deletions(-) > > > >>> > > > >>> diff --git a/include/kunit/test.h b/include/kunit/test.h > > > >>> index db1b0ae666c4..16616d3974f9 100644 > > > >>> --- a/include/kunit/test.h > > > >>> +++ b/include/kunit/test.h > > > >>> @@ -107,6 +107,7 @@ struct kunit; > > > > [...] > > > >>> - kunit_suite_for_each_test_case(suite, test_case) > > > >>> - kunit_run_case_catch_errors(suite, test_case); > > > >>> + kunit_suite_for_each_test_case(suite, test_case) { > > > >>> + struct kunit test =3D { .param_value =3D NULL, .p= aram_index =3D 0 }; > > > >>> + bool test_success =3D true; > > > >>> + > > > >>> + if (test_case->generate_params) > > > >>> + test.param_value =3D test_case->generate_= params(NULL); > > > >>> + > > > >>> + do { > > > >>> + kunit_run_case_catch_errors(suite, test_c= ase, &test); > > > >>> + test_success &=3D test_case->success; > > > >>> + > > > >>> + if (test_case->generate_params) { > > > >>> + kunit_log(KERN_INFO, &test, > > > >>> + KUNIT_SUBTEST_INDENT > > > >>> + "# %s: param-%d %s", > > > >> > > > >> Would it make sense to have this imitate the TAP format a bit more= ? > > > >> So, have "# [ok|not ok] - [name]" as the format? [name] could be > > > >> something like "[test_case->name]:param-[index]" or similar. > > > >> If we keep it commented out and don't indent it further, it won't > > > >> formally be a nested test (though if we wanted to support those la= ter, > > > >> it'd be easy to add), but I think it would be nicer to be consiste= nt > > > >> here. > > > > > > > > The previous attempt [1] at something similar failed because it see= ms > > > > we'd need to teach kunit-tool new tricks [2], too. > > > > [1] https://lkml.kernel.org/r/20201105195503.GA2399621@elver.google= .com > > > > [2] https://lkml.kernel.org/r/20201106123433.GA3563235@elver.google= .com > > > > > > > > So if we go with a different format, we might need a patch before t= his > > > > one to make kunit-tool compatible with that type of diagnostic. > > > > > > > > Currently I think we have the following proposals for a format: > > > > > > > > 1. The current "# [test_case->name]: param-[index] [ok|not ok]" -- > > > > this works well, because no changes to kunit-tool are required, and= it > > > > also picks up the diagnostic context for the case and displays that= on > > > > test failure. > > > > > > > > 2. Your proposed "# [ok|not ok] - [test_case->name]:param-[index]". > > > > As-is, this needs a patch for kunit-tool as well. I just checked, a= nd > > > > if we change it to "# [ok|not ok] - [test_case->name]: param-[index= ]" > > > > (note the space after ':') it works without changing kunit-tool. ;-= ) > > > > > > > > 3. Something like "# [ok|not ok] param-[index] - [test_case->name]"= , > > > > which I had played with earlier but kunit-tool is definitely not ye= t > > > > happy with. > > > > > > > > So my current preference is (2) with the extra space (no change to > > > > kunit-tool required). WDYT? > > > > > > > > Hmm=E2=80=A6 that failure in kunit_tool is definitely a bug: we shouldn= 't care > > what comes after the comment character except if it's an explicit > > subtest declaration or a crash. I'll try to put a patch together to > > fix it, but I'd rather not delay this just for that. > > > > In any thought about this a bit more, It turns out that the proposed > > KTAP spec[1] discourages the use of ':', except as part of a subtest > > declaration, or perhaps an as-yet-unspecified fully-qualified test > > name. The latter is what I was going for, but if it's actively > > breaking kunit_tool, we might want to hold off on it. > > > > If we were to try to treat these as subtests in accordance with that > > spec, the way we'd want to use one of these options: > > A) "[ok|not ok] [index] - param-[index]" -- This doesn't mention the > > test case name, but otherwise treats things exactly the same way we > > treat existing subtests. > > > > B) "[ok|not ok] [index] - [test_case->name]" -- This doesn't name the > > "subtest", just gives repeated results with the same name. > > > > C) "[ok|not ok] [index] - [test_case->name][separator]param-[index]" > > -- This is equivalent to my suggestion with a separator of ":", or 2 > > above with a separator of ": ". The in-progress spec doesn't yet > > specify how these fully-qualified names would work, other than that > > they'd use a colon somewhere, and if we comment it out, ": " is > > required. > > > > > > > > Which format do we finally go with? > > > > > > > I'm actually going to make another wild suggestion for this, which is > > a combination of (1) and (A): > > "# [test_case->name]: [ok|not ok] [index] - param-[index]" > > I strongly object to putting actual testcase results in comments. > I'd rather that we found a way to include the parameter in the > sub-test-case name, rather than require all parsers to know about > specially-formatted comments. There are tools outside > the kernel that parse these lines. > I wasn't intending to treat these as actual testcases yet: from KUnit's point of view, they're definitely just supposed to be human-readable diagnostic comments for the one combined testcase. This largely stems from KUnit being pretty rigid in its test hierarchy: it has test suites (the root-level testcases), which contain tests (the first-level subtests). Basically, arbitrary nesting of tests isn't supported at all by any of the KUnit tools, code, documentation, etc. So, if we do actually want to treat these individual parameters as sub-subtests, it'll require a lot of work on the KUnit side to be able to parse and represent those results. So, as planned at the moment, these lines won't be parsed at all (just passed to the user), and should KUnit support more complicated test hierarchies down the line, we can remove the "# [test_case->name]" prefix, add the test plan lines, etc, and have this be picked up by parsers then. > > > > This gives us a KTAP-compliant result line, except prepended with "# > > [test_case->name]: ", which makes it formally a diagnostic line, > > rather than an actual subtest. Putting the test name at the start > > matches what kunit_tool is expecting at the moment. If we then want to > > turn it into a proper subtest, we can just get rid of that prefix (and > > add the appropriate counts elsewhere). > > > > Does that sound good? > No. > > I strongly prefer option C above: > "[ok|not ok] [index] - [test_case->name][separator]param-[index]" > > Except of course the second index is not the same as the first, so it > would be: > "[ok|not ok] [index] - [test_case->name][separator]param-[param-index]" So, the second index would be the same as the first (at most with an off-by-one to account for different indexing if we wished) in what I was thinking. I think this boils down to how we treat these tests and parameters: - There is one TAP/KUnit test per-parameter, probably with a name like "test_case:param-n". There's no "container" test. - There is a test and result for the whole test, and per-parameter tests and results are nested in that as subtests. - There is a single test, and any per-parameter information is simply diagnostic data for the one test, not to be parsed. The current code follows the last of these options, and it was my view that by having that diagnostic data be in a similar format to a test result line, it'd be easier to convert this to the second option while having a familiar format for people reading the results manually. Only the first option should need separate indices for the result and the parameter. > If ':' is problematical as a separator, let's choose something else. > What are the allowed and disallowed characters in the testcase name now? > How bad would it be to use something like % or &? > > Unless the separator is #, I think most parsers are going to just treat t= he whole > string from after the '[index] -' to a following '#' as a testcase name, = and it > should get parsed (and presented) OK. I'm not sure what kunit_tool's prob= lem is. > kunit_tool has a bug when parsing the comments / diagnostic lines, which requires a ": " to be present. This is a bug, which is being fixed[1], so while it's _nice_ to not trigger it, it's not really an important long-term goal of the format. In any case, this kunit_tool issue only affects the comment lines: if the per-parameter result line is an actual result, rather than just a diagnostic, this shouldn't be a problem. In any case, I still prefer my proposed option for now -- noting that these per-parameter results are not actually supposed to be parsed -- with then the possibility of expanding them to actual nested results later should we wish. But if the idea of having TAP-like lines in diagnostics seems too dangerous (e.g. because people will try to parse them anyway), then I think the options we have are to stick to the output format given in the current version of this patch (which doesn't resemble a TAP result), make each parameterised version its own test (without a "container test", which would require a bit of extra work while computing test plans), or to hold this whole feature back until we can support arbitrary test hierarchies in KUnit. Personally, I'd rather not hold this feature back, and prefer to have a single combined result available, so would just stick with v6 if so... Does that make sense? Cheers, -- David