perf tests: Move test__syscall_open_tp_fields into separate object
authorJiri Olsa <jolsa@redhat.com>
Sat, 10 Nov 2012 00:46:49 +0000 (01:46 +0100)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 14 Nov 2012 19:50:09 +0000 (16:50 -0300)
Separating test__syscall_open_tp_fields test from the builtin-test into
open-syscall-tp-fields object.

Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1352508412-16914-10-git-send-email-jolsa@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/Makefile
tools/perf/tests/builtin-test.c
tools/perf/tests/open-syscall-tp-fields.c [new file with mode: 0644]
tools/perf/tests/tests.h

index e510b53eb8df41ecc81c9bfcd5a0ac0ea97b465e..1e5055915549feb5630df9ee41963af4a0936ac1 100644 (file)
@@ -434,6 +434,7 @@ LIB_OBJS += $(OUTPUT)tests/attr.o
 LIB_OBJS += $(OUTPUT)tests/vmlinux-kallsyms.o
 LIB_OBJS += $(OUTPUT)tests/open-syscall.o
 LIB_OBJS += $(OUTPUT)tests/open-syscall-all-cpus.o
+LIB_OBJS += $(OUTPUT)tests/open-syscall-tp-fields.o
 LIB_OBJS += $(OUTPUT)tests/mmap-basic.o
 LIB_OBJS += $(OUTPUT)tests/perf-record.o
 LIB_OBJS += $(OUTPUT)tests/rdpmc.o
index c66caa79c622960c15dfd3e1fcc67446a9cdb372..bab849039852310490a6e37bdc8bcfd072c49fc2 100644 (file)
@@ -35,118 +35,6 @@ static int test__perf_pmu(void)
        return perf_pmu__test();
 }
 
-static int test__syscall_open_tp_fields(void)
-{
-       struct perf_record_opts opts = {
-               .target = {
-                       .uid = UINT_MAX,
-                       .uses_mmap = true,
-               },
-               .no_delay   = true,
-               .freq       = 1,
-               .mmap_pages = 256,
-               .raw_samples = true,
-       };
-       const char *filename = "/etc/passwd";
-       int flags = O_RDONLY | O_DIRECTORY;
-       struct perf_evlist *evlist = perf_evlist__new(NULL, NULL);
-       struct perf_evsel *evsel;
-       int err = -1, i, nr_events = 0, nr_polls = 0;
-
-       if (evlist == NULL) {
-               pr_debug("%s: perf_evlist__new\n", __func__);
-               goto out;
-       }
-
-       evsel = perf_evsel__newtp("syscalls", "sys_enter_open", 0);
-       if (evsel == NULL) {
-               pr_debug("%s: perf_evsel__newtp\n", __func__);
-               goto out_delete_evlist;
-       }
-
-       perf_evlist__add(evlist, evsel);
-
-       err = perf_evlist__create_maps(evlist, &opts.target);
-       if (err < 0) {
-               pr_debug("%s: perf_evlist__create_maps\n", __func__);
-               goto out_delete_evlist;
-       }
-
-       perf_evsel__config(evsel, &opts, evsel);
-
-       evlist->threads->map[0] = getpid();
-
-       err = perf_evlist__open(evlist);
-       if (err < 0) {
-               pr_debug("perf_evlist__open: %s\n", strerror(errno));
-               goto out_delete_evlist;
-       }
-
-       err = perf_evlist__mmap(evlist, UINT_MAX, false);
-       if (err < 0) {
-               pr_debug("perf_evlist__mmap: %s\n", strerror(errno));
-               goto out_delete_evlist;
-       }
-
-       perf_evlist__enable(evlist);
-
-       /*
-        * Generate the event:
-        */
-       open(filename, flags);
-
-       while (1) {
-               int before = nr_events;
-
-               for (i = 0; i < evlist->nr_mmaps; i++) {
-                       union perf_event *event;
-
-                       while ((event = perf_evlist__mmap_read(evlist, i)) != NULL) {
-                               const u32 type = event->header.type;
-                               int tp_flags;
-                               struct perf_sample sample;
-
-                               ++nr_events;
-
-                               if (type != PERF_RECORD_SAMPLE)
-                                       continue;
-
-                               err = perf_evsel__parse_sample(evsel, event, &sample);
-                               if (err) {
-                                       pr_err("Can't parse sample, err = %d\n", err);
-                                       goto out_munmap;
-                               }
-
-                               tp_flags = perf_evsel__intval(evsel, &sample, "flags");
-
-                               if (flags != tp_flags) {
-                                       pr_debug("%s: Expected flags=%#x, got %#x\n",
-                                                __func__, flags, tp_flags);
-                                       goto out_munmap;
-                               }
-
-                               goto out_ok;
-                       }
-               }
-
-               if (nr_events == before)
-                       poll(evlist->pollfd, evlist->nr_fds, 10);
-
-               if (++nr_polls > 5) {
-                       pr_debug("%s: no events!\n", __func__);
-                       goto out_munmap;
-               }
-       }
-out_ok:
-       err = 0;
-out_munmap:
-       perf_evlist__munmap(evlist);
-out_delete_evlist:
-       perf_evlist__delete(evlist);
-out:
-       return err;
-}
-
 static struct test {
        const char *desc;
        int (*func)(void);
diff --git a/tools/perf/tests/open-syscall-tp-fields.c b/tools/perf/tests/open-syscall-tp-fields.c
new file mode 100644 (file)
index 0000000..b05b6a6
--- /dev/null
@@ -0,0 +1,117 @@
+#include "perf.h"
+#include "evlist.h"
+#include "evsel.h"
+#include "thread_map.h"
+#include "tests.h"
+
+int test__syscall_open_tp_fields(void)
+{
+       struct perf_record_opts opts = {
+               .target = {
+                       .uid = UINT_MAX,
+                       .uses_mmap = true,
+               },
+               .no_delay   = true,
+               .freq       = 1,
+               .mmap_pages = 256,
+               .raw_samples = true,
+       };
+       const char *filename = "/etc/passwd";
+       int flags = O_RDONLY | O_DIRECTORY;
+       struct perf_evlist *evlist = perf_evlist__new(NULL, NULL);
+       struct perf_evsel *evsel;
+       int err = -1, i, nr_events = 0, nr_polls = 0;
+
+       if (evlist == NULL) {
+               pr_debug("%s: perf_evlist__new\n", __func__);
+               goto out;
+       }
+
+       evsel = perf_evsel__newtp("syscalls", "sys_enter_open", 0);
+       if (evsel == NULL) {
+               pr_debug("%s: perf_evsel__newtp\n", __func__);
+               goto out_delete_evlist;
+       }
+
+       perf_evlist__add(evlist, evsel);
+
+       err = perf_evlist__create_maps(evlist, &opts.target);
+       if (err < 0) {
+               pr_debug("%s: perf_evlist__create_maps\n", __func__);
+               goto out_delete_evlist;
+       }
+
+       perf_evsel__config(evsel, &opts, evsel);
+
+       evlist->threads->map[0] = getpid();
+
+       err = perf_evlist__open(evlist);
+       if (err < 0) {
+               pr_debug("perf_evlist__open: %s\n", strerror(errno));
+               goto out_delete_evlist;
+       }
+
+       err = perf_evlist__mmap(evlist, UINT_MAX, false);
+       if (err < 0) {
+               pr_debug("perf_evlist__mmap: %s\n", strerror(errno));
+               goto out_delete_evlist;
+       }
+
+       perf_evlist__enable(evlist);
+
+       /*
+        * Generate the event:
+        */
+       open(filename, flags);
+
+       while (1) {
+               int before = nr_events;
+
+               for (i = 0; i < evlist->nr_mmaps; i++) {
+                       union perf_event *event;
+
+                       while ((event = perf_evlist__mmap_read(evlist, i)) != NULL) {
+                               const u32 type = event->header.type;
+                               int tp_flags;
+                               struct perf_sample sample;
+
+                               ++nr_events;
+
+                               if (type != PERF_RECORD_SAMPLE)
+                                       continue;
+
+                               err = perf_evsel__parse_sample(evsel, event, &sample);
+                               if (err) {
+                                       pr_err("Can't parse sample, err = %d\n", err);
+                                       goto out_munmap;
+                               }
+
+                               tp_flags = perf_evsel__intval(evsel, &sample, "flags");
+
+                               if (flags != tp_flags) {
+                                       pr_debug("%s: Expected flags=%#x, got %#x\n",
+                                                __func__, flags, tp_flags);
+                                       goto out_munmap;
+                               }
+
+                               goto out_ok;
+                       }
+               }
+
+               if (nr_events == before)
+                       poll(evlist->pollfd, evlist->nr_fds, 10);
+
+               if (++nr_polls > 5) {
+                       pr_debug("%s: no events!\n", __func__);
+                       goto out_munmap;
+               }
+       }
+out_ok:
+       err = 0;
+out_munmap:
+       perf_evlist__munmap(evlist);
+out_delete_evlist:
+       perf_evlist__delete(evlist);
+out:
+       return err;
+}
index 1ef265d84a6ec61cb48428e8f5b6afbb37bb71d3..f70f99848a22ea1e9747febcf7544b899dcc21f9 100644 (file)
@@ -10,6 +10,7 @@ int test__PERF_RECORD(void);
 int test__rdpmc(void);
 int test__perf_evsel__roundtrip_name_test(void);
 int test__perf_evsel__tp_sched_test(void);
+int test__syscall_open_tp_fields(void);
 
 /* Util */
 int trace_event__id(const char *evname);