[RFC] kunit: Support for Parameterized Testing

42 views
Skip to first unread message

Arpitha Raghunandan

unread,
Sep 20, 2020, 2:40:48 AM9/20/20
to brendan...@google.com, Arpitha Raghunandan, kuni...@googlegroups.com, linux-kern...@lists.linuxfoundation.org
This patch has a basic implementation for adding support for parameterized
testing in KUnit. It is not complete. Currently there is only support
for integer parameters for test cases. I will generalize this to support
other data types as well. I have tested this by making some small changes
to the ext4/inode-test.c test. The main logic of this test hasn't been
changed. However, I have created an integer array of inputs. The test only
shows that these values can be accessed through the kunit struct as shown
by the dmesg output:

# inode_test_xtimestamp_decoding:
Parameterized = 1
# inode_test_xtimestamp_decoding:
a[0][0] = 1 and a[0][1] = 2 and a[1][0] = 3 and a[1][1] = 4

While this does not affect the test, it shows that this initial approach
for parameterized testing works.
Please let me know any suggestions for this approach and how it can be improved.

Signed-off-by: Arpitha Raghunandan <98....@gmail.com>
---
fs/ext4/inode-test.c | 22 +++++++++++++++++++++-
include/kunit/test.h | 11 ++++++++++-
lib/kunit/kunit-test.c | 4 ++--
lib/kunit/test.c | 15 +++++++++++++--
4 files changed, 46 insertions(+), 6 deletions(-)

diff --git a/fs/ext4/inode-test.c b/fs/ext4/inode-test.c
index d62d802c9c12..5ef242f2fef3 100644
--- a/fs/ext4/inode-test.c
+++ b/fs/ext4/inode-test.c
@@ -235,6 +235,11 @@ static void inode_test_xtimestamp_decoding(struct kunit *test)
struct timespec64 timestamp;
int i;

+ kunit_info(test, "\nParameterized = %d\n", test->parameterized);
+ kunit_info(test, "\na[0][0] = %d and a[0][1] = %d and a[1][0] = %d and a[1][1] = %d\n",
+ test->param_values[0][0], test->param_values[0][1],
+ test->param_values[1][0], test->param_values[1][1]);
+
for (i = 0; i < ARRAY_SIZE(test_data); ++i) {
timestamp.tv_sec = get_32bit_time(&test_data[i]);
ext4_decode_extra_time(&timestamp,
@@ -259,8 +264,23 @@ static void inode_test_xtimestamp_decoding(struct kunit *test)
}
}

+int **getParams(void)
+{
+ int *x = (int *)kmalloc(sizeof(int) * 2, GFP_KERNEL);
+ int *y = (int *)kmalloc(sizeof(int) * 2, GFP_KERNEL);
+ int **a = (int **)kmalloc(sizeof(x) * 2, GFP_KERNEL);
+
+ x[0] = 1;
+ x[1] = 2;
+ y[0] = 3;
+ y[1] = 4;
+ a[0] = x;
+ a[1] = y;
+ return a;
+}
+
static struct kunit_case ext4_inode_test_cases[] = {
- KUNIT_CASE(inode_test_xtimestamp_decoding),
+ KUNIT_CASE_PARAM(inode_test_xtimestamp_decoding, getParams),
{}
};

diff --git a/include/kunit/test.h b/include/kunit/test.h
index 59f3144f009a..23e4ff68c4b5 100644
--- a/include/kunit/test.h
+++ b/include/kunit/test.h
@@ -140,6 +140,8 @@ struct kunit;
struct kunit_case {
void (*run_case)(struct kunit *test);
const char *name;
+ bool parameterized;
+ int** (*get_params)(void);

/* private: internal use only. */
bool success;
@@ -162,6 +164,10 @@ static inline char *kunit_status_to_string(bool status)
*/
#define KUNIT_CASE(test_name) { .run_case = test_name, .name = #test_name }

+#define KUNIT_CASE_PARAM(test_name, getparams) { .run_case = test_name, \
+ .name = #test_name, .parameterized = true, \
+ .get_params = getparams }
+
/**
* struct kunit_suite - describes a related collection of &struct kunit_case
*
@@ -206,6 +212,8 @@ struct kunit {
/* private: internal use only. */
const char *name; /* Read only after initialization! */
char *log; /* Points at case log after initialization */
+ bool parameterized;
+ int **param_values;
struct kunit_try_catch try_catch;
/*
* success starts as true, and may only be set to false during a
@@ -224,7 +232,8 @@ struct kunit {
struct list_head resources; /* Protected by lock. */
};

-void kunit_init_test(struct kunit *test, const char *name, char *log);
+void kunit_init_test(struct kunit *test, const char *name, char *log, bool parameterized);
+void kunit_init_param_test(struct kunit *test, struct kunit_case *test_case);

int kunit_run_tests(struct kunit_suite *suite);

diff --git a/lib/kunit/kunit-test.c b/lib/kunit/kunit-test.c
index 69f902440a0e..b79e287ca19b 100644
--- a/lib/kunit/kunit-test.c
+++ b/lib/kunit/kunit-test.c
@@ -134,7 +134,7 @@ static void kunit_resource_test_init_resources(struct kunit *test)
{
struct kunit_test_resource_context *ctx = test->priv;

- kunit_init_test(&ctx->test, "testing_test_init_test", NULL);
+ kunit_init_test(&ctx->test, "testing_test_init_test", NULL, false);

KUNIT_EXPECT_TRUE(test, list_empty(&ctx->test.resources));
}
@@ -370,7 +370,7 @@ static int kunit_resource_test_init(struct kunit *test)

test->priv = ctx;

- kunit_init_test(&ctx->test, "test_test_context", NULL);
+ kunit_init_test(&ctx->test, "test_test_context", NULL, false);

return 0;
}
diff --git a/lib/kunit/test.c b/lib/kunit/test.c
index c36037200310..2e061bfe154d 100644
--- a/lib/kunit/test.c
+++ b/lib/kunit/test.c
@@ -224,7 +224,7 @@ void kunit_do_assertion(struct kunit *test,
}
EXPORT_SYMBOL_GPL(kunit_do_assertion);

-void kunit_init_test(struct kunit *test, const char *name, char *log)
+void kunit_init_test(struct kunit *test, const char *name, char *log, bool parameterized)
{
spin_lock_init(&test->lock);
INIT_LIST_HEAD(&test->resources);
@@ -232,10 +232,19 @@ void kunit_init_test(struct kunit *test, const char *name, char *log)
test->log = log;
if (test->log)
test->log[0] = '\0';
+ test->parameterized = parameterized;
test->success = true;
}
EXPORT_SYMBOL_GPL(kunit_init_test);

+void kunit_init_param_test(struct kunit *test, struct kunit_case *test_case)
+{
+ spin_lock_init(&test->lock);
+ INIT_LIST_HEAD(&test->resources);
+ test->param_values = test_case->get_params();
+}
+EXPORT_SYMBOL_GPL(kunit_init_param_test);
+
/*
* Initializes and runs test case. Does not clean up or do post validations.
*/
@@ -342,7 +351,9 @@ static void kunit_run_case_catch_errors(struct kunit_suite *suite,
struct kunit_try_catch *try_catch;
struct kunit test;

- kunit_init_test(&test, test_case->name, test_case->log);
+ kunit_init_test(&test, test_case->name, test_case->log, test_case->parameterized);
+ if (test_case->parameterized)
+ kunit_init_param_test(&test, test_case);
try_catch = &test.try_catch;

kunit_try_catch_init(try_catch,
--
2.25.1

Brendan Higgins

unread,
Sep 23, 2020, 11:01:52 PM9/23/20
to Arpitha Raghunandan, KUnit Development, linux-kern...@lists.linuxfoundation.org
On Sat, Sep 19, 2020 at 11:40 PM Arpitha Raghunandan <98....@gmail.com> wrote:
>
> This patch has a basic implementation for adding support for parameterized
> testing in KUnit. It is not complete. Currently there is only support
> for integer parameters for test cases. I will generalize this to support
> other data types as well. I have tested this by making some small changes
> to the ext4/inode-test.c test. The main logic of this test hasn't been
> changed. However, I have created an integer array of inputs. The test only
> shows that these values can be accessed through the kunit struct as shown
> by the dmesg output:
>
> # inode_test_xtimestamp_decoding:
> Parameterized = 1
> # inode_test_xtimestamp_decoding:
> a[0][0] = 1 and a[0][1] = 2 and a[1][0] = 3 and a[1][1] = 4
>
> While this does not affect the test, it shows that this initial approach
> for parameterized testing works.
> Please let me know any suggestions for this approach and how it can be improved.
>
> Signed-off-by: Arpitha Raghunandan <98....@gmail.com>

All in all, looks like a good start, but I think we might need a
slightly more concrete example.

> ---
> fs/ext4/inode-test.c | 22 +++++++++++++++++++++-
> include/kunit/test.h | 11 ++++++++++-
> lib/kunit/kunit-test.c | 4 ++--
> lib/kunit/test.c | 15 +++++++++++++--
> 4 files changed, 46 insertions(+), 6 deletions(-)
>
> diff --git a/fs/ext4/inode-test.c b/fs/ext4/inode-test.c

This is maintained by non-KUnit people; this should probably be in
another commit.

> index d62d802c9c12..5ef242f2fef3 100644
> --- a/fs/ext4/inode-test.c
> +++ b/fs/ext4/inode-test.c
> @@ -235,6 +235,11 @@ static void inode_test_xtimestamp_decoding(struct kunit *test)
> struct timespec64 timestamp;
> int i;
>
> + kunit_info(test, "\nParameterized = %d\n", test->parameterized);
> + kunit_info(test, "\na[0][0] = %d and a[0][1] = %d and a[1][0] = %d and a[1][1] = %d\n",
> + test->param_values[0][0], test->param_values[0][1],
> + test->param_values[1][0], test->param_values[1][1]);
> +

These look like debug statements. Did you forget to remove them?
I don't see where you are using this other than in those debug
statements; can we see something more concrete?

Arpitha Raghunandan

unread,
Sep 30, 2020, 10:42:23 AM9/30/20
to brendan...@google.com, ty...@mit.edu, adilger...@dilger.ca, sk...@linuxfoundation.org, Arpitha Raghunandan, kuni...@googlegroups.com, linux-kern...@lists.linuxfoundation.org
This patch has a basic implementation for adding support for
parameterized testing in KUnit. The macro KUNIT_CASE_PARAM takes
in a function pointer to a function that returns the test case
parameters, the number of test cases and the size of each test
case parameter. The get_test_case_parameters() acts as an iterator
and returns one test case parameter each time it is called.


Signed-off-by: Arpitha Raghunandan <98....@gmail.com>
---
Changes v1->v2:
- Parameterized input stored in a void* array
- An iterator method to access the different parameters

include/kunit/test.h | 17 +++++++++++++++++
lib/kunit/test.c | 27 +++++++++++++++++++++++++++
2 files changed, 44 insertions(+)

diff --git a/include/kunit/test.h b/include/kunit/test.h
index 59f3144f009a..d037ba8c3002 100644
--- a/include/kunit/test.h
+++ b/include/kunit/test.h
@@ -140,10 +140,14 @@ struct kunit;
struct kunit_case {
void (*run_case)(struct kunit *test);
const char *name;
+ void* (*get_params)(void);
+ int max_parameters_count;
+ int parameter_size;

/* private: internal use only. */
bool success;
char *log;
+ bool parameterized;
};

static inline char *kunit_status_to_string(bool status)
@@ -162,6 +166,11 @@ static inline char *kunit_status_to_string(bool status)
*/
#define KUNIT_CASE(test_name) { .run_case = test_name, .name = #test_name }

+#define KUNIT_CASE_PARAM(test_name, getparams, count, size) { .run_case = test_name, \
+ .name = #test_name, .parameterized = true, \
+ .get_params = (void* (*)(void))getparams, \
+ .max_parameters_count = count, .parameter_size = size }
+
/**
* struct kunit_suite - describes a related collection of &struct kunit_case
*
@@ -206,6 +215,11 @@ struct kunit {
/* private: internal use only. */
const char *name; /* Read only after initialization! */
char *log; /* Points at case log after initialization */
+ bool parameterized; /* True for parameterized tests */
+ void *param_values; /* Stores the test parameters for parameterized tests */
+ int max_parameters_count; /* Indicates maximum number of parameters for parameterized tests */
+ int iterator_count; /* Used by the iterator method for parameterized tests */
+ int parameter_size; /* Indicates size of a single test case for parameterized tests */
struct kunit_try_catch try_catch;
/*
* success starts as true, and may only be set to false during a
@@ -225,6 +239,7 @@ struct kunit {
};

void kunit_init_test(struct kunit *test, const char *name, char *log);
+void kunit_init_param_test(struct kunit *test, struct kunit_case *test_case);

int kunit_run_tests(struct kunit_suite *suite);

@@ -237,6 +252,8 @@ int __kunit_test_suites_init(struct kunit_suite **suites);

void __kunit_test_suites_exit(struct kunit_suite **suites);

+void *get_test_case_parameters(struct kunit *test);
+
/**
* kunit_test_suites() - used to register one or more &struct kunit_suite
* with KUnit.
diff --git a/lib/kunit/test.c b/lib/kunit/test.c
index c36037200310..c4fd8f729e96 100644
--- a/lib/kunit/test.c
+++ b/lib/kunit/test.c
@@ -236,6 +236,18 @@ void kunit_init_test(struct kunit *test, const char *name, char *log)
}
EXPORT_SYMBOL_GPL(kunit_init_test);

+void kunit_init_param_test(struct kunit *test, struct kunit_case *test_case)
+{
+ spin_lock_init(&test->lock);
+ INIT_LIST_HEAD(&test->resources);
+ test->parameterized = true;
+ test->param_values = (void *)(test_case->get_params());
+ test->max_parameters_count = test_case->max_parameters_count;
+ test->parameter_size = test_case->parameter_size;
+ test->iterator_count = 0;
+}
+EXPORT_SYMBOL_GPL(kunit_init_param_test);
+
/*
* Initializes and runs test case. Does not clean up or do post validations.
*/
@@ -343,6 +355,8 @@ static void kunit_run_case_catch_errors(struct kunit_suite *suite,
struct kunit test;

kunit_init_test(&test, test_case->name, test_case->log);
+ if (test_case->parameterized)
+ kunit_init_param_test(&test, test_case);
try_catch = &test.try_catch;

kunit_try_catch_init(try_catch,
@@ -407,6 +421,19 @@ void __kunit_test_suites_exit(struct kunit_suite **suites)
}
EXPORT_SYMBOL_GPL(__kunit_test_suites_exit);

+/*
+ * Iterator method for the parameterized test cases
+ */
+void *get_test_case_parameters(struct kunit *test)
+{
+ int index = test->iterator_count * test->parameter_size;
+
+ if (test->iterator_count != test->max_parameters_count)
+ test->iterator_count++;
+ return (test->param_values + index);
+}
+EXPORT_SYMBOL_GPL(get_test_case_parameters);
+
/*
* Used for static resources and when a kunit_resource * has been created by
* kunit_alloc_resource(). When an init function is supplied, @data is passed
--
2.25.1

Arpitha Raghunandan

unread,
Sep 30, 2020, 11:22:04 PM9/30/20
to brendan...@google.com, ty...@mit.edu, adilger...@dilger.ca, sk...@linuxfoundation.org, Arpitha Raghunandan, kuni...@googlegroups.com, linux-kern...@lists.linuxfoundation.org
Modifies fs/ext4/inode-test.c to use the parameterized testing
feature of KUnit.

Signed-off-by: Arpitha Raghunandan <98....@gmail.com>
---
fs/ext4/inode-test.c | 65 ++++++++++++++++++++++++++------------------
1 file changed, 39 insertions(+), 26 deletions(-)

diff --git a/fs/ext4/inode-test.c b/fs/ext4/inode-test.c
index d62d802c9c12..f127f9123cc1 100644
--- a/fs/ext4/inode-test.c
+++ b/fs/ext4/inode-test.c
@@ -72,6 +72,8 @@
#define UPPER_BOUND_NONNEG_EXTRA_BITS_1_CASE\
"2446-05-10 Upper bound of 32bit >=0 timestamp. All extra sec bits on"

+#define NUMBER_OF_TESTCASES 16
+
struct timestamp_expectation {
const char *test_case_name;
struct timespec64 expected;
@@ -101,7 +103,40 @@ 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[] = {
+ struct timespec64 timestamp;
+ int i;
+
+ for (i = 0; i < NUMBER_OF_TESTCASES; ++i) {
+ struct timestamp_expectation *test_case = (struct timestamp_expectation *)get_test_case_parameters(test);
+
+ timestamp.tv_sec = get_32bit_time(test_case);
+ ext4_decode_extra_time(&timestamp,
+ cpu_to_le32(test_case->extra_bits));
+
+ KUNIT_EXPECT_EQ_MSG(test,
+ test_case->expected.tv_sec,
+ timestamp.tv_sec,
+ CASE_NAME_FORMAT,
+ test_case->test_case_name,
+ test_case->msb_set,
+ test_case->lower_bound,
+ test_case->extra_bits);
+ KUNIT_EXPECT_EQ_MSG(test,
+ test_case->expected.tv_nsec,
+ timestamp.tv_nsec,
+ CASE_NAME_FORMAT,
+ test_case->test_case_name,
+ test_case->msb_set,
+ test_case->lower_bound,
+ test_case->extra_bits);
+ }
+}
+
+struct timestamp_expectation *get_test_parameters(void)
+{
+ struct timestamp_expectation *test_data = (struct timestamp_expectation *)kmalloc(sizeof(struct timestamp_expectation) * NUMBER_OF_TESTCASES, GFP_KERNEL);
+
+ const struct timestamp_expectation test_data_init[] = {
{
.test_case_name = LOWER_BOUND_NEG_NO_EXTRA_BITS_CASE,
.msb_set = true,
@@ -232,35 +267,13 @@ static void inode_test_xtimestamp_decoding(struct kunit *test)
}
};

- 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(&timestamp,
- cpu_to_le32(test_data[i].extra_bits));
+ memcpy(test_data, test_data_init, sizeof(struct timestamp_expectation) * ARRAY_SIZE(test_data_init));

- 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);
- }
+ return test_data;
}

static struct kunit_case ext4_inode_test_cases[] = {
- KUNIT_CASE(inode_test_xtimestamp_decoding),
+ KUNIT_CASE_PARAM(inode_test_xtimestamp_decoding, get_test_parameters, NUMBER_OF_TESTCASES, sizeof(struct timestamp_expectation)),
{}
};

--
2.25.1

Arpitha Raghunandan

unread,
Oct 3, 2020, 10:50:48 AM10/3/20
to brendan...@google.com, ty...@mit.edu, adilger...@dilger.ca, sk...@linuxfoundation.org, Arpitha Raghunandan, kuni...@googlegroups.com, linux-kern...@lists.linuxfoundation.org
Implementation of support for parameterized testing in KUnit.

Signed-off-by: Arpitha Raghunandan <98....@gmail.com>
---
Changes v2->v3:
- Support for test to run iterating through all parameters added
within the KUnit framework
- The index of the parameter causing test failure is displayed

Changes v1->v2:
- Parameterized input stored in a void* array
- An iterator method to access the different parameters

include/kunit/test.h | 29 +++++++++++++++++++++++++++++
lib/kunit/test.c | 44 +++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 72 insertions(+), 1 deletion(-)

diff --git a/include/kunit/test.h b/include/kunit/test.h
index 59f3144f009a..8e9325b29058 100644
@@ -206,6 +215,23 @@ struct kunit {
/* private: internal use only. */
const char *name; /* Read only after initialization! */
char *log; /* Points at case log after initialization */
+ bool parameterized; /* True for parameterized tests */
+ /* param_values stores the test parameters
+ * for parameterized tests.
+ */
+ void *param_values;
+ /* max_parameters_count indicates maximum number of
+ * parameters for parameterized tests.
+ */
+ int max_parameters_count;
+ /* iterator_count is used by the iterator method
+ * for parameterized tests.
+ */
+ int iterator_count;
+ /* parameter_size indicates size of a single test case
+ * for parameterized tests.
+ */
+ int parameter_size;
struct kunit_try_catch try_catch;
/*
* success starts as true, and may only be set to false during a
@@ -225,6 +251,7 @@ struct kunit {
};

void kunit_init_test(struct kunit *test, const char *name, char *log);
+void kunit_init_param_test(struct kunit *test, struct kunit_case *test_case);

int kunit_run_tests(struct kunit_suite *suite);

@@ -237,6 +264,8 @@ int __kunit_test_suites_init(struct kunit_suite **suites);

void __kunit_test_suites_exit(struct kunit_suite **suites);

+void *get_test_case_parameters(struct kunit *test);
+
/**
* kunit_test_suites() - used to register one or more &struct kunit_suite
* with KUnit.
diff --git a/lib/kunit/test.c b/lib/kunit/test.c
index c36037200310..ae012e65368e 100644
--- a/lib/kunit/test.c
+++ b/lib/kunit/test.c
@@ -142,6 +142,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->iterator_count);
+}
+
static void kunit_print_string_stream(struct kunit *test,
struct string_stream *stream)
{
@@ -182,6 +187,9 @@ static void kunit_fail(struct kunit *test, struct kunit_assert *assert)

assert->format(assert, stream);

+ if (test->parameterized)
+ kunit_print_failed_param(test);
+
kunit_print_string_stream(test, stream);

WARN_ON(string_stream_destroy(stream));
@@ -236,6 +244,18 @@ void kunit_init_test(struct kunit *test, const char *name, char *log)
}
EXPORT_SYMBOL_GPL(kunit_init_test);

+void kunit_init_param_test(struct kunit *test, struct kunit_case *test_case)
+{
+ spin_lock_init(&test->lock);
+ INIT_LIST_HEAD(&test->resources);
+ test->parameterized = true;
+ test->param_values = (void *)(test_case->get_params());
+ test->max_parameters_count = test_case->max_parameters_count;
+ test->parameter_size = test_case->parameter_size;
+ test->iterator_count = 0;
+}
+EXPORT_SYMBOL_GPL(kunit_init_param_test);
+
/*
* Initializes and runs test case. Does not clean up or do post validations.
*/
@@ -254,7 +274,14 @@ static void kunit_run_case_internal(struct kunit *test,
}
}

- test_case->run_case(test);
+ if (!test->parameterized)
+ test_case->run_case(test);
+ else {
+ int i;
+
+ for (i = 0; i < test->max_parameters_count; i++)
+ test_case->run_case(test);
+ }
}

static void kunit_case_internal_cleanup(struct kunit *test)
@@ -343,6 +370,8 @@ static void kunit_run_case_catch_errors(struct kunit_suite *suite,
struct kunit test;

kunit_init_test(&test, test_case->name, test_case->log);
+ if (test_case->parameterized)
+ kunit_init_param_test(&test, test_case);
try_catch = &test.try_catch;

kunit_try_catch_init(try_catch,
@@ -407,6 +436,19 @@ void __kunit_test_suites_exit(struct kunit_suite **suites)

Arpitha Raghunandan

unread,
Oct 3, 2020, 10:51:47 AM10/3/20
to brendan...@google.com, ty...@mit.edu, adilger...@dilger.ca, sk...@linuxfoundation.org, Arpitha Raghunandan, kuni...@googlegroups.com, linux-kern...@lists.linuxfoundation.org
Modifies fs/ext4/inode-test.c to use the parameterized testing
feature of KUnit.

Signed-off-by: Arpitha Raghunandan <98....@gmail.com>
---
fs/ext4/inode-test.c | 69 +++++++++++++++++++++++++++-----------------
1 file changed, 42 insertions(+), 27 deletions(-)

diff --git a/fs/ext4/inode-test.c b/fs/ext4/inode-test.c
index d62d802c9c12..e262fef505b3 100644
--- a/fs/ext4/inode-test.c
+++ b/fs/ext4/inode-test.c
@@ -72,6 +72,8 @@
#define UPPER_BOUND_NONNEG_EXTRA_BITS_1_CASE\
"2446-05-10 Upper bound of 32bit >=0 timestamp. All extra sec bits on"

+#define NUMBER_OF_TESTCASES 16
+
struct timestamp_expectation {
const char *test_case_name;
struct timespec64 expected;
@@ -101,7 +103,39 @@ 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[] = {
+ struct timespec64 timestamp;
+
+ struct timestamp_expectation *test_case =
+ (struct timestamp_expectation *)get_test_case_parameters(test);
+
+ timestamp.tv_sec = get_32bit_time(test_case);
+ ext4_decode_extra_time(&timestamp,
+ cpu_to_le32(test_case->extra_bits));
+
+ KUNIT_EXPECT_EQ_MSG(test,
+ test_case->expected.tv_sec,
+ timestamp.tv_sec,
+ CASE_NAME_FORMAT,
+ test_case->test_case_name,
+ test_case->msb_set,
+ test_case->lower_bound,
+ test_case->extra_bits);
+ KUNIT_EXPECT_EQ_MSG(test,
+ test_case->expected.tv_nsec,
+ timestamp.tv_nsec,
+ CASE_NAME_FORMAT,
+ test_case->test_case_name,
+ test_case->msb_set,
+ test_case->lower_bound,
+ test_case->extra_bits);
+}
+
+struct timestamp_expectation *get_test_parameters(void)
+{
+ struct timestamp_expectation *test_data = (struct timestamp_expectation *)
+ kmalloc(sizeof(struct timestamp_expectation) * NUMBER_OF_TESTCASES, GFP_KERNEL);
+
+ const struct timestamp_expectation test_data_init[] = {
{
.test_case_name = LOWER_BOUND_NEG_NO_EXTRA_BITS_CASE,
.msb_set = true,
@@ -232,35 +266,16 @@ static void inode_test_xtimestamp_decoding(struct kunit *test)
}
};

- 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(&timestamp,
- 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);
- }
+ memcpy(test_data, test_data_init,
+ sizeof(struct timestamp_expectation) * ARRAY_SIZE(test_data_init));
+
+ return test_data;
}

static struct kunit_case ext4_inode_test_cases[] = {
- KUNIT_CASE(inode_test_xtimestamp_decoding),
+ KUNIT_CASE_PARAM(inode_test_xtimestamp_decoding,
+ get_test_parameters, NUMBER_OF_TESTCASES,
+ sizeof(struct timestamp_expectation)),
{}
};

--
2.25.1

Brendan Higgins

unread,
Oct 9, 2020, 2:08:16 PM10/9/20
to Arpitha Raghunandan, Marco Elver, Theodore Ts'o, Andreas Dilger, Shuah Khan, KUnit Development, linux-kern...@lists.linuxfoundation.org
+Marco Elver

Marco, just figured you might want to see and comment on the current
state of parameterized testing.

Arpitha, can you add Marco on to future revisions?

Brendan Higgins

unread,
Oct 9, 2020, 2:20:21 PM10/9/20
to Arpitha Raghunandan, Marco Elver, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, Shuah Khan, KUnit Development, linux-kern...@lists.linuxfoundation.org
Arpitha, please add Iurii on future revisions. He authored this test.
I think test_data or test_parameters makes more sense.
I don't see this get freed anywhere; you can get around it with
kunit_kmalloc. However, I suspect you won't need this at all given my
next comment...

> +
> + const struct timestamp_expectation test_data_init[] = {

Can't you just make the scope of this array global or static and then
just return a pointer to an element in the array?

Brendan Higgins

unread,
Oct 9, 2020, 2:24:01 PM10/9/20
to Arpitha Raghunandan, Theodore Ts'o, Andreas Dilger, Shuah Khan, KUnit Development, linux-kern...@lists.linuxfoundation.org, Marco Elver
On Sat, Oct 3, 2020 at 7:50 AM Arpitha Raghunandan <98....@gmail.com> wrote:
[...]
> @@ -254,7 +274,14 @@ static void kunit_run_case_internal(struct kunit *test,
> }
> }
>
> - test_case->run_case(test);
> + if (!test->parameterized)
> + test_case->run_case(test);
> + else {

Sorry, I just caught this. When you put either the if or else block in
braces; the other should go in braces as well.

> + int i;
> +
> + for (i = 0; i < test->max_parameters_count; i++)
> + test_case->run_case(test);
> + }
> }
>
[...]

Arpitha Raghunandan

unread,
Oct 9, 2020, 2:59:58 PM10/9/20
to Brendan Higgins, Marco Elver, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, Shuah Khan, KUnit Development, linux-kern...@lists.linuxfoundation.org
On 09/10/20 11:50 pm, Brendan Higgins wrote:
> Arpitha, please add Iurii on future revisions. He authored this test.
> Okay!
Yes, this is better. I will make this change.

Arpitha Raghunandan

unread,
Oct 9, 2020, 3:02:32 PM10/9/20
to Brendan Higgins, Theodore Ts'o, Andreas Dilger, Shuah Khan, KUnit Development, linux-kern...@lists.linuxfoundation.org, Marco Elver
On 09/10/20 11:53 pm, Brendan Higgins wrote:
> On Sat, Oct 3, 2020 at 7:50 AM Arpitha Raghunandan <98....@gmail.com> wrote:
> [...]
>> @@ -254,7 +274,14 @@ static void kunit_run_case_internal(struct kunit *test,
>> }
>> }
>>
>> - test_case->run_case(test);
>> + if (!test->parameterized)
>> + test_case->run_case(test);
>> + else {
>
> Sorry, I just caught this. When you put either the if or else block in
> braces; the other should go in braces as well.
>

Okay, I'll fix this.

Arpitha Raghunandan

unread,
Oct 10, 2020, 10:54:45 AM10/10/20
to brendan...@google.com, sk...@linuxfoundation.org, yza...@google.com, el...@google.com, ty...@mit.edu, adilger...@dilger.ca, Arpitha Raghunandan, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org, linux-...@vger.kernel.org
Implementation of support for parameterized testing in KUnit.

Signed-off-by: Arpitha Raghunandan <98....@gmail.com>
---
include/kunit/test.h | 29 +++++++++++++++++++++++++++++
lib/kunit/test.c | 44 +++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 72 insertions(+), 1 deletion(-)

diff --git a/include/kunit/test.h b/include/kunit/test.h
index 59f3144f009a..4740d66269b4 100644
--- a/include/kunit/test.h
+++ b/include/kunit/test.h
@@ -140,10 +140,14 @@ struct kunit;
struct kunit_case {
void (*run_case)(struct kunit *test);
const char *name;
+ void* (*get_params)(void);
+ int max_parameters_count;
+ int parameter_size;

/* private: internal use only. */
bool success;
char *log;
+ bool parameterized;
};

static inline char *kunit_status_to_string(bool status)
@@ -162,6 +166,11 @@ static inline char *kunit_status_to_string(bool status)
*/
#define KUNIT_CASE(test_name) { .run_case = test_name, .name = #test_name }

+#define KUNIT_CASE_PARAM(test_name, getparams, count, size) \
+ { .run_case = test_name, .name = #test_name, \
+ .parameterized = true, .get_params = (void* (*)(void))getparams, \
index c36037200310..ab9e13c81d4a 100644
@@ -254,7 +274,14 @@ static void kunit_run_case_internal(struct kunit *test,
}
}

- test_case->run_case(test);
+ if (!test->parameterized) {
+ test_case->run_case(test);
+ } else {
+ int i;
+
+ for (i = 0; i < test->max_parameters_count; i++)
+ test_case->run_case(test);
+ }
}

Arpitha Raghunandan

unread,
Oct 10, 2020, 10:56:09 AM10/10/20
to brendan...@google.com, sk...@linuxfoundation.org, yza...@google.com, el...@google.com, ty...@mit.edu, adilger...@dilger.ca, Arpitha Raghunandan, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org, linux-...@vger.kernel.org
Modifies fs/ext4/inode-test.c to use the parameterized testing
feature of KUnit.

Signed-off-by: Arpitha Raghunandan <98....@gmail.com>
---
fs/ext4/inode-test.c | 64 +++++++++++++++++++++++++-------------------
1 file changed, 36 insertions(+), 28 deletions(-)

diff --git a/fs/ext4/inode-test.c b/fs/ext4/inode-test.c
index d62d802c9c12..691ef0a4ffe1 100644
--- a/fs/ext4/inode-test.c
+++ b/fs/ext4/inode-test.c
@@ -72,6 +72,8 @@
#define UPPER_BOUND_NONNEG_EXTRA_BITS_1_CASE\
"2446-05-10 Upper bound of 32bit >=0 timestamp. All extra sec bits on"

+#define NUMBER_OF_TESTCASES 16
+
struct timestamp_expectation {
const char *test_case_name;
struct timespec64 expected;
@@ -101,7 +103,36 @@ 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[] = {
+ struct timespec64 timestamp;
+
+ struct timestamp_expectation *test_data =
+ (struct timestamp_expectation *)get_test_case_parameters(test);
+
+ timestamp.tv_sec = get_32bit_time(test_data);
+ ext4_decode_extra_time(&timestamp,
+ cpu_to_le32(test_data->extra_bits));
+
+ KUNIT_EXPECT_EQ_MSG(test,
+ test_data->expected.tv_sec,
+ timestamp.tv_sec,
+ CASE_NAME_FORMAT,
+ test_data->test_case_name,
+ test_data->msb_set,
+ test_data->lower_bound,
+ test_data->extra_bits);
+ KUNIT_EXPECT_EQ_MSG(test,
+ test_data->expected.tv_nsec,
+ timestamp.tv_nsec,
+ CASE_NAME_FORMAT,
+ test_data->test_case_name,
+ test_data->msb_set,
+ test_data->lower_bound,
+ test_data->extra_bits);
+}
+
+struct timestamp_expectation *get_test_parameters(void)
+{
+ static struct timestamp_expectation test_data[] = {
{
.test_case_name = LOWER_BOUND_NEG_NO_EXTRA_BITS_CASE,
.msb_set = true,
@@ -231,36 +262,13 @@ static void inode_test_xtimestamp_decoding(struct kunit *test)
.expected = {.tv_sec = 0x37fffffffLL, .tv_nsec = 0L},
}
};
-

kernel test robot

unread,
Oct 10, 2020, 8:03:46 PM10/10/20
to Arpitha Raghunandan, brendan...@google.com, sk...@linuxfoundation.org, yza...@google.com, el...@google.com, ty...@mit.edu, adilger...@dilger.ca, kbuil...@lists.01.org, clang-bu...@googlegroups.com, Arpitha Raghunandan, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-kern...@lists.linuxfoundation.org
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.9-rc8 next-20201009]
[cannot apply to tytso-fscrypt/master]
[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/20201011-051918
base: https://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git dev
config: arm-randconfig-r031-20201011 (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project 9b5b3050237db3642ed7ab1bdb3ffa2202511b99)
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
# install arm cross compiling tool for clang build
# apt-get install binutils-arm-linux-gnueabi
# https://github.com/0day-ci/linux/commit/0cd253a8f2af3fd4e88c9ec8d7327bb26302c1da
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Arpitha-Raghunandan/kunit-Support-for-Parameterized-Testing/20201011-051918
git checkout 0cd253a8f2af3fd4e88c9ec8d7327bb26302c1da
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <l...@intel.com>

All warnings (new ones prefixed by >>):

>> fs/ext4/inode-test.c:133:31: warning: no previous prototype for function 'get_test_parameters' [-Wmissing-prototypes]
struct timestamp_expectation *get_test_parameters(void)
^
fs/ext4/inode-test.c:133:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
struct timestamp_expectation *get_test_parameters(void)
^
static
1 warning generated.

vim +/get_test_parameters +133 fs/ext4/inode-test.c

132
> 133 struct timestamp_expectation *get_test_parameters(void)
134 {
135 static struct timestamp_expectation test_data[] = {
136 {
137 .test_case_name = LOWER_BOUND_NEG_NO_EXTRA_BITS_CASE,
138 .msb_set = true,
139 .lower_bound = true,
140 .extra_bits = 0,
141 .expected = {.tv_sec = -0x80000000LL, .tv_nsec = 0L},
142 },
143
144 {
145 .test_case_name = UPPER_BOUND_NEG_NO_EXTRA_BITS_CASE,
146 .msb_set = true,
147 .lower_bound = false,
148 .extra_bits = 0,
149 .expected = {.tv_sec = -1LL, .tv_nsec = 0L},
150 },
151
152 {
153 .test_case_name = LOWER_BOUND_NONNEG_NO_EXTRA_BITS_CASE,
154 .msb_set = false,
155 .lower_bound = true,
156 .extra_bits = 0,
157 .expected = {0LL, 0L},
158 },
159
160 {
161 .test_case_name = UPPER_BOUND_NONNEG_NO_EXTRA_BITS_CASE,
162 .msb_set = false,
163 .lower_bound = false,
164 .extra_bits = 0,
165 .expected = {.tv_sec = 0x7fffffffLL, .tv_nsec = 0L},
166 },
167
168 {
169 .test_case_name = LOWER_BOUND_NEG_LO_1_CASE,
170 .msb_set = true,
171 .lower_bound = true,
172 .extra_bits = 1,
173 .expected = {.tv_sec = 0x80000000LL, .tv_nsec = 0L},
174 },
175
176 {
177 .test_case_name = UPPER_BOUND_NEG_LO_1_CASE,
178 .msb_set = true,
179 .lower_bound = false,
180 .extra_bits = 1,
181 .expected = {.tv_sec = 0xffffffffLL, .tv_nsec = 0L},
182 },
183
184 {
185 .test_case_name = LOWER_BOUND_NONNEG_LO_1_CASE,
186 .msb_set = false,
187 .lower_bound = true,
188 .extra_bits = 1,
189 .expected = {.tv_sec = 0x100000000LL, .tv_nsec = 0L},
190 },
191
192 {
193 .test_case_name = UPPER_BOUND_NONNEG_LO_1_CASE,
194 .msb_set = false,
195 .lower_bound = false,
196 .extra_bits = 1,
197 .expected = {.tv_sec = 0x17fffffffLL, .tv_nsec = 0L},
198 },
199
200 {
201 .test_case_name = LOWER_BOUND_NEG_HI_1_CASE,
202 .msb_set = true,
203 .lower_bound = true,
204 .extra_bits = 2,
205 .expected = {.tv_sec = 0x180000000LL, .tv_nsec = 0L},
206 },
207
208 {
209 .test_case_name = UPPER_BOUND_NEG_HI_1_CASE,
210 .msb_set = true,
211 .lower_bound = false,
212 .extra_bits = 2,
213 .expected = {.tv_sec = 0x1ffffffffLL, .tv_nsec = 0L},
214 },
215
216 {
217 .test_case_name = LOWER_BOUND_NONNEG_HI_1_CASE,
218 .msb_set = false,
219 .lower_bound = true,
220 .extra_bits = 2,
221 .expected = {.tv_sec = 0x200000000LL, .tv_nsec = 0L},
222 },
223
224 {
225 .test_case_name = UPPER_BOUND_NONNEG_HI_1_CASE,
226 .msb_set = false,
227 .lower_bound = false,
228 .extra_bits = 2,
229 .expected = {.tv_sec = 0x27fffffffLL, .tv_nsec = 0L},
230 },
231
232 {
233 .test_case_name = UPPER_BOUND_NONNEG_HI_1_NS_1_CASE,
234 .msb_set = false,
235 .lower_bound = false,
236 .extra_bits = 6,
237 .expected = {.tv_sec = 0x27fffffffLL, .tv_nsec = 1L},
238 },
239
240 {
241 .test_case_name = LOWER_BOUND_NONNEG_HI_1_NS_MAX_CASE,
242 .msb_set = false,
243 .lower_bound = true,
244 .extra_bits = 0xFFFFFFFF,
245 .expected = {.tv_sec = 0x300000000LL,
246 .tv_nsec = MAX_NANOSECONDS},
247 },
248
249 {
250 .test_case_name = LOWER_BOUND_NONNEG_EXTRA_BITS_1_CASE,
251 .msb_set = false,
252 .lower_bound = true,
253 .extra_bits = 3,
254 .expected = {.tv_sec = 0x300000000LL, .tv_nsec = 0L},
255 },
256
257 {
258 .test_case_name = UPPER_BOUND_NONNEG_EXTRA_BITS_1_CASE,
259 .msb_set = false,
260 .lower_bound = false,
261 .extra_bits = 3,
262 .expected = {.tv_sec = 0x37fffffffLL, .tv_nsec = 0L},
263 }
264 };
265 return test_data;
266 }
267

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuil...@lists.01.org
.config.gz

kernel test robot

unread,
Oct 11, 2020, 10:08:44 PM10/11/20
to Arpitha Raghunandan, brendan...@google.com, sk...@linuxfoundation.org, yza...@google.com, el...@google.com, ty...@mit.edu, adilger...@dilger.ca, Arpitha Raghunandan, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org, linux-...@vger.kernel.org, 0day robot, l...@lists.01.org
Greeting,

FYI, we noticed the following commit (built with gcc-9):

commit: c89d849f6934c3f3e65a77dfa9734164218a166e ("[PATCH 1/2] kunit: Support for Parameterized Testing")
url: https://github.com/0day-ci/linux/commits/Arpitha-Raghunandan/kunit-Support-for-Parameterized-Testing/20201011-051918
base: https://git.kernel.org/cgit/linux/kernel/git/tytso/ext4.git dev

in testcase: trinity
version: trinity-i386-4d2343bd-1_20200320
with following parameters:

runtime: 300s

test-description: Trinity is a linux system call fuzz tester.
test-url: http://codemonkey.org.uk/projects/trinity/


on test machine: qemu-system-x86_64 -enable-kvm -cpu SandyBridge -smp 2 -m 8G

caused below changes (please refer to attached dmesg/kmsg for entire log/backtrace):


+----------------------------------------+------------+------------+
| | 9cb3701fb5 | c89d849f69 |
+----------------------------------------+------------+------------+
| boot_successes | 8 | 0 |
| boot_failures | 0 | 6 |
| UBSAN:invalid-load_in_lib/kunit/test.c | 0 | 6 |
+----------------------------------------+------------+------------+


If you fix the issue, kindly add following tag
Reported-by: kernel test robot <l...@intel.com>


[ 86.984701] UBSAN: invalid-load in lib/kunit/test.c:277:11
[ 86.986363] load of value 41 is not a valid value for type '_Bool'
[ 86.987708] CPU: 0 PID: 289 Comm: kunit_try_catch Not tainted 5.9.0-rc7-00035-gc89d849f6934c #1
[ 86.989652] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.12.0-1 04/01/2014
[ 86.991492] Call Trace:
[ 86.992176] dump_stack+0x6d/0x99
[ 86.992984] ubsan_epilogue+0x8/0x3e
[ 86.993880] __ubsan_handle_load_invalid_value.cold+0x42/0x47
[ 86.995137] ? _raw_spin_unlock_irqrestore+0x3d/0x40
[ 86.996245] ? lockdep_hardirqs_on_prepare+0xfc/0x1b0
[ 86.997386] kunit_try_run_case.cold+0x10/0x25
[ 86.998432] kunit_generic_run_threadfn_adapter+0xc/0x20
[ 86.999629] kthread+0x107/0x120
[ 87.000457] ? kunit_try_catch_throw+0x20/0x20
[ 87.002254] ? kthread_stop+0x290/0x290
[ 87.003108] ret_from_fork+0x19/0x24
[ 87.003952] ================================================================================
[ 103.329893] ok 1 - inode_test_xtimestamp_decoding
[ 103.329897] ok 1 - ext4_inode_test
[ 103.339337] Btrfs loaded, crc32c=crc32c-intel, integrity-checker=on, ref-verify=on
[ 103.341469] # Subtest: apparmor_policy_unpack
[ 103.341471] 1..30
[ 103.343065] ok 1 - policy_unpack_test_inbounds_when_inbounds
[ 103.343855] ok 2 - policy_unpack_test_inbounds_when_out_of_bounds
[ 103.345393] ok 3 - policy_unpack_test_unpack_array_with_null_name
[ 103.347053] ok 4 - policy_unpack_test_unpack_array_with_name
[ 103.348677] ok 5 - policy_unpack_test_unpack_array_out_of_bounds
[ 103.350201] ok 6 - policy_unpack_test_unpack_blob_with_null_name
[ 103.351867] ok 7 - policy_unpack_test_unpack_blob_with_name
[ 103.353558] ok 8 - policy_unpack_test_unpack_blob_out_of_bounds
[ 103.355165] ok 9 - policy_unpack_test_unpack_nameX_with_null_name
[ 103.356794] ok 10 - policy_unpack_test_unpack_nameX_with_wrong_code
[ 103.358646] ok 11 - policy_unpack_test_unpack_nameX_with_name
[ 103.360375] ok 12 - policy_unpack_test_unpack_nameX_with_wrong_name
[ 103.361921] ok 13 - policy_unpack_test_unpack_str_with_null_name
[ 103.365212] ok 14 - policy_unpack_test_unpack_str_with_name
[ 103.370046] ok 15 - policy_unpack_test_unpack_str_out_of_bounds
[ 103.371617] ok 16 - policy_unpack_test_unpack_strdup_with_null_name
[ 103.373347] ok 17 - policy_unpack_test_unpack_strdup_with_name
[ 103.375023] ok 18 - policy_unpack_test_unpack_strdup_out_of_bounds
[ 103.376544] ok 19 - policy_unpack_test_unpack_u16_chunk_basic
[ 103.378152] ok 20 - policy_unpack_test_unpack_u16_chunk_out_of_bounds_1
[ 103.379736] ok 21 - policy_unpack_test_unpack_u16_chunk_out_of_bounds_2
[ 103.381438] ok 22 - policy_unpack_test_unpack_u32_with_null_name
[ 103.388133] ok 23 - policy_unpack_test_unpack_u32_with_name
[ 103.389767] ok 24 - policy_unpack_test_unpack_u32_out_of_bounds
[ 103.391356] ok 25 - policy_unpack_test_unpack_u64_with_null_name
[ 103.393195] ok 26 - policy_unpack_test_unpack_u64_with_name
[ 103.394780] ok 27 - policy_unpack_test_unpack_u64_out_of_bounds
[ 103.396308] ok 28 - policy_unpack_test_unpack_X_code_match
[ 103.397961] ok 29 - policy_unpack_test_unpack_X_code_mismatch
[ 103.399374] ok 30 - policy_unpack_test_unpack_X_out_of_bounds
[ 103.400753] ok 2 - apparmor_policy_unpack
[ 103.403320] AppArmor: AppArmor sha1 policy hashing enabled
[ 103.410418] ima: No TPM chip found, activating TPM-bypass!
[ 103.411805] ima: Allocated hash algorithm: sha256
[ 103.413187] ima: No architecture policies found
[ 103.416171] # Subtest: kunit-try-catch-test
[ 103.416175] 1..2
[ 105.412314] rcu-torture: rcu_torture_read_exit: Start of episode
[ 105.458748] rcu-torture: rcu_torture_read_exit: End of episode
[ 106.171539] kunit_try_catch (9479) used greatest stack depth: 6392 bytes left
[ 112.831599] kunit_try_catch (26158) used greatest stack depth: 6368 bytes left
[ 119.013165] rcu-torture: rcu_torture_read_exit: Start of episode
[ 119.244274] rcu-torture: rcu_torture_read_exit: End of episode
[ 132.852213] rcu-torture: rcu_torture_read_exit: Start of episode
[ 135.816147] rcu-torture: rcu_torture_read_exit: End of episode
[ 140.942223] rcu-torture: rtc: (ptrval) ver: 1070 tfle: 0 rta: 1071 rtaf: 0 rtf: 1061 rtmbe: 0 rtbe: 0 rtbke: 0 rtbre: 0 rtbf: 0 rtb: 0 nt: 4157 onoff: 0/0:0/0 -1,0:-1,0 0:0 (HZ=100) barrier: 0/0:0 read-exits: 135
[ 140.946168] rcu-torture: Reader Pipe: 9171121 50 0 0 0 0 0 0 0 0 0
[ 140.947629] rcu-torture: Reader Batch: 9170828 343 0 0 0 0 0 0 0 0 0
[ 140.949106] rcu-torture: Free-Block Circulation: 1070 1069 1068 1067 1066 1065 1064 1063 1062 1061 0
[ 149.412890] rcu-torture: rcu_torture_read_exit: Start of episode
[ 149.579098] rcu-torture: rcu_torture_read_exit: End of episode
[ 163.172214] rcu-torture: rcu_torture_read_exit: Start of episode
[ 163.194427] rcu-torture: rcu_torture_read_exit: End of episode
[ 176.782188] rcu-torture: rcu_torture_read_exit: Start of episode
[ 176.818242] rcu-torture: rcu_torture_read_exit: End of episode
[ 180.452640] rcu_torture_fwd_prog_nr: Duration 10026 cver 1689 gps 4385
[ 190.532908] rcu-torture: rcu_torture_read_exit: Start of episode
[ 190.544968] rcu-torture: rcu_torture_read_exit: End of episode
[ 202.383687] rcu-torture: rtc: (ptrval) ver: 2405 tfle: 0 rta: 2405 rtaf: 0 rtf: 2393 rtmbe: 0 rtbe: 0 rtbke: 0 rtbre: 0 rtbf: 0 rtb: 0 nt: 6439 onoff: 0/0:0/0 -1,0:-1,0 0:0 (HZ=100) barrier: 0/0:0 read-exits: 203
[ 202.387918] rcu-torture: Reader Pipe: 14079393 218 0 0 0 0 0 0 0 0 0
[ 202.389371] rcu-torture: Reader Batch: 14078475 1136 0 0 0 0 0 0 0 0 0
[ 202.390876] rcu-torture: Free-Block Circulation: 2404 2404 2403 2402 2401 2399 2398 2397 2394 2393 0
[ 204.212351] rcu-torture: rcu_torture_read_exit: Start of episode
[ 204.231090] rcu-torture: rcu_torture_read_exit: End of episode
[ 219.206128] rcu-torture: rcu_torture_read_exit: Start of episode
[ 219.357586] rcu-torture: rcu_torture_read_exit: End of episode
[ 233.254429] rcu-torture: rcu_torture_read_exit: Start of episode
[ 233.446637] rcu-torture: rcu_torture_read_exit: End of episode
[ 247.252348] rcu-torture: rcu_torture_read_exit: Start of episode
[ 248.612429] rcu-torture: rcu_torture_read_exit: End of episode
[ 262.212257] rcu-torture: rcu_torture_read_exit: Start of episode
[ 262.238186] rcu-torture: rcu_torture_read_exit: End of episode
[ 263.820785] rcu-torture: rtc: (ptrval) ver: 3552 tfle: 0 rta: 3553 rtaf: 0 rtf: 3539 rtmbe: 0 rtbe: 0 rtbke: 0 rtbre: 0 rtbf: 0 rtb: 0 nt: 8461 onoff: 0/0:0/0 -1,0:-1,0 0:0 (HZ=100) barrier: 0/0:0 read-exits: 288
[ 263.841057] rcu-torture: Reader Pipe: 18852184 371 0 0 0 0 0 0 0 0 0
[ 263.842544] rcu-torture: Reader Batch: 18850453 2102 0 0 0 0 0 0 0 0 0
[ 263.844013] rcu-torture: Free-Block Circulation: 3552 3552 3551 3549 3547 3546 3545 3543 3541 3540 0
[ 275.820884] rcu-torture: rcu_torture_read_exit: Start of episode
[ 276.012299] rcu-torture: rcu_torture_read_exit: End of episode
[ 289.572388] rcu-torture: rcu_torture_read_exit: Start of episode


To reproduce:

# build kernel
cd linux
cp config-5.9.0-rc7-00035-gc89d849f6934c .config
make HOSTCC=gcc-9 CC=gcc-9 ARCH=i386 olddefconfig prepare modules_prepare bzImage

git clone https://github.com/intel/lkp-tests.git
cd lkp-tests
bin/lkp qemu -k <bzImage> job-script # job-script is attached in this email



Thanks,
lkp

config-5.9.0-rc7-00035-gc89d849f6934c
job-script
dmesg.xz

Marco Elver

unread,
Oct 12, 2020, 7:01:07 AM10/12/20
to Arpitha Raghunandan, Brendan Higgins, sk...@linuxfoundation.org, yza...@google.com, Theodore Ts'o, Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org, LKML
On Sat, 10 Oct 2020 at 16:54, Arpitha Raghunandan <98....@gmail.com> wrote:
> Implementation of support for parameterized testing in KUnit.
>
> Signed-off-by: Arpitha Raghunandan <98....@gmail.com>
> ---
> include/kunit/test.h | 29 +++++++++++++++++++++++++++++
> lib/kunit/test.c | 44 +++++++++++++++++++++++++++++++++++++++++++-
> 2 files changed, 72 insertions(+), 1 deletion(-)
>
> diff --git a/include/kunit/test.h b/include/kunit/test.h
> index 59f3144f009a..4740d66269b4 100644
> --- a/include/kunit/test.h
> +++ b/include/kunit/test.h
> @@ -140,10 +140,14 @@ struct kunit;
> struct kunit_case {
> void (*run_case)(struct kunit *test);
> const char *name;
> + void* (*get_params)(void);
> + int max_parameters_count;
> + int parameter_size;
>
> /* private: internal use only. */
> bool success;
> char *log;
> + bool parameterized;

Why do you need this bool? Doesn't get_params being non-NULL tell you
if the test case is parameterized?

> };
>
> static inline char *kunit_status_to_string(bool status)
> @@ -162,6 +166,11 @@ static inline char *kunit_status_to_string(bool status)
> */
> #define KUNIT_CASE(test_name) { .run_case = test_name, .name = #test_name }
>
> +#define KUNIT_CASE_PARAM(test_name, getparams, count, size) \
> + { .run_case = test_name, .name = #test_name, \
> + .parameterized = true, .get_params = (void* (*)(void))getparams, \
> + .max_parameters_count = count, .parameter_size = size }
> +

I think this interface is overly complex. For one, if the only purpose
of the getparams function is to return a pointer to some array, then
there are only few cases where I see getparams being a function could
be useful.

Instead, could we make the getparams function behave like a generator?
Because then you do not need count, nor size. Its function signature
would be:

void* (*generate_params)(void* prev_param);

The protocol would be:

- The first call to generate_params is passed prev_param of NULL, and
returns a pointer to the first parameter P[0].

- Every nth successive call to generate_params is passed the previous
parameter P[n-1].

- When no more parameters are available, generate_params returns NULL.

- (generate_params should otherwise be stateless, but this is only
relevant if concurrent calls are expected.)


> /**
> * struct kunit_suite - describes a related collection of &struct kunit_case
> *
> @@ -206,6 +215,23 @@ struct kunit {
> /* private: internal use only. */
> const char *name; /* Read only after initialization! */
> char *log; /* Points at case log after initialization */
> + bool parameterized; /* True for parameterized tests */
> + /* param_values stores the test parameters
> + * for parameterized tests.
> + */
> + void *param_values;
> + /* max_parameters_count indicates maximum number of
> + * parameters for parameterized tests.
> + */
> + int max_parameters_count;
> + /* iterator_count is used by the iterator method
> + * for parameterized tests.
> + */
> + int iterator_count;
> + /* parameter_size indicates size of a single test case
> + * for parameterized tests.
> + */
> + int parameter_size;

All of this would become much simpler if you used the generator
approach. Likely only 1 field would be required, which is the current
param.
With a generator approach, here you'd call generate_params. Most
likely, you'll need to stash its result somewhere, e.g. test->param,
so it can be retrieved by the test case.

> + }
> }
>
> static void kunit_case_internal_cleanup(struct kunit *test)
> @@ -343,6 +370,8 @@ static void kunit_run_case_catch_errors(struct kunit_suite *suite,
> struct kunit test;
>
> kunit_init_test(&test, test_case->name, test_case->log);
> + if (test_case->parameterized)
> + kunit_init_param_test(&test, test_case);
> try_catch = &test.try_catch;
>
> kunit_try_catch_init(try_catch,
> @@ -407,6 +436,19 @@ void __kunit_test_suites_exit(struct kunit_suite **suites)
> }
> EXPORT_SYMBOL_GPL(__kunit_test_suites_exit);
>
> +/*
> + * Iterator method for the parameterized test cases
> + */
> +void *get_test_case_parameters(struct kunit *test)
> +{
> + int index = test->iterator_count * test->parameter_size;
> +
> + if (test->iterator_count != test->max_parameters_count)
> + test->iterator_count++;

This is quite confusing, because if get_test_case_parameters is called
multiple times within the same test case, we'll iterate through all
the test case params in the same test case? I think this function
should not have side-effects (like normal getters).

But if you use the generator approach, you'll likely not need this
function anyway.

> + return (test->param_values + index);

Braces not needed.

Iurii Zaikin

unread,
Oct 12, 2020, 12:53:56 PM10/12/20
to Arpitha Raghunandan, Brendan Higgins, Marco Elver, Theodore Ts'o, Andreas Dilger, Shuah Khan, KUnit Development, linux-kern...@lists.linuxfoundation.org
Thanks for modernizing the test!

> >> +#define NUMBER_OF_TESTCASES 16
If you move the test case array outside the function body, you won't
need this because you'll be able to use ARRAY_SIZE.
Although it could be argued that the get_test_case_parameters
interface should provide the array length to go with the array itself.


> >> +struct timestamp_expectation *get_test_parameters(void)
static?

Arpitha Raghunandan

unread,
Oct 15, 2020, 1:28:19 AM10/15/20
to Marco Elver, Brendan Higgins, sk...@linuxfoundation.org, yza...@google.com, Theodore Ts'o, Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org, LKML
>Yeah, this will.
The generator approach sounds good. I will work on it for the next version.

>> + return (test->param_values + index);
>
> Braces not needed.
>
I will fix this.

Arpitha Raghunandan

unread,
Oct 23, 2020, 11:06:10 AM10/23/20
to brendan...@google.com, sk...@linuxfoundation.org, el...@google.com, yza...@google.com, ty...@mit.edu, adilger...@dilger.ca, Arpitha Raghunandan, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-...@vger.kernel.org, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
Implementation of support for parameterized testing in KUnit.

Signed-off-by: Arpitha Raghunandan <98....@gmail.com>
---
Changes v1->v2:
- Use of a generator method to access test case parameters

include/kunit/test.h | 45 ++++++++++++++++++++++++++++++++++++++++++++
lib/kunit/test.c | 20 +++++++++++++++++++-
2 files changed, 64 insertions(+), 1 deletion(-)

diff --git a/include/kunit/test.h b/include/kunit/test.h
index a423fffefea0..c417ac140326 100644
--- a/include/kunit/test.h
+++ b/include/kunit/test.h
@@ -141,6 +141,7 @@ struct kunit;
struct kunit_case {
void (*run_case)(struct kunit *test);
const char *name;
+ void* (*generate_params)(struct kunit *test, void *prev);

/* private: internal use only. */
bool success;
@@ -162,6 +163,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 +212,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 +1755,36 @@ do { \
fmt, \
##__VA_ARGS__)

+/**
+ * kunit_param_generator_helper() - Helper method for test parameter generators
+ * required in parameterized tests.
+ * @test: The test context object.
+ * @prev_param: a pointer to the previous test parameter, NULL for first parameter.
+ * @param_array: a user-supplied pointer to an array of test parameters.
+ * @array_size: number of test parameters in the array.
+ * @type_size: size of one test parameter.
+ */
+static inline void *kunit_param_generator_helper(struct kunit *test,
+ void *prev_param,
+ void *param_array,
+ size_t array_size,
+ size_t type_size)
+{
+ KUNIT_ASSERT_EQ(test, (prev_param - param_array) % type_size, 0);
+
+ if (!prev_param)
+ return param_array;
+
+ KUNIT_ASSERT_GE(test, prev_param, param_array);
+
+ if (prev_param + type_size < param_array + (array_size * type_size))
+ return prev_param + type_size;
+ else
+ return NULL;
+}
+
+#define KUNIT_PARAM_GENERATOR_HELPER(test, prev_param, param_array, param_type) \
+ kunit_param_generator_helper(test, prev_param, param_array, \
+ ARRAY_SIZE(param_array), sizeof(param_type))
+
#endif /* _KUNIT_TEST_H */
diff --git a/lib/kunit/test.c b/lib/kunit/test.c
index 750704abe89a..0e6ffe6384a7 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(test, NULL);
+ test->current_param = 0;
+
+ while (test->param_values) {
+ test_case->run_case(test);
+ test->param_values = test_case->generate_params(test, test->param_values);
+ test->current_param++;
+ }
+ }
}

static void kunit_case_internal_cleanup(struct kunit *test)
--
2.25.1

Arpitha Raghunandan

unread,
Oct 23, 2020, 11:07:01 AM10/23/20
to brendan...@google.com, sk...@linuxfoundation.org, el...@google.com, yza...@google.com, ty...@mit.edu, adilger...@dilger.ca, Arpitha Raghunandan, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-...@vger.kernel.org, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
Modify fs/ext4/inode-test.c to use the parameterized testing
feature of KUnit.

Signed-off-by: Arpitha Raghunandan <98....@gmail.com>
---
Changes v1->v2:
- Modification based on latest implementation of KUnit parameterized testing

fs/ext4/inode-test.c | 318 ++++++++++++++++++++++---------------------
1 file changed, 162 insertions(+), 156 deletions(-)

diff --git a/fs/ext4/inode-test.c b/fs/ext4/inode-test.c
index d62d802c9c12..611a1cf2581d 100644
--- a/fs/ext4/inode-test.c
+++ b/fs/ext4/inode-test.c
@@ -80,6 +80,137 @@ struct timestamp_expectation {
bool lower_bound;
};

+static struct timestamp_expectation test_data[] = {
+ {
+ .test_case_name = LOWER_BOUND_NEG_NO_EXTRA_BITS_CASE,
+ .msb_set = true,
+ .lower_bound = true,
+ .extra_bits = 0,
+ .expected = {.tv_sec = -0x80000000LL, .tv_nsec = 0L},
+ },
+
+ {
+ .test_case_name = UPPER_BOUND_NEG_NO_EXTRA_BITS_CASE,
+ .msb_set = true,
+ .lower_bound = false,
+ .extra_bits = 0,
+ .expected = {.tv_sec = -1LL, .tv_nsec = 0L},
+ },
+
+ {
+ .test_case_name = LOWER_BOUND_NONNEG_NO_EXTRA_BITS_CASE,
+ .msb_set = false,
+ .lower_bound = true,
+ .extra_bits = 0,
+ .expected = {0LL, 0L},
+ },
+
+ {
+ .test_case_name = UPPER_BOUND_NONNEG_NO_EXTRA_BITS_CASE,
+ .msb_set = false,
+ .lower_bound = false,
+ .extra_bits = 0,
+ .expected = {.tv_sec = 0x7fffffffLL, .tv_nsec = 0L},
+ },
+
+ {
+ .test_case_name = LOWER_BOUND_NEG_LO_1_CASE,
+ .msb_set = true,
+ .lower_bound = true,
+ .extra_bits = 1,
+ .expected = {.tv_sec = 0x80000000LL, .tv_nsec = 0L},
+ },
+
+ {
+ .test_case_name = UPPER_BOUND_NEG_LO_1_CASE,
+ .msb_set = true,
+ .lower_bound = false,
+ .extra_bits = 1,
+ .expected = {.tv_sec = 0xffffffffLL, .tv_nsec = 0L},
+ },
+
+ {
+ .test_case_name = LOWER_BOUND_NONNEG_LO_1_CASE,
+ .msb_set = false,
+ .lower_bound = true,
+ .extra_bits = 1,
+ .expected = {.tv_sec = 0x100000000LL, .tv_nsec = 0L},
+ },
+
+ {
+ .test_case_name = UPPER_BOUND_NONNEG_LO_1_CASE,
+ .msb_set = false,
+ .lower_bound = false,
+ .extra_bits = 1,
+ .expected = {.tv_sec = 0x17fffffffLL, .tv_nsec = 0L},
+ },
+
+ {
+ .test_case_name = LOWER_BOUND_NEG_HI_1_CASE,
+ .msb_set = true,
+ .lower_bound = true,
+ .extra_bits = 2,
+ .expected = {.tv_sec = 0x180000000LL, .tv_nsec = 0L},
+ },
+
+ {
+ .test_case_name = UPPER_BOUND_NEG_HI_1_CASE,
+ .msb_set = true,
+ .lower_bound = false,
+ .extra_bits = 2,
+ .expected = {.tv_sec = 0x1ffffffffLL, .tv_nsec = 0L},
+ },
+
+ {
+ .test_case_name = LOWER_BOUND_NONNEG_HI_1_CASE,
+ .msb_set = false,
+ .lower_bound = true,
+ .extra_bits = 2,
+ .expected = {.tv_sec = 0x200000000LL, .tv_nsec = 0L},
+ },
+
+ {
+ .test_case_name = UPPER_BOUND_NONNEG_HI_1_CASE,
+ .msb_set = false,
+ .lower_bound = false,
+ .extra_bits = 2,
+ .expected = {.tv_sec = 0x27fffffffLL, .tv_nsec = 0L},
+ },
+
+ {
+ .test_case_name = UPPER_BOUND_NONNEG_HI_1_NS_1_CASE,
+ .msb_set = false,
+ .lower_bound = false,
+ .extra_bits = 6,
+ .expected = {.tv_sec = 0x27fffffffLL, .tv_nsec = 1L},
+ },
+
+ {
+ .test_case_name = LOWER_BOUND_NONNEG_HI_1_NS_MAX_CASE,
+ .msb_set = false,
+ .lower_bound = true,
+ .extra_bits = 0xFFFFFFFF,
+ .expected = {.tv_sec = 0x300000000LL,
+ .tv_nsec = MAX_NANOSECONDS},
+ },
+
+ {
+ .test_case_name = LOWER_BOUND_NONNEG_EXTRA_BITS_1_CASE,
+ .msb_set = false,
+ .lower_bound = true,
+ .extra_bits = 3,
+ .expected = {.tv_sec = 0x300000000LL, .tv_nsec = 0L},
+ },
+
+ {
+ .test_case_name = UPPER_BOUND_NONNEG_EXTRA_BITS_1_CASE,
+ .msb_set = false,
+ .lower_bound = false,
+ .extra_bits = 3,
+ .expected = {.tv_sec = 0x37fffffffLL, .tv_nsec = 0L},
+ }
+};
+
static time64_t get_32bit_time(const struct timestamp_expectation * const test)
{
if (test->msb_set) {
@@ -101,166 +232,41 @@ 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 timestamp_expectation *test_param =
+ (struct timestamp_expectation *)(test->param_values);
+
+ timestamp.tv_sec = get_32bit_time(test_param);
+ ext4_decode_extra_time(&timestamp,
+ 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 void *generate_params(struct kunit *test, void *prev)
+{
+ return KUNIT_PARAM_GENERATOR_HELPER(test, prev, test_data,
+ struct timestamp_expectation);
}

static struct kunit_case ext4_inode_test_cases[] = {
- KUNIT_CASE(inode_test_xtimestamp_decoding),
+ KUNIT_CASE_PARAM(inode_test_xtimestamp_decoding, generate_params),
{}
};

--
2.25.1

kernel test robot

unread,
Oct 23, 2020, 1:33:45 PM10/23/20
to Arpitha Raghunandan, brendan...@google.com, sk...@linuxfoundation.org, el...@google.com, yza...@google.com, ty...@mit.edu, adilger...@dilger.ca, kbuil...@lists.01.org, Arpitha Raghunandan, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-...@vger.kernel.org
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.9 next-20201023]
[cannot apply to tytso-fscrypt/master]
[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/20201023-230827
base: https://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git dev
config: x86_64-randconfig-s021-20201023 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
reproduce:
# apt-get install sparse
# sparse version: v0.6.3-17-g2d3af347-dirty
# https://github.com/0day-ci/linux/commit/67c9830f2988a5b2153f7bb05396611947ee6677
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Arpitha-Raghunandan/kunit-Support-for-Parameterized-Testing/20201023-230827
git checkout 67c9830f2988a5b2153f7bb05396611947ee6677
# save the attached .config to linux build tree
make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=x86_64

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <l...@intel.com>


"sparse warnings: (new ones prefixed by >>)"
fs/ext4/inode-test.c: note: in included file:
>> include/kunit/test.h:1732:9: sparse: sparse: incompatible types in comparison expression (different type sizes):
>> include/kunit/test.h:1732:9: sparse: unsigned long *
>> include/kunit/test.h:1732:9: sparse: int *

vim +1732 include/kunit/test.h

73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1147
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1148 #define KUNIT_PTR_NOT_ERR_OR_NULL_ASSERTION(test, assert_type, ptr) \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1149 KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1150 assert_type, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1151 ptr, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1152 NULL)
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1153
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1154 /**
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1155 * KUNIT_EXPECT_TRUE() - Causes a test failure when the expression is not true.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1156 * @test: The test context object.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1157 * @condition: an arbitrary boolean expression. The test fails when this does
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1158 * not evaluate to true.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1159 *
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1160 * This and expectations of the form `KUNIT_EXPECT_*` will cause the test case
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1161 * to fail when the specified condition is not met; however, it will not prevent
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1162 * the test case from continuing to run; this is otherwise known as an
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1163 * *expectation failure*.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1164 */
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1165 #define KUNIT_EXPECT_TRUE(test, condition) \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1166 KUNIT_TRUE_ASSERTION(test, KUNIT_EXPECTATION, condition)
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1167
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1168 #define KUNIT_EXPECT_TRUE_MSG(test, condition, fmt, ...) \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1169 KUNIT_TRUE_MSG_ASSERTION(test, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1170 KUNIT_EXPECTATION, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1171 condition, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1172 fmt, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1173 ##__VA_ARGS__)
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1174
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1175 /**
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1176 * KUNIT_EXPECT_FALSE() - Makes a test failure when the expression is not false.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1177 * @test: The test context object.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1178 * @condition: an arbitrary boolean expression. The test fails when this does
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1179 * not evaluate to false.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1180 *
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1181 * Sets an expectation that @condition evaluates to false. See
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1182 * KUNIT_EXPECT_TRUE() for more information.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1183 */
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1184 #define KUNIT_EXPECT_FALSE(test, condition) \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1185 KUNIT_FALSE_ASSERTION(test, KUNIT_EXPECTATION, condition)
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1186
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1187 #define KUNIT_EXPECT_FALSE_MSG(test, condition, fmt, ...) \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1188 KUNIT_FALSE_MSG_ASSERTION(test, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1189 KUNIT_EXPECTATION, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1190 condition, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1191 fmt, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1192 ##__VA_ARGS__)
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1193
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1194 /**
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1195 * KUNIT_EXPECT_EQ() - Sets an expectation that @left and @right are equal.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1196 * @test: The test context object.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1197 * @left: an arbitrary expression that evaluates to a primitive C type.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1198 * @right: an arbitrary expression that evaluates to a primitive C type.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1199 *
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1200 * Sets an expectation that the values that @left and @right evaluate to are
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1201 * equal. This is semantically equivalent to
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1202 * KUNIT_EXPECT_TRUE(@test, (@left) == (@right)). See KUNIT_EXPECT_TRUE() for
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1203 * more information.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1204 */
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1205 #define KUNIT_EXPECT_EQ(test, left, right) \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1206 KUNIT_BINARY_EQ_ASSERTION(test, KUNIT_EXPECTATION, left, right)
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1207
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1208 #define KUNIT_EXPECT_EQ_MSG(test, left, right, fmt, ...) \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1209 KUNIT_BINARY_EQ_MSG_ASSERTION(test, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1210 KUNIT_EXPECTATION, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1211 left, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1212 right, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1213 fmt, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1214 ##__VA_ARGS__)
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1215
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1216 /**
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1217 * KUNIT_EXPECT_PTR_EQ() - Expects that pointers @left and @right are equal.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1218 * @test: The test context object.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1219 * @left: an arbitrary expression that evaluates to a pointer.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1220 * @right: an arbitrary expression that evaluates to a pointer.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1221 *
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1222 * Sets an expectation that the values that @left and @right evaluate to are
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1223 * equal. This is semantically equivalent to
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1224 * KUNIT_EXPECT_TRUE(@test, (@left) == (@right)). See KUNIT_EXPECT_TRUE() for
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1225 * more information.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1226 */
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1227 #define KUNIT_EXPECT_PTR_EQ(test, left, right) \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1228 KUNIT_BINARY_PTR_EQ_ASSERTION(test, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1229 KUNIT_EXPECTATION, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1230 left, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1231 right)
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1232
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1233 #define KUNIT_EXPECT_PTR_EQ_MSG(test, left, right, fmt, ...) \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1234 KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1235 KUNIT_EXPECTATION, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1236 left, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1237 right, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1238 fmt, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1239 ##__VA_ARGS__)
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1240
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1241 /**
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1242 * KUNIT_EXPECT_NE() - An expectation that @left and @right are not equal.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1243 * @test: The test context object.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1244 * @left: an arbitrary expression that evaluates to a primitive C type.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1245 * @right: an arbitrary expression that evaluates to a primitive C type.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1246 *
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1247 * Sets an expectation that the values that @left and @right evaluate to are not
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1248 * equal. This is semantically equivalent to
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1249 * KUNIT_EXPECT_TRUE(@test, (@left) != (@right)). See KUNIT_EXPECT_TRUE() for
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1250 * more information.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1251 */
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1252 #define KUNIT_EXPECT_NE(test, left, right) \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1253 KUNIT_BINARY_NE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1254
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1255 #define KUNIT_EXPECT_NE_MSG(test, left, right, fmt, ...) \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1256 KUNIT_BINARY_NE_MSG_ASSERTION(test, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1257 KUNIT_EXPECTATION, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1258 left, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1259 right, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1260 fmt, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1261 ##__VA_ARGS__)
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1262
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1263 /**
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1264 * KUNIT_EXPECT_PTR_NE() - Expects that pointers @left and @right are not equal.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1265 * @test: The test context object.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1266 * @left: an arbitrary expression that evaluates to a pointer.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1267 * @right: an arbitrary expression that evaluates to a pointer.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1268 *
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1269 * Sets an expectation that the values that @left and @right evaluate to are not
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1270 * equal. This is semantically equivalent to
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1271 * KUNIT_EXPECT_TRUE(@test, (@left) != (@right)). See KUNIT_EXPECT_TRUE() for
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1272 * more information.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1273 */
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1274 #define KUNIT_EXPECT_PTR_NE(test, left, right) \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1275 KUNIT_BINARY_PTR_NE_ASSERTION(test, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1276 KUNIT_EXPECTATION, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1277 left, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1278 right)
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1279
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1280 #define KUNIT_EXPECT_PTR_NE_MSG(test, left, right, fmt, ...) \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1281 KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1282 KUNIT_EXPECTATION, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1283 left, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1284 right, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1285 fmt, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1286 ##__VA_ARGS__)
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1287
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1288 /**
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1289 * KUNIT_EXPECT_LT() - An expectation that @left is less than @right.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1290 * @test: The test context object.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1291 * @left: an arbitrary expression that evaluates to a primitive C type.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1292 * @right: an arbitrary expression that evaluates to a primitive C type.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1293 *
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1294 * Sets an expectation that the value that @left evaluates to is less than the
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1295 * value that @right evaluates to. This is semantically equivalent to
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1296 * KUNIT_EXPECT_TRUE(@test, (@left) < (@right)). See KUNIT_EXPECT_TRUE() for
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1297 * more information.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1298 */
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1299 #define KUNIT_EXPECT_LT(test, left, right) \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1300 KUNIT_BINARY_LT_ASSERTION(test, KUNIT_EXPECTATION, left, right)
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1301
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1302 #define KUNIT_EXPECT_LT_MSG(test, left, right, fmt, ...) \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1303 KUNIT_BINARY_LT_MSG_ASSERTION(test, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1304 KUNIT_EXPECTATION, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1305 left, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1306 right, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1307 fmt, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1308 ##__VA_ARGS__)
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1309
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1310 /**
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1311 * KUNIT_EXPECT_LE() - Expects that @left is less than or equal to @right.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1312 * @test: The test context object.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1313 * @left: an arbitrary expression that evaluates to a primitive C type.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1314 * @right: an arbitrary expression that evaluates to a primitive C type.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1315 *
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1316 * Sets an expectation that the value that @left evaluates to is less than or
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1317 * equal to the value that @right evaluates to. Semantically this is equivalent
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1318 * to KUNIT_EXPECT_TRUE(@test, (@left) <= (@right)). See KUNIT_EXPECT_TRUE() for
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1319 * more information.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1320 */
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1321 #define KUNIT_EXPECT_LE(test, left, right) \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1322 KUNIT_BINARY_LE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1323
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1324 #define KUNIT_EXPECT_LE_MSG(test, left, right, fmt, ...) \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1325 KUNIT_BINARY_LE_MSG_ASSERTION(test, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1326 KUNIT_EXPECTATION, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1327 left, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1328 right, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1329 fmt, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1330 ##__VA_ARGS__)
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1331
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1332 /**
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1333 * KUNIT_EXPECT_GT() - An expectation that @left is greater than @right.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1334 * @test: The test context object.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1335 * @left: an arbitrary expression that evaluates to a primitive C type.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1336 * @right: an arbitrary expression that evaluates to a primitive C type.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1337 *
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1338 * Sets an expectation that the value that @left evaluates to is greater than
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1339 * the value that @right evaluates to. This is semantically equivalent to
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1340 * KUNIT_EXPECT_TRUE(@test, (@left) > (@right)). See KUNIT_EXPECT_TRUE() for
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1341 * more information.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1342 */
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1343 #define KUNIT_EXPECT_GT(test, left, right) \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1344 KUNIT_BINARY_GT_ASSERTION(test, KUNIT_EXPECTATION, left, right)
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1345
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1346 #define KUNIT_EXPECT_GT_MSG(test, left, right, fmt, ...) \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1347 KUNIT_BINARY_GT_MSG_ASSERTION(test, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1348 KUNIT_EXPECTATION, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1349 left, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1350 right, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1351 fmt, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1352 ##__VA_ARGS__)
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1353
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1354 /**
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1355 * KUNIT_EXPECT_GE() - Expects that @left is greater than or equal to @right.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1356 * @test: The test context object.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1357 * @left: an arbitrary expression that evaluates to a primitive C type.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1358 * @right: an arbitrary expression that evaluates to a primitive C type.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1359 *
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1360 * Sets an expectation that the value that @left evaluates to is greater than
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1361 * the value that @right evaluates to. This is semantically equivalent to
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1362 * KUNIT_EXPECT_TRUE(@test, (@left) >= (@right)). See KUNIT_EXPECT_TRUE() for
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1363 * more information.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1364 */
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1365 #define KUNIT_EXPECT_GE(test, left, right) \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1366 KUNIT_BINARY_GE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1367
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1368 #define KUNIT_EXPECT_GE_MSG(test, left, right, fmt, ...) \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1369 KUNIT_BINARY_GE_MSG_ASSERTION(test, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1370 KUNIT_EXPECTATION, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1371 left, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1372 right, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1373 fmt, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1374 ##__VA_ARGS__)
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1375
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1376 /**
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1377 * KUNIT_EXPECT_STREQ() - Expects that strings @left and @right are equal.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1378 * @test: The test context object.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1379 * @left: an arbitrary expression that evaluates to a null terminated string.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1380 * @right: an arbitrary expression that evaluates to a null terminated string.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1381 *
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1382 * Sets an expectation that the values that @left and @right evaluate to are
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1383 * equal. This is semantically equivalent to
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1384 * KUNIT_EXPECT_TRUE(@test, !strcmp((@left), (@right))). See KUNIT_EXPECT_TRUE()
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1385 * for more information.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1386 */
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1387 #define KUNIT_EXPECT_STREQ(test, left, right) \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1388 KUNIT_BINARY_STR_EQ_ASSERTION(test, KUNIT_EXPECTATION, left, right)
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1389
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1390 #define KUNIT_EXPECT_STREQ_MSG(test, left, right, fmt, ...) \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1391 KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1392 KUNIT_EXPECTATION, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1393 left, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1394 right, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1395 fmt, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1396 ##__VA_ARGS__)
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1397
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1398 /**
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1399 * KUNIT_EXPECT_STRNEQ() - Expects that strings @left and @right are not equal.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1400 * @test: The test context object.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1401 * @left: an arbitrary expression that evaluates to a null terminated string.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1402 * @right: an arbitrary expression that evaluates to a null terminated string.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1403 *
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1404 * Sets an expectation that the values that @left and @right evaluate to are
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1405 * not equal. This is semantically equivalent to
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1406 * KUNIT_EXPECT_TRUE(@test, strcmp((@left), (@right))). See KUNIT_EXPECT_TRUE()
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1407 * for more information.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1408 */
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1409 #define KUNIT_EXPECT_STRNEQ(test, left, right) \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1410 KUNIT_BINARY_STR_NE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1411
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1412 #define KUNIT_EXPECT_STRNEQ_MSG(test, left, right, fmt, ...) \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1413 KUNIT_BINARY_STR_NE_MSG_ASSERTION(test, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1414 KUNIT_EXPECTATION, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1415 left, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1416 right, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1417 fmt, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1418 ##__VA_ARGS__)
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1419
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1420 /**
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1421 * KUNIT_EXPECT_NOT_ERR_OR_NULL() - Expects that @ptr is not null and not err.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1422 * @test: The test context object.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1423 * @ptr: an arbitrary pointer.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1424 *
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1425 * Sets an expectation that the value that @ptr evaluates to is not null and not
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1426 * an errno stored in a pointer. This is semantically equivalent to
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1427 * KUNIT_EXPECT_TRUE(@test, !IS_ERR_OR_NULL(@ptr)). See KUNIT_EXPECT_TRUE() for
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1428 * more information.
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1429 */
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1430 #define KUNIT_EXPECT_NOT_ERR_OR_NULL(test, ptr) \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1431 KUNIT_PTR_NOT_ERR_OR_NULL_ASSERTION(test, KUNIT_EXPECTATION, ptr)
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1432
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1433 #define KUNIT_EXPECT_NOT_ERR_OR_NULL_MSG(test, ptr, fmt, ...) \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1434 KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1435 KUNIT_EXPECTATION, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1436 ptr, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1437 fmt, \
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1438 ##__VA_ARGS__)
73cda7bb8bfb1d4 Brendan Higgins 2019-09-23 1439
e4aea8f8532b55f Brendan Higgins 2019-09-23 1440 #define KUNIT_ASSERT_FAILURE(test, fmt, ...) \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1441 KUNIT_FAIL_ASSERTION(test, KUNIT_ASSERTION, fmt, ##__VA_ARGS__)
e4aea8f8532b55f Brendan Higgins 2019-09-23 1442
e4aea8f8532b55f Brendan Higgins 2019-09-23 1443 /**
e4aea8f8532b55f Brendan Higgins 2019-09-23 1444 * KUNIT_ASSERT_TRUE() - Sets an assertion that @condition is true.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1445 * @test: The test context object.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1446 * @condition: an arbitrary boolean expression. The test fails and aborts when
e4aea8f8532b55f Brendan Higgins 2019-09-23 1447 * this does not evaluate to true.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1448 *
e4aea8f8532b55f Brendan Higgins 2019-09-23 1449 * This and assertions of the form `KUNIT_ASSERT_*` will cause the test case to
e4aea8f8532b55f Brendan Higgins 2019-09-23 1450 * fail *and immediately abort* when the specified condition is not met. Unlike
e4aea8f8532b55f Brendan Higgins 2019-09-23 1451 * an expectation failure, it will prevent the test case from continuing to run;
e4aea8f8532b55f Brendan Higgins 2019-09-23 1452 * this is otherwise known as an *assertion failure*.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1453 */
e4aea8f8532b55f Brendan Higgins 2019-09-23 1454 #define KUNIT_ASSERT_TRUE(test, condition) \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1455 KUNIT_TRUE_ASSERTION(test, KUNIT_ASSERTION, condition)
e4aea8f8532b55f Brendan Higgins 2019-09-23 1456
e4aea8f8532b55f Brendan Higgins 2019-09-23 1457 #define KUNIT_ASSERT_TRUE_MSG(test, condition, fmt, ...) \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1458 KUNIT_TRUE_MSG_ASSERTION(test, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1459 KUNIT_ASSERTION, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1460 condition, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1461 fmt, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1462 ##__VA_ARGS__)
e4aea8f8532b55f Brendan Higgins 2019-09-23 1463
e4aea8f8532b55f Brendan Higgins 2019-09-23 1464 /**
e4aea8f8532b55f Brendan Higgins 2019-09-23 1465 * KUNIT_ASSERT_FALSE() - Sets an assertion that @condition is false.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1466 * @test: The test context object.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1467 * @condition: an arbitrary boolean expression.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1468 *
e4aea8f8532b55f Brendan Higgins 2019-09-23 1469 * Sets an assertion that the value that @condition evaluates to is false. This
e4aea8f8532b55f Brendan Higgins 2019-09-23 1470 * is the same as KUNIT_EXPECT_FALSE(), except it causes an assertion failure
e4aea8f8532b55f Brendan Higgins 2019-09-23 1471 * (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1472 */
e4aea8f8532b55f Brendan Higgins 2019-09-23 1473 #define KUNIT_ASSERT_FALSE(test, condition) \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1474 KUNIT_FALSE_ASSERTION(test, KUNIT_ASSERTION, condition)
e4aea8f8532b55f Brendan Higgins 2019-09-23 1475
e4aea8f8532b55f Brendan Higgins 2019-09-23 1476 #define KUNIT_ASSERT_FALSE_MSG(test, condition, fmt, ...) \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1477 KUNIT_FALSE_MSG_ASSERTION(test, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1478 KUNIT_ASSERTION, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1479 condition, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1480 fmt, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1481 ##__VA_ARGS__)
e4aea8f8532b55f Brendan Higgins 2019-09-23 1482
e4aea8f8532b55f Brendan Higgins 2019-09-23 1483 /**
e4aea8f8532b55f Brendan Higgins 2019-09-23 1484 * KUNIT_ASSERT_EQ() - Sets an assertion that @left and @right are equal.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1485 * @test: The test context object.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1486 * @left: an arbitrary expression that evaluates to a primitive C type.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1487 * @right: an arbitrary expression that evaluates to a primitive C type.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1488 *
e4aea8f8532b55f Brendan Higgins 2019-09-23 1489 * Sets an assertion that the values that @left and @right evaluate to are
e4aea8f8532b55f Brendan Higgins 2019-09-23 1490 * equal. This is the same as KUNIT_EXPECT_EQ(), except it causes an assertion
e4aea8f8532b55f Brendan Higgins 2019-09-23 1491 * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1492 */
e4aea8f8532b55f Brendan Higgins 2019-09-23 1493 #define KUNIT_ASSERT_EQ(test, left, right) \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1494 KUNIT_BINARY_EQ_ASSERTION(test, KUNIT_ASSERTION, left, right)
e4aea8f8532b55f Brendan Higgins 2019-09-23 1495
e4aea8f8532b55f Brendan Higgins 2019-09-23 1496 #define KUNIT_ASSERT_EQ_MSG(test, left, right, fmt, ...) \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1497 KUNIT_BINARY_EQ_MSG_ASSERTION(test, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1498 KUNIT_ASSERTION, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1499 left, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1500 right, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1501 fmt, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1502 ##__VA_ARGS__)
e4aea8f8532b55f Brendan Higgins 2019-09-23 1503
e4aea8f8532b55f Brendan Higgins 2019-09-23 1504 /**
e4aea8f8532b55f Brendan Higgins 2019-09-23 1505 * KUNIT_ASSERT_PTR_EQ() - Asserts that pointers @left and @right are equal.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1506 * @test: The test context object.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1507 * @left: an arbitrary expression that evaluates to a pointer.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1508 * @right: an arbitrary expression that evaluates to a pointer.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1509 *
e4aea8f8532b55f Brendan Higgins 2019-09-23 1510 * Sets an assertion that the values that @left and @right evaluate to are
e4aea8f8532b55f Brendan Higgins 2019-09-23 1511 * equal. This is the same as KUNIT_EXPECT_EQ(), except it causes an assertion
e4aea8f8532b55f Brendan Higgins 2019-09-23 1512 * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1513 */
e4aea8f8532b55f Brendan Higgins 2019-09-23 1514 #define KUNIT_ASSERT_PTR_EQ(test, left, right) \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1515 KUNIT_BINARY_PTR_EQ_ASSERTION(test, KUNIT_ASSERTION, left, right)
e4aea8f8532b55f Brendan Higgins 2019-09-23 1516
e4aea8f8532b55f Brendan Higgins 2019-09-23 1517 #define KUNIT_ASSERT_PTR_EQ_MSG(test, left, right, fmt, ...) \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1518 KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1519 KUNIT_ASSERTION, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1520 left, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1521 right, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1522 fmt, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1523 ##__VA_ARGS__)
e4aea8f8532b55f Brendan Higgins 2019-09-23 1524
e4aea8f8532b55f Brendan Higgins 2019-09-23 1525 /**
e4aea8f8532b55f Brendan Higgins 2019-09-23 1526 * KUNIT_ASSERT_NE() - An assertion that @left and @right are not equal.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1527 * @test: The test context object.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1528 * @left: an arbitrary expression that evaluates to a primitive C type.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1529 * @right: an arbitrary expression that evaluates to a primitive C type.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1530 *
e4aea8f8532b55f Brendan Higgins 2019-09-23 1531 * Sets an assertion that the values that @left and @right evaluate to are not
e4aea8f8532b55f Brendan Higgins 2019-09-23 1532 * equal. This is the same as KUNIT_EXPECT_NE(), except it causes an assertion
e4aea8f8532b55f Brendan Higgins 2019-09-23 1533 * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1534 */
e4aea8f8532b55f Brendan Higgins 2019-09-23 1535 #define KUNIT_ASSERT_NE(test, left, right) \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1536 KUNIT_BINARY_NE_ASSERTION(test, KUNIT_ASSERTION, left, right)
e4aea8f8532b55f Brendan Higgins 2019-09-23 1537
e4aea8f8532b55f Brendan Higgins 2019-09-23 1538 #define KUNIT_ASSERT_NE_MSG(test, left, right, fmt, ...) \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1539 KUNIT_BINARY_NE_MSG_ASSERTION(test, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1540 KUNIT_ASSERTION, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1541 left, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1542 right, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1543 fmt, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1544 ##__VA_ARGS__)
e4aea8f8532b55f Brendan Higgins 2019-09-23 1545
e4aea8f8532b55f Brendan Higgins 2019-09-23 1546 /**
e4aea8f8532b55f Brendan Higgins 2019-09-23 1547 * KUNIT_ASSERT_PTR_NE() - Asserts that pointers @left and @right are not equal.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1548 * KUNIT_ASSERT_PTR_EQ() - Asserts that pointers @left and @right are equal.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1549 * @test: The test context object.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1550 * @left: an arbitrary expression that evaluates to a pointer.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1551 * @right: an arbitrary expression that evaluates to a pointer.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1552 *
e4aea8f8532b55f Brendan Higgins 2019-09-23 1553 * Sets an assertion that the values that @left and @right evaluate to are not
e4aea8f8532b55f Brendan Higgins 2019-09-23 1554 * equal. This is the same as KUNIT_EXPECT_NE(), except it causes an assertion
e4aea8f8532b55f Brendan Higgins 2019-09-23 1555 * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1556 */
e4aea8f8532b55f Brendan Higgins 2019-09-23 1557 #define KUNIT_ASSERT_PTR_NE(test, left, right) \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1558 KUNIT_BINARY_PTR_NE_ASSERTION(test, KUNIT_ASSERTION, left, right)
e4aea8f8532b55f Brendan Higgins 2019-09-23 1559
e4aea8f8532b55f Brendan Higgins 2019-09-23 1560 #define KUNIT_ASSERT_PTR_NE_MSG(test, left, right, fmt, ...) \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1561 KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1562 KUNIT_ASSERTION, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1563 left, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1564 right, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1565 fmt, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1566 ##__VA_ARGS__)
e4aea8f8532b55f Brendan Higgins 2019-09-23 1567 /**
e4aea8f8532b55f Brendan Higgins 2019-09-23 1568 * KUNIT_ASSERT_LT() - An assertion that @left is less than @right.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1569 * @test: The test context object.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1570 * @left: an arbitrary expression that evaluates to a primitive C type.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1571 * @right: an arbitrary expression that evaluates to a primitive C type.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1572 *
e4aea8f8532b55f Brendan Higgins 2019-09-23 1573 * Sets an assertion that the value that @left evaluates to is less than the
e4aea8f8532b55f Brendan Higgins 2019-09-23 1574 * value that @right evaluates to. This is the same as KUNIT_EXPECT_LT(), except
e4aea8f8532b55f Brendan Higgins 2019-09-23 1575 * it causes an assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion
e4aea8f8532b55f Brendan Higgins 2019-09-23 1576 * is not met.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1577 */
e4aea8f8532b55f Brendan Higgins 2019-09-23 1578 #define KUNIT_ASSERT_LT(test, left, right) \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1579 KUNIT_BINARY_LT_ASSERTION(test, KUNIT_ASSERTION, left, right)
e4aea8f8532b55f Brendan Higgins 2019-09-23 1580
e4aea8f8532b55f Brendan Higgins 2019-09-23 1581 #define KUNIT_ASSERT_LT_MSG(test, left, right, fmt, ...) \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1582 KUNIT_BINARY_LT_MSG_ASSERTION(test, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1583 KUNIT_ASSERTION, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1584 left, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1585 right, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1586 fmt, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1587 ##__VA_ARGS__)
e4aea8f8532b55f Brendan Higgins 2019-09-23 1588 /**
e4aea8f8532b55f Brendan Higgins 2019-09-23 1589 * KUNIT_ASSERT_LE() - An assertion that @left is less than or equal to @right.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1590 * @test: The test context object.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1591 * @left: an arbitrary expression that evaluates to a primitive C type.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1592 * @right: an arbitrary expression that evaluates to a primitive C type.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1593 *
e4aea8f8532b55f Brendan Higgins 2019-09-23 1594 * Sets an assertion that the value that @left evaluates to is less than or
e4aea8f8532b55f Brendan Higgins 2019-09-23 1595 * equal to the value that @right evaluates to. This is the same as
e4aea8f8532b55f Brendan Higgins 2019-09-23 1596 * KUNIT_EXPECT_LE(), except it causes an assertion failure (see
e4aea8f8532b55f Brendan Higgins 2019-09-23 1597 * KUNIT_ASSERT_TRUE()) when the assertion is not met.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1598 */
e4aea8f8532b55f Brendan Higgins 2019-09-23 1599 #define KUNIT_ASSERT_LE(test, left, right) \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1600 KUNIT_BINARY_LE_ASSERTION(test, KUNIT_ASSERTION, left, right)
e4aea8f8532b55f Brendan Higgins 2019-09-23 1601
e4aea8f8532b55f Brendan Higgins 2019-09-23 1602 #define KUNIT_ASSERT_LE_MSG(test, left, right, fmt, ...) \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1603 KUNIT_BINARY_LE_MSG_ASSERTION(test, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1604 KUNIT_ASSERTION, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1605 left, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1606 right, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1607 fmt, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1608 ##__VA_ARGS__)
e4aea8f8532b55f Brendan Higgins 2019-09-23 1609
e4aea8f8532b55f Brendan Higgins 2019-09-23 1610 /**
e4aea8f8532b55f Brendan Higgins 2019-09-23 1611 * KUNIT_ASSERT_GT() - An assertion that @left is greater than @right.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1612 * @test: The test context object.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1613 * @left: an arbitrary expression that evaluates to a primitive C type.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1614 * @right: an arbitrary expression that evaluates to a primitive C type.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1615 *
e4aea8f8532b55f Brendan Higgins 2019-09-23 1616 * Sets an assertion that the value that @left evaluates to is greater than the
e4aea8f8532b55f Brendan Higgins 2019-09-23 1617 * value that @right evaluates to. This is the same as KUNIT_EXPECT_GT(), except
e4aea8f8532b55f Brendan Higgins 2019-09-23 1618 * it causes an assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion
e4aea8f8532b55f Brendan Higgins 2019-09-23 1619 * is not met.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1620 */
e4aea8f8532b55f Brendan Higgins 2019-09-23 1621 #define KUNIT_ASSERT_GT(test, left, right) \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1622 KUNIT_BINARY_GT_ASSERTION(test, KUNIT_ASSERTION, left, right)
e4aea8f8532b55f Brendan Higgins 2019-09-23 1623
e4aea8f8532b55f Brendan Higgins 2019-09-23 1624 #define KUNIT_ASSERT_GT_MSG(test, left, right, fmt, ...) \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1625 KUNIT_BINARY_GT_MSG_ASSERTION(test, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1626 KUNIT_ASSERTION, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1627 left, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1628 right, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1629 fmt, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1630 ##__VA_ARGS__)
e4aea8f8532b55f Brendan Higgins 2019-09-23 1631
e4aea8f8532b55f Brendan Higgins 2019-09-23 1632 /**
e4aea8f8532b55f Brendan Higgins 2019-09-23 1633 * KUNIT_ASSERT_GE() - Assertion that @left is greater than or equal to @right.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1634 * @test: The test context object.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1635 * @left: an arbitrary expression that evaluates to a primitive C type.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1636 * @right: an arbitrary expression that evaluates to a primitive C type.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1637 *
e4aea8f8532b55f Brendan Higgins 2019-09-23 1638 * Sets an assertion that the value that @left evaluates to is greater than the
e4aea8f8532b55f Brendan Higgins 2019-09-23 1639 * value that @right evaluates to. This is the same as KUNIT_EXPECT_GE(), except
e4aea8f8532b55f Brendan Higgins 2019-09-23 1640 * it causes an assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion
e4aea8f8532b55f Brendan Higgins 2019-09-23 1641 * is not met.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1642 */
e4aea8f8532b55f Brendan Higgins 2019-09-23 1643 #define KUNIT_ASSERT_GE(test, left, right) \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1644 KUNIT_BINARY_GE_ASSERTION(test, KUNIT_ASSERTION, left, right)
e4aea8f8532b55f Brendan Higgins 2019-09-23 1645
e4aea8f8532b55f Brendan Higgins 2019-09-23 1646 #define KUNIT_ASSERT_GE_MSG(test, left, right, fmt, ...) \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1647 KUNIT_BINARY_GE_MSG_ASSERTION(test, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1648 KUNIT_ASSERTION, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1649 left, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1650 right, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1651 fmt, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1652 ##__VA_ARGS__)
e4aea8f8532b55f Brendan Higgins 2019-09-23 1653
e4aea8f8532b55f Brendan Higgins 2019-09-23 1654 /**
e4aea8f8532b55f Brendan Higgins 2019-09-23 1655 * KUNIT_ASSERT_STREQ() - An assertion that strings @left and @right are equal.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1656 * @test: The test context object.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1657 * @left: an arbitrary expression that evaluates to a null terminated string.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1658 * @right: an arbitrary expression that evaluates to a null terminated string.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1659 *
e4aea8f8532b55f Brendan Higgins 2019-09-23 1660 * Sets an assertion that the values that @left and @right evaluate to are
e4aea8f8532b55f Brendan Higgins 2019-09-23 1661 * equal. This is the same as KUNIT_EXPECT_STREQ(), except it causes an
e4aea8f8532b55f Brendan Higgins 2019-09-23 1662 * assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1663 */
e4aea8f8532b55f Brendan Higgins 2019-09-23 1664 #define KUNIT_ASSERT_STREQ(test, left, right) \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1665 KUNIT_BINARY_STR_EQ_ASSERTION(test, KUNIT_ASSERTION, left, right)
e4aea8f8532b55f Brendan Higgins 2019-09-23 1666
e4aea8f8532b55f Brendan Higgins 2019-09-23 1667 #define KUNIT_ASSERT_STREQ_MSG(test, left, right, fmt, ...) \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1668 KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1669 KUNIT_ASSERTION, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1670 left, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1671 right, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1672 fmt, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1673 ##__VA_ARGS__)
e4aea8f8532b55f Brendan Higgins 2019-09-23 1674
e4aea8f8532b55f Brendan Higgins 2019-09-23 1675 /**
e4aea8f8532b55f Brendan Higgins 2019-09-23 1676 * KUNIT_ASSERT_STRNEQ() - Expects that strings @left and @right are not equal.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1677 * @test: The test context object.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1678 * @left: an arbitrary expression that evaluates to a null terminated string.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1679 * @right: an arbitrary expression that evaluates to a null terminated string.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1680 *
e4aea8f8532b55f Brendan Higgins 2019-09-23 1681 * Sets an expectation that the values that @left and @right evaluate to are
e4aea8f8532b55f Brendan Higgins 2019-09-23 1682 * not equal. This is semantically equivalent to
e4aea8f8532b55f Brendan Higgins 2019-09-23 1683 * KUNIT_ASSERT_TRUE(@test, strcmp((@left), (@right))). See KUNIT_ASSERT_TRUE()
e4aea8f8532b55f Brendan Higgins 2019-09-23 1684 * for more information.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1685 */
e4aea8f8532b55f Brendan Higgins 2019-09-23 1686 #define KUNIT_ASSERT_STRNEQ(test, left, right) \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1687 KUNIT_BINARY_STR_NE_ASSERTION(test, KUNIT_ASSERTION, left, right)
e4aea8f8532b55f Brendan Higgins 2019-09-23 1688
e4aea8f8532b55f Brendan Higgins 2019-09-23 1689 #define KUNIT_ASSERT_STRNEQ_MSG(test, left, right, fmt, ...) \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1690 KUNIT_BINARY_STR_NE_MSG_ASSERTION(test, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1691 KUNIT_ASSERTION, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1692 left, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1693 right, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1694 fmt, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1695 ##__VA_ARGS__)
e4aea8f8532b55f Brendan Higgins 2019-09-23 1696
e4aea8f8532b55f Brendan Higgins 2019-09-23 1697 /**
e4aea8f8532b55f Brendan Higgins 2019-09-23 1698 * KUNIT_ASSERT_NOT_ERR_OR_NULL() - Assertion that @ptr is not null and not err.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1699 * @test: The test context object.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1700 * @ptr: an arbitrary pointer.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1701 *
e4aea8f8532b55f Brendan Higgins 2019-09-23 1702 * Sets an assertion that the value that @ptr evaluates to is not null and not
e4aea8f8532b55f Brendan Higgins 2019-09-23 1703 * an errno stored in a pointer. This is the same as
e4aea8f8532b55f Brendan Higgins 2019-09-23 1704 * KUNIT_EXPECT_NOT_ERR_OR_NULL(), except it causes an assertion failure (see
e4aea8f8532b55f Brendan Higgins 2019-09-23 1705 * KUNIT_ASSERT_TRUE()) when the assertion is not met.
e4aea8f8532b55f Brendan Higgins 2019-09-23 1706 */
e4aea8f8532b55f Brendan Higgins 2019-09-23 1707 #define KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr) \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1708 KUNIT_PTR_NOT_ERR_OR_NULL_ASSERTION(test, KUNIT_ASSERTION, ptr)
e4aea8f8532b55f Brendan Higgins 2019-09-23 1709
e4aea8f8532b55f Brendan Higgins 2019-09-23 1710 #define KUNIT_ASSERT_NOT_ERR_OR_NULL_MSG(test, ptr, fmt, ...) \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1711 KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1712 KUNIT_ASSERTION, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1713 ptr, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1714 fmt, \
e4aea8f8532b55f Brendan Higgins 2019-09-23 1715 ##__VA_ARGS__)
e4aea8f8532b55f Brendan Higgins 2019-09-23 1716
2c09a7974ce3b43 Arpitha Raghunandan 2020-10-23 1717 /**
2c09a7974ce3b43 Arpitha Raghunandan 2020-10-23 1718 * kunit_param_generator_helper() - Helper method for test parameter generators
2c09a7974ce3b43 Arpitha Raghunandan 2020-10-23 1719 * required in parameterized tests.
2c09a7974ce3b43 Arpitha Raghunandan 2020-10-23 1720 * @test: The test context object.
2c09a7974ce3b43 Arpitha Raghunandan 2020-10-23 1721 * @prev_param: a pointer to the previous test parameter, NULL for first parameter.
2c09a7974ce3b43 Arpitha Raghunandan 2020-10-23 1722 * @param_array: a user-supplied pointer to an array of test parameters.
2c09a7974ce3b43 Arpitha Raghunandan 2020-10-23 1723 * @array_size: number of test parameters in the array.
2c09a7974ce3b43 Arpitha Raghunandan 2020-10-23 1724 * @type_size: size of one test parameter.
2c09a7974ce3b43 Arpitha Raghunandan 2020-10-23 1725 */
2c09a7974ce3b43 Arpitha Raghunandan 2020-10-23 1726 static inline void *kunit_param_generator_helper(struct kunit *test,
2c09a7974ce3b43 Arpitha Raghunandan 2020-10-23 1727 void *prev_param,
2c09a7974ce3b43 Arpitha Raghunandan 2020-10-23 1728 void *param_array,
2c09a7974ce3b43 Arpitha Raghunandan 2020-10-23 1729 size_t array_size,
2c09a7974ce3b43 Arpitha Raghunandan 2020-10-23 1730 size_t type_size)
2c09a7974ce3b43 Arpitha Raghunandan 2020-10-23 1731 {
2c09a7974ce3b43 Arpitha Raghunandan 2020-10-23 @1732 KUNIT_ASSERT_EQ(test, (prev_param - param_array) % type_size, 0);
2c09a7974ce3b43 Arpitha Raghunandan 2020-10-23 1733
2c09a7974ce3b43 Arpitha Raghunandan 2020-10-23 1734 if (!prev_param)
2c09a7974ce3b43 Arpitha Raghunandan 2020-10-23 1735 return param_array;
2c09a7974ce3b43 Arpitha Raghunandan 2020-10-23 1736
2c09a7974ce3b43 Arpitha Raghunandan 2020-10-23 1737 KUNIT_ASSERT_GE(test, prev_param, param_array);
2c09a7974ce3b43 Arpitha Raghunandan 2020-10-23 1738
2c09a7974ce3b43 Arpitha Raghunandan 2020-10-23 1739 if (prev_param + type_size < param_array + (array_size * type_size))
2c09a7974ce3b43 Arpitha Raghunandan 2020-10-23 1740 return prev_param + type_size;
2c09a7974ce3b43 Arpitha Raghunandan 2020-10-23 1741 else
2c09a7974ce3b43 Arpitha Raghunandan 2020-10-23 1742 return NULL;
2c09a7974ce3b43 Arpitha Raghunandan 2020-10-23 1743 }
2c09a7974ce3b43 Arpitha Raghunandan 2020-10-23 1744
.config.gz

kernel test robot

unread,
Oct 23, 2020, 2:09:26 PM10/23/20
to Arpitha Raghunandan, brendan...@google.com, sk...@linuxfoundation.org, el...@google.com, yza...@google.com, ty...@mit.edu, adilger...@dilger.ca, kbuil...@lists.01.org, clang-bu...@googlegroups.com, Arpitha Raghunandan, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-...@vger.kernel.org
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.9 next-20201023]
[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/20201023-230827
base: https://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git dev
config: x86_64-randconfig-r015-20201023 (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project 147b9497e79a98a8614b2b5eb4ba653b44f6b6f0)
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
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
# https://github.com/0day-ci/linux/commit/2c09a7974ce3b438845bfafb539513dc91c021b4
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Arpitha-Raghunandan/kunit-Support-for-Parameterized-Testing/20201023-230827
git checkout 2c09a7974ce3b438845bfafb539513dc91c021b4
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <l...@intel.com>

All warnings (new ones prefixed by >>):

In file included from lib/kunit/test.c:9:
>> include/kunit/test.h:1732:2: warning: comparison of distinct pointer types ('typeof (__left) *' (aka 'unsigned long *') and 'typeof (__right) *' (aka 'int *')) [-Wcompare-distinct-pointer-types]
KUNIT_ASSERT_EQ(test, (prev_param - param_array) % type_size, 0);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/kunit/test.h:1494:2: note: expanded from macro 'KUNIT_ASSERT_EQ'
KUNIT_BINARY_EQ_ASSERTION(test, KUNIT_ASSERTION, left, right)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/kunit/test.h:843:2: note: expanded from macro 'KUNIT_BINARY_EQ_ASSERTION'
KUNIT_BINARY_EQ_MSG_ASSERTION(test, \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/kunit/test.h:833:2: note: expanded from macro 'KUNIT_BINARY_EQ_MSG_ASSERTION'
KUNIT_BASE_EQ_MSG_ASSERTION(test, \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/kunit/test.h:744:2: note: expanded from macro 'KUNIT_BASE_EQ_MSG_ASSERTION'
KUNIT_BASE_BINARY_ASSERTION(test, \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/kunit/test.h:720:9: note: expanded from macro 'KUNIT_BASE_BINARY_ASSERTION'
((void)__typecheck(__left, __right)); \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/kernel.h:850:29: note: expanded from macro '__typecheck'
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~
In file included from lib/kunit/test.c:9:
>> include/kunit/test.h:1737:2: warning: incompatible pointer to integer conversion initializing 'long long' with an expression of type 'typeof (prev_param)' (aka 'void *') [-Wint-conversion]
KUNIT_ASSERT_GE(test, prev_param, param_array);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/kunit/test.h:1644:2: note: expanded from macro 'KUNIT_ASSERT_GE'
KUNIT_BINARY_GE_ASSERTION(test, KUNIT_ASSERTION, left, right)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/kunit/test.h:1038:2: note: expanded from macro 'KUNIT_BINARY_GE_ASSERTION'
KUNIT_BINARY_GE_MSG_ASSERTION(test, \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/kunit/test.h:1028:2: note: expanded from macro 'KUNIT_BINARY_GE_MSG_ASSERTION'
KUNIT_BASE_GE_MSG_ASSERTION(test, \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
include/kunit/test.h:729:8: note: expanded from macro 'KUNIT_BASE_BINARY_ASSERTION'
__left, \
^~~~~~
include/kunit/assert.h:238:16: note: expanded from macro 'KUNIT_INIT_BINARY_ASSERT_STRUCT'
.left_value = left_val, \
^~~~~~~~
include/kunit/test.h:622:36: note: expanded from macro 'KUNIT_ASSERTION'
struct assert_class __assertion = INITIALIZER; \
^~~~~~~~~~~
>> include/kunit/test.h:1737:2: warning: incompatible pointer to integer conversion initializing 'long long' with an expression of type 'typeof (param_array)' (aka 'void *') [-Wint-conversion]
KUNIT_ASSERT_GE(test, prev_param, param_array);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/kunit/test.h:1644:2: note: expanded from macro 'KUNIT_ASSERT_GE'
KUNIT_BINARY_GE_ASSERTION(test, KUNIT_ASSERTION, left, right)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/kunit/test.h:1038:2: note: expanded from macro 'KUNIT_BINARY_GE_ASSERTION'
KUNIT_BINARY_GE_MSG_ASSERTION(test, \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/kunit/test.h:1028:2: note: expanded from macro 'KUNIT_BINARY_GE_MSG_ASSERTION'
KUNIT_BASE_GE_MSG_ASSERTION(test, \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
include/kunit/test.h:731:8: note: expanded from macro 'KUNIT_BASE_BINARY_ASSERTION'
__right), \
^~~~~~~
include/kunit/assert.h:240:17: note: expanded from macro 'KUNIT_INIT_BINARY_ASSERT_STRUCT'
.right_value = right_val \
^~~~~~~~~
include/kunit/test.h:622:36: note: expanded from macro 'KUNIT_ASSERTION'
struct assert_class __assertion = INITIALIZER; \
^~~~~~~~~~~
3 warnings generated.
--
In file included from lib/kunit/debugfs.c:10:
>> include/kunit/test.h:1732:2: warning: comparison of distinct pointer types ('typeof (__left) *' (aka 'unsigned long *') and 'typeof (__right) *' (aka 'int *')) [-Wcompare-distinct-pointer-types]
KUNIT_ASSERT_EQ(test, (prev_param - param_array) % type_size, 0);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/kunit/test.h:1494:2: note: expanded from macro 'KUNIT_ASSERT_EQ'
KUNIT_BINARY_EQ_ASSERTION(test, KUNIT_ASSERTION, left, right)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/kunit/test.h:843:2: note: expanded from macro 'KUNIT_BINARY_EQ_ASSERTION'
KUNIT_BINARY_EQ_MSG_ASSERTION(test, \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/kunit/test.h:833:2: note: expanded from macro 'KUNIT_BINARY_EQ_MSG_ASSERTION'
KUNIT_BASE_EQ_MSG_ASSERTION(test, \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/kunit/test.h:744:2: note: expanded from macro 'KUNIT_BASE_EQ_MSG_ASSERTION'
KUNIT_BASE_BINARY_ASSERTION(test, \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/kunit/test.h:720:9: note: expanded from macro 'KUNIT_BASE_BINARY_ASSERTION'
((void)__typecheck(__left, __right)); \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/kernel.h:850:29: note: expanded from macro '__typecheck'
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~
In file included from lib/kunit/debugfs.c:10:
>> include/kunit/test.h:1737:2: warning: incompatible pointer to integer conversion initializing 'long long' with an expression of type 'typeof (prev_param)' (aka 'void *') [-Wint-conversion]
KUNIT_ASSERT_GE(test, prev_param, param_array);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/kunit/test.h:1644:2: note: expanded from macro 'KUNIT_ASSERT_GE'
KUNIT_BINARY_GE_ASSERTION(test, KUNIT_ASSERTION, left, right)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/kunit/test.h:1038:2: note: expanded from macro 'KUNIT_BINARY_GE_ASSERTION'
KUNIT_BINARY_GE_MSG_ASSERTION(test, \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/kunit/test.h:1028:2: note: expanded from macro 'KUNIT_BINARY_GE_MSG_ASSERTION'
KUNIT_BASE_GE_MSG_ASSERTION(test, \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
include/kunit/test.h:729:8: note: expanded from macro 'KUNIT_BASE_BINARY_ASSERTION'
__left, \
^~~~~~
include/kunit/assert.h:238:16: note: expanded from macro 'KUNIT_INIT_BINARY_ASSERT_STRUCT'
.left_value = left_val, \
^~~~~~~~
include/kunit/test.h:622:36: note: expanded from macro 'KUNIT_ASSERTION'
struct assert_class __assertion = INITIALIZER; \
^~~~~~~~~~~
>> include/kunit/test.h:1737:2: warning: incompatible pointer to integer conversion initializing 'long long' with an expression of type 'typeof (param_array)' (aka 'void *') [-Wint-conversion]
KUNIT_ASSERT_GE(test, prev_param, param_array);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/kunit/test.h:1644:2: note: expanded from macro 'KUNIT_ASSERT_GE'
KUNIT_BINARY_GE_ASSERTION(test, KUNIT_ASSERTION, left, right)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/kunit/test.h:1038:2: note: expanded from macro 'KUNIT_BINARY_GE_ASSERTION'
KUNIT_BINARY_GE_MSG_ASSERTION(test, \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/kunit/test.h:1028:2: note: expanded from macro 'KUNIT_BINARY_GE_MSG_ASSERTION'
KUNIT_BASE_GE_MSG_ASSERTION(test, \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
include/kunit/test.h:731:8: note: expanded from macro 'KUNIT_BASE_BINARY_ASSERTION'
__right), \
^~~~~~~
include/kunit/assert.h:240:17: note: expanded from macro 'KUNIT_INIT_BINARY_ASSERT_STRUCT'
.right_value = right_val \
^~~~~~~~~
include/kunit/test.h:622:36: note: expanded from macro 'KUNIT_ASSERTION'
struct assert_class __assertion = INITIALIZER; \
^~~~~~~~~~~
lib/kunit/debugfs.c:28:6: warning: no previous prototype for function 'kunit_debugfs_cleanup' [-Wmissing-prototypes]
void kunit_debugfs_cleanup(void)
^
lib/kunit/debugfs.c:28:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
void kunit_debugfs_cleanup(void)
^
static
lib/kunit/debugfs.c:33:6: warning: no previous prototype for function 'kunit_debugfs_init' [-Wmissing-prototypes]
void kunit_debugfs_init(void)
^
lib/kunit/debugfs.c:33:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
void kunit_debugfs_init(void)
^
static
lib/kunit/debugfs.c:92:6: warning: no previous prototype for function 'kunit_debugfs_create_suite' [-Wmissing-prototypes]
void kunit_debugfs_create_suite(struct kunit_suite *suite)
^
lib/kunit/debugfs.c:92:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
void kunit_debugfs_create_suite(struct kunit_suite *suite)
^
static
lib/kunit/debugfs.c:108:6: warning: no previous prototype for function 'kunit_debugfs_destroy_suite' [-Wmissing-prototypes]
void kunit_debugfs_destroy_suite(struct kunit_suite *suite)
^
lib/kunit/debugfs.c:108:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
void kunit_debugfs_destroy_suite(struct kunit_suite *suite)
^
static
7 warnings generated.

vim +1732 include/kunit/test.h

1147
1148 #define KUNIT_PTR_NOT_ERR_OR_NULL_ASSERTION(test, assert_type, ptr) \
1149 KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \
1150 assert_type, \
1151 ptr, \
1152 NULL)
1153
1154 /**
1155 * KUNIT_EXPECT_TRUE() - Causes a test failure when the expression is not true.
1156 * @test: The test context object.
1157 * @condition: an arbitrary boolean expression. The test fails when this does
1158 * not evaluate to true.
1159 *
1160 * This and expectations of the form `KUNIT_EXPECT_*` will cause the test case
1161 * to fail when the specified condition is not met; however, it will not prevent
1162 * the test case from continuing to run; this is otherwise known as an
1163 * *expectation failure*.
1164 */
1165 #define KUNIT_EXPECT_TRUE(test, condition) \
1166 KUNIT_TRUE_ASSERTION(test, KUNIT_EXPECTATION, condition)
1167
1168 #define KUNIT_EXPECT_TRUE_MSG(test, condition, fmt, ...) \
1169 KUNIT_TRUE_MSG_ASSERTION(test, \
1170 KUNIT_EXPECTATION, \
1171 condition, \
1172 fmt, \
1173 ##__VA_ARGS__)
1174
1175 /**
1176 * KUNIT_EXPECT_FALSE() - Makes a test failure when the expression is not false.
1177 * @test: The test context object.
1178 * @condition: an arbitrary boolean expression. The test fails when this does
1179 * not evaluate to false.
1180 *
1181 * Sets an expectation that @condition evaluates to false. See
1182 * KUNIT_EXPECT_TRUE() for more information.
1183 */
1184 #define KUNIT_EXPECT_FALSE(test, condition) \
1185 KUNIT_FALSE_ASSERTION(test, KUNIT_EXPECTATION, condition)
1186
1187 #define KUNIT_EXPECT_FALSE_MSG(test, condition, fmt, ...) \
1188 KUNIT_FALSE_MSG_ASSERTION(test, \
1189 KUNIT_EXPECTATION, \
1190 condition, \
1191 fmt, \
1192 ##__VA_ARGS__)
1193
1194 /**
1195 * KUNIT_EXPECT_EQ() - Sets an expectation that @left and @right are equal.
1196 * @test: The test context object.
1197 * @left: an arbitrary expression that evaluates to a primitive C type.
1198 * @right: an arbitrary expression that evaluates to a primitive C type.
1199 *
1200 * Sets an expectation that the values that @left and @right evaluate to are
1201 * equal. This is semantically equivalent to
1202 * KUNIT_EXPECT_TRUE(@test, (@left) == (@right)). See KUNIT_EXPECT_TRUE() for
1203 * more information.
1204 */
1205 #define KUNIT_EXPECT_EQ(test, left, right) \
1206 KUNIT_BINARY_EQ_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1207
1208 #define KUNIT_EXPECT_EQ_MSG(test, left, right, fmt, ...) \
1209 KUNIT_BINARY_EQ_MSG_ASSERTION(test, \
1210 KUNIT_EXPECTATION, \
1211 left, \
1212 right, \
1213 fmt, \
1214 ##__VA_ARGS__)
1215
1216 /**
1217 * KUNIT_EXPECT_PTR_EQ() - Expects that pointers @left and @right are equal.
1218 * @test: The test context object.
1219 * @left: an arbitrary expression that evaluates to a pointer.
1220 * @right: an arbitrary expression that evaluates to a pointer.
1221 *
1222 * Sets an expectation that the values that @left and @right evaluate to are
1223 * equal. This is semantically equivalent to
1224 * KUNIT_EXPECT_TRUE(@test, (@left) == (@right)). See KUNIT_EXPECT_TRUE() for
1225 * more information.
1226 */
1227 #define KUNIT_EXPECT_PTR_EQ(test, left, right) \
1228 KUNIT_BINARY_PTR_EQ_ASSERTION(test, \
1229 KUNIT_EXPECTATION, \
1230 left, \
1231 right)
1232
1233 #define KUNIT_EXPECT_PTR_EQ_MSG(test, left, right, fmt, ...) \
1234 KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \
1235 KUNIT_EXPECTATION, \
1236 left, \
1237 right, \
1238 fmt, \
1239 ##__VA_ARGS__)
1240
1241 /**
1242 * KUNIT_EXPECT_NE() - An expectation that @left and @right are not equal.
1243 * @test: The test context object.
1244 * @left: an arbitrary expression that evaluates to a primitive C type.
1245 * @right: an arbitrary expression that evaluates to a primitive C type.
1246 *
1247 * Sets an expectation that the values that @left and @right evaluate to are not
1248 * equal. This is semantically equivalent to
1249 * KUNIT_EXPECT_TRUE(@test, (@left) != (@right)). See KUNIT_EXPECT_TRUE() for
1250 * more information.
1251 */
1252 #define KUNIT_EXPECT_NE(test, left, right) \
1253 KUNIT_BINARY_NE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1254
1255 #define KUNIT_EXPECT_NE_MSG(test, left, right, fmt, ...) \
1256 KUNIT_BINARY_NE_MSG_ASSERTION(test, \
1257 KUNIT_EXPECTATION, \
1258 left, \
1259 right, \
1260 fmt, \
1261 ##__VA_ARGS__)
1262
1263 /**
1264 * KUNIT_EXPECT_PTR_NE() - Expects that pointers @left and @right are not equal.
1265 * @test: The test context object.
1266 * @left: an arbitrary expression that evaluates to a pointer.
1267 * @right: an arbitrary expression that evaluates to a pointer.
1268 *
1269 * Sets an expectation that the values that @left and @right evaluate to are not
1270 * equal. This is semantically equivalent to
1271 * KUNIT_EXPECT_TRUE(@test, (@left) != (@right)). See KUNIT_EXPECT_TRUE() for
1272 * more information.
1273 */
1274 #define KUNIT_EXPECT_PTR_NE(test, left, right) \
1275 KUNIT_BINARY_PTR_NE_ASSERTION(test, \
1276 KUNIT_EXPECTATION, \
1277 left, \
1278 right)
1279
1280 #define KUNIT_EXPECT_PTR_NE_MSG(test, left, right, fmt, ...) \
1281 KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \
1282 KUNIT_EXPECTATION, \
1283 left, \
1284 right, \
1285 fmt, \
1286 ##__VA_ARGS__)
1287
1288 /**
1289 * KUNIT_EXPECT_LT() - An expectation that @left is less than @right.
1290 * @test: The test context object.
1291 * @left: an arbitrary expression that evaluates to a primitive C type.
1292 * @right: an arbitrary expression that evaluates to a primitive C type.
1293 *
1294 * Sets an expectation that the value that @left evaluates to is less than the
1295 * value that @right evaluates to. This is semantically equivalent to
1296 * KUNIT_EXPECT_TRUE(@test, (@left) < (@right)). See KUNIT_EXPECT_TRUE() for
1297 * more information.
1298 */
1299 #define KUNIT_EXPECT_LT(test, left, right) \
1300 KUNIT_BINARY_LT_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1301
1302 #define KUNIT_EXPECT_LT_MSG(test, left, right, fmt, ...) \
1303 KUNIT_BINARY_LT_MSG_ASSERTION(test, \
1304 KUNIT_EXPECTATION, \
1305 left, \
1306 right, \
1307 fmt, \
1308 ##__VA_ARGS__)
1309
1310 /**
1311 * KUNIT_EXPECT_LE() - Expects that @left is less than or equal to @right.
1312 * @test: The test context object.
1313 * @left: an arbitrary expression that evaluates to a primitive C type.
1314 * @right: an arbitrary expression that evaluates to a primitive C type.
1315 *
1316 * Sets an expectation that the value that @left evaluates to is less than or
1317 * equal to the value that @right evaluates to. Semantically this is equivalent
1318 * to KUNIT_EXPECT_TRUE(@test, (@left) <= (@right)). See KUNIT_EXPECT_TRUE() for
1319 * more information.
1320 */
1321 #define KUNIT_EXPECT_LE(test, left, right) \
1322 KUNIT_BINARY_LE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1323
1324 #define KUNIT_EXPECT_LE_MSG(test, left, right, fmt, ...) \
1325 KUNIT_BINARY_LE_MSG_ASSERTION(test, \
1326 KUNIT_EXPECTATION, \
1327 left, \
1328 right, \
1329 fmt, \
1330 ##__VA_ARGS__)
1331
1332 /**
1333 * KUNIT_EXPECT_GT() - An expectation that @left is greater than @right.
1334 * @test: The test context object.
1335 * @left: an arbitrary expression that evaluates to a primitive C type.
1336 * @right: an arbitrary expression that evaluates to a primitive C type.
1337 *
1338 * Sets an expectation that the value that @left evaluates to is greater than
1339 * the value that @right evaluates to. This is semantically equivalent to
1340 * KUNIT_EXPECT_TRUE(@test, (@left) > (@right)). See KUNIT_EXPECT_TRUE() for
1341 * more information.
1342 */
1343 #define KUNIT_EXPECT_GT(test, left, right) \
1344 KUNIT_BINARY_GT_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1345
1346 #define KUNIT_EXPECT_GT_MSG(test, left, right, fmt, ...) \
1347 KUNIT_BINARY_GT_MSG_ASSERTION(test, \
1348 KUNIT_EXPECTATION, \
1349 left, \
1350 right, \
1351 fmt, \
1352 ##__VA_ARGS__)
1353
1354 /**
1355 * KUNIT_EXPECT_GE() - Expects that @left is greater than or equal to @right.
1356 * @test: The test context object.
1357 * @left: an arbitrary expression that evaluates to a primitive C type.
1358 * @right: an arbitrary expression that evaluates to a primitive C type.
1359 *
1360 * Sets an expectation that the value that @left evaluates to is greater than
1361 * the value that @right evaluates to. This is semantically equivalent to
1362 * KUNIT_EXPECT_TRUE(@test, (@left) >= (@right)). See KUNIT_EXPECT_TRUE() for
1363 * more information.
1364 */
1365 #define KUNIT_EXPECT_GE(test, left, right) \
1366 KUNIT_BINARY_GE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1367
1368 #define KUNIT_EXPECT_GE_MSG(test, left, right, fmt, ...) \
1369 KUNIT_BINARY_GE_MSG_ASSERTION(test, \
1370 KUNIT_EXPECTATION, \
1371 left, \
1372 right, \
1373 fmt, \
1374 ##__VA_ARGS__)
1375
1376 /**
1377 * KUNIT_EXPECT_STREQ() - Expects that strings @left and @right are equal.
1378 * @test: The test context object.
1379 * @left: an arbitrary expression that evaluates to a null terminated string.
1380 * @right: an arbitrary expression that evaluates to a null terminated string.
1381 *
1382 * Sets an expectation that the values that @left and @right evaluate to are
1383 * equal. This is semantically equivalent to
1384 * KUNIT_EXPECT_TRUE(@test, !strcmp((@left), (@right))). See KUNIT_EXPECT_TRUE()
1385 * for more information.
1386 */
1387 #define KUNIT_EXPECT_STREQ(test, left, right) \
1388 KUNIT_BINARY_STR_EQ_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1389
1390 #define KUNIT_EXPECT_STREQ_MSG(test, left, right, fmt, ...) \
1391 KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test, \
1392 KUNIT_EXPECTATION, \
1393 left, \
1394 right, \
1395 fmt, \
1396 ##__VA_ARGS__)
1397
1398 /**
1399 * KUNIT_EXPECT_STRNEQ() - Expects that strings @left and @right are not equal.
1400 * @test: The test context object.
1401 * @left: an arbitrary expression that evaluates to a null terminated string.
1402 * @right: an arbitrary expression that evaluates to a null terminated string.
1403 *
1404 * Sets an expectation that the values that @left and @right evaluate to are
1405 * not equal. This is semantically equivalent to
1406 * KUNIT_EXPECT_TRUE(@test, strcmp((@left), (@right))). See KUNIT_EXPECT_TRUE()
1407 * for more information.
1408 */
1409 #define KUNIT_EXPECT_STRNEQ(test, left, right) \
1410 KUNIT_BINARY_STR_NE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1411
1412 #define KUNIT_EXPECT_STRNEQ_MSG(test, left, right, fmt, ...) \
1413 KUNIT_BINARY_STR_NE_MSG_ASSERTION(test, \
1414 KUNIT_EXPECTATION, \
1415 left, \
1416 right, \
1417 fmt, \
1418 ##__VA_ARGS__)
1419
1420 /**
1421 * KUNIT_EXPECT_NOT_ERR_OR_NULL() - Expects that @ptr is not null and not err.
1422 * @test: The test context object.
1423 * @ptr: an arbitrary pointer.
1424 *
1425 * Sets an expectation that the value that @ptr evaluates to is not null and not
1426 * an errno stored in a pointer. This is semantically equivalent to
1427 * KUNIT_EXPECT_TRUE(@test, !IS_ERR_OR_NULL(@ptr)). See KUNIT_EXPECT_TRUE() for
1428 * more information.
1429 */
1430 #define KUNIT_EXPECT_NOT_ERR_OR_NULL(test, ptr) \
1431 KUNIT_PTR_NOT_ERR_OR_NULL_ASSERTION(test, KUNIT_EXPECTATION, ptr)
1432
1433 #define KUNIT_EXPECT_NOT_ERR_OR_NULL_MSG(test, ptr, fmt, ...) \
1434 KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \
1435 KUNIT_EXPECTATION, \
1436 ptr, \
1437 fmt, \
1438 ##__VA_ARGS__)
1439
1440 #define KUNIT_ASSERT_FAILURE(test, fmt, ...) \
1441 KUNIT_FAIL_ASSERTION(test, KUNIT_ASSERTION, fmt, ##__VA_ARGS__)
1442
1443 /**
1444 * KUNIT_ASSERT_TRUE() - Sets an assertion that @condition is true.
1445 * @test: The test context object.
1446 * @condition: an arbitrary boolean expression. The test fails and aborts when
1447 * this does not evaluate to true.
1448 *
1449 * This and assertions of the form `KUNIT_ASSERT_*` will cause the test case to
1450 * fail *and immediately abort* when the specified condition is not met. Unlike
1451 * an expectation failure, it will prevent the test case from continuing to run;
1452 * this is otherwise known as an *assertion failure*.
1453 */
1454 #define KUNIT_ASSERT_TRUE(test, condition) \
1455 KUNIT_TRUE_ASSERTION(test, KUNIT_ASSERTION, condition)
1456
1457 #define KUNIT_ASSERT_TRUE_MSG(test, condition, fmt, ...) \
1458 KUNIT_TRUE_MSG_ASSERTION(test, \
1459 KUNIT_ASSERTION, \
1460 condition, \
1461 fmt, \
1462 ##__VA_ARGS__)
1463
1464 /**
1465 * KUNIT_ASSERT_FALSE() - Sets an assertion that @condition is false.
1466 * @test: The test context object.
1467 * @condition: an arbitrary boolean expression.
1468 *
1469 * Sets an assertion that the value that @condition evaluates to is false. This
1470 * is the same as KUNIT_EXPECT_FALSE(), except it causes an assertion failure
1471 * (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1472 */
1473 #define KUNIT_ASSERT_FALSE(test, condition) \
1474 KUNIT_FALSE_ASSERTION(test, KUNIT_ASSERTION, condition)
1475
1476 #define KUNIT_ASSERT_FALSE_MSG(test, condition, fmt, ...) \
1477 KUNIT_FALSE_MSG_ASSERTION(test, \
1478 KUNIT_ASSERTION, \
1479 condition, \
1480 fmt, \
1481 ##__VA_ARGS__)
1482
1483 /**
1484 * KUNIT_ASSERT_EQ() - Sets an assertion that @left and @right are equal.
1485 * @test: The test context object.
1486 * @left: an arbitrary expression that evaluates to a primitive C type.
1487 * @right: an arbitrary expression that evaluates to a primitive C type.
1488 *
1489 * Sets an assertion that the values that @left and @right evaluate to are
1490 * equal. This is the same as KUNIT_EXPECT_EQ(), except it causes an assertion
1491 * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1492 */
1493 #define KUNIT_ASSERT_EQ(test, left, right) \
1494 KUNIT_BINARY_EQ_ASSERTION(test, KUNIT_ASSERTION, left, right)
1495
1496 #define KUNIT_ASSERT_EQ_MSG(test, left, right, fmt, ...) \
1497 KUNIT_BINARY_EQ_MSG_ASSERTION(test, \
1498 KUNIT_ASSERTION, \
1499 left, \
1500 right, \
1501 fmt, \
1502 ##__VA_ARGS__)
1503
1504 /**
1505 * KUNIT_ASSERT_PTR_EQ() - Asserts that pointers @left and @right are equal.
1506 * @test: The test context object.
1507 * @left: an arbitrary expression that evaluates to a pointer.
1508 * @right: an arbitrary expression that evaluates to a pointer.
1509 *
1510 * Sets an assertion that the values that @left and @right evaluate to are
1511 * equal. This is the same as KUNIT_EXPECT_EQ(), except it causes an assertion
1512 * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1513 */
1514 #define KUNIT_ASSERT_PTR_EQ(test, left, right) \
1515 KUNIT_BINARY_PTR_EQ_ASSERTION(test, KUNIT_ASSERTION, left, right)
1516
1517 #define KUNIT_ASSERT_PTR_EQ_MSG(test, left, right, fmt, ...) \
1518 KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \
1519 KUNIT_ASSERTION, \
1520 left, \
1521 right, \
1522 fmt, \
1523 ##__VA_ARGS__)
1524
1525 /**
1526 * KUNIT_ASSERT_NE() - An assertion that @left and @right are not equal.
1527 * @test: The test context object.
1528 * @left: an arbitrary expression that evaluates to a primitive C type.
1529 * @right: an arbitrary expression that evaluates to a primitive C type.
1530 *
1531 * Sets an assertion that the values that @left and @right evaluate to are not
1532 * equal. This is the same as KUNIT_EXPECT_NE(), except it causes an assertion
1533 * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1534 */
1535 #define KUNIT_ASSERT_NE(test, left, right) \
1536 KUNIT_BINARY_NE_ASSERTION(test, KUNIT_ASSERTION, left, right)
1537
1538 #define KUNIT_ASSERT_NE_MSG(test, left, right, fmt, ...) \
1539 KUNIT_BINARY_NE_MSG_ASSERTION(test, \
1540 KUNIT_ASSERTION, \
1541 left, \
1542 right, \
1543 fmt, \
1544 ##__VA_ARGS__)
1545
1546 /**
1547 * KUNIT_ASSERT_PTR_NE() - Asserts that pointers @left and @right are not equal.
1548 * KUNIT_ASSERT_PTR_EQ() - Asserts that pointers @left and @right are equal.
1549 * @test: The test context object.
1550 * @left: an arbitrary expression that evaluates to a pointer.
1551 * @right: an arbitrary expression that evaluates to a pointer.
1552 *
1553 * Sets an assertion that the values that @left and @right evaluate to are not
1554 * equal. This is the same as KUNIT_EXPECT_NE(), except it causes an assertion
1555 * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1556 */
1557 #define KUNIT_ASSERT_PTR_NE(test, left, right) \
1558 KUNIT_BINARY_PTR_NE_ASSERTION(test, KUNIT_ASSERTION, left, right)
1559
1560 #define KUNIT_ASSERT_PTR_NE_MSG(test, left, right, fmt, ...) \
1561 KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \
1562 KUNIT_ASSERTION, \
1563 left, \
1564 right, \
1565 fmt, \
1566 ##__VA_ARGS__)
1567 /**
1568 * KUNIT_ASSERT_LT() - An assertion that @left is less than @right.
1569 * @test: The test context object.
1570 * @left: an arbitrary expression that evaluates to a primitive C type.
1571 * @right: an arbitrary expression that evaluates to a primitive C type.
1572 *
1573 * Sets an assertion that the value that @left evaluates to is less than the
1574 * value that @right evaluates to. This is the same as KUNIT_EXPECT_LT(), except
1575 * it causes an assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion
1576 * is not met.
1577 */
1578 #define KUNIT_ASSERT_LT(test, left, right) \
1579 KUNIT_BINARY_LT_ASSERTION(test, KUNIT_ASSERTION, left, right)
1580
1581 #define KUNIT_ASSERT_LT_MSG(test, left, right, fmt, ...) \
1582 KUNIT_BINARY_LT_MSG_ASSERTION(test, \
1583 KUNIT_ASSERTION, \
1584 left, \
1585 right, \
1586 fmt, \
1587 ##__VA_ARGS__)
1588 /**
1589 * KUNIT_ASSERT_LE() - An assertion that @left is less than or equal to @right.
1590 * @test: The test context object.
1591 * @left: an arbitrary expression that evaluates to a primitive C type.
1592 * @right: an arbitrary expression that evaluates to a primitive C type.
1593 *
1594 * Sets an assertion that the value that @left evaluates to is less than or
1595 * equal to the value that @right evaluates to. This is the same as
1596 * KUNIT_EXPECT_LE(), except it causes an assertion failure (see
1597 * KUNIT_ASSERT_TRUE()) when the assertion is not met.
1598 */
1599 #define KUNIT_ASSERT_LE(test, left, right) \
1600 KUNIT_BINARY_LE_ASSERTION(test, KUNIT_ASSERTION, left, right)
1601
1602 #define KUNIT_ASSERT_LE_MSG(test, left, right, fmt, ...) \
1603 KUNIT_BINARY_LE_MSG_ASSERTION(test, \
1604 KUNIT_ASSERTION, \
1605 left, \
1606 right, \
1607 fmt, \
1608 ##__VA_ARGS__)
1609
1610 /**
1611 * KUNIT_ASSERT_GT() - An assertion that @left is greater than @right.
1612 * @test: The test context object.
1613 * @left: an arbitrary expression that evaluates to a primitive C type.
1614 * @right: an arbitrary expression that evaluates to a primitive C type.
1615 *
1616 * Sets an assertion that the value that @left evaluates to is greater than the
1617 * value that @right evaluates to. This is the same as KUNIT_EXPECT_GT(), except
1618 * it causes an assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion
1619 * is not met.
1620 */
1621 #define KUNIT_ASSERT_GT(test, left, right) \
1622 KUNIT_BINARY_GT_ASSERTION(test, KUNIT_ASSERTION, left, right)
1623
1624 #define KUNIT_ASSERT_GT_MSG(test, left, right, fmt, ...) \
1625 KUNIT_BINARY_GT_MSG_ASSERTION(test, \
1626 KUNIT_ASSERTION, \
1627 left, \
1628 right, \
1629 fmt, \
1630 ##__VA_ARGS__)
1631
1632 /**
1633 * KUNIT_ASSERT_GE() - Assertion that @left is greater than or equal to @right.
1634 * @test: The test context object.
1635 * @left: an arbitrary expression that evaluates to a primitive C type.
1636 * @right: an arbitrary expression that evaluates to a primitive C type.
1637 *
1638 * Sets an assertion that the value that @left evaluates to is greater than the
1639 * value that @right evaluates to. This is the same as KUNIT_EXPECT_GE(), except
1640 * it causes an assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion
1641 * is not met.
1642 */
1643 #define KUNIT_ASSERT_GE(test, left, right) \
1644 KUNIT_BINARY_GE_ASSERTION(test, KUNIT_ASSERTION, left, right)
1645
1646 #define KUNIT_ASSERT_GE_MSG(test, left, right, fmt, ...) \
1647 KUNIT_BINARY_GE_MSG_ASSERTION(test, \
1648 KUNIT_ASSERTION, \
1649 left, \
1650 right, \
1651 fmt, \
1652 ##__VA_ARGS__)
1653
1654 /**
1655 * KUNIT_ASSERT_STREQ() - An assertion that strings @left and @right are equal.
1656 * @test: The test context object.
1657 * @left: an arbitrary expression that evaluates to a null terminated string.
1658 * @right: an arbitrary expression that evaluates to a null terminated string.
1659 *
1660 * Sets an assertion that the values that @left and @right evaluate to are
1661 * equal. This is the same as KUNIT_EXPECT_STREQ(), except it causes an
1662 * assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1663 */
1664 #define KUNIT_ASSERT_STREQ(test, left, right) \
1665 KUNIT_BINARY_STR_EQ_ASSERTION(test, KUNIT_ASSERTION, left, right)
1666
1667 #define KUNIT_ASSERT_STREQ_MSG(test, left, right, fmt, ...) \
1668 KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test, \
1669 KUNIT_ASSERTION, \
1670 left, \
1671 right, \
1672 fmt, \
1673 ##__VA_ARGS__)
1674
1675 /**
1676 * KUNIT_ASSERT_STRNEQ() - Expects that strings @left and @right are not equal.
1677 * @test: The test context object.
1678 * @left: an arbitrary expression that evaluates to a null terminated string.
1679 * @right: an arbitrary expression that evaluates to a null terminated string.
1680 *
1681 * Sets an expectation that the values that @left and @right evaluate to are
1682 * not equal. This is semantically equivalent to
1683 * KUNIT_ASSERT_TRUE(@test, strcmp((@left), (@right))). See KUNIT_ASSERT_TRUE()
1684 * for more information.
1685 */
1686 #define KUNIT_ASSERT_STRNEQ(test, left, right) \
1687 KUNIT_BINARY_STR_NE_ASSERTION(test, KUNIT_ASSERTION, left, right)
1688
1689 #define KUNIT_ASSERT_STRNEQ_MSG(test, left, right, fmt, ...) \
1690 KUNIT_BINARY_STR_NE_MSG_ASSERTION(test, \
1691 KUNIT_ASSERTION, \
1692 left, \
1693 right, \
1694 fmt, \
1695 ##__VA_ARGS__)
1696
1697 /**
1698 * KUNIT_ASSERT_NOT_ERR_OR_NULL() - Assertion that @ptr is not null and not err.
1699 * @test: The test context object.
1700 * @ptr: an arbitrary pointer.
1701 *
1702 * Sets an assertion that the value that @ptr evaluates to is not null and not
1703 * an errno stored in a pointer. This is the same as
1704 * KUNIT_EXPECT_NOT_ERR_OR_NULL(), except it causes an assertion failure (see
1705 * KUNIT_ASSERT_TRUE()) when the assertion is not met.
1706 */
1707 #define KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr) \
1708 KUNIT_PTR_NOT_ERR_OR_NULL_ASSERTION(test, KUNIT_ASSERTION, ptr)
1709
1710 #define KUNIT_ASSERT_NOT_ERR_OR_NULL_MSG(test, ptr, fmt, ...) \
1711 KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \
1712 KUNIT_ASSERTION, \
1713 ptr, \
1714 fmt, \
1715 ##__VA_ARGS__)
1716
1717 /**
1718 * kunit_param_generator_helper() - Helper method for test parameter generators
1719 * required in parameterized tests.
1720 * @test: The test context object.
1721 * @prev_param: a pointer to the previous test parameter, NULL for first parameter.
1722 * @param_array: a user-supplied pointer to an array of test parameters.
1723 * @array_size: number of test parameters in the array.
1724 * @type_size: size of one test parameter.
1725 */
1726 static inline void *kunit_param_generator_helper(struct kunit *test,
1727 void *prev_param,
1728 void *param_array,
1729 size_t array_size,
1730 size_t type_size)
1731 {
> 1732 KUNIT_ASSERT_EQ(test, (prev_param - param_array) % type_size, 0);
1733
1734 if (!prev_param)
1735 return param_array;
1736
> 1737 KUNIT_ASSERT_GE(test, prev_param, param_array);
1738
1739 if (prev_param + type_size < param_array + (array_size * type_size))
1740 return prev_param + type_size;
1741 else
1742 return NULL;
1743 }
.config.gz

kernel test robot

unread,
Oct 23, 2020, 2:15:30 PM10/23/20
to Arpitha Raghunandan, brendan...@google.com, sk...@linuxfoundation.org, el...@google.com, yza...@google.com, ty...@mit.edu, adilger...@dilger.ca, kbuil...@lists.01.org, clang-bu...@googlegroups.com, Arpitha Raghunandan, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-...@vger.kernel.org
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.9 next-20201023]
[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/20201023-230827
base: https://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git dev
config: arm64-randconfig-r026-20201023 (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project 147b9497e79a98a8614b2b5eb4ba653b44f6b6f0)
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
# install arm64 cross compiling tool for clang build
# apt-get install binutils-aarch64-linux-gnu
# https://github.com/0day-ci/linux/commit/2c09a7974ce3b438845bfafb539513dc91c021b4
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Arpitha-Raghunandan/kunit-Support-for-Parameterized-Testing/20201023-230827
git checkout 2c09a7974ce3b438845bfafb539513dc91c021b4
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm64

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <l...@intel.com>

All warnings (new ones prefixed by >>):

In file included from lib/kunit/test.c:9:
>> include/kunit/test.h:1732:2: warning: comparison of distinct pointer types ('typeof (__left) *' (aka 'unsigned long *') and 'typeof (__right) *' (aka 'int *')) [-Wcompare-distinct-pointer-types]
KUNIT_ASSERT_EQ(test, (prev_param - param_array) % type_size, 0);
KUNIT_ASSERT_EQ(test, (prev_param - param_array) % type_size, 0);
.config.gz

Marco Elver

unread,
Oct 23, 2020, 2:48:11 PM10/23/20
to Arpitha Raghunandan, brendan...@google.com, sk...@linuxfoundation.org, yza...@google.com, ty...@mit.edu, adilger...@dilger.ca, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-...@vger.kernel.org, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
On Fri, Oct 23, 2020 at 08:35PM +0530, Arpitha Raghunandan wrote:
> Implementation of support for parameterized testing in KUnit.

Already looks much cleaner, thanks for using this approach!

I think the commit message needs a brief summary of the approach.

> Signed-off-by: Arpitha Raghunandan <98....@gmail.com>
> ---
> Changes v1->v2:
> - Use of a generator method to access test case parameters
>
> include/kunit/test.h | 45 ++++++++++++++++++++++++++++++++++++++++++++
> lib/kunit/test.c | 20 +++++++++++++++++++-
> 2 files changed, 64 insertions(+), 1 deletion(-)
>
> diff --git a/include/kunit/test.h b/include/kunit/test.h
> index a423fffefea0..c417ac140326 100644
> --- a/include/kunit/test.h
> +++ b/include/kunit/test.h
> @@ -141,6 +141,7 @@ struct kunit;
> struct kunit_case {
> void (*run_case)(struct kunit *test);
> const char *name;
> + void* (*generate_params)(struct kunit *test, void *prev);

Would adding documentation above this field be the right place, or
somewhere else? In any case, some explanation of the protocol would be
good.
I don't think this needs to be inline, but see my other suggestion
below, which might make this function obsolete.

> + void *prev_param,
> + void *param_array,
> + size_t array_size,
> + size_t type_size)
> +{
> + KUNIT_ASSERT_EQ(test, (prev_param - param_array) % type_size, 0);
> +
> + if (!prev_param)
> + return param_array;
> +
> + KUNIT_ASSERT_GE(test, prev_param, param_array);
> +
> + if (prev_param + type_size < param_array + (array_size * type_size))
> + return prev_param + type_size;
> + else
> + return NULL;
> +}
> +
> +#define KUNIT_PARAM_GENERATOR_HELPER(test, prev_param, param_array, param_type) \
> + kunit_param_generator_helper(test, prev_param, param_array, \
> + ARRAY_SIZE(param_array), sizeof(param_type))

You do not need param_type, you can use the same trick that ARRAY_SIZE
uses:

#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))

So you could use sizeof((param_aray)[0]) instead of sizeof(param_type).
ARRAY_SIZE already checks for you that it's a real array via
__must_be_array().


The other question is, will kunit_param_generator_helper() find much use
without the KUNIT_PARAM_GENERATOR_HELPER() macro? If I have some
complicated generator protocol to generate params, then I'd just
directly write the generator function. If your intent is to simplify the
common-case array based generators, why not just have a macro generate
the generator function?

More specifically, have this macro here:

+#define KUNIT_ARRAY_PARAM(name, array) \
+ static void *name##_gen_params(struct kunit *test, void *prev) \
+ { \
+ typeof((array)[0]) *__next = prev ? ((typeof(__next)) prev) + 1 : (array); \
+ return __next - (array) < ARRAY_SIZE((array)) ? __next : NULL; \
+ }

[ It is entirely untested, but if it works verbatim you'll probably need my

Co-developed-by: Marco Elver <el...@google.com>
Signed-off-by: Marco Elver <el...@google.com>

just in case... ]

Then, it can be used as follows:

static int num_cpus[] = {1, 2, 3, 4, 5};
KUNIT_ARRAY_PARAM(num_cpus, num_cpus);

Then somewhere else:

KUNIT_CASE_PARAM(some_test, num_cpus_gen_params);
Otherwise looks fine.

Thanks,
-- Marco

Marco Elver

unread,
Oct 23, 2020, 2:56:35 PM10/23/20
to Arpitha Raghunandan, Brendan Higgins, sk...@linuxfoundation.org, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, LKML, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
On Fri, 23 Oct 2020 at 20:48, Marco Elver <el...@google.com> wrote:
[...]
> > + */
> > +static inline void *kunit_param_generator_helper(struct kunit *test,
>
> I don't think this needs to be inline, but see my other suggestion
> below, which might make this function obsolete.

Ah sorry, it's in a header so we might get complaints if it's not
inline. But in any case, if you use the KUNIT_ARRAY_PARAM() macro I
proposed, this function will become obsolete.

Thanks,
-- Marco

Arpitha Raghunandan

unread,
Oct 24, 2020, 1:23:59 AM10/24/20
to Marco Elver, brendan...@google.com, sk...@linuxfoundation.org, yza...@google.com, ty...@mit.edu, adilger...@dilger.ca, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-...@vger.kernel.org, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
On 24/10/20 12:18 am, Marco Elver wrote:
> On Fri, Oct 23, 2020 at 08:35PM +0530, Arpitha Raghunandan wrote:
>> Implementation of support for parameterized testing in KUnit.
>
> Already looks much cleaner, thanks for using this approach!
>
> I think the commit message needs a brief summary of the approach.
>

Okay, I will add a more detailed commit message for the next version.

>> Signed-off-by: Arpitha Raghunandan <98....@gmail.com>
>> ---
>> Changes v1->v2:
>> - Use of a generator method to access test case parameters
>>
>> include/kunit/test.h | 45 ++++++++++++++++++++++++++++++++++++++++++++
>> lib/kunit/test.c | 20 +++++++++++++++++++-
>> 2 files changed, 64 insertions(+), 1 deletion(-)
>>
>> diff --git a/include/kunit/test.h b/include/kunit/test.h
>> index a423fffefea0..c417ac140326 100644
>> --- a/include/kunit/test.h
>> +++ b/include/kunit/test.h
>> @@ -141,6 +141,7 @@ struct kunit;
>> struct kunit_case {
>> void (*run_case)(struct kunit *test);
>> const char *name;
>> + void* (*generate_params)(struct kunit *test, void *prev);
>
> Would adding documentation above this field be the right place, or
> somewhere else? In any case, some explanation of the protocol would be
> good.
>

I will include this.
Yes, a macro can be used to generate the generator function. I will work with this
for the next version.
Thanks!

Iurii Zaikin

unread,
Oct 26, 2020, 2:11:40 PM10/26/20
to Arpitha Raghunandan, Brendan Higgins, Shuah Khan, Marco Elver, Theodore Ts'o, Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, Linux Kernel Mailing List, linux-kern...@lists.linuxfoundation.org, Ext4 Developers List
> +static struct timestamp_expectation test_data[] = {
Can you mark this and the rest of the hardcoded values as the const they are?

Arpitha Raghunandan

unread,
Oct 26, 2020, 2:19:19 PM10/26/20
to Iurii Zaikin, Brendan Higgins, Shuah Khan, Marco Elver, Theodore Ts'o, Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, Linux Kernel Mailing List, linux-kern...@lists.linuxfoundation.org, Ext4 Developers List
On 26/10/20 11:41 pm, Iurii Zaikin wrote:
>> +static struct timestamp_expectation test_data[] = {
> Can you mark this and the rest of the hardcoded values as the const they are?
>

Sure, I will make this change for the next version.

Arpitha Raghunandan

unread,
Oct 26, 2020, 2:36:11 PM10/26/20
to brendan...@google.com, sk...@linuxfoundation.org, el...@google.com, yza...@google.com, ty...@mit.edu, adilger...@dilger.ca, Arpitha Raghunandan, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-...@vger.kernel.org, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
Implementation of support for parameterized testing in KUnit.
This approach requires the creation of a test case using the
KUNIT_CASE_PARAM macro that accepts a generator function as input.
This generator function should return the next parameter given the
previous parameter in parameterized tests. It also provides
a macro to generate common-case generators.

Signed-off-by: Arpitha Raghunandan <98....@gmail.com>
Co-developed-by: Marco Elver <el...@google.com>
Signed-off-by: Marco Elver <el...@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

Arpitha Raghunandan

unread,
Oct 26, 2020, 2:37:09 PM10/26/20
to brendan...@google.com, sk...@linuxfoundation.org, el...@google.com, yza...@google.com, ty...@mit.edu, adilger...@dilger.ca, Arpitha Raghunandan, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-...@vger.kernel.org, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
Modify fs/ext4/inode-test.c to use the parameterized testing
feature of KUnit.

Signed-off-by: Arpitha Raghunandan <98....@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[] = {
+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 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

kernel test robot

unread,
Oct 26, 2020, 4:19:44 PM10/26/20
to Arpitha Raghunandan, brendan...@google.com, sk...@linuxfoundation.org, el...@google.com, yza...@google.com, ty...@mit.edu, adilger...@dilger.ca, kbuil...@lists.01.org, Arpitha Raghunandan, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-...@vger.kernel.org
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 <l...@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
.config.gz

kernel test robot

unread,
Oct 26, 2020, 6:19:58 PM10/26/20
to Arpitha Raghunandan, brendan...@google.com, sk...@linuxfoundation.org, el...@google.com, yza...@google.com, ty...@mit.edu, adilger...@dilger.ca, kbuil...@lists.01.org, Arpitha Raghunandan, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-...@vger.kernel.org
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 <l...@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
.config.gz

Marco Elver

unread,
Oct 26, 2020, 7:14:15 PM10/26/20
to Arpitha Raghunandan, Brendan Higgins, sk...@linuxfoundation.org, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, LKML, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
On Mon, 26 Oct 2020 at 19:36, Arpitha Raghunandan <98....@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....@gmail.com>
> Co-developed-by: Marco Elver <el...@google.com>
> Signed-off-by: Marco Elver <el...@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."
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

Arpitha Raghunandan

unread,
Oct 27, 2020, 1:14:12 AM10/27/20
to Marco Elver, Brendan Higgins, sk...@linuxfoundation.org, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, LKML, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
Oh okay. I am not sure if this is the best place to add documentation for this.
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!

Marco Elver

unread,
Oct 27, 2020, 3:45:03 AM10/27/20
to Arpitha Raghunandan, Brendan Higgins, sk...@linuxfoundation.org, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, LKML, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
On Tue, 27 Oct 2020 at 06:14, Arpitha Raghunandan <98....@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

Arpitha Raghunandan

unread,
Oct 27, 2020, 3:51:21 AM10/27/20
to Marco Elver, Brendan Higgins, sk...@linuxfoundation.org, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, LKML, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
Alright, I will move the comment there.

> Thanks,
> -- Marco
>

Thanks.

Marco Elver

unread,
Oct 27, 2020, 3:55:34 AM10/27/20
to Arpitha Raghunandan, Brendan Higgins, sk...@linuxfoundation.org, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, LKML, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
On Mon, 26 Oct 2020 at 19:36, Arpitha Raghunandan <98....@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

Marco Elver

unread,
Oct 27, 2020, 5:03:56 AM10/27/20
to Arpitha Raghunandan, Brendan Higgins, sk...@linuxfoundation.org, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, LKML, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
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....@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.
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

Arpitha Raghunandan

unread,
Oct 27, 2020, 10:39:22 AM10/27/20
to Marco Elver, Brendan Higgins, sk...@linuxfoundation.org, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, LKML, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
Yes, this is the only place param index is used.
I will make all the suggested changes.
Thanks!

Iurii Zaikin

unread,
Oct 27, 2020, 1:34:13 PM10/27/20
to Arpitha Raghunandan, Brendan Higgins, Shuah Khan, Marco Elver, Theodore Ts'o, Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, Linux Kernel Mailing List, linux-kern...@lists.linuxfoundation.org, Ext4 Developers List
Reviewed-by: Iurii Zaikin <yza...@google.com>

Arpitha Raghunandan

unread,
Oct 27, 2020, 1:47:07 PM10/27/20
to brendan...@google.com, sk...@linuxfoundation.org, el...@google.com, yza...@google.com, ty...@mit.edu, adilger...@dilger.ca, Arpitha Raghunandan, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-...@vger.kernel.org, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
Implementation of support for parameterized testing in KUnit.
This approach requires the creation of a test case using the
KUNIT_CASE_PARAM macro that accepts a generator function as input.
This generator function should return the next parameter given the
previous parameter in parameterized tests. It also provides
a macro to generate common-case generators.

Signed-off-by: Arpitha Raghunandan <98....@gmail.com>
Co-developed-by: Marco Elver <el...@google.com>
Signed-off-by: Marco Elver <el...@google.com>
---
Changes v3->v4:
- Rename kunit variables
- Rename generator function helper macro
- Add documentation for generator approach
- Display test case name in case of failure along with param index
Changes v2->v3:
- Modifictaion of generator macro and method
Changes v1->v2:
- Use of a generator method to access test case parameters

include/kunit/test.h | 34 ++++++++++++++++++++++++++++++++++
lib/kunit/test.c | 21 ++++++++++++++++++++-
2 files changed, 54 insertions(+), 1 deletion(-)

diff --git a/include/kunit/test.h b/include/kunit/test.h
index 9197da792336..ec2307ee9bb0 100644
--- a/include/kunit/test.h
+++ b/include/kunit/test.h
@@ -107,6 +107,13 @@ struct kunit;
*
* @run_case: the function representing the actual test case.
* @name: the name of the test case.
+ * @generate_params: the generator function for parameterized tests.
+ *
+ * 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.
*
* A test case is a function with the signature,
* ``void (*)(struct kunit *)``
@@ -141,6 +148,7 @@ struct kunit;
struct kunit_case {
void (*run_case)(struct kunit *test);
const char *name;
+ void* (*generate_params)(void *prev);

/* private: internal use only. */
bool success;
@@ -162,6 +170,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 +219,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_value points to test case parameters in parameterized tests */
+ void *param_value;
+ /*
+ * param_index stores the index of the parameter in
+ * parameterized tests. param_index + 1 is printed
+ * to indicate the parameter that causes the test
+ * to fail in case of test failure.
+ */
+ int param_index;
/*
* 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 +1762,18 @@ do { \
fmt, \
##__VA_ARGS__)

+/**
+ * KUNIT_ARRAY_PARAM() - Helper method for test parameter generators
+ * required in parameterized tests.
+ * @name: prefix of the name for the test parameter generator function.
+ * It will be suffixed by "_gen_params".
+ * @array: a user-supplied pointer to an array of test parameters.
+ */
+#define KUNIT_ARRAY_PARAM(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..8ad908b61494 100644
--- a/lib/kunit/test.c
+++ b/lib/kunit/test.c
@@ -127,6 +127,12 @@ 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:\n\ttest case: %s\n\tparameter: %d\n",
+ test->name, test->param_index + 1);
+}
+
static void kunit_print_string_stream(struct kunit *test,
struct string_stream *stream)
{
@@ -168,6 +174,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_value)
+ kunit_print_failed_param(test);

WARN_ON(string_stream_destroy(stream));
}
@@ -239,7 +247,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_value = test_case->generate_params(NULL);
+ test->param_index = 0;
+
+ while (test->param_value) {
+ test_case->run_case(test);
+ test->param_value = test_case->generate_params(test->param_value);
+ test->param_index++;

Arpitha Raghunandan

unread,
Oct 27, 2020, 1:47:56 PM10/27/20
to brendan...@google.com, sk...@linuxfoundation.org, el...@google.com, yza...@google.com, ty...@mit.edu, adilger...@dilger.ca, Arpitha Raghunandan, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-...@vger.kernel.org, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
Modify fs/ext4/inode-test.c to use the parameterized testing
feature of KUnit.

Signed-off-by: Arpitha Raghunandan <98....@gmail.com>
---
Changes v3->v4:
- Modification based on latest implementation of KUnit parameterized testing
Changes v2->v3:
- Marked hardcoded test data const
- Modification based on latest implementation of KUnit parameterized testing
Changes v1->v2:
- Modification based on latest implementation of KUnit parameterized testing

fs/ext4/inode-test.c | 314 ++++++++++++++++++++++---------------------
1 file changed, 158 insertions(+), 156 deletions(-)

diff --git a/fs/ext4/inode-test.c b/fs/ext4/inode-test.c
index d62d802c9c12..ebf1b1af4f1d 100644
+KUNIT_ARRAY_PARAM(ext4_inode, test_data);
+ (struct timestamp_expectation *)(test->param_value);

Marco Elver

unread,
Oct 27, 2020, 3:21:19 PM10/27/20
to Arpitha Raghunandan, Brendan Higgins, sk...@linuxfoundation.org, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, LKML, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
Hmm, should this really be the first paragraph? I think it should be
the paragraph before "Example:" maybe. But then that paragraph should
refer to generate_params e.g. "The generator function @generate_params
is used to ........".

The other option you have is to move this paragraph to the kernel-doc
comment for KUNIT_CASE_PARAM, which seems to be missing a kernel-doc
comment.

> * A test case is a function with the signature,
> * ``void (*)(struct kunit *)``
> @@ -141,6 +148,7 @@ struct kunit;
> struct kunit_case {
> void (*run_case)(struct kunit *test);
> const char *name;
> + void* (*generate_params)(void *prev);
>
> /* private: internal use only. */
> bool success;
> @@ -162,6 +170,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 }

I.e. create a new kernel-doc comment for KUNIT_CASE_PARAM here, and
simply move the paragraph describing the generator protocol into that
comment.

> +#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 +219,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_value points to test case parameters in parameterized tests */

Hmm, not quite: param_value is the current parameter value for a test
case. Most likely it's a pointer, but it doesn't need to be.

> + void *param_value;
> + /*
> + * param_index stores the index of the parameter in
> + * parameterized tests. param_index + 1 is printed
> + * to indicate the parameter that causes the test
> + * to fail in case of test failure.
> + */

I think this comment needs to be reformatted, because you can use at
the very least use 80 cols per line. (If you use vim, visual select
and do 'gq'.)
Hmm, perhaps I wasn't clear, but I think I also misunderstood how the
test case successes are presented: they are not, and it's all bunched
into a single test case.

Firstly, kunit_err() already prints the test name, so if we want
something like " # : the_test_case_name: failed at parameter #X",
simply having

kunit_err(test, "failed at parameter #%d\n", test->param_index + 1)

would be what you want.

But I think I missed that parameters do not actually produce a set of
test cases (sorry for noticing late). I think in their current form,
the parameterized tests would not be useful for my tests, because each
of my tests have test cases that have specific init and exit
functions. For each parameter, these would also need to run.

Ideally, each parameter produces its own independent test case
"test_case#param_index". That way, CI systems will also be able to
logically separate different test case params, simply because each
param produced its own distinct test case.

So, for example, we would get a series of test cases from something
like KUNIT_CASE_PARAM(test_case, foo_gen_params), and in the output
we'd see:

ok X - test_case#1
ok X - test_case#2
ok X - test_case#3
ok X - test_case#4
....

Would that make more sense?

That way we'd ensure that test-case specific initialization and
cleanup done in init and exit functions is properly taken care of, and
you wouldn't need kunit_print_failed_param().

AFAIK, for what I propose you'd have to modify kunit_print_ok_not_ok()
(show param_index if parameterized test) and probably
kunit_run_case_catch_errors() (generate params and set
test->param_value and param_index).

Was there a reason why each param cannot be a distinct test case? If
not, I think this would be more useful.

> static void kunit_print_string_stream(struct kunit *test,
> struct string_stream *stream)
> {
> @@ -168,6 +174,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_value)
> + kunit_print_failed_param(test);
>
> WARN_ON(string_stream_destroy(stream));
> }
> @@ -239,7 +247,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_value = test_case->generate_params(NULL);
> + test->param_index = 0;
> +
> + while (test->param_value) {
> + test_case->run_case(test);
> + test->param_value = test_case->generate_params(test->param_value);
> + test->param_index++;
> + }
> + }

Thanks,
-- Marco

kernel test robot

unread,
Oct 27, 2020, 7:50:47 PM10/27/20
to Arpitha Raghunandan, brendan...@google.com, sk...@linuxfoundation.org, el...@google.com, yza...@google.com, ty...@mit.edu, adilger...@dilger.ca, kbuil...@lists.01.org, Arpitha Raghunandan, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-...@vger.kernel.org
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-20201027]
[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/20201028-015018
base: https://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git dev
config: mips-randconfig-r016-20201027 (attached as .config)
compiler: mipsel-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/2de1e52708cd83d1dc4c718876683f6809045a98
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Arpitha-Raghunandan/kunit-Support-for-Parameterized-Testing/20201028-015018
git checkout 2de1e52708cd83d1dc4c718876683f6809045a98
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=mips

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <l...@intel.com>

All warnings (new ones prefixed by >>):

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:1735:58: warning: return discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
1735 | return __next - (array) < ARRAY_SIZE((array)) ? __next : NULL; \
fs/ext4/inode-test.c:214:1: note: in expansion of macro 'KUNIT_ARRAY_PARAM'
214 | KUNIT_ARRAY_PARAM(ext4_inode, test_data);
| ^~~~~~~~~~~~~~~~~

vim +/const +1735 include/kunit/test.h

73cda7bb8bfb1d Brendan Higgins 2019-09-23 1154
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1155 #define KUNIT_PTR_NOT_ERR_OR_NULL_ASSERTION(test, assert_type, ptr) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1156 KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1157 assert_type, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1158 ptr, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1159 NULL)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1160
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1161 /**
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1162 * KUNIT_EXPECT_TRUE() - Causes a test failure when the expression is not true.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1163 * @test: The test context object.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1164 * @condition: an arbitrary boolean expression. The test fails when this does
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1165 * not evaluate to true.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1166 *
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1167 * This and expectations of the form `KUNIT_EXPECT_*` will cause the test case
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1168 * to fail when the specified condition is not met; however, it will not prevent
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1169 * the test case from continuing to run; this is otherwise known as an
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1170 * *expectation failure*.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1171 */
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1172 #define KUNIT_EXPECT_TRUE(test, condition) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1173 KUNIT_TRUE_ASSERTION(test, KUNIT_EXPECTATION, condition)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1174
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1175 #define KUNIT_EXPECT_TRUE_MSG(test, condition, fmt, ...) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1176 KUNIT_TRUE_MSG_ASSERTION(test, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1177 KUNIT_EXPECTATION, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1178 condition, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1179 fmt, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1180 ##__VA_ARGS__)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1181
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1182 /**
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1183 * KUNIT_EXPECT_FALSE() - Makes a test failure when the expression is not false.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1184 * @test: The test context object.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1185 * @condition: an arbitrary boolean expression. The test fails when this does
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1186 * not evaluate to false.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1187 *
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1188 * Sets an expectation that @condition evaluates to false. See
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1189 * KUNIT_EXPECT_TRUE() for more information.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1190 */
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1191 #define KUNIT_EXPECT_FALSE(test, condition) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1192 KUNIT_FALSE_ASSERTION(test, KUNIT_EXPECTATION, condition)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1193
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1194 #define KUNIT_EXPECT_FALSE_MSG(test, condition, fmt, ...) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1195 KUNIT_FALSE_MSG_ASSERTION(test, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1196 KUNIT_EXPECTATION, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1197 condition, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1198 fmt, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1199 ##__VA_ARGS__)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1200
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1201 /**
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1202 * KUNIT_EXPECT_EQ() - Sets an expectation that @left and @right are equal.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1203 * @test: The test context object.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1204 * @left: an arbitrary expression that evaluates to a primitive C type.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1205 * @right: an arbitrary expression that evaluates to a primitive C type.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1206 *
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1207 * Sets an expectation that the values that @left and @right evaluate to are
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1208 * equal. This is semantically equivalent to
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1209 * KUNIT_EXPECT_TRUE(@test, (@left) == (@right)). See KUNIT_EXPECT_TRUE() for
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1210 * more information.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1211 */
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1212 #define KUNIT_EXPECT_EQ(test, left, right) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1213 KUNIT_BINARY_EQ_ASSERTION(test, KUNIT_EXPECTATION, left, right)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1214
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1215 #define KUNIT_EXPECT_EQ_MSG(test, left, right, fmt, ...) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1216 KUNIT_BINARY_EQ_MSG_ASSERTION(test, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1217 KUNIT_EXPECTATION, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1218 left, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1219 right, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1220 fmt, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1221 ##__VA_ARGS__)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1222
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1223 /**
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1224 * KUNIT_EXPECT_PTR_EQ() - Expects that pointers @left and @right are equal.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1225 * @test: The test context object.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1226 * @left: an arbitrary expression that evaluates to a pointer.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1227 * @right: an arbitrary expression that evaluates to a pointer.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1228 *
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1229 * Sets an expectation that the values that @left and @right evaluate to are
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1230 * equal. This is semantically equivalent to
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1231 * KUNIT_EXPECT_TRUE(@test, (@left) == (@right)). See KUNIT_EXPECT_TRUE() for
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1232 * more information.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1233 */
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1234 #define KUNIT_EXPECT_PTR_EQ(test, left, right) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1235 KUNIT_BINARY_PTR_EQ_ASSERTION(test, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1236 KUNIT_EXPECTATION, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1237 left, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1238 right)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1239
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1240 #define KUNIT_EXPECT_PTR_EQ_MSG(test, left, right, fmt, ...) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1241 KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1242 KUNIT_EXPECTATION, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1243 left, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1244 right, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1245 fmt, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1246 ##__VA_ARGS__)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1247
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1248 /**
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1249 * KUNIT_EXPECT_NE() - An expectation that @left and @right are not equal.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1250 * @test: The test context object.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1251 * @left: an arbitrary expression that evaluates to a primitive C type.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1252 * @right: an arbitrary expression that evaluates to a primitive C type.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1253 *
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1254 * Sets an expectation that the values that @left and @right evaluate to are not
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1255 * equal. This is semantically equivalent to
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1256 * KUNIT_EXPECT_TRUE(@test, (@left) != (@right)). See KUNIT_EXPECT_TRUE() for
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1257 * more information.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1258 */
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1259 #define KUNIT_EXPECT_NE(test, left, right) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1260 KUNIT_BINARY_NE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1261
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1262 #define KUNIT_EXPECT_NE_MSG(test, left, right, fmt, ...) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1263 KUNIT_BINARY_NE_MSG_ASSERTION(test, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1264 KUNIT_EXPECTATION, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1265 left, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1266 right, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1267 fmt, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1268 ##__VA_ARGS__)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1269
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1270 /**
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1271 * KUNIT_EXPECT_PTR_NE() - Expects that pointers @left and @right are not equal.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1272 * @test: The test context object.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1273 * @left: an arbitrary expression that evaluates to a pointer.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1274 * @right: an arbitrary expression that evaluates to a pointer.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1275 *
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1276 * Sets an expectation that the values that @left and @right evaluate to are not
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1277 * equal. This is semantically equivalent to
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1278 * KUNIT_EXPECT_TRUE(@test, (@left) != (@right)). See KUNIT_EXPECT_TRUE() for
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1279 * more information.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1280 */
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1281 #define KUNIT_EXPECT_PTR_NE(test, left, right) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1282 KUNIT_BINARY_PTR_NE_ASSERTION(test, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1283 KUNIT_EXPECTATION, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1284 left, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1285 right)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1286
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1287 #define KUNIT_EXPECT_PTR_NE_MSG(test, left, right, fmt, ...) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1288 KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1289 KUNIT_EXPECTATION, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1290 left, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1291 right, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1292 fmt, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1293 ##__VA_ARGS__)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1294
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1295 /**
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1296 * KUNIT_EXPECT_LT() - An expectation that @left is less than @right.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1297 * @test: The test context object.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1298 * @left: an arbitrary expression that evaluates to a primitive C type.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1299 * @right: an arbitrary expression that evaluates to a primitive C type.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1300 *
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1301 * Sets an expectation that the value that @left evaluates to is less than the
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1302 * value that @right evaluates to. This is semantically equivalent to
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1303 * KUNIT_EXPECT_TRUE(@test, (@left) < (@right)). See KUNIT_EXPECT_TRUE() for
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1304 * more information.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1305 */
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1306 #define KUNIT_EXPECT_LT(test, left, right) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1307 KUNIT_BINARY_LT_ASSERTION(test, KUNIT_EXPECTATION, left, right)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1308
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1309 #define KUNIT_EXPECT_LT_MSG(test, left, right, fmt, ...) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1310 KUNIT_BINARY_LT_MSG_ASSERTION(test, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1311 KUNIT_EXPECTATION, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1312 left, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1313 right, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1314 fmt, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1315 ##__VA_ARGS__)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1316
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1317 /**
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1318 * KUNIT_EXPECT_LE() - Expects that @left is less than or equal to @right.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1319 * @test: The test context object.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1320 * @left: an arbitrary expression that evaluates to a primitive C type.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1321 * @right: an arbitrary expression that evaluates to a primitive C type.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1322 *
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1323 * Sets an expectation that the value that @left evaluates to is less than or
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1324 * equal to the value that @right evaluates to. Semantically this is equivalent
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1325 * to KUNIT_EXPECT_TRUE(@test, (@left) <= (@right)). See KUNIT_EXPECT_TRUE() for
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1326 * more information.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1327 */
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1328 #define KUNIT_EXPECT_LE(test, left, right) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1329 KUNIT_BINARY_LE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1330
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1331 #define KUNIT_EXPECT_LE_MSG(test, left, right, fmt, ...) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1332 KUNIT_BINARY_LE_MSG_ASSERTION(test, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1333 KUNIT_EXPECTATION, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1334 left, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1335 right, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1336 fmt, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1337 ##__VA_ARGS__)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1338
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1339 /**
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1340 * KUNIT_EXPECT_GT() - An expectation that @left is greater than @right.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1341 * @test: The test context object.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1342 * @left: an arbitrary expression that evaluates to a primitive C type.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1343 * @right: an arbitrary expression that evaluates to a primitive C type.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1344 *
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1345 * Sets an expectation that the value that @left evaluates to is greater than
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1346 * the value that @right evaluates to. This is semantically equivalent to
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1347 * KUNIT_EXPECT_TRUE(@test, (@left) > (@right)). See KUNIT_EXPECT_TRUE() for
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1348 * more information.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1349 */
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1350 #define KUNIT_EXPECT_GT(test, left, right) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1351 KUNIT_BINARY_GT_ASSERTION(test, KUNIT_EXPECTATION, left, right)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1352
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1353 #define KUNIT_EXPECT_GT_MSG(test, left, right, fmt, ...) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1354 KUNIT_BINARY_GT_MSG_ASSERTION(test, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1355 KUNIT_EXPECTATION, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1356 left, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1357 right, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1358 fmt, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1359 ##__VA_ARGS__)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1360
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1361 /**
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1362 * KUNIT_EXPECT_GE() - Expects that @left is greater than or equal to @right.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1363 * @test: The test context object.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1364 * @left: an arbitrary expression that evaluates to a primitive C type.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1365 * @right: an arbitrary expression that evaluates to a primitive C type.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1366 *
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1367 * Sets an expectation that the value that @left evaluates to is greater than
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1368 * the value that @right evaluates to. This is semantically equivalent to
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1369 * KUNIT_EXPECT_TRUE(@test, (@left) >= (@right)). See KUNIT_EXPECT_TRUE() for
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1370 * more information.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1371 */
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1372 #define KUNIT_EXPECT_GE(test, left, right) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1373 KUNIT_BINARY_GE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1374
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1375 #define KUNIT_EXPECT_GE_MSG(test, left, right, fmt, ...) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1376 KUNIT_BINARY_GE_MSG_ASSERTION(test, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1377 KUNIT_EXPECTATION, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1378 left, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1379 right, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1380 fmt, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1381 ##__VA_ARGS__)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1382
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1383 /**
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1384 * KUNIT_EXPECT_STREQ() - Expects that strings @left and @right are equal.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1385 * @test: The test context object.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1386 * @left: an arbitrary expression that evaluates to a null terminated string.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1387 * @right: an arbitrary expression that evaluates to a null terminated string.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1388 *
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1389 * Sets an expectation that the values that @left and @right evaluate to are
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1390 * equal. This is semantically equivalent to
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1391 * KUNIT_EXPECT_TRUE(@test, !strcmp((@left), (@right))). See KUNIT_EXPECT_TRUE()
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1392 * for more information.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1393 */
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1394 #define KUNIT_EXPECT_STREQ(test, left, right) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1395 KUNIT_BINARY_STR_EQ_ASSERTION(test, KUNIT_EXPECTATION, left, right)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1396
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1397 #define KUNIT_EXPECT_STREQ_MSG(test, left, right, fmt, ...) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1398 KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1399 KUNIT_EXPECTATION, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1400 left, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1401 right, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1402 fmt, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1403 ##__VA_ARGS__)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1404
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1405 /**
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1406 * KUNIT_EXPECT_STRNEQ() - Expects that strings @left and @right are not equal.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1407 * @test: The test context object.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1408 * @left: an arbitrary expression that evaluates to a null terminated string.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1409 * @right: an arbitrary expression that evaluates to a null terminated string.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1410 *
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1411 * Sets an expectation that the values that @left and @right evaluate to are
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1412 * not equal. This is semantically equivalent to
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1413 * KUNIT_EXPECT_TRUE(@test, strcmp((@left), (@right))). See KUNIT_EXPECT_TRUE()
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1414 * for more information.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1415 */
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1416 #define KUNIT_EXPECT_STRNEQ(test, left, right) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1417 KUNIT_BINARY_STR_NE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1418
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1419 #define KUNIT_EXPECT_STRNEQ_MSG(test, left, right, fmt, ...) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1420 KUNIT_BINARY_STR_NE_MSG_ASSERTION(test, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1421 KUNIT_EXPECTATION, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1422 left, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1423 right, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1424 fmt, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1425 ##__VA_ARGS__)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1426
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1427 /**
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1428 * KUNIT_EXPECT_NOT_ERR_OR_NULL() - Expects that @ptr is not null and not err.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1429 * @test: The test context object.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1430 * @ptr: an arbitrary pointer.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1431 *
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1432 * Sets an expectation that the value that @ptr evaluates to is not null and not
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1433 * an errno stored in a pointer. This is semantically equivalent to
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1434 * KUNIT_EXPECT_TRUE(@test, !IS_ERR_OR_NULL(@ptr)). See KUNIT_EXPECT_TRUE() for
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1435 * more information.
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1436 */
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1437 #define KUNIT_EXPECT_NOT_ERR_OR_NULL(test, ptr) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1438 KUNIT_PTR_NOT_ERR_OR_NULL_ASSERTION(test, KUNIT_EXPECTATION, ptr)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1439
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1440 #define KUNIT_EXPECT_NOT_ERR_OR_NULL_MSG(test, ptr, fmt, ...) \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1441 KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1442 KUNIT_EXPECTATION, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1443 ptr, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1444 fmt, \
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1445 ##__VA_ARGS__)
73cda7bb8bfb1d Brendan Higgins 2019-09-23 1446
e4aea8f8532b55 Brendan Higgins 2019-09-23 1447 #define KUNIT_ASSERT_FAILURE(test, fmt, ...) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1448 KUNIT_FAIL_ASSERTION(test, KUNIT_ASSERTION, fmt, ##__VA_ARGS__)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1449
e4aea8f8532b55 Brendan Higgins 2019-09-23 1450 /**
e4aea8f8532b55 Brendan Higgins 2019-09-23 1451 * KUNIT_ASSERT_TRUE() - Sets an assertion that @condition is true.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1452 * @test: The test context object.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1453 * @condition: an arbitrary boolean expression. The test fails and aborts when
e4aea8f8532b55 Brendan Higgins 2019-09-23 1454 * this does not evaluate to true.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1455 *
e4aea8f8532b55 Brendan Higgins 2019-09-23 1456 * This and assertions of the form `KUNIT_ASSERT_*` will cause the test case to
e4aea8f8532b55 Brendan Higgins 2019-09-23 1457 * fail *and immediately abort* when the specified condition is not met. Unlike
e4aea8f8532b55 Brendan Higgins 2019-09-23 1458 * an expectation failure, it will prevent the test case from continuing to run;
e4aea8f8532b55 Brendan Higgins 2019-09-23 1459 * this is otherwise known as an *assertion failure*.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1460 */
e4aea8f8532b55 Brendan Higgins 2019-09-23 1461 #define KUNIT_ASSERT_TRUE(test, condition) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1462 KUNIT_TRUE_ASSERTION(test, KUNIT_ASSERTION, condition)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1463
e4aea8f8532b55 Brendan Higgins 2019-09-23 1464 #define KUNIT_ASSERT_TRUE_MSG(test, condition, fmt, ...) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1465 KUNIT_TRUE_MSG_ASSERTION(test, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1466 KUNIT_ASSERTION, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1467 condition, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1468 fmt, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1469 ##__VA_ARGS__)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1470
e4aea8f8532b55 Brendan Higgins 2019-09-23 1471 /**
e4aea8f8532b55 Brendan Higgins 2019-09-23 1472 * KUNIT_ASSERT_FALSE() - Sets an assertion that @condition is false.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1473 * @test: The test context object.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1474 * @condition: an arbitrary boolean expression.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1475 *
e4aea8f8532b55 Brendan Higgins 2019-09-23 1476 * Sets an assertion that the value that @condition evaluates to is false. This
e4aea8f8532b55 Brendan Higgins 2019-09-23 1477 * is the same as KUNIT_EXPECT_FALSE(), except it causes an assertion failure
e4aea8f8532b55 Brendan Higgins 2019-09-23 1478 * (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1479 */
e4aea8f8532b55 Brendan Higgins 2019-09-23 1480 #define KUNIT_ASSERT_FALSE(test, condition) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1481 KUNIT_FALSE_ASSERTION(test, KUNIT_ASSERTION, condition)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1482
e4aea8f8532b55 Brendan Higgins 2019-09-23 1483 #define KUNIT_ASSERT_FALSE_MSG(test, condition, fmt, ...) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1484 KUNIT_FALSE_MSG_ASSERTION(test, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1485 KUNIT_ASSERTION, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1486 condition, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1487 fmt, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1488 ##__VA_ARGS__)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1489
e4aea8f8532b55 Brendan Higgins 2019-09-23 1490 /**
e4aea8f8532b55 Brendan Higgins 2019-09-23 1491 * KUNIT_ASSERT_EQ() - Sets an assertion that @left and @right are equal.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1492 * @test: The test context object.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1493 * @left: an arbitrary expression that evaluates to a primitive C type.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1494 * @right: an arbitrary expression that evaluates to a primitive C type.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1495 *
e4aea8f8532b55 Brendan Higgins 2019-09-23 1496 * Sets an assertion that the values that @left and @right evaluate to are
e4aea8f8532b55 Brendan Higgins 2019-09-23 1497 * equal. This is the same as KUNIT_EXPECT_EQ(), except it causes an assertion
e4aea8f8532b55 Brendan Higgins 2019-09-23 1498 * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1499 */
e4aea8f8532b55 Brendan Higgins 2019-09-23 1500 #define KUNIT_ASSERT_EQ(test, left, right) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1501 KUNIT_BINARY_EQ_ASSERTION(test, KUNIT_ASSERTION, left, right)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1502
e4aea8f8532b55 Brendan Higgins 2019-09-23 1503 #define KUNIT_ASSERT_EQ_MSG(test, left, right, fmt, ...) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1504 KUNIT_BINARY_EQ_MSG_ASSERTION(test, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1505 KUNIT_ASSERTION, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1506 left, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1507 right, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1508 fmt, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1509 ##__VA_ARGS__)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1510
e4aea8f8532b55 Brendan Higgins 2019-09-23 1511 /**
e4aea8f8532b55 Brendan Higgins 2019-09-23 1512 * KUNIT_ASSERT_PTR_EQ() - Asserts that pointers @left and @right are equal.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1513 * @test: The test context object.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1514 * @left: an arbitrary expression that evaluates to a pointer.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1515 * @right: an arbitrary expression that evaluates to a pointer.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1516 *
e4aea8f8532b55 Brendan Higgins 2019-09-23 1517 * Sets an assertion that the values that @left and @right evaluate to are
e4aea8f8532b55 Brendan Higgins 2019-09-23 1518 * equal. This is the same as KUNIT_EXPECT_EQ(), except it causes an assertion
e4aea8f8532b55 Brendan Higgins 2019-09-23 1519 * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1520 */
e4aea8f8532b55 Brendan Higgins 2019-09-23 1521 #define KUNIT_ASSERT_PTR_EQ(test, left, right) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1522 KUNIT_BINARY_PTR_EQ_ASSERTION(test, KUNIT_ASSERTION, left, right)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1523
e4aea8f8532b55 Brendan Higgins 2019-09-23 1524 #define KUNIT_ASSERT_PTR_EQ_MSG(test, left, right, fmt, ...) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1525 KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1526 KUNIT_ASSERTION, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1527 left, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1528 right, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1529 fmt, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1530 ##__VA_ARGS__)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1531
e4aea8f8532b55 Brendan Higgins 2019-09-23 1532 /**
e4aea8f8532b55 Brendan Higgins 2019-09-23 1533 * KUNIT_ASSERT_NE() - An assertion that @left and @right are not equal.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1534 * @test: The test context object.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1535 * @left: an arbitrary expression that evaluates to a primitive C type.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1536 * @right: an arbitrary expression that evaluates to a primitive C type.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1537 *
e4aea8f8532b55 Brendan Higgins 2019-09-23 1538 * Sets an assertion that the values that @left and @right evaluate to are not
e4aea8f8532b55 Brendan Higgins 2019-09-23 1539 * equal. This is the same as KUNIT_EXPECT_NE(), except it causes an assertion
e4aea8f8532b55 Brendan Higgins 2019-09-23 1540 * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1541 */
e4aea8f8532b55 Brendan Higgins 2019-09-23 1542 #define KUNIT_ASSERT_NE(test, left, right) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1543 KUNIT_BINARY_NE_ASSERTION(test, KUNIT_ASSERTION, left, right)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1544
e4aea8f8532b55 Brendan Higgins 2019-09-23 1545 #define KUNIT_ASSERT_NE_MSG(test, left, right, fmt, ...) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1546 KUNIT_BINARY_NE_MSG_ASSERTION(test, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1547 KUNIT_ASSERTION, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1548 left, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1549 right, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1550 fmt, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1551 ##__VA_ARGS__)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1552
e4aea8f8532b55 Brendan Higgins 2019-09-23 1553 /**
e4aea8f8532b55 Brendan Higgins 2019-09-23 1554 * KUNIT_ASSERT_PTR_NE() - Asserts that pointers @left and @right are not equal.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1555 * KUNIT_ASSERT_PTR_EQ() - Asserts that pointers @left and @right are equal.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1556 * @test: The test context object.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1557 * @left: an arbitrary expression that evaluates to a pointer.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1558 * @right: an arbitrary expression that evaluates to a pointer.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1559 *
e4aea8f8532b55 Brendan Higgins 2019-09-23 1560 * Sets an assertion that the values that @left and @right evaluate to are not
e4aea8f8532b55 Brendan Higgins 2019-09-23 1561 * equal. This is the same as KUNIT_EXPECT_NE(), except it causes an assertion
e4aea8f8532b55 Brendan Higgins 2019-09-23 1562 * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1563 */
e4aea8f8532b55 Brendan Higgins 2019-09-23 1564 #define KUNIT_ASSERT_PTR_NE(test, left, right) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1565 KUNIT_BINARY_PTR_NE_ASSERTION(test, KUNIT_ASSERTION, left, right)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1566
e4aea8f8532b55 Brendan Higgins 2019-09-23 1567 #define KUNIT_ASSERT_PTR_NE_MSG(test, left, right, fmt, ...) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1568 KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1569 KUNIT_ASSERTION, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1570 left, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1571 right, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1572 fmt, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1573 ##__VA_ARGS__)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1574 /**
e4aea8f8532b55 Brendan Higgins 2019-09-23 1575 * KUNIT_ASSERT_LT() - An assertion that @left is less than @right.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1576 * @test: The test context object.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1577 * @left: an arbitrary expression that evaluates to a primitive C type.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1578 * @right: an arbitrary expression that evaluates to a primitive C type.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1579 *
e4aea8f8532b55 Brendan Higgins 2019-09-23 1580 * Sets an assertion that the value that @left evaluates to is less than the
e4aea8f8532b55 Brendan Higgins 2019-09-23 1581 * value that @right evaluates to. This is the same as KUNIT_EXPECT_LT(), except
e4aea8f8532b55 Brendan Higgins 2019-09-23 1582 * it causes an assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion
e4aea8f8532b55 Brendan Higgins 2019-09-23 1583 * is not met.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1584 */
e4aea8f8532b55 Brendan Higgins 2019-09-23 1585 #define KUNIT_ASSERT_LT(test, left, right) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1586 KUNIT_BINARY_LT_ASSERTION(test, KUNIT_ASSERTION, left, right)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1587
e4aea8f8532b55 Brendan Higgins 2019-09-23 1588 #define KUNIT_ASSERT_LT_MSG(test, left, right, fmt, ...) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1589 KUNIT_BINARY_LT_MSG_ASSERTION(test, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1590 KUNIT_ASSERTION, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1591 left, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1592 right, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1593 fmt, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1594 ##__VA_ARGS__)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1595 /**
e4aea8f8532b55 Brendan Higgins 2019-09-23 1596 * KUNIT_ASSERT_LE() - An assertion that @left is less than or equal to @right.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1597 * @test: The test context object.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1598 * @left: an arbitrary expression that evaluates to a primitive C type.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1599 * @right: an arbitrary expression that evaluates to a primitive C type.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1600 *
e4aea8f8532b55 Brendan Higgins 2019-09-23 1601 * Sets an assertion that the value that @left evaluates to is less than or
e4aea8f8532b55 Brendan Higgins 2019-09-23 1602 * equal to the value that @right evaluates to. This is the same as
e4aea8f8532b55 Brendan Higgins 2019-09-23 1603 * KUNIT_EXPECT_LE(), except it causes an assertion failure (see
e4aea8f8532b55 Brendan Higgins 2019-09-23 1604 * KUNIT_ASSERT_TRUE()) when the assertion is not met.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1605 */
e4aea8f8532b55 Brendan Higgins 2019-09-23 1606 #define KUNIT_ASSERT_LE(test, left, right) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1607 KUNIT_BINARY_LE_ASSERTION(test, KUNIT_ASSERTION, left, right)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1608
e4aea8f8532b55 Brendan Higgins 2019-09-23 1609 #define KUNIT_ASSERT_LE_MSG(test, left, right, fmt, ...) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1610 KUNIT_BINARY_LE_MSG_ASSERTION(test, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1611 KUNIT_ASSERTION, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1612 left, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1613 right, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1614 fmt, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1615 ##__VA_ARGS__)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1616
e4aea8f8532b55 Brendan Higgins 2019-09-23 1617 /**
e4aea8f8532b55 Brendan Higgins 2019-09-23 1618 * KUNIT_ASSERT_GT() - An assertion that @left is greater than @right.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1619 * @test: The test context object.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1620 * @left: an arbitrary expression that evaluates to a primitive C type.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1621 * @right: an arbitrary expression that evaluates to a primitive C type.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1622 *
e4aea8f8532b55 Brendan Higgins 2019-09-23 1623 * Sets an assertion that the value that @left evaluates to is greater than the
e4aea8f8532b55 Brendan Higgins 2019-09-23 1624 * value that @right evaluates to. This is the same as KUNIT_EXPECT_GT(), except
e4aea8f8532b55 Brendan Higgins 2019-09-23 1625 * it causes an assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion
e4aea8f8532b55 Brendan Higgins 2019-09-23 1626 * is not met.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1627 */
e4aea8f8532b55 Brendan Higgins 2019-09-23 1628 #define KUNIT_ASSERT_GT(test, left, right) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1629 KUNIT_BINARY_GT_ASSERTION(test, KUNIT_ASSERTION, left, right)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1630
e4aea8f8532b55 Brendan Higgins 2019-09-23 1631 #define KUNIT_ASSERT_GT_MSG(test, left, right, fmt, ...) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1632 KUNIT_BINARY_GT_MSG_ASSERTION(test, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1633 KUNIT_ASSERTION, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1634 left, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1635 right, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1636 fmt, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1637 ##__VA_ARGS__)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1638
e4aea8f8532b55 Brendan Higgins 2019-09-23 1639 /**
e4aea8f8532b55 Brendan Higgins 2019-09-23 1640 * KUNIT_ASSERT_GE() - Assertion that @left is greater than or equal to @right.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1641 * @test: The test context object.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1642 * @left: an arbitrary expression that evaluates to a primitive C type.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1643 * @right: an arbitrary expression that evaluates to a primitive C type.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1644 *
e4aea8f8532b55 Brendan Higgins 2019-09-23 1645 * Sets an assertion that the value that @left evaluates to is greater than the
e4aea8f8532b55 Brendan Higgins 2019-09-23 1646 * value that @right evaluates to. This is the same as KUNIT_EXPECT_GE(), except
e4aea8f8532b55 Brendan Higgins 2019-09-23 1647 * it causes an assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion
e4aea8f8532b55 Brendan Higgins 2019-09-23 1648 * is not met.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1649 */
e4aea8f8532b55 Brendan Higgins 2019-09-23 1650 #define KUNIT_ASSERT_GE(test, left, right) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1651 KUNIT_BINARY_GE_ASSERTION(test, KUNIT_ASSERTION, left, right)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1652
e4aea8f8532b55 Brendan Higgins 2019-09-23 1653 #define KUNIT_ASSERT_GE_MSG(test, left, right, fmt, ...) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1654 KUNIT_BINARY_GE_MSG_ASSERTION(test, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1655 KUNIT_ASSERTION, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1656 left, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1657 right, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1658 fmt, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1659 ##__VA_ARGS__)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1660
e4aea8f8532b55 Brendan Higgins 2019-09-23 1661 /**
e4aea8f8532b55 Brendan Higgins 2019-09-23 1662 * KUNIT_ASSERT_STREQ() - An assertion that strings @left and @right are equal.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1663 * @test: The test context object.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1664 * @left: an arbitrary expression that evaluates to a null terminated string.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1665 * @right: an arbitrary expression that evaluates to a null terminated string.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1666 *
e4aea8f8532b55 Brendan Higgins 2019-09-23 1667 * Sets an assertion that the values that @left and @right evaluate to are
e4aea8f8532b55 Brendan Higgins 2019-09-23 1668 * equal. This is the same as KUNIT_EXPECT_STREQ(), except it causes an
e4aea8f8532b55 Brendan Higgins 2019-09-23 1669 * assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1670 */
e4aea8f8532b55 Brendan Higgins 2019-09-23 1671 #define KUNIT_ASSERT_STREQ(test, left, right) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1672 KUNIT_BINARY_STR_EQ_ASSERTION(test, KUNIT_ASSERTION, left, right)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1673
e4aea8f8532b55 Brendan Higgins 2019-09-23 1674 #define KUNIT_ASSERT_STREQ_MSG(test, left, right, fmt, ...) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1675 KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1676 KUNIT_ASSERTION, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1677 left, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1678 right, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1679 fmt, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1680 ##__VA_ARGS__)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1681
e4aea8f8532b55 Brendan Higgins 2019-09-23 1682 /**
e4aea8f8532b55 Brendan Higgins 2019-09-23 1683 * KUNIT_ASSERT_STRNEQ() - Expects that strings @left and @right are not equal.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1684 * @test: The test context object.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1685 * @left: an arbitrary expression that evaluates to a null terminated string.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1686 * @right: an arbitrary expression that evaluates to a null terminated string.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1687 *
e4aea8f8532b55 Brendan Higgins 2019-09-23 1688 * Sets an expectation that the values that @left and @right evaluate to are
e4aea8f8532b55 Brendan Higgins 2019-09-23 1689 * not equal. This is semantically equivalent to
e4aea8f8532b55 Brendan Higgins 2019-09-23 1690 * KUNIT_ASSERT_TRUE(@test, strcmp((@left), (@right))). See KUNIT_ASSERT_TRUE()
e4aea8f8532b55 Brendan Higgins 2019-09-23 1691 * for more information.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1692 */
e4aea8f8532b55 Brendan Higgins 2019-09-23 1693 #define KUNIT_ASSERT_STRNEQ(test, left, right) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1694 KUNIT_BINARY_STR_NE_ASSERTION(test, KUNIT_ASSERTION, left, right)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1695
e4aea8f8532b55 Brendan Higgins 2019-09-23 1696 #define KUNIT_ASSERT_STRNEQ_MSG(test, left, right, fmt, ...) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1697 KUNIT_BINARY_STR_NE_MSG_ASSERTION(test, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1698 KUNIT_ASSERTION, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1699 left, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1700 right, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1701 fmt, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1702 ##__VA_ARGS__)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1703
e4aea8f8532b55 Brendan Higgins 2019-09-23 1704 /**
e4aea8f8532b55 Brendan Higgins 2019-09-23 1705 * KUNIT_ASSERT_NOT_ERR_OR_NULL() - Assertion that @ptr is not null and not err.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1706 * @test: The test context object.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1707 * @ptr: an arbitrary pointer.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1708 *
e4aea8f8532b55 Brendan Higgins 2019-09-23 1709 * Sets an assertion that the value that @ptr evaluates to is not null and not
e4aea8f8532b55 Brendan Higgins 2019-09-23 1710 * an errno stored in a pointer. This is the same as
e4aea8f8532b55 Brendan Higgins 2019-09-23 1711 * KUNIT_EXPECT_NOT_ERR_OR_NULL(), except it causes an assertion failure (see
e4aea8f8532b55 Brendan Higgins 2019-09-23 1712 * KUNIT_ASSERT_TRUE()) when the assertion is not met.
e4aea8f8532b55 Brendan Higgins 2019-09-23 1713 */
e4aea8f8532b55 Brendan Higgins 2019-09-23 1714 #define KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1715 KUNIT_PTR_NOT_ERR_OR_NULL_ASSERTION(test, KUNIT_ASSERTION, ptr)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1716
e4aea8f8532b55 Brendan Higgins 2019-09-23 1717 #define KUNIT_ASSERT_NOT_ERR_OR_NULL_MSG(test, ptr, fmt, ...) \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1718 KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1719 KUNIT_ASSERTION, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1720 ptr, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1721 fmt, \
e4aea8f8532b55 Brendan Higgins 2019-09-23 1722 ##__VA_ARGS__)
e4aea8f8532b55 Brendan Higgins 2019-09-23 1723
ae68283f3e666a Arpitha Raghunandan 2020-10-27 1724 /**
ae68283f3e666a Arpitha Raghunandan 2020-10-27 1725 * KUNIT_ARRAY_PARAM() - Helper method for test parameter generators
ae68283f3e666a Arpitha Raghunandan 2020-10-27 1726 * required in parameterized tests.
ae68283f3e666a Arpitha Raghunandan 2020-10-27 1727 * @name: prefix of the name for the test parameter generator function.
ae68283f3e666a Arpitha Raghunandan 2020-10-27 1728 * It will be suffixed by "_gen_params".
ae68283f3e666a Arpitha Raghunandan 2020-10-27 1729 * @array: a user-supplied pointer to an array of test parameters.
ae68283f3e666a Arpitha Raghunandan 2020-10-27 1730 */
ae68283f3e666a Arpitha Raghunandan 2020-10-27 1731 #define KUNIT_ARRAY_PARAM(name, array) \
ae68283f3e666a Arpitha Raghunandan 2020-10-27 1732 static void *name##_gen_params(void *prev) \
ae68283f3e666a Arpitha Raghunandan 2020-10-27 1733 { \
ae68283f3e666a Arpitha Raghunandan 2020-10-27 1734 typeof((array)[0]) * __next = prev ? ((typeof(__next)) prev) + 1 : (array); \
ae68283f3e666a Arpitha Raghunandan 2020-10-27 @1735 return __next - (array) < ARRAY_SIZE((array)) ? __next : NULL; \
ae68283f3e666a Arpitha Raghunandan 2020-10-27 1736 }
ae68283f3e666a Arpitha Raghunandan 2020-10-27 1737
.config.gz

Marco Elver

unread,
Oct 28, 2020, 4:30:38 AM10/28/20
to kernel test robot, Arpitha Raghunandan, Brendan Higgins, sk...@linuxfoundation.org, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, kbuil...@lists.01.org, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, LKML
So this means we probably want to make the param_value, and the return
and prev types of the generator "const void*".

Thanks,
-- Marco

Arpitha Raghunandan

unread,
Oct 28, 2020, 4:45:29 AM10/28/20
to Marco Elver, Brendan Higgins, sk...@linuxfoundation.org, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, LKML, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
I will make this change.
Oh, I hadn't considered this earlier. I will try it out for the next version.

>> static void kunit_print_string_stream(struct kunit *test,
>> struct string_stream *stream)
>> {
>> @@ -168,6 +174,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_value)
>> + kunit_print_failed_param(test);
>>
>> WARN_ON(string_stream_destroy(stream));
>> }
>> @@ -239,7 +247,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_value = test_case->generate_params(NULL);
>> + test->param_index = 0;
>> +
>> + while (test->param_value) {
>> + test_case->run_case(test);
>> + test->param_value = test_case->generate_params(test->param_value);
>> + test->param_index++;
>> + }
>> + }
>
> Thanks,
> -- Marco
>

I'll make all the suggested changes.
Thanks!

Arpitha Raghunandan

unread,
Oct 28, 2020, 4:47:34 AM10/28/20
to Marco Elver, kernel test robot, Brendan Higgins, sk...@linuxfoundation.org, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, kbuil...@lists.01.org, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, LKML
Okay, I'll fix this.
Thanks!

kernel test robot

unread,
Oct 31, 2020, 2:42:25 PM10/31/20
to Arpitha Raghunandan, brendan...@google.com, sk...@linuxfoundation.org, el...@google.com, yza...@google.com, ty...@mit.edu, adilger...@dilger.ca, kbuil...@lists.01.org, clang-bu...@googlegroups.com, Arpitha Raghunandan, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-...@vger.kernel.org
Hi Arpitha,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on ext4/dev]
[also build test ERROR on linus/master v5.10-rc1 next-20201030]
[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/20201028-015018
base: https://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git dev
config: x86_64-randconfig-a005-20201031 (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project 72ddd559b8aafef402091f8e192e025022e4ebef)
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
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
# https://github.com/0day-ci/linux/commit/2de1e52708cd83d1dc4c718876683f6809045a98
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Arpitha-Raghunandan/kunit-Support-for-Parameterized-Testing/20201028-015018
git checkout 2de1e52708cd83d1dc4c718876683f6809045a98
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <l...@intel.com>

All errors (new ones prefixed by >>):

>> fs/ext4/inode-test.c:214:1: error: returning 'typeof ((test_data)[0]) *' (aka 'const struct timestamp_expectation *') from a function with result type 'void *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
KUNIT_ARRAY_PARAM(ext4_inode, test_data);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/kunit/test.h:1735:10: note: expanded from macro 'KUNIT_ARRAY_PARAM'
return __next - (array) < ARRAY_SIZE((array)) ? __next : NULL; \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

vim +214 fs/ext4/inode-test.c

213
> 214 KUNIT_ARRAY_PARAM(ext4_inode, test_data);
215
.config.gz

Arpitha Raghunandan

unread,
Nov 5, 2020, 2:31:59 AM11/5/20
to Marco Elver, Brendan Higgins, sk...@linuxfoundation.org, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, LKML, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
On 28/10/20 12:51 am, Marco Elver wrote:
I tried adding support to run each parameter as a distinct test case by
making changes to kunit_run_case_catch_errors(). The issue here is that
since the results are displayed in KTAP format, this change will result in
each parameter being considered a subtest of another subtest (test case
in KUnit). To make this work, a lot of changes in other parts will be required,
and it will get complicated. Running all parameters as one test case seems
to be a better option right now. So for now, I will modify what is displayed
by kunit_err() in case of test failure.

Marco Elver

unread,
Nov 5, 2020, 3:30:29 AM11/5/20
to Arpitha Raghunandan, Brendan Higgins, sk...@linuxfoundation.org, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, LKML, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
Do you have example output? That might help understand what's going on.
> --
> You received this message because you are subscribed to the Google Groups "KUnit Development" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to kunit-dev+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/kunit-dev/73c4e46c-10f1-9362-b4fb-94ea9d74e9b2%40gmail.com.

Arpitha Raghunandan

unread,
Nov 5, 2020, 9:30:35 AM11/5/20
to Marco Elver, Brendan Higgins, sk...@linuxfoundation.org, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, LKML, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
The change that I tried can be seen here (based on the v4 patch):
https://gist.github.com/arpi-r/4822899087ca4cc34572ed9e45cc5fee.

Using the kunit tool, I get this error:

[19:20:41] [ERROR] expected 7 test suites, but got -1
[ERROR] no tests run!
[19:20:41] ============================================================
[19:20:41] Testing complete. 0 tests run. 0 failed. 0 crashed.

But this error is only because of how the tool displays the results.
The test actually does run, as can be seen in the dmesg output:

TAP version 14
1..7
# Subtest: ext4_inode_test
1..1
ok 1 - inode_test_xtimestamp_decoding 1
ok 1 - inode_test_xtimestamp_decoding 2
ok 1 - inode_test_xtimestamp_decoding 3
ok 1 - inode_test_xtimestamp_decoding 4
ok 1 - inode_test_xtimestamp_decoding 5
ok 1 - inode_test_xtimestamp_decoding 6
ok 1 - inode_test_xtimestamp_decoding 7
ok 1 - inode_test_xtimestamp_decoding 8
ok 1 - inode_test_xtimestamp_decoding 9
ok 1 - inode_test_xtimestamp_decoding 10
ok 1 - inode_test_xtimestamp_decoding 11
ok 1 - inode_test_xtimestamp_decoding 12
ok 1 - inode_test_xtimestamp_decoding 13
ok 1 - inode_test_xtimestamp_decoding 14
ok 1 - inode_test_xtimestamp_decoding 15
ok 1 - inode_test_xtimestamp_decoding 16
ok 1 - ext4_inode_test
(followed by other kunit test outputs)

Marco Elver

unread,
Nov 5, 2020, 10:02:34 AM11/5/20
to Arpitha Raghunandan, Brendan Higgins, sk...@linuxfoundation.org, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, LKML, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
Hmm, interesting. Let me play with your patch a bit.

One option is to just have the test case number increment as well,
i.e. have this:
| ok 1 - inode_test_xtimestamp_decoding#1
| ok 2 - inode_test_xtimestamp_decoding#2
| ok 3 - inode_test_xtimestamp_decoding#3
| ok 4 - inode_test_xtimestamp_decoding#4
| ok 5 - inode_test_xtimestamp_decoding#5
...

Or is there something else I missed?

Thanks,
-- Marco

Marco Elver

unread,
Nov 5, 2020, 2:55:12 PM11/5/20
to Arpitha Raghunandan, Brendan Higgins, sk...@linuxfoundation.org, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, LKML, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
On Thu, Nov 05, 2020 at 04:02PM +0100, Marco Elver wrote:
> On Thu, 5 Nov 2020 at 15:30, Arpitha Raghunandan <98....@gmail.com> wrote:
[...]
Right, so TAP wants the exact number of tests it will run ahead of time.
In which case we can still put the results of each parameterized test in
a diagnostic. Please see my proposed patch below, which still does
proper initialization/destruction of each parameter case as if it was
its own test case.

With it the output looks as follows:

| TAP version 14
| 1..6
| # Subtest: ext4_inode_test
| 1..1
| # ok param#0 - inode_test_xtimestamp_decoding
| # ok param#1 - inode_test_xtimestamp_decoding
| # ok param#2 - inode_test_xtimestamp_decoding
| # ok param#3 - inode_test_xtimestamp_decoding
| # ok param#4 - inode_test_xtimestamp_decoding
| # ok param#5 - inode_test_xtimestamp_decoding
| # ok param#6 - inode_test_xtimestamp_decoding
| # ok param#7 - inode_test_xtimestamp_decoding
| # ok param#8 - inode_test_xtimestamp_decoding
| # ok param#9 - inode_test_xtimestamp_decoding
| # ok param#10 - inode_test_xtimestamp_decoding
| # ok param#11 - inode_test_xtimestamp_decoding
| # ok param#12 - inode_test_xtimestamp_decoding
| # ok param#13 - inode_test_xtimestamp_decoding
| # ok param#14 - inode_test_xtimestamp_decoding
| # ok param#15 - inode_test_xtimestamp_decoding
| ok 1 - inode_test_xtimestamp_decoding
| ok 1 - ext4_inode_test

Would that be reasonable? If so, feel free to take the patch and
test/adjust as required.

I'm not sure on the best format -- is there is a recommended format for
parameterized test result output? If not, I suppose we can put anything
we like into the diagnostic.

Thanks,
-- Marco

------ >8 ------

From ccbf4e2e190a2d7c6a94a51c9b1fb3b9a940e578 Mon Sep 17 00:00:00 2001
From: Arpitha Raghunandan <98....@gmail.com>
Date: Tue, 27 Oct 2020 23:16:30 +0530
Subject: [PATCH] kunit: Support for Parameterized Testing

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....@gmail.com>
Co-developed-by: Marco Elver <el...@google.com>
Signed-off-by: Marco Elver <el...@google.com>
---
Changes v4->v5:
- Update kernel-doc comments.
- Use const void* for generator return and prev value types.
- Add kernel-doc comment for KUNIT_ARRAY_PARAM.
- Rework parameterized test case execution strategy: each parameter is executed
as if it was its own test case, with its own test initialization and cleanup
(init and exit are called, etc.). However, we cannot add new test cases per TAP
protocol once we have already started execution. Instead, log the result of
each parameter run as a diagnostic comment.
Changes v3->v4:
- Rename kunit variables
- Rename generator function helper macro
- Add documentation for generator approach
- Display test case name in case of failure along with param index
Changes v2->v3:
- Modifictaion of generator macro and method
Changes v1->v2:
- Use of a generator method to access test case parameters
---
include/kunit/test.h | 36 ++++++++++++++++++++++++++++++++++
lib/kunit/test.c | 46 +++++++++++++++++++++++++++++++-------------
2 files changed, 69 insertions(+), 13 deletions(-)

diff --git a/include/kunit/test.h b/include/kunit/test.h
index 9197da792336..ae5488a37e48 100644
--- a/include/kunit/test.h
+++ b/include/kunit/test.h
@@ -107,6 +107,7 @@ struct kunit;
*
* @run_case: the function representing the actual test case.
* @name: the name of the test case.
+ * @generate_params: the generator function for parameterized tests.
*
* A test case is a function with the signature,
* ``void (*)(struct kunit *)``
@@ -141,6 +142,7 @@ struct kunit;
struct kunit_case {
void (*run_case)(struct kunit *test);
const char *name;
+ const void* (*generate_params)(const void *prev);

/* private: internal use only. */
bool success;
@@ -163,6 +165,22 @@ static inline char *kunit_status_to_string(bool status)
*/
#define KUNIT_CASE(test_name) { .run_case = test_name, .name = #test_name }

+/**
+ * KUNIT_CASE_PARAM - A helper for creation a parameterized &struct kunit_case
+ *
+ * @test_name: a reference to a test case function.
+ * @gen_params: a reference to a parameter generator function.
+ *
+ * The generator function ``const void* gen_params(const void *prev)`` 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.
+ */
+#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 +226,10 @@ struct kunit {
const char *name; /* Read only after initialization! */
char *log; /* Points at case log after initialization */
struct kunit_try_catch try_catch;
+ /* param_value is the current parameter value for a test case. */
+ const void *param_value;
+ /* param_index stores the index of the parameter in parameterized tests. */
+ int param_index;
/*
* 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 +1764,18 @@ do { \
fmt, \
##__VA_ARGS__)

+/**
+ * KUNIT_ARRAY_PARAM() - Define test parameter generator from an array.
+ * @name: prefix for the test parameter generator function.
+ * @array: array of test parameters.
+ *
+ * Define function @name_gen_params which uses @array to generate parameters.
+ */
+#define KUNIT_ARRAY_PARAM(name, array) \
+ static const void *name##_gen_params(const 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..453ebe4da77d 100644
--- a/lib/kunit/test.c
+++ b/lib/kunit/test.c
@@ -325,29 +325,25 @@ static void kunit_catch_run_case(void *data)
* occur in a test case and reports them as failures.
*/
static void kunit_run_case_catch_errors(struct kunit_suite *suite,
- struct kunit_case *test_case)
+ struct kunit_case *test_case,
+ struct kunit *test)
{
struct kunit_try_catch_context context;
struct kunit_try_catch *try_catch;
- struct kunit test;

- kunit_init_test(&test, test_case->name, test_case->log);
- try_catch = &test.try_catch;
+ kunit_init_test(test, test_case->name, test_case->log);
+ try_catch = &test->try_catch;

kunit_try_catch_init(try_catch,
- &test,
+ test,
kunit_try_run_case,
kunit_catch_run_case);
- context.test = &test;
+ context.test = test;
context.suite = suite;
context.test_case = test_case;
kunit_try_catch_run(try_catch, &context);

- test_case->success = test.success;
-
- kunit_print_ok_not_ok(&test, true, test_case->success,
- kunit_test_case_num(suite, test_case),
- test_case->name);
+ test_case->success = test->success;
}

int kunit_run_tests(struct kunit_suite *suite)
@@ -356,8 +352,32 @@ int kunit_run_tests(struct kunit_suite *suite)

kunit_print_subtest_start(suite);

- kunit_suite_for_each_test_case(suite, test_case)
- kunit_run_case_catch_errors(suite, test_case);
+ kunit_suite_for_each_test_case(suite, test_case) {
+ struct kunit test = { .param_value = NULL, .param_index = 0 };
+ bool test_success = true;
+
+ if (test_case->generate_params)
+ test.param_value = test_case->generate_params(NULL);
+
+ do {
+ kunit_run_case_catch_errors(suite, test_case, &test);
+ test_success &= test_case->success;
+
+ if (test_case->generate_params) {
+ kunit_log(KERN_INFO, &test,
+ KUNIT_SUBTEST_INDENT
+ "# %s param#%d - %s",
+ kunit_status_to_string(test.success),
+ test.param_index, test_case->name);
+ test.param_value = test_case->generate_params(test.param_value);
+ test.param_index++;
+ }
+ } while (test.param_value);
+
+ kunit_print_ok_not_ok(&test, true, test_success,
+ kunit_test_case_num(suite, test_case),
+ test_case->name);
+ }

kunit_print_subtest_end(suite);

--
2.29.1.341.ge80a0c044ae-goog

Arpitha Raghunandan

unread,
Nov 6, 2020, 12:54:22 AM11/6/20
to Marco Elver, Brendan Higgins, sk...@linuxfoundation.org, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, LKML, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
I think this format of output should be fine for parameterized tests.
But, this patch has the same issue as earlier. While, the tests run and
this is the output that can be seen using dmesg, it still causes an issue on
using the kunit tool. It gives a similar error:

[11:07:38] [ERROR] expected 7 test suites, but got -1
[11:07:38] [ERROR] expected_suite_index -1, but got 2
[11:07:38] [ERROR] got unexpected test suite: kunit-try-catch-test
[ERROR] no tests run!
[11:07:38] ============================================================
[11:07:38] Testing complete. 0 tests run. 0 failed. 0 crashed.

Thanks!

Marco Elver

unread,
Nov 6, 2020, 3:11:37 AM11/6/20
to Arpitha Raghunandan, Brendan Higgins, sk...@linuxfoundation.org, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, LKML, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
I'd suggest testing without these patches and diffing the output.
AFAIK we're not adding any new non-# output, so it might be a
pre-existing bug in some parsing code. Either that, or the parsing
code does not respect the # correctly?

Thanks,
-- Marco

Marco Elver

unread,
Nov 6, 2020, 7:34:41 AM11/6/20
to Arpitha Raghunandan, Brendan Higgins, sk...@linuxfoundation.org, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, LKML, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
On Fri, Nov 06, 2020 at 09:11AM +0100, Marco Elver wrote:
> On Fri, 6 Nov 2020 at 06:54, Arpitha Raghunandan <98....@gmail.com> wrote:
[...]
> > I think this format of output should be fine for parameterized tests.
> > But, this patch has the same issue as earlier. While, the tests run and
> > this is the output that can be seen using dmesg, it still causes an issue on
> > using the kunit tool. It gives a similar error:
> >
> > [11:07:38] [ERROR] expected 7 test suites, but got -1
> > [11:07:38] [ERROR] expected_suite_index -1, but got 2
> > [11:07:38] [ERROR] got unexpected test suite: kunit-try-catch-test
> > [ERROR] no tests run!
> > [11:07:38] ============================================================
> > [11:07:38] Testing complete. 0 tests run. 0 failed. 0 crashed.
> >
>
> I'd suggest testing without these patches and diffing the output.
> AFAIK we're not adding any new non-# output, so it might be a
> pre-existing bug in some parsing code. Either that, or the parsing
> code does not respect the # correctly?

Hmm, tools/testing/kunit/kunit_parser.py has

SUBTEST_DIAGNOSTIC = re.compile(r'^[\s]+# .*?: (.*)$')

, which seems to expect a ': ' in there. Not sure if this is required by
TAP, but let's leave this alone for now.

We can change the output to not trip this up, which might also be more a
consistent diagnostic format vs. other diagnostics. See the revised
patch below. With it the output is as follows:

| TAP version 14
| 1..6
| # Subtest: ext4_inode_test
| 1..1
| # inode_test_xtimestamp_decoding: param-0 ok
| # inode_test_xtimestamp_decoding: param-1 ok
| # inode_test_xtimestamp_decoding: param-2 ok
| # inode_test_xtimestamp_decoding: param-3 ok
| # inode_test_xtimestamp_decoding: param-4 ok
| # inode_test_xtimestamp_decoding: param-5 ok
| # inode_test_xtimestamp_decoding: param-6 ok
| # inode_test_xtimestamp_decoding: param-7 ok
| # inode_test_xtimestamp_decoding: param-8 ok
| # inode_test_xtimestamp_decoding: param-9 ok
| # inode_test_xtimestamp_decoding: param-10 ok
| # inode_test_xtimestamp_decoding: param-11 ok
| # inode_test_xtimestamp_decoding: param-12 ok
| # inode_test_xtimestamp_decoding: param-13 ok
| # inode_test_xtimestamp_decoding: param-14 ok
| # inode_test_xtimestamp_decoding: param-15 ok
| ok 1 - inode_test_xtimestamp_decoding
| ok 1 - ext4_inode_test

And kunit-tool seems to be happy as well.

Thanks,
-- Marco

------ >8 ------

From 13a94d75d6b1b430e89fcff2cd76629b56b9d636 Mon Sep 17 00:00:00 2001
index 750704abe89a..329fee9e0634 100644
+ "# %s: param-%d %s",
+ test_case->name, test.param_index,
+ kunit_status_to_string(test.success));
+ test.param_value = test_case->generate_params(test.param_value);
+ test.param_index++;
+ }
+ } while (test.param_value);
+
+ kunit_print_ok_not_ok(&test, true, test_success,
+ kunit_test_case_num(suite, test_case),
+ test_case->name);
+ }

kunit_print_subtest_end(suite);

--
2.29.2.222.g5d2a92d10f8-goog

Arpitha Raghunandan

unread,
Nov 6, 2020, 11:17:03 AM11/6/20
to Marco Elver, Brendan Higgins, sk...@linuxfoundation.org, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, LKML, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
On 06/11/20 6:04 pm, Marco Elver wrote:
> On Fri, Nov 06, 2020 at 09:11AM +0100, Marco Elver wrote:
>> On Fri, 6 Nov 2020 at 06:54, Arpitha Raghunandan <98....@gmail.com> wrote:
> [...]
>>> I think this format of output should be fine for parameterized tests.
>>> But, this patch has the same issue as earlier. While, the tests run and
>>> this is the output that can be seen using dmesg, it still causes an issue on
>>> using the kunit tool. It gives a similar error:
>>>
>>> [11:07:38] [ERROR] expected 7 test suites, but got -1
>>> [11:07:38] [ERROR] expected_suite_index -1, but got 2
>>> [11:07:38] [ERROR] got unexpected test suite: kunit-try-catch-test
>>> [ERROR] no tests run!
>>> [11:07:38] ============================================================
>>> [11:07:38] Testing complete. 0 tests run. 0 failed. 0 crashed.
>>>
>>
>> I'd suggest testing without these patches and diffing the output.
>> AFAIK we're not adding any new non-# output, so it might be a
>> pre-existing bug in some parsing code. Either that, or the parsing
>> code does not respect the # correctly?
>
> Hmm, tools/testing/kunit/kunit_parser.py has
>
> SUBTEST_DIAGNOSTIC = re.compile(r'^[\s]+# .*?: (.*)$')
>
> , which seems to expect a ': ' in there. Not sure if this is required by
> TAP, but let's leave this alone for now.
>

Oh okay.
Yes this works as expected. Thank you!
I will send this patch as v5.

Arpitha Raghunandan

unread,
Nov 6, 2020, 1:28:31 PM11/6/20
to brendan...@google.com, sk...@linuxfoundation.org, el...@google.com, yza...@google.com, ty...@mit.edu, adilger...@dilger.ca, Arpitha Raghunandan, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-...@vger.kernel.org, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
index 750704abe89a..b8b63aeda504 100644
--
2.25.1

Arpitha Raghunandan

unread,
Nov 6, 2020, 1:29:15 PM11/6/20
to brendan...@google.com, sk...@linuxfoundation.org, el...@google.com, yza...@google.com, ty...@mit.edu, adilger...@dilger.ca, Arpitha Raghunandan, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-...@vger.kernel.org, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
Modify fs/ext4/inode-test.c to use the parameterized testing
feature of KUnit.

Signed-off-by: Arpitha Raghunandan <98....@gmail.com>
---
Changes v4->v5:
- No change to this patch of the patch series

Marco Elver

unread,
Nov 6, 2020, 1:37:46 PM11/6/20
to Arpitha Raghunandan, Brendan Higgins, sk...@linuxfoundation.org, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, LKML, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
On Fri, 6 Nov 2020 at 19:28, Arpitha Raghunandan <98....@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....@gmail.com>
> Co-developed-by: Marco Elver <el...@google.com>
> Signed-off-by: Marco Elver <el...@google.com>
> ---
[...]
> include/kunit/test.h | 36 ++++++++++++++++++++++++++++++++++
> lib/kunit/test.c | 46 +++++++++++++++++++++++++++++++-------------
> 2 files changed, 69 insertions(+), 13 deletions(-)

I think this is ready. Thank you for your patience, and addressing my
comments! I'm obviously fine with v5, but I think my Ack or Review
won't count much because of Co-developed. :-)

Others: Please take another look.

Thanks,
-- Marco

Marco Elver

unread,
Nov 6, 2020, 1:38:56 PM11/6/20
to Arpitha Raghunandan, Brendan Higgins, sk...@linuxfoundation.org, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, LKML, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
On Fri, 6 Nov 2020 at 19:29, Arpitha Raghunandan <98....@gmail.com> wrote:
> Modify fs/ext4/inode-test.c to use the parameterized testing
> feature of KUnit.
>
> Signed-off-by: Arpitha Raghunandan <98....@gmail.com>
> ---
[...]
> fs/ext4/inode-test.c | 314 ++++++++++++++++++++++---------------------
> 1 file changed, 158 insertions(+), 156 deletions(-)

Acked-by: Marco Elver <el...@google.com>

Thanks,
-- Marco

Marco Elver

unread,
Nov 6, 2020, 1:46:10 PM11/6/20
to Arpitha Raghunandan, Brendan Higgins, sk...@linuxfoundation.org, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, LKML, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
On Fri, 6 Nov 2020 at 19:28, Arpitha Raghunandan <98....@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....@gmail.com>
> Co-developed-by: Marco Elver <el...@google.com>
> Signed-off-by: Marco Elver <el...@google.com>
[...]
> - kunit_suite_for_each_test_case(suite, test_case)
> - kunit_run_case_catch_errors(suite, test_case);
> + kunit_suite_for_each_test_case(suite, test_case) {
> + struct kunit test = { .param_value = NULL, .param_index = 0 };
> + bool test_success = true;
> +
> + if (test_case->generate_params)
> + test.param_value = test_case->generate_params(NULL);
> +
> + do {
> + kunit_run_case_catch_errors(suite, test_case, &test);
> + test_success &= test_case->success;
> +
> + if (test_case->generate_params) {
> + kunit_log(KERN_INFO, &test,
> + KUNIT_SUBTEST_INDENT
> + "# %s: param-%d %s",
> + test_case->name, test.param_index,
> + kunit_status_to_string(test.success));

Sorry, I still found something. The patch I sent had this aligned with
the '(', whereas when I apply this patch it no longer is aligned. Why?

I see the rest of the file also aligns arguments with opening '(', so
I think your change is inconsistent.

Thanks,
-- Marco

Arpitha Raghunandan

unread,
Nov 6, 2020, 2:00:45 PM11/6/20
to Marco Elver, Brendan Higgins, sk...@linuxfoundation.org, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, LKML, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
Ah those lines had spaces instead of tab and I think I messed up the alignment
fixing that. I will send another version fixing this.
Thanks!

> Thanks,
> -- Marco
>

Marco Elver

unread,
Nov 6, 2020, 2:05:36 PM11/6/20
to Arpitha Raghunandan, Brendan Higgins, sk...@linuxfoundation.org, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, LKML, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
It was tabs then <8 spaces to align. checkpatch.pl certainly is happy with that.

> > Thanks,
> > -- Marco
> >
>

Arpitha Raghunandan

unread,
Nov 6, 2020, 2:22:27 PM11/6/20
to brendan...@google.com, sk...@linuxfoundation.org, el...@google.com, yza...@google.com, ty...@mit.edu, adilger...@dilger.ca, Arpitha Raghunandan, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-...@vger.kernel.org, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
Implementation of support for parameterized testing in KUnit.
This approach requires the creation of a test case using the
KUNIT_CASE_PARAM macro that accepts a generator function as input.
This generator function should return the next parameter given the
previous parameter in parameterized tests. It also provides
a macro to generate common-case generators.

Signed-off-by: Arpitha Raghunandan <98....@gmail.com>
Co-developed-by: Marco Elver <el...@google.com>
Signed-off-by: Marco Elver <el...@google.com>
---
Changes v5->v6:
- Fix alignment to maintain consistency
Changes v4->v5:
- Update kernel-doc comments.
- Use const void* for generator return and prev value types.
- Add kernel-doc comment for KUNIT_ARRAY_PARAM.
- Rework parameterized test case execution strategy: each parameter is executed
as if it was its own test case, with its own test initialization and cleanup
(init and exit are called, etc.). However, we cannot add new test cases per TAP
protocol once we have already started execution. Instead, log the result of
each parameter run as a diagnostic comment.
Changes v3->v4:
- Rename kunit variables
- Rename generator function helper macro
- Add documentation for generator approach
- Display test case name in case of failure along with param index
Changes v2->v3:
- Modifictaion of generator macro and method
Changes v1->v2:
- Use of a generator method to access test case parameters

include/kunit/test.h | 36 ++++++++++++++++++++++++++++++++++
lib/kunit/test.c | 46 +++++++++++++++++++++++++++++++-------------
2 files changed, 69 insertions(+), 13 deletions(-)

diff --git a/include/kunit/test.h b/include/kunit/test.h
index db1b0ae666c4..16616d3974f9 100644
index 750704abe89a..329fee9e0634 100644
- kunit_suite_for_each_test_case(suite, test_case)
- kunit_run_case_catch_errors(suite, test_case);
+ kunit_suite_for_each_test_case(suite, test_case) {
+ struct kunit test = { .param_value = NULL, .param_index = 0 };
+ bool test_success = true;
+
+ if (test_case->generate_params)
+ test.param_value = test_case->generate_params(NULL);
+
+ do {
+ kunit_run_case_catch_errors(suite, test_case, &test);
+ test_success &= test_case->success;
+
+ if (test_case->generate_params) {
+ kunit_log(KERN_INFO, &test,
+ KUNIT_SUBTEST_INDENT
+ "# %s: param-%d %s",
+ test_case->name, test.param_index,
+ kunit_status_to_string(test.success));

Arpitha Raghunandan

unread,
Nov 6, 2020, 2:23:13 PM11/6/20
to brendan...@google.com, sk...@linuxfoundation.org, el...@google.com, yza...@google.com, ty...@mit.edu, adilger...@dilger.ca, Arpitha Raghunandan, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-...@vger.kernel.org, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
Modify fs/ext4/inode-test.c to use the parameterized testing
feature of KUnit.

Signed-off-by: Arpitha Raghunandan <98....@gmail.com>
---
Changes v5->v6:
- No change to this patch of the patch series
Changes v4->v5:
- No change to this patch of the patch series
Changes v3->v4:
- Modification based on latest implementation of KUnit parameterized testing
Changes v2->v3:
- Marked hardcoded test data const
- Modification based on latest implementation of KUnit parameterized testing
Changes v1->v2:
- Modification based on latest implementation of KUnit parameterized testing

fs/ext4/inode-test.c | 314 ++++++++++++++++++++++---------------------
1 file changed, 158 insertions(+), 156 deletions(-)

Marco Elver

unread,
Nov 6, 2020, 2:37:38 PM11/6/20
to Arpitha Raghunandan, Brendan Higgins, sk...@linuxfoundation.org, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, LKML, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
On Fri, 6 Nov 2020 at 20:22, Arpitha Raghunandan <98....@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....@gmail.com>
> Co-developed-by: Marco Elver <el...@google.com>
> Signed-off-by: Marco Elver <el...@google.com>
> ---
[...]
>
> include/kunit/test.h | 36 ++++++++++++++++++++++++++++++++++
> lib/kunit/test.c | 46 +++++++++++++++++++++++++++++++-------------
> 2 files changed, 69 insertions(+), 13 deletions(-)

Looks good, thank you!

David Gow

unread,
Nov 6, 2020, 11:58:34 PM11/6/20
to Arpitha Raghunandan, Brendan Higgins, Shuah Khan, Marco Elver, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, Linux Kernel Mailing List, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
On Sat, Nov 7, 2020 at 3:22 AM Arpitha Raghunandan <98....@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....@gmail.com>
> Co-developed-by: Marco Elver <el...@google.com>
> Signed-off-by: Marco Elver <el...@google.com>
> ---

This looks good to me! A couple of minor thoughts about the output
format below, but I'm quite happy to have this as-is regardless.

Reviewed-by: David Gow <davi...@google.com>

Cheers,
-- David
Would it make sense to have this imitate the TAP format a bit more?
So, have "# [ok|not ok] - [name]" as the format? [name] could be
something like "[test_case->name]:param-[index]" or similar.
If we keep it commented out and don't indent it further, it won't
formally be a nested test (though if we wanted to support those later,
it'd be easy to add), but I think it would be nicer to be consistent
here.

My other suggestion -- albeit one outside the scope of this initial
version -- would be to allow the "param-%d" name to be overridden
somehow by a test. For example, the ext4 inode test has names for all
its test cases: it'd be nice to be able to display those instead (even
if they're not formatted as identifiers as-is).

> + test_case->name, test.param_index,
> + kunit_status_to_string(test.success));
> + test.param_value = test_case->generate_params(test.param_value);
> + test.param_index++;
> + }
> + } while (test.param_value);
> +
> + kunit_print_ok_not_ok(&test, true, test_success,
> + kunit_test_case_num(suite, test_case),
> + test_case->name);
> + }
>
> kunit_print_subtest_end(suite);
>
> --
> 2.25.1
>
> --
> You received this message because you are subscribed to the Google Groups "KUnit Development" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to kunit-dev+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/kunit-dev/20201106192154.51514-1-98.arpi%40gmail.com.

David Gow

unread,
Nov 7, 2020, 12:00:30 AM11/7/20
to Arpitha Raghunandan, Brendan Higgins, Shuah Khan, Marco Elver, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, Linux Kernel Mailing List, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
On Sat, Nov 7, 2020 at 3:23 AM Arpitha Raghunandan <98....@gmail.com> wrote:
>
> Modify fs/ext4/inode-test.c to use the parameterized testing
> feature of KUnit.
>
> Signed-off-by: Arpitha Raghunandan <98....@gmail.com>
> ---

This looks good to me. Thanks!

Reviewed-by: David Gow <davi...@google.com>

-- David

Marco Elver

unread,
Nov 7, 2020, 5:06:40 AM11/7/20
to David Gow, Arpitha Raghunandan, Brendan Higgins, Shuah Khan, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, Linux Kernel Mailing List, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
[...]
> > - kunit_suite_for_each_test_case(suite, test_case)
> > - kunit_run_case_catch_errors(suite, test_case);
> > + kunit_suite_for_each_test_case(suite, test_case) {
> > + struct kunit test = { .param_value = NULL, .param_index = 0 };
> > + bool test_success = true;
> > +
> > + if (test_case->generate_params)
> > + test.param_value = test_case->generate_params(NULL);
> > +
> > + do {
> > + kunit_run_case_catch_errors(suite, test_case, &test);
> > + test_success &= test_case->success;
> > +
> > + if (test_case->generate_params) {
> > + kunit_log(KERN_INFO, &test,
> > + KUNIT_SUBTEST_INDENT
> > + "# %s: param-%d %s",
>
> Would it make sense to have this imitate the TAP format a bit more?
> So, have "# [ok|not ok] - [name]" as the format? [name] could be
> something like "[test_case->name]:param-[index]" or similar.
> If we keep it commented out and don't indent it further, it won't
> formally be a nested test (though if we wanted to support those later,
> it'd be easy to add), but I think it would be nicer to be consistent
> here.

The previous attempt [1] at something similar failed because it seems
we'd need to teach kunit-tool new tricks [2], too.
[1] https://lkml.kernel.org/r/202011051955...@elver.google.com
[2] https://lkml.kernel.org/r/202011061234...@elver.google.com

So if we go with a different format, we might need a patch before this
one to make kunit-tool compatible with that type of diagnostic.

Currently I think we have the following proposals for a format:

1. The current "# [test_case->name]: param-[index] [ok|not ok]" --
this works well, because no changes to kunit-tool are required, and it
also picks up the diagnostic context for the case and displays that on
test failure.

2. Your proposed "# [ok|not ok] - [test_case->name]:param-[index]".
As-is, this needs a patch for kunit-tool as well. I just checked, and
if we change it to "# [ok|not ok] - [test_case->name]: param-[index]"
(note the space after ':') it works without changing kunit-tool. ;-)

3. Something like "# [ok|not ok] param-[index] - [test_case->name]",
which I had played with earlier but kunit-tool is definitely not yet
happy with.

So my current preference is (2) with the extra space (no change to
kunit-tool required). WDYT?

> My other suggestion -- albeit one outside the scope of this initial
> version -- would be to allow the "param-%d" name to be overridden
> somehow by a test. For example, the ext4 inode test has names for all
> its test cases: it'd be nice to be able to display those instead (even
> if they're not formatted as identifiers as-is).

Right, I was thinking about this, but it'd need a way to optionally
pass another function that converts const void* params to readable
strings. But as you say, we should do that as a follow-up patch later
because it might require a few more iterations.

[...]

Thanks,
-- Marco

Arpitha Raghunandan

unread,
Nov 9, 2020, 1:49:31 AM11/9/20
to Marco Elver, David Gow, Brendan Higgins, Shuah Khan, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, Linux Kernel Mailing List, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
Which format do we finally go with?

David Gow

unread,
Nov 10, 2020, 2:21:03 AM11/10/20
to Arpitha Raghunandan, Marco Elver, Brendan Higgins, Shuah Khan, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, Linux Kernel Mailing List, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
Hmm… that failure in kunit_tool is definitely a bug: we shouldn't care
what comes after the comment character except if it's an explicit
subtest declaration or a crash. I'll try to put a patch together to
fix it, but I'd rather not delay this just for that.

In any thought about this a bit more, It turns out that the proposed
KTAP spec[1] discourages the use of ':', except as part of a subtest
declaration, or perhaps an as-yet-unspecified fully-qualified test
name. The latter is what I was going for, but if it's actively
breaking kunit_tool, we might want to hold off on it.

If we were to try to treat these as subtests in accordance with that
spec, the way we'd want to use one of these options:
A) "[ok|not ok] [index] - param-[index]" -- This doesn't mention the
test case name, but otherwise treats things exactly the same way we
treat existing subtests.

B) "[ok|not ok] [index] - [test_case->name]" -- This doesn't name the
"subtest", just gives repeated results with the same name.

C) "[ok|not ok] [index] - [test_case->name][separator]param-[index]"
-- This is equivalent to my suggestion with a separator of ":", or 2
above with a separator of ": ". The in-progress spec doesn't yet
specify how these fully-qualified names would work, other than that
they'd use a colon somewhere, and if we comment it out, ": " is
required.

>
> Which format do we finally go with?
>

I'm actually going to make another wild suggestion for this, which is
a combination of (1) and (A):
"# [test_case->name]: [ok|not ok] [index] - param-[index]"

This gives us a KTAP-compliant result line, except prepended with "#
[test_case->name]: ", which makes it formally a diagnostic line,
rather than an actual subtest. Putting the test name at the start
matches what kunit_tool is expecting at the moment. If we then want to
turn it into a proper subtest, we can just get rid of that prefix (and
add the appropriate counts elsewhere).

Does that sound good?


> [...]

Thanks,
-- David

[1]: https://lore.kernel.org/linux-kselftest/CY4PR13MB1175B804E3...@CY4PR13MB1175.namprd13.prod.outlook.com/T/

Marco Elver

unread,
Nov 10, 2020, 5:35:24 AM11/10/20
to David Gow, Arpitha Raghunandan, Brendan Higgins, Shuah Khan, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, Linux Kernel Mailing List, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
On Tue, 10 Nov 2020 at 08:21, David Gow <davi...@google.com> wrote:
[...]
Sounds reasonable to me! The repetition of [index] seems unnecessary
for now, but I think if we at some point have a way to get a string
representation of a param, we can substitute param-[index] with a
string that represents the param.

Note that once we want to make it a real subtest, we'd need to run the
generator twice, once to get the number of params and then to run the
tests. If we require that param generators are deterministic in the
number of params generated, this is not a problem.

Thanks,
-- Marco

Arpitha Raghunandan

unread,
Nov 10, 2020, 11:32:18 AM11/10/20
to Marco Elver, David Gow, Brendan Higgins, Shuah Khan, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, Linux Kernel Mailing List, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
So, with this the inode-test.c will have the following output, right?

TAP version 14
1..7
# Subtest: ext4_inode_test
1..1
# inode_test_xtimestamp_decoding: ok 0 - param-0
# inode_test_xtimestamp_decoding: ok 1 - param-1
# inode_test_xtimestamp_decoding: ok 2 - param-2
# inode_test_xtimestamp_decoding: ok 3 - param-3
# inode_test_xtimestamp_decoding: ok 4 - param-4
# inode_test_xtimestamp_decoding: ok 5 - param-5
# inode_test_xtimestamp_decoding: ok 6 - param-6
# inode_test_xtimestamp_decoding: ok 7 - param-7
# inode_test_xtimestamp_decoding: ok 8 - param-8
# inode_test_xtimestamp_decoding: ok 9 - param-9
# inode_test_xtimestamp_decoding: ok 10 - param-10
# inode_test_xtimestamp_decoding: ok 11 - param-11
# inode_test_xtimestamp_decoding: ok 12 - param-12
# inode_test_xtimestamp_decoding: ok 13 - param-13
# inode_test_xtimestamp_decoding: ok 14 - param-14
# inode_test_xtimestamp_decoding: ok 15 - param-15
ok 1 - inode_test_xtimestamp_decoding
ok 1 - ext4_inode_test

I will send another patch with this change.
Thanks!

Marco Elver

unread,
Nov 10, 2020, 11:41:14 AM11/10/20
to Arpitha Raghunandan, David Gow, Brendan Higgins, Shuah Khan, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, Linux Kernel Mailing List, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
So the params should certainly be 0-indexed, but I think TAP starts
counting at 1, so maybe this should be:

# inode_test_xtimestamp_decoding: ok 1 - param-0

and so on... ?

Right now it doesn't matter, but it will if we make these subsubtests
as David suggested.

> # inode_test_xtimestamp_decoding: ok 1 - param-1
> # inode_test_xtimestamp_decoding: ok 2 - param-2
> # inode_test_xtimestamp_decoding: ok 3 - param-3
> # inode_test_xtimestamp_decoding: ok 4 - param-4
> # inode_test_xtimestamp_decoding: ok 5 - param-5
> # inode_test_xtimestamp_decoding: ok 6 - param-6
> # inode_test_xtimestamp_decoding: ok 7 - param-7
> # inode_test_xtimestamp_decoding: ok 8 - param-8
> # inode_test_xtimestamp_decoding: ok 9 - param-9
> # inode_test_xtimestamp_decoding: ok 10 - param-10
> # inode_test_xtimestamp_decoding: ok 11 - param-11
> # inode_test_xtimestamp_decoding: ok 12 - param-12
> # inode_test_xtimestamp_decoding: ok 13 - param-13
> # inode_test_xtimestamp_decoding: ok 14 - param-14
> # inode_test_xtimestamp_decoding: ok 15 - param-15
> ok 1 - inode_test_xtimestamp_decoding
> ok 1 - ext4_inode_test
>
> I will send another patch with this change.
> Thanks!

Yes that looks right, but see the comment above ^

Thanks,
-- Marco

Arpitha Raghunandan

unread,
Nov 10, 2020, 11:51:06 AM11/10/20
to Marco Elver, David Gow, Brendan Higgins, Shuah Khan, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, Linux Kernel Mailing List, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
Okay yes, I will make the first index (following [ok|not ok]) start with 1
and let the params remain 0-indexed.
Thanks!

Bird, Tim

unread,
Nov 10, 2020, 12:02:34 PM11/10/20
to David Gow, Arpitha Raghunandan, Marco Elver, Brendan Higgins, Shuah Khan, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, Linux Kernel Mailing List, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
I strongly object to putting actual testcase results in comments.
I'd rather that we found a way to include the parameter in the
sub-test-case name, rather than require all parsers to know about
specially-formatted comments. There are tools outside
the kernel that parse these lines.

>
> This gives us a KTAP-compliant result line, except prepended with "#
> [test_case->name]: ", which makes it formally a diagnostic line,
> rather than an actual subtest. Putting the test name at the start
> matches what kunit_tool is expecting at the moment. If we then want to
> turn it into a proper subtest, we can just get rid of that prefix (and
> add the appropriate counts elsewhere).
>
> Does that sound good?
No.

I strongly prefer option C above:
"[ok|not ok] [index] - [test_case->name][separator]param-[index]"

Except of course the second index is not the same as the first, so it
would be:
"[ok|not ok] [index] - [test_case->name][separator]param-[param-index]"

If ':' is problematical as a separator, let's choose something else.
What are the allowed and disallowed characters in the testcase name now?
How bad would it be to use something like % or &?

Unless the separator is #, I think most parsers are going to just treat the whole
string from after the '[index] -' to a following '#' as a testcase name, and it
should get parsed (and presented) OK. I'm not sure what kunit_tool's problem is.

-- Tim

David Gow

unread,
Nov 10, 2020, 6:27:57 PM11/10/20
to Bird, Tim, Arpitha Raghunandan, Marco Elver, Brendan Higgins, Shuah Khan, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, Linux Kernel Mailing List, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
I wasn't intending to treat these as actual testcases yet: from
KUnit's point of view, they're definitely just supposed to be
human-readable diagnostic comments for the one combined testcase.

This largely stems from KUnit being pretty rigid in its test
hierarchy: it has test suites (the root-level testcases), which
contain tests (the first-level subtests). Basically, arbitrary nesting
of tests isn't supported at all by any of the KUnit tools, code,
documentation, etc. So, if we do actually want to treat these
individual parameters as sub-subtests, it'll require a lot of work on
the KUnit side to be able to parse and represent those results.

So, as planned at the moment, these lines won't be parsed at all (just
passed to the user), and should KUnit support more complicated test
hierarchies down the line, we can remove the "# [test_case->name]"
prefix, add the test plan lines, etc, and have this be picked up by
parsers then.


> >
> > This gives us a KTAP-compliant result line, except prepended with "#
> > [test_case->name]: ", which makes it formally a diagnostic line,
> > rather than an actual subtest. Putting the test name at the start
> > matches what kunit_tool is expecting at the moment. If we then want to
> > turn it into a proper subtest, we can just get rid of that prefix (and
> > add the appropriate counts elsewhere).
> >
> > Does that sound good?
> No.
>
> I strongly prefer option C above:
> "[ok|not ok] [index] - [test_case->name][separator]param-[index]"
>
> Except of course the second index is not the same as the first, so it
> would be:
> "[ok|not ok] [index] - [test_case->name][separator]param-[param-index]"

So, the second index would be the same as the first (at most with an
off-by-one to account for different indexing if we wished) in what I
was thinking.

I think this boils down to how we treat these tests and parameters:
- There is one TAP/KUnit test per-parameter, probably with a name like
"test_case:param-n". There's no "container" test.
- There is a test and result for the whole test, and per-parameter
tests and results are nested in that as subtests.
- There is a single test, and any per-parameter information is simply
diagnostic data for the one test, not to be parsed.

The current code follows the last of these options, and it was my view
that by having that diagnostic data be in a similar format to a test
result line, it'd be easier to convert this to the second option while
having a familiar format for people reading the results manually. Only
the first option should need separate indices for the result and the
parameter.

> If ':' is problematical as a separator, let's choose something else.
> What are the allowed and disallowed characters in the testcase name now?
> How bad would it be to use something like % or &?
>
> Unless the separator is #, I think most parsers are going to just treat the whole
> string from after the '[index] -' to a following '#' as a testcase name, and it
> should get parsed (and presented) OK. I'm not sure what kunit_tool's problem is.
>

kunit_tool has a bug when parsing the comments / diagnostic lines,
which requires a ": " to be present. This is a bug, which is being
fixed[1], so while it's _nice_ to not trigger it, it's not really an
important long-term goal of the format. In any case, this kunit_tool
issue only affects the comment lines: if the per-parameter result line
is an actual result, rather than just a diagnostic, this shouldn't be
a problem.

In any case, I still prefer my proposed option for now -- noting that
these per-parameter results are not actually supposed to be parsed --
with then the possibility of expanding them to actual nested results
later should we wish. But if the idea of having TAP-like lines in
diagnostics seems too dangerous (e.g. because people will try to parse
them anyway), then I think the options we have are to stick to the
output format given in the current version of this patch (which
doesn't resemble a TAP result), make each parameterised version its
own test (without a "container test", which would require a bit of
extra work while computing test plans), or to hold this whole feature
back until we can support arbitrary test hierarchies in KUnit.
Personally, I'd rather not hold this feature back, and prefer to have
a single combined result available, so would just stick with v6 if
so...

Does that make sense?

Cheers,
-- David

Bird, Tim

unread,
Nov 11, 2020, 11:55:32 AM11/11/20
to David Gow, Arpitha Raghunandan, Marco Elver, Brendan Higgins, Shuah Khan, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, Linux Kernel Mailing List, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
It seems like you're missing a 4th option, which is just tack the parameter
name on, without using a colon, and have these testcases treated
as unique within the context of the super-test. Is there some reason
these can't be expressed as individual testcases in the parent test?

> Personally, I'd rather not hold this feature back, and prefer to have
> a single combined result available, so would just stick with v6 if
> so...
>
> Does that make sense?

I understand what you are saying, but this seems like a step backwards.
We already know that having just numbers to represent a test case is not
very human friendly. The same will go for these parameter case numbers.
I admit to not following this kunit test parameterization effort, so I don't
know the background of how the numbers relate to the parameters.
But there must be some actual semantic meaning to each of the parameter
cases. Not conveying that meaning as part of the test case name seems like
a missed opportunity.

I'm at a little of a loss as to why, if you have valid testcase results, you would
shy away from putting them into a format that is machine-readable. If it's because
the tooling is not there, then IMHO you should fix the tooling.

I realize that perfect is the enemy of good enough, and that there's value for humans
to see these testcase results and manually interpret them, even if they are put into
a syntax that automated parsers will ignore. However, I do think there's a danger that
this syntax will get canonicalized. Personally, I'd rather see the testcases
with parameters show up in the parsable results. I'd rather sacrifice the hierarchy
than the results.

Just my 2 cents.
-- Tim

David Gow

unread,
Nov 12, 2020, 3:18:59 AM11/12/20
to Bird, Tim, Arpitha Raghunandan, Marco Elver, Brendan Higgins, Shuah Khan, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, Linux Kernel Mailing List, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
No: there's no fundamental reason why we couldn't do that, though
there are some things which make it suboptiomal, IMHO.

Firstly, there could be a lot of parameters, and that by not grouping
them together it could make dealing with the results a little
unwieldy. The other side of that is that it'll result in tests being
split up and renamed as they're ported to use this, whereas if the
whole test shows up once (with subtests or without), the old test name
can still be there, with a single PASS/FAIL for the whole test.

(It also might be a little tricky with the current implementation to
produce the test plan, as the parameters come from a generator, and I
don't think there's a way of getting the number of parameters ahead of
time. That's a problem with the sub-subtest model, too, though at
least there it's a little more isolated from other tests.)

> > Personally, I'd rather not hold this feature back, and prefer to have
> > a single combined result available, so would just stick with v6 if
> > so...
> >
> > Does that make sense?
>
> I understand what you are saying, but this seems like a step backwards.
> We already know that having just numbers to represent a test case is not
> very human friendly. The same will go for these parameter case numbers.
> I admit to not following this kunit test parameterization effort, so I don't
> know the background of how the numbers relate to the parameters.
> But there must be some actual semantic meaning to each of the parameter
> cases. Not conveying that meaning as part of the test case name seems like
> a missed opportunity.

Yeah: I'm not a big fan of just numbering the parameters either: the
plan is to eventually support naming these. Basically, the goal is to
be able to run the same test code repeatedly with different inputs
(which may be programmatically generated): depending on the testcase /
parameter generator in question, the numbers may mean something
specific, but it's not necessarily the case. Certainly in most cases,
the order of these parameters is unlikely to matter, so having the
number be part of the test name isn't ideal there: it's unlikely to
have semantic meaning, and worst-case could be unstable due to code
changes.


>
> I'm at a little of a loss as to why, if you have valid testcase results, you would
> shy away from putting them into a format that is machine-readable. If it's because
> the tooling is not there, then IMHO you should fix the tooling.

I think the real disconnect here is the ambiguity between treating
each run-through with a different parameter as its own test case,
versus an implementation detail of the single "meta testcase". Since
parameters are not really named/ordered properly, (and the example is
replacing a single test) it feels more like an implementation detail
to me.

> I realize that perfect is the enemy of good enough, and that there's value for humans
> to see these testcase results and manually interpret them, even if they are put into
> a syntax that automated parsers will ignore. However, I do think there's a danger that
> this syntax will get canonicalized. Personally, I'd rather see the testcases
> with parameters show up in the parsable results. I'd rather sacrifice the hierarchy
> than the results.

With the state of things at the moment, I don't think the individual
results for given parameters are as useful as the overall result for
the test (run over all parameters), so for me the hierarchy is more
important than the actual results. There are certainly a lot of things
we can do to make the results more useful (supporting named
parameters, for one), and actually supporting the extra level of
nesting in the tooling would make it possible to have both.

There is of course another possibility -- to just not print the
individual parameter results at all (the parameters will likely show
up in the assertion messages of failures anyway -- especially if, as
in the example, the _MSG() variants are used). That's probably
slightly easier to read than a huge list of parameters which are all
"ok" anyway...

In any case, I'm happy to leave the final decision here to Arpitha and
Marco, so long as we don't actually violate the TAP/KTAP spec and
kunit_tool is able to read at least the top-level result. My
preference is still to go either with the "# [test_case->name]:
[ok|not ok] [index] - param-[index]", or to get rid of the
per-parameter results entirely for now (or just print out a diagnostic
message on failure). In any case, it's a decision we can revisit once
we have support for named parameters, better tooling, or a better idea
of how people are actually using this.

Thanks,
-- David

Marco Elver

unread,
Nov 12, 2020, 7:37:15 AM11/12/20
to David Gow, Bird, Tim, Arpitha Raghunandan, Brendan Higgins, Shuah Khan, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, Linux Kernel Mailing List, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
On Thu, Nov 12, 2020 at 04:18PM +0800, David Gow wrote:
> On Thu, Nov 12, 2020 at 12:55 AM Bird, Tim <Tim....@sony.com> wrote:
[...]
Agree, it's suboptimal and having the parameterized not be absorbed by
the whole suite would be strongly preferred.

> (It also might be a little tricky with the current implementation to
> produce the test plan, as the parameters come from a generator, and I
> don't think there's a way of getting the number of parameters ahead of
> time. That's a problem with the sub-subtest model, too, though at
> least there it's a little more isolated from other tests.)

The whole point of generators, as I envisage it, is to also provide the
ability for varying parameters dependent on e.g. environment,
configuration, number of CPUs, etc. The current array-based generator is
the simplest possible use-case.

However, we *can* require generators generate a deterministic number of
parameters when called multiple times on the same system.

To that end, I propose a v7 (below) that takes care of getting number of
parameters (and also displays descriptions for each parameter where
available).

Now it is up to you how you want to turn the output from diagnostic
lines into something TAP compliant, because now we have the number of
parameters and can turn it into a subsubtest. But I think kunit-tool
doesn't understand subsubtests yet, so I suggest we take these patches,
and then somebody can prepare kunit-tool.

Or did I miss something else?

> > > Personally, I'd rather not hold this feature back, and prefer to have
> > > a single combined result available, so would just stick with v6 if
> > > so...
> > >
> > > Does that make sense?
> >
> > I understand what you are saying, but this seems like a step backwards.
> > We already know that having just numbers to represent a test case is not
> > very human friendly. The same will go for these parameter case numbers.
> > I admit to not following this kunit test parameterization effort, so I don't
> > know the background of how the numbers relate to the parameters.
> > But there must be some actual semantic meaning to each of the parameter
> > cases. Not conveying that meaning as part of the test case name seems like
> > a missed opportunity.
>
> Yeah: I'm not a big fan of just numbering the parameters either: the
> plan is to eventually support naming these. Basically, the goal is to
> be able to run the same test code repeatedly with different inputs
> (which may be programmatically generated): depending on the testcase /
> parameter generator in question, the numbers may mean something
> specific, but it's not necessarily the case. Certainly in most cases,
> the order of these parameters is unlikely to matter, so having the
> number be part of the test name isn't ideal there: it's unlikely to
> have semantic meaning, and worst-case could be unstable due to code
> changes.

We can name them. Probably a good idea to do it while we can, as I think
the best design is changing the generator function signature.

> > I'm at a little of a loss as to why, if you have valid testcase results, you would
> > shy away from putting them into a format that is machine-readable. If it's because
> > the tooling is not there, then IMHO you should fix the tooling.
>
> I think the real disconnect here is the ambiguity between treating
> each run-through with a different parameter as its own test case,
> versus an implementation detail of the single "meta testcase". Since
> parameters are not really named/ordered properly, (and the example is
> replacing a single test) it feels more like an implementation detail
> to me.
>
> > I realize that perfect is the enemy of good enough, and that there's value for humans
> > to see these testcase results and manually interpret them, even if they are put into
> > a syntax that automated parsers will ignore. However, I do think there's a danger that
> > this syntax will get canonicalized. Personally, I'd rather see the testcases
> > with parameters show up in the parsable results. I'd rather sacrifice the hierarchy
> > than the results.
>
> With the state of things at the moment, I don't think the individual
> results for given parameters are as useful as the overall result for
> the test (run over all parameters), so for me the hierarchy is more
> important than the actual results. There are certainly a lot of things
> we can do to make the results more useful (supporting named
> parameters, for one), and actually supporting the extra level of
> nesting in the tooling would make it possible to have both.

Named parameters are supported in my proposed v7 (see below). I think
it's now up to you what the format should be, as now it's just a matter
of changing 2 prints' formats to some non-diagnostic TAP compliant
output (but I have no idea what ;-)).

> There is of course another possibility -- to just not print the
> individual parameter results at all (the parameters will likely show
> up in the assertion messages of failures anyway -- especially if, as
> in the example, the _MSG() variants are used). That's probably
> slightly easier to read than a huge list of parameters which are all
> "ok" anyway...

To me this is not acceptable, as I'd like to see some progress feedback
for long tests.

> In any case, I'm happy to leave the final decision here to Arpitha and
> Marco, so long as we don't actually violate the TAP/KTAP spec and
> kunit_tool is able to read at least the top-level result. My
> preference is still to go either with the "# [test_case->name]:
> [ok|not ok] [index] - param-[index]", or to get rid of the
> per-parameter results entirely for now (or just print out a diagnostic
> message on failure). In any case, it's a decision we can revisit once
> we have support for named parameters, better tooling, or a better idea
> of how people are actually using this.

Right, so I think we'll be in a better place if we implement: 1)
parameter to description conversion support, 2) counting parameters. So
I decided to see what it looks like, and it wasn't too bad. I just don't
know how you want to fix kunit-tool to make these non-diagnostic lines
and not complain, but as I said, it'd be good to not block these
patches.

It currently looks like this:

| TAP version 14
| 1..6
| # Subtest: ext4_inode_test
| 1..1
| # inode_test_xtimestamp_decoding: Test with 1..16 params
| # inode_test_xtimestamp_decoding: ok 1 - [1901-12-13 Lower bound of 32bit < 0 timestamp, no extra bits]
| # inode_test_xtimestamp_decoding: ok 2 - [1969-12-31 Upper bound of 32bit < 0 timestamp, no extra bits]
| # inode_test_xtimestamp_decoding: ok 3 - [1970-01-01 Lower bound of 32bit >=0 timestamp, no extra bits]
| # inode_test_xtimestamp_decoding: ok 4 - [2038-01-19 Upper bound of 32bit >=0 timestamp, no extra bits]
| # inode_test_xtimestamp_decoding: ok 5 - [2038-01-19 Lower bound of 32bit <0 timestamp, lo extra sec bit on]
| # inode_test_xtimestamp_decoding: ok 6 - [2106-02-07 Upper bound of 32bit <0 timestamp, lo extra sec bit on]
| # inode_test_xtimestamp_decoding: ok 7 - [2106-02-07 Lower bound of 32bit >=0 timestamp, lo extra sec bit on]
| # inode_test_xtimestamp_decoding: ok 8 - [2174-02-25 Upper bound of 32bit >=0 timestamp, lo extra sec bit on]
| # inode_test_xtimestamp_decoding: ok 9 - [2174-02-25 Lower bound of 32bit <0 timestamp, hi extra sec bit on]
| # inode_test_xtimestamp_decoding: ok 10 - [2242-03-16 Upper bound of 32bit <0 timestamp, hi extra sec bit on]
| # inode_test_xtimestamp_decoding: ok 11 - [2242-03-16 Lower bound of 32bit >=0 timestamp, hi extra sec bit on]
| # inode_test_xtimestamp_decoding: ok 12 - [2310-04-04 Upper bound of 32bit >=0 timestamp, hi extra sec bit on]
| # inode_test_xtimestamp_decoding: ok 13 - [2310-04-04 Upper bound of 32bit>=0 timestamp, hi extra sec bit 1. 1 ns]
| # inode_test_xtimestamp_decoding: ok 14 - [2378-04-22 Lower bound of 32bit>= timestamp. Extra sec bits 1. Max ns]
| # inode_test_xtimestamp_decoding: ok 15 - [2378-04-22 Lower bound of 32bit >=0 timestamp. All extra sec bits on]
| # inode_test_xtimestamp_decoding: ok 16 - [2446-05-10 Upper bound of 32bit >=0 timestamp. All extra sec bits on]
| ok 1 - inode_test_xtimestamp_decoding
| ok 1 - ext4_inode_test

Changing the format of the 2 prints to something else TAP-compliant
should be easy enough once kunit-tool supports subsubtests. :-)

I hope this is a reasonable compromise for now.

[Arpitha: I suggest waiting a day or two and see what further comments
we get, and then take the 2 patches and send the v7 if we decide this is
what we want.]

Thanks,
-- Marco

------ >8 ------

From 31a77b18c874ed93f2d4f8b398b56f10e56bcfd9 Mon Sep 17 00:00:00 2001
From: Arpitha Raghunandan <98....@gmail.com>
Date: Sat, 7 Nov 2020 00:51:54 +0530
Subject: [PATCH 1/2] kunit: Support for Parameterized Testing

Implementation of support for parameterized testing in KUnit. This
approach requires the creation of a test case using the
KUNIT_CASE_PARAM() macro that accepts a generator function as input.

This generator function should return the next parameter given the
previous parameter in parameterized tests. It also provides a macro to
generate common-case generators based on arrays. Generators may also
optionally provide a human-readable description of parameters, which is
displayed where available.

Note, currently the result of each parameter run is displayed in
diagnostic lines, and only the overall test case output summarizes
TAP-compliant success or failure of all parameter runs. In future, when
supported by kunit-tool, these can be turned into subsubtest outputs.

Signed-off-by: Arpitha Raghunandan <98....@gmail.com>
Co-developed-by: Marco Elver <el...@google.com>
Signed-off-by: Marco Elver <el...@google.com>
---
Changes v6->v7:
- Clarify commit message.
- Introduce ability to optionally generate descriptions for parameters;
if no description is provided, we'll still print 'param-N'.
- Change diagnostic line format to:
# <test-case-name>: <ok|not ok> N - [<param description>]
- Before execution of parameterized test case, count number of
parameters and display number of parameters. Currently also as a
diagnostic line, but this may be used in future to generate a subsubtest
plan. A requirement of this change is that generators must generate a
deterministic number of parameters.

Changes v5->v6:
- Fix alignment to maintain consistency

Changes v4->v5:
- Update kernel-doc comments.
- Use const void* for generator return and prev value types.
- Add kernel-doc comment for KUNIT_ARRAY_PARAM.
- Rework parameterized test case execution strategy: each parameter is executed
as if it was its own test case, with its own test initialization and cleanup
(init and exit are called, etc.). However, we cannot add new test cases per TAP
protocol once we have already started execution. Instead, log the result of
each parameter run as a diagnostic comment.

Changes v3->v4:
- Rename kunit variables
- Rename generator function helper macro
- Add documentation for generator approach
- Display test case name in case of failure along with param index

Changes v2->v3:
- Modifictaion of generator macro and method

Changes v1->v2:
- Use of a generator method to access test case parameters
---
include/kunit/test.h | 50 +++++++++++++++++++++++++
lib/kunit/test.c | 89 +++++++++++++++++++++++++++++++++++++-------
2 files changed, 126 insertions(+), 13 deletions(-)

diff --git a/include/kunit/test.h b/include/kunit/test.h
index 9197da792336..5935efb7b533 100644
--- a/include/kunit/test.h
+++ b/include/kunit/test.h
@@ -94,6 +94,9 @@ struct kunit;
/* Size of log associated with test. */
#define KUNIT_LOG_SIZE 512

+/* Maximum size of parameter description string. */
+#define KUNIT_PARAM_DESC_SIZE 64
+
/*
* TAP specifies subtest stream indentation of 4 spaces, 8 spaces for a
* sub-subtest. See the "Subtests" section in
@@ -107,6 +110,7 @@ struct kunit;
*
* @run_case: the function representing the actual test case.
* @name: the name of the test case.
+ * @generate_params: the generator function for parameterized tests.
*
* A test case is a function with the signature,
* ``void (*)(struct kunit *)``
@@ -141,6 +145,7 @@ struct kunit;
struct kunit_case {
void (*run_case)(struct kunit *test);
const char *name;
+ const void* (*generate_params)(const void *prev, char *desc);

/* private: internal use only. */
bool success;
@@ -163,6 +168,27 @@ static inline char *kunit_status_to_string(bool status)
*/
#define KUNIT_CASE(test_name) { .run_case = test_name, .name = #test_name }

+/**
+ * KUNIT_CASE_PARAM - A helper for creation a parameterized &struct kunit_case
+ *
+ * @test_name: a reference to a test case function.
+ * @gen_params: a reference to a parameter generator function.
+ *
+ * The generator function::
+ *
+ * const void* gen_params(const void *prev, char *desc)
+ *
+ * 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.
+ * Optionally write a string into @desc (size of KUNIT_PARAM_DESC_SIZE)
+ * describing the parameter.
+ */
+#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 +234,10 @@ struct kunit {
const char *name; /* Read only after initialization! */
char *log; /* Points at case log after initialization */
struct kunit_try_catch try_catch;
+ /* param_value is the current parameter value for a test case. */
+ const void *param_value;
+ /* param_index stores the index of the parameter in parameterized tests. */
+ int param_index;
/*
* 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 +1772,24 @@ do { \
fmt, \
##__VA_ARGS__)

+/**
+ * KUNIT_ARRAY_PARAM() - Define test parameter generator from an array.
+ * @name: prefix for the test parameter generator function.
+ * @array: array of test parameters.
+ * @get_desc: function to convert param to description; NULL to use default
+ *
+ * Define function @name_gen_params which uses @array to generate parameters.
+ */
+#define KUNIT_ARRAY_PARAM(name, array, get_desc) \
+ static const void *name##_gen_params(const void *prev, char *desc) \
+ { \
+ typeof((array)[0]) *__next = prev ? ((typeof(__next)) prev) + 1 : (array); \
+ if (__next - (array) < ARRAY_SIZE((array))) { \
+ void (*__get_desc)(typeof(__next), char *) = get_desc; \
+ if (__get_desc) __get_desc(__next, desc); \
+ return __next; \
+ } \
+ return NULL; \
+ }
+
#endif /* _KUNIT_TEST_H */
diff --git a/lib/kunit/test.c b/lib/kunit/test.c
index 750704abe89a..1a728bfc4da7 100644
--- a/lib/kunit/test.c
+++ b/lib/kunit/test.c
@@ -325,39 +325,102 @@ static void kunit_catch_run_case(void *data)
{
+ char param_desc[KUNIT_PARAM_DESC_SIZE];
struct kunit_case *test_case;

kunit_print_subtest_start(suite);

- kunit_suite_for_each_test_case(suite, test_case)
- kunit_run_case_catch_errors(suite, test_case);
+ kunit_suite_for_each_test_case(suite, test_case) {
+ struct kunit test = { .param_value = NULL, .param_index = 0 };
+ bool test_success = true;
+ int num_params = 0;
+
+ if (test_case->generate_params) {
+ const void *val; /* Only for counting params. */
+
+ /*
+ * Count number of params: requires that param
+ * generators are deterministic in number of params
+ * generated. Always execute at least 1 param:
+ * - 1 or more non-NULL params;
+ * - special case: 1 param which may be NULL.
+ */
+ val = test_case->generate_params(NULL, param_desc);
+ for (num_params = val ? 0 : 1; val; num_params++) {
+ val = test_case->generate_params(val, param_desc);
+ }
+
+ kunit_log(KERN_INFO, &test,
+ KUNIT_SUBTEST_INDENT
+ "# %s: Test with 1..%d params",
+ test_case->name, num_params);
+
+ /* Get initial param. */
+ param_desc[0] = '\0';
+ test.param_value = test_case->generate_params(NULL, param_desc);
+ }
+
+ do {
+ kunit_run_case_catch_errors(suite, test_case, &test);
+ test_success &= test_case->success;
+
+ if (test_case->generate_params) {
+ if (param_desc[0] == '\0') {
+ snprintf(param_desc, sizeof(param_desc),
+ "param-%d", test.param_index);
+ }
+
+ kunit_log(KERN_INFO, &test,
+ KUNIT_SUBTEST_INDENT
+ "# %s: %s %d - [%s]",
+ test_case->name,
+ kunit_status_to_string(test.success),
+ test.param_index + 1, param_desc);
+
+ /* Get next param. */
+ param_desc[0] = '\0';
+ test.param_value = test_case->generate_params(test.param_value, param_desc);
+ test.param_index++;
+
+ /* Assert deterministic number of params. */
+ num_params--;
+ if (!!test.param_value != !!num_params) {
+ kunit_log(KERN_INFO, &test,
+ KUNIT_SUBTEST_INDENT
+ "# %s: Non-deterministic number of params",
+ test_case->name);
+ test_success = false;
+ }
+ }
+ } while (test.param_value);
+
+ kunit_print_ok_not_ok(&test, true, test_success,
+ kunit_test_case_num(suite, test_case),
+ test_case->name);
+ }

kunit_print_subtest_end(suite);

--
2.29.2.222.g5d2a92d10f8-goog


From 1705948e9d1e1095ee56737a6d7a5c6342cdb5ee Mon Sep 17 00:00:00 2001
From: Arpitha Raghunandan <98....@gmail.com>
Date: Sat, 7 Nov 2020 00:52:49 +0530
Subject: [PATCH 2/2] fs: ext4: Modify inode-test.c to use KUnit parameterized
testing feature

Modify fs/ext4/inode-test.c to use the parameterized testing
feature of KUnit.

Signed-off-by: Arpitha Raghunandan <98....@gmail.com>
Signed-off-by: Marco Elver <el...@google.com>
---
Changes v6->v7:
- Introduce timestamp_expectation_to_desc() to convert param to
description.
Changes v5->v6:
- No change to this patch of the patch series
Changes v4->v5:
- No change to this patch of the patch series
Changes v3->v4:
- Modification based on latest implementation of KUnit parameterized testing
Changes v2->v3:
- Marked hardcoded test data const
- Modification based on latest implementation of KUnit parameterized testing
Changes v1->v2:
- Modification based on latest implementation of KUnit parameterized testing
---
fs/ext4/inode-test.c | 320 ++++++++++++++++++++++---------------------
1 file changed, 164 insertions(+), 156 deletions(-)

diff --git a/fs/ext4/inode-test.c b/fs/ext4/inode-test.c
index d62d802c9c12..97390ab13681 100644
--- a/fs/ext4/inode-test.c
+++ b/fs/ext4/inode-test.c
@@ -80,6 +80,145 @@ struct timestamp_expectation {
+static void timestamp_expectation_to_desc(const struct timestamp_expectation *t,
+ char *desc)
+{
+ strcpy(desc, t->test_case_name);
+}
+
+KUNIT_ARRAY_PARAM(ext4_inode, test_data, timestamp_expectation_to_desc);
+
static time64_t get_32bit_time(const struct timestamp_expectation * const test)
{
if (test->msb_set) {
@@ -101,166 +240,35 @@ static time64_t get_32bit_time(const struct timestamp_expectation * const test)
2.29.2.222.g5d2a92d10f8-goog

David Gow

unread,
Nov 13, 2020, 12:17:21 AM11/13/20
to Marco Elver, Bird, Tim, Arpitha Raghunandan, Brendan Higgins, Shuah Khan, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, Linux Kernel Mailing List, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
I think this is a reasonable compromise, though it's not actually
essential. As I understand the TAP spec, the test plan is actually
optional (and/or can be at the end of the sequence of tests), though
kunit_tool currently only supports having it at the beginning (which
is strongly preferred by the spec anyway). I think we could get away
with having it at the bottom of the subtest results though, which
would save having to run the generator twice, when subtest support is
added to kunit_tool.

> To that end, I propose a v7 (below) that takes care of getting number of
> parameters (and also displays descriptions for each parameter where
> available).
>
> Now it is up to you how you want to turn the output from diagnostic
> lines into something TAP compliant, because now we have the number of
> parameters and can turn it into a subsubtest. But I think kunit-tool
> doesn't understand subsubtests yet, so I suggest we take these patches,
> and then somebody can prepare kunit-tool.
>

This sounds good to me. The only thing I'm not sure about is the
format of the parameter description: thus far test names be valid C
identifier names, due to the fact they're named after the test
function. I don't think there's a fundamental reason parameters (and
hence, potentially, subsubtests) need to follow that convention as
well, but it does look a bit odd. Equally, the square brackets around
the description shouldn't be necessary according to the TAP spec, but
do seem to make things a little more readable, particuarly with the
names in the ext4 inode test. I'm not too worried about either of
those, though: I'm sure it'll look fine once I've got used to it.
This works for me. I was thinking of having a separate
parameter_to_string() function, but I think this is better.
Thanks -- I think the changes from this v7 to a TAP compliant format
should mostly just be replacing the "# [test_name]" with an extra
level of indentation. We'll just have to add support for it to
kunit_tool's parser (which has been in need of work anyway.)

> > There is of course another possibility -- to just not print the
> > individual parameter results at all (the parameters will likely show
> > up in the assertion messages of failures anyway -- especially if, as
> > in the example, the _MSG() variants are used). That's probably
> > slightly easier to read than a huge list of parameters which are all
> > "ok" anyway...
>
> To me this is not acceptable, as I'd like to see some progress feedback
> for long tests.

Hopefully most tests don't take long enough that this level of
feedback is necessary (and those that do could always log diagnostic
lines themselves), but I'm also happy with these being printed out
here.

> > In any case, I'm happy to leave the final decision here to Arpitha and
> > Marco, so long as we don't actually violate the TAP/KTAP spec and
> > kunit_tool is able to read at least the top-level result. My
> > preference is still to go either with the "# [test_case->name]:
> > [ok|not ok] [index] - param-[index]", or to get rid of the
> > per-parameter results entirely for now (or just print out a diagnostic
> > message on failure). In any case, it's a decision we can revisit once
> > we have support for named parameters, better tooling, or a better idea
> > of how people are actually using this.
>
> Right, so I think we'll be in a better place if we implement: 1)
> parameter to description conversion support, 2) counting parameters. So
> I decided to see what it looks like, and it wasn't too bad. I just don't
> know how you want to fix kunit-tool to make these non-diagnostic lines
> and not complain, but as I said, it'd be good to not block these
> patches.

Yup, I tried this v7, and it looks good to me. The kunit_tool work
will probably be a touch more involved, so I definitely don't want to
hold up supporting this on that.

My only thoughts on the v7 patch are:
- I don't think we actually need the parameter count yet (or perhaps
ever if we go with subtests as planned), so I be okay with getting rid
of that.
- It'd be a possibility to get rid of the square brackets from the
output, and if we still want them, make them part of the test itself:
if this were TAP formatted, those brackets would be part of the
subsubtest name.
Yeah: this seems like a great compromise until kunit_tool is improved.

Thanks a bunch,
-- David

Marco Elver

unread,
Nov 13, 2020, 5:31:04 AM11/13/20
to David Gow, Bird, Tim, Arpitha Raghunandan, Brendan Higgins, Shuah Khan, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, Linux Kernel Mailing List, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
On Fri, Nov 13, 2020 at 01:17PM +0800, David Gow wrote:
> On Thu, Nov 12, 2020 at 8:37 PM Marco Elver <el...@google.com> wrote:
[...]
> > > (It also might be a little tricky with the current implementation to
> > > produce the test plan, as the parameters come from a generator, and I
> > > don't think there's a way of getting the number of parameters ahead of
> > > time. That's a problem with the sub-subtest model, too, though at
> > > least there it's a little more isolated from other tests.)
> >
> > The whole point of generators, as I envisage it, is to also provide the
> > ability for varying parameters dependent on e.g. environment,
> > configuration, number of CPUs, etc. The current array-based generator is
> > the simplest possible use-case.
> >
> > However, we *can* require generators generate a deterministic number of
> > parameters when called multiple times on the same system.
>
> I think this is a reasonable compromise, though it's not actually
> essential. As I understand the TAP spec, the test plan is actually
> optional (and/or can be at the end of the sequence of tests), though
> kunit_tool currently only supports having it at the beginning (which
> is strongly preferred by the spec anyway). I think we could get away
> with having it at the bottom of the subtest results though, which
> would save having to run the generator twice, when subtest support is
> added to kunit_tool.

I can't find this in the TAP spec, where should I look? Perhaps we
shouldn't venture too far off the beaten path, given we might not be the
only ones that want to parse this output.

> > To that end, I propose a v7 (below) that takes care of getting number of
> > parameters (and also displays descriptions for each parameter where
> > available).
> >
> > Now it is up to you how you want to turn the output from diagnostic
> > lines into something TAP compliant, because now we have the number of
> > parameters and can turn it into a subsubtest. But I think kunit-tool
> > doesn't understand subsubtests yet, so I suggest we take these patches,
> > and then somebody can prepare kunit-tool.
> >
>
> This sounds good to me. The only thing I'm not sure about is the
> format of the parameter description: thus far test names be valid C
> identifier names, due to the fact they're named after the test
> function. I don't think there's a fundamental reason parameters (and
> hence, potentially, subsubtests) need to follow that convention as
> well, but it does look a bit odd. Equally, the square brackets around
> the description shouldn't be necessary according to the TAP spec, but
> do seem to make things a little more readable, particuarly with the
> names in the ext4 inode test. I'm not too worried about either of
> those, though: I'm sure it'll look fine once I've got used to it.

The parameter description doesn't need to be a C identifier. At least
that's what I could immediately glean from TAP v13 spec (I'm looking
here: https://testanything.org/tap-version-13-specification.html and see
e.g. "ok 1 - Input file opened" ...).

[...]
> > > In any case, I'm happy to leave the final decision here to Arpitha and
> > > Marco, so long as we don't actually violate the TAP/KTAP spec and
> > > kunit_tool is able to read at least the top-level result. My
> > > preference is still to go either with the "# [test_case->name]:
> > > [ok|not ok] [index] - param-[index]", or to get rid of the
> > > per-parameter results entirely for now (or just print out a diagnostic
> > > message on failure). In any case, it's a decision we can revisit once
> > > we have support for named parameters, better tooling, or a better idea
> > > of how people are actually using this.
> >
> > Right, so I think we'll be in a better place if we implement: 1)
> > parameter to description conversion support, 2) counting parameters. So
> > I decided to see what it looks like, and it wasn't too bad. I just don't
> > know how you want to fix kunit-tool to make these non-diagnostic lines
> > and not complain, but as I said, it'd be good to not block these
> > patches.
>
> Yup, I tried this v7, and it looks good to me. The kunit_tool work
> will probably be a touch more involved, so I definitely don't want to
> hold up supporting this on that.
>
> My only thoughts on the v7 patch are:
> - I don't think we actually need the parameter count yet (or perhaps
> ever if we go with subtests as planned), so I be okay with getting rid
> of that.

As noted above, perhaps we should keep it for compatibility with other
parsers and CI systems we don't have much control over. It'd be a shame
if 99% of KUnit output can be parsed by some partially compliant parser,
yet this would break it.

> - It'd be a possibility to get rid of the square brackets from the
> output, and if we still want them, make them part of the test itself:
> if this were TAP formatted, those brackets would be part of the
> subsubtest name.

I don't mind. It's just that we can't prescribe a format, and as
seen below the descriptions include characters -<>=,. which can be
confusing. But perhaps you're right, so let's remove them.

But as noted, TAP doesn't seem to care. So let's remove them.

[...]
> > I hope this is a reasonable compromise for now.
>
> Yeah: this seems like a great compromise until kunit_tool is improved.

Thank you!

-- Marco

David Gow

unread,
Nov 13, 2020, 5:37:59 PM11/13/20
to Marco Elver, Bird, Tim, Arpitha Raghunandan, Brendan Higgins, Shuah Khan, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, Linux Kernel Mailing List, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
It's in the "Test Lines and the Plan" section:
"The plan is optional but if there is a plan before the test points it
must be the first non-diagnostic line output by the test file. In
certain instances a test file may not know how many test points it
will ultimately be running. In this case the plan can be the last
non-diagnostic line in the output. The plan cannot appear in the
middle of the output, nor can it appear more than once."

My only concern with running through the generator multiple times to
get the count is that it might be slow and/or more difficult if
someone uses a more complicated generator. I can't think of anything
specific yet, though, so we can always do it for now and change it
later if a problematic case occurs.

> > > To that end, I propose a v7 (below) that takes care of getting number of
> > > parameters (and also displays descriptions for each parameter where
> > > available).
> > >
> > > Now it is up to you how you want to turn the output from diagnostic
> > > lines into something TAP compliant, because now we have the number of
> > > parameters and can turn it into a subsubtest. But I think kunit-tool
> > > doesn't understand subsubtests yet, so I suggest we take these patches,
> > > and then somebody can prepare kunit-tool.
> > >
> >
> > This sounds good to me. The only thing I'm not sure about is the
> > format of the parameter description: thus far test names be valid C
> > identifier names, due to the fact they're named after the test
> > function. I don't think there's a fundamental reason parameters (and
> > hence, potentially, subsubtests) need to follow that convention as
> > well, but it does look a bit odd. Equally, the square brackets around
> > the description shouldn't be necessary according to the TAP spec, but
> > do seem to make things a little more readable, particuarly with the
> > names in the ext4 inode test. I'm not too worried about either of
> > those, though: I'm sure it'll look fine once I've got used to it.
>
> The parameter description doesn't need to be a C identifier. At least
> that's what I could immediately glean from TAP v13 spec (I'm looking
> here: https://testanything.org/tap-version-13-specification.html and see
> e.g. "ok 1 - Input file opened" ...).
>

Yeah: it looked a bit weird for everything else to be an identifier
(given that KUnit does require it for tests), but these parameter
descriptions not to be. It's not a problem, though, so let's go ahead
with it.
KUnit has only started providing the test plans in some cases pretty
recently, and the spec does make it optional, so I'm not particularly
worried about this breaking parsers. I'm not too worried about it
causing problems to have it either, though, so if you'd rather keep
it, that's fine by me as well.

> > - It'd be a possibility to get rid of the square brackets from the
> > output, and if we still want them, make them part of the test itself:
> > if this were TAP formatted, those brackets would be part of the
> > subsubtest name.
>
> I don't mind. It's just that we can't prescribe a format, and as
> seen below the descriptions include characters -<>=,. which can be
> confusing. But perhaps you're right, so let's remove them.
>
> But as noted, TAP doesn't seem to care. So let's remove them.
>

Yeah: I have a slight preference for removing them, as TAP parsers
would otherwise include them in the parameter name, which looks a
little weird.
Of course, the point is moot until we actually fix kunit_tool and make
these subtests, so there's no fundamental reason we couldn't leave
them in for now, and remove them then if you thought it was
significantly more readable. (Personally, I'd still err on the side of
removing them to avoid any unnecessary churn.)

Cheers,
-- David

Marco Elver

unread,
Nov 13, 2020, 7:14:28 PM11/13/20
to David Gow, Bird, Tim, Arpitha Raghunandan, Brendan Higgins, Shuah Khan, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, Linux Kernel Mailing List, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
Ah, that's fine then.

> My only concern with running through the generator multiple times to
> get the count is that it might be slow and/or more difficult if
> someone uses a more complicated generator. I can't think of anything
> specific yet, though, so we can always do it for now and change it
> later if a problematic case occurs.

I'm all for simplicity, so if nobody objects, let's just get rid of
the number of parameters and avoid running it twice.
Sounds good.

Arpitha: Do you want to send v7, but with the following modifications
from what I proposed? Assuming nobody objects.

1. Remove the num_params counter and don't print the number of params
anymore, nor do validation that generators are deterministic.
2. Remove the [].
[ I'm happy to send as well, just let me know what you prefer. ]

Thanks,
-- Marco

Arpitha Raghunandan

unread,
Nov 13, 2020, 8:38:03 PM11/13/20
to Marco Elver, David Gow, Bird, Tim, Brendan Higgins, Shuah Khan, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, Linux Kernel Mailing List, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
If no objections I will send the v7 with the above changes.
Thanks!

David Gow

unread,
Nov 13, 2020, 10:17:51 PM11/13/20
to Arpitha Raghunandan, Marco Elver, Bird, Tim, Brendan Higgins, Shuah Khan, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, Linux Kernel Mailing List, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
This sounds good to me!

Cheers,
-- David

Arpitha Raghunandan

unread,
Nov 14, 2020, 7:38:24 AM11/14/20
to brendan...@google.com, sk...@linuxfoundation.org, el...@google.com, yza...@google.com, ty...@mit.edu, adilger...@dilger.ca, Tim....@sony.com, davi...@google.com, Arpitha Raghunandan, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-...@vger.kernel.org, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
Implementation of support for parameterized testing in KUnit. This
approach requires the creation of a test case using the
KUNIT_CASE_PARAM() macro that accepts a generator function as input.

This generator function should return the next parameter given the
previous parameter in parameterized tests. It also provides a macro to
generate common-case generators based on arrays. Generators may also
optionally provide a human-readable description of parameters, which is
displayed where available.

Note, currently the result of each parameter run is displayed in
diagnostic lines, and only the overall test case output summarizes
TAP-compliant success or failure of all parameter runs. In future, when
supported by kunit-tool, these can be turned into subsubtest outputs.

Signed-off-by: Arpitha Raghunandan <98....@gmail.com>
Co-developed-by: Marco Elver <el...@google.com>
Signed-off-by: Marco Elver <el...@google.com>
---
Changes v6->v7:
- Clarify commit message.
- Introduce ability to optionally generate descriptions for parameters;
if no description is provided, we'll still print 'param-N'.
- Change diagnostic line format to:
# <test-case-name>: <ok|not ok> N - [<param description>]

Changes v5->v6:
- Fix alignment to maintain consistency

Changes v4->v5:
- Update kernel-doc comments.
- Use const void* for generator return and prev value types.
- Add kernel-doc comment for KUNIT_ARRAY_PARAM.
- Rework parameterized test case execution strategy: each parameter is executed
as if it was its own test case, with its own test initialization and cleanup
(init and exit are called, etc.). However, we cannot add new test cases per TAP
protocol once we have already started execution. Instead, log the result of
each parameter run as a diagnostic comment.

Changes v3->v4:
- Rename kunit variables
- Rename generator function helper macro
- Add documentation for generator approach
- Display test case name in case of failure along with param index

Changes v2->v3:
- Modifictaion of generator macro and method

Changes v1->v2:
- Use of a generator method to access test case parameters
include/kunit/test.h | 51 ++++++++++++++++++++++++++++++++++++++
lib/kunit/test.c | 59 ++++++++++++++++++++++++++++++++++----------
2 files changed, 97 insertions(+), 13 deletions(-)

diff --git a/include/kunit/test.h b/include/kunit/test.h
index db1b0ae666c4..cf5f33b1c890 100644
@@ -1742,4 +1772,25 @@ do { \
fmt, \
##__VA_ARGS__)

+/**
+ * KUNIT_ARRAY_PARAM() - Define test parameter generator from an array.
+ * @name: prefix for the test parameter generator function.
+ * @array: array of test parameters.
+ * @get_desc: function to convert param to description; NULL to use default
+ *
+ * Define function @name_gen_params which uses @array to generate parameters.
+ */
+#define KUNIT_ARRAY_PARAM(name, array, get_desc) \
+ static const void *name##_gen_params(const void *prev, char *desc) \
+ { \
+ typeof((array)[0]) * __next = prev ? ((typeof(__next)) prev) + 1 : (array); \
+ if (__next - (array) < ARRAY_SIZE((array))) { \
+ void (*__get_desc)(typeof(__next), char *) = get_desc; \
+ if (__get_desc) \
+ __get_desc(__next, desc); \
+ return __next; \
+ } \
+ return NULL; \
+ }
+
#endif /* _KUNIT_TEST_H */
diff --git a/lib/kunit/test.c b/lib/kunit/test.c
index 750704abe89a..ec9494e914ef 100644
--- a/lib/kunit/test.c
+++ b/lib/kunit/test.c
@@ -325,39 +325,72 @@ static void kunit_catch_run_case(void *data)
+ if (test_case->generate_params) {
+ } while (test.param_value);
+
+ kunit_print_ok_not_ok(&test, true, test_success,
+ kunit_test_case_num(suite, test_case),
+ test_case->name);
+ }

kunit_print_subtest_end(suite);

--
2.25.1

Arpitha Raghunandan

unread,
Nov 14, 2020, 7:39:28 AM11/14/20
to brendan...@google.com, sk...@linuxfoundation.org, el...@google.com, yza...@google.com, ty...@mit.edu, adilger...@dilger.ca, Tim....@sony.com, davi...@google.com, Arpitha Raghunandan, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-...@vger.kernel.org, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
Modify fs/ext4/inode-test.c to use the parameterized testing
feature of KUnit.

Signed-off-by: Arpitha Raghunandan <98....@gmail.com>
Signed-off-by: Marco Elver <el...@google.com>
---
Changes v6->v7:
- Introduce timestamp_expectation_to_desc() to convert param to
description.
Changes v5->v6:
- No change to this patch of the patch series
Changes v4->v5:
- No change to this patch of the patch series
Changes v3->v4:
- Modification based on latest implementation of KUnit parameterized testing
Changes v2->v3:
- Marked hardcoded test data const
- Modification based on latest implementation of KUnit parameterized testing
Changes v1->v2:
- Modification based on latest implementation of KUnit parameterized testing

2.25.1

Marco Elver

unread,
Nov 15, 2020, 3:58:33 AM11/15/20
to Arpitha Raghunandan, Brendan Higgins, Shuah Khan, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, Tim Bird, David Gow, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, LKML, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
I think we need to make this larger, perhaps 128. I just noticed a few
of the inode-test strings are >64 chars (and it should probably also
use strncpy() to copy to description, which is my bad).

> /*
> * TAP specifies subtest stream indentation of 4 spaces, 8 spaces for a
> * sub-subtest. See the "Subtests" section in
> @@ -107,6 +110,7 @@ struct kunit;
[...]
> +/**
> + * KUNIT_ARRAY_PARAM() - Define test parameter generator from an array.
> + * @name: prefix for the test parameter generator function.
> + * @array: array of test parameters.
> + * @get_desc: function to convert param to description; NULL to use default
> + *
> + * Define function @name_gen_params which uses @array to generate parameters.
> + */
> +#define KUNIT_ARRAY_PARAM(name, array, get_desc) \
> + static const void *name##_gen_params(const void *prev, char *desc) \
> + { \
> + typeof((array)[0]) * __next = prev ? ((typeof(__next)) prev) + 1 : (array); \

Why did you reintroduce a space between * and __next? AFAIK, this
should follow the same style as the rest of the kernel, and it should
just be 'thetype *ptr'.

> + if (__next - (array) < ARRAY_SIZE((array))) { \
> + void (*__get_desc)(typeof(__next), char *) = get_desc; \
> + if (__get_desc) \
> + __get_desc(__next, desc); \
> + return __next; \
> + } \
> + return NULL; \
> + }
> +

Thanks,
-- Marco

kernel test robot

unread,
Nov 15, 2020, 5:11:11 AM11/15/20
to Arpitha Raghunandan, brendan...@google.com, sk...@linuxfoundation.org, el...@google.com, yza...@google.com, ty...@mit.edu, adilger...@dilger.ca, Tim....@sony.com, davi...@google.com, Arpitha Raghunandan, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-...@vger.kernel.org, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org, 0day robot, l...@lists.01.org

Greeting,

FYI, we noticed the following commit (built with gcc-9):

commit: 4ffef91a3b1b35b64502da85fe682897e4a123cd ("[PATCH v7 2/2] fs: ext4: Modify inode-test.c to use KUnit parameterized testing feature")
url: https://github.com/0day-ci/linux/commits/Arpitha-Raghunandan/kunit-Support-for-Parameterized-Testing/20201114-204322
base: https://git.kernel.org/cgit/linux/kernel/git/tytso/ext4.git dev

in testcase: boot

on test machine: qemu-system-x86_64 -enable-kvm -cpu SandyBridge -smp 2 -m 8G

caused below changes (please refer to attached dmesg/kmsg for entire log/backtrace):


+---------------------------------------------------------------------------------------+------------+------------+
| | 0f0922dc1c | 4ffef91a3b |
+---------------------------------------------------------------------------------------+------------+------------+
| Kernel_panic-not_syncing:stack-protector:Kernel_stack_is_corrupted_in:kunit_run_tests | 0 | 16 |
+---------------------------------------------------------------------------------------+------------+------------+


If you fix the issue, kindly add following tag
Reported-by: kernel test robot <olive...@intel.com>


[ 21.894954] # inode_test_xtimestamp_decoding: ok 14 - 2378-04-22 Lower bound of 32bit>= timestamp. Extra sec bits 1. Max ns
[ 21.896398] # inode_test_xtimestamp_decoding: ok 15 - 2378-04-22 Lower bound of 32bit >=0 timestamp. All extra sec bits on
[ 21.898125] # inode_test_xtimestamp_decoding: ok 16 - 2446-05-10 Upper bound of 32bit >=0 timestamp. All extra sec bits on
[ 21.899303] ok 1 - inode_test_xtimestamp_decoding
[ 21.900451] ok 2 - ext4_inode_test
[ 21.901545] Kernel panic - not syncing: stack-protector: Kernel stack is corrupted in: kunit_run_tests+0x301/0x315
[ 21.905219] CPU: 0 PID: 1 Comm: swapper Not tainted 5.10.0-rc3-00098-g4ffef91a3b1b #7
[ 21.906045] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.12.0-1 04/01/2014
[ 21.906871] Call Trace:
[ 21.907143] dump_stack+0x20/0x22
[ 21.907541] panic+0x101/0x2d1
[ 21.907868] ? kunit_run_tests+0x301/0x315
[ 21.908281] __stack_chk_fail+0x14/0x20
[ 21.908646] kunit_run_tests+0x301/0x315
[ 21.909026] ? kunit_catch_run_case+0x40/0x40
[ 21.909476] ? kunit_cleanup+0x60/0x60
[ 21.909912] ? kunit_cleanup+0x41/0x60
[ 21.910316] __kunit_test_suites_init+0x27/0x50
[ 21.910797] kunit_run_all_tests.cold+0x37/0x40
[ 21.911283] kernel_init_freeable+0x8b/0xb3
[ 21.911736] ? rest_init+0x233/0x233
[ 21.912115] kernel_init+0x9/0xfd
[ 21.912464] ret_from_fork+0x22/0x30
[ 21.912893] Kernel Offset: disabled

Kboot worker: lkp-worker53
Elapsed time: 60



To reproduce:

# build kernel
cd linux
cp config-5.10.0-rc3-00098-g4ffef91a3b1b .config
make HOSTCC=gcc-9 CC=gcc-9 ARCH=x86_64 olddefconfig prepare modules_prepare bzImage

git clone https://github.com/intel/lkp-tests.git
cd lkp-tests
bin/lkp qemu -k <bzImage> job-script # job-script is attached in this email



Thanks,
Oliver Sang

config-5.10.0-rc3-00098-g4ffef91a3b1b
job-script
dmesg.xz

Arpitha Raghunandan

unread,
Nov 15, 2020, 7:18:54 AM11/15/20
to Marco Elver, Brendan Higgins, Shuah Khan, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, Tim Bird, David Gow, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, LKML, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
Okay, I will make the description size larger and use strncpy().

>> /*
>> * TAP specifies subtest stream indentation of 4 spaces, 8 spaces for a
>> * sub-subtest. See the "Subtests" section in
>> @@ -107,6 +110,7 @@ struct kunit;
> [...]
>> +/**
>> + * KUNIT_ARRAY_PARAM() - Define test parameter generator from an array.
>> + * @name: prefix for the test parameter generator function.
>> + * @array: array of test parameters.
>> + * @get_desc: function to convert param to description; NULL to use default
>> + *
>> + * Define function @name_gen_params which uses @array to generate parameters.
>> + */
>> +#define KUNIT_ARRAY_PARAM(name, array, get_desc) \
>> + static const void *name##_gen_params(const void *prev, char *desc) \
>> + { \
>> + typeof((array)[0]) * __next = prev ? ((typeof(__next)) prev) + 1 : (array); \
>
> Why did you reintroduce a space between * and __next? AFAIK, this
> should follow the same style as the rest of the kernel, and it should
> just be 'thetype *ptr'.
>

I introduced this space because checkpatch.pl gave an error without the space:
ERROR: need consistent spacing around '*' (ctx:WxV)
#1786: FILE: ./include/kunit/test.h:1786:
+ typeof((array)[0]) *__next = prev ? ((typeof(__next)) prev) + 1 : (array); \

But, if this is a mistake as it doesn't recognize __next to be a pointer, I will remove the space.

>> + if (__next - (array) < ARRAY_SIZE((array))) { \
>> + void (*__get_desc)(typeof(__next), char *) = get_desc; \
>> + if (__get_desc) \
>> + __get_desc(__next, desc); \
>> + return __next; \
>> + } \
>> + return NULL; \
>> + }
>> +
>
> Thanks,
> -- Marco
>

Thanks!

Marco Elver

unread,
Nov 15, 2020, 1:11:44 PM11/15/20
to Arpitha Raghunandan, Brendan Higgins, Shuah Khan, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, Tim Bird, David Gow, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, LKML, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
Thanks. There's also a report by the test robot now which noticed this.
I think checkpatch.pl thinks this is a multiplication. It's definitely
a false positive. Please do format it like a normal pointer.

Thanks,
-- Marco

Arpitha Raghunandan

unread,
Nov 15, 2020, 1:58:43 PM11/15/20
to brendan...@google.com, sk...@linuxfoundation.org, el...@google.com, yza...@google.com, ty...@mit.edu, adilger...@dilger.ca, Tim....@sony.com, davi...@google.com, Arpitha Raghunandan, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-...@vger.kernel.org, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
Implementation of support for parameterized testing in KUnit. This
approach requires the creation of a test case using the
KUNIT_CASE_PARAM() macro that accepts a generator function as input.

This generator function should return the next parameter given the
previous parameter in parameterized tests. It also provides a macro to
generate common-case generators based on arrays. Generators may also
optionally provide a human-readable description of parameters, which is
displayed where available.

Note, currently the result of each parameter run is displayed in
diagnostic lines, and only the overall test case output summarizes
TAP-compliant success or failure of all parameter runs. In future, when
supported by kunit-tool, these can be turned into subsubtest outputs.

Signed-off-by: Arpitha Raghunandan <98....@gmail.com>
Co-developed-by: Marco Elver <el...@google.com>
Signed-off-by: Marco Elver <el...@google.com>
---
Changes v7->v8:
- Increase KUNIT_PARAM_DESC_SIZE to 128
- Format pointer style appropriately
index db1b0ae666c4..27b42a008c7a 100644
--- a/include/kunit/test.h
+++ b/include/kunit/test.h
@@ -94,6 +94,9 @@ struct kunit;
/* Size of log associated with test. */
#define KUNIT_LOG_SIZE 512

+/* Maximum size of parameter description string. */
+#define KUNIT_PARAM_DESC_SIZE 128
+
/*
* TAP specifies subtest stream indentation of 4 spaces, 8 spaces for a
* sub-subtest. See the "Subtests" section in
@@ -107,6 +110,7 @@ struct kunit;
*
* @run_case: the function representing the actual test case.
* @name: the name of the test case.
+ * @generate_params: the generator function for parameterized tests.
*
* A test case is a function with the signature,
* ``void (*)(struct kunit *)``
@@ -141,6 +145,7 @@ struct kunit;
struct kunit_case {
void (*run_case)(struct kunit *test);
const char *name;
+ const void* (*generate_params)(const void *prev, char *desc);

/* private: internal use only. */
bool success;
@@ -163,6 +168,27 @@ static inline char *kunit_status_to_string(bool status)
*/
#define KUNIT_CASE(test_name) { .run_case = test_name, .name = #test_name }

+/**
+ * KUNIT_CASE_PARAM - A helper for creation a parameterized &struct kunit_case
+ *
+ * @test_name: a reference to a test case function.
+ * @gen_params: a reference to a parameter generator function.
+ *
+/**
+ * KUNIT_ARRAY_PARAM() - Define test parameter generator from an array.
+ * @name: prefix for the test parameter generator function.
+ * @array: array of test parameters.
+ * @get_desc: function to convert param to description; NULL to use default
+ *
+ * Define function @name_gen_params which uses @array to generate parameters.
+ */
+#define KUNIT_ARRAY_PARAM(name, array, get_desc) \
+ static const void *name##_gen_params(const void *prev, char *desc) \
+ { \
+ typeof((array)[0]) *__next = prev ? ((typeof(__next)) prev) + 1 : (array); \
+ if (__next - (array) < ARRAY_SIZE((array))) { \
+ void (*__get_desc)(typeof(__next), char *) = get_desc; \
+ if (__get_desc) \
+ __get_desc(__next, desc); \
+ return __next; \
+ } \
+ return NULL; \
+ }
+

Arpitha Raghunandan

unread,
Nov 15, 2020, 1:59:35 PM11/15/20
to brendan...@google.com, sk...@linuxfoundation.org, el...@google.com, yza...@google.com, ty...@mit.edu, adilger...@dilger.ca, Tim....@sony.com, davi...@google.com, Arpitha Raghunandan, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-...@vger.kernel.org, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
Modify fs/ext4/inode-test.c to use the parameterized testing
feature of KUnit.

Signed-off-by: Arpitha Raghunandan <98....@gmail.com>
Signed-off-by: Marco Elver <el...@google.com>
---
Changes v7->v8:
- Replace strcpy() with strncpy() in timestamp_expectation_to_desc()
Changes v6->v7:
- Introduce timestamp_expectation_to_desc() to convert param to
description.
Changes v5->v6:
- No change to this patch of the patch series
Changes v4->v5:
- No change to this patch of the patch series
Changes v3->v4:
- Modification based on latest implementation of KUnit parameterized testing
Changes v2->v3:
- Marked hardcoded test data const
- Modification based on latest implementation of KUnit parameterized testing
Changes v1->v2:
- Modification based on latest implementation of KUnit parameterized testing

fs/ext4/inode-test.c | 323 ++++++++++++++++++++++---------------------
1 file changed, 167 insertions(+), 156 deletions(-)

diff --git a/fs/ext4/inode-test.c b/fs/ext4/inode-test.c
index d62d802c9c12..2c0c00c45c6b 100644
--- a/fs/ext4/inode-test.c
+++ b/fs/ext4/inode-test.c
@@ -80,6 +80,148 @@ struct timestamp_expectation {
+ int desc_length = strlen(t->test_case_name);
+
+ strncpy(desc, t->test_case_name, desc_length);
+ desc[desc_length] = '\0';
+}
+
+KUNIT_ARRAY_PARAM(ext4_inode, test_data, timestamp_expectation_to_desc);
+
static time64_t get_32bit_time(const struct timestamp_expectation * const test)
{
if (test->msb_set) {
@@ -101,166 +243,35 @@ static time64_t get_32bit_time(const struct timestamp_expectation * const test)

Marco Elver

unread,
Nov 15, 2020, 2:45:09 PM11/15/20
to Arpitha Raghunandan, Brendan Higgins, Shuah Khan, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, Tim Bird, David Gow, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, LKML, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
This unfortunately won't prevent out-of-bounds accesses if the
description is longer than KUNIT_PARAM_DESC_SIZE.

With strncpy() we want to avoid copying more bytes than the
destination buffer can hold. This can be done by simply a
strncpy(desc, t->test_case_name, KUNIT_PARAM_DESC_SIZE). But,
strncpy() is unsafe in certain cases, too, so the kernel introduced
strscpy() -- see the note about strncpy() in
Documentation/process/deprecated.rst. Also have a look at the
documentation about str{n,l,s}cpy() in lib/string.c.

So, finally, what we want here is just 1 line:

strscpy(desc, t->test_case_name, KUNIT_PARAM_DESC_SIZE);

Patch 1/2 looks fine though, so hopefully v9 will be final. :-)

Thanks,
-- Marco

Arpitha Raghunandan

unread,
Nov 15, 2020, 11:55:03 PM11/15/20
to Marco Elver, Brendan Higgins, Shuah Khan, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, Tim Bird, David Gow, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, LKML, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
Okay, I'll look this up and make this change for v9.

> Patch 1/2 looks fine though, so hopefully v9 will be final. :-)
>
> Thanks,
> -- Marco
>

Thanks!

Arpitha Raghunandan

unread,
Nov 16, 2020, 12:41:35 AM11/16/20
to brendan...@google.com, sk...@linuxfoundation.org, el...@google.com, yza...@google.com, ty...@mit.edu, adilger...@dilger.ca, Tim....@sony.com, davi...@google.com, Arpitha Raghunandan, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-...@vger.kernel.org, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
Implementation of support for parameterized testing in KUnit. This
approach requires the creation of a test case using the
KUNIT_CASE_PARAM() macro that accepts a generator function as input.

This generator function should return the next parameter given the
previous parameter in parameterized tests. It also provides a macro to
generate common-case generators based on arrays. Generators may also
optionally provide a human-readable description of parameters, which is
displayed where available.

Note, currently the result of each parameter run is displayed in
diagnostic lines, and only the overall test case output summarizes
TAP-compliant success or failure of all parameter runs. In future, when
supported by kunit-tool, these can be turned into subsubtest outputs.

Signed-off-by: Arpitha Raghunandan <98....@gmail.com>
Co-developed-by: Marco Elver <el...@google.com>
Signed-off-by: Marco Elver <el...@google.com>
---
Changes v8->v9:
- No change to this patch of the patch series

Arpitha Raghunandan

unread,
Nov 16, 2020, 12:42:28 AM11/16/20
to brendan...@google.com, sk...@linuxfoundation.org, el...@google.com, yza...@google.com, ty...@mit.edu, adilger...@dilger.ca, Tim....@sony.com, davi...@google.com, Arpitha Raghunandan, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-...@vger.kernel.org, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
Modify fs/ext4/inode-test.c to use the parameterized testing
feature of KUnit.

Signed-off-by: Arpitha Raghunandan <98....@gmail.com>
Signed-off-by: Marco Elver <el...@google.com>
---
Changes v8->v9:
- Replace strncpy() with strscpy() in timestamp_expectation_to_desc()
Changes v7->v8:
- Replace strcpy() with strncpy() in timestamp_expectation_to_desc()
Changes v6->v7:
- Introduce timestamp_expectation_to_desc() to convert param to
description.
Changes v5->v6:
- No change to this patch of the patch series
Changes v4->v5:
- No change to this patch of the patch series
Changes v3->v4:
- Modification based on latest implementation of KUnit parameterized testing
Changes v2->v3:
- Marked hardcoded test data const
- Modification based on latest implementation of KUnit parameterized testing
Changes v1->v2:
- Modification based on latest implementation of KUnit parameterized testing

fs/ext4/inode-test.c | 320 ++++++++++++++++++++++---------------------
1 file changed, 164 insertions(+), 156 deletions(-)

diff --git a/fs/ext4/inode-test.c b/fs/ext4/inode-test.c
index d62d802c9c12..7935ea6cf92c 100644
--- a/fs/ext4/inode-test.c
+++ b/fs/ext4/inode-test.c
@@ -80,6 +80,145 @@ struct timestamp_expectation {
+ strscpy(desc, t->test_case_name, KUNIT_PARAM_DESC_SIZE);
+}
+
+KUNIT_ARRAY_PARAM(ext4_inode, test_data, timestamp_expectation_to_desc);
+
static time64_t get_32bit_time(const struct timestamp_expectation * const test)
{
if (test->msb_set) {
@@ -101,166 +240,35 @@ static time64_t get_32bit_time(const struct timestamp_expectation * const test)

Marco Elver

unread,
Nov 16, 2020, 3:51:23 AM11/16/20
to Arpitha Raghunandan, Brendan Higgins, Shuah Khan, Iurii Zaikin, Theodore Ts'o, Andreas Dilger, Tim Bird, David Gow, open list:KERNEL SELFTEST FRAMEWORK, KUnit Development, LKML, linux-kern...@lists.linuxfoundation.org, linux...@vger.kernel.org
On Mon, 16 Nov 2020 at 06:42, Arpitha Raghunandan <98....@gmail.com> wrote:
>
> Modify fs/ext4/inode-test.c to use the parameterized testing
> feature of KUnit.
>
> Signed-off-by: Arpitha Raghunandan <98....@gmail.com>
> Signed-off-by: Marco Elver <el...@google.com>

Reviewed-by: Marco Elver <el...@google.com>

Thank you!
It is loading more messages.
0 new messages