From: Jiri Olsa <jolsa@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: Jiri Olsa <jolsa@redhat.com>,
Corey Ashford <cjashfor@linux.vnet.ibm.com>,
Frederic Weisbecker <fweisbec@gmail.com>,
Ingo Molnar <mingo@elte.hu>, Namhyung Kim <namhyung@kernel.org>,
Paul Mackerras <paulus@samba.org>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Arnaldo Carvalho de Melo <acme@redhat.com>,
Andi Kleen <ak@linux.intel.com>, David Ahern <dsahern@gmail.com>
Subject: [PATCH 05/23] perf tests: Add simple session read/write test
Date: Wed, 17 Jul 2013 19:49:45 +0200 [thread overview]
Message-ID: <1374083403-14591-6-git-send-email-jolsa@redhat.com> (raw)
In-Reply-To: <1374083403-14591-1-git-send-email-jolsa@redhat.com>
Adding simple session read/write test to keep up
with file format changes.
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: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
---
tools/perf/Makefile | 1 +
tools/perf/tests/builtin-test.c | 4 +
tools/perf/tests/session-simple.c | 274 ++++++++++++++++++++++++++++++++++++++
tools/perf/tests/tests.h | 1 +
4 files changed, 280 insertions(+)
create mode 100644 tools/perf/tests/session-simple.c
diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 5b7c6db..ca3e17b 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -389,6 +389,7 @@ LIB_OBJS += $(OUTPUT)tests/bp_signal.o
LIB_OBJS += $(OUTPUT)tests/bp_signal_overflow.o
LIB_OBJS += $(OUTPUT)tests/task-exit.o
LIB_OBJS += $(OUTPUT)tests/sw-clock.o
+LIB_OBJS += $(OUTPUT)tests/session-simple.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 35b45f1466..67fc0ea 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -94,6 +94,10 @@ static struct test {
.func = test__sw_clock_freq,
},
{
+ .desc = "Test session - simple read/write",
+ .func = test__session_simple,
+ },
+ {
.func = NULL,
},
};
diff --git a/tools/perf/tests/session-simple.c b/tools/perf/tests/session-simple.c
new file mode 100644
index 0000000..3bcd7eb
--- /dev/null
+++ b/tools/perf/tests/session-simple.c
@@ -0,0 +1,274 @@
+
+#include <stdlib.h>
+#include <linux/kernel.h>
+
+#include "tests.h"
+#include "session.h"
+#include "header.h"
+#include "util.h"
+#include "evlist.h"
+
+
+static char *get_file(void)
+{
+ static char buf[PATH_MAX];
+ static char *file;
+ int fd;
+
+ if (file)
+ return file;
+
+ snprintf(buf, PATH_MAX, "/tmp/perf-test-session-simple-data-XXXXXX");
+ fd = mkstemp(buf);
+ if (fd < 0) {
+ pr_err("mkstemp failed");
+ return NULL;
+ }
+
+ close(fd);
+
+ file = buf;
+ pr_debug("data file %s\n", file);
+ return file;
+}
+
+static struct perf_evlist *get_evlist(void)
+{
+ struct perf_evlist *evlist;
+ int err;
+
+ evlist = perf_evlist__new();
+ if (evlist == NULL) {
+ pr_err("perf_evlist__new failed\n");
+ return NULL;
+ }
+
+ err = perf_evlist__add_default(evlist);
+ if (err < 0) {
+ pr_err("Not enough memory to create evsel\n");
+ perf_evlist__delete(evlist);
+ evlist = NULL;
+ }
+
+ return evlist;
+}
+
+static union perf_event *get_event_MMAP(void)
+{
+ static union perf_event event;
+ size_t size;
+
+ size = snprintf(event.mmap.filename, sizeof(event.mmap.filename),
+ "krava") + 1;
+ size = PERF_ALIGN(size, sizeof(u64));
+
+ event.header.type = PERF_RECORD_MMAP;
+ event.header.misc = PERF_RECORD_MISC_KERNEL;
+ event.header.size = sizeof(event.mmap) -
+ (sizeof(event.mmap.filename) - size);
+
+ event.mmap.pgoff = 10;
+ event.mmap.start = 0;
+ event.mmap.len = 10;
+ event.mmap.pid = 123;
+
+ return &event;
+}
+
+static union perf_event *get_event_COMM(void)
+{
+ static union perf_event event;
+ size_t size;
+
+ size = snprintf(event.comm.comm, sizeof(event.comm.comm),
+ "krava") + 1;
+ size = PERF_ALIGN(size, sizeof(u64));
+
+ event.header.type = PERF_RECORD_COMM;
+ event.header.size = sizeof(event.comm) -
+ (sizeof(event.comm.comm) - size);
+
+ event.comm.pid = 1234;
+ event.comm.tid = 4321;
+
+ return &event;
+}
+
+static int store_event(int fd, union perf_event *event, size_t *size)
+{
+ *size += event->header.size;
+ return write(fd, event, event->header.size) > 0 ? 0 : -1;
+}
+
+static int session_write(void)
+{
+ struct perf_session *session;
+ struct perf_evlist *evlist;
+ size_t size = 0;
+ char *file;
+ int feat, fd;
+
+ file = get_file();
+ TEST_ASSERT_VAL("failed to get temporary file", file);
+
+ fd = open(file, O_RDWR);
+ TEST_ASSERT_VAL("failed to open data file", fd >= 0);
+
+ evlist = get_evlist();
+ TEST_ASSERT_VAL("failed to get evlist", evlist);
+
+ pr_debug("session writing start\n");
+
+ session = perf_session__new(file, O_WRONLY, true, false, NULL);
+ TEST_ASSERT_VAL("failed to create session", session);
+
+ session->evlist = evlist;
+ session->fd = fd;
+
+ for (feat = HEADER_FIRST_FEATURE; feat < HEADER_LAST_FEATURE; feat++)
+ perf_header__set_feat(&session->header, feat);
+
+ perf_header__clear_feat(&session->header, HEADER_BUILD_ID);
+ perf_header__clear_feat(&session->header, HEADER_TRACING_DATA);
+ perf_header__clear_feat(&session->header, HEADER_BRANCH_STACK);
+
+ TEST_ASSERT_VAL("failed to write header",
+ !perf_session__write_header(session, evlist, fd, false));
+
+ TEST_ASSERT_VAL("failed to store MMAP event",
+ !store_event(fd, get_event_MMAP(), &size));
+
+ TEST_ASSERT_VAL("failed to store COMM event",
+ !store_event(fd, get_event_COMM(), &size));
+
+ session->header.data_size += size;
+
+ TEST_ASSERT_VAL("failed to write header",
+ !perf_session__write_header(session, evlist, fd, true));
+
+ perf_session__delete(session);
+ perf_evlist__delete(evlist);
+
+ pr_debug("session writing stop\n");
+ return 0;
+}
+
+static int events_comm;
+static int events_mmap;
+
+static int process_comm(struct perf_tool *tool __maybe_unused,
+ union perf_event *event,
+ struct perf_sample *sample __maybe_unused,
+ struct machine *machine __maybe_unused)
+{
+ pr_debug("event COMM pid %d, tid %d, comm '%s'\n",
+ event->comm.pid,
+ event->comm.pid,
+ event->comm.comm);
+
+ TEST_ASSERT_VAL("wrong COMM pid\n",
+ event->comm.pid == 1234);
+
+ TEST_ASSERT_VAL("wrong COMM tid\n",
+ event->comm.tid == 4321);
+
+ TEST_ASSERT_VAL("wrong COMM comm\n",
+ !strcmp(event->comm.comm,"krava"));
+
+ events_comm++;
+ return 0;
+}
+
+static int process_mmap(struct perf_tool *tool __maybe_unused,
+ union perf_event *event,
+ struct perf_sample *sample __maybe_unused,
+ struct machine *machine __maybe_unused)
+{
+ pr_debug("event MMAP misc %d, pgoff %lu, start %lu,"
+ " len %lu, pid %d, filename '%s'\n",
+ event->header.misc,
+ event->mmap.pgoff,
+ event->mmap.start,
+ event->mmap.len,
+ event->mmap.pid,
+ event->mmap.filename);
+
+ TEST_ASSERT_VAL("wrong MMAP misc\n",
+ event->header.misc == PERF_RECORD_MISC_KERNEL);
+
+ TEST_ASSERT_VAL("wrong MMAP pgoff\n",
+ event->mmap.pgoff == 10);
+
+ TEST_ASSERT_VAL("wrong MMAP start\n",
+ event->mmap.start == 0);
+
+ TEST_ASSERT_VAL("wrong MMAP len\n",
+ event->mmap.len == 10);
+
+ TEST_ASSERT_VAL("wrong MMAP pid\n",
+ event->mmap.pid == 123);
+
+ TEST_ASSERT_VAL("wrong MMAP filename\n",
+ !strcmp(event->mmap.filename,"krava"));
+
+ TEST_ASSERT_VAL("wrong MMAP misc\n",
+ event->header.misc == PERF_RECORD_MISC_KERNEL);
+
+ TEST_ASSERT_VAL("wrong MMAP pgoff\n",
+ event->mmap.pgoff == 10);
+
+ TEST_ASSERT_VAL("wrong MMAP start\n",
+ event->mmap.start == 0);
+
+ TEST_ASSERT_VAL("wrong MMAP len\n",
+ event->mmap.len == 10);
+
+ TEST_ASSERT_VAL("wrong MMAP pid\n",
+ event->mmap.pid == 123);
+
+ TEST_ASSERT_VAL("wrong MMAP filename\n",
+ !strcmp(event->mmap.filename,"krava"));
+
+ events_mmap++;
+ return 0;
+}
+
+static int session_read(void)
+{
+ struct perf_session *session;
+ struct perf_tool tool = {
+ .mmap = process_mmap,
+ .comm = process_comm,
+ };
+ char *file;
+
+ file = get_file();
+ TEST_ASSERT_VAL("failed to get temporary file", file);
+
+ pr_debug("session reading start\n");
+
+ session = perf_session__new(file, O_RDONLY, false, false, &tool);
+ TEST_ASSERT_VAL("failed to create session", session);
+
+ TEST_ASSERT_VAL("failed to process events", session);
+ perf_session__process_events(session, &tool);
+
+ perf_session__delete(session);
+
+ pr_debug("session reading stop\n");
+
+ return 0;
+}
+
+int test__session_simple(void)
+{
+ TEST_ASSERT_VAL("failed to write data", !session_write());
+ TEST_ASSERT_VAL("failed to read data", !session_read());
+
+ unlink(get_file());
+
+ TEST_ASSERT_VAL("wrong MMAP events count", events_mmap == 1);
+ TEST_ASSERT_VAL("wrong COMM events count", events_comm == 1);
+
+ return 0;
+}
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
index 07a92f9..155b474 100644
--- a/tools/perf/tests/tests.h
+++ b/tools/perf/tests/tests.h
@@ -35,5 +35,6 @@ int test__bp_signal(void);
int test__bp_signal_overflow(void);
int test__task_exit(void);
int test__sw_clock_freq(void);
+int test__session_simple(void);
#endif /* TESTS_H */
--
1.7.11.7
next prev parent reply other threads:[~2013-07-17 17:52 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-17 17:49 [RFC 0/23] perf tool: Add support for multiple data file storage Jiri Olsa
2013-07-17 17:49 ` [PATCH 01/23] perf tools: Use session->fd instead of passing fd as argument Jiri Olsa
2013-07-19 7:54 ` [tip:perf/core] perf session: Use session-> fd " tip-bot for Jiri Olsa
2013-07-17 17:49 ` [PATCH 02/23] perf tools: Remove data_offset seek as it's not needed Jiri Olsa
2013-07-18 7:27 ` Namhyung Kim
2013-07-18 12:46 ` Jiri Olsa
2013-07-19 7:54 ` [tip:perf/core] perf header: Remove data_offset seek as it' s " tip-bot for Jiri Olsa
2013-07-17 17:49 ` [PATCH 03/23] perf tools: Remove attr_offset from perf_header Jiri Olsa
2013-07-19 7:54 ` [tip:perf/core] perf header: " tip-bot for Jiri Olsa
2013-07-17 17:49 ` [PATCH 04/23] perf tools: Introduce feat_offset into perf_header Jiri Olsa
2013-07-19 7:54 ` [tip:perf/core] perf header: " tip-bot for Jiri Olsa
2013-07-17 17:49 ` Jiri Olsa [this message]
2013-07-18 7:46 ` [PATCH 05/23] perf tests: Add simple session read/write test Namhyung Kim
2013-07-18 12:52 ` Jiri Olsa
[not found] ` <20130717193313.GA5127@infradead.org>
2013-07-18 12:52 ` Jiri Olsa
2013-07-18 14:26 ` Jiri Olsa
2013-07-17 17:49 ` [PATCH 06/23] perf doc: Add perf data file documentation Jiri Olsa
2013-07-17 19:59 ` Arnaldo Carvalho de Melo
2013-07-18 12:40 ` Jiri Olsa
2013-07-19 15:46 ` Andi Kleen
2013-07-17 17:49 ` [PATCH 07/23] perf tools: Recognize version number for perf data file Jiri Olsa
2013-07-19 7:54 ` [tip:perf/core] perf header: " tip-bot for Jiri Olsa
2013-07-17 17:49 ` [PATCH 08/23] perf tools: Introduce perf data file version CHECK macro Jiri Olsa
[not found] ` <20130717194250.GB5127@infradead.org>
2013-07-18 12:39 ` Jiri Olsa
2013-07-17 17:49 ` [PATCH 09/23] perf tools: Introduce swap_features function Jiri Olsa
2013-07-17 17:49 ` [PATCH 10/23] perf tools: Introduce swap_header function Jiri Olsa
2013-07-19 11:33 ` Namhyung Kim
2013-07-22 13:44 ` Jiri Olsa
2013-07-17 17:49 ` [PATCH 11/23] perf tools: Separate version 2 specific perf data header bits Jiri Olsa
2013-07-17 17:49 ` [PATCH 12/23] perf tools: Using evlist as a holder for event_desc feature Jiri Olsa
2013-07-17 17:49 ` [PATCH 13/23] perf tools: Introduce perf.data version 3 format Jiri Olsa
2013-07-19 12:06 ` Namhyung Kim
2013-07-22 10:00 ` Jiri Olsa
2013-07-17 17:49 ` [PATCH 14/23] perf tools: Add perf data version 3 header swap Jiri Olsa
2013-07-17 17:49 ` [PATCH 15/23] perf tools: Add perf data version 3 header read Jiri Olsa
2013-07-19 12:11 ` Namhyung Kim
2013-07-22 10:02 ` Jiri Olsa
2013-07-17 17:49 ` [PATCH 16/23] perf tools: Add perf.data version 3 header write Jiri Olsa
2013-07-17 17:49 ` [PATCH 17/23] perf tools: Get rid of post_processing_offset in record command Jiri Olsa
2013-07-17 17:49 ` [PATCH 18/23] perf tools: Move synthetizing into single function Jiri Olsa
2013-07-19 12:30 ` Namhyung Kim
2013-07-22 10:15 ` Jiri Olsa
2013-07-17 17:49 ` [PATCH 19/23] perf tools: Add data object to handle perf data file Jiri Olsa
2013-07-17 17:50 ` [PATCH 20/23] perf tools: Add perf_data_file__open interface to data object Jiri Olsa
2013-07-17 17:50 ` [PATCH 21/23] perf tools: Separating data file properties from session Jiri Olsa
2013-07-17 17:50 ` [PATCH 22/23] perf tools: Add multi file '-M' option for record command Jiri Olsa
2013-07-19 13:02 ` Namhyung Kim
2013-07-22 10:17 ` Jiri Olsa
2013-07-17 17:50 ` [PATCH 23/23] perf tools: Have the process properly sythesized in subsequent data files 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=1374083403-14591-6-git-send-email-jolsa@redhat.com \
--to=jolsa@redhat.com \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@redhat.com \
--cc=ak@linux.intel.com \
--cc=cjashfor@linux.vnet.ibm.com \
--cc=dsahern@gmail.com \
--cc=fweisbec@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=namhyung@kernel.org \
--cc=paulus@samba.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).