netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next 1/2] selftests/bpf: test_progs: fix verbose mode garbage
@ 2019-08-31  2:34 Stanislav Fomichev
  2019-08-31  2:34 ` [PATCH bpf-next 2/2] selftests/bpf: test_progs: add missing \n to CHECK_FAIL Stanislav Fomichev
  2019-09-03 13:40 ` [PATCH bpf-next 1/2] selftests/bpf: test_progs: fix verbose mode garbage Daniel Borkmann
  0 siblings, 2 replies; 3+ messages in thread
From: Stanislav Fomichev @ 2019-08-31  2:34 UTC (permalink / raw)
  To: netdev, bpf; +Cc: davem, ast, daniel, 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);

Output:

	buf=aaa, len=3
	buf=baa, len=1

Fixes: 946152b3c5d6 ("selftests/bpf: test_progs: switch to open_memstream")
Signed-off-by: Stanislav Fomichev <sdf@google.com>
---
 tools/testing/selftests/bpf/test_progs.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/testing/selftests/bpf/test_progs.c b/tools/testing/selftests/bpf/test_progs.c
index e5892cb60eca..e8616e778cb5 100644
--- a/tools/testing/selftests/bpf/test_progs.c
+++ b/tools/testing/selftests/bpf/test_progs.c
@@ -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");
-- 
2.23.0.187.g17f5b7556c-goog


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

* [PATCH bpf-next 2/2] selftests/bpf: test_progs: add missing \n to CHECK_FAIL
  2019-08-31  2:34 [PATCH bpf-next 1/2] selftests/bpf: test_progs: fix verbose mode garbage Stanislav Fomichev
@ 2019-08-31  2:34 ` Stanislav Fomichev
  2019-09-03 13:40 ` [PATCH bpf-next 1/2] selftests/bpf: test_progs: fix verbose mode garbage Daniel Borkmann
  1 sibling, 0 replies; 3+ messages in thread
From: Stanislav Fomichev @ 2019-08-31  2:34 UTC (permalink / raw)
  To: netdev, bpf; +Cc: davem, ast, daniel, Stanislav Fomichev

Copy-paste error from CHECK.

Fixes: d38835b75f67 ("selftests/bpf: test_progs: remove global fail/success counts")
Signed-off-by: Stanislav Fomichev <sdf@google.com>
---
 tools/testing/selftests/bpf/test_progs.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/bpf/test_progs.h b/tools/testing/selftests/bpf/test_progs.h
index 33da849cb765..c8edb9464ba6 100644
--- a/tools/testing/selftests/bpf/test_progs.h
+++ b/tools/testing/selftests/bpf/test_progs.h
@@ -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;								\
 })
-- 
2.23.0.187.g17f5b7556c-goog


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

* Re: [PATCH bpf-next 1/2] selftests/bpf: test_progs: fix verbose mode garbage
  2019-08-31  2:34 [PATCH bpf-next 1/2] selftests/bpf: test_progs: fix verbose mode garbage Stanislav Fomichev
  2019-08-31  2:34 ` [PATCH bpf-next 2/2] selftests/bpf: test_progs: add missing \n to CHECK_FAIL Stanislav Fomichev
@ 2019-09-03 13:40 ` Daniel Borkmann
  1 sibling, 0 replies; 3+ messages in thread
From: Daniel Borkmann @ 2019-09-03 13:40 UTC (permalink / raw)
  To: Stanislav Fomichev, netdev, bpf; +Cc: davem, ast

On 8/31/19 4:34 AM, Stanislav Fomichev wrote:
> 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
> 
> Fixes: 946152b3c5d6 ("selftests/bpf: test_progs: switch to open_memstream")
> Signed-off-by: Stanislav Fomichev <sdf@google.com>

Both applied, thanks!

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

end of thread, other threads:[~2019-09-03 13:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-31  2:34 [PATCH bpf-next 1/2] selftests/bpf: test_progs: fix verbose mode garbage Stanislav Fomichev
2019-08-31  2:34 ` [PATCH bpf-next 2/2] selftests/bpf: test_progs: add missing \n to CHECK_FAIL Stanislav Fomichev
2019-09-03 13:40 ` [PATCH bpf-next 1/2] selftests/bpf: test_progs: fix verbose mode garbage Daniel Borkmann

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).