Skip to content

Commit 3067eaa

Browse files
Andi Kleenacmel
authored andcommitted
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>
1 parent 52839e6 commit 3067eaa

4 files changed

Lines changed: 62 additions & 0 deletions

File tree

‎tools/perf/tests/Build‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ perf-y += thread-map.o
3434
perf-y += llvm.o llvm-src-base.o llvm-src-kbuild.o llvm-src-prologue.o llvm-src-relocation.o
3535
perf-y += bpf.o
3636
perf-y += topology.o
37+
perf-y += mem.o
3738
perf-y += cpumap.o
3839
perf-y += stat.o
3940
perf-y += event_update.o

‎tools/perf/tests/builtin-test.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ static struct test generic_tests[] = {
4747
.desc = "Read samples using the mmap interface",
4848
.func = test__basic_mmap,
4949
},
50+
{
51+
.desc = "Test data source output",
52+
.func = test__mem,
53+
},
5054
{
5155
.desc = "Parse event definition strings",
5256
.func = test__parse_events,

‎tools/perf/tests/mem.c‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
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+
snprintf(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+
}

‎tools/perf/tests/tests.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ int test__python_use(struct test *test, int subtest);
5858
int test__bp_signal(struct test *test, int subtest);
5959
int test__bp_signal_overflow(struct test *test, int subtest);
6060
int test__task_exit(struct test *test, int subtest);
61+
int test__mem(struct test *test, int subtest);
6162
int test__sw_clock_freq(struct test *test, int subtest);
6263
int test__code_reading(struct test *test, int subtest);
6364
int test__sample_parsing(struct test *test, int subtest);

0 commit comments

Comments
 (0)