Skip to content

Commit 6bb955f

Browse files
taosu-linuxakpm00
authored andcommitted
Revert "selftests/harness: remove use of LINE_MAX"
Patch series "Selftests: Fix compilation warnings due to missing _GNU_SOURCE definition", v2. Since kselftest_harness.h introduces asprintf()[1], many selftests have compilation warnings or errors due to missing _GNU_SOURCE definitions. The issue stems from a lack of a LINE_MAX definition in Android (see commit 38c957f), which is the reason why asprintf() was introduced. We tried adding _GNU_SOURCE definitions to more selftests to fix, but asprintf() may continue to cause problems, and since it is quite late in the 6.9 cycle, we would like to revert 8092162 first to provide testing for forks[2]. [1] https://lore.kernel.org/all/[email protected] [2] https://lore.kernel.org/linux-kselftest/[email protected] This patch (of 2): This reverts commit 8092162. asprintf() is declared in stdio.h when defining _GNU_SOURCE, but stdio.h is so common that many files don't define _GNU_SOURCE before including stdio.h, and defining _GNU_SOURCE after including stdio.h will no longer take effect, which causes warnings or even errors during compilation in many selftests. Revert 'commit 8092162 ("selftests/harness: remove use of LINE_MAX")' as that came in quite late in the 6.9 cycle. Link: https://lkml.kernel.org/r/[email protected] Link: https://lore.kernel.org/linux-kselftest/[email protected]/ Link: https://lkml.kernel.org/r/[email protected] Fixes: 8092162 ("selftests/harness: remove use of LINE_MAX") Signed-off-by: Tao Su <[email protected]> Reviewed-by: Simon Horman <[email protected]> Cc: Alexandre Belloni <[email protected]> Cc: Bongsu Jeon <[email protected]> Cc: Dave Hansen <[email protected]> Cc: David S. Miller <[email protected]> Cc: Edward Liaw <[email protected]> Cc: Eric Dumazet <[email protected]> Cc: Ivan Orlov <[email protected]> Cc: Jakub Kicinski <[email protected]> Cc: Jarkko Sakkinen <[email protected]> Cc: Jaroslav Kysela <[email protected]> Cc: Mark Brown <[email protected]> Cc: Paolo Abeni <[email protected]> Cc: Paolo Bonzini <[email protected]> Cc: Sean Christopherson <[email protected]> Cc: Shuah Khan <[email protected]> Cc: Takashi Iwai <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 790a4a3 commit 6bb955f

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

tools/testing/selftests/kselftest_harness.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ static_assert(0, "kselftest harness requires _GNU_SOURCE to be defined");
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>
@@ -1216,7 +1217,7 @@ void __run_test(struct __fixture_metadata *f,
12161217
struct __test_metadata *t)
12171218
{
12181219
struct __test_xfail *xfail;
1219-
char *test_name;
1220+
char test_name[LINE_MAX];
12201221
const char *diagnostic;
12211222

12221223
/* reset test struct */
@@ -1227,12 +1228,8 @@ void __run_test(struct __fixture_metadata *f,
12271228
memset(t->env, 0, sizeof(t->env));
12281229
memset(t->results->reason, 0, sizeof(t->results->reason));
12291230

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

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

@@ -1270,7 +1267,6 @@ void __run_test(struct __fixture_metadata *f,
12701267

12711268
ksft_test_result_code(t->exit_code, test_name,
12721269
diagnostic ? "%s" : NULL, diagnostic);
1273-
free(test_name);
12741270
}
12751271

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

tools/testing/selftests/mm/mdwe_test.c

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

10-
#define _GNU_SOURCE
1110
#include <stdio.h>
1211
#include <stdlib.h>
1312
#include <sys/auxv.h>

0 commit comments

Comments
 (0)