Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp2936298pxb; Mon, 16 Nov 2020 00:52:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJzyt9ZfJ//MuzR5rSTtAVFK3SWk8tTjhK3jPKqzR2c1d7R2cS4vcX/HOWxHmBSO6XYG42vs X-Received: by 2002:aa7:cd9a:: with SMTP id x26mr14801551edv.226.1605516748049; Mon, 16 Nov 2020 00:52:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605516748; cv=none; d=google.com; s=arc-20160816; b=MwGHychmoPhr/a58RC398vjTOsVq9bcxHf+Eejde2hwz4TPrsSREWiL+u4vYyu9uX0 9wMtJyZUQVU4QgWy3ISLm77Ajv9c0ZUUeqKFXVstAkkbgvHQoeELB1cIA93B8qizsSj8 mjIG6EVYlNVTHjTXWwJZb5R8SR0ZZUr8j10Ld8wHVz9SYLkaxr8rpFdZdjz5L0kf++p0 C2W6BpjaecJkW1TChmTx1uuGwV5hRVyUI8rT5wry02VBy77Wd9/UII5RBDqTEzumrSah UyUUXoW1t7kldbZycUzQkgGOkc2zyQNgFDYtB8+V/9soGDEDUTSs/1nyH2cXFkP2rgok p3rA== 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=zy986Vg7ccKVkvtXBhD6NQzZqFrJZe4eCvqprIanDG0=; b=Q5oWL2oyBh7+f17WDbJkw0K/bqHWtqOO4k1gUYRDFpszLRm+1Y1pJph1l6Z/FxstME FnzivvgCYv2FaFeYROlXiby11eGIlDB+nFfiqzz6onkc3cqPe3CWXrjRl8bAilBn02BC l6PF/gV3Op9Tjao6hJQL1By02UsNgrcpqTIDOhFExrWOy2VKSZd2KdKoTyzcUpOGYdra 5T66SzV9Mwy3Ev+WGhZ/gOp8/Gz7CZ4yQOADrwKEf8nSshrw/Gx7Qe4XGktEAKuhfw4d VQQDPJrxlWymnSGaDptGlN06qdG+62SHEA/7U/BnMV2/4AEVVzYuK0LA5biXa5X0b8ou 5NKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=JuvqGj0C; 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 lj26si10139416ejb.663.2020.11.16.00.51.55; Mon, 16 Nov 2020 00:52:28 -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=JuvqGj0C; 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 S1728211AbgKPIvX (ORCPT + 99 others); Mon, 16 Nov 2020 03:51:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726455AbgKPIvX (ORCPT ); Mon, 16 Nov 2020 03:51:23 -0500 Received: from mail-ot1-x342.google.com (mail-ot1-x342.google.com [IPv6:2607:f8b0:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 149FBC0613D2 for ; Mon, 16 Nov 2020 00:51:23 -0800 (PST) Received: by mail-ot1-x342.google.com with SMTP id l36so15266546ota.4 for ; Mon, 16 Nov 2020 00:51:23 -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=zy986Vg7ccKVkvtXBhD6NQzZqFrJZe4eCvqprIanDG0=; b=JuvqGj0Cq1pYlbEVb8edLk08OVHo7+rEVlDBsptQd/hn5A8VD/z31ibnpUBhIXBNyL HNn5+9FdCObQmigZ8uLvav50NVbvNFRC9O19XcnaaQqx1+IsxlVooo0JWWdicnHqYRPd O60q+ykj3LZ1M/DUSjYmpfDTQr+ajOpoW9PNSgIeVpJv48KSMcsCiCzBVI9kawoz/XGV efmNAyL8UwvR80V6O7jmT5CSBeE1faIXkrdFvIzk/976avizYp9YzCKo2ZC8pZHhejST 98BPsM/MmUhowaR9HpLQR3CnEiQsneuUs5uVHinz9LXv77QUPRbvQ8iXfL590xZxITDa QMuA== 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=zy986Vg7ccKVkvtXBhD6NQzZqFrJZe4eCvqprIanDG0=; b=HbK2sQ23rXRtz5M4O1k1ULwTtFCBNxH3tk4FR+Xs0SU/k18k+XWXQNZW2ZkHCKUqQ7 r84yipUem8dtDjM9Zcazjl4fns8WFSA8x3XvrosX8Nq/1nyLiSPjBa1yy3bgoxl/SXsb eOD+e/JWhymuT4/EWqjNeAoIZKNbgIR1npYpSA7LeFc0crB1M37B04z87HhIcanEtoWG Js/l4R9yILmQhlYWDCw9MtFotp/HxylmhyAP0Fl5rEw6Q0QfZfsAiPXy9aE8N80XtOTX XPFGhS4p2ZYCwscRatdsoSvSfeUFdAR7+Js4Dy8GSmw/15wl7qTXtRQ4AGknIPoEaW66 Jyew== X-Gm-Message-State: AOAM5327f3yEdiFIwlc5tcl+0TTeY6QXcOtkYvz6owLX4YkA1b82nzUk xFzEg2Y4s3715MSQ/rkH8j7YeLyUWR3ISd2BNyH/Fg== X-Received: by 2002:a9d:65d5:: with SMTP id z21mr9315212oth.251.1605516682127; Mon, 16 Nov 2020 00:51:22 -0800 (PST) MIME-Version: 1.0 References: <20201116054035.211498-1-98.arpi@gmail.com> <20201116054150.211562-1-98.arpi@gmail.com> In-Reply-To: <20201116054150.211562-1-98.arpi@gmail.com> From: Marco Elver Date: Mon, 16 Nov 2020 09:51:10 +0100 Message-ID: Subject: Re: [PATCH v9 2/2] fs: ext4: Modify inode-test.c to use KUnit parameterized testing feature 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 Mon, 16 Nov 2020 at 06:42, Arpitha Raghunandan <98.arpi@gmail.com> wrote: > > Modify fs/ext4/inode-test.c to use the parameterized testing > feature of KUnit. > > Signed-off-by: Arpitha Raghunandan <98.arpi@gmail.com> > Signed-off-by: Marco Elver Reviewed-by: Marco Elver Thank you! > --- > Changes v8->v9: > - Replace strncpy() with strscpy() in timestamp_expectation_to_desc() > Changes v7->v8: > - Replace strcpy() with strncpy() in timestamp_expectation_to_desc() > Changes v6->v7: > - Introduce timestamp_expectation_to_desc() to convert param to > description. > Changes v5->v6: > - No change to this patch of the patch series > Changes v4->v5: > - No change to this patch of the patch series > Changes v3->v4: > - Modification based on latest implementation of KUnit parameterized testing > Changes v2->v3: > - Marked hardcoded test data const > - Modification based on latest implementation of KUnit parameterized testing > Changes v1->v2: > - Modification based on latest implementation of KUnit parameterized testing > > fs/ext4/inode-test.c | 320 ++++++++++++++++++++++--------------------- > 1 file changed, 164 insertions(+), 156 deletions(-) > > diff --git a/fs/ext4/inode-test.c b/fs/ext4/inode-test.c > index d62d802c9c12..7935ea6cf92c 100644 > --- a/fs/ext4/inode-test.c > +++ b/fs/ext4/inode-test.c > @@ -80,6 +80,145 @@ struct timestamp_expectation { > bool lower_bound; > }; > > +static const struct timestamp_expectation test_data[] = { > + { > + .test_case_name = LOWER_BOUND_NEG_NO_EXTRA_BITS_CASE, > + .msb_set = true, > + .lower_bound = true, > + .extra_bits = 0, > + .expected = {.tv_sec = -0x80000000LL, .tv_nsec = 0L}, > + }, > + > + { > + .test_case_name = UPPER_BOUND_NEG_NO_EXTRA_BITS_CASE, > + .msb_set = true, > + .lower_bound = false, > + .extra_bits = 0, > + .expected = {.tv_sec = -1LL, .tv_nsec = 0L}, > + }, > + > + { > + .test_case_name = LOWER_BOUND_NONNEG_NO_EXTRA_BITS_CASE, > + .msb_set = false, > + .lower_bound = true, > + .extra_bits = 0, > + .expected = {0LL, 0L}, > + }, > + > + { > + .test_case_name = UPPER_BOUND_NONNEG_NO_EXTRA_BITS_CASE, > + .msb_set = false, > + .lower_bound = false, > + .extra_bits = 0, > + .expected = {.tv_sec = 0x7fffffffLL, .tv_nsec = 0L}, > + }, > + > + { > + .test_case_name = LOWER_BOUND_NEG_LO_1_CASE, > + .msb_set = true, > + .lower_bound = true, > + .extra_bits = 1, > + .expected = {.tv_sec = 0x80000000LL, .tv_nsec = 0L}, > + }, > + > + { > + .test_case_name = UPPER_BOUND_NEG_LO_1_CASE, > + .msb_set = true, > + .lower_bound = false, > + .extra_bits = 1, > + .expected = {.tv_sec = 0xffffffffLL, .tv_nsec = 0L}, > + }, > + > + { > + .test_case_name = LOWER_BOUND_NONNEG_LO_1_CASE, > + .msb_set = false, > + .lower_bound = true, > + .extra_bits = 1, > + .expected = {.tv_sec = 0x100000000LL, .tv_nsec = 0L}, > + }, > + > + { > + .test_case_name = UPPER_BOUND_NONNEG_LO_1_CASE, > + .msb_set = false, > + .lower_bound = false, > + .extra_bits = 1, > + .expected = {.tv_sec = 0x17fffffffLL, .tv_nsec = 0L}, > + }, > + > + { > + .test_case_name = LOWER_BOUND_NEG_HI_1_CASE, > + .msb_set = true, > + .lower_bound = true, > + .extra_bits = 2, > + .expected = {.tv_sec = 0x180000000LL, .tv_nsec = 0L}, > + }, > + > + { > + .test_case_name = UPPER_BOUND_NEG_HI_1_CASE, > + .msb_set = true, > + .lower_bound = false, > + .extra_bits = 2, > + .expected = {.tv_sec = 0x1ffffffffLL, .tv_nsec = 0L}, > + }, > + > + { > + .test_case_name = LOWER_BOUND_NONNEG_HI_1_CASE, > + .msb_set = false, > + .lower_bound = true, > + .extra_bits = 2, > + .expected = {.tv_sec = 0x200000000LL, .tv_nsec = 0L}, > + }, > + > + { > + .test_case_name = UPPER_BOUND_NONNEG_HI_1_CASE, > + .msb_set = false, > + .lower_bound = false, > + .extra_bits = 2, > + .expected = {.tv_sec = 0x27fffffffLL, .tv_nsec = 0L}, > + }, > + > + { > + .test_case_name = UPPER_BOUND_NONNEG_HI_1_NS_1_CASE, > + .msb_set = false, > + .lower_bound = false, > + .extra_bits = 6, > + .expected = {.tv_sec = 0x27fffffffLL, .tv_nsec = 1L}, > + }, > + > + { > + .test_case_name = LOWER_BOUND_NONNEG_HI_1_NS_MAX_CASE, > + .msb_set = false, > + .lower_bound = true, > + .extra_bits = 0xFFFFFFFF, > + .expected = {.tv_sec = 0x300000000LL, > + .tv_nsec = MAX_NANOSECONDS}, > + }, > + > + { > + .test_case_name = LOWER_BOUND_NONNEG_EXTRA_BITS_1_CASE, > + .msb_set = false, > + .lower_bound = true, > + .extra_bits = 3, > + .expected = {.tv_sec = 0x300000000LL, .tv_nsec = 0L}, > + }, > + > + { > + .test_case_name = UPPER_BOUND_NONNEG_EXTRA_BITS_1_CASE, > + .msb_set = false, > + .lower_bound = false, > + .extra_bits = 3, > + .expected = {.tv_sec = 0x37fffffffLL, .tv_nsec = 0L}, > + } > +}; > + > +static void timestamp_expectation_to_desc(const struct timestamp_expectation *t, > + char *desc) > +{ > + strscpy(desc, t->test_case_name, KUNIT_PARAM_DESC_SIZE); > +} > + > +KUNIT_ARRAY_PARAM(ext4_inode, test_data, timestamp_expectation_to_desc); > + > static time64_t get_32bit_time(const struct timestamp_expectation * const test) > { > if (test->msb_set) { > @@ -101,166 +240,35 @@ static time64_t get_32bit_time(const struct timestamp_expectation * const test) > */ > static void inode_test_xtimestamp_decoding(struct kunit *test) > { > - const struct timestamp_expectation test_data[] = { > - { > - .test_case_name = LOWER_BOUND_NEG_NO_EXTRA_BITS_CASE, > - .msb_set = true, > - .lower_bound = true, > - .extra_bits = 0, > - .expected = {.tv_sec = -0x80000000LL, .tv_nsec = 0L}, > - }, > - > - { > - .test_case_name = UPPER_BOUND_NEG_NO_EXTRA_BITS_CASE, > - .msb_set = true, > - .lower_bound = false, > - .extra_bits = 0, > - .expected = {.tv_sec = -1LL, .tv_nsec = 0L}, > - }, > - > - { > - .test_case_name = LOWER_BOUND_NONNEG_NO_EXTRA_BITS_CASE, > - .msb_set = false, > - .lower_bound = true, > - .extra_bits = 0, > - .expected = {0LL, 0L}, > - }, > - > - { > - .test_case_name = UPPER_BOUND_NONNEG_NO_EXTRA_BITS_CASE, > - .msb_set = false, > - .lower_bound = false, > - .extra_bits = 0, > - .expected = {.tv_sec = 0x7fffffffLL, .tv_nsec = 0L}, > - }, > - > - { > - .test_case_name = LOWER_BOUND_NEG_LO_1_CASE, > - .msb_set = true, > - .lower_bound = true, > - .extra_bits = 1, > - .expected = {.tv_sec = 0x80000000LL, .tv_nsec = 0L}, > - }, > - > - { > - .test_case_name = UPPER_BOUND_NEG_LO_1_CASE, > - .msb_set = true, > - .lower_bound = false, > - .extra_bits = 1, > - .expected = {.tv_sec = 0xffffffffLL, .tv_nsec = 0L}, > - }, > - > - { > - .test_case_name = LOWER_BOUND_NONNEG_LO_1_CASE, > - .msb_set = false, > - .lower_bound = true, > - .extra_bits = 1, > - .expected = {.tv_sec = 0x100000000LL, .tv_nsec = 0L}, > - }, > - > - { > - .test_case_name = UPPER_BOUND_NONNEG_LO_1_CASE, > - .msb_set = false, > - .lower_bound = false, > - .extra_bits = 1, > - .expected = {.tv_sec = 0x17fffffffLL, .tv_nsec = 0L}, > - }, > - > - { > - .test_case_name = LOWER_BOUND_NEG_HI_1_CASE, > - .msb_set = true, > - .lower_bound = true, > - .extra_bits = 2, > - .expected = {.tv_sec = 0x180000000LL, .tv_nsec = 0L}, > - }, > - > - { > - .test_case_name = UPPER_BOUND_NEG_HI_1_CASE, > - .msb_set = true, > - .lower_bound = false, > - .extra_bits = 2, > - .expected = {.tv_sec = 0x1ffffffffLL, .tv_nsec = 0L}, > - }, > - > - { > - .test_case_name = LOWER_BOUND_NONNEG_HI_1_CASE, > - .msb_set = false, > - .lower_bound = true, > - .extra_bits = 2, > - .expected = {.tv_sec = 0x200000000LL, .tv_nsec = 0L}, > - }, > - > - { > - .test_case_name = UPPER_BOUND_NONNEG_HI_1_CASE, > - .msb_set = false, > - .lower_bound = false, > - .extra_bits = 2, > - .expected = {.tv_sec = 0x27fffffffLL, .tv_nsec = 0L}, > - }, > - > - { > - .test_case_name = UPPER_BOUND_NONNEG_HI_1_NS_1_CASE, > - .msb_set = false, > - .lower_bound = false, > - .extra_bits = 6, > - .expected = {.tv_sec = 0x27fffffffLL, .tv_nsec = 1L}, > - }, > - > - { > - .test_case_name = LOWER_BOUND_NONNEG_HI_1_NS_MAX_CASE, > - .msb_set = false, > - .lower_bound = true, > - .extra_bits = 0xFFFFFFFF, > - .expected = {.tv_sec = 0x300000000LL, > - .tv_nsec = MAX_NANOSECONDS}, > - }, > - > - { > - .test_case_name = LOWER_BOUND_NONNEG_EXTRA_BITS_1_CASE, > - .msb_set = false, > - .lower_bound = true, > - .extra_bits = 3, > - .expected = {.tv_sec = 0x300000000LL, .tv_nsec = 0L}, > - }, > - > - { > - .test_case_name = UPPER_BOUND_NONNEG_EXTRA_BITS_1_CASE, > - .msb_set = false, > - .lower_bound = false, > - .extra_bits = 3, > - .expected = {.tv_sec = 0x37fffffffLL, .tv_nsec = 0L}, > - } > - }; > - > struct timespec64 timestamp; > - int i; > - > - for (i = 0; i < ARRAY_SIZE(test_data); ++i) { > - timestamp.tv_sec = get_32bit_time(&test_data[i]); > - ext4_decode_extra_time(×tamp, > - cpu_to_le32(test_data[i].extra_bits)); > - > - KUNIT_EXPECT_EQ_MSG(test, > - test_data[i].expected.tv_sec, > - timestamp.tv_sec, > - CASE_NAME_FORMAT, > - test_data[i].test_case_name, > - test_data[i].msb_set, > - test_data[i].lower_bound, > - test_data[i].extra_bits); > - KUNIT_EXPECT_EQ_MSG(test, > - test_data[i].expected.tv_nsec, > - timestamp.tv_nsec, > - CASE_NAME_FORMAT, > - test_data[i].test_case_name, > - test_data[i].msb_set, > - test_data[i].lower_bound, > - test_data[i].extra_bits); > - } > + > + struct timestamp_expectation *test_param = > + (struct timestamp_expectation *)(test->param_value); > + > + timestamp.tv_sec = get_32bit_time(test_param); > + ext4_decode_extra_time(×tamp, > + cpu_to_le32(test_param->extra_bits)); > + > + KUNIT_EXPECT_EQ_MSG(test, > + test_param->expected.tv_sec, > + timestamp.tv_sec, > + CASE_NAME_FORMAT, > + test_param->test_case_name, > + test_param->msb_set, > + test_param->lower_bound, > + test_param->extra_bits); > + KUNIT_EXPECT_EQ_MSG(test, > + test_param->expected.tv_nsec, > + timestamp.tv_nsec, > + CASE_NAME_FORMAT, > + test_param->test_case_name, > + test_param->msb_set, > + test_param->lower_bound, > + test_param->extra_bits); > } > > static struct kunit_case ext4_inode_test_cases[] = { > - KUNIT_CASE(inode_test_xtimestamp_decoding), > + KUNIT_CASE_PARAM(inode_test_xtimestamp_decoding, ext4_inode_gen_params), > {} > }; > > -- > 2.25.1 >