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>
This commit is contained in:
Marie Zhussupova
2025-06-26 17:17:29 +00:00
committed by Shuah Khan
parent 63d0a91231
commit 5ac244b9cc
2 changed files with 21 additions and 7 deletions

View File

@@ -93,4 +93,17 @@ config KUNIT_AUTORUN_ENABLED
In most cases this should be left as Y. Only if additional opt-in
behavior is needed should this be set to N.
config KUNIT_DEFAULT_TIMEOUT
int "Default value of the timeout module parameter"
default 300
help
Sets the default timeout, in seconds, for Kunit test cases. This value
is further multiplied by a factor determined by the assigned speed
setting: 1x for `DEFAULT`, 3x for `KUNIT_SPEED_SLOW`, and 12x for
`KUNIT_SPEED_VERY_SLOW`. This allows slower tests on slower machines
sufficient time to complete.
If unsure, the default timeout of 300 seconds is suitable for most
cases.
endif # KUNIT

View File

@@ -69,6 +69,13 @@ static bool enable_param;
module_param_named(enable, enable_param, bool, 0);
MODULE_PARM_DESC(enable, "Enable KUnit tests");
/*
* Configure the base timeout.
*/
static unsigned long kunit_base_timeout = CONFIG_KUNIT_DEFAULT_TIMEOUT;
module_param_named(timeout, kunit_base_timeout, ulong, 0644);
MODULE_PARM_DESC(timeout, "Set the base timeout for Kunit test cases");
/*
* KUnit statistic mode:
* 0 - disabled
@@ -393,12 +400,6 @@ static int kunit_timeout_mult(enum kunit_speed speed)
static unsigned long kunit_test_timeout(struct kunit_suite *suite, struct kunit_case *test_case)
{
int mult = 1;
/*
* TODO: Make the default (base) timeout configurable, so that users with
* particularly slow or fast machines can successfully run tests, while
* still taking advantage of the relative speed.
*/
unsigned long default_timeout = 300;
/*
* 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_
mult = kunit_timeout_mult(suite->attr.speed);
if (test_case->attr.speed != KUNIT_SPEED_UNSET)
mult = kunit_timeout_mult(test_case->attr.speed);
return mult * default_timeout * msecs_to_jiffies(MSEC_PER_SEC);
return mult * kunit_base_timeout * msecs_to_jiffies(MSEC_PER_SEC);
}