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

Commit e8c6d500 authored by Wang Nan's avatar Wang Nan Committed by Arnaldo Carvalho de Melo
Browse files

perf test: Print result for each LLVM subtest



Currently 'perf test llvm' and 'perf test BPF' have multiple sub-tests,
but the result is provided in only one line:

  # perf test LLVM
  35: Test LLVM searching and compiling                        : Ok

This patch introduces sub-tests support, allowing 'perf test' to report
result for each sub-tests:

  # perf test LLVM
  35: Test LLVM searching and compiling                        :
  35.1: Basic BPF llvm compiling test                          : Ok
  35.2: Test kbuild searching                                  : Ok
  35.3: Compile source for BPF prologue generation test        : Ok

When a failure happens:

  # cat ~/.perfconfig
  [llvm]
       clang-path = "/bin/false"
  # perf test LLVM
  35: Test LLVM searching and compiling                        :
  35.1: Basic BPF llvm compiling test                          : FAILED!
  35.2: Test kbuild searching                                  : Skip
  35.3: Compile source for BPF prologue generation test        : Skip

And:

  # rm ~/.perfconfig
  # ./perf test LLVM
  35: Test LLVM searching and compiling                        :
  35.1: Basic BPF llvm compiling test                          : Skip
  35.2: Test kbuild searching                                  : Skip
  35.3: Compile source for BPF prologue generation test        : Skip

Skip by user:

  # ./perf test -s 1,`seq -s , 3 42`
   1: vmlinux symtab matches kallsyms                          : Skip (user override)
   2: detect openat syscall event                              : Ok
  ...
  35: Test LLVM searching and compiling                        : Skip (user override)
  ...

Suggested-and-Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: default avatarWang Nan <wangnan0@huawei.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1447749170-175898-4-git-send-email-wangnan0@huawei.com


[ Changed so that func is not on an anonymous union ]
Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 721a1f53
Loading
Loading
Loading
Loading
+76 −15
Original line number Original line Diff line number Diff line
@@ -160,6 +160,11 @@ static struct test generic_tests[] = {
	{
	{
		.desc = "Test LLVM searching and compiling",
		.desc = "Test LLVM searching and compiling",
		.func = test__llvm,
		.func = test__llvm,
		.subtest = {
			.skip_if_fail	= true,
			.get_nr		= test__llvm_subtest_get_nr,
			.get_desc	= test__llvm_subtest_get_desc,
		},
	},
	},
	{
	{
		.desc = "Test topology in session",
		.desc = "Test topology in session",
@@ -237,6 +242,40 @@ static int run_test(struct test *test, int subtest)
	for (j = 0; j < ARRAY_SIZE(tests); j++)	\
	for (j = 0; j < ARRAY_SIZE(tests); j++)	\
		for (t = &tests[j][0]; t->func; t++)
		for (t = &tests[j][0]; t->func; t++)


static int test_and_print(struct test *t, bool force_skip, int subtest)
{
	int err;

	if (!force_skip) {
		pr_debug("\n--- start ---\n");
		err = run_test(t, subtest);
		pr_debug("---- end ----\n");
	} else {
		pr_debug("\n--- force skipped ---\n");
		err = TEST_SKIP;
	}

	if (!t->subtest.get_nr)
		pr_debug("%s:", t->desc);
	else
		pr_debug("%s subtest %d:", t->desc, subtest);

	switch (err) {
	case TEST_OK:
		pr_info(" Ok\n");
		break;
	case TEST_SKIP:
		color_fprintf(stderr, PERF_COLOR_YELLOW, " Skip\n");
		break;
	case TEST_FAIL:
	default:
		color_fprintf(stderr, PERF_COLOR_RED, " FAILED!\n");
		break;
	}

	return err;
}

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;
	struct test *t;
@@ -264,21 +303,43 @@ static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist)
			continue;
			continue;
		}
		}


		pr_debug("\n--- start ---\n");
		if (!t->subtest.get_nr) {
		err = run_test(t, i);
			test_and_print(t, false, -1);
		pr_debug("---- end ----\n%s:", t->desc);
		} else {
			int subn = t->subtest.get_nr();
			/*
			 * minus 2 to align with normal testcases.
			 * For subtest we print additional '.x' in number.
			 * for example:
			 *
			 * 35: Test LLVM searching and compiling                        :
			 * 35.1: Basic BPF llvm compiling test                          : Ok
			 */
			int subw = width > 2 ? width - 2 : width;
			bool skip = false;
			int subi;


		switch (err) {
			if (subn <= 0) {
		case TEST_OK:
				color_fprintf(stderr, PERF_COLOR_YELLOW,
			pr_info(" Ok\n");
					      " Skip (not compiled in)\n");
			break;
				continue;
		case TEST_SKIP:
			}
			color_fprintf(stderr, PERF_COLOR_YELLOW, " Skip\n");
			pr_info("\n");
			break;

		case TEST_FAIL:
			for (subi = 0; subi < subn; subi++) {
		default:
				int len = strlen(t->subtest.get_desc(subi));
			color_fprintf(stderr, PERF_COLOR_RED, " FAILED!\n");

			break;
				if (subw < len)
					subw = len;
			}

			for (subi = 0; subi < subn; subi++) {
				pr_info("%2d.%1d: %-*s:", i, subi + 1, subw,
					t->subtest.get_desc(subi));
				err = test_and_print(t, skip, subi);
				if (err != TEST_OK && t->subtest.skip_if_fail)
					skip = true;
			}
		}
		}
	}
	}


+30 −35
Original line number Original line Diff line number Diff line
@@ -46,7 +46,7 @@ static struct {
	},
	},
	[LLVM_TESTCASE_BPF_PROLOGUE] = {
	[LLVM_TESTCASE_BPF_PROLOGUE] = {
		.source = test_llvm__bpf_test_prologue_prog,
		.source = test_llvm__bpf_test_prologue_prog,
		.desc = "Test BPF prologue generation",
		.desc = "Compile source for BPF prologue generation test",
	},
	},
};
};


@@ -131,44 +131,39 @@ test_llvm__fetch_bpf_obj(void **p_obj_buf,
	return ret;
	return ret;
}
}


int test__llvm(int subtest __maybe_unused)
int test__llvm(int subtest)
{
{
	enum test_llvm__testcase i;

	for (i = 0; i < __LLVM_TESTCASE_MAX; i++) {
	int ret;
	int ret;
	void *obj_buf = NULL;
	void *obj_buf = NULL;
	size_t obj_buf_sz = 0;
	size_t obj_buf_sz = 0;


	if ((subtest < 0) || (subtest >= __LLVM_TESTCASE_MAX))
		return TEST_FAIL;

	ret = test_llvm__fetch_bpf_obj(&obj_buf, &obj_buf_sz,
	ret = test_llvm__fetch_bpf_obj(&obj_buf, &obj_buf_sz,
					       i, false);
				       subtest, false);


	if (ret == TEST_OK) {
	if (ret == TEST_OK) {
		ret = test__bpf_parsing(obj_buf, obj_buf_sz);
		ret = test__bpf_parsing(obj_buf, obj_buf_sz);
			if (ret != TEST_OK)
		if (ret != TEST_OK) {
			pr_debug("Failed to parse test case '%s'\n",
			pr_debug("Failed to parse test case '%s'\n",
					 bpf_source_table[i].desc);
				 bpf_source_table[subtest].desc);
		}
	}
	}
	free(obj_buf);
	free(obj_buf);


		switch (ret) {
	return ret;
		case TEST_SKIP:
			return TEST_SKIP;
		case TEST_OK:
			break;
		default:
			/*
			 * Test 0 is the basic LLVM test. If test 0
			 * fail, the basic LLVM support not functional
			 * so the whole test should fail. If other test
			 * case fail, it can be fixed by adjusting
			 * config so don't report error.
			 */
			if (i == 0)
				return TEST_FAIL;
			else
				return TEST_SKIP;
}
}

int test__llvm_subtest_get_nr(void)
{
	return __LLVM_TESTCASE_MAX;
}
}
	return TEST_OK;

const char *test__llvm_subtest_get_desc(int subtest)
{
	if ((subtest < 0) || (subtest >= __LLVM_TESTCASE_MAX))
		return NULL;

	return bpf_source_table[subtest].desc;
}
}
+9 −0
Original line number Original line Diff line number Diff line
#ifndef TESTS_H
#ifndef TESTS_H
#define TESTS_H
#define TESTS_H


#include <stdbool.h>

#define TEST_ASSERT_VAL(text, cond)					 \
#define TEST_ASSERT_VAL(text, cond)					 \
do {									 \
do {									 \
	if (!(cond)) {							 \
	if (!(cond)) {							 \
@@ -27,6 +29,11 @@ enum {
struct test {
struct test {
	const char *desc;
	const char *desc;
	int (*func)(int subtest);
	int (*func)(int subtest);
	struct {
		bool skip_if_fail;
		int (*get_nr)(void);
		const char *(*get_desc)(int subtest);
	} subtest;
};
};


/* Tests */
/* Tests */
@@ -66,6 +73,8 @@ int test__fdarray__add(int subtest);
int test__kmod_path__parse(int subtest);
int test__kmod_path__parse(int subtest);
int test__thread_map(int subtest);
int test__thread_map(int subtest);
int test__llvm(int subtest);
int test__llvm(int subtest);
const char *test__llvm_subtest_get_desc(int subtest);
int test__llvm_subtest_get_nr(void);
int test__bpf(int subtest);
int test__bpf(int subtest);
int test_session_topology(int subtest);
int test_session_topology(int subtest);