Skip to contentSkip to conversation

selftests/harness: remove use of LINE_MAX

PATCH Applied Edward Liaw 2 participants 4 messages Apr 11, 2024 – Apr 12, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests/harness: remove use of LINE_MAX

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:
https://github.com/llvm/llvm-project/issues/88119

---
 tools/testing/selftests/kselftest_harness.h | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
tools/testing/selftests/kselftest_harness.h +4 -3
index 4fd735e48ee7..70fedd2411ed 100644
@@ -1156,7 +1156,7 @@ 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 */
@@ -1164,8 +1164,8 @@ void __run_test(struct __fixture_metadata *f,
 	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);
+	asprintf(&test_name, "%s%s%s.%s", f->name,
+	         variant->name[0] ? "." : "", variant->name, t->name);
 
 	ksft_print_msg(" RUN           %s ...\n", test_name);
 
@@ -1203,6 +1203,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)
Signature · 1 line
2.44.0.683.g7961c838ac-goog
maintainer
#1 lore raw
Quoted 4 lines · On Thu, 11 Apr 2024 23:19:49 +0000 Edward Liaw <[email protected]> wrote:

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.

Thanks, I'll grab and shall send it Linuswards for 6.9-rcX.

I added

Fixes 38c957f07038 ("selftests: kselftest_harness: generate test name once")
#2 lore raw
Quoted 7 lines · Andrew Morton

Thanks, I'll grab and shall send it Linuswards for 6.9-rcX.

I added

Fixes 38c957f07038 ("selftests: kselftest_harness: generate test name once")

Thanks, I just realized I forgot to remove the <limits.h> includes. Should I send another patch for that or send a v2 of this one?

maintainer
#3 lore raw
Quoted 11 lines · On Fri, 12 Apr 2024 12:30:15 -0700 Edward Liaw <[email protected]> wrote:
Quoted 7 lines · Andrew Morton

Thanks, I'll grab and shall send it Linuswards for 6.9-rcX.

I added

Fixes 38c957f07038 ("selftests: kselftest_harness: generate test name once")

Thanks, I just realized I forgot to remove the <limits.h> includes. Should I send another patch for that or send a v2 of this one?

I fixed it up, thanks.