xref: /openbmc/linux/tools/perf/tests/mem.c (revision 4cff79e9)
1 #include "util/mem-events.h"
2 #include "util/symbol.h"
3 #include "linux/perf_event.h"
4 #include "util/debug.h"
5 #include "tests.h"
6 #include <string.h>
7 
8 static int check(union perf_mem_data_src data_src,
9 		  const char *string)
10 {
11 	char out[100];
12 	char failure[100];
13 	struct mem_info mi = { .data_src = data_src };
14 
15 	int n;
16 
17 	n = perf_mem__snp_scnprintf(out, sizeof out, &mi);
18 	n += perf_mem__lvl_scnprintf(out + n, sizeof out - n, &mi);
19 	scnprintf(failure, sizeof failure, "unexpected %s", out);
20 	TEST_ASSERT_VAL(failure, !strcmp(string, out));
21 	return 0;
22 }
23 
24 int test__mem(struct test *text __maybe_unused, int subtest __maybe_unused)
25 {
26 	int ret = 0;
27 	union perf_mem_data_src src;
28 
29 	memset(&src, 0, sizeof(src));
30 
31 	src.mem_lvl = PERF_MEM_LVL_HIT;
32 	src.mem_lvl_num = 4;
33 
34 	ret |= check(src, "N/AL4 hit");
35 
36 	src.mem_remote = 1;
37 
38 	ret |= check(src, "N/ARemote L4 hit");
39 
40 	src.mem_lvl = PERF_MEM_LVL_MISS;
41 	src.mem_lvl_num = PERF_MEM_LVLNUM_PMEM;
42 	src.mem_remote = 0;
43 
44 	ret |= check(src, "N/APMEM miss");
45 
46 	src.mem_remote = 1;
47 
48 	ret |= check(src, "N/ARemote PMEM miss");
49 
50 	src.mem_snoopx = PERF_MEM_SNOOPX_FWD;
51 	src.mem_lvl_num = PERF_MEM_LVLNUM_RAM;
52 
53 	ret |= check(src , "FwdRemote RAM miss");
54 
55 	return ret;
56 }
57