aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/tests/mem.c
diff options
context:
space:
mode:
authorAndi Kleen <ak@linux.intel.com>2017-08-16 18:21:56 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2017-08-22 12:23:10 -0400
commit3067eaa7ce2dbcde89d87277cdbc91c211480060 (patch)
tree1005cd0a1e325d6fe42481c4d9bab46065d4e9c9 /tools/perf/tests/mem.c
parent52839e653b5629bd237ad2ecdd8fdd897fcd5712 (diff)
perf test: Add test cases for new data source encoding
Add some simple tests to perf test to test data source printing. v2: Make the tests actually checked for the correct name of Forward v3: Adjust to new encoding Committer notes: Avoid the in place declaration to make this build with older compilers, for instance, in Debian 7 we get: tests/mem.c: In function 'test__mem': tests/mem.c:30:5: error: missing initializer [-Werror=missing-field-initializers] tests/mem.c:30:5: error: (near initialization for '(anonymous).<anonymous>.mem_snoop') [-Werror=missing-field-initializers] So just zero a struct, then go on building the unions as needed, reusing settings from the previous test, i.e. local -> remote, etc. Signed-off-by: Andi Kleen <ak@linux.intel.com> Acked-by: Peter Zijlstra <peterz@infradead.org> Cc: Jiri Olsa <jolsa@kernel.org> Link: http://lkml.kernel.org/r/20170816222156.19953-5-andi@firstfloor.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/tests/mem.c')
-rw-r--r--tools/perf/tests/mem.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/tools/perf/tests/mem.c b/tools/perf/tests/mem.c
new file mode 100644
index 000000000000..21952e1e6e6d
--- /dev/null
+++ b/tools/perf/tests/mem.c
@@ -0,0 +1,56 @@
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
8static 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 snprintf(failure, sizeof failure, "unexpected %s", out);
20 TEST_ASSERT_VAL(failure, !strcmp(string, out));
21 return 0;
22}
23
24int 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}