[LTP] [PATCH] lib: tst_has_slow_kconfig() cache the result
Cyril Hrubis
chrubis@suse.cz
Mon Jan 20 13:06:06 CET 2025
The result from the tst_has_slow_kconfig() is not going to change so we
can cache the result as there are several cases where the function may
end up being called. For instance any test that calls SAFE_CLONE() will
call the function repeatedly. This change makes the tests slightly
faster and also avoids repeated messages in the test output.
For example before:
tst_kconfig.c:88: TINFO: Parsing kernel config '/lib/modules/6.12.3/build/.config'
tst_test.c:1722: TINFO: Overall timeout per run is 0h 00m 30s
tst_kconfig.c:88: TINFO: Parsing kernel config '/lib/modules/6.12.3/build/.config'
pidns05.c:34: TPASS: cpid == 1 (1)
pidns05.c:35: TPASS: ppid == 0 (0)
tst_kconfig.c:88: TINFO: Parsing kernel config '/lib/modules/6.12.3/build/.config'
pidns05.c:34: TPASS: cpid == 1 (1)
pidns05.c:35: TPASS: ppid == 0 (0)
tst_kconfig.c:88: TINFO: Parsing kernel config '/lib/modules/6.12.3/build/.config'
pidns05.c:34: TPASS: cpid == 1 (1)
pidns05.c:35: TPASS: ppid == 0 (0)
tst_kconfig.c:88: TINFO: Parsing kernel config '/lib/modules/6.12.3/build/.config'
pidns05.c:34: TPASS: cpid == 1 (1)
pidns05.c:35: TPASS: ppid == 0 (0)
tst_kconfig.c:88: TINFO: Parsing kernel config '/lib/modules/6.12.3/build/.config'
pidns05.c:34: TPASS: cpid == 1 (1)
pidns05.c:35: TPASS: ppid == 0 (0)
pidns05.c:94: TPASS: find_cinit_pids(pids) returned 5
pidns05.c:112: TPASS: No children left after sending SIGKILL to the first child
And after:
tst_kconfig.c:88: TINFO: Parsing kernel config '/lib/modules/6.12.3/build/.config'
tst_test.c:1722: TINFO: Overall timeout per run is 0h 00m 30s
pidns05.c:34: TPASS: cpid == 1 (1)
pidns05.c:35: TPASS: ppid == 0 (0)
pidns05.c:34: TPASS: cpid == 1 (1)
pidns05.c:35: TPASS: ppid == 0 (0)
pidns05.c:34: TPASS: cpid == 1 (1)
pidns05.c:35: TPASS: ppid == 0 (0)
pidns05.c:34: TPASS: cpid == 1 (1)
pidns05.c:35: TPASS: ppid == 0 (0)
pidns05.c:34: TPASS: cpid == 1 (1)
pidns05.c:35: TPASS: ppid == 0 (0)
pidns05.c:94: TPASS: find_cinit_pids(pids) returned 5
pidns05.c:112: TPASS: No children left after sending SIGKILL to the first child
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
lib/tst_kconfig.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/lib/tst_kconfig.c b/lib/tst_kconfig.c
index e83de3dcd..66402e370 100644
--- a/lib/tst_kconfig.c
+++ b/lib/tst_kconfig.c
@@ -652,13 +652,23 @@ static struct tst_kconfig_var slow_kconfigs[] = {
TST_KCONFIG_INIT("CONFIG_DEBUG_OBJECTS")
};
+static bool slow_kconfig_cached;
+static bool slow_kconfig_result;
+
int tst_has_slow_kconfig(void)
{
unsigned int i;
char path_buf[1024];
- if (!kconfig_path(path_buf, sizeof(path_buf)))
+ if (slow_kconfig_cached)
+ return slow_kconfig_result;
+
+ slow_kconfig_cached = 1;
+
+ if (!kconfig_path(path_buf, sizeof(path_buf))) {
+ slow_kconfig_result = 0;
return 0;
+ }
tst_kconfig_read(slow_kconfigs, ARRAY_SIZE(slow_kconfigs));
@@ -667,9 +677,11 @@ int tst_has_slow_kconfig(void)
tst_res(TINFO,
"%s kernel option detected which might slow the execution",
slow_kconfigs[i].id);
+ slow_kconfig_result = 1;
return 1;
}
}
+ slow_kconfig_result = 0;
return 0;
}
--
2.45.2
More information about the ltp
mailing list