lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1439187369-66492-15-git-send-email-wangnan0@huawei.com>
Date:	Mon, 10 Aug 2015 06:15:56 +0000
From:	Wang Nan <wangnan0@...wei.com>
To:	<acme@...nel.org>, <ast@...mgrid.com>
CC:	<linux-kernel@...r.kernel.org>, <lizefan@...wei.com>,
	<hekuang@...wei.com>, <xiakaixu@...wei.com>, <pi3orama@....com>,
	<brendan.d.gregg@...il.com>, <daniel@...earbox.net>,
	<dsahern@...il.com>, <jolsa@...nel.org>,
	<masami.hiramatsu.pt@...achi.com>, <namhyung@...nel.org>,
	<paulus@...ba.org>, <a.p.zijlstra@...llo.nl>
Subject: [PATCH 14/27] perf test: Enable 'perf test' run as test targets

This patch introduce test target support which allows 'perf test'
work as program be traced by test cases. One test target
'testtarget__epoll_pwait_loop' is added, which calls epoll_pwait()
111 times with different invalid fd. Further test cases can use it
to test result of reacing and filtering. BPF test will be the first
user so it resides in bpf.c.

Signed-off-by: Wang Nan <wangnan0@...wei.com>
Cc: Arnaldo Carvalho de Melo <acme@...hat.com>
Cc: Alexei Starovoitov <ast@...mgrid.com>
Cc: Brendan Gregg <brendan.d.gregg@...il.com>
Cc: Daniel Borkmann <daniel@...earbox.net>
Cc: David Ahern <dsahern@...il.com>
Cc: He Kuang <hekuang@...wei.com>
Cc: Jiri Olsa <jolsa@...nel.org>
Cc: Kaixu Xia <xiakaixu@...wei.com>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@...achi.com>
Cc: Namhyung Kim <namhyung@...nel.org>
Cc: Peter Zijlstra <a.p.zijlstra@...llo.nl>
Cc: Zefan Li <lizefan@...wei.com>
Cc: pi3orama@....com
---
 tools/perf/tests/Build          |  1 +
 tools/perf/tests/bpf.c          | 15 +++++++++++++
 tools/perf/tests/builtin-test.c | 49 +++++++++++++++++++++++++++++++++++++++++
 tools/perf/tests/tests.h        |  2 ++
 4 files changed, 67 insertions(+)
 create mode 100644 tools/perf/tests/bpf.c

diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build
index 8c98409..7ceb448 100644
--- a/tools/perf/tests/Build
+++ b/tools/perf/tests/Build
@@ -33,6 +33,7 @@ perf-y += parse-no-sample-id-all.o
 perf-y += kmod-path.o
 perf-y += thread-map.o
 perf-y += llvm.o llvm-src.o
+perf-y += bpf.o
 
 $(OUTPUT)tests/llvm-src.c: tests/bpf-script-example.c
 	$(Q)echo '#include <tests/llvm.h>' > $@
diff --git a/tools/perf/tests/bpf.c b/tools/perf/tests/bpf.c
new file mode 100644
index 0000000..1a9eec3
--- /dev/null
+++ b/tools/perf/tests/bpf.c
@@ -0,0 +1,15 @@
+#include <stdio.h>
+#include <sys/epoll.h>
+#include "tests.h"
+#include "debug.h"
+#define NR_ITERS	111
+
+int testtarget__epoll_pwait_loop(void)
+{
+	int i;
+
+	/* Should fail NR_ITERS times */
+	for (i = 0; i < NR_ITERS; i++)
+		epoll_pwait(-(i + 1), NULL, 0, 0, NULL);
+	return 0;
+}
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 1a349e8..0d0c963 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -15,6 +15,7 @@
 #include "symbol.h"
 
 static struct test {
+	bool is_test_target;
 	const char *desc;
 	int (*func)(void);
 	void (*prepare)(void);
@@ -182,6 +183,15 @@ static struct test {
 		.prepare = test__llvm_prepare,
 		.cleanup = test__llvm_cleanup,
 	},
+	/*
+	 * Put test targets after all test cases so sequence number will be
+	 * less confusing.
+	 */
+	{
+		.is_test_target = true,
+		.desc = TESTTARGET_EPOLL_PWAIT_LOOP,
+		.func = testtarget__epoll_pwait_loop,
+	},
 	{
 		.func = NULL,
 	},
@@ -245,12 +255,39 @@ static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist)
 {
 	int i = 0;
 	int width = 0;
+	bool run_test_targets = true;
 
 	while (tests[i].func) {
 		int len = strlen(tests[i].desc);
 
 		if (width < len)
 			width = len;
+
+		/*
+		 * Check whether we are going to run test targets or test
+		 * cases:
+		 *
+		 * Test targets must be specified explicitly.
+		 */
+		switch (argc) {
+		case 0:
+			run_test_targets = false;
+			break;
+		default:
+			if (!perf_test__matches(i, argc, argv))
+				break;
+			/*
+			 * If there is at lease one matched tests is
+			 * not test target, run test cases.
+			 *
+			 * This can avoid something like 'perf test T'
+			 * matches different targets and cases.
+			 */
+			if (!tests[i].is_test_target)
+				run_test_targets = false;
+			break;
+		}
+
 		++i;
 	}
 
@@ -261,6 +298,15 @@ static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist)
 		if (!perf_test__matches(curr, argc, argv))
 			continue;
 
+		if (run_test_targets) {
+			if (tests[curr].is_test_target)
+				tests[curr].func();
+			continue;
+		}
+
+		if (tests[curr].is_test_target)
+			continue;
+
 		pr_info("%2d: %-*s:", i, width, tests[curr].desc);
 
 		if (intlist__find(skiplist, i)) {
@@ -290,6 +336,9 @@ static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist)
 		}
 	}
 
+	if (run_test_targets)
+		exit(0);
+
 	return 0;
 }
 
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
index 0d79f04..0138a3d 100644
--- a/tools/perf/tests/tests.h
+++ b/tools/perf/tests/tests.h
@@ -65,6 +65,8 @@ int test__thread_map(void);
 int test__llvm(void);
 void test__llvm_prepare(void);
 void test__llvm_cleanup(void);
+#define TESTTARGET_EPOLL_PWAIT_LOOP "TESTTARGET: epoll_pwait loop"
+int testtarget__epoll_pwait_loop(void);
 
 #if defined(__x86_64__) || defined(__i386__) || defined(__arm__) || defined(__aarch64__)
 #ifdef HAVE_DWARF_UNWIND_SUPPORT
-- 
1.8.3.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ