diff mbox series

[bpf-next,1/4] selftests/bpf: test_progs: change formatting of the condenced output

Message ID 20190814164742.208909-2-sdf@google.com
State Changes Requested
Delegated to: BPF Maintainers
Headers show
Series selftests/bpf: test_progs: misc fixes | expand

Commit Message

Stanislav Fomichev Aug. 14, 2019, 4:47 p.m. UTC
This makes it visually simpler to follow the output.
Also, highlight with red color failures when outputting to tty.

Before:
  #1 attach_probe:FAIL
  #2 bpf_obj_id:OK
  #3/1 bpf_verif_scale:loop3.o:OK
  #3/2 bpf_verif_scale:test_verif_scale1.o:OK
  #3/3 bpf_verif_scale:test_verif_scale2.o:OK
  #3/4 bpf_verif_scale:test_verif_scale3.o:OK
  #3/5 bpf_verif_scale:pyperf50.o:OK
  #3/6 bpf_verif_scale:pyperf100.o:OK
  #3/7 bpf_verif_scale:pyperf180.o:OK
  #3/8 bpf_verif_scale:pyperf600.o:OK
  #3/9 bpf_verif_scale:pyperf600_nounroll.o:OK
  #3/10 bpf_verif_scale:loop1.o:OK
  #3/11 bpf_verif_scale:loop2.o:OK
  #3/12 bpf_verif_scale:loop4.o:OK
  #3/13 bpf_verif_scale:loop5.o:OK
  #3/14 bpf_verif_scale:strobemeta.o:OK
  #3/15 bpf_verif_scale:strobemeta_nounroll1.o:OK
  #3/16 bpf_verif_scale:strobemeta_nounroll2.o:OK
  #3/17 bpf_verif_scale:test_sysctl_loop1.o:OK
  #3/18 bpf_verif_scale:test_sysctl_loop2.o:OK
  #3/19 bpf_verif_scale:test_xdp_loop.o:OK
  #3/20 bpf_verif_scale:test_seg6_loop.o:OK
  #3 bpf_verif_scale:OK
  #4 flow_dissector:OK

After:
  #  1     FAIL attach_probe
  #  2       OK bpf_obj_id
  #  3/1     OK bpf_verif_scale:loop3.o
  #  3/2     OK bpf_verif_scale:test_verif_scale1.o
  #  3/3     OK bpf_verif_scale:test_verif_scale2.o
  #  3/4     OK bpf_verif_scale:test_verif_scale3.o
  #  3/5     OK bpf_verif_scale:pyperf50.o
  #  3/6     OK bpf_verif_scale:pyperf100.o
  #  3/7     OK bpf_verif_scale:pyperf180.o
  #  3/8     OK bpf_verif_scale:pyperf600.o
  #  3/9     OK bpf_verif_scale:pyperf600_nounroll.o
  #  3/10    OK bpf_verif_scale:loop1.o
  #  3/11    OK bpf_verif_scale:loop2.o
  #  3/12    OK bpf_verif_scale:loop4.o
  #  3/13    OK bpf_verif_scale:loop5.o
  #  3/14    OK bpf_verif_scale:strobemeta.o
  #  3/15    OK bpf_verif_scale:strobemeta_nounroll1.o
  #  3/16    OK bpf_verif_scale:strobemeta_nounroll2.o
  #  3/17    OK bpf_verif_scale:test_sysctl_loop1.o
  #  3/18    OK bpf_verif_scale:test_sysctl_loop2.o
  #  3/19    OK bpf_verif_scale:test_xdp_loop.o
  #  3/20    OK bpf_verif_scale:test_seg6_loop.o
  #  3       OK bpf_verif_scale
  #  4       OK flow_dissector

Cc: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Stanislav Fomichev <sdf@google.com>
---
 tools/testing/selftests/bpf/test_progs.c | 29 +++++++++++++++++++-----
 1 file changed, 23 insertions(+), 6 deletions(-)

Comments

Alexei Starovoitov Aug. 14, 2019, 5 p.m. UTC | #1
On Wed, Aug 14, 2019 at 9:47 AM Stanislav Fomichev <sdf@google.com> wrote:
>
> This makes it visually simpler to follow the output.
> Also, highlight with red color failures when outputting to tty.
>
> Before:
>   #1 attach_probe:FAIL
>   #2 bpf_obj_id:OK
>   #3/1 bpf_verif_scale:loop3.o:OK
>   #3/2 bpf_verif_scale:test_verif_scale1.o:OK
>   #3/3 bpf_verif_scale:test_verif_scale2.o:OK
>   #3/4 bpf_verif_scale:test_verif_scale3.o:OK
>   #3/5 bpf_verif_scale:pyperf50.o:OK
>   #3/6 bpf_verif_scale:pyperf100.o:OK
>   #3/7 bpf_verif_scale:pyperf180.o:OK
>   #3/8 bpf_verif_scale:pyperf600.o:OK
>   #3/9 bpf_verif_scale:pyperf600_nounroll.o:OK
>   #3/10 bpf_verif_scale:loop1.o:OK
>   #3/11 bpf_verif_scale:loop2.o:OK
>   #3/12 bpf_verif_scale:loop4.o:OK
>   #3/13 bpf_verif_scale:loop5.o:OK
>   #3/14 bpf_verif_scale:strobemeta.o:OK
>   #3/15 bpf_verif_scale:strobemeta_nounroll1.o:OK
>   #3/16 bpf_verif_scale:strobemeta_nounroll2.o:OK
>   #3/17 bpf_verif_scale:test_sysctl_loop1.o:OK
>   #3/18 bpf_verif_scale:test_sysctl_loop2.o:OK
>   #3/19 bpf_verif_scale:test_xdp_loop.o:OK
>   #3/20 bpf_verif_scale:test_seg6_loop.o:OK
>   #3 bpf_verif_scale:OK
>   #4 flow_dissector:OK
>
> After:
>   #  1     FAIL attach_probe
>   #  2       OK bpf_obj_id
>   #  3/1     OK bpf_verif_scale:loop3.o
>   #  3/2     OK bpf_verif_scale:test_verif_scale1.o
>   #  3/3     OK bpf_verif_scale:test_verif_scale2.o
>   #  3/4     OK bpf_verif_scale:test_verif_scale3.o
>   #  3/5     OK bpf_verif_scale:pyperf50.o
>   #  3/6     OK bpf_verif_scale:pyperf100.o
>   #  3/7     OK bpf_verif_scale:pyperf180.o
>   #  3/8     OK bpf_verif_scale:pyperf600.o
>   #  3/9     OK bpf_verif_scale:pyperf600_nounroll.o
>   #  3/10    OK bpf_verif_scale:loop1.o
>   #  3/11    OK bpf_verif_scale:loop2.o
>   #  3/12    OK bpf_verif_scale:loop4.o
>   #  3/13    OK bpf_verif_scale:loop5.o
>   #  3/14    OK bpf_verif_scale:strobemeta.o
>   #  3/15    OK bpf_verif_scale:strobemeta_nounroll1.o
>   #  3/16    OK bpf_verif_scale:strobemeta_nounroll2.o
>   #  3/17    OK bpf_verif_scale:test_sysctl_loop1.o
>   #  3/18    OK bpf_verif_scale:test_sysctl_loop2.o
>   #  3/19    OK bpf_verif_scale:test_xdp_loop.o
>   #  3/20    OK bpf_verif_scale:test_seg6_loop.o
>   #  3       OK bpf_verif_scale
>   #  4       OK flow_dissector

sorry this is nack.
I prefer consistency with test_verifier output.
Stanislav Fomichev Aug. 14, 2019, 5:07 p.m. UTC | #2
On 08/14, Alexei Starovoitov wrote:
> On Wed, Aug 14, 2019 at 9:47 AM Stanislav Fomichev <sdf@google.com> wrote:
> >
> > This makes it visually simpler to follow the output.
> > Also, highlight with red color failures when outputting to tty.
> >
> > Before:
> >   #1 attach_probe:FAIL
> >   #2 bpf_obj_id:OK
> >   #3/1 bpf_verif_scale:loop3.o:OK
> >   #3/2 bpf_verif_scale:test_verif_scale1.o:OK
> >   #3/3 bpf_verif_scale:test_verif_scale2.o:OK
> >   #3/4 bpf_verif_scale:test_verif_scale3.o:OK
> >   #3/5 bpf_verif_scale:pyperf50.o:OK
> >   #3/6 bpf_verif_scale:pyperf100.o:OK
> >   #3/7 bpf_verif_scale:pyperf180.o:OK
> >   #3/8 bpf_verif_scale:pyperf600.o:OK
> >   #3/9 bpf_verif_scale:pyperf600_nounroll.o:OK
> >   #3/10 bpf_verif_scale:loop1.o:OK
> >   #3/11 bpf_verif_scale:loop2.o:OK
> >   #3/12 bpf_verif_scale:loop4.o:OK
> >   #3/13 bpf_verif_scale:loop5.o:OK
> >   #3/14 bpf_verif_scale:strobemeta.o:OK
> >   #3/15 bpf_verif_scale:strobemeta_nounroll1.o:OK
> >   #3/16 bpf_verif_scale:strobemeta_nounroll2.o:OK
> >   #3/17 bpf_verif_scale:test_sysctl_loop1.o:OK
> >   #3/18 bpf_verif_scale:test_sysctl_loop2.o:OK
> >   #3/19 bpf_verif_scale:test_xdp_loop.o:OK
> >   #3/20 bpf_verif_scale:test_seg6_loop.o:OK
> >   #3 bpf_verif_scale:OK
> >   #4 flow_dissector:OK
> >
> > After:
> >   #  1     FAIL attach_probe
> >   #  2       OK bpf_obj_id
> >   #  3/1     OK bpf_verif_scale:loop3.o
> >   #  3/2     OK bpf_verif_scale:test_verif_scale1.o
> >   #  3/3     OK bpf_verif_scale:test_verif_scale2.o
> >   #  3/4     OK bpf_verif_scale:test_verif_scale3.o
> >   #  3/5     OK bpf_verif_scale:pyperf50.o
> >   #  3/6     OK bpf_verif_scale:pyperf100.o
> >   #  3/7     OK bpf_verif_scale:pyperf180.o
> >   #  3/8     OK bpf_verif_scale:pyperf600.o
> >   #  3/9     OK bpf_verif_scale:pyperf600_nounroll.o
> >   #  3/10    OK bpf_verif_scale:loop1.o
> >   #  3/11    OK bpf_verif_scale:loop2.o
> >   #  3/12    OK bpf_verif_scale:loop4.o
> >   #  3/13    OK bpf_verif_scale:loop5.o
> >   #  3/14    OK bpf_verif_scale:strobemeta.o
> >   #  3/15    OK bpf_verif_scale:strobemeta_nounroll1.o
> >   #  3/16    OK bpf_verif_scale:strobemeta_nounroll2.o
> >   #  3/17    OK bpf_verif_scale:test_sysctl_loop1.o
> >   #  3/18    OK bpf_verif_scale:test_sysctl_loop2.o
> >   #  3/19    OK bpf_verif_scale:test_xdp_loop.o
> >   #  3/20    OK bpf_verif_scale:test_seg6_loop.o
> >   #  3       OK bpf_verif_scale
> >   #  4       OK flow_dissector
> 
> sorry this is nack.
> I prefer consistency with test_verifier output.
No problem, let me know how you feel about the other patches
in the series, can drop this one.
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/test_progs.c b/tools/testing/selftests/bpf/test_progs.c
index 12895d03d58b..1a7a2a0c0a11 100644
--- a/tools/testing/selftests/bpf/test_progs.c
+++ b/tools/testing/selftests/bpf/test_progs.c
@@ -56,6 +56,21 @@  static void dump_test_log(const struct prog_test_def *test, bool failed)
 	fseeko(stdout, 0, SEEK_SET); /* rewind */
 }
 
+static const char *test_status_string(bool success)
+{
+#define COLOR_RED	"\033[31m"
+#define COLOR_RESET	"\033[m"
+	if (success)
+		return "OK";
+
+	if (isatty(fileno(env.stdout)))
+		return COLOR_RED "FAIL" COLOR_RESET;
+	else
+		return "FAIL";
+#undef COLOR_RED
+#undef COLOR_RESET
+}
+
 void test__end_subtest()
 {
 	struct prog_test_def *test = env.test;
@@ -68,9 +83,10 @@  void test__end_subtest()
 
 	dump_test_log(test, sub_error_cnt);
 
-	fprintf(env.stdout, "#%d/%d %s:%s\n",
-	       test->test_num, test->subtest_num,
-	       test->subtest_name, sub_error_cnt ? "FAIL" : "OK");
+	fprintf(env.stdout, "#%3d/%-3d %4s %s:%s\n",
+		test->test_num, test->subtest_num,
+		test_status_string(test->fail_cnt == 0),
+		test->test_name, test->subtest_name);
 }
 
 bool test__start_subtest(const char *name)
@@ -513,9 +529,10 @@  int main(int argc, char **argv)
 
 		dump_test_log(test, test->error_cnt);
 
-		fprintf(env.stdout, "#%d %s:%s\n",
-			test->test_num, test->test_name,
-			test->error_cnt ? "FAIL" : "OK");
+		fprintf(env.stdout, "#%3d     %4s %s\n",
+			test->test_num,
+			test_status_string(test->fail_cnt == 0),
+			test->test_name);
 	}
 	stdio_restore();
 	printf("Summary: %d/%d PASSED, %d FAILED\n",