Home | History | Annotate | Download | only in tests
      1 /**
      2  * @file parse_event_tests.c
      3  *
      4  * @remark Copyright 2003 OProfile authors
      5  * @remark Read the file COPYING
      6  *
      7  * @author John Levon
      8  * @author Philippe Elie
      9  */
     10 
     11 #include <stdlib.h>
     12 #include <stdio.h>
     13 #include <string.h>
     14 
     15 #include "op_parse_event.h"
     16 
     17 struct events_test {
     18 	/* second pointer is the null terminating array marker */
     19 	char const * const tests[2];
     20 	struct parsed_event expected;
     21 };
     22 
     23 static struct events_test const events[] =
     24 {
     25 	{ { "FOO:3000:0:0:0", 0 },    { "FOO", 3000, 0, 0, 0, 0 } },
     26 	{ { "BAR:3000", 0 },          { "BAR", 3000, 0, 1, 1, 0 } },
     27 	{ { "FOOBAR:3000:1:1:1", 0 }, { "FOOBAR", 3000, 1, 1, 1, 0 } },
     28 	{ { NULL, NULL },             { 0, 0, 0, 0, 0, 0 } }
     29 };
     30 
     31 static void do_test(struct events_test const * ev)
     32 {
     33 	struct parsed_event parsed;
     34 
     35 	parse_events(&parsed, 1, ev->tests);
     36 
     37 	if (strcmp(ev->expected.name, parsed.name) ||
     38 	    ev->expected.count != parsed.count ||
     39 	    ev->expected.unit_mask != parsed.unit_mask ||
     40 	    ev->expected.kernel != parsed.kernel ||
     41 	    ev->expected.user != parsed.user) {
     42 		printf("for %s expect { %s, %d, %d, %d, %d } found "
     43 		       "{ %s, %d, %d, %d, %d }\n",
     44                        ev->tests[0], ev->expected.name, ev->expected.count,
     45                        ev->expected.unit_mask, ev->expected.kernel,
     46                        ev->expected.user, parsed.name, parsed.count,
     47                        parsed.unit_mask, parsed.kernel, parsed.user);
     48 		exit(EXIT_FAILURE);
     49 	}
     50 }
     51 
     52 int main(void)
     53 {
     54 	struct events_test const * ev;
     55 	for (ev = events; ev->tests[0]; ++ev)
     56 		do_test(ev);
     57 
     58 	return 0;
     59 }
     60