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