From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758972AbeAIPgE (ORCPT + 1 other); Tue, 9 Jan 2018 10:36:04 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42458 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758891AbeAIPgB (ORCPT ); Tue, 9 Jan 2018 10:36:01 -0500 From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: Frederic Weisbecker , lkml , Ingo Molnar , Namhyung Kim , David Ahern , Andi Kleen , Alexander Shishkin , Peter Zijlstra Subject: [PATCH 15/49] perf tools: Add a test case for thread comm handling Date: Tue, 9 Jan 2018 16:34:48 +0100 Message-Id: <20180109153522.14116-16-jolsa@kernel.org> In-Reply-To: <20180109153522.14116-1-jolsa@kernel.org> References: <20180109153522.14116-1-jolsa@kernel.org> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 09 Jan 2018 15:36:00 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: From: Namhyung Kim The new test case checks various thread comm handling APIs like overridding and time sorting. Cc: Frederic Weisbecker Link: http://lkml.kernel.org/n/tip-b31f0pktgl0k2dba3lqp159w@git.kernel.org Signed-off-by: Namhyung Kim Signed-off-by: Jiri Olsa --- tools/perf/tests/Build | 1 + tools/perf/tests/builtin-test.c | 4 ++++ tools/perf/tests/tests.h | 1 + tools/perf/tests/thread-comm.c | 48 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 54 insertions(+) create mode 100644 tools/perf/tests/thread-comm.c diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build index 87bf3edb037c..ca961bed1bb1 100644 --- a/tools/perf/tests/Build +++ b/tools/perf/tests/Build @@ -23,6 +23,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 fafa014240cd..6c715e030dfd 100644 --- a/tools/perf/tests/builtin-test.c +++ b/tools/perf/tests/builtin-test.c @@ -271,6 +271,10 @@ static struct test generic_tests[] = { .func = test__unit_number__scnprint, }, { + .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 2862b80bc288..d7880e5207ec 100644 --- a/tools/perf/tests/tests.h +++ b/tools/perf/tests/tests.h @@ -102,6 +102,7 @@ int test__clang(struct test *test, int subtest); const char *test__clang_subtest_get_desc(int subtest); int test__clang_subtest_get_nr(void); int test__unit_number__scnprint(struct test *test, int subtest); +int test__thread_comm(struct test *test, int subtest); bool test__bp_signal_is_supported(void); diff --git a/tools/perf/tests/thread-comm.c b/tools/perf/tests/thread-comm.c new file mode 100644 index 000000000000..9fcfd2c43488 --- /dev/null +++ b/tools/perf/tests/thread-comm.c @@ -0,0 +1,48 @@ +#include +#include "tests.h" +#include "machine.h" +#include "thread.h" +#include "debug.h" + +int test__thread_comm(struct test *test __maybe_unused, int subtest __maybe_unused) +{ + 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.13.6