From: "Li Wang (Hieco)" <li.wang@linux.dev>
To: ltp@lists.linux.it
Cc: Xiaochen Shen <shenxiaochen@open-hieco.net>
Subject: [LTP] [PATCH v3 2/2] sys_hwmon01: always report a result
Date: Wed, 21 Oct 2026 10:59:11 +0800 [thread overview]
Message-ID: <20261021025911.165250-2-li.wang@linux.dev> (raw)
In-Reply-To: <20261021025911.165250-1-li.wang@linux.dev>
On machines where the hwmon devices expose no checkable attributes
(e.g. a VM or a laptop where hwmon0 is just 'ACAD' with nothing but
a name attribute), every *_SILENT assertion skips silently and the
test finishes without reporting a single result, which the library
turns into:
tst_test.c:1730: TBROK: Test haven't reported results!
Fix this by using the new tst_sysfs_cnt_*() helpers to count the
attributes that actually exist and get validated, then reporting a
TPASS summary at the end, or TCONF when hwmon devices are present
but expose nothing we can check.
While at it, fix a preexisting off-by-one in the inN channel loop:
probe in0..in31 so that all channel types probe exactly MAX_CHANNELS
indices.
Suggested-by: Cyril Hrubis <chrubis@suse.cz>
Signed-off-by: Li Wang (Hieco) <li.wang@linux.dev>
Cc: Xiaochen Shen <shenxiaochen@open-hieco.net>
---
Notes:
v3:
- move the counter into the sysfs library as
tst_sysfs_cnt_reset()/tst_sysfs_cnt_get(), drop the CHECK_*
wrapper macros and the extra existence probe (Cyril)
v2:
- rename attr_exists() to sysfs_attr_exists() (Xiaochen)
- flatten the final result reporting with an early return (Xiaochen)
- fix a preexisting off-by-one in the inN channel loop (Xiaochen)
.../kernel/sysfs/class/hwmon/sys_hwmon01.c | 21 +++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)
diff --git a/testcases/kernel/sysfs/class/hwmon/sys_hwmon01.c b/testcases/kernel/sysfs/class/hwmon/sys_hwmon01.c
index 1bb574c23..482bd7a23 100644
--- a/testcases/kernel/sysfs/class/hwmon/sys_hwmon01.c
+++ b/testcases/kernel/sysfs/class/hwmon/sys_hwmon01.c
@@ -131,7 +131,7 @@ static void check_hwmon_device(const char *hwmon)
PATH_CLASS_HWMON "/%s/update_interval", hwmon);
/* inN channels are numbered from 0, per the hwmon ABI */
- for (i = 0; i <= MAX_CHANNELS; i++)
+ for (i = 0; i < MAX_CHANNELS; i++)
check_in_channel(hwmon, i);
for (i = 1; i <= MAX_CHANNELS; i++) {
@@ -147,7 +147,9 @@ static void do_test(void)
{
DIR *d;
struct dirent *ent;
- int found = 0;
+ int devices = 0;
+
+ tst_sysfs_cnt_reset();
if (!tst_sysfs_exists(PATH_CLASS_HWMON))
tst_brk(TCONF, PATH_CLASS_HWMON ": not present");
@@ -158,14 +160,25 @@ static void do_test(void)
if (strncmp(ent->d_name, "hwmon", 5))
continue;
- found = 1;
+ devices++;
check_hwmon_device(ent->d_name);
}
SAFE_CLOSEDIR(d);
- if (!found)
+ if (!devices) {
tst_res(TCONF, "No hwmon device found");
+ return;
+ }
+
+ if (!tst_sysfs_cnt_get()) {
+ tst_res(TCONF, "%d hwmon devices present, but no checkable attributes",
+ devices);
+ return;
+ }
+
+ tst_res(TPASS, "Validated %u attributes on %d hwmon devices",
+ tst_sysfs_cnt_get(), devices);
}
static struct tst_test test = {
--
2.56.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2026-10-21 2:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-21 2:59 [LTP] [PATCH v3 1/2] lib: add a checked-attribute counter to sysfs assert helpers Li Wang (Hieco)
2026-10-21 2:59 ` Li Wang (Hieco) [this message]
2026-10-21 3:10 ` Li Wang
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=20261021025911.165250-2-li.wang@linux.dev \
--to=li.wang@linux.dev \
--cc=ltp@lists.linux.it \
--cc=shenxiaochen@open-hieco.net \
/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