Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[0d0e60]: libop / tests / mangle_tests.c Maximize Restore History

Download this file

mangle_tests.c    68 lines (59 with data), 2.4 kB

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