Skip to content

Commit 8092162

Browse files
edliawakpm00
authored andcommitted
selftests/harness: remove use of LINE_MAX
Android was seeing a compliation error because its C library does not define LINE_MAX. This replaces the use of LINE_MAX / snprintf with asprintf, which will change the behavior to not truncate the test name if it is over 2048 chars long. See also: llvm/llvm-project#88119 [[email protected]: remove limits.h include, per Edward] [[email protected]: check asprintf() return] [[email protected]: fix undeclared function error] Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Fixes: 38c957f ("selftests: kselftest_harness: generate test name once") Signed-off-by: Edward Liaw <[email protected]> Signed-off-by: Muhammad Usama Anjum <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Axel Rasmussen <[email protected]> Cc: Bill Wendling <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: Edward Liaw <[email protected]> Cc: Justin Stitt <[email protected]> Cc: Kees Cook <[email protected]> Cc: "Mike Rapoport (IBM)" <[email protected]> Cc: Nathan Chancellor <[email protected]> Cc: Nick Desaulniers <[email protected]> Cc: Peter Xu <[email protected]> Cc: Shuah Khan <[email protected]> Cc: Will Drewry <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent c4a7dc9 commit 8092162

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

tools/testing/selftests/kselftest_harness.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
#include <asm/types.h>
5757
#include <ctype.h>
5858
#include <errno.h>
59-
#include <limits.h>
6059
#include <stdbool.h>
6160
#include <stdint.h>
6261
#include <stdio.h>
@@ -1156,16 +1155,20 @@ void __run_test(struct __fixture_metadata *f,
11561155
struct __test_metadata *t)
11571156
{
11581157
struct __test_xfail *xfail;
1159-
char test_name[LINE_MAX];
1158+
char *test_name;
11601159
const char *diagnostic;
11611160

11621161
/* reset test struct */
11631162
t->exit_code = KSFT_PASS;
11641163
t->trigger = 0;
11651164
memset(t->results->reason, 0, sizeof(t->results->reason));
11661165

1167-
snprintf(test_name, sizeof(test_name), "%s%s%s.%s",
1168-
f->name, variant->name[0] ? "." : "", variant->name, t->name);
1166+
if (asprintf(&test_name, "%s%s%s.%s", f->name,
1167+
variant->name[0] ? "." : "", variant->name, t->name) == -1) {
1168+
ksft_print_msg("ERROR ALLOCATING MEMORY\n");
1169+
t->exit_code = KSFT_FAIL;
1170+
_exit(t->exit_code);
1171+
}
11691172

11701173
ksft_print_msg(" RUN %s ...\n", test_name);
11711174

@@ -1203,6 +1206,7 @@ void __run_test(struct __fixture_metadata *f,
12031206

12041207
ksft_test_result_code(t->exit_code, test_name,
12051208
diagnostic ? "%s" : "", diagnostic);
1209+
free(test_name);
12061210
}
12071211

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

tools/testing/selftests/mm/mdwe_test.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <linux/mman.h>
88
#include <linux/prctl.h>
99

10+
#define _GNU_SOURCE
1011
#include <stdio.h>
1112
#include <stdlib.h>
1213
#include <sys/auxv.h>

0 commit comments

Comments
 (0)