From patchwork Mon Oct 26 18:35:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arpitha Raghunandan <98.arpi@gmail.com> X-Patchwork-Id: 11858229 X-Patchwork-Delegate: brendanhiggins@google.com Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 17B2992C for ; Mon, 26 Oct 2020 18:36:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E3C612224E for ; Mon, 26 Oct 2020 18:36:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Oluu89m6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1790019AbgJZSgN (ORCPT ); Mon, 26 Oct 2020 14:36:13 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:37713 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1790017AbgJZSgM (ORCPT ); Mon, 26 Oct 2020 14:36:12 -0400 Received: by mail-pl1-f194.google.com with SMTP id b12so2790581plr.4; Mon, 26 Oct 2020 11:36:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=GDOHv5b8HiOM16zq/llcw/rbyjliyY5uE1ixYVZQCRk=; b=Oluu89m6zfnz2xjgPuqZ/RtqNtSFMlEBWuKWY6dglhynSZHo52MpwU4nIX/l9JqgBN VAWmDkz5EtHdhrStBWaYy0XSF15h0gb5VOmfQTL8nkeOh6BYtLAisjFqocIuPlpH/ZWd Q9FEbXvfhwzq/+BN9aRU+0+DeoMf+7hEkbQ1ZMCBEjUph0HQmkWd4qgAeZKkBZ9JydvD yQD2cCtL8Kdf6eAfhHpmVHp+BwyvUEWelMiHhRkEcDaGdXyDbyjTQSb7pXPQftDuXR9E 5kjXcMxTwR3Wojl8R9kX5fDWk9vxT8NZdMeNBzlCeQoFLtb/xTVk05VEN/mqZtngfZH+ nbng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=GDOHv5b8HiOM16zq/llcw/rbyjliyY5uE1ixYVZQCRk=; b=jTMNt6g1qfcAdx5e42ro5VOLajPC0q8+AYwAaetDTPRAFRQ/ErCMUwpd9/8fqaGHTI o6Qu9kJ0IUC2ss1/mcNrCp4uX0n6XTHSrE1AiGZ65gTbYIzy+kPRuFjIW7wd5NH6HD0A pznjKG5/91oTHi27JL9VM2qWfIVr8BuqyntXiu/F77Ze9H8e8R9BtJ6pg/FekugHAuoJ q+mliRFGZVwgJ9I6bavhhbE6q2ts0UARAQcpF65HJ7lKSHER7DW9nbsztVz5lnEGLOwg KtK2iIaVgtkhcbQ3kl59KQpxfGiHY7hnJL2ly5asSDYMw57tBbnyk3vBSnV9SwIW51i0 yldA== X-Gm-Message-State: AOAM533KRia6tby1c2Cs8WVFe4nyOaJrbSSvMqugQSH/L6k9t9GX4s4C DUFD9eAyzbMftmJIFcEbcGw= X-Google-Smtp-Source: ABdhPJw+Kpj72k9Rn6j1v/PbCzIUTKXOjmOgwzcUZNhWRbstWGMZPmaBxBy8VHtiGcdwZKqlH49fTQ== X-Received: by 2002:a17:90a:fe8:: with SMTP id 95mr17238402pjz.73.1603737370301; Mon, 26 Oct 2020 11:36:10 -0700 (PDT) Received: from arpitha-Inspiron-7570.lan ([106.51.240.100]) by smtp.gmail.com with ESMTPSA id z23sm11085260pgf.12.2020.10.26.11.36.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Oct 2020 11:36:09 -0700 (PDT) From: Arpitha Raghunandan <98.arpi@gmail.com> To: brendanhiggins@google.com, skhan@linuxfoundation.org, elver@google.com, yzaikin@google.com, tytso@mit.edu, adilger.kernel@dilger.ca Cc: Arpitha Raghunandan <98.arpi@gmail.com>, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org, linux-ext4@vger.kernel.org Subject: [PATCH v3 1/2] kunit: Support for Parameterized Testing Date: Tue, 27 Oct 2020 00:05:23 +0530 Message-Id: <20201026183523.82749-1-98.arpi@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org 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. Signed-off-by: Arpitha Raghunandan <98.arpi@gmail.com> Co-developed-by: Marco Elver Signed-off-by: Marco Elver --- 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 | 32 ++++++++++++++++++++++++++++++++ lib/kunit/test.c | 20 +++++++++++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/include/kunit/test.h b/include/kunit/test.h index a423fffefea0..16bf9f334e2c 100644 --- a/include/kunit/test.h +++ b/include/kunit/test.h @@ -142,6 +142,12 @@ struct kunit_case { void (*run_case)(struct kunit *test); const char *name; + /* + * Pointer to test parameter generator function. + * Used only for parameterized tests. + */ + void* (*generate_params)(void *prev); + /* private: internal use only. */ bool success; char *log; @@ -162,6 +168,9 @@ static inline char *kunit_status_to_string(bool status) * &struct kunit_case for an example on how to use it. */ #define KUNIT_CASE(test_name) { .run_case = test_name, .name = #test_name } +#define KUNIT_CASE_PARAM(test_name, gen_params) \ + { .run_case = test_name, .name = #test_name, \ + .generate_params = gen_params } /** * 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; + /* + * 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; /* * 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); +} + 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++; + } + } } static void kunit_case_internal_cleanup(struct kunit *test) From patchwork Mon Oct 26 18:36:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arpitha Raghunandan <98.arpi@gmail.com> X-Patchwork-Id: 11858231 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 97CF061C for ; Mon, 26 Oct 2020 18:37:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6FA792076A for ; Mon, 26 Oct 2020 18:37:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aj/Pygjz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1790073AbgJZShM (ORCPT ); Mon, 26 Oct 2020 14:37:12 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:33255 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1790047AbgJZShK (ORCPT ); Mon, 26 Oct 2020 14:37:10 -0400 Received: by mail-pl1-f194.google.com with SMTP id b19so5158454pld.0; Mon, 26 Oct 2020 11:37:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KNb3aa4/7lLeB65oO/Y1tHmkRQneZk5eatkdpCxWGSo=; b=aj/PygjzPPH0eEMElWirl46OqLcmYxzl8HbFFoGlFMLQPVuzA8iIscKygl34znPmH/ 1EBK2eLHWc2QzAwLBoQHQ1puSmrjl1gTco9FR9bxk4Bh0G9aNVs1qrSfrAsUdyrOikqK tcZQ+1OUtBV0oonjHFpL7oJRfIWrGNBa/2PKgiHkBoXHPHY4d/yOGvCpYGaXm12KVfDI 1Y/d2q28/hJEGSZjwFfUedDn/i/AtpwhSWeuF0hFszACXwjQ/6enTgzBKjRLeIKkcIgK 2701w6qA2VwOVqdvvO+c3m2sFGFAfJTZf724++fEYpTUFW7M7RO5cUAv8BJkW+331/VA 8WRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KNb3aa4/7lLeB65oO/Y1tHmkRQneZk5eatkdpCxWGSo=; b=X1BScwV+1NIlGig/JIbqAZxTDKlhlBypchRfqeQzyIAugmDVIAHZBVPk6B/DbyfPtj Wb5ncdHizOswaYgn4lMDTeSXl5v6VHemg/iW3AVbauLp6GfPxoeQ9JkkOMOacqYut7nX qxBf9k3Ep9OYH3ts6h+pA1kDNmr1Gv+lAsLfPS5vDPAhKObGPi2QcMgs7HS0QdRoScd8 gBLzHDH9WtcmoDhRzGcWj+SMh86u3xNtGXZl0mFevVyZ/j+IuWzIqc09TaFyyQxkUCWP lJjz8pli0TRR2RY5sAVT5MjuU2taYH5ylMs6bURpGonyEgRrNCKsUuVC0N6rsrMjZ7o+ s/FQ== X-Gm-Message-State: AOAM531zZ0BAAPXdpDO+SJORs/GoHxI+5/zKMjNN6Z+4+yIXvIbW420m ZgnFRnJV7JsrodvYn3JDDFI= X-Google-Smtp-Source: ABdhPJwp3A//wWV0Z2sXb6ZWGjPnHReWlL48OvnbvrCVSuAef2MnphrN+LQ4bd3ENJu7WIpIR8zmjQ== X-Received: by 2002:a17:902:8c88:b029:d5:ffe1:6653 with SMTP id t8-20020a1709028c88b02900d5ffe16653mr16386997plo.22.1603737427679; Mon, 26 Oct 2020 11:37:07 -0700 (PDT) Received: from arpitha-Inspiron-7570.lan ([106.51.240.100]) by smtp.gmail.com with ESMTPSA id s23sm11247799pgl.47.2020.10.26.11.37.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Oct 2020 11:37:06 -0700 (PDT) From: Arpitha Raghunandan <98.arpi@gmail.com> To: brendanhiggins@google.com, skhan@linuxfoundation.org, elver@google.com, yzaikin@google.com, tytso@mit.edu, adilger.kernel@dilger.ca Cc: Arpitha Raghunandan <98.arpi@gmail.com>, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org, linux-ext4@vger.kernel.org Subject: [PATCH v3 2/2] fs: ext4: Modify inode-test.c to use KUnit parameterized testing feature Date: Tue, 27 Oct 2020 00:06:39 +0530 Message-Id: <20201026183639.82883-1-98.arpi@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201026183523.82749-1-98.arpi@gmail.com> References: <20201026183523.82749-1-98.arpi@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Modify fs/ext4/inode-test.c to use the parameterized testing feature of KUnit. Signed-off-by: Arpitha Raghunandan <98.arpi@gmail.com> Reported-by: kernel test robot Reviewed-by: Iurii Zaikin --- 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 | 314 ++++++++++++++++++++++--------------------- 1 file changed, 158 insertions(+), 156 deletions(-) diff --git a/fs/ext4/inode-test.c b/fs/ext4/inode-test.c index d62d802c9c12..3a449623b775 100644 --- a/fs/ext4/inode-test.c +++ b/fs/ext4/inode-test.c @@ -80,6 +80,139 @@ 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}, + } +}; + +KUNIT_PARAM_GENERATOR(ext4_inode, test_data); + static time64_t get_32bit_time(const struct timestamp_expectation * const test) { if (test->msb_set) { @@ -101,166 +234,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_values); + + 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), {} };