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

perf tests: Add is_printable_array test

Add automated test for is_printable_array function.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Pirko <jiri@mellanox.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/r/1468685480-18951-4-git-send-email-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Jiri Olsa and committed by
Arnaldo Carvalho de Melo
988dd774 accaed26

+42
+1
tools/perf/tests/Build
··· 40 40 perf-y += event-times.o 41 41 perf-y += backward-ring-buffer.o 42 42 perf-y += sdt.o 43 + perf-y += is_printable_array.o 43 44 44 45 $(OUTPUT)tests/llvm-src-base.c: tests/bpf-script-example.c tests/Build 45 46 $(call rule_mkdir)
+4
tools/perf/tests/builtin-test.c
··· 222 222 .func = test__sdt_event, 223 223 }, 224 224 { 225 + .desc = "Test is_printable_array function", 226 + .func = test__is_printable_array, 227 + }, 228 + { 225 229 .func = NULL, 226 230 }, 227 231 };
+36
tools/perf/tests/is_printable_array.c
··· 1 + #include <linux/compiler.h> 2 + #include "tests.h" 3 + #include "debug.h" 4 + #include "util.h" 5 + 6 + int test__is_printable_array(int subtest __maybe_unused) 7 + { 8 + char buf1[] = { 'k', 'r', 4, 'v', 'a', 0 }; 9 + char buf2[] = { 'k', 'r', 'a', 'v', 4, 0 }; 10 + struct { 11 + char *buf; 12 + unsigned int len; 13 + int ret; 14 + } t[] = { 15 + { (char *) "krava", sizeof("krava"), 1 }, 16 + { (char *) "krava", sizeof("krava") - 1, 0 }, 17 + { (char *) "", sizeof(""), 1 }, 18 + { (char *) "", 0, 0 }, 19 + { NULL, 0, 0 }, 20 + { buf1, sizeof(buf1), 0 }, 21 + { buf2, sizeof(buf2), 0 }, 22 + }; 23 + unsigned int i; 24 + 25 + for (i = 0; i < ARRAY_SIZE(t); i++) { 26 + int ret; 27 + 28 + ret = is_printable_array((char *) t[i].buf, t[i].len); 29 + if (ret != t[i].ret) { 30 + pr_err("failed: test %u\n", i); 31 + return TEST_FAIL; 32 + } 33 + } 34 + 35 + return TEST_OK; 36 + }
+1
tools/perf/tests/tests.h
··· 89 89 int test__backward_ring_buffer(int subtest); 90 90 int test__cpu_map_print(int subtest); 91 91 int test__sdt_event(int subtest); 92 + int test__is_printable_array(int subtest); 92 93 93 94 #if defined(__arm__) || defined(__aarch64__) 94 95 #ifdef HAVE_DWARF_UNWIND_SUPPORT