Skip to content

Commit

Permalink
selftests/harness: remove use of LINE_MAX
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
edliaw authored and akpm00 committed Apr 25, 2024
1 parent c4a7dc9 commit 8092162
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
12 changes: 8 additions & 4 deletions tools/testing/selftests/kselftest_harness.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
#include <asm/types.h>
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
Expand Down Expand Up @@ -1156,16 +1155,20 @@ void __run_test(struct __fixture_metadata *f,
struct __test_metadata *t)
{
struct __test_xfail *xfail;
char test_name[LINE_MAX];
char *test_name;
const char *diagnostic;

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

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

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

Expand Down Expand Up @@ -1203,6 +1206,7 @@ void __run_test(struct __fixture_metadata *f,

ksft_test_result_code(t->exit_code, test_name,
diagnostic ? "%s" : "", diagnostic);
free(test_name);
}

static int test_harness_run(int argc, char **argv)
Expand Down
1 change: 1 addition & 0 deletions tools/testing/selftests/mm/mdwe_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <linux/mman.h>
#include <linux/prctl.h>

#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <sys/auxv.h>
Expand Down

0 comments on commit 8092162

Please sign in to comment.