Home | History | Annotate | Download | only in tests
      1 /**
      2  * @file mangle_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 <stdio.h>
     12 #include <stdlib.h>
     13 #include <string.h>
     14 
     15 #include "op_libiberty.h"
     16 #include "op_mangle.h"
     17 #include "op_config.h"
     18 
     19 struct test_input {
     20 	struct mangle_values values;
     21 	char const * result;
     22 };
     23 
     24 static struct test_input const tests[] = {
     25 	{ { MANGLE_NONE, "foo", "", "bar", NULL, "EVENT", 0, 0, 0, 0, 0 },
     26 	  "{root}/bar/{dep}/{root}/foo/EVENT.0.0.all.all.all" },
     27 	{ { MANGLE_CPU, "foo", "", "bar", NULL, "EVENT", 0, 0, 0, 0, 2 },
     28 	  "{root}/bar/{dep}/{root}/foo/EVENT.0.0.all.all.2" },
     29 	{ { MANGLE_TID, "foo", "", "bar", NULL, "EVENT", 0, 0, 0, 33, 0 },
     30 	  "{root}/bar/{dep}/{root}/foo/EVENT.0.0.all.33.all" },
     31 	{ { MANGLE_TGID, "foo", "", "bar", NULL, "EVENT", 0, 0, 34, 0, 0 },
     32 	  "{root}/bar/{dep}/{root}/foo/EVENT.0.0.34.all.all" },
     33 	{ { MANGLE_KERNEL, "foo", "", "bar", NULL, "EVENT", 0, 0, 0, 0, 0 },
     34 	  "{kern}/bar/{dep}/{kern}/foo/EVENT.0.0.all.all.all" },
     35 	{ { MANGLE_CALLGRAPH, "foo-from", "", "bar-from", "foo-to", "EVENT", 0, 0, 0, 0, 0 },
     36 	  "{root}/bar-from/{dep}/{root}/foo-from/{cg}/{root}/foo-to/EVENT.0.0.all.all.all" },
     37 	{ { MANGLE_CPU|MANGLE_TID|MANGLE_TID|MANGLE_TGID|MANGLE_KERNEL, "foo", "", "bar", NULL, "EVENT", 1234, 8192, 34, 35, 2 },
     38 	  "{kern}/bar/{dep}/{kern}/foo/EVENT.1234.8192.34.35.2" },
     39 	{ { MANGLE_CPU|MANGLE_TID|MANGLE_TID|MANGLE_TGID|MANGLE_KERNEL, "foo1/foo2", "", "bar1/bar2", NULL, "EVENT", 1234, 8192, 34, 35, 2 },
     40 	  "{root}/bar1/bar2/{dep}/{root}/foo1/foo2/EVENT.1234.8192.34.35.2" },
     41 	{ { MANGLE_CALLGRAPH|MANGLE_CPU|MANGLE_TID|MANGLE_TID|MANGLE_TGID|MANGLE_KERNEL, "bar1/bar2", "", "bar1/bar2", "bar1/bar2-to", "EVENT", 1234, 8192, 34, 35, 2 },
     42 	  "{root}/bar1/bar2/{dep}/{root}/bar1/bar2/{cg}/{root}/bar1/bar2-to/EVENT.1234.8192.34.35.2" },
     43 
     44 	{ { 0, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0 }, NULL }
     45 };
     46 
     47 
     48 int main(void)
     49 {
     50 	struct test_input const * test;
     51 	for (test = tests; test->result; ++test) {
     52 		char * result = op_mangle_filename(&test->values);
     53 		char * expect = xmalloc(strlen(test->result) +
     54 					strlen(op_samples_current_dir) + 1);
     55 		strcpy(expect, op_samples_current_dir);
     56 		strcat(expect, test->result);
     57 		if (strcmp(result, expect)) {
     58 			fprintf(stderr, "test %d:\nfound: %s\nexpect: %s\n",
     59 				(int)(test - tests), result, expect);
     60 			exit(EXIT_FAILURE);
     61 		}
     62 		free(expect);
     63 		free(result);
     64 	}
     65 
     66 	return EXIT_SUCCESS;
     67 }
     68