From: Michael Petlan <mpetlan@redhat.com>
To: Arnaldo Carvalho de Melo <acme@redhat.com>, Jiri Olsa <jolsa@redhat.com>
Cc: "linux-perf-users@vger.kernel.org" <linux-perf-users@vger.kernel.org>
Subject: [PATCH 1/9] perf test: Adding an entry for the perftool-testsuite
Date: Mon, 07 Dec 2015 19:52:59 +0100 [thread overview]
Message-ID: <1449514379.24573.251.camel@redhat.com> (raw)
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 0ff8a97..3bf23a6 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 llvm-src-prologue.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 2b1ade1..6a3aa60 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -180,6 +180,10 @@ static struct test generic_tests[] = {
},
},
{
+ .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..b79f66b
--- /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(int subtest __maybe_unused)
+{
+ 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 a0733aa..9ad6bd4 100644
--- a/tools/perf/tests/tests.h
+++ b/tools/perf/tests/tests.h
@@ -79,6 +79,7 @@ int test__bpf(int subtest);
const char *test__bpf_subtest_get_desc(int subtest);
int test__bpf_subtest_get_nr(void);
int test_session_topology(int subtest);
+int test__suite(int subtest);
#if defined(__arm__) || defined(__aarch64__)
#ifdef HAVE_DWARF_UNWIND_SUPPORT
next reply other threads:[~2015-12-07 18:53 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-07 18:52 Michael Petlan [this message]
2015-12-15 12:03 ` [PATCH 1/9] perf test: Adding an entry for the perftool-testsuite Jiri Olsa
[not found] <cover.1458134357.git.mpetlan@redhat.com>
2016-03-16 13:50 ` Michael Petlan
2016-03-27 12:23 ` Jiri Olsa
2016-03-29 12:57 ` Michael Petlan
2016-03-27 12:23 ` Jiri Olsa
2016-03-27 12:24 ` Jiri Olsa
2016-03-27 12:24 ` Jiri Olsa
2016-03-29 12:19 ` Michael Petlan
2016-03-27 12:24 ` Jiri Olsa
2016-03-29 12:19 ` Michael Petlan
2016-03-29 19:39 ` Jiri Olsa
2016-03-27 12:24 ` Jiri Olsa
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=1449514379.24573.251.camel@redhat.com \
--to=mpetlan@redhat.com \
--cc=acme@redhat.com \
--cc=jolsa@redhat.com \
--cc=linux-perf-users@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).