[RFC/PATCH 12/38] perf tools: Add a test case for thread comm handling

From: Namhyung Kim
Date: Fri Oct 02 2015 - 01:23:56 EST


The new test case checks various thread comm handling APIs like
overridding and time sorting.

Cc: Frederic Weisbecker <fweisbec@xxxxxxxxx>
Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxxx>
---
tools/perf/tests/Build | 1 +
tools/perf/tests/builtin-test.c | 4 ++++
tools/perf/tests/tests.h | 1 +
tools/perf/tests/thread-comm.c | 47 +++++++++++++++++++++++++++++++++++++++++
4 files changed, 53 insertions(+)
create mode 100644 tools/perf/tests/thread-comm.c

diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build
index c6f198ae65fb..6bf705c4cd89 100644
--- a/tools/perf/tests/Build
+++ b/tools/perf/tests/Build
@@ -24,6 +24,7 @@ perf-y += bp_signal_overflow.o
perf-y += task-exit.o
perf-y += sw-clock.o
perf-y += mmap-thread-lookup.o
+perf-y += thread-comm.o
perf-y += thread-mg-share.o
perf-y += switch-tracking.o
perf-y += keep-tracking.o
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index d9bf51dc8cf5..5e6f4e56113c 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -191,6 +191,10 @@ static struct test {
.func = test_session_topology,
},
{
+ .desc = "Test thread comm handling",
+ .func = test__thread_comm,
+ },
+ {
.func = NULL,
},
};
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
index 0b3549672c16..23552471535a 100644
--- a/tools/perf/tests/tests.h
+++ b/tools/perf/tests/tests.h
@@ -65,6 +65,7 @@ int test__thread_map(void);
int test__llvm(void);
int test__insn_x86(void);
int test_session_topology(void);
+int test__thread_comm(void);

#if defined(__x86_64__) || defined(__i386__) || defined(__arm__) || defined(__aarch64__)
#ifdef HAVE_DWARF_UNWIND_SUPPORT
diff --git a/tools/perf/tests/thread-comm.c b/tools/perf/tests/thread-comm.c
new file mode 100644
index 000000000000..d146dedf63b4
--- /dev/null
+++ b/tools/perf/tests/thread-comm.c
@@ -0,0 +1,47 @@
+#include "tests.h"
+#include "machine.h"
+#include "thread.h"
+#include "debug.h"
+
+int test__thread_comm(void)
+{
+ struct machines machines;
+ struct machine *machine;
+ struct thread *t;
+
+ /*
+ * This test is to check whether it can retrieve a correct
+ * comm for a given time. When multi-file data storage is
+ * enabled, those task/comm events are processed first so the
+ * later sample should find a matching comm properly.
+ */
+ machines__init(&machines);
+ machine = &machines.host;
+
+ t = machine__findnew_thread(machine, 100, 100);
+ TEST_ASSERT_VAL("wrong init thread comm",
+ !strcmp(thread__comm_str(t), ":100"));
+
+ thread__set_comm(t, "perf-test1", 10000);
+ TEST_ASSERT_VAL("failed to override thread comm",
+ !strcmp(thread__comm_str(t), "perf-test1"));
+
+ thread__set_comm(t, "perf-test2", 20000);
+ thread__set_comm(t, "perf-test3", 30000);
+ thread__set_comm(t, "perf-test4", 40000);
+
+ TEST_ASSERT_VAL("failed to find timed comm",
+ !strcmp(thread__comm_str_by_time(t, 20000), "perf-test2"));
+ TEST_ASSERT_VAL("failed to find timed comm",
+ !strcmp(thread__comm_str_by_time(t, 35000), "perf-test3"));
+ TEST_ASSERT_VAL("failed to find timed comm",
+ !strcmp(thread__comm_str_by_time(t, 50000), "perf-test4"));
+
+ thread__set_comm(t, "perf-test1.5", 15000);
+ TEST_ASSERT_VAL("failed to sort timed comm",
+ !strcmp(thread__comm_str_by_time(t, 15000), "perf-test1.5"));
+
+ machine__delete_threads(machine);
+ machines__exit(&machines);
+ return 0;
+}
--
2.6.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/