The pmtu.sh test script treats all non-zero return code as a failure,
thus it will be marked as FAILED when some sub-test got skipped.
This patchset will:
1. Use the kselftest framework skip code $ksft_skip to replace the
hardcoded SKIP return code.
2. Improve the result processing, the test will be marked as PASSED
if nothing goes wrong and not all the tests were skipped.
Po-Hsu Lin (2):
selftests: pmtu.sh: use $ksft_skip for skipped return code
selftests: pmtu.sh: improve the test result processing
tools/testing/selftests/net/pmtu.sh | 83 ++++++++++++++++++++++---------------
1 file changed, 50 insertions(+), 33 deletions(-)
--
2.7.4
Currently KVM lacks a simple, userspace agnostic, performance benchmark for
dirty logging. Such a benchmark will be beneficial for ensuring that dirty
logging performance does not regress, and to give a common baseline for
validating performance improvements. The dirty log perf test introduced in
this series builds on aspects of the existing demand paging perf test and
provides time-based performance metrics for enabling and disabling dirty
logging, getting the dirty log, and dirtying memory.
While the test currently only has a build target for x86, I expect it will
work on, or be easily modified to support other architectures.
Ben Gardon (5):
KVM: selftests: Factor code out of demand_paging_test
KVM: selftests: Remove address rounding in guest code
KVM: selftests: Simplify demand_paging_test with timespec_diff_now
KVM: selftests: Add wrfract to common guest code
KVM: selftests: Introduce the dirty log perf test
tools/testing/selftests/kvm/.gitignore | 1 +
tools/testing/selftests/kvm/Makefile | 1 +
.../selftests/kvm/demand_paging_test.c | 230 ++---------
.../selftests/kvm/dirty_log_perf_test.c | 382 ++++++++++++++++++
.../selftests/kvm/include/perf_test_util.h | 192 +++++++++
.../testing/selftests/kvm/include/test_util.h | 2 +
tools/testing/selftests/kvm/lib/test_util.c | 22 +-
7 files changed, 635 insertions(+), 195 deletions(-)
create mode 100644 tools/testing/selftests/kvm/dirty_log_perf_test.c
create mode 100644 tools/testing/selftests/kvm/include/perf_test_util.h
--
2.29.0.rc2.309.g374f81d7ae-goog
writting -> writing
Signed-off-by: Wang Qing <wangqing(a)vivo.com>
---
tools/testing/selftests/vm/userfaultfd.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/vm/userfaultfd.c b/tools/testing/selftests/vm/userfaultfd.c
index 9b0912a..9132fae7
--- a/tools/testing/selftests/vm/userfaultfd.c
+++ b/tools/testing/selftests/vm/userfaultfd.c
@@ -894,7 +894,7 @@ static int faulting_process(int signal_test)
count_verify[nr]);
}
/*
- * Trigger write protection if there is by writting
+ * Trigger write protection if there is by writing
* the same value back.
*/
*area_count(area_dst, nr) = count;
@@ -922,7 +922,7 @@ static int faulting_process(int signal_test)
count_verify[nr]); exit(1);
}
/*
- * Trigger write protection if there is by writting
+ * Trigger write protection if there is by writing
* the same value back.
*/
*area_count(area_dst, nr) = count;
--
2.7.4
Hi Linus,
Please pull the following Kselftest fixes update for Linux 5.10-rc3.
This Kselftest fixes update for Linux 5.10-rc3 consists of fixes to
ftrace test and several fixes from Tommi Rantala for several tests.
Please note that these fixes have been in next for a while. I dropped
a minor fix for soon to be removed staging ion driver selftest yesterday
to make the merge easier so it doesn't conflict with the staging pull
request.
diff is attached.
thanks,
-- Shuah
----------------------------------------------------------------
The following changes since commit 3650b228f83adda7e5ee532e2b90429c03f7b9ec:
Linux 5.10-rc1 (2020-10-25 15:14:11 -0700)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest
tags/linux-kselftest-fixes-5.10-rc3
for you to fetch changes up to 7d764b685ee1bc73a9fa2b6cb4d42fa72b943145:
selftests: binderfs: use SKIP instead of XFAIL (2020-11-05 10:08:15
-0700)
----------------------------------------------------------------
linux-kselftest-fixes-5.10-rc3
This Kselftest fixes update for Linux 5.10-rc3 consists of fixes to
ftrace test and several fixes from Tommi Rantala for several tests.
----------------------------------------------------------------
Colin Ian King (1):
selftests/ftrace: check for do_sys_openat2 in user-memory test
Steven Rostedt (VMware) (1):
selftests/ftrace: Use $FUNCTION_FORK to reference kernel fork
function
Tommi Rantala (11):
selftests: filter kselftest headers from command in lib.mk
selftests: pidfd: fix compilation errors due to wait.h
selftests/harness: prettify SKIP message whitespace again
selftests: pidfd: use ksft_test_result_skip() when skipping test
selftests: pidfd: skip test on kcmp() ENOSYS
selftests: pidfd: add CONFIG_CHECKPOINT_RESTORE=y to config
selftests: pidfd: drop needless linux/kcmp.h inclusion in
pidfd_setns_test.c
selftests: proc: fix warning: _GNU_SOURCE redefined
selftests: core: use SKIP instead of XFAIL in close_range_test.c
selftests: clone3: use SKIP instead of XFAIL
selftests: binderfs: use SKIP instead of XFAIL
.../selftests/clone3/clone3_cap_checkpoint_restore.c | 2 +-
tools/testing/selftests/core/close_range_test.c | 8 ++++----
.../testing/selftests/filesystems/binderfs/binderfs_test.c | 8 ++++----
.../selftests/ftrace/test.d/dynevent/add_remove_kprobe.tc | 2 +-
.../ftrace/test.d/dynevent/clear_select_events.tc | 2 +-
.../ftrace/test.d/dynevent/generic_clear_event.tc | 2 +-
.../ftrace/test.d/ftrace/func-filter-notrace-pid.tc | 2 +-
.../selftests/ftrace/test.d/ftrace/func-filter-pid.tc | 2 +-
.../ftrace/test.d/ftrace/func-filter-stacktrace.tc | 4 ++--
tools/testing/selftests/ftrace/test.d/functions | 7 +++++++
.../selftests/ftrace/test.d/kprobe/add_and_remove.tc | 2 +-
tools/testing/selftests/ftrace/test.d/kprobe/busy_check.tc | 2 +-
.../testing/selftests/ftrace/test.d/kprobe/kprobe_args.tc | 4 ++--
.../selftests/ftrace/test.d/kprobe/kprobe_args_comm.tc | 2 +-
.../selftests/ftrace/test.d/kprobe/kprobe_args_string.tc | 4 ++--
.../selftests/ftrace/test.d/kprobe/kprobe_args_symbol.tc | 10 +++++-----
.../selftests/ftrace/test.d/kprobe/kprobe_args_type.tc | 2 +-
.../selftests/ftrace/test.d/kprobe/kprobe_args_user.tc | 4 ++++
.../selftests/ftrace/test.d/kprobe/kprobe_ftrace.tc | 14
+++++++-------
.../selftests/ftrace/test.d/kprobe/kprobe_multiprobe.tc | 2 +-
.../selftests/ftrace/test.d/kprobe/kprobe_syntax_errors.tc | 12 ++++++------
.../selftests/ftrace/test.d/kprobe/kretprobe_args.tc | 4 ++--
tools/testing/selftests/ftrace/test.d/kprobe/profile.tc | 2 +-
tools/testing/selftests/kselftest_harness.h | 2 +-
tools/testing/selftests/lib.mk | 2 +-
tools/testing/selftests/pidfd/config | 1 +
tools/testing/selftests/pidfd/pidfd_getfd_test.c | 5 ++++-
tools/testing/selftests/pidfd/pidfd_open_test.c | 1 -
tools/testing/selftests/pidfd/pidfd_poll_test.c | 1 -
tools/testing/selftests/pidfd/pidfd_setns_test.c | 1 -
tools/testing/selftests/pidfd/pidfd_test.c | 2 +-
tools/testing/selftests/proc/proc-loadavg-001.c | 1 -
tools/testing/selftests/proc/proc-self-syscall.c | 1 -
tools/testing/selftests/proc/proc-uptime-002.c | 1 -
----------------------------------------------------------------
Implementation of support for parameterized testing in KUnit.
This approach requires the creation of a test case using the
KUNIT_CASE_PARAM macro that accepts a generator function as input.
This generator function should return the next parameter given the
previous parameter in parameterized tests. It also provides
a macro to generate common-case generators.
Signed-off-by: Arpitha Raghunandan <98.arpi(a)gmail.com>
Co-developed-by: Marco Elver <elver(a)google.com>
Signed-off-by: Marco Elver <elver(a)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..b8b63aeda504 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",
+ 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
Implementation of support for parameterized testing in KUnit.
This approach requires the creation of a test case using the
KUNIT_CASE_PARAM macro that accepts a generator function as input.
This generator function should return the next parameter given the
previous parameter in parameterized tests. It also provides
a macro to generate common-case generators.
Signed-off-by: Arpitha Raghunandan <98.arpi(a)gmail.com>
Co-developed-by: Marco Elver <elver(a)google.com>
Signed-off-by: Marco Elver <elver(a)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++;
+ }
+ }
}
static void kunit_case_internal_cleanup(struct kunit *test)
--
2.25.1
Hi Linus,
Please pull the following Kunit fixes update for Linux 5.10-rc3
This Kunit update for Linux 5.10-rc3 consists of several kunit_tool
and documentation fixes.
diff is attached.
thanks,
-- Shuah
----------------------------------------------------------------
The following changes since commit 3650b228f83adda7e5ee532e2b90429c03f7b9ec:
Linux 5.10-rc1 (2020-10-25 15:14:11 -0700)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest
tags/linux-kselftest-kunit-fixes-5.10-rc3
for you to fetch changes up to 0d0d245104a42e593adcf11396017a6420c08ba8:
kunit: tools: fix kunit_tool tests for parsing test plans (2020-10-26
13:25:40 -0600)
----------------------------------------------------------------
linux-kselftest-kunit-fixes-5.10-rc3
This Kunit update for Linux 5.10-rc3 consists of several kunit_tool
and documentation fixes.
----------------------------------------------------------------
Andy Shevchenko (1):
kunit: Don't fail test suites if one of them is empty
Brendan Higgins (1):
kunit: tools: fix kunit_tool tests for parsing test plans
David Gow (1):
kunit: Fix kunit.py --raw_output option
Mauro Carvalho Chehab (1):
kunit: test: fix remaining kernel-doc warnings
SeongJae Park (1):
Documentation: kunit: Update Kconfig parts for KUNIT's module support
Documentation/dev-tools/kunit/start.rst | 2 +-
Documentation/dev-tools/kunit/usage.rst | 5 ++++
include/kunit/test.h | 16 +++++------
tools/testing/kunit/kunit_parser.py | 3 +-
tools/testing/kunit/kunit_tool_test.py | 32
++++++++++++++++-----
.../kunit/test_data/test_config_printk_time.log | Bin 1584 -> 1605
bytes
.../test_data/test_interrupted_tap_output.log | Bin 1982 -> 2003
bytes
.../test_data/test_kernel_panic_interrupt.log | Bin 1321 -> 1342
bytes
.../kunit/test_data/test_multiple_prefixes.log | Bin 1832 -> 1861
bytes
.../kunit/test_data/test_pound_no_prefix.log | Bin 1193 -> 1200
bytes
tools/testing/kunit/test_data/test_pound_sign.log | Bin 1656 -> 1676
bytes
11 files changed, 40 insertions(+), 18 deletions(-)
----------------------------------------------------------------