1 #include "parse-events.h"
6 /* Simulated format definitions. */
7 static struct test_format
{
11 { "krava01", "config:0-1,62-63\n", },
12 { "krava02", "config:10-17\n", },
13 { "krava03", "config:5\n", },
14 { "krava11", "config1:0,2,4,6,8,20-28\n", },
15 { "krava12", "config1:63\n", },
16 { "krava13", "config1:45-47\n", },
17 { "krava21", "config2:0-3,10-13,20-23,30-33,40-43,50-53,60-63\n", },
18 { "krava22", "config2:8,18,48,58\n", },
19 { "krava23", "config2:28-29,38\n", },
22 /* Simulated users input. */
23 static struct parse_events_term test_terms
[] = {
25 .config
= (char *) "krava01",
27 .type_val
= PARSE_EVENTS__TERM_TYPE_NUM
,
28 .type_term
= PARSE_EVENTS__TERM_TYPE_USER
,
31 .config
= (char *) "krava02",
33 .type_val
= PARSE_EVENTS__TERM_TYPE_NUM
,
34 .type_term
= PARSE_EVENTS__TERM_TYPE_USER
,
37 .config
= (char *) "krava03",
39 .type_val
= PARSE_EVENTS__TERM_TYPE_NUM
,
40 .type_term
= PARSE_EVENTS__TERM_TYPE_USER
,
43 .config
= (char *) "krava11",
45 .type_val
= PARSE_EVENTS__TERM_TYPE_NUM
,
46 .type_term
= PARSE_EVENTS__TERM_TYPE_USER
,
49 .config
= (char *) "krava12",
51 .type_val
= PARSE_EVENTS__TERM_TYPE_NUM
,
52 .type_term
= PARSE_EVENTS__TERM_TYPE_USER
,
55 .config
= (char *) "krava13",
57 .type_val
= PARSE_EVENTS__TERM_TYPE_NUM
,
58 .type_term
= PARSE_EVENTS__TERM_TYPE_USER
,
61 .config
= (char *) "krava21",
63 .type_val
= PARSE_EVENTS__TERM_TYPE_NUM
,
64 .type_term
= PARSE_EVENTS__TERM_TYPE_USER
,
67 .config
= (char *) "krava22",
69 .type_val
= PARSE_EVENTS__TERM_TYPE_NUM
,
70 .type_term
= PARSE_EVENTS__TERM_TYPE_USER
,
73 .config
= (char *) "krava23",
75 .type_val
= PARSE_EVENTS__TERM_TYPE_NUM
,
76 .type_term
= PARSE_EVENTS__TERM_TYPE_USER
,
81 * Prepare format directory data, exported by kernel
82 * at /sys/bus/event_source/devices/<dev>/format.
84 static char *test_format_dir_get(void)
86 static char dir
[PATH_MAX
];
89 snprintf(dir
, PATH_MAX
, "/tmp/perf-pmu-test-format-XXXXXX");
93 for (i
= 0; i
< ARRAY_SIZE(test_formats
); i
++) {
94 static char name
[PATH_MAX
];
95 struct test_format
*format
= &test_formats
[i
];
98 snprintf(name
, PATH_MAX
, "%s/%s", dir
, format
->name
);
100 file
= fopen(name
, "w");
104 if (1 != fwrite(format
->value
, strlen(format
->value
), 1, file
))
113 /* Cleanup format directory. */
114 static int test_format_dir_put(char *dir
)
117 snprintf(buf
, PATH_MAX
, "rm -f %s/*\n", dir
);
121 snprintf(buf
, PATH_MAX
, "rmdir %s\n", dir
);
125 static struct list_head
*test_terms_list(void)
127 static LIST_HEAD(terms
);
130 for (i
= 0; i
< ARRAY_SIZE(test_terms
); i
++)
131 list_add_tail(&test_terms
[i
].list
, &terms
);
138 char *format
= test_format_dir_get();
140 struct list_head
*terms
= test_terms_list();
147 struct perf_event_attr attr
;
149 memset(&attr
, 0, sizeof(attr
));
151 ret
= perf_pmu__format_parse(format
, &formats
);
155 ret
= perf_pmu__config_terms(&formats
, &attr
, terms
, false);
161 if (attr
.config
!= 0xc00000000002a823)
163 if (attr
.config1
!= 0x8000400000000145)
165 if (attr
.config2
!= 0x0400000020041d07)
171 test_format_dir_put(format
);