* [PATCH v3 1/2] kunit: Support for Parameterized Testing
@ 2020-10-26 18:35 Arpitha Raghunandan
2020-10-26 18:36 ` [PATCH v3 2/2] fs: ext4: Modify inode-test.c to use KUnit parameterized testing feature Arpitha Raghunandan
` (3 more replies)
0 siblings, 4 replies; 12+ messages in thread
From: Arpitha Raghunandan @ 2020-10-26 18:35 UTC (permalink / raw)
To: brendanhiggins, skhan, elver, yzaikin, tytso, adilger.kernel
Cc: Arpitha Raghunandan, linux-kselftest, kunit-dev, linux-kernel,
linux-kernel-mentees, linux-ext4
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 <elver@google.com>
Signed-off-by: Marco Elver <elver@google.com>
---
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)
--
2.25.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v3 2/2] fs: ext4: Modify inode-test.c to use KUnit parameterized testing feature
2020-10-26 18:35 [PATCH v3 1/2] kunit: Support for Parameterized Testing Arpitha Raghunandan
@ 2020-10-26 18:36 ` Arpitha Raghunandan
2020-10-26 20:19 ` kernel test robot
` (2 more replies)
2020-10-26 23:14 ` [PATCH v3 1/2] kunit: Support for Parameterized Testing Marco Elver
` (2 subsequent siblings)
3 siblings, 3 replies; 12+ messages in thread
From: Arpitha Raghunandan @ 2020-10-26 18:36 UTC (permalink / raw)
To: brendanhiggins, skhan, elver, yzaikin, tytso, adilger.kernel
Cc: Arpitha Raghunandan, linux-kselftest, kunit-dev, linux-kernel,
linux-kernel-mentees, linux-ext4
Modify fs/ext4/inode-test.c to use the parameterized testing
feature of KUnit.
Signed-off-by: Arpitha Raghunandan <98.arpi@gmail.com>
---
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),
{}
};
--
2.25.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH v3 2/2] fs: ext4: Modify inode-test.c to use KUnit parameterized testing feature
2020-10-26 18:36 ` [PATCH v3 2/2] fs: ext4: Modify inode-test.c to use KUnit parameterized testing feature Arpitha Raghunandan
@ 2020-10-26 20:19 ` kernel test robot
2020-10-26 22:19 ` kernel test robot
2020-10-27 17:33 ` Iurii Zaikin
2 siblings, 0 replies; 12+ messages in thread
From: kernel test robot @ 2020-10-26 20:19 UTC (permalink / raw)
To: Arpitha Raghunandan, brendanhiggins, skhan, elver, yzaikin,
tytso, adilger.kernel
Cc: kbuild-all, Arpitha Raghunandan, linux-kselftest, kunit-dev,
linux-kernel
[-- Attachment #1: Type: text/plain, Size: 57317 bytes --]
Hi Arpitha,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on ext4/dev]
[also build test WARNING on linus/master v5.10-rc1 next-20201026]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Arpitha-Raghunandan/kunit-Support-for-Parameterized-Testing/20201027-023812
base: https://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git dev
config: m68k-allmodconfig (attached as .config)
compiler: m68k-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/1c6cd3899d5ed7da9b746ba887779ca2c89c5bab
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Arpitha-Raghunandan/kunit-Support-for-Parameterized-Testing/20201027-023812
git checkout 1c6cd3899d5ed7da9b746ba887779ca2c89c5bab
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=m68k
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
All warnings (new ones prefixed by >>):
In file included from include/linux/err.h:5,
from include/kunit/assert.h:12,
from include/kunit/test.h:12,
from fs/ext4/inode-test.c:7:
include/linux/scatterlist.h: In function 'sg_set_buf':
arch/m68k/include/asm/page_mm.h:169:49: warning: ordered comparison of pointer with null pointer [-Wextra]
169 | #define virt_addr_valid(kaddr) ((void *)(kaddr) >= (void *)PAGE_OFFSET && (void *)(kaddr) < high_memory)
| ^~
include/linux/compiler.h:78:42: note: in definition of macro 'unlikely'
78 | # define unlikely(x) __builtin_expect(!!(x), 0)
| ^
include/linux/scatterlist.h:143:2: note: in expansion of macro 'BUG_ON'
143 | BUG_ON(!virt_addr_valid(buf));
| ^~~~~~
include/linux/scatterlist.h:143:10: note: in expansion of macro 'virt_addr_valid'
143 | BUG_ON(!virt_addr_valid(buf));
| ^~~~~~~~~~~~~~~
In file included from fs/ext4/inode-test.c:7:
fs/ext4/inode-test.c: In function 'ext4_inode_gen_params':
>> include/kunit/test.h:1733:58: warning: return discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
1733 | return __next - (array) < ARRAY_SIZE((array)) ? __next : NULL; \
fs/ext4/inode-test.c:214:1: note: in expansion of macro 'KUNIT_PARAM_GENERATOR'
214 | KUNIT_PARAM_GENERATOR(ext4_inode, test_data);
| ^~~~~~~~~~~~~~~~~~~~~
vim +/const +1733 include/kunit/test.h
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1152
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1153 #define KUNIT_PTR_NOT_ERR_OR_NULL_ASSERTION(test, assert_type, ptr) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1154 KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1155 assert_type, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1156 ptr, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1157 NULL)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1158
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1159 /**
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1160 * KUNIT_EXPECT_TRUE() - Causes a test failure when the expression is not true.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1161 * @test: The test context object.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1162 * @condition: an arbitrary boolean expression. The test fails when this does
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1163 * not evaluate to true.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1164 *
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1165 * This and expectations of the form `KUNIT_EXPECT_*` will cause the test case
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1166 * to fail when the specified condition is not met; however, it will not prevent
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1167 * the test case from continuing to run; this is otherwise known as an
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1168 * *expectation failure*.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1169 */
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1170 #define KUNIT_EXPECT_TRUE(test, condition) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1171 KUNIT_TRUE_ASSERTION(test, KUNIT_EXPECTATION, condition)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1172
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1173 #define KUNIT_EXPECT_TRUE_MSG(test, condition, fmt, ...) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1174 KUNIT_TRUE_MSG_ASSERTION(test, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1175 KUNIT_EXPECTATION, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1176 condition, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1177 fmt, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1178 ##__VA_ARGS__)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1179
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1180 /**
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1181 * KUNIT_EXPECT_FALSE() - Makes a test failure when the expression is not false.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1182 * @test: The test context object.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1183 * @condition: an arbitrary boolean expression. The test fails when this does
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1184 * not evaluate to false.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1185 *
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1186 * Sets an expectation that @condition evaluates to false. See
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1187 * KUNIT_EXPECT_TRUE() for more information.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1188 */
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1189 #define KUNIT_EXPECT_FALSE(test, condition) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1190 KUNIT_FALSE_ASSERTION(test, KUNIT_EXPECTATION, condition)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1191
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1192 #define KUNIT_EXPECT_FALSE_MSG(test, condition, fmt, ...) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1193 KUNIT_FALSE_MSG_ASSERTION(test, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1194 KUNIT_EXPECTATION, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1195 condition, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1196 fmt, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1197 ##__VA_ARGS__)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1198
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1199 /**
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1200 * KUNIT_EXPECT_EQ() - Sets an expectation that @left and @right are equal.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1201 * @test: The test context object.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1202 * @left: an arbitrary expression that evaluates to a primitive C type.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1203 * @right: an arbitrary expression that evaluates to a primitive C type.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1204 *
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1205 * Sets an expectation that the values that @left and @right evaluate to are
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1206 * equal. This is semantically equivalent to
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1207 * KUNIT_EXPECT_TRUE(@test, (@left) == (@right)). See KUNIT_EXPECT_TRUE() for
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1208 * more information.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1209 */
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1210 #define KUNIT_EXPECT_EQ(test, left, right) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1211 KUNIT_BINARY_EQ_ASSERTION(test, KUNIT_EXPECTATION, left, right)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1212
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1213 #define KUNIT_EXPECT_EQ_MSG(test, left, right, fmt, ...) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1214 KUNIT_BINARY_EQ_MSG_ASSERTION(test, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1215 KUNIT_EXPECTATION, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1216 left, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1217 right, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1218 fmt, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1219 ##__VA_ARGS__)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1220
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1221 /**
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1222 * KUNIT_EXPECT_PTR_EQ() - Expects that pointers @left and @right are equal.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1223 * @test: The test context object.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1224 * @left: an arbitrary expression that evaluates to a pointer.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1225 * @right: an arbitrary expression that evaluates to a pointer.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1226 *
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1227 * Sets an expectation that the values that @left and @right evaluate to are
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1228 * equal. This is semantically equivalent to
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1229 * KUNIT_EXPECT_TRUE(@test, (@left) == (@right)). See KUNIT_EXPECT_TRUE() for
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1230 * more information.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1231 */
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1232 #define KUNIT_EXPECT_PTR_EQ(test, left, right) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1233 KUNIT_BINARY_PTR_EQ_ASSERTION(test, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1234 KUNIT_EXPECTATION, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1235 left, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1236 right)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1237
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1238 #define KUNIT_EXPECT_PTR_EQ_MSG(test, left, right, fmt, ...) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1239 KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1240 KUNIT_EXPECTATION, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1241 left, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1242 right, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1243 fmt, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1244 ##__VA_ARGS__)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1245
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1246 /**
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1247 * KUNIT_EXPECT_NE() - An expectation that @left and @right are not equal.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1248 * @test: The test context object.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1249 * @left: an arbitrary expression that evaluates to a primitive C type.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1250 * @right: an arbitrary expression that evaluates to a primitive C type.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1251 *
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1252 * Sets an expectation that the values that @left and @right evaluate to are not
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1253 * equal. This is semantically equivalent to
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1254 * KUNIT_EXPECT_TRUE(@test, (@left) != (@right)). See KUNIT_EXPECT_TRUE() for
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1255 * more information.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1256 */
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1257 #define KUNIT_EXPECT_NE(test, left, right) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1258 KUNIT_BINARY_NE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1259
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1260 #define KUNIT_EXPECT_NE_MSG(test, left, right, fmt, ...) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1261 KUNIT_BINARY_NE_MSG_ASSERTION(test, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1262 KUNIT_EXPECTATION, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1263 left, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1264 right, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1265 fmt, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1266 ##__VA_ARGS__)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1267
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1268 /**
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1269 * KUNIT_EXPECT_PTR_NE() - Expects that pointers @left and @right are not equal.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1270 * @test: The test context object.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1271 * @left: an arbitrary expression that evaluates to a pointer.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1272 * @right: an arbitrary expression that evaluates to a pointer.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1273 *
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1274 * Sets an expectation that the values that @left and @right evaluate to are not
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1275 * equal. This is semantically equivalent to
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1276 * KUNIT_EXPECT_TRUE(@test, (@left) != (@right)). See KUNIT_EXPECT_TRUE() for
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1277 * more information.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1278 */
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1279 #define KUNIT_EXPECT_PTR_NE(test, left, right) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1280 KUNIT_BINARY_PTR_NE_ASSERTION(test, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1281 KUNIT_EXPECTATION, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1282 left, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1283 right)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1284
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1285 #define KUNIT_EXPECT_PTR_NE_MSG(test, left, right, fmt, ...) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1286 KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1287 KUNIT_EXPECTATION, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1288 left, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1289 right, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1290 fmt, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1291 ##__VA_ARGS__)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1292
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1293 /**
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1294 * KUNIT_EXPECT_LT() - An expectation that @left is less than @right.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1295 * @test: The test context object.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1296 * @left: an arbitrary expression that evaluates to a primitive C type.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1297 * @right: an arbitrary expression that evaluates to a primitive C type.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1298 *
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1299 * Sets an expectation that the value that @left evaluates to is less than the
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1300 * value that @right evaluates to. This is semantically equivalent to
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1301 * KUNIT_EXPECT_TRUE(@test, (@left) < (@right)). See KUNIT_EXPECT_TRUE() for
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1302 * more information.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1303 */
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1304 #define KUNIT_EXPECT_LT(test, left, right) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1305 KUNIT_BINARY_LT_ASSERTION(test, KUNIT_EXPECTATION, left, right)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1306
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1307 #define KUNIT_EXPECT_LT_MSG(test, left, right, fmt, ...) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1308 KUNIT_BINARY_LT_MSG_ASSERTION(test, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1309 KUNIT_EXPECTATION, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1310 left, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1311 right, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1312 fmt, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1313 ##__VA_ARGS__)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1314
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1315 /**
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1316 * KUNIT_EXPECT_LE() - Expects that @left is less than or equal to @right.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1317 * @test: The test context object.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1318 * @left: an arbitrary expression that evaluates to a primitive C type.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1319 * @right: an arbitrary expression that evaluates to a primitive C type.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1320 *
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1321 * Sets an expectation that the value that @left evaluates to is less than or
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1322 * equal to the value that @right evaluates to. Semantically this is equivalent
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1323 * to KUNIT_EXPECT_TRUE(@test, (@left) <= (@right)). See KUNIT_EXPECT_TRUE() for
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1324 * more information.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1325 */
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1326 #define KUNIT_EXPECT_LE(test, left, right) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1327 KUNIT_BINARY_LE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1328
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1329 #define KUNIT_EXPECT_LE_MSG(test, left, right, fmt, ...) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1330 KUNIT_BINARY_LE_MSG_ASSERTION(test, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1331 KUNIT_EXPECTATION, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1332 left, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1333 right, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1334 fmt, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1335 ##__VA_ARGS__)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1336
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1337 /**
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1338 * KUNIT_EXPECT_GT() - An expectation that @left is greater than @right.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1339 * @test: The test context object.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1340 * @left: an arbitrary expression that evaluates to a primitive C type.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1341 * @right: an arbitrary expression that evaluates to a primitive C type.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1342 *
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1343 * Sets an expectation that the value that @left evaluates to is greater than
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1344 * the value that @right evaluates to. This is semantically equivalent to
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1345 * KUNIT_EXPECT_TRUE(@test, (@left) > (@right)). See KUNIT_EXPECT_TRUE() for
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1346 * more information.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1347 */
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1348 #define KUNIT_EXPECT_GT(test, left, right) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1349 KUNIT_BINARY_GT_ASSERTION(test, KUNIT_EXPECTATION, left, right)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1350
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1351 #define KUNIT_EXPECT_GT_MSG(test, left, right, fmt, ...) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1352 KUNIT_BINARY_GT_MSG_ASSERTION(test, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1353 KUNIT_EXPECTATION, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1354 left, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1355 right, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1356 fmt, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1357 ##__VA_ARGS__)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1358
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1359 /**
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1360 * KUNIT_EXPECT_GE() - Expects that @left is greater than or equal to @right.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1361 * @test: The test context object.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1362 * @left: an arbitrary expression that evaluates to a primitive C type.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1363 * @right: an arbitrary expression that evaluates to a primitive C type.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1364 *
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1365 * Sets an expectation that the value that @left evaluates to is greater than
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1366 * the value that @right evaluates to. This is semantically equivalent to
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1367 * KUNIT_EXPECT_TRUE(@test, (@left) >= (@right)). See KUNIT_EXPECT_TRUE() for
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1368 * more information.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1369 */
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1370 #define KUNIT_EXPECT_GE(test, left, right) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1371 KUNIT_BINARY_GE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1372
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1373 #define KUNIT_EXPECT_GE_MSG(test, left, right, fmt, ...) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1374 KUNIT_BINARY_GE_MSG_ASSERTION(test, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1375 KUNIT_EXPECTATION, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1376 left, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1377 right, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1378 fmt, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1379 ##__VA_ARGS__)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1380
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1381 /**
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1382 * KUNIT_EXPECT_STREQ() - Expects that strings @left and @right are equal.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1383 * @test: The test context object.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1384 * @left: an arbitrary expression that evaluates to a null terminated string.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1385 * @right: an arbitrary expression that evaluates to a null terminated string.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1386 *
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1387 * Sets an expectation that the values that @left and @right evaluate to are
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1388 * equal. This is semantically equivalent to
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1389 * KUNIT_EXPECT_TRUE(@test, !strcmp((@left), (@right))). See KUNIT_EXPECT_TRUE()
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1390 * for more information.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1391 */
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1392 #define KUNIT_EXPECT_STREQ(test, left, right) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1393 KUNIT_BINARY_STR_EQ_ASSERTION(test, KUNIT_EXPECTATION, left, right)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1394
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1395 #define KUNIT_EXPECT_STREQ_MSG(test, left, right, fmt, ...) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1396 KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1397 KUNIT_EXPECTATION, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1398 left, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1399 right, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1400 fmt, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1401 ##__VA_ARGS__)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1402
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1403 /**
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1404 * KUNIT_EXPECT_STRNEQ() - Expects that strings @left and @right are not equal.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1405 * @test: The test context object.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1406 * @left: an arbitrary expression that evaluates to a null terminated string.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1407 * @right: an arbitrary expression that evaluates to a null terminated string.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1408 *
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1409 * Sets an expectation that the values that @left and @right evaluate to are
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1410 * not equal. This is semantically equivalent to
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1411 * KUNIT_EXPECT_TRUE(@test, strcmp((@left), (@right))). See KUNIT_EXPECT_TRUE()
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1412 * for more information.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1413 */
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1414 #define KUNIT_EXPECT_STRNEQ(test, left, right) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1415 KUNIT_BINARY_STR_NE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1416
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1417 #define KUNIT_EXPECT_STRNEQ_MSG(test, left, right, fmt, ...) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1418 KUNIT_BINARY_STR_NE_MSG_ASSERTION(test, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1419 KUNIT_EXPECTATION, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1420 left, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1421 right, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1422 fmt, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1423 ##__VA_ARGS__)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1424
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1425 /**
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1426 * KUNIT_EXPECT_NOT_ERR_OR_NULL() - Expects that @ptr is not null and not err.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1427 * @test: The test context object.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1428 * @ptr: an arbitrary pointer.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1429 *
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1430 * Sets an expectation that the value that @ptr evaluates to is not null and not
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1431 * an errno stored in a pointer. This is semantically equivalent to
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1432 * KUNIT_EXPECT_TRUE(@test, !IS_ERR_OR_NULL(@ptr)). See KUNIT_EXPECT_TRUE() for
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1433 * more information.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1434 */
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1435 #define KUNIT_EXPECT_NOT_ERR_OR_NULL(test, ptr) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1436 KUNIT_PTR_NOT_ERR_OR_NULL_ASSERTION(test, KUNIT_EXPECTATION, ptr)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1437
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1438 #define KUNIT_EXPECT_NOT_ERR_OR_NULL_MSG(test, ptr, fmt, ...) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1439 KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1440 KUNIT_EXPECTATION, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1441 ptr, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1442 fmt, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1443 ##__VA_ARGS__)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1444
e4aea8f8532b55 Brendan Higgins 2019-09-23 1445 #define KUNIT_ASSERT_FAILURE(test, fmt, ...) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1446 KUNIT_FAIL_ASSERTION(test, KUNIT_ASSERTION, fmt, ##__VA_ARGS__)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1447
e4aea8f8532b55 Brendan Higgins 2019-09-23 1448 /**
e4aea8f8532b55 Brendan Higgins 2019-09-23 1449 * KUNIT_ASSERT_TRUE() - Sets an assertion that @condition is true.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1450 * @test: The test context object.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1451 * @condition: an arbitrary boolean expression. The test fails and aborts when
e4aea8f8532b55 Brendan Higgins 2019-09-23 1452 * this does not evaluate to true.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1453 *
e4aea8f8532b55 Brendan Higgins 2019-09-23 1454 * This and assertions of the form `KUNIT_ASSERT_*` will cause the test case to
e4aea8f8532b55 Brendan Higgins 2019-09-23 1455 * fail *and immediately abort* when the specified condition is not met. Unlike
e4aea8f8532b55 Brendan Higgins 2019-09-23 1456 * an expectation failure, it will prevent the test case from continuing to run;
e4aea8f8532b55 Brendan Higgins 2019-09-23 1457 * this is otherwise known as an *assertion failure*.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1458 */
e4aea8f8532b55 Brendan Higgins 2019-09-23 1459 #define KUNIT_ASSERT_TRUE(test, condition) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1460 KUNIT_TRUE_ASSERTION(test, KUNIT_ASSERTION, condition)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1461
e4aea8f8532b55 Brendan Higgins 2019-09-23 1462 #define KUNIT_ASSERT_TRUE_MSG(test, condition, fmt, ...) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1463 KUNIT_TRUE_MSG_ASSERTION(test, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1464 KUNIT_ASSERTION, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1465 condition, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1466 fmt, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1467 ##__VA_ARGS__)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1468
e4aea8f8532b55 Brendan Higgins 2019-09-23 1469 /**
e4aea8f8532b55 Brendan Higgins 2019-09-23 1470 * KUNIT_ASSERT_FALSE() - Sets an assertion that @condition is false.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1471 * @test: The test context object.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1472 * @condition: an arbitrary boolean expression.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1473 *
e4aea8f8532b55 Brendan Higgins 2019-09-23 1474 * Sets an assertion that the value that @condition evaluates to is false. This
e4aea8f8532b55 Brendan Higgins 2019-09-23 1475 * is the same as KUNIT_EXPECT_FALSE(), except it causes an assertion failure
e4aea8f8532b55 Brendan Higgins 2019-09-23 1476 * (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1477 */
e4aea8f8532b55 Brendan Higgins 2019-09-23 1478 #define KUNIT_ASSERT_FALSE(test, condition) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1479 KUNIT_FALSE_ASSERTION(test, KUNIT_ASSERTION, condition)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1480
e4aea8f8532b55 Brendan Higgins 2019-09-23 1481 #define KUNIT_ASSERT_FALSE_MSG(test, condition, fmt, ...) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1482 KUNIT_FALSE_MSG_ASSERTION(test, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1483 KUNIT_ASSERTION, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1484 condition, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1485 fmt, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1486 ##__VA_ARGS__)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1487
e4aea8f8532b55 Brendan Higgins 2019-09-23 1488 /**
e4aea8f8532b55 Brendan Higgins 2019-09-23 1489 * KUNIT_ASSERT_EQ() - Sets an assertion that @left and @right are equal.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1490 * @test: The test context object.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1491 * @left: an arbitrary expression that evaluates to a primitive C type.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1492 * @right: an arbitrary expression that evaluates to a primitive C type.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1493 *
e4aea8f8532b55 Brendan Higgins 2019-09-23 1494 * Sets an assertion that the values that @left and @right evaluate to are
e4aea8f8532b55 Brendan Higgins 2019-09-23 1495 * equal. This is the same as KUNIT_EXPECT_EQ(), except it causes an assertion
e4aea8f8532b55 Brendan Higgins 2019-09-23 1496 * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1497 */
e4aea8f8532b55 Brendan Higgins 2019-09-23 1498 #define KUNIT_ASSERT_EQ(test, left, right) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1499 KUNIT_BINARY_EQ_ASSERTION(test, KUNIT_ASSERTION, left, right)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1500
e4aea8f8532b55 Brendan Higgins 2019-09-23 1501 #define KUNIT_ASSERT_EQ_MSG(test, left, right, fmt, ...) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1502 KUNIT_BINARY_EQ_MSG_ASSERTION(test, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1503 KUNIT_ASSERTION, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1504 left, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1505 right, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1506 fmt, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1507 ##__VA_ARGS__)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1508
e4aea8f8532b55 Brendan Higgins 2019-09-23 1509 /**
e4aea8f8532b55 Brendan Higgins 2019-09-23 1510 * KUNIT_ASSERT_PTR_EQ() - Asserts that pointers @left and @right are equal.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1511 * @test: The test context object.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1512 * @left: an arbitrary expression that evaluates to a pointer.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1513 * @right: an arbitrary expression that evaluates to a pointer.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1514 *
e4aea8f8532b55 Brendan Higgins 2019-09-23 1515 * Sets an assertion that the values that @left and @right evaluate to are
e4aea8f8532b55 Brendan Higgins 2019-09-23 1516 * equal. This is the same as KUNIT_EXPECT_EQ(), except it causes an assertion
e4aea8f8532b55 Brendan Higgins 2019-09-23 1517 * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1518 */
e4aea8f8532b55 Brendan Higgins 2019-09-23 1519 #define KUNIT_ASSERT_PTR_EQ(test, left, right) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1520 KUNIT_BINARY_PTR_EQ_ASSERTION(test, KUNIT_ASSERTION, left, right)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1521
e4aea8f8532b55 Brendan Higgins 2019-09-23 1522 #define KUNIT_ASSERT_PTR_EQ_MSG(test, left, right, fmt, ...) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1523 KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1524 KUNIT_ASSERTION, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1525 left, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1526 right, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1527 fmt, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1528 ##__VA_ARGS__)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1529
e4aea8f8532b55 Brendan Higgins 2019-09-23 1530 /**
e4aea8f8532b55 Brendan Higgins 2019-09-23 1531 * KUNIT_ASSERT_NE() - An assertion that @left and @right are not equal.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1532 * @test: The test context object.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1533 * @left: an arbitrary expression that evaluates to a primitive C type.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1534 * @right: an arbitrary expression that evaluates to a primitive C type.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1535 *
e4aea8f8532b55 Brendan Higgins 2019-09-23 1536 * Sets an assertion that the values that @left and @right evaluate to are not
e4aea8f8532b55 Brendan Higgins 2019-09-23 1537 * equal. This is the same as KUNIT_EXPECT_NE(), except it causes an assertion
e4aea8f8532b55 Brendan Higgins 2019-09-23 1538 * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1539 */
e4aea8f8532b55 Brendan Higgins 2019-09-23 1540 #define KUNIT_ASSERT_NE(test, left, right) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1541 KUNIT_BINARY_NE_ASSERTION(test, KUNIT_ASSERTION, left, right)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1542
e4aea8f8532b55 Brendan Higgins 2019-09-23 1543 #define KUNIT_ASSERT_NE_MSG(test, left, right, fmt, ...) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1544 KUNIT_BINARY_NE_MSG_ASSERTION(test, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1545 KUNIT_ASSERTION, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1546 left, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1547 right, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1548 fmt, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1549 ##__VA_ARGS__)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1550
e4aea8f8532b55 Brendan Higgins 2019-09-23 1551 /**
e4aea8f8532b55 Brendan Higgins 2019-09-23 1552 * KUNIT_ASSERT_PTR_NE() - Asserts that pointers @left and @right are not equal.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1553 * KUNIT_ASSERT_PTR_EQ() - Asserts that pointers @left and @right are equal.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1554 * @test: The test context object.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1555 * @left: an arbitrary expression that evaluates to a pointer.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1556 * @right: an arbitrary expression that evaluates to a pointer.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1557 *
e4aea8f8532b55 Brendan Higgins 2019-09-23 1558 * Sets an assertion that the values that @left and @right evaluate to are not
e4aea8f8532b55 Brendan Higgins 2019-09-23 1559 * equal. This is the same as KUNIT_EXPECT_NE(), except it causes an assertion
e4aea8f8532b55 Brendan Higgins 2019-09-23 1560 * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1561 */
e4aea8f8532b55 Brendan Higgins 2019-09-23 1562 #define KUNIT_ASSERT_PTR_NE(test, left, right) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1563 KUNIT_BINARY_PTR_NE_ASSERTION(test, KUNIT_ASSERTION, left, right)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1564
e4aea8f8532b55 Brendan Higgins 2019-09-23 1565 #define KUNIT_ASSERT_PTR_NE_MSG(test, left, right, fmt, ...) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1566 KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1567 KUNIT_ASSERTION, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1568 left, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1569 right, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1570 fmt, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1571 ##__VA_ARGS__)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1572 /**
e4aea8f8532b55 Brendan Higgins 2019-09-23 1573 * KUNIT_ASSERT_LT() - An assertion that @left is less than @right.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1574 * @test: The test context object.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1575 * @left: an arbitrary expression that evaluates to a primitive C type.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1576 * @right: an arbitrary expression that evaluates to a primitive C type.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1577 *
e4aea8f8532b55 Brendan Higgins 2019-09-23 1578 * Sets an assertion that the value that @left evaluates to is less than the
e4aea8f8532b55 Brendan Higgins 2019-09-23 1579 * value that @right evaluates to. This is the same as KUNIT_EXPECT_LT(), except
e4aea8f8532b55 Brendan Higgins 2019-09-23 1580 * it causes an assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion
e4aea8f8532b55 Brendan Higgins 2019-09-23 1581 * is not met.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1582 */
e4aea8f8532b55 Brendan Higgins 2019-09-23 1583 #define KUNIT_ASSERT_LT(test, left, right) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1584 KUNIT_BINARY_LT_ASSERTION(test, KUNIT_ASSERTION, left, right)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1585
e4aea8f8532b55 Brendan Higgins 2019-09-23 1586 #define KUNIT_ASSERT_LT_MSG(test, left, right, fmt, ...) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1587 KUNIT_BINARY_LT_MSG_ASSERTION(test, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1588 KUNIT_ASSERTION, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1589 left, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1590 right, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1591 fmt, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1592 ##__VA_ARGS__)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1593 /**
e4aea8f8532b55 Brendan Higgins 2019-09-23 1594 * KUNIT_ASSERT_LE() - An assertion that @left is less than or equal to @right.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1595 * @test: The test context object.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1596 * @left: an arbitrary expression that evaluates to a primitive C type.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1597 * @right: an arbitrary expression that evaluates to a primitive C type.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1598 *
e4aea8f8532b55 Brendan Higgins 2019-09-23 1599 * Sets an assertion that the value that @left evaluates to is less than or
e4aea8f8532b55 Brendan Higgins 2019-09-23 1600 * equal to the value that @right evaluates to. This is the same as
e4aea8f8532b55 Brendan Higgins 2019-09-23 1601 * KUNIT_EXPECT_LE(), except it causes an assertion failure (see
e4aea8f8532b55 Brendan Higgins 2019-09-23 1602 * KUNIT_ASSERT_TRUE()) when the assertion is not met.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1603 */
e4aea8f8532b55 Brendan Higgins 2019-09-23 1604 #define KUNIT_ASSERT_LE(test, left, right) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1605 KUNIT_BINARY_LE_ASSERTION(test, KUNIT_ASSERTION, left, right)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1606
e4aea8f8532b55 Brendan Higgins 2019-09-23 1607 #define KUNIT_ASSERT_LE_MSG(test, left, right, fmt, ...) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1608 KUNIT_BINARY_LE_MSG_ASSERTION(test, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1609 KUNIT_ASSERTION, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1610 left, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1611 right, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1612 fmt, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1613 ##__VA_ARGS__)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1614
e4aea8f8532b55 Brendan Higgins 2019-09-23 1615 /**
e4aea8f8532b55 Brendan Higgins 2019-09-23 1616 * KUNIT_ASSERT_GT() - An assertion that @left is greater than @right.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1617 * @test: The test context object.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1618 * @left: an arbitrary expression that evaluates to a primitive C type.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1619 * @right: an arbitrary expression that evaluates to a primitive C type.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1620 *
e4aea8f8532b55 Brendan Higgins 2019-09-23 1621 * Sets an assertion that the value that @left evaluates to is greater than the
e4aea8f8532b55 Brendan Higgins 2019-09-23 1622 * value that @right evaluates to. This is the same as KUNIT_EXPECT_GT(), except
e4aea8f8532b55 Brendan Higgins 2019-09-23 1623 * it causes an assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion
e4aea8f8532b55 Brendan Higgins 2019-09-23 1624 * is not met.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1625 */
e4aea8f8532b55 Brendan Higgins 2019-09-23 1626 #define KUNIT_ASSERT_GT(test, left, right) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1627 KUNIT_BINARY_GT_ASSERTION(test, KUNIT_ASSERTION, left, right)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1628
e4aea8f8532b55 Brendan Higgins 2019-09-23 1629 #define KUNIT_ASSERT_GT_MSG(test, left, right, fmt, ...) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1630 KUNIT_BINARY_GT_MSG_ASSERTION(test, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1631 KUNIT_ASSERTION, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1632 left, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1633 right, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1634 fmt, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1635 ##__VA_ARGS__)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1636
e4aea8f8532b55 Brendan Higgins 2019-09-23 1637 /**
e4aea8f8532b55 Brendan Higgins 2019-09-23 1638 * KUNIT_ASSERT_GE() - Assertion that @left is greater than or equal to @right.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1639 * @test: The test context object.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1640 * @left: an arbitrary expression that evaluates to a primitive C type.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1641 * @right: an arbitrary expression that evaluates to a primitive C type.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1642 *
e4aea8f8532b55 Brendan Higgins 2019-09-23 1643 * Sets an assertion that the value that @left evaluates to is greater than the
e4aea8f8532b55 Brendan Higgins 2019-09-23 1644 * value that @right evaluates to. This is the same as KUNIT_EXPECT_GE(), except
e4aea8f8532b55 Brendan Higgins 2019-09-23 1645 * it causes an assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion
e4aea8f8532b55 Brendan Higgins 2019-09-23 1646 * is not met.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1647 */
e4aea8f8532b55 Brendan Higgins 2019-09-23 1648 #define KUNIT_ASSERT_GE(test, left, right) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1649 KUNIT_BINARY_GE_ASSERTION(test, KUNIT_ASSERTION, left, right)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1650
e4aea8f8532b55 Brendan Higgins 2019-09-23 1651 #define KUNIT_ASSERT_GE_MSG(test, left, right, fmt, ...) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1652 KUNIT_BINARY_GE_MSG_ASSERTION(test, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1653 KUNIT_ASSERTION, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1654 left, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1655 right, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1656 fmt, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1657 ##__VA_ARGS__)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1658
e4aea8f8532b55 Brendan Higgins 2019-09-23 1659 /**
e4aea8f8532b55 Brendan Higgins 2019-09-23 1660 * KUNIT_ASSERT_STREQ() - An assertion that strings @left and @right are equal.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1661 * @test: The test context object.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1662 * @left: an arbitrary expression that evaluates to a null terminated string.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1663 * @right: an arbitrary expression that evaluates to a null terminated string.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1664 *
e4aea8f8532b55 Brendan Higgins 2019-09-23 1665 * Sets an assertion that the values that @left and @right evaluate to are
e4aea8f8532b55 Brendan Higgins 2019-09-23 1666 * equal. This is the same as KUNIT_EXPECT_STREQ(), except it causes an
e4aea8f8532b55 Brendan Higgins 2019-09-23 1667 * assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1668 */
e4aea8f8532b55 Brendan Higgins 2019-09-23 1669 #define KUNIT_ASSERT_STREQ(test, left, right) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1670 KUNIT_BINARY_STR_EQ_ASSERTION(test, KUNIT_ASSERTION, left, right)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1671
e4aea8f8532b55 Brendan Higgins 2019-09-23 1672 #define KUNIT_ASSERT_STREQ_MSG(test, left, right, fmt, ...) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1673 KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1674 KUNIT_ASSERTION, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1675 left, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1676 right, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1677 fmt, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1678 ##__VA_ARGS__)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1679
e4aea8f8532b55 Brendan Higgins 2019-09-23 1680 /**
e4aea8f8532b55 Brendan Higgins 2019-09-23 1681 * KUNIT_ASSERT_STRNEQ() - Expects that strings @left and @right are not equal.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1682 * @test: The test context object.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1683 * @left: an arbitrary expression that evaluates to a null terminated string.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1684 * @right: an arbitrary expression that evaluates to a null terminated string.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1685 *
e4aea8f8532b55 Brendan Higgins 2019-09-23 1686 * Sets an expectation that the values that @left and @right evaluate to are
e4aea8f8532b55 Brendan Higgins 2019-09-23 1687 * not equal. This is semantically equivalent to
e4aea8f8532b55 Brendan Higgins 2019-09-23 1688 * KUNIT_ASSERT_TRUE(@test, strcmp((@left), (@right))). See KUNIT_ASSERT_TRUE()
e4aea8f8532b55 Brendan Higgins 2019-09-23 1689 * for more information.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1690 */
e4aea8f8532b55 Brendan Higgins 2019-09-23 1691 #define KUNIT_ASSERT_STRNEQ(test, left, right) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1692 KUNIT_BINARY_STR_NE_ASSERTION(test, KUNIT_ASSERTION, left, right)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1693
e4aea8f8532b55 Brendan Higgins 2019-09-23 1694 #define KUNIT_ASSERT_STRNEQ_MSG(test, left, right, fmt, ...) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1695 KUNIT_BINARY_STR_NE_MSG_ASSERTION(test, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1696 KUNIT_ASSERTION, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1697 left, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1698 right, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1699 fmt, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1700 ##__VA_ARGS__)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1701
e4aea8f8532b55 Brendan Higgins 2019-09-23 1702 /**
e4aea8f8532b55 Brendan Higgins 2019-09-23 1703 * KUNIT_ASSERT_NOT_ERR_OR_NULL() - Assertion that @ptr is not null and not err.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1704 * @test: The test context object.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1705 * @ptr: an arbitrary pointer.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1706 *
e4aea8f8532b55 Brendan Higgins 2019-09-23 1707 * Sets an assertion that the value that @ptr evaluates to is not null and not
e4aea8f8532b55 Brendan Higgins 2019-09-23 1708 * an errno stored in a pointer. This is the same as
e4aea8f8532b55 Brendan Higgins 2019-09-23 1709 * KUNIT_EXPECT_NOT_ERR_OR_NULL(), except it causes an assertion failure (see
e4aea8f8532b55 Brendan Higgins 2019-09-23 1710 * KUNIT_ASSERT_TRUE()) when the assertion is not met.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1711 */
e4aea8f8532b55 Brendan Higgins 2019-09-23 1712 #define KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1713 KUNIT_PTR_NOT_ERR_OR_NULL_ASSERTION(test, KUNIT_ASSERTION, ptr)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1714
e4aea8f8532b55 Brendan Higgins 2019-09-23 1715 #define KUNIT_ASSERT_NOT_ERR_OR_NULL_MSG(test, ptr, fmt, ...) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1716 KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1717 KUNIT_ASSERTION, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1718 ptr, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1719 fmt, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1720 ##__VA_ARGS__)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1721
6b4ee29da75136 Arpitha Raghunandan 2020-10-27 1722 /**
6b4ee29da75136 Arpitha Raghunandan 2020-10-27 1723 * KUNIT_PARAM_GENERATOR() - Helper method for test parameter generators
6b4ee29da75136 Arpitha Raghunandan 2020-10-27 1724 * required in parameterized tests.
6b4ee29da75136 Arpitha Raghunandan 2020-10-27 1725 * @name: prefix of the name for the test parameter generator function.
6b4ee29da75136 Arpitha Raghunandan 2020-10-27 1726 * @prev: a pointer to the previous test parameter, NULL for first parameter.
6b4ee29da75136 Arpitha Raghunandan 2020-10-27 1727 * @array: a user-supplied pointer to an array of test parameters.
6b4ee29da75136 Arpitha Raghunandan 2020-10-27 1728 */
6b4ee29da75136 Arpitha Raghunandan 2020-10-27 1729 #define KUNIT_PARAM_GENERATOR(name, array) \
6b4ee29da75136 Arpitha Raghunandan 2020-10-27 1730 static void *name##_gen_params(void *prev) \
6b4ee29da75136 Arpitha Raghunandan 2020-10-27 1731 { \
6b4ee29da75136 Arpitha Raghunandan 2020-10-27 1732 typeof((array)[0]) * __next = prev ? ((typeof(__next)) prev) + 1 : (array); \
6b4ee29da75136 Arpitha Raghunandan 2020-10-27 @1733 return __next - (array) < ARRAY_SIZE((array)) ? __next : NULL; \
6b4ee29da75136 Arpitha Raghunandan 2020-10-27 1734 }
6b4ee29da75136 Arpitha Raghunandan 2020-10-27 1735
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 57832 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v3 2/2] fs: ext4: Modify inode-test.c to use KUnit parameterized testing feature
2020-10-26 18:36 ` [PATCH v3 2/2] fs: ext4: Modify inode-test.c to use KUnit parameterized testing feature Arpitha Raghunandan
2020-10-26 20:19 ` kernel test robot
@ 2020-10-26 22:19 ` kernel test robot
2020-10-27 17:33 ` Iurii Zaikin
2 siblings, 0 replies; 12+ messages in thread
From: kernel test robot @ 2020-10-26 22:19 UTC (permalink / raw)
To: Arpitha Raghunandan, brendanhiggins, skhan, elver, yzaikin,
tytso, adilger.kernel
Cc: kbuild-all, Arpitha Raghunandan, linux-kselftest, kunit-dev,
linux-kernel
[-- Attachment #1: Type: text/plain, Size: 2121 bytes --]
Hi Arpitha,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on ext4/dev]
[also build test WARNING on linus/master v5.10-rc1 next-20201026]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Arpitha-Raghunandan/kunit-Support-for-Parameterized-Testing/20201027-023812
base: https://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git dev
config: sparc64-randconfig-s032-20201026 (attached as .config)
compiler: sparc64-linux-gcc (GCC) 9.3.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# apt-get install sparse
# sparse version: v0.6.3-56-gc09e8239-dirty
# https://github.com/0day-ci/linux/commit/1c6cd3899d5ed7da9b746ba887779ca2c89c5bab
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Arpitha-Raghunandan/kunit-Support-for-Parameterized-Testing/20201027-023812
git checkout 1c6cd3899d5ed7da9b746ba887779ca2c89c5bab
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=sparc64
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
"sparse warnings: (new ones prefixed by >>)"
>> fs/ext4/inode-test.c:214:1: sparse: sparse: incorrect type in return expression (different modifiers) @@ expected void * @@ got struct timestamp_expectation const * @@
>> fs/ext4/inode-test.c:214:1: sparse: expected void *
>> fs/ext4/inode-test.c:214:1: sparse: got struct timestamp_expectation const *
vim +214 fs/ext4/inode-test.c
213
> 214 KUNIT_PARAM_GENERATOR(ext4_inode, test_data);
215
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 29912 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v3 1/2] kunit: Support for Parameterized Testing
2020-10-26 18:35 [PATCH v3 1/2] kunit: Support for Parameterized Testing Arpitha Raghunandan
2020-10-26 18:36 ` [PATCH v3 2/2] fs: ext4: Modify inode-test.c to use KUnit parameterized testing feature Arpitha Raghunandan
@ 2020-10-26 23:14 ` Marco Elver
2020-10-27 5:14 ` Arpitha Raghunandan
2020-10-27 7:55 ` Marco Elver
2020-10-27 9:03 ` Marco Elver
3 siblings, 1 reply; 12+ messages in thread
From: Marco Elver @ 2020-10-26 23:14 UTC (permalink / raw)
To: Arpitha Raghunandan
Cc: Brendan Higgins, skhan, Iurii Zaikin, Theodore Ts'o,
Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK,
KUnit Development, LKML, linux-kernel-mentees, linux-ext4
On Mon, 26 Oct 2020 at 19:36, 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.
>
> Signed-off-by: Arpitha Raghunandan <98.arpi@gmail.com>
> Co-developed-by: Marco Elver <elver@google.com>
> Signed-off-by: Marco Elver <elver@google.com>
> ---
> Changes v2->v3:
> - Modifictaion of generator macro and method
Great to see it worked as expected!
> 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.
What I meant was to give a description of the protocol, so that if
somebody wanted, they could (without reading the implementation)
implement their own custom generator without the helper macro.
E.g. something like: "The generator function is used to lazily
generate a series of arbitrarily typed values that fit into a void*.
The argument @prev is the previously returned value, which should be
used to derive the next value; @prev is set to NULL on the initial
generator call. When no more values are available, the generator must
return NULL."
> + */
> + 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.
This is only for arrays, which is why I suggested KUNIT_ARRAY_PARAM()
as the name.
A generator can very well be implemented without an array, so this
macro name is confusing. In future somebody might want to provide a
macro that takes a start + end value (and maybe a step value) to
generate a series of values. That generator could be named
KUNIT_RANGE_PARAM(name, start, end, step) and gives us a generator
that is also named name##_gen_params. (If you want to try implementing
that macro, I'd suggest doing it as a separate patch.)
And I don't think we need to put "GENERATOR" into the name of these
macros, because the generators are now the fundamental method with
which to get parameterized tests. We don't need to state the obvious,
in favor of some brevity.
> + * @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 */
Thanks,
-- Marco
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v3 1/2] kunit: Support for Parameterized Testing
2020-10-26 23:14 ` [PATCH v3 1/2] kunit: Support for Parameterized Testing Marco Elver
@ 2020-10-27 5:14 ` Arpitha Raghunandan
2020-10-27 7:44 ` Marco Elver
0 siblings, 1 reply; 12+ messages in thread
From: Arpitha Raghunandan @ 2020-10-27 5:14 UTC (permalink / raw)
To: Marco Elver
Cc: Brendan Higgins, skhan, Iurii Zaikin, Theodore Ts'o,
Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK,
KUnit Development, LKML, linux-kernel-mentees, linux-ext4
On 27/10/20 4:44 am, Marco Elver wrote:
> On Mon, 26 Oct 2020 at 19:36, 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.
>>
>> Signed-off-by: Arpitha Raghunandan <98.arpi@gmail.com>
>> Co-developed-by: Marco Elver <elver@google.com>
>> Signed-off-by: Marco Elver <elver@google.com>
>> ---
>> Changes v2->v3:
>> - Modifictaion of generator macro and method
>
> Great to see it worked as expected!
>
>> 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.
>
> What I meant was to give a description of the protocol, so that if
> somebody wanted, they could (without reading the implementation)
> implement their own custom generator without the helper macro.
>
> E.g. something like: "The generator function is used to lazily
> generate a series of arbitrarily typed values that fit into a void*.
> The argument @prev is the previously returned value, which should be
> used to derive the next value; @prev is set to NULL on the initial
> generator call. When no more values are available, the generator must
> return NULL."
>
Oh okay. I am not sure if this is the best place to add documentation for this.
>> + */
>> + 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.
>
> This is only for arrays, which is why I suggested KUNIT_ARRAY_PARAM()
> as the name.
>
> A generator can very well be implemented without an array, so this
> macro name is confusing. In future somebody might want to provide a
> macro that takes a start + end value (and maybe a step value) to
> generate a series of values. That generator could be named
> KUNIT_RANGE_PARAM(name, start, end, step) and gives us a generator
> that is also named name##_gen_params. (If you want to try implementing
> that macro, I'd suggest doing it as a separate patch.)
>
> And I don't think we need to put "GENERATOR" into the name of these
> macros, because the generators are now the fundamental method with
> which to get parameterized tests. We don't need to state the obvious,
> in favor of some brevity.
>
Okay, makes sense. I will change it to KUNIT_ARRAY_PARAM() for the next version.
>> + * @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 */
>
> Thanks,
> -- Marco
>
Thanks!
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v3 1/2] kunit: Support for Parameterized Testing
2020-10-27 5:14 ` Arpitha Raghunandan
@ 2020-10-27 7:44 ` Marco Elver
2020-10-27 7:51 ` Arpitha Raghunandan
0 siblings, 1 reply; 12+ messages in thread
From: Marco Elver @ 2020-10-27 7:44 UTC (permalink / raw)
To: Arpitha Raghunandan
Cc: Brendan Higgins, skhan, Iurii Zaikin, Theodore Ts'o,
Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK,
KUnit Development, LKML, linux-kernel-mentees, linux-ext4
On Tue, 27 Oct 2020 at 06:14, Arpitha Raghunandan <98.arpi@gmail.com> wrote:
[...]
> >> 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.
> >
> > What I meant was to give a description of the protocol, so that if
> > somebody wanted, they could (without reading the implementation)
> > implement their own custom generator without the helper macro.
> >
> > E.g. something like: "The generator function is used to lazily
> > generate a series of arbitrarily typed values that fit into a void*.
> > The argument @prev is the previously returned value, which should be
> > used to derive the next value; @prev is set to NULL on the initial
> > generator call. When no more values are available, the generator must
> > return NULL."
> >
>
> Oh okay. I am not sure if this is the best place to add documentation for this.
I think it doesn't hurt to add, but have a look at the comment above
this struct, which is already a kernel-doc comment. It probably makes
sense to move the comment there to describe the new variable.
Thanks,
-- Marco
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v3 1/2] kunit: Support for Parameterized Testing
2020-10-27 7:44 ` Marco Elver
@ 2020-10-27 7:51 ` Arpitha Raghunandan
0 siblings, 0 replies; 12+ messages in thread
From: Arpitha Raghunandan @ 2020-10-27 7:51 UTC (permalink / raw)
To: Marco Elver
Cc: Brendan Higgins, skhan, Iurii Zaikin, Theodore Ts'o,
Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK,
KUnit Development, LKML, linux-kernel-mentees, linux-ext4
On 27/10/20 1:14 pm, Marco Elver wrote:
> On Tue, 27 Oct 2020 at 06:14, Arpitha Raghunandan <98.arpi@gmail.com> wrote:
> [...]
>>>> 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.
>>>
>>> What I meant was to give a description of the protocol, so that if
>>> somebody wanted, they could (without reading the implementation)
>>> implement their own custom generator without the helper macro.
>>>
>>> E.g. something like: "The generator function is used to lazily
>>> generate a series of arbitrarily typed values that fit into a void*.
>>> The argument @prev is the previously returned value, which should be
>>> used to derive the next value; @prev is set to NULL on the initial
>>> generator call. When no more values are available, the generator must
>>> return NULL."
>>>
>>
>> Oh okay. I am not sure if this is the best place to add documentation for this.
>
> I think it doesn't hurt to add, but have a look at the comment above
> this struct, which is already a kernel-doc comment. It probably makes
> sense to move the comment there to describe the new variable.
>
Alright, I will move the comment there.
> Thanks,
> -- Marco
>
Thanks.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v3 1/2] kunit: Support for Parameterized Testing
2020-10-26 18:35 [PATCH v3 1/2] kunit: Support for Parameterized Testing Arpitha Raghunandan
2020-10-26 18:36 ` [PATCH v3 2/2] fs: ext4: Modify inode-test.c to use KUnit parameterized testing feature Arpitha Raghunandan
2020-10-26 23:14 ` [PATCH v3 1/2] kunit: Support for Parameterized Testing Marco Elver
@ 2020-10-27 7:55 ` Marco Elver
2020-10-27 9:03 ` Marco Elver
3 siblings, 0 replies; 12+ messages in thread
From: Marco Elver @ 2020-10-27 7:55 UTC (permalink / raw)
To: Arpitha Raghunandan
Cc: Brendan Higgins, skhan, Iurii Zaikin, Theodore Ts'o,
Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK,
KUnit Development, LKML, linux-kernel-mentees, linux-ext4
On Mon, 26 Oct 2020 at 19:36, Arpitha Raghunandan <98.arpi@gmail.com> wrote:
[...]
> * 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.
This could mention that the generator function will be suffixed by
"_gen_params".
> + * @prev: a pointer to the previous test parameter, NULL for first parameter.
> + * @array: a user-supplied pointer to an array of test parameters.
> + */
I just noticed this: the interface of this macro does not include
"prev" (which is an argument of the generated function, but not
supplied to this macro; "prev" should hopefully be explained in the
other comment you're adding for the new struct field). So, the
kernel-doc comment here should only list the actual arguments of this
macro, which is only "name" and "array".
> +#define KUNIT_PARAM_GENERATOR(name, array) \
[...]
Thanks,
-- Marco
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v3 1/2] kunit: Support for Parameterized Testing
2020-10-26 18:35 [PATCH v3 1/2] kunit: Support for Parameterized Testing Arpitha Raghunandan
` (2 preceding siblings ...)
2020-10-27 7:55 ` Marco Elver
@ 2020-10-27 9:03 ` Marco Elver
2020-10-27 14:39 ` Arpitha Raghunandan
3 siblings, 1 reply; 12+ messages in thread
From: Marco Elver @ 2020-10-27 9:03 UTC (permalink / raw)
To: Arpitha Raghunandan
Cc: Brendan Higgins, skhan, Iurii Zaikin, Theodore Ts'o,
Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK,
KUnit Development, LKML, linux-kernel-mentees, linux-ext4
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
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v3 1/2] kunit: Support for Parameterized Testing
2020-10-27 9:03 ` Marco Elver
@ 2020-10-27 14:39 ` Arpitha Raghunandan
0 siblings, 0 replies; 12+ messages in thread
From: Arpitha Raghunandan @ 2020-10-27 14:39 UTC (permalink / raw)
To: Marco Elver
Cc: Brendan Higgins, skhan, Iurii Zaikin, Theodore Ts'o,
Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK,
KUnit Development, LKML, linux-kernel-mentees, linux-ext4
On 27/10/20 2:33 pm, Marco Elver wrote:
> 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.
>
Yes, this is the only place param index is used.
>> 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
>
I will make all the suggested changes.
Thanks!
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v3 2/2] fs: ext4: Modify inode-test.c to use KUnit parameterized testing feature
2020-10-26 18:36 ` [PATCH v3 2/2] fs: ext4: Modify inode-test.c to use KUnit parameterized testing feature Arpitha Raghunandan
2020-10-26 20:19 ` kernel test robot
2020-10-26 22:19 ` kernel test robot
@ 2020-10-27 17:33 ` Iurii Zaikin
2 siblings, 0 replies; 12+ messages in thread
From: Iurii Zaikin @ 2020-10-27 17:33 UTC (permalink / raw)
To: Arpitha Raghunandan
Cc: Brendan Higgins, Shuah Khan, Marco Elver, Theodore Ts'o,
Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK,
KUnit Development, Linux Kernel Mailing List,
linux-kernel-mentees, Ext4 Developers List
>
> Modify fs/ext4/inode-test.c to use the parameterized testing
> feature of KUnit.
>
> Signed-off-by: Arpitha Raghunandan <98.arpi@gmail.com>
> ---
> 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),
> {}
> };
>
> --
> 2.25.1
>
Reviewed-by: Iurii Zaikin <yzaikin@google.com>
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2020-10-27 17:34 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-26 18:35 [PATCH v3 1/2] kunit: Support for Parameterized Testing Arpitha Raghunandan
2020-10-26 18:36 ` [PATCH v3 2/2] fs: ext4: Modify inode-test.c to use KUnit parameterized testing feature Arpitha Raghunandan
2020-10-26 20:19 ` kernel test robot
2020-10-26 22:19 ` kernel test robot
2020-10-27 17:33 ` Iurii Zaikin
2020-10-26 23:14 ` [PATCH v3 1/2] kunit: Support for Parameterized Testing Marco Elver
2020-10-27 5:14 ` Arpitha Raghunandan
2020-10-27 7:44 ` Marco Elver
2020-10-27 7:51 ` Arpitha Raghunandan
2020-10-27 7:55 ` Marco Elver
2020-10-27 9:03 ` Marco Elver
2020-10-27 14:39 ` Arpitha Raghunandan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).