Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e8210cef authored by Matt Fleming's avatar Matt Fleming Committed by Arnaldo Carvalho de Melo
Browse files

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: default avatarMatt Fleming <matt.fleming@intel.com>
Acked-by: default avatarJiri 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: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent c84974ed
Loading
Loading
Loading
Loading
+16 −16
Original line number Original line Diff line number Diff line
@@ -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;
	int i;


@@ -212,7 +212,7 @@ static bool perf_test__matches(int curr, int argc, const char *argv[])
			continue;
			continue;
		}
		}


		if (strstr(tests[curr].desc, argv[i]))
		if (strstr(test->desc, argv[i]))
			return true;
			return true;
	}
	}


@@ -249,27 +249,28 @@ static int run_test(struct test *test)
	return err;
	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)
static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist)
{
{
	struct test *t;
	int i = 0;
	int i = 0;
	int width = 0;
	int width = 0;


	while (tests[i].func) {
	for_each_test(t) {
		int len = strlen(tests[i].desc);
		int len = strlen(t->desc);


		if (width < len)
		if (width < len)
			width = len;
			width = len;
		++i;
	}
	}


	i = 0;
	for_each_test(t) {
	while (tests[i].func) {
		int curr = i++, err;
		int curr = i++, err;


		if (!perf_test__matches(curr, argc, argv))
		if (!perf_test__matches(t, curr, argc, argv))
			continue;
			continue;


		pr_info("%2d: %-*s:", i, width, tests[curr].desc);
		pr_info("%2d: %-*s:", i, width, t->desc);


		if (intlist__find(skiplist, i)) {
		if (intlist__find(skiplist, i)) {
			color_fprintf(stderr, PERF_COLOR_YELLOW, " Skip (user override)\n");
			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");
		pr_debug("\n--- start ---\n");
		err = run_test(&tests[curr]);
		err = run_test(t);
		pr_debug("---- end ----\n%s:", tests[curr].desc);
		pr_debug("---- end ----\n%s:", t->desc);


		switch (err) {
		switch (err) {
		case TEST_OK:
		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)
static int perf_test__list(int argc, const char **argv)
{
{
	struct test *t;
	int i = 0;
	int i = 0;


	while (tests[i].func) {
	for_each_test(t) {
		int curr = i++;
		if (argc > 1 && !strstr(t->desc, argv[1]))

		if (argc > 1 && !strstr(tests[curr].desc, argv[1]))
			continue;
			continue;


		pr_info("%2d: %s\n", i, tests[curr].desc);
		pr_info("%2d: %s\n", ++i, t->desc);
	}
	}


	return 0;
	return 0;