Skip to content

Commit 38c957f

Browse files
kuba-moodavem330
authored andcommitted
selftests: kselftest_harness: generate test name once
Since we added variant support generating full test case name takes 4 string arguments. We're about to need it in another two places. Stop the duplication and print once into a temporary buffer. Suggested-by: Jakub Sitnicki <[email protected]> Acked-by: Kees Cook <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent a724707 commit 38c957f

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

tools/testing/selftests/kselftest_harness.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
#include <asm/types.h>
5757
#include <ctype.h>
5858
#include <errno.h>
59+
#include <limits.h>
5960
#include <stdbool.h>
6061
#include <stdint.h>
6162
#include <stdio.h>
@@ -1107,14 +1108,18 @@ void __run_test(struct __fixture_metadata *f,
11071108
struct __fixture_variant_metadata *variant,
11081109
struct __test_metadata *t)
11091110
{
1111+
char test_name[LINE_MAX];
1112+
11101113
/* reset test struct */
11111114
t->passed = 1;
11121115
t->skip = 0;
11131116
t->trigger = 0;
11141117
memset(t->results->reason, 0, sizeof(t->results->reason));
11151118

1116-
ksft_print_msg(" RUN %s%s%s.%s ...\n",
1117-
f->name, variant->name[0] ? "." : "", variant->name, t->name);
1119+
snprintf(test_name, sizeof(test_name), "%s%s%s.%s",
1120+
f->name, variant->name[0] ? "." : "", variant->name, t->name);
1121+
1122+
ksft_print_msg(" RUN %s ...\n", test_name);
11181123

11191124
/* Make sure output buffers are flushed before fork */
11201125
fflush(stdout);
@@ -1135,15 +1140,14 @@ void __run_test(struct __fixture_metadata *f,
11351140
} else {
11361141
__wait_for_test(t);
11371142
}
1138-
ksft_print_msg(" %4s %s%s%s.%s\n", t->passed ? "OK" : "FAIL",
1139-
f->name, variant->name[0] ? "." : "", variant->name, t->name);
1143+
ksft_print_msg(" %4s %s\n",
1144+
t->passed ? "OK" : "FAIL", test_name);
11401145

11411146
if (t->skip)
11421147
ksft_test_result_skip("%s\n", t->results->reason[0] ?
11431148
t->results->reason : "unknown");
11441149
else
1145-
ksft_test_result(t->passed, "%s%s%s.%s\n",
1146-
f->name, variant->name[0] ? "." : "", variant->name, t->name);
1150+
ksft_test_result(t->passed, "%s\n", test_name);
11471151
}
11481152

11491153
static int test_harness_run(int argc, char **argv)

0 commit comments

Comments
 (0)