Skip to content

Commit 5ac244b

Browse files
Marie Zhussupovashuahkh
authored andcommitted
kunit: Make default kunit_test timeout configurable via both a module parameter and a Kconfig option
To accommodate varying hardware performance and use cases, the default kunit test case timeout (currently 300 seconds) is now configurable. Users can adjust the timeout by either setting the 'timeout' module parameter or the KUNIT_DEFAULT_TIMEOUT Kconfig option to their desired timeout in seconds. Link: https://lore.kernel.org/r/20250626171730.1765004-1-marievic@google.com Signed-off-by: Marie Zhussupova <marievic@google.com> Reviewed-by: David Gow <davidgow@google.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
1 parent 63d0a91 commit 5ac244b

2 files changed

Lines changed: 21 additions & 7 deletions

File tree

lib/kunit/Kconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,17 @@ config KUNIT_AUTORUN_ENABLED
9393
In most cases this should be left as Y. Only if additional opt-in
9494
behavior is needed should this be set to N.
9595

96+
config KUNIT_DEFAULT_TIMEOUT
97+
int "Default value of the timeout module parameter"
98+
default 300
99+
help
100+
Sets the default timeout, in seconds, for Kunit test cases. This value
101+
is further multiplied by a factor determined by the assigned speed
102+
setting: 1x for `DEFAULT`, 3x for `KUNIT_SPEED_SLOW`, and 12x for
103+
`KUNIT_SPEED_VERY_SLOW`. This allows slower tests on slower machines
104+
sufficient time to complete.
105+
106+
If unsure, the default timeout of 300 seconds is suitable for most
107+
cases.
108+
96109
endif # KUNIT

lib/kunit/test.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ static bool enable_param;
6969
module_param_named(enable, enable_param, bool, 0);
7070
MODULE_PARM_DESC(enable, "Enable KUnit tests");
7171

72+
/*
73+
* Configure the base timeout.
74+
*/
75+
static unsigned long kunit_base_timeout = CONFIG_KUNIT_DEFAULT_TIMEOUT;
76+
module_param_named(timeout, kunit_base_timeout, ulong, 0644);
77+
MODULE_PARM_DESC(timeout, "Set the base timeout for Kunit test cases");
78+
7279
/*
7380
* KUnit statistic mode:
7481
* 0 - disabled
@@ -393,12 +400,6 @@ static int kunit_timeout_mult(enum kunit_speed speed)
393400
static unsigned long kunit_test_timeout(struct kunit_suite *suite, struct kunit_case *test_case)
394401
{
395402
int mult = 1;
396-
/*
397-
* TODO: Make the default (base) timeout configurable, so that users with
398-
* particularly slow or fast machines can successfully run tests, while
399-
* still taking advantage of the relative speed.
400-
*/
401-
unsigned long default_timeout = 300;
402403

403404
/*
404405
* The default test timeout is 300 seconds and will be adjusted by mult
@@ -409,7 +410,7 @@ static unsigned long kunit_test_timeout(struct kunit_suite *suite, struct kunit_
409410
mult = kunit_timeout_mult(suite->attr.speed);
410411
if (test_case->attr.speed != KUNIT_SPEED_UNSET)
411412
mult = kunit_timeout_mult(test_case->attr.speed);
412-
return mult * default_timeout * msecs_to_jiffies(MSEC_PER_SEC);
413+
return mult * kunit_base_timeout * msecs_to_jiffies(MSEC_PER_SEC);
413414
}
414415

415416

0 commit comments

Comments
 (0)