11 #define CLR_RESET "\033[m"
12 #define CLR_BOLD "\033[1m"
13 #define CLR_RED "\033[31m"
14 #define CLR_GREEN "\033[32m"
15 #define CLR_BROWN "\033[33m"
16 #define CLR_YELLOW "\033[33m\033[1m"
17 #define CLR_BLUE "\033[34m"
18 #define CLR_MAGENTA "\033[35m"
19 #define CLR_CYAN "\033[36m"
20 #define CLR_BG_RED "\033[41m"
22 static struct lparse_test
{
27 { "logs/nuls.log", 20002, 8, 2 },
28 { "logs/no-lf-terminator.log", 1, 0, 1 },
29 { "logs/beta.log", 6114, 0, 2 },
33 static struct lparse_test
*t
;
35 void sighandler(int signum
)
37 if (signum
== SIGALRM
) {
38 fprintf(stderr
, "Failed to complete parsing %s in under %d seconds\n",
39 t
->path
, t
->max_runtime
);
44 static int lines
, empty
;
45 static unsigned long long bytes
= 0;
46 static int check_line(char *str
, uint len
)
56 #define print_expected(a, b, what) \
57 printf("# expected %llu " what ", got %llu. delta %d\n", \
58 (unsigned long long)a, (unsigned long long)b, (int)(a - b));
60 int main(int argc
, char **argv
)
62 int i
, passed
= 0, failed
= 0, use_alarm
= 1;
63 const char *green
, *cyan
, *red
, *yellow
, *reset
;
65 if (isatty(fileno(stdout
))) {
72 green
= red
= yellow
= cyan
= reset
= "";
75 signal(SIGALRM
, sighandler
);
77 for (i
= 1; i
< argc
; i
++) {
78 if (!strcmp(argv
[i
], "--no-alarm"))
82 for (i
= 0; testfiles
[i
].path
; i
++) {
87 if (stat(testfiles
[i
].path
, &st
) < 0) {
88 fprintf(stderr
, "Failed to stat '%s': %s\n", t
->path
, strerror(errno
));
92 if (use_alarm
&& t
->max_runtime
)
93 alarm(t
->max_runtime
);
94 lparse_path(t
->path
, st
.st_size
, check_line
);
95 if (use_alarm
&& t
->max_runtime
)
98 if (lines
== t
->lines
&& t
->empty
== empty
&& bytes
== st
.st_size
) {
100 printf("%sPASS%s %s\n", green
, reset
, t
->path
);
102 if (lines
== t
->lines
)
103 printf("%spass%s %s\n", yellow
, reset
, t
->path
);
106 printf("%sFAIL%s %s\n", red
, reset
, t
->path
);
108 if (lines
!= t
->lines
)
109 print_expected(t
->lines
, lines
, "lines");
110 if (empty
!= t
->empty
)
111 print_expected(t
->empty
, empty
, "empty lines");
112 if (st
.st_size
!= bytes
)
113 print_expected(st
.st_size
, bytes
, "bytes");
116 lines
= bytes
= empty
= 0;