Commit 47669f40 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'linux_kselftest-kunit-fixes-6.7-rc4' of...

Merge tag 'linux_kselftest-kunit-fixes-6.7-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest

Pull KUnit fixes from Shuah Khan:
 "Three fixes to warnings and run-time test behavior. With these fixes,
  test suite counter will be reset correctly before running tests, kunit
  will warn if tests are too slow, and eliminate warning when kfree() as
  an action"

* tag 'linux_kselftest-kunit-fixes-6.7-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest:
  kunit: test: Avoid cast warning when adding kfree() as an action
  kunit: Reset suite counter right before running tests
  kunit: Warn if tests are slow
parents 2594faaf 1bddcf77
...@@ -562,7 +562,7 @@ static void kunit_log_test(struct kunit *test) ...@@ -562,7 +562,7 @@ static void kunit_log_test(struct kunit *test)
KUNIT_EXPECT_TRUE(test, test->log->append_newlines); KUNIT_EXPECT_TRUE(test, test->log->append_newlines);
full_log = string_stream_get_string(test->log); full_log = string_stream_get_string(test->log);
kunit_add_action(test, (kunit_action_t *)kfree, full_log); kunit_add_action(test, kfree_wrapper, full_log);
KUNIT_EXPECT_NOT_ERR_OR_NULL(test, KUNIT_EXPECT_NOT_ERR_OR_NULL(test,
strstr(full_log, "put this in log.")); strstr(full_log, "put this in log."));
KUNIT_EXPECT_NOT_ERR_OR_NULL(test, KUNIT_EXPECT_NOT_ERR_OR_NULL(test,
......
...@@ -338,6 +338,36 @@ void kunit_init_test(struct kunit *test, const char *name, struct string_stream ...@@ -338,6 +338,36 @@ void kunit_init_test(struct kunit *test, const char *name, struct string_stream
} }
EXPORT_SYMBOL_GPL(kunit_init_test); EXPORT_SYMBOL_GPL(kunit_init_test);
/* Only warn when a test takes more than twice the threshold */
#define KUNIT_SPEED_WARNING_MULTIPLIER 2
/* Slow tests are defined as taking more than 1s */
#define KUNIT_SPEED_SLOW_THRESHOLD_S 1
#define KUNIT_SPEED_SLOW_WARNING_THRESHOLD_S \
(KUNIT_SPEED_WARNING_MULTIPLIER * KUNIT_SPEED_SLOW_THRESHOLD_S)
#define s_to_timespec64(s) ns_to_timespec64((s) * NSEC_PER_SEC)
static void kunit_run_case_check_speed(struct kunit *test,
struct kunit_case *test_case,
struct timespec64 duration)
{
struct timespec64 slow_thr =
s_to_timespec64(KUNIT_SPEED_SLOW_WARNING_THRESHOLD_S);
enum kunit_speed speed = test_case->attr.speed;
if (timespec64_compare(&duration, &slow_thr) < 0)
return;
if (speed == KUNIT_SPEED_VERY_SLOW || speed == KUNIT_SPEED_SLOW)
return;
kunit_warn(test,
"Test should be marked slow (runtime: %lld.%09lds)",
duration.tv_sec, duration.tv_nsec);
}
/* /*
* Initializes and runs test case. Does not clean up or do post validations. * Initializes and runs test case. Does not clean up or do post validations.
*/ */
...@@ -345,6 +375,8 @@ static void kunit_run_case_internal(struct kunit *test, ...@@ -345,6 +375,8 @@ static void kunit_run_case_internal(struct kunit *test,
struct kunit_suite *suite, struct kunit_suite *suite,
struct kunit_case *test_case) struct kunit_case *test_case)
{ {
struct timespec64 start, end;
if (suite->init) { if (suite->init) {
int ret; int ret;
...@@ -356,7 +388,13 @@ static void kunit_run_case_internal(struct kunit *test, ...@@ -356,7 +388,13 @@ static void kunit_run_case_internal(struct kunit *test,
} }
} }
ktime_get_ts64(&start);
test_case->run_case(test); test_case->run_case(test);
ktime_get_ts64(&end);
kunit_run_case_check_speed(test, test_case, timespec64_sub(end, start));
} }
static void kunit_case_internal_cleanup(struct kunit *test) static void kunit_case_internal_cleanup(struct kunit *test)
...@@ -670,6 +708,8 @@ int __kunit_test_suites_init(struct kunit_suite * const * const suites, int num_ ...@@ -670,6 +708,8 @@ int __kunit_test_suites_init(struct kunit_suite * const * const suites, int num_
return 0; return 0;
} }
kunit_suite_counter = 1;
static_branch_inc(&kunit_running); static_branch_inc(&kunit_running);
for (i = 0; i < num_suites; i++) { for (i = 0; i < num_suites; i++) {
...@@ -696,8 +736,6 @@ void __kunit_test_suites_exit(struct kunit_suite **suites, int num_suites) ...@@ -696,8 +736,6 @@ void __kunit_test_suites_exit(struct kunit_suite **suites, int num_suites)
for (i = 0; i < num_suites; i++) for (i = 0; i < num_suites; i++)
kunit_exit_suite(suites[i]); kunit_exit_suite(suites[i]);
kunit_suite_counter = 1;
} }
EXPORT_SYMBOL_GPL(__kunit_test_suites_exit); EXPORT_SYMBOL_GPL(__kunit_test_suites_exit);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment