* [PATCH 1/2] perf test: Adding an entry for the perftool-testsuite
@ 2015-12-04 17:11 Michael Petlan
2015-12-06 15:53 ` Jiri Olsa
0 siblings, 1 reply; 4+ messages in thread
From: Michael Petlan @ 2015-12-04 17:11 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo, Jiri Olsa,
平松雅巳 / HIRAMATU,MASAMI
Cc: linux-perf-users@vger.kernel.org
In order to be able to run the bash/subcommand-based testsuite directly
from perf test a new perf-test entry has been created for it.
The driver (suite.c) runs all the tests that it finds in the testsuite
directory: tools/perf/testsuite/ (rather ./testsuite as it expects it
it being run from the perf's directory).
In case the testsuite is not found, the testcase is skipped. If this is
not the desired behaviour, some packaging will be needed.
Usage:
./perf test suite
or
./perf test suite -v
(for the verbose output)
Signed-off-by: Michael Petlan <mpetlan@redhat.com>
---
tools/perf/tests/Build | 1 +
tools/perf/tests/builtin-test.c | 4 ++
tools/perf/tests/suite.c | 143 ++++++++++++++++++++++++++++++++++++++++
tools/perf/tests/suite.h | 30 +++++++++
tools/perf/tests/tests.h | 1 +
5 files changed, 179 insertions(+)
create mode 100644 tools/perf/tests/suite.c
create mode 100644 tools/perf/tests/suite.h
diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build
index f41ebf8..af3bb23 100644
--- a/tools/perf/tests/Build
+++ b/tools/perf/tests/Build
@@ -34,6 +34,7 @@ perf-y += thread-map.o
perf-y += llvm.o llvm-src-base.o llvm-src-kbuild.o
perf-y += bpf.o
perf-y += topology.o
+perf-y += suite.o
$(OUTPUT)tests/llvm-src-base.c: tests/bpf-script-example.c
$(call rule_mkdir)
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 80c442e..f98e1ed 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -170,6 +170,10 @@ static struct test generic_tests[] = {
.func = test__bpf,
},
{
+ .desc = "Testsuite",
+ .func = test__suite,
+ },
+ {
.func = NULL,
},
};
diff --git a/tools/perf/tests/suite.c b/tools/perf/tests/suite.c
new file mode 100644
index 0000000..9cf19b1
--- /dev/null
+++ b/tools/perf/tests/suite.c
@@ -0,0 +1,143 @@
+#include "suite.h"
+
+#define TESTSUITE_ROOT "./testsuite/"
+
+/* globals */
+int fatal_occured = 0;
+char *cwd;
+
+
+/* runs a shell script */
+int _run_shell(const char *script)
+{
+ int ret;
+ char *cmd = malloc(strlen(script) + 3 * sizeof(char));
+ strcpy(cmd, "./");
+ strcpy(cmd + 2, script);
+ ret = system(cmd);
+ if (ret == -1) {
+ fprintf(stderr, "FATAL: Could not run %s", cmd);
+ fatal_occured++;
+ return 1;
+ }
+ return ret;
+}
+
+
+/* checks for existence of a file and runs it */
+int run_shell(const char *script)
+{
+ struct stat sb;
+
+ if (stat(script, &sb) == -1) {
+ fatal_occured++;
+ return 1;
+ }
+
+ if (! (sb.st_mode & (S_IXUSR | S_IFREG))) {
+ fatal_occured++;
+ return 1;
+ }
+
+ return _run_shell(script);
+}
+
+
+/* if a script is available, run it, otherwise ignore it */
+int try_shell(const char *script)
+{
+ struct stat sb;
+
+ if (stat(script, &sb) == -1)
+ return 0;
+
+ if (! (sb.st_mode & (S_IXUSR | S_IFREG)))
+ return 0;
+
+ return _run_shell(script);
+}
+
+
+/* runs a group of tests ("base_something", ...) */
+int run_group(const char *path)
+{
+ DIR *dp;
+ struct dirent *ep;
+ int ret;
+
+ int failures = 0;
+ ret = chdir(path);
+
+ if (verbose)
+ printf("======== %s ========\n", path);
+
+ /* try to run setup */
+ failures += try_shell("setup.sh");
+
+ /* scan the dir and run tests */
+ dp = opendir("./");
+ if (dp != NULL) {
+ while ((ep = readdir(dp))) {
+ if (strncmp(ep->d_name, "test_", 5))
+ continue;
+ failures += run_shell(ep->d_name);
+ }
+ closedir(dp);
+ }
+ else
+ perror("Cannot open inner dir.");
+
+ /* try to do clean-up */
+ try_shell("cleanup.sh");
+
+ ret = chdir("..");
+ ret = ret;
+ if (verbose)
+ printf("\n");
+ return failures;
+}
+
+
+/* main test */
+int test__suite(void)
+{
+ DIR *dp;
+ struct dirent *ep;
+ int failures = 0;
+ int ret;
+ int test_status = TEST_OK;
+
+ if (verbose > 0)
+ setenv("TESTMODE_QUIET", "n", 1);
+ else
+ setenv("TESTMODE_QUIET", "y", 1);
+
+ cwd = getcwd(NULL, 0);
+ ret = chdir(TESTSUITE_ROOT);
+ if (ret != 0) {
+ free(cwd);
+ return TEST_SKIP;
+ }
+
+ dp = opendir("./");
+ if (dp != NULL) {
+
+ while ((ep = readdir(dp))) {
+ if (strncmp(ep->d_name, "base_", 5))
+ continue;
+ failures += run_group(ep->d_name);
+ }
+ closedir(dp);
+ }
+ else
+ test_status = TEST_SKIP;
+
+ ret = chdir(cwd);
+ ret = ret;
+ free(cwd);
+
+ if(failures || fatal_occured)
+ test_status = TEST_FAIL;
+
+ return test_status;
+}
diff --git a/tools/perf/tests/suite.h b/tools/perf/tests/suite.h
new file mode 100644
index 0000000..53c768b
--- /dev/null
+++ b/tools/perf/tests/suite.h
@@ -0,0 +1,30 @@
+#ifndef PERF_TEST_SUITE_H
+#define PERF_TEST_SUITE_H
+
+#include <linux/compiler.h>
+#include "tests.h"
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <unistd.h>
+#include <string.h>
+
+
+/* verbosity */
+extern int verbose;
+
+/* runs a shell script */
+int _run_shell(const char *script);
+
+/* checks for existence of a file and runs it */
+int run_shell(const char *script);
+
+/* if a script is available, run it, otherwise ignore it */
+int try_shell(const char *script);
+
+/* runs a group of tests ("base_something", ...) */
+int run_group(const char *path);
+
+#endif
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
index 3c8734a..754ade3 100644
--- a/tools/perf/tests/tests.h
+++ b/tools/perf/tests/tests.h
@@ -68,6 +68,7 @@ int test__thread_map(void);
int test__llvm(void);
int test__bpf(void);
int test_session_topology(void);
+int test__suite(void);
#if defined(__arm__) || defined(__aarch64__)
#ifdef HAVE_DWARF_UNWIND_SUPPORT
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] perf test: Adding an entry for the perftool-testsuite
2015-12-04 17:11 [PATCH 1/2] perf test: Adding an entry for the perftool-testsuite Michael Petlan
@ 2015-12-06 15:53 ` Jiri Olsa
2015-12-07 11:45 ` Michael Petlan
0 siblings, 1 reply; 4+ messages in thread
From: Jiri Olsa @ 2015-12-06 15:53 UTC (permalink / raw)
To: Michael Petlan
Cc: Arnaldo Carvalho de Melo,
平松雅巳 / HIRAMATU,MASAMI,
linux-perf-users@vger.kernel.org
On Fri, Dec 04, 2015 at 06:11:04PM +0100, Michael Petlan wrote:
> In order to be able to run the bash/subcommand-based testsuite directly
> from perf test a new perf-test entry has been created for it.
>
> The driver (suite.c) runs all the tests that it finds in the testsuite
> directory: tools/perf/testsuite/ (rather ./testsuite as it expects it
> it being run from the perf's directory).
>
> In case the testsuite is not found, the testcase is skipped. If this is
> not the desired behaviour, some packaging will be needed.
>
> Usage:
> ./perf test suite
>
> or
> ./perf test suite -v
>
> (for the verbose output)
>
> Signed-off-by: Michael Petlan <mpetlan@redhat.com>
I can't get this applied on latest acme's perf/core
[jolsa@krava perf]$ git am /tmp/w/
Applying: perf test: Adding an entry for the perftool-testsuite
error: patch failed: tools/perf/tests/Build:34
error: tools/perf/tests/Build: patch does not apply
error: patch failed: tools/perf/tests/builtin-test.c:170
error: tools/perf/tests/builtin-test.c: patch does not apply
error: patch failed: tools/perf/tests/tests.h:68
error: tools/perf/tests/tests.h: patch does not apply
Patch failed at 0001 perf test: Adding an entry for the perftool-testsuite
The copy of the patch that failed is found in:
/home/jolsa/kernel/linux-perf/.git/rebase-apply/patch
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
jirka
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] perf test: Adding an entry for the perftool-testsuite
2015-12-06 15:53 ` Jiri Olsa
@ 2015-12-07 11:45 ` Michael Petlan
2015-12-07 12:58 ` Jiri Olsa
0 siblings, 1 reply; 4+ messages in thread
From: Michael Petlan @ 2015-12-07 11:45 UTC (permalink / raw)
To: Jiri Olsa
Cc: Arnaldo Carvalho de Melo,
平松雅巳 / HIRAMATU,MASAMI,
linux-perf-users@vger.kernel.org
On Sun, 2015-12-06 at 16:53 +0100, Jiri Olsa wrote:
> I can't get this applied on latest acme's perf/core
>
Hi, I send patches that apply to latest Linus' tree:
https://github.com/torvalds/linux.git
Should I use some different tree? Arnaldo's? What is the URL
of the proper tree I should send patches against?
Thanks.
Michael
> [jolsa@krava perf]$ git am /tmp/w/
> Applying: perf test: Adding an entry for the perftool-testsuite
> error: patch failed: tools/perf/tests/Build:34
> error: tools/perf/tests/Build: patch does not apply
> error: patch failed: tools/perf/tests/builtin-test.c:170
> error: tools/perf/tests/builtin-test.c: patch does not apply
> error: patch failed: tools/perf/tests/tests.h:68
> error: tools/perf/tests/tests.h: patch does not apply
> Patch failed at 0001 perf test: Adding an entry for the perftool-testsuite
> The copy of the patch that failed is found in:
> /home/jolsa/kernel/linux-perf/.git/rebase-apply/patch
> When you have resolved this problem, run "git am --continue".
> If you prefer to skip this patch, run "git am --skip" instead.
> To restore the original branch and stop patching, run "git am --abort".
>
>
> jirka
> --
> To unsubscribe from this list: send the line "unsubscribe linux-perf-users" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] perf test: Adding an entry for the perftool-testsuite
2015-12-07 11:45 ` Michael Petlan
@ 2015-12-07 12:58 ` Jiri Olsa
0 siblings, 0 replies; 4+ messages in thread
From: Jiri Olsa @ 2015-12-07 12:58 UTC (permalink / raw)
To: Michael Petlan
Cc: Arnaldo Carvalho de Melo,
平松雅巳 / HIRAMATU,MASAMI,
linux-perf-users@vger.kernel.org
On Mon, Dec 07, 2015 at 12:45:55PM +0100, Michael Petlan wrote:
> On Sun, 2015-12-06 at 16:53 +0100, Jiri Olsa wrote:
> > I can't get this applied on latest acme's perf/core
> >
>
>
> Hi, I send patches that apply to latest Linus' tree:
>
> https://github.com/torvalds/linux.git
>
> Should I use some different tree? Arnaldo's? What is the URL
> of the proper tree I should send patches against?
git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git
perf/core branch
jirka
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-12-07 12:58 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-04 17:11 [PATCH 1/2] perf test: Adding an entry for the perftool-testsuite Michael Petlan
2015-12-06 15:53 ` Jiri Olsa
2015-12-07 11:45 ` Michael Petlan
2015-12-07 12:58 ` Jiri Olsa
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).