Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 38c957f07038), 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 809216233555 first to provide
testing for forks[2].

[1] https://lore.kernel.org/all/20240411231954.62156-1-edliaw@google.com
[2] https://lore.kernel.org/linux-kselftest/ZjuA3aY_iHkjP7bQ@google.com


This patch (of 2):

This reverts commit 8092162335554c8ef5e7f50eff68aa9cfbdbf865.

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 809216233555 ("selftests/harness: remove use of LINE_MAX")'
as that came in quite late in the 6.9 cycle.

Link: https://lkml.kernel.org/r/20240509053113.43462-1-tao1.su@linux.intel.com
Link: https://lore.kernel.org/linux-kselftest/ZjuA3aY_iHkjP7bQ@google.com/
Link: https://lkml.kernel.org/r/20240509053113.43462-2-tao1.su@linux.intel.com
Fixes: 809216233555 ("selftests/harness: remove use of LINE_MAX")
Signed-off-by: Tao Su <tao1.su@linux.intel.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
Cc: Bongsu Jeon <bongsu.jeon@samsung.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: Edward Liaw <edliaw@google.com>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Ivan Orlov <ivan.orlov0322@gmail.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Jarkko Sakkinen <jarkko@kernel.org>
Cc: Jaroslav Kysela <perex@perex.cz>
Cc: Mark Brown <broonie@kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Sean Christopherson <seanjc@google.com>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Takashi Iwai <tiwai@suse.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Tao Su and committed by
Andrew Morton
6bb955fc 790a4a3d

+4 -9
+4 -8
tools/testing/selftests/kselftest_harness.h
··· 56 56 #include <asm/types.h> 57 57 #include <ctype.h> 58 58 #include <errno.h> 59 + #include <limits.h> 59 60 #include <stdbool.h> 60 61 #include <stdint.h> 61 62 #include <stdio.h> ··· 1217 1216 struct __test_metadata *t) 1218 1217 { 1219 1218 struct __test_xfail *xfail; 1220 - char *test_name; 1219 + char test_name[LINE_MAX]; 1221 1220 const char *diagnostic; 1222 1221 1223 1222 /* reset test struct */ ··· 1228 1227 memset(t->env, 0, sizeof(t->env)); 1229 1228 memset(t->results->reason, 0, sizeof(t->results->reason)); 1230 1229 1231 - if (asprintf(&test_name, "%s%s%s.%s", f->name, 1232 - variant->name[0] ? "." : "", variant->name, t->name) == -1) { 1233 - ksft_print_msg("ERROR ALLOCATING MEMORY\n"); 1234 - t->exit_code = KSFT_FAIL; 1235 - _exit(t->exit_code); 1236 - } 1230 + snprintf(test_name, sizeof(test_name), "%s%s%s.%s", 1231 + f->name, variant->name[0] ? "." : "", variant->name, t->name); 1237 1232 1238 1233 ksft_print_msg(" RUN %s ...\n", test_name); 1239 1234 ··· 1267 1270 1268 1271 ksft_test_result_code(t->exit_code, test_name, 1269 1272 diagnostic ? "%s" : NULL, diagnostic); 1270 - free(test_name); 1271 1273 } 1272 1274 1273 1275 static int test_harness_run(int argc, char **argv)
-1
tools/testing/selftests/mm/mdwe_test.c
··· 7 7 #include <linux/mman.h> 8 8 #include <linux/prctl.h> 9 9 10 - #define _GNU_SOURCE 11 10 #include <stdio.h> 12 11 #include <stdlib.h> 13 12 #include <sys/auxv.h>