From nobody Sun Nov 24 02:53:14 2024 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 04CA01A9B28 for ; Fri, 8 Nov 2024 17:49:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731088196; cv=none; b=s2DMZqJMfgWxqT2pV+nAqEQ8J+nCBRYUQrZQdVShHI3CGj2srWP7++eB7vDn+DyhqPas6Lel67qJIw3ToUBZpZoZgmg60rgNlM0MxxYGD71XwpnOc7VuA5994amH7HeIgXqrDoQGV4OKlIZqITGrTwNENydepqzFo/zeK2E5XRI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731088196; c=relaxed/simple; bh=NKbShQvwHgvwfpa9vU/9CUtrorWgMpA+fuT3dsm8tiw=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=prMOFEzc4sIS1KRkd7Cu/5F9visiB4ts2UGV6AWrk+vnTj8Pbd3sGZ1SzH2LsfQ1L7KESKuutEkW+ABmUzA29kk9fL3d8ZQ7a0pD2jD9SwdXy5xU3CiJrwtxFAkpMg8LUEy7XjyffDjajApZ6lWjfPGAFffGuSeO7udbY+gnJZo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=12U/qiqB; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="12U/qiqB" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6ea8a5e83a3so48125287b3.2 for ; Fri, 08 Nov 2024 09:49:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731088193; x=1731692993; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=U29VnNAdGfcDQYAQsqPFX5iA64VqRhVFXyadfuAtcAQ=; b=12U/qiqBwuzrJ2tD8l9GJCi78C8dnKPojWzmwn+LEjZbRUd1aXE4xuegjHKJxXE+Pd vi+rU6KjR84i5Fdnx+c5H5meJuI7s3FEtcmvlWr+ts6R2LT7ImHmZPxNQYTFeFRyq6jX oDEE2xWAkzjq8s+SPmMNVqFnQiD7BH3ZvH2y/yPdbzxW1zW59+wnBoY86xt6rRsVvYeP mufDMxmwRyZy2R9GS7vchhEPZq9BRGtTcX23h+ar5wAq9ltWrKSagppEvoFWUeyfTeWm QxLFlaoELD9EjTmsnhAGc9eryp4VleXsEfRJCfWC8/sQgfdoX6NtA9M3AUdqFGxaUCRd Sd9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731088193; x=1731692993; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=U29VnNAdGfcDQYAQsqPFX5iA64VqRhVFXyadfuAtcAQ=; b=C6YmPlZ4Cr7h7vCMvIyHz7B4WLZksWqSagL3Gd1nps00QDfDu+FRIiADhN9FZp8463 4ZkxCoysSOme6hXG2xMO/POCXwkblr1r1lc5SpL68vLilJgB6O/SAC0V8pmiUQmcZkX+ Nr9S8IUERDl/kgZZ3zRkSWMajWyFikBPPbBApoQCnztshFw3Bu4jgMHjHZk6GS6Kfakz lqgTenjQIn40ZVEd/zPXWtYNtC0HR81lbo8VlYZtF7+9FWanrNuXp+vOxl/LNAm7P7+4 3vCI6g/CMzU1t8kbaQsampzKx6Vk+J9rsDe8aqjSc0BxvdHdiBoD/JCAWIolefAH1It2 UWPA== X-Forwarded-Encrypted: i=1; AJvYcCU7/c95v8NQSOEhi35tugD5pYtv0pb9nVS3kviJz1o8Xptj+MbTGcY/ano5ymRrg425WFTm+8LYacjyxjQ=@vger.kernel.org X-Gm-Message-State: AOJu0YwufVa3Gi5yAXLVMcg0BLzbD/81UbAeGu8CBe0SatNP4VjP/Btb doaYi6RDSOmWWXtl8mZ0aHfpEkCFwuo2hPgcfCF2y42c/5NGeDmAXnrNKK+toiAMlVIg4rRUipW nBFqCTg== X-Google-Smtp-Source: AGHT+IEfV+T366mI7dWlMLWxQa/MdgOP3+nlG9w8nkhQHhM9EQOoTVfZRzQEA2XOw0C0dD2GGRP4uqSSUgJQ X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:6fd2:1e36:6d8c:7c49]) (user=irogers job=sendgmr) by 2002:a05:690c:4a13:b0:6e3:b93:3ae2 with SMTP id 00721157ae682-6eaddd704d6mr196847b3.1.1731088193078; Fri, 08 Nov 2024 09:49:53 -0800 (PST) Date: Fri, 8 Nov 2024 09:49:32 -0800 In-Reply-To: <20241108174936.262704-1-irogers@google.com> Message-Id: <20241108174936.262704-4-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241108174936.262704-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Subject: [PATCH v7 3/7] perf test: Add hwmon filename parser test From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Ravi Bangoria , Weilin Wang , Yoshihiro Furudera , James Clark , Athira Jajeev , Howard Chu , Oliver Upton , Changbin Du , Ze Gao , Junhao He , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Filename parsing maps a hwmon filename to constituent parts enum/int parts for the hwmon config value. Add a test case for the parsing. Signed-off-by: Ian Rogers --- tools/perf/tests/Build | 1 + tools/perf/tests/builtin-test.c | 1 + tools/perf/tests/hwmon_pmu.c | 110 ++++++++++++++++++++++++++++++++ tools/perf/tests/tests.h | 1 + tools/perf/util/hwmon_pmu.c | 2 +- 5 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 tools/perf/tests/hwmon_pmu.c diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build index 01ed9335db4d..ec4e1f034742 100644 --- a/tools/perf/tests/Build +++ b/tools/perf/tests/Build @@ -66,6 +66,7 @@ perf-test-y +=3D sigtrap.o perf-test-y +=3D event_groups.o perf-test-y +=3D symbols.o perf-test-y +=3D util.o +perf-test-y +=3D hwmon_pmu.o perf-test-y +=3D tool_pmu.o =20 ifeq ($(SRCARCH),$(filter $(SRCARCH),x86 arm arm64 powerpc)) diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-tes= t.c index d2cabaa8ad92..8dcf74d3c0a3 100644 --- a/tools/perf/tests/builtin-test.c +++ b/tools/perf/tests/builtin-test.c @@ -71,6 +71,7 @@ static struct test_suite *generic_tests[] =3D { &suite__PERF_RECORD, &suite__pmu, &suite__pmu_events, + &suite__hwmon_pmu, &suite__tool_pmu, &suite__dso_data, &suite__perf_evsel__roundtrip_name_test, diff --git a/tools/perf/tests/hwmon_pmu.c b/tools/perf/tests/hwmon_pmu.c new file mode 100644 index 000000000000..f5b58486d8d3 --- /dev/null +++ b/tools/perf/tests/hwmon_pmu.c @@ -0,0 +1,110 @@ +// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) +#include "debug.h" +#include "hwmon_pmu.h" +#include "tests.h" +#include +#include + +static int test__parse_hwmon_filename(struct test_suite *test __maybe_unus= ed, + int subtest __maybe_unused) +{ + const struct hwmon_parse_test { + const char *filename; + enum hwmon_type type; + int number; + enum hwmon_item item; + bool alarm; + bool parse_ok; + } tests[] =3D { + { + .filename =3D "cpu0_accuracy", + .type =3D HWMON_TYPE_CPU, + .number =3D 0, + .item =3D HWMON_ITEM_ACCURACY, + .alarm =3D false, + .parse_ok =3D true, + }, + { + .filename =3D "temp1_input", + .type =3D HWMON_TYPE_TEMP, + .number =3D 1, + .item =3D HWMON_ITEM_INPUT, + .alarm =3D false, + .parse_ok =3D true, + }, + { + .filename =3D "fan2_vid", + .type =3D HWMON_TYPE_FAN, + .number =3D 2, + .item =3D HWMON_ITEM_VID, + .alarm =3D false, + .parse_ok =3D true, + }, + { + .filename =3D "power3_crit_alarm", + .type =3D HWMON_TYPE_POWER, + .number =3D 3, + .item =3D HWMON_ITEM_CRIT, + .alarm =3D true, + .parse_ok =3D true, + }, + { + .filename =3D "intrusion4_average_interval_min_alarm", + .type =3D HWMON_TYPE_INTRUSION, + .number =3D 4, + .item =3D HWMON_ITEM_AVERAGE_INTERVAL_MIN, + .alarm =3D true, + .parse_ok =3D true, + }, + { + .filename =3D "badtype5_baditem", + .type =3D HWMON_TYPE_NONE, + .number =3D 5, + .item =3D HWMON_ITEM_NONE, + .alarm =3D false, + .parse_ok =3D false, + }, + { + .filename =3D "humidity6_baditem", + .type =3D HWMON_TYPE_NONE, + .number =3D 6, + .item =3D HWMON_ITEM_NONE, + .alarm =3D false, + .parse_ok =3D false, + }, + }; + + for (size_t i =3D 0; i < ARRAY_SIZE(tests); i++) { + enum hwmon_type type; + int number; + enum hwmon_item item; + bool alarm; + + TEST_ASSERT_EQUAL("parse_hwmon_filename", + parse_hwmon_filename( + tests[i].filename, + &type, + &number, + &item, + &alarm), + tests[i].parse_ok + ); + if (tests[i].parse_ok) { + TEST_ASSERT_EQUAL("parse_hwmon_filename type", type, tests[i].type); + TEST_ASSERT_EQUAL("parse_hwmon_filename number", number, tests[i].numbe= r); + TEST_ASSERT_EQUAL("parse_hwmon_filename item", item, tests[i].item); + TEST_ASSERT_EQUAL("parse_hwmon_filename alarm", alarm, tests[i].alarm); + } + } + return TEST_OK; +} + +static struct test_case tests__hwmon_pmu[] =3D { + TEST_CASE("Basic parsing test", parse_hwmon_filename), + { .name =3D NULL, } +}; + +struct test_suite suite__hwmon_pmu =3D { + .desc =3D "Hwmon PMU", + .test_cases =3D tests__hwmon_pmu, +}; diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h index af284dd47e5c..cb58b43aa063 100644 --- a/tools/perf/tests/tests.h +++ b/tools/perf/tests/tests.h @@ -92,6 +92,7 @@ DECLARE_SUITE(perf_evsel__tp_sched_test); DECLARE_SUITE(syscall_openat_tp_fields); DECLARE_SUITE(pmu); DECLARE_SUITE(pmu_events); +DECLARE_SUITE(hwmon_pmu); DECLARE_SUITE(tool_pmu); DECLARE_SUITE(attr); DECLARE_SUITE(dso_data); diff --git a/tools/perf/util/hwmon_pmu.c b/tools/perf/util/hwmon_pmu.c index ee5fb1c41da3..f4b7b3b6a052 100644 --- a/tools/perf/util/hwmon_pmu.c +++ b/tools/perf/util/hwmon_pmu.c @@ -126,7 +126,7 @@ bool parse_hwmon_filename(const char *filename, fn_item_len =3D strlen(fn_item); if (fn_item_len > 6 && !strcmp(&fn_item[fn_item_len - 6], "_alarm")) { assert(strlen(LONGEST_HWMON_ITEM_STR) < sizeof(fn_type)); - strlcpy(fn_type, fn_item, fn_item_len - 6); + strlcpy(fn_type, fn_item, fn_item_len - 5); fn_item =3D fn_type; *alarm =3D true; } --=20 2.47.0.277.g8800431eea-goog