From: Matt Fleming <matt@codeblueprint.co.uk>
To: Arnaldo Carvalho de Melo <acme@redhat.com>,
Jiri Olsa <jolsa@redhat.com>, Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org, Andi Kleen <andi@firstfloor.org>,
Vince Weaver <vince@deater.net>,
Peter Zijlstra <peterz@infradead.org>,
Kanaka Juvva <kanaka.d.juvva@intel.com>,
Vikas Shivappa <vikas.shivappa@intel.com>,
Matt Fleming <matt.fleming@intel.com>
Subject: [PATCH 1/3] perf tests: Introduce iterator function for tests
Date: Sat, 5 Sep 2015 20:02:20 +0100 [thread overview]
Message-ID: <1441479742-15402-2-git-send-email-matt@codeblueprint.co.uk> (raw)
In-Reply-To: <1441479742-15402-1-git-send-email-matt@codeblueprint.co.uk>
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.
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Matt Fleming <matt.fleming@intel.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 136cd934be66..8cf0601d1662 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -183,7 +183,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;
@@ -200,7 +200,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;
}
@@ -237,27 +237,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");
@@ -265,8 +266,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:
@@ -287,15 +288,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
next prev parent reply other threads:[~2015-09-05 19:02 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-05 19:02 [PATCH 0/3] perf tests: Add arch tests Matt Fleming
2015-09-05 19:02 ` Matt Fleming [this message]
2015-09-07 12:36 ` [PATCH 1/3] perf tests: Introduce iterator function for tests Jiri Olsa
2015-09-15 7:00 ` [tip:perf/core] " tip-bot for Matt Fleming
2015-09-05 19:02 ` [PATCH 2/3] perf tests: Add arch tests Matt Fleming
2015-09-07 12:23 ` Jiri Olsa
2015-09-12 11:00 ` Matt Fleming
2015-09-07 12:28 ` Jiri Olsa
2015-09-12 11:03 ` Matt Fleming
2015-09-07 12:29 ` Jiri Olsa
2015-09-12 11:04 ` Matt Fleming
2015-09-05 19:02 ` [PATCH 3/3] perf tests: Add Intel CQM test Matt Fleming
2015-09-07 12:58 ` [PATCH 0/3] perf tests: Add arch tests Jiri Olsa
2015-09-08 14:24 ` Arnaldo Carvalho de Melo
2015-09-12 10:46 ` Matt Fleming
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1441479742-15402-2-git-send-email-matt@codeblueprint.co.uk \
--to=matt@codeblueprint.co.uk \
--cc=acme@redhat.com \
--cc=andi@firstfloor.org \
--cc=jolsa@redhat.com \
--cc=kanaka.d.juvva@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=matt.fleming@intel.com \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=vikas.shivappa@intel.com \
--cc=vince@deater.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox