Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf tests: Add mem2node object test

Adding mem2node object automated test.

The test prepares few artificial nodes - memory maps and verifies the
mem2node object returns proper node values to given addresses.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20180309101442.9224-4-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Jiri Olsa and committed by
Arnaldo Carvalho de Melo
8185850a 4acf6142

+81
+1
tools/perf/tests/Build
··· 48 48 perf-y += perf-hooks.o 49 49 perf-y += clang.o 50 50 perf-y += unit_number__scnprintf.o 51 + perf-y += mem2node.o 51 52 52 53 $(OUTPUT)tests/llvm-src-base.c: tests/bpf-script-example.c tests/Build 53 54 $(call rule_mkdir)
+4
tools/perf/tests/builtin-test.c
··· 275 275 .func = test__unit_number__scnprint, 276 276 }, 277 277 { 278 + .desc = "mem2node", 279 + .func = test__mem2node, 280 + }, 281 + { 278 282 .func = NULL, 279 283 }, 280 284 };
+75
tools/perf/tests/mem2node.c
··· 1 + #include <linux/compiler.h> 2 + #include <linux/bitmap.h> 3 + #include "cpumap.h" 4 + #include "mem2node.h" 5 + #include "tests.h" 6 + 7 + static struct node { 8 + int node; 9 + const char *map; 10 + } test_nodes[] = { 11 + { .node = 0, .map = "0" }, 12 + { .node = 1, .map = "1-2" }, 13 + { .node = 3, .map = "5-7,9" }, 14 + }; 15 + 16 + #define T TEST_ASSERT_VAL 17 + 18 + static unsigned long *get_bitmap(const char *str, int nbits) 19 + { 20 + struct cpu_map *map = cpu_map__new(str); 21 + unsigned long *bm = NULL; 22 + int i; 23 + 24 + bm = bitmap_alloc(nbits); 25 + 26 + if (map && bm) { 27 + bitmap_zero(bm, nbits); 28 + 29 + for (i = 0; i < map->nr; i++) { 30 + set_bit(map->map[i], bm); 31 + } 32 + } 33 + 34 + if (map) 35 + cpu_map__put(map); 36 + else 37 + free(bm); 38 + 39 + return bm && map ? bm : NULL; 40 + } 41 + 42 + int test__mem2node(struct test *t __maybe_unused, int subtest __maybe_unused) 43 + { 44 + struct mem2node map; 45 + struct memory_node nodes[3]; 46 + struct perf_env env = { 47 + .memory_nodes = (struct memory_node *) &nodes[0], 48 + .nr_memory_nodes = ARRAY_SIZE(nodes), 49 + .memory_bsize = 0x100, 50 + }; 51 + unsigned int i; 52 + 53 + for (i = 0; i < ARRAY_SIZE(nodes); i++) { 54 + nodes[i].node = test_nodes[i].node; 55 + nodes[i].size = 10; 56 + 57 + T("failed: alloc bitmap", 58 + (nodes[i].set = get_bitmap(test_nodes[i].map, 10))); 59 + } 60 + 61 + T("failed: mem2node__init", !mem2node__init(&map, &env)); 62 + T("failed: mem2node__node", 0 == mem2node__node(&map, 0x50)); 63 + T("failed: mem2node__node", 1 == mem2node__node(&map, 0x100)); 64 + T("failed: mem2node__node", 1 == mem2node__node(&map, 0x250)); 65 + T("failed: mem2node__node", 3 == mem2node__node(&map, 0x500)); 66 + T("failed: mem2node__node", 3 == mem2node__node(&map, 0x650)); 67 + T("failed: mem2node__node", -1 == mem2node__node(&map, 0x450)); 68 + T("failed: mem2node__node", -1 == mem2node__node(&map, 0x1050)); 69 + 70 + for (i = 0; i < ARRAY_SIZE(nodes); i++) 71 + free(nodes[i].set); 72 + 73 + mem2node__exit(&map); 74 + return 0; 75 + }
+1
tools/perf/tests/tests.h
··· 103 103 const char *test__clang_subtest_get_desc(int subtest); 104 104 int test__clang_subtest_get_nr(void); 105 105 int test__unit_number__scnprint(struct test *test, int subtest); 106 + int test__mem2node(struct test *t, int subtest); 106 107 107 108 bool test__bp_signal_is_supported(void); 108 109