selftests/bpf: test_progs: fix verbose mode garbage
Subsystems (5)
PATCH 1/2 selftests/bpf: test_progs: fix verbose mode garbage
fseeko(.., 0, SEEK_SET) on a memstream just puts the buffer pointer to the beginning so when we call fflush on it we get some garbage log data from the previous test. Let's manually set terminating byte to zero at the reported buffer size.
To show the issue consider the following snippet:
stream = open_memstream (&buf, &len);
fprintf(stream, "aaa");
fflush(stream);
printf("buf=%s, len=%zu\n", buf, len);
fseeko(stream, 0, SEEK_SET);
fprintf(stream, "b");
fflush(stream);
printf("buf=%s, len=%zu\n", buf, len);Output:
buf=aaa, len=3 buf=baa, len=1
--- tools/testing/selftests/bpf/test_progs.c | 1 + 1 file changed, 1 insertion(+)
tools/testing/selftests/bpf/test_progs.c +1 -0
@@ -45,6 +45,7 @@ static void dump_test_log(const struct prog_test_def *test, bool failed)if (env.verbose || test->force_log || failed) {if (env.log_cnt) { + env.log_buf[env.log_cnt] ='\0' ;fprintf (env.stdout,"%s" , env.log_buf);if (env.log_buf[env.log_cnt -1 ] !='\n' )fprintf (env.stdout,"\n" );
Signature · 1 line
2.23.0.187.g17f5b7556c-goog
PATCH 2/2 selftests/bpf: test_progs: add missing \n to CHECK_FAIL
Copy-paste error from CHECK.
--- tools/testing/selftests/bpf/test_progs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/test_progs.h +1 -1
@@ -107,7 +107,7 @@ extern struct ipv6_packet pkt_v6;int __ret = !!(condition); \if (__ret) { \test__fail (); \ -printf ("%s:FAIL:%d " , __func__, __LINE__); \ +printf ("%s:FAIL:%d\n" , __func__, __LINE__); \ } \ __ret; \ })
Signature · 1 line
2.23.0.187.g17f5b7556c-goog
Daniel Borkmann
maintainerQuoted 18 lines · Stanislav Fomichev
fseeko(.., 0, SEEK_SET)on a memstream just puts the buffer pointer to the beginning so when we call fflush on it we get some garbage log data from the previous test. Let's manually set terminating byte to zero at the reported buffer size.To show the issue consider the following snippet:
stream = open_memstream (&buf, &len); fprintf(stream, "aaa"); fflush(stream); printf("buf=%s, len=%zu\n", buf, len); fseeko(stream, 0, SEEK_SET); fprintf(stream, "b"); fflush(stream); printf("buf=%s, len=%zu\n", buf, len);
Quoted 7 lines
Output:
buf=aaa, len=3 buf=baa, len=1Fixes 946152b3c5d6 ("selftests/bpf: test_progs: switch to open_memstream")Signed-off-by Stanislav Fomichev <[email protected]>
Both applied, thanks!