From: "Li Wang (Hieco)" <li.wang@linux.dev>
To: ltp@lists.linux.it
Cc: Xiaochen Shen <shenxiaochen@open-hieco.net>
Subject: [LTP] [PATCH v4 1/2] lib: add a checked-attribute counter to sysfs assert helpers
Date: Wed, 21 Oct 2026 11:18:15 +0800 [thread overview]
Message-ID: <20261021031816.166499-1-li.wang@linux.dev> (raw)
The TST_SYSFS_ASSERT_*_SILENT() assertions skip silently when the
attribute does not exist. A test that only uses SILENT assertions can
therefore finish without reporting a single result on machines where
none of the probed attributes are present, which the library turns
into:
tst_test.c:1730: TBROK: Test haven't reported results!
Add a counter that is bumped every time a SILENT assertion finds the
attribute and actually checks it, regardless of whether the check
passes or fails (failures produce TFAIL on their own). Tests can reset
it at the start, then report a TPASS summary or a TCONF based on the
final count.
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:
v4:
- drop the silent_attr_exists() helper, bump the counter
directly after the existence check in each silent assertion,
which also keeps the cmp_silent counting consistent.
include/tst_sysfs_assert.h | 11 +++++++++++
lib/tst_sysfs_assert.c | 20 ++++++++++++++++++++
2 files changed, 31 insertions(+)
diff --git a/include/tst_sysfs_assert.h b/include/tst_sysfs_assert.h
index b21c09849..d2a010d80 100644
--- a/include/tst_sysfs_assert.h
+++ b/include/tst_sysfs_assert.h
@@ -649,4 +649,15 @@ long tst_sysfs_read_li(const char *file, const int lineno,
unsigned long tst_sysfs_read_lx(const char *file, const int lineno,
const char *fmt, ...);
+/**
+ * tst_sysfs_cnt_reset() - Reset the checked-attribute counter.
+ */
+void tst_sysfs_cnt_reset(void);
+
+/**
+ * tst_sysfs_cnt_get() - Number of attributes the *_SILENT assertions
+ * found and checked (pass or fail) since the last reset.
+ */
+unsigned int tst_sysfs_cnt_get(void);
+
#endif /* TST_SYSFS_ASSERT_H__ */
diff --git a/lib/tst_sysfs_assert.c b/lib/tst_sysfs_assert.c
index 98680e976..4a34acc35 100644
--- a/lib/tst_sysfs_assert.c
+++ b/lib/tst_sysfs_assert.c
@@ -15,6 +15,8 @@
#include "tst_test.h"
#include "tst_sysfs_assert.h"
+static unsigned int tst_sysfs_cnt;
+
static void build_path(char *path, size_t size, const char *fmt, va_list ap)
{
vsnprintf(path, size, fmt, ap);
@@ -98,6 +100,8 @@ void tst_sysfs_assert_rangell_silent(const char *file, const int lineno,
if (access(path, F_OK))
return;
+ tst_sysfs_cnt++;
+
range_check(file, lineno, path, min, max);
}
@@ -156,6 +160,8 @@ void tst_sysfs_assert_rangeuu_silent(const char *file, const int lineno,
if (access(path, F_OK))
return;
+ tst_sysfs_cnt++;
+
range_check_u(file, lineno, path, min, max);
}
@@ -242,6 +248,8 @@ void tst_sysfs_assert_bool_silent(const char *file, const int lineno,
if (access(path, F_OK))
return;
+ tst_sysfs_cnt++;
+
bool_check(file, lineno, path);
}
@@ -684,6 +692,8 @@ void tst_sysfs_assert_cmp_silent(const char *file, const int lineno,
if (access(path1, F_OK) || access(path2, F_OK))
return;
+ tst_sysfs_cnt++;
+
tst_sysfs_assert_cmp(file, lineno, path1, op, path2);
}
@@ -869,3 +879,13 @@ unsigned long tst_sysfs_read_lx(const char *file, const int lineno,
return val;
}
+
+void tst_sysfs_cnt_reset(void)
+{
+ tst_sysfs_cnt = 0;
+}
+
+unsigned int tst_sysfs_cnt_get(void)
+{
+ return tst_sysfs_cnt;
+}
--
2.56.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next reply other threads:[~2026-10-21 3:18 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-21 3:18 Li Wang (Hieco) [this message]
2026-10-21 3:18 ` [LTP] [PATCH v4 2/2] sys_hwmon01: always report a result Li Wang (Hieco)
2026-10-21 11:27 ` Cyril Hrubis
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=20261021031816.166499-1-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