@@ -21,6 +21,53 @@ static int kflag; /* run kprobe tests */
21
21
22
22
#define msleep (_x ) usleep((uint64_t)_x * 1000ULL)
23
23
24
+ enum {
25
+ SANE ,
26
+ RED ,
27
+ GREEN
28
+ };
29
+
30
+ static int
31
+ fancy_tty (void )
32
+ {
33
+ char * term = getenv ("TERM" );
34
+
35
+ if (term == NULL || !strcmp (term , "dumb" ))
36
+ return (0 );
37
+
38
+ return (isatty (STDOUT_FILENO ) == 1 );
39
+ }
40
+
41
+ static int
42
+ color (int color )
43
+ {
44
+ static int old ;
45
+ int ret ;
46
+
47
+ if (!fancy_tty ())
48
+ return (SANE );
49
+
50
+ ret = old ;
51
+
52
+ switch (color ) {
53
+ case SANE :
54
+ printf ("\033[0m" );
55
+ break ;
56
+ case RED :
57
+ printf ("\033[31m" );
58
+ break ;
59
+ case GREEN :
60
+ printf ("\033[32m" );
61
+ break ;
62
+ default :
63
+ errx (1 , "bad color %d" , color );
64
+ }
65
+
66
+ old = color ;
67
+
68
+ return (ret );
69
+ }
70
+
24
71
static char *
25
72
binpath (void )
26
73
{
@@ -53,6 +100,10 @@ static void
53
100
spin (void )
54
101
{
55
102
static int ch ;
103
+
104
+ if (!fancy_tty ())
105
+ return ;
106
+
56
107
/* -\|/ */
57
108
switch (ch ) {
58
109
case 0 : /* FALLTHROUGH */
@@ -458,7 +509,7 @@ static int
458
509
run_test (const struct test * t , struct quark_queue_attr * qa )
459
510
{
460
511
pid_t child ;
461
- int status ;
512
+ int status , x , linepos ;
462
513
const char * be ;
463
514
int child_stderr [2 ];
464
515
FILE * child_stream ;
@@ -476,7 +527,9 @@ run_test(const struct test *t, struct quark_queue_attr *qa)
476
527
else
477
528
errx (1 , "bad backend" );
478
529
479
- printf ("%s @ %s: " , t -> name , be );
530
+ linepos = printf ("%s @ %s" , t -> name , be );
531
+ while (++ linepos < 30 )
532
+ putchar ('.' );
480
533
fflush (stdout );
481
534
482
535
/*
@@ -560,10 +613,15 @@ run_test(const struct test *t, struct quark_queue_attr *qa)
560
613
if (waitpid (child , & status , 0 ) == -1 )
561
614
err (1 , "waitpid" );
562
615
563
- if (WIFEXITED (status ) && WEXITSTATUS (status ) == 0 )
616
+ if (WIFEXITED (status ) && WEXITSTATUS (status ) == 0 ) {
617
+ x = color (GREEN );
564
618
printf ("ok\n" );
565
- else
619
+ color (x );
620
+ } else {
621
+ x = color (RED );
566
622
printf ("failed\n" );
623
+ color (x );
624
+ }
567
625
fflush (stdout );
568
626
569
627
/*
@@ -632,7 +690,7 @@ run_tests(int argc, char *argv[])
632
690
int
633
691
main (int argc , char * argv [])
634
692
{
635
- int ch , failed ;
693
+ int ch , x , failed ;
636
694
637
695
while ((ch = getopt (argc , argv , "bklNvV" )) != -1 ) {
638
696
switch (ch ) {
@@ -667,7 +725,9 @@ main(int argc, char *argv[])
667
725
668
726
failed = run_tests (argc , argv );
669
727
670
- printf ("failed tests %d\n" , failed );
728
+ x = failed == 0 ? color (GREEN ) : color (RED );
729
+ printf ("%d failures\n" , failed );
730
+ color (x );
671
731
672
732
return (failed );
673
733
}
0 commit comments