Skip to content

Commit

Permalink
lib: tst_has_slow_kconfig() cache the result
Browse files Browse the repository at this point in the history
The result from the tst_has_slow_kconfig() is not going to change so we
can cache the result as there are several places where the function may
end up being called from. 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 <[email protected]>
Reviewed-by: Li Wang <[email protected]>
Reviewed-by: Petr Vorel <[email protected]>
  • Loading branch information
metan-ucw committed Jan 20, 2025
1 parent a8213a6 commit c9a1511
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/tst_kconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand All @@ -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;
}

0 comments on commit c9a1511

Please sign in to comment.