From: Arnaldo Carvalho de Melo <acme@infradead.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org, Namhyung Kim <namhyung.kim@lge.com>,
Namhyung Kim <namhyung@kernel.org>, Jiri Olsa <jolsa@redhat.com>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 51/54] perf test: Add test case for checking number of EXIT events
Date: Mon, 18 Mar 2013 13:25:36 -0300 [thread overview]
Message-ID: <1363623939-10748-52-git-send-email-acme@infradead.org> (raw)
In-Reply-To: <1363623939-10748-1-git-send-email-acme@infradead.org>
From: Namhyung Kim <namhyung.kim@lge.com>
The new test__task_exit() test runs a simple "/usr/bin/true" workload and then
checks whether the number of EXIT event is 1 or not.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/87obeljax4.fsf@sejong.aot.lge.com
[ committer note: Fixup conflicts with f4c66b4 ( bp overflow tests ) ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/Makefile | 1 +
tools/perf/tests/builtin-test.c | 4 +
tools/perf/tests/task-exit.c | 123 +++++++++++++++++++++++++++++++++++++++
tools/perf/tests/tests.h | 1 +
4 files changed, 129 insertions(+), 0 deletions(-)
create mode 100644 tools/perf/tests/task-exit.c
diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 990e9a1..8e1bba3 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -513,6 +513,7 @@ LIB_OBJS += $(OUTPUT)tests/hists_link.o
LIB_OBJS += $(OUTPUT)tests/python-use.o
LIB_OBJS += $(OUTPUT)tests/bp_signal.o
LIB_OBJS += $(OUTPUT)tests/bp_signal_overflow.o
+LIB_OBJS += $(OUTPUT)tests/task-exit.o
BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o
BUILTIN_OBJS += $(OUTPUT)builtin-bench.o
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 45d9ad4..9b5c70a 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -86,6 +86,10 @@ static struct test {
.func = test__bp_signal_overflow,
},
{
+ .desc = "Test number of exit event of a simple workload",
+ .func = test__task_exit,
+ },
+ {
.func = NULL,
},
};
diff --git a/tools/perf/tests/task-exit.c b/tools/perf/tests/task-exit.c
new file mode 100644
index 0000000..28fe589
--- /dev/null
+++ b/tools/perf/tests/task-exit.c
@@ -0,0 +1,123 @@
+#include "evlist.h"
+#include "evsel.h"
+#include "thread_map.h"
+#include "cpumap.h"
+#include "tests.h"
+
+#include <signal.h>
+
+static int exited;
+static int nr_exit;
+
+static void sig_handler(int sig)
+{
+ exited = 1;
+
+ if (sig == SIGUSR1)
+ nr_exit = -1;
+}
+
+/*
+ * This test will start a workload that does nothing then it checks
+ * if the number of exit event reported by the kernel is 1 or not
+ * in order to check the kernel returns correct number of event.
+ */
+int test__task_exit(void)
+{
+ int err = -1;
+ union perf_event *event;
+ struct perf_evsel *evsel;
+ struct perf_evlist *evlist;
+ struct perf_target target = {
+ .uid = UINT_MAX,
+ .uses_mmap = true,
+ };
+ const char *argv[] = { "true", NULL };
+
+ signal(SIGCHLD, sig_handler);
+ signal(SIGUSR1, sig_handler);
+
+ evlist = perf_evlist__new();
+ if (evlist == NULL) {
+ pr_debug("perf_evlist__new\n");
+ return -1;
+ }
+ /*
+ * We need at least one evsel in the evlist, use the default
+ * one: "cycles".
+ */
+ err = perf_evlist__add_default(evlist);
+ if (err < 0) {
+ pr_debug("Not enough memory to create evsel\n");
+ goto out_free_evlist;
+ }
+
+ /*
+ * Create maps of threads and cpus to monitor. In this case
+ * we start with all threads and cpus (-1, -1) but then in
+ * perf_evlist__prepare_workload we'll fill in the only thread
+ * we're monitoring, the one forked there.
+ */
+ evlist->cpus = cpu_map__dummy_new();
+ evlist->threads = thread_map__new_by_tid(-1);
+ if (!evlist->cpus || !evlist->threads) {
+ err = -ENOMEM;
+ pr_debug("Not enough memory to create thread/cpu maps\n");
+ goto out_delete_maps;
+ }
+
+ err = perf_evlist__prepare_workload(evlist, &target, argv, false, true);
+ if (err < 0) {
+ pr_debug("Couldn't run the workload!\n");
+ goto out_delete_maps;
+ }
+
+ evsel = perf_evlist__first(evlist);
+ evsel->attr.task = 1;
+ evsel->attr.sample_freq = 0;
+ evsel->attr.inherit = 0;
+ evsel->attr.watermark = 0;
+ evsel->attr.wakeup_events = 1;
+ evsel->attr.exclude_kernel = 1;
+
+ err = perf_evlist__open(evlist);
+ if (err < 0) {
+ pr_debug("Couldn't open the evlist: %s\n", strerror(-err));
+ goto out_delete_maps;
+ }
+
+ if (perf_evlist__mmap(evlist, 128, true) < 0) {
+ pr_debug("failed to mmap events: %d (%s)\n", errno,
+ strerror(errno));
+ goto out_close_evlist;
+ }
+
+ perf_evlist__start_workload(evlist);
+
+retry:
+ while ((event = perf_evlist__mmap_read(evlist, 0)) != NULL) {
+ if (event->header.type != PERF_RECORD_EXIT)
+ continue;
+
+ nr_exit++;
+ }
+
+ if (!exited || !nr_exit) {
+ poll(evlist->pollfd, evlist->nr_fds, -1);
+ goto retry;
+ }
+
+ if (nr_exit != 1) {
+ pr_debug("received %d EXIT records\n", nr_exit);
+ err = -1;
+ }
+
+ perf_evlist__munmap(evlist);
+out_close_evlist:
+ perf_evlist__close(evlist);
+out_delete_maps:
+ perf_evlist__delete_maps(evlist);
+out_free_evlist:
+ perf_evlist__delete(evlist);
+ return err;
+}
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
index 6cf1ec4..b33b328 100644
--- a/tools/perf/tests/tests.h
+++ b/tools/perf/tests/tests.h
@@ -25,5 +25,6 @@ int test__hists_link(void);
int test__python_use(void);
int test__bp_signal(void);
int test__bp_signal_overflow(void);
+int test__task_exit(void);
#endif /* TESTS_H */
--
1.7.1
next prev parent reply other threads:[~2013-03-18 16:29 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-18 16:24 [GIT PULL 00/54] perf/core improvements and fixes Arnaldo Carvalho de Melo
2013-03-18 16:24 ` [PATCH 01/54] perf tools: Fix build on non-glibc systems due to libio.h absence Arnaldo Carvalho de Melo
2013-03-18 16:24 ` [PATCH 02/54] perf tools: Remove a write-only variable in the debugfs code Arnaldo Carvalho de Melo
2013-03-18 16:24 ` [PATCH 03/54] perf tools: Honor parallel jobs Arnaldo Carvalho de Melo
2013-03-18 16:24 ` [PATCH 04/54] perf tools: Correct Makefile.include Arnaldo Carvalho de Melo
2013-03-18 16:24 ` [PATCH 05/54] perf tools: Sort command-list.txt alphabetically Arnaldo Carvalho de Melo
2013-03-18 16:24 ` [PATCH 06/54] perf tests: Make attr script verbose friendly Arnaldo Carvalho de Melo
2013-03-18 16:24 ` [PATCH 07/54] perf tests: Make attr script test event cpu Arnaldo Carvalho de Melo
2013-03-18 16:24 ` [PATCH 08/54] perf tests: Add attr record -C cpu test Arnaldo Carvalho de Melo
2013-03-18 16:24 ` [PATCH 09/54] perf tests: Add attr stat " Arnaldo Carvalho de Melo
2013-03-18 16:24 ` [PATCH 10/54] perf tools: Introduce tools/lib/lk library Arnaldo Carvalho de Melo
2013-03-18 16:24 ` [PATCH 11/54] perf tools: Extract perf-specific stuff from debugfs.c Arnaldo Carvalho de Melo
2013-03-18 16:24 ` [PATCH 12/54] tools/vm: Switch to liblk library Arnaldo Carvalho de Melo
2013-03-18 16:24 ` [PATCH 13/54] tools lib lk: Fix _FORTIFY_SOURCE builds Arnaldo Carvalho de Melo
2013-03-18 16:24 ` [PATCH 14/54] perf evlist: Remove cpus and threads arguments from perf_evlist__new() Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 15/54] perf evlist: Use cpu_map__nr() helper Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 16/54] perf evlist: Add thread_map__nr() helper Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 17/54] perf evlist: Pass struct perf_target to perf_evlist__prepare_workload() Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 18/54] perf evlist: Do not pass struct record_opts " Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 19/54] perf evlist: Add want_signal parameter " Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 20/54] perf stat: Use perf_evlist__prepare/start_workload() Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 21/54] perf annotate: Pass evsel instead of evidx on annotation functions Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 22/54] perf annotate: Add a comment on the symbol__parse_objdump_line() Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 23/54] perf annotate: Factor out disasm__calc_percent() Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 24/54] perf annotate: Cleanup disasm__calc_percent() Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 25/54] perf annotate: Add basic support to event group view Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 26/54] perf evsel: Introduce perf_evsel__is_group_event() helper Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 27/54] perf annotate: Factor out struct source_line_percent Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 28/54] perf annotate: Support event group view for --print-line Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 29/54] perf annotate browser: Make browser_disasm_line->percent an array Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 30/54] perf annotate browser: Use disasm__calc_percent() Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 31/54] perf annotate/gtk: Support event group view on GTK Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 32/54] perf annotate browser: Support event group view on TUI Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 33/54] perf trace: Get rid of a duplicate code Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 34/54] perf tools: Remove unused tracing functions Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 35/54] perf session: Remove unused perf_session__remove_thread method Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 36/54] perf machine: Move machine__remove_thread and make static Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 37/54] perf report: Remove duplicated include Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 38/54] perf tools: Remove unused trace_read_data function Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 39/54] perf tools: Remove unused struct definitions Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 40/54] perf tools: Remove unnecessary calc_data_size variable Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 41/54] perf tools: Remove unused macro definitions Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 42/54] perf tools: Remove duplicated page_size definition Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 43/54] perf tests: Test breakpoint overflow signal handler Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 44/54] perf tests: Test breakpoint overflow signal handler counts Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 45/54] perf evsel: Cleanup perf_evsel__exit() Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 46/54] perf evlist: Introduce perf_evlist__close() Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 47/54] perf trace: Free evlist resources properly on return path Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 48/54] perf record: Fixup return path of cmd_record() Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 49/54] perf tests: Fixup return path of open-syscall-tp-fields test case Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 50/54] perf tests: Fixup return path of perf record " Arnaldo Carvalho de Melo
2013-03-18 16:25 ` Arnaldo Carvalho de Melo [this message]
2013-03-18 16:25 ` [PATCH 52/54] perf stat: Introduce --repeat forever Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 53/54] perf stat: Introduce evlist methods to allocate/free the stats Arnaldo Carvalho de Melo
2013-03-18 16:25 ` [PATCH 54/54] perf tests: Add a test case for checking sw clock event frequency Arnaldo Carvalho de Melo
2013-03-21 10:08 ` [GIT PULL 00/54] perf/core improvements and fixes Ingo Molnar
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=1363623939-10748-52-git-send-email-acme@infradead.org \
--to=acme@infradead.org \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@redhat.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung.kim@lge.com \
--cc=namhyung@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
all inboxes | Powered by JetHome®