Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp2344473pxb; Sun, 15 Nov 2020 01:01:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJw2ykX8EB3U+xhUT+KeghghdtmhWWWQFDY7EYiYB36KgLYIO/sHr5PqVlDIHc75W00tzJ8W X-Received: by 2002:a17:906:3a55:: with SMTP id a21mr9469274ejf.357.1605430906731; Sun, 15 Nov 2020 01:01:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605430906; cv=none; d=google.com; s=arc-20160816; b=JmbduCARCDT6HuPS/Pghp0zNUQqCleVA0sFFeMfbbruFvqpNRzlh/dxCS1+vP9bTiA AyfH88Cx7kJPw908pzx5XPd6A2QP7ltqcr49Xb292+6lqvVu6eIyqnVFB4a+gYuKvq5f YTBlPj0jxUMvj0ApCpdlF4O7tUdYu4hkKTTiM9TpoBCYybvwqB/Fjn0QyqeQ3xZ5nbz+ bsF0mzs9V6grdPdP71XzBj/tPES5LFuM/t0Z4RIABUOme0EifJ8OVrByZNFU6LWrhxCH aq9xfebfiZl0RYG1fVX5Zrdv2wtbxIJpjXXVMYSceRPHq/1Cf9a8GgGQbBIZNNEUlDP0 +61A== 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=eOfon08D4Z8QqvBeUPGRpAKg2puT4+gjjSEjZd3iW9U=; b=FvaaCQDpwBqQblh9OAPa/Xfvl/ztTvhhjVXp0wGoTslWi0YiGLj/cIDXLQoG5UF0nQ PtNC+uXW15+Uh9SBtxYfyVooBEz3WZCR+JaYQ5czsdFC9Vk600EQ9i0uUPWUe9IbKYg6 94TipkmfyR1Y6NtN4m0OgrVLkMQRGdZGrnW9Ou/hKVmJSGzwzXzhMICncB7jt2oaLR8Y Et3SEa97jq/wLpNe6stbEli8/SUQ+mVOfP8Z8IqflECW6R2vAtZkKjiw15tfwAXA6KCS d8p/GEc5OhkmoXPvP7HENKLQxhGo3Kaf67YwVyb/R5h4udoIMNXDZKrSFNK9LXS73SLf y6ZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=wKSPTVfF; 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 hr31si9410916ejc.233.2020.11.15.01.01.13; Sun, 15 Nov 2020 01:01:46 -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=wKSPTVfF; 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 S1726855AbgKOI6v (ORCPT + 99 others); Sun, 15 Nov 2020 03:58:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726483AbgKOI6d (ORCPT ); Sun, 15 Nov 2020 03:58:33 -0500 Received: from mail-ot1-x344.google.com (mail-ot1-x344.google.com [IPv6:2607:f8b0:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68FF6C0613D1 for ; Sun, 15 Nov 2020 00:58:33 -0800 (PST) Received: by mail-ot1-x344.google.com with SMTP id j14so12989246ots.1 for ; Sun, 15 Nov 2020 00:58:33 -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; bh=eOfon08D4Z8QqvBeUPGRpAKg2puT4+gjjSEjZd3iW9U=; b=wKSPTVfFPmI7y0+3EK74LC5ZHIYhP+UsyUVeT4mOjbN3rjOPwenhkD76d8kMEmEwTU fZ9IU5vPB0KFoFeB5wj8Kwb1ZgcDdj0IIMztyZkcDYdQJ6bGROofOV56xq3/Zf9U6kp9 WFrdoQ05yQLtZcgF7N0+cn02+xpeEtjRitJCPap8GmhYRoJIJ/QBfIGxMQLpEMwsTu7e DGMUk1Qc1Q8WXsdtBli++0Z27BrxaduSAculqD4fx8QQRvN1Uw2zvzK6A/9qkiyMXRxo 0axZhijITMHaydwtu9To8uf/nfQhFCmp/+DyEVZCkAGfC9xva7++5Z7zOY8NecyA+rxt M+/g== 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=eOfon08D4Z8QqvBeUPGRpAKg2puT4+gjjSEjZd3iW9U=; b=SLJC8y8QoInnHFvxneHfrrhFJ7IpMylC+rjvFOVycGgLLutgPEPkAqmOrFjyyHk8BZ diK0pMdrWL3y9821YVynFOYSddg8Vp2kYzdduyJdALNZWS7dBtk4kNCQY1/LbdEt1/3r Ex9p/IQDTUGH/s+hrzwgD3TkiibneBL+qBOe8s8aRgXZf+Cxh0x9E6lu1SgtkSolV2f2 /1QsXY/kXtIxiXxr0NePSaB+Jo7C2CfOw/YQ6nWdMO8C+/VFrYZmtKuy6BZWig0722LK rZrcbmL59VdyY/Q9+Kv3eX1grTdErz2+ROxwRekwGWi4S8Fv4NEq6VZ1Tmie5rWI4xiW XlRA== X-Gm-Message-State: AOAM530s9HKAGmFR9E/CUuu4RdZWAjQ2kEDN5NYkProRlHCH1gSiUdmX boxmi98OgwjakugGlXIv8ug9x5nMQsDJmsw3oLXXgg== X-Received: by 2002:a9d:65d5:: with SMTP id z21mr6656603oth.251.1605430712516; Sun, 15 Nov 2020 00:58:32 -0800 (PST) MIME-Version: 1.0 References: <20201114123648.97857-1-98.arpi@gmail.com> In-Reply-To: <20201114123648.97857-1-98.arpi@gmail.com> From: Marco Elver Date: Sun, 15 Nov 2020 09:58:21 +0100 Message-ID: Subject: Re: [PATCH v7 1/2] kunit: Support for Parameterized Testing To: Arpitha Raghunandan <98.arpi@gmail.com> Cc: Brendan Higgins , Shuah Khan , Iurii Zaikin , "Theodore Ts'o" , Andreas Dilger , Tim Bird , David Gow , "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 On Sat, 14 Nov 2020 at 13:38, 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 the > previous parameter in parameterized tests. It also provides a macro to > generate common-case generators based on arrays. Generators may also > optionally provide a human-readable description of parameters, which is > displayed where available. > > Note, currently the result of each parameter run is displayed in > diagnostic lines, and only the overall test case output summarizes > TAP-compliant success or failure of all parameter runs. In future, when > supported by kunit-tool, these can be turned into subsubtest outputs. > > Signed-off-by: Arpitha Raghunandan <98.arpi@gmail.com> > Co-developed-by: Marco Elver > Signed-off-by: Marco Elver > --- > Changes v6->v7: > - Clarify commit message. > - Introduce ability to optionally generate descriptions for parameters; > if no description is provided, we'll still print 'param-N'. > - Change diagnostic line format to: > # : N - [] > > 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 parameter is executed > as if it was its own test case, with its own test initialization and cleanup > (init and exit are called, etc.). However, we cannot add new test cases per TAP > protocol once we have already started execution. Instead, log the 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 index > > Changes v2->v3: > - Modifictaion of generator macro and method > > Changes v1->v2: > - Use of a generator method to access test case parameters > Changes v6->v7: > - Clarify commit message. > - Introduce ability to optionally generate descriptions for parameters; > if no description is provided, we'll still print 'param-N'. > - Change diagnostic line format to: > # : N - [] > - Before execution of parameterized test case, count number of > parameters and display number of parameters. Currently also as a > diagnostic line, but this may be used in future to generate a subsubtest > plan. A requirement of this change is that generators must generate a > deterministic number of parameters. > > 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 parameter is executed > as if it was its own test case, with its own test initialization and cleanup > (init and exit are called, etc.). However, we cannot add new test cases per TAP > protocol once we have already started execution. Instead, log the 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 index > > 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 | 51 ++++++++++++++++++++++++++++++++++++++ > lib/kunit/test.c | 59 ++++++++++++++++++++++++++++++++++---------- > 2 files changed, 97 insertions(+), 13 deletions(-) > > diff --git a/include/kunit/test.h b/include/kunit/test.h > index db1b0ae666c4..cf5f33b1c890 100644 > --- a/include/kunit/test.h > +++ b/include/kunit/test.h > @@ -94,6 +94,9 @@ struct kunit; > /* Size of log associated with test. */ > #define KUNIT_LOG_SIZE 512 > > +/* Maximum size of parameter description string. */ > +#define KUNIT_PARAM_DESC_SIZE 64 I think we need to make this larger, perhaps 128. I just noticed a few of the inode-test strings are >64 chars (and it should probably also use strncpy() to copy to description, which is my bad). > /* > * TAP specifies subtest stream indentation of 4 spaces, 8 spaces for a > * sub-subtest. See the "Subtests" section in > @@ -107,6 +110,7 @@ struct kunit; [...] > +/** > + * KUNIT_ARRAY_PARAM() - Define test parameter generator from an array. > + * @name: prefix for the test parameter generator function. > + * @array: array of test parameters. > + * @get_desc: function to convert param to description; NULL to use default > + * > + * Define function @name_gen_params which uses @array to generate parameters. > + */ > +#define KUNIT_ARRAY_PARAM(name, array, get_desc) \ > + static const void *name##_gen_params(const void *prev, char *desc) \ > + { \ > + typeof((array)[0]) * __next = prev ? ((typeof(__next)) prev) + 1 : (array); \ Why did you reintroduce a space between * and __next? AFAIK, this should follow the same style as the rest of the kernel, and it should just be 'thetype *ptr'. > + if (__next - (array) < ARRAY_SIZE((array))) { \ > + void (*__get_desc)(typeof(__next), char *) = get_desc; \ > + if (__get_desc) \ > + __get_desc(__next, desc); \ > + return __next; \ > + } \ > + return NULL; \ > + } > + Thanks, -- Marco