From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752732AbbIOHBz (ORCPT ); Tue, 15 Sep 2015 03:01:55 -0400 Received: from terminus.zytor.com ([198.137.202.10]:50091 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751477AbbIOHBw (ORCPT ); Tue, 15 Sep 2015 03:01:52 -0400 Date: Tue, 15 Sep 2015 00:00:50 -0700 From: tip-bot for Matt Fleming Message-ID: Cc: hpa@zytor.com, vince@deater.net, kanaka.d.juvva@intel.com, acme@redhat.com, tglx@linutronix.de, matt.fleming@intel.com, linux-kernel@vger.kernel.org, mingo@kernel.org, peterz@infradead.org, vikas.shivappa@intel.com, andi@firstfloor.org, jolsa@kernel.org Reply-To: vince@deater.net, kanaka.d.juvva@intel.com, hpa@zytor.com, jolsa@kernel.org, andi@firstfloor.org, vikas.shivappa@intel.com, peterz@infradead.org, mingo@kernel.org, linux-kernel@vger.kernel.org, matt.fleming@intel.com, acme@redhat.com, tglx@linutronix.de In-Reply-To: <1441479742-15402-2-git-send-email-matt@codeblueprint.co.uk> References: <1441479742-15402-2-git-send-email-matt@codeblueprint.co.uk> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf tests: Introduce iterator function for tests Git-Commit-ID: e8210cefb7e1ec0760a6fe581ad0727a2dcf8dd1 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: e8210cefb7e1ec0760a6fe581ad0727a2dcf8dd1 Gitweb: http://git.kernel.org/tip/e8210cefb7e1ec0760a6fe581ad0727a2dcf8dd1 Author: Matt Fleming AuthorDate: Sat, 5 Sep 2015 20:02:20 +0100 Committer: Arnaldo Carvalho de Melo CommitDate: Mon, 14 Sep 2015 12:50:18 -0300 perf tests: Introduce iterator function for tests 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 Acked-by: Jiri Olsa Cc: Andi Kleen Cc: Kanaka Juvva Cc: Peter Zijlstra Cc: Vikas Shivappa Cc: Vince Weaver Link: http://lkml.kernel.org/r/1441479742-15402-2-git-send-email-matt@codeblueprint.co.uk Signed-off-by: Arnaldo Carvalho de Melo --- 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 98b0b24..d9bf51d 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;