Skip to content

Commit

Permalink
Revert "selftests/harness: remove use of LINE_MAX"
Browse files Browse the repository at this point in the history
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/20240411231954.62156-1-edliaw@google.com
[2] https://lore.kernel.org/linux-kselftest/ZjuA3aY_iHkjP7bQ@google.com


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/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: 8092162 ("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>
  • Loading branch information
Tao Su authored and Andrew Morton committed May 19, 2024
1 parent 790a4a3 commit 6bb955f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
12 changes: 4 additions & 8 deletions tools/testing/selftests/kselftest_harness.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ static_assert(0, "kselftest harness requires _GNU_SOURCE to be defined");
#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 @@ -1216,7 +1217,7 @@ void __run_test(struct __fixture_metadata *f,
struct __test_metadata *t)
{
struct __test_xfail *xfail;
char *test_name;
char test_name[LINE_MAX];
const char *diagnostic;

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

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);
}
snprintf(test_name, sizeof(test_name), "%s%s%s.%s",
f->name, variant->name[0] ? "." : "", variant->name, t->name);

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

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

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

static int test_harness_run(int argc, char **argv)
Expand Down
1 change: 0 additions & 1 deletion tools/testing/selftests/mm/mdwe_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#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 6bb955f

Please sign in to comment.