Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1224323

[PATCH 10/27] perf tests: Introduce iterator function for tests

From Arnaldo Carvalho de Melo <acme@kernel.org>
Newsgroups linux.kernel
Subject [PATCH 10/27] perf tests: Introduce iterator function for tests
Date 2015-09-14 18:50 +0200
Message-ID <q8F75-3qM-45@gated-at.bofh.it> (permalink)
References <q8EXn-3f1-7@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


From: Matt Fleming <matt.fleming@intel.com>

In preparation for introducing more arrays of tests, e.g. "arch tests"
(architecture-specific tests), abstract the code to iterate over the
list of tests into a helper function.

This way, code that uses a 'struct test' doesn't need to worry about how
the tests are grouped together and changes to the list of tests doesn't
require changes to the code using it.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: Kanaka Juvva <kanaka.d.juvva@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Vikas Shivappa <vikas.shivappa@intel.com>
Cc: Vince Weaver <vince@deater.net>
Link: http://lkml.kernel.org/r/1441479742-15402-2-git-send-email-matt@codeblueprint.co.uk
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/tests/builtin-test.c | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 98b0b2486100..d9bf51dc8cf5 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -195,7 +195,7 @@ static struct test {
 	},
 };
 
-static bool perf_test__matches(int curr, int argc, const char *argv[])
+static bool perf_test__matches(struct test *test, int curr, int argc, const char *argv[])
 {
 	int i;
 
@@ -212,7 +212,7 @@ static bool perf_test__matches(int curr, int argc, const char *argv[])
 			continue;
 		}
 
-		if (strstr(tests[curr].desc, argv[i]))
+		if (strstr(test->desc, argv[i]))
 			return true;
 	}
 
@@ -249,27 +249,28 @@ static int run_test(struct test *test)
 	return err;
 }
 
+#define for_each_test(t)	 for (t = &tests[0]; t->func; t++)
+
 static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist)
 {
+	struct test *t;
 	int i = 0;
 	int width = 0;
 
-	while (tests[i].func) {
-		int len = strlen(tests[i].desc);
+	for_each_test(t) {
+		int len = strlen(t->desc);
 
 		if (width < len)
 			width = len;
-		++i;
 	}
 
-	i = 0;
-	while (tests[i].func) {
+	for_each_test(t) {
 		int curr = i++, err;
 
-		if (!perf_test__matches(curr, argc, argv))
+		if (!perf_test__matches(t, curr, argc, argv))
 			continue;
 
-		pr_info("%2d: %-*s:", i, width, tests[curr].desc);
+		pr_info("%2d: %-*s:", i, width, t->desc);
 
 		if (intlist__find(skiplist, i)) {
 			color_fprintf(stderr, PERF_COLOR_YELLOW, " Skip (user override)\n");
@@ -277,8 +278,8 @@ static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist)
 		}
 
 		pr_debug("\n--- start ---\n");
-		err = run_test(&tests[curr]);
-		pr_debug("---- end ----\n%s:", tests[curr].desc);
+		err = run_test(t);
+		pr_debug("---- end ----\n%s:", t->desc);
 
 		switch (err) {
 		case TEST_OK:
@@ -299,15 +300,14 @@ static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist)
 
 static int perf_test__list(int argc, const char **argv)
 {
+	struct test *t;
 	int i = 0;
 
-	while (tests[i].func) {
-		int curr = i++;
-
-		if (argc > 1 && !strstr(tests[curr].desc, argv[1]))
+	for_each_test(t) {
+		if (argc > 1 && !strstr(t->desc, argv[1]))
 			continue;
 
-		pr_info("%2d: %s\n", i, tests[curr].desc);
+		pr_info("%2d: %s\n", ++i, t->desc);
 	}
 
 	return 0;
-- 
2.1.0

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

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[GIT PULL 00/27] perf/core2 improvements and fixes Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 18:40 +0200
  [PATCH 01/27] perf tests: Take into account address of each objdump line Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 18:40 +0200
  [PATCH 03/27] perf tests: Stop reading if objdump output crossed sections Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 18:40 +0200
  [PATCH 12/27] perf env: Rename some leftovers from rename to perf_env Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 18:50 +0200
  [PATCH 16/27] perf tools: Add tools/include into tags directories Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 18:50 +0200
  [PATCH 14/27] perf hists browser: Fixup the "cpu" column width calculation Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 18:50 +0200
  [PATCH 21/27] perf env: Introduce read_cpu_topology_map() method Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 18:50 +0200
  [PATCH 19/27] tools lib api cpu: Introduce cpu.[ch] to obtain cpu related information Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 18:50 +0200
  [PATCH 22/27] perf machine: Add pointer to sample's environment Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 18:50 +0200
  [PATCH 11/27] perf env: Move perf_env out of header.h and session.c into separate object Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 18:50 +0200
  [PATCH 27/27] perf test: Add entry for hists socket filter Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 18:50 +0200
  [PATCH 15/27] perf evsel: Remove forward declaration of 'struct perf_evlist' Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 18:50 +0200
  [PATCH 10/27] perf tests: Introduce iterator function for tests Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 18:50 +0200
  [PATCH 20/27] perf cpu_map: Use sysfs__read_int in get_{core,socket}_id() Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 18:50 +0200
  [PATCH 13/27] perf env: Adopt perf_header__set_cmdline Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 18:50 +0200
  [PATCH 24/27] perf tools: Introduce new sort type "socket" for the processor socket Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 18:50 +0200
  [PATCH 08/27] perf tools: Switch to tracing_path interface on appropriate places Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 18:50 +0200
  [PATCH 23/27] perf tools: Add processor socket info to hist_entry and addr_location Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 18:50 +0200
  [PATCH 25/27] perf report: Introduce --socket-filter option Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 18:50 +0200
  [PATCH 26/27] perf hists browser: Zoom in/out for processor socket Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 18:50 +0200
  [PATCH 18/27] tools lib api fs: Introduce sysfs__read_{int,ull}() Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 18:50 +0200
  [PATCH 17/27] perf env: Read msr pmu type from header Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 18:50 +0200
  [PATCH 09/27] perf test: Add entry to test cpu topology Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 18:50 +0200
  [PATCH 07/27] tools lib api fs: Remove debugfs, tracefs and findfs objects Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 19:00 +0200
  [PATCH 06/27] tools lib api fs: Replace debugfs/tracefs objects interface with fs.c Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 19:00 +0200
  [PATCH 05/27] tools lib api fs: Make tracing_path_strerror_open message generic Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 19:00 +0200
  Re: [GIT PULL 00/27] perf/core2 improvements and fixes Ingo Molnar <mingo@kernel.org> - 2015-09-15 09:00 +0200

csiph-web