Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752544AbdFGXYG (ORCPT ); Wed, 7 Jun 2017 19:24:06 -0400 Received: from mga02.intel.com ([134.134.136.20]:37707 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752598AbdFGXW6 (ORCPT ); Wed, 7 Jun 2017 19:22:58 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.39,312,1493708400"; d="scan'208";a="978097121" From: Andi Kleen To: peterz@infradead.org, acme@kernel.org Cc: linux-kernel@vger.kernel.org, jolsa@kernel.org, eranian@google.com, Andi Kleen Subject: [PATCH v2 4/4] perf, tools: Add test cases for new data source encoding Date: Wed, 7 Jun 2017 16:22:26 -0700 Message-Id: <20170607232226.26365-5-andi@firstfloor.org> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170607232226.26365-1-andi@firstfloor.org> References: <20170607232226.26365-1-andi@firstfloor.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3431 Lines: 111 From: Andi Kleen Add some simple tests to perf test to test data source printing. v2: Make the tests actually checked for the correct name of Forward Signed-off-by: Andi Kleen --- tools/perf/tests/Build | 1 + tools/perf/tests/builtin-test.c | 4 ++++ tools/perf/tests/mem.c | 50 +++++++++++++++++++++++++++++++++++++++++ tools/perf/tests/tests.h | 1 + 4 files changed, 56 insertions(+) create mode 100644 tools/perf/tests/mem.c diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build index af58ebc243ef..540409613b73 100644 --- a/tools/perf/tests/Build +++ b/tools/perf/tests/Build @@ -34,6 +34,7 @@ perf-y += thread-map.o perf-y += llvm.o llvm-src-base.o llvm-src-kbuild.o llvm-src-prologue.o llvm-src-relocation.o perf-y += bpf.o perf-y += topology.o +perf-y += mem.o perf-y += cpumap.o perf-y += stat.o perf-y += event_update.o diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c index 9e08d297f1a9..57d355445c4f 100644 --- a/tools/perf/tests/builtin-test.c +++ b/tools/perf/tests/builtin-test.c @@ -43,6 +43,10 @@ static struct test generic_tests[] = { .func = test__basic_mmap, }, { + .desc = "Test data source output", + .func = test__mem, + }, + { .desc = "Parse event definition strings", .func = test__parse_events, }, diff --git a/tools/perf/tests/mem.c b/tools/perf/tests/mem.c new file mode 100644 index 000000000000..b3fa20bd46df --- /dev/null +++ b/tools/perf/tests/mem.c @@ -0,0 +1,50 @@ +#include "util/mem-events.h" +#include "util/symbol.h" +#include "linux/perf_event.h" +#include "util/debug.h" +#include "tests.h" +#include + +static int check(union perf_mem_data_src data_src, + const char *string) +{ + char out[100]; + char failure[100]; + struct mem_info mi = { .data_src = data_src }; + + int n; + + n = perf_mem__snp_scnprintf(out, sizeof out, &mi); + n += perf_mem__lvl_scnprintf(out + n, sizeof out - n, &mi); + snprintf(failure, sizeof failure, "unexpected %s", out); + TEST_ASSERT_VAL(failure, !strcmp(string, out)); + return 0; +} + +int test__mem(int subtest __maybe_unused) +{ + int ret = 0; + + ret |= check(((union perf_mem_data_src) { + .mem_lvl = PERF_MEM_LVL_HIT, + .mem_lvlx = PERF_MEM_LVLX_L4 }), "N/AL4 hit"); + + ret |= check(((union perf_mem_data_src) { + .mem_lvl = PERF_MEM_LVL_HIT, + .mem_lvlx = PERF_MEM_LVLX_REM_L4 }), "N/ARemote L4 hit"); + + ret |= check(((union perf_mem_data_src) { + .mem_lvl = PERF_MEM_LVL_MISS, + .mem_lvlx = PERF_MEM_LVLX_PMEM }), "N/APMEM miss"); + + ret |= check(((union perf_mem_data_src) { + .mem_lvl = PERF_MEM_LVL_MISS, + .mem_lvlx = PERF_MEM_LVLX_REM_PMEM }), "N/ARemote PMEM miss"); + + ret |= check(((union perf_mem_data_src) { + .mem_snoopx = PERF_MEM_SNOOPX_FWD, + .mem_lvl = PERF_MEM_LVL_MISS, + .mem_lvlx = PERF_MEM_LVLX_REM_RAM }), "FwdRemote RAM miss"); + + return ret; +} diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h index 631859629403..3b3017ee91d6 100644 --- a/tools/perf/tests/tests.h +++ b/tools/perf/tests/tests.h @@ -56,6 +56,7 @@ int test__python_use(int subtest); int test__bp_signal(int subtest); int test__bp_signal_overflow(int subtest); int test__task_exit(int subtest); +int test__mem(int subtest); int test__sw_clock_freq(int subtest); int test__code_reading(int subtest); int test__sample_parsing(int subtest); -- 2.9.4