]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
kunit: Make default kunit_test timeout configurable via both a module parameter and...
authorMarie Zhussupova <marievic@google.com>
Thu, 26 Jun 2025 17:17:29 +0000 (17:17 +0000)
committerShuah Khan <skhan@linuxfoundation.org>
Fri, 27 Jun 2025 21:00:05 +0000 (15:00 -0600)
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>
lib/kunit/Kconfig
lib/kunit/test.c

index a97897edd9642f3e5df7fdd9dee26ee5cf00d6a4..c10ede4b1d2201d5f8cddeb71cc5096e21be9b6a 100644 (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
index 002121675605d082c040b271fd8fba2e86e70d8c..f3c6b11f12b81d1c81ea581305b685f115d2bf7f 100644 (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);
 }