00001
00011 #include <stdio.h>
00012 #include <stdlib.h>
00013 #include <string.h>
00014
00015 #include "op_libiberty.h"
00016 #include "op_mangle.h"
00017 #include "op_config.h"
00018
00019 struct test_input {
00020 struct mangle_values values;
00021 char const * result;
00022 };
00023
00024 static struct test_input const tests[] = {
00025 { { MANGLE_NONE, "foo", "", "bar", NULL, "EVENT", 0, 0, 0, 0, 0 },
00026 "{root}/bar/{dep}/{root}/foo/EVENT.0.0.all.all.all" },
00027 { { MANGLE_CPU, "foo", "", "bar", NULL, "EVENT", 0, 0, 0, 0, 2 },
00028 "{root}/bar/{dep}/{root}/foo/EVENT.0.0.all.all.2" },
00029 { { MANGLE_TID, "foo", "", "bar", NULL, "EVENT", 0, 0, 0, 33, 0 },
00030 "{root}/bar/{dep}/{root}/foo/EVENT.0.0.all.33.all" },
00031 { { MANGLE_TGID, "foo", "", "bar", NULL, "EVENT", 0, 0, 34, 0, 0 },
00032 "{root}/bar/{dep}/{root}/foo/EVENT.0.0.34.all.all" },
00033 { { MANGLE_KERNEL, "foo", "", "bar", NULL, "EVENT", 0, 0, 0, 0, 0 },
00034 "{kern}/bar/{dep}/{kern}/foo/EVENT.0.0.all.all.all" },
00035 { { MANGLE_CALLGRAPH, "foo-from", "", "bar-from", "foo-to", "EVENT", 0, 0, 0, 0, 0 },
00036 "{root}/bar-from/{dep}/{root}/foo-from/{cg}/{root}/foo-to/EVENT.0.0.all.all.all" },
00037 { { MANGLE_CPU|MANGLE_TID|MANGLE_TID|MANGLE_TGID|MANGLE_KERNEL, "foo", "", "bar", NULL, "EVENT", 1234, 8192, 34, 35, 2 },
00038 "{kern}/bar/{dep}/{kern}/foo/EVENT.1234.8192.34.35.2" },
00039 { { MANGLE_CPU|MANGLE_TID|MANGLE_TID|MANGLE_TGID|MANGLE_KERNEL, "foo1/foo2", "", "bar1/bar2", NULL, "EVENT", 1234, 8192, 34, 35, 2 },
00040 "{root}/bar1/bar2/{dep}/{root}/foo1/foo2/EVENT.1234.8192.34.35.2" },
00041 { { 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 },
00042 "{root}/bar1/bar2/{dep}/{root}/bar1/bar2/{cg}/{root}/bar1/bar2-to/EVENT.1234.8192.34.35.2" },
00043
00044 { { 0, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0 }, NULL }
00045 };
00046
00047
00048 int main(void)
00049 {
00050 struct test_input const * test;
00051 for (test = tests; test->result; ++test) {
00052 char * result = op_mangle_filename(&test->values);
00053 char * expect = xmalloc(strlen(test->result) +
00054 strlen(op_samples_current_dir) + 1);
00055 strcpy(expect, op_samples_current_dir);
00056 strcat(expect, test->result);
00057 if (strcmp(result, expect)) {
00058 fprintf(stderr, "test %d:\nfound: %s\nexpect: %s\n",
00059 (int)(test - tests), result, expect);
00060 exit(EXIT_FAILURE);
00061 }
00062 free(expect);
00063 free(result);
00064 }
00065
00066 return EXIT_SUCCESS;
00067 }