parse_event_tests.c

Go to the documentation of this file.
00001 
00011 #include <stdlib.h>
00012 #include <stdio.h>
00013 #include <string.h>
00014 
00015 #include "op_parse_event.h"
00016 
00017 struct events_test {
00018     /* second pointer is the null terminating array marker */
00019     char const * const tests[2];
00020     struct parsed_event expected;
00021 };
00022 
00023 static struct events_test const events[] = 
00024 {
00025     { { "FOO:3000:0:0:0", 0 },    { "FOO", 3000, 0, NULL, 0, 0, 0 } },
00026     { { "BAR:3000", 0 },          { "BAR", 3000, 0, NULL, 1, 1, 0 } },
00027     { { "FOOBAR:3000:1:1:1", 0 }, { "FOOBAR", 3000, 1, NULL, 1, 1, 0 } },
00028     { { NULL, NULL },             { 0, 0, 0, NULL, 0, 0, 0 } }
00029 };
00030 
00031 static void do_test(struct events_test const * ev)
00032 {
00033     struct parsed_event parsed;
00034 
00035     parse_events(&parsed, 1, ev->tests);
00036 
00037     if (strcmp(ev->expected.name, parsed.name) ||
00038         ev->expected.count != parsed.count ||
00039         ev->expected.unit_mask != parsed.unit_mask ||
00040         ev->expected.kernel != parsed.kernel ||
00041         ev->expected.user != parsed.user) {
00042         printf("for %s expect { %s, %d, %d, %d, %d } found "
00043                "{ %s, %d, %d, %d, %d }\n",
00044                        ev->tests[0], ev->expected.name, ev->expected.count,
00045                        ev->expected.unit_mask, ev->expected.kernel,
00046                        ev->expected.user, parsed.name, parsed.count,
00047                        parsed.unit_mask, parsed.kernel, parsed.user);
00048         exit(EXIT_FAILURE);
00049     }
00050 }
00051 
00052 int main(void)
00053 {
00054     struct events_test const * ev;
00055     for (ev = events; ev->tests[0]; ++ev)
00056         do_test(ev);
00057 
00058     return 0;
00059 }

Generated on 8 Nov 2012 for Oprofile by  doxygen 1.6.1