linux-rtc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] Selftests: Fix compilation warnings due to missing _GNU_SOURCE definition
@ 2024-05-09  5:31 Tao Su
  2024-05-09  5:31 ` [PATCH v2 1/2] Revert "selftests/harness: remove use of LINE_MAX" Tao Su
  2024-05-09  5:31 ` [PATCH v2 2/2] selftests/harness: Use 1024 in place of LINE_MAX Tao Su
  0 siblings, 2 replies; 5+ messages in thread
From: Tao Su @ 2024-05-09  5:31 UTC (permalink / raw)
  To: linux-kselftest, linux-kernel, linux-sound, kvm, netdev,
	linux-rtc, linux-sgx
  Cc: akpm, edliaw, ivan.orlov0322, broonie, perex, tiwai, shuah,
	seanjc, pbonzini, bongsu.jeon, davem, edumazet, kuba, pabeni,
	alexandre.belloni, jarkko, dave.hansen, tao1.su

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

v1 -> v2:
- Stop defining _GNU_SOURCE in related selftests
- Revert commit 809216233555
- Use 1024 in place of LINE_MAX to fix 38c957f07038

v1: https://lore.kernel.org/all/20240507063534.4191447-1-tao1.su@linux.intel.com/

Tao Su (2):
  Revert "selftests/harness: remove use of LINE_MAX"
  selftests/harness: Use 1024 in place of LINE_MAX

 tools/testing/selftests/kselftest_harness.h | 11 +++--------
 tools/testing/selftests/mm/mdwe_test.c      |  1 -
 2 files changed, 3 insertions(+), 9 deletions(-)


base-commit: 45db3ab70092637967967bfd8e6144017638563c
-- 
2.34.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 1/2] Revert "selftests/harness: remove use of LINE_MAX"
  2024-05-09  5:31 [PATCH v2 0/2] Selftests: Fix compilation warnings due to missing _GNU_SOURCE definition Tao Su
@ 2024-05-09  5:31 ` Tao Su
  2024-05-10 12:33   ` Simon Horman
  2024-05-09  5:31 ` [PATCH v2 2/2] selftests/harness: Use 1024 in place of LINE_MAX Tao Su
  1 sibling, 1 reply; 5+ messages in thread
From: Tao Su @ 2024-05-09  5:31 UTC (permalink / raw)
  To: linux-kselftest, linux-kernel, linux-sound, kvm, netdev,
	linux-rtc, linux-sgx
  Cc: akpm, edliaw, ivan.orlov0322, broonie, perex, tiwai, shuah,
	seanjc, pbonzini, bongsu.jeon, davem, edumazet, kuba, pabeni,
	alexandre.belloni, jarkko, dave.hansen, tao1.su

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://lore.kernel.org/linux-kselftest/ZjuA3aY_iHkjP7bQ@google.com/
Fixes: 809216233555 ("selftests/harness: remove use of LINE_MAX")
Signed-off-by: Tao Su <tao1.su@linux.intel.com>
---
 tools/testing/selftests/kselftest_harness.h | 12 ++++--------
 tools/testing/selftests/mm/mdwe_test.c      |  1 -
 2 files changed, 4 insertions(+), 9 deletions(-)

diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h
index d98702b6955d..ba3ddeda24bf 100644
--- a/tools/testing/selftests/kselftest_harness.h
+++ b/tools/testing/selftests/kselftest_harness.h
@@ -56,6 +56,7 @@
 #include <asm/types.h>
 #include <ctype.h>
 #include <errno.h>
+#include <limits.h>
 #include <stdbool.h>
 #include <stdint.h>
 #include <stdio.h>
@@ -1158,7 +1159,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 */
@@ -1166,12 +1167,8 @@ void __run_test(struct __fixture_metadata *f,
 	t->trigger = 0;
 	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);
 
@@ -1209,7 +1206,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)
diff --git a/tools/testing/selftests/mm/mdwe_test.c b/tools/testing/selftests/mm/mdwe_test.c
index 1e01d3ddc11c..200bedcdc32e 100644
--- a/tools/testing/selftests/mm/mdwe_test.c
+++ b/tools/testing/selftests/mm/mdwe_test.c
@@ -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>
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 2/2] selftests/harness: Use 1024 in place of LINE_MAX
  2024-05-09  5:31 [PATCH v2 0/2] Selftests: Fix compilation warnings due to missing _GNU_SOURCE definition Tao Su
  2024-05-09  5:31 ` [PATCH v2 1/2] Revert "selftests/harness: remove use of LINE_MAX" Tao Su
@ 2024-05-09  5:31 ` Tao Su
  2024-05-10 12:33   ` Simon Horman
  1 sibling, 1 reply; 5+ messages in thread
From: Tao Su @ 2024-05-09  5:31 UTC (permalink / raw)
  To: linux-kselftest, linux-kernel, linux-sound, kvm, netdev,
	linux-rtc, linux-sgx
  Cc: akpm, edliaw, ivan.orlov0322, broonie, perex, tiwai, shuah,
	seanjc, pbonzini, bongsu.jeon, davem, edumazet, kuba, pabeni,
	alexandre.belloni, jarkko, dave.hansen, tao1.su

Android was seeing a compilation error because its C library does not
define LINE_MAX. Since LINE_MAX is only used to determine the size of
test_name[] and 1024 should be enough for the test name, use 1024
instead of LINE_MAX.

Fixes: 38c957f07038 ("selftests: kselftest_harness: generate test name once")
Signed-off-by: Tao Su <tao1.su@linux.intel.com>
---
 tools/testing/selftests/kselftest_harness.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h
index ba3ddeda24bf..610642f50977 100644
--- a/tools/testing/selftests/kselftest_harness.h
+++ b/tools/testing/selftests/kselftest_harness.h
@@ -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>
@@ -1159,7 +1158,7 @@ void __run_test(struct __fixture_metadata *f,
 		struct __test_metadata *t)
 {
 	struct __test_xfail *xfail;
-	char test_name[LINE_MAX];
+	char test_name[1024];
 	const char *diagnostic;
 
 	/* reset test struct */
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 1/2] Revert "selftests/harness: remove use of LINE_MAX"
  2024-05-09  5:31 ` [PATCH v2 1/2] Revert "selftests/harness: remove use of LINE_MAX" Tao Su
@ 2024-05-10 12:33   ` Simon Horman
  0 siblings, 0 replies; 5+ messages in thread
From: Simon Horman @ 2024-05-10 12:33 UTC (permalink / raw)
  To: Tao Su
  Cc: linux-kselftest, linux-kernel, linux-sound, kvm, netdev,
	linux-rtc, linux-sgx, akpm, edliaw, ivan.orlov0322, broonie,
	perex, tiwai, shuah, seanjc, pbonzini, bongsu.jeon, davem,
	edumazet, kuba, pabeni, alexandre.belloni, jarkko, dave.hansen

On Thu, May 09, 2024 at 01:31:12PM +0800, Tao Su wrote:
> 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://lore.kernel.org/linux-kselftest/ZjuA3aY_iHkjP7bQ@google.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>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 2/2] selftests/harness: Use 1024 in place of LINE_MAX
  2024-05-09  5:31 ` [PATCH v2 2/2] selftests/harness: Use 1024 in place of LINE_MAX Tao Su
@ 2024-05-10 12:33   ` Simon Horman
  0 siblings, 0 replies; 5+ messages in thread
From: Simon Horman @ 2024-05-10 12:33 UTC (permalink / raw)
  To: Tao Su
  Cc: linux-kselftest, linux-kernel, linux-sound, kvm, netdev,
	linux-rtc, linux-sgx, akpm, edliaw, ivan.orlov0322, broonie,
	perex, tiwai, shuah, seanjc, pbonzini, bongsu.jeon, davem,
	edumazet, kuba, pabeni, alexandre.belloni, jarkko, dave.hansen

On Thu, May 09, 2024 at 01:31:13PM +0800, Tao Su wrote:
> Android was seeing a compilation error because its C library does not
> define LINE_MAX. Since LINE_MAX is only used to determine the size of
> test_name[] and 1024 should be enough for the test name, use 1024
> instead of LINE_MAX.
> 
> Fixes: 38c957f07038 ("selftests: kselftest_harness: generate test name once")
> Signed-off-by: Tao Su <tao1.su@linux.intel.com>

Reviewed-by: Simon Horman <horms@kernel.org>


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-05-10 12:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-09  5:31 [PATCH v2 0/2] Selftests: Fix compilation warnings due to missing _GNU_SOURCE definition Tao Su
2024-05-09  5:31 ` [PATCH v2 1/2] Revert "selftests/harness: remove use of LINE_MAX" Tao Su
2024-05-10 12:33   ` Simon Horman
2024-05-09  5:31 ` [PATCH v2 2/2] selftests/harness: Use 1024 in place of LINE_MAX Tao Su
2024-05-10 12:33   ` Simon Horman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).