Merge tag 'block-5.9-2020-08-14' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / tools / perf / tests / mem.c
blob673a11a6cd1b14bb84003c9a05b674fe9c147575
1 // SPDX-License-Identifier: GPL-2.0
2 #include "util/map_symbol.h"
3 #include "util/mem-events.h"
4 #include "util/symbol.h"
5 #include "linux/perf_event.h"
6 #include "util/debug.h"
7 #include "tests.h"
8 #include <string.h>
10 static int check(union perf_mem_data_src data_src,
11 const char *string)
13 char out[100];
14 char failure[100];
15 struct mem_info mi = { .data_src = data_src };
17 int n;
19 n = perf_mem__snp_scnprintf(out, sizeof out, &mi);
20 n += perf_mem__lvl_scnprintf(out + n, sizeof out - n, &mi);
21 scnprintf(failure, sizeof failure, "unexpected %s", out);
22 TEST_ASSERT_VAL(failure, !strcmp(string, out));
23 return 0;
26 int test__mem(struct test *text __maybe_unused, int subtest __maybe_unused)
28 int ret = 0;
29 union perf_mem_data_src src;
31 memset(&src, 0, sizeof(src));
33 src.mem_lvl = PERF_MEM_LVL_HIT;
34 src.mem_lvl_num = 4;
36 ret |= check(src, "N/AL4 hit");
38 src.mem_remote = 1;
40 ret |= check(src, "N/ARemote L4 hit");
42 src.mem_lvl = PERF_MEM_LVL_MISS;
43 src.mem_lvl_num = PERF_MEM_LVLNUM_PMEM;
44 src.mem_remote = 0;
46 ret |= check(src, "N/APMEM miss");
48 src.mem_remote = 1;
50 ret |= check(src, "N/ARemote PMEM miss");
52 src.mem_snoopx = PERF_MEM_SNOOPX_FWD;
53 src.mem_lvl_num = PERF_MEM_LVLNUM_RAM;
55 ret |= check(src , "FwdRemote RAM miss");
57 return ret;