From: wen.yang@linux.dev
To: Gabriele Monaco <gmonaco@redhat.com>
Cc: Nam Cao <namcao@linutronix.de>,
linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org,
Wen Yang <wen.yang@linux.dev>
Subject: [PATCH v7 12/14] rv: Add KUnit tests for the tlob monitor
Date: Mon, 12 Oct 2026 03:39:18 +0800 [thread overview]
Message-ID: <74239f278c36fe9b5cb2cf42869843cd8eca4f36.1791745088.git.wen.yang@linux.dev> (raw)
In-Reply-To: <cover.1791745088.git.wen.yang@linux.dev>
From: Wen Yang <wen.yang@linux.dev>
Add a test case to the shared rv_monitors_test.c suite covering
the uprobe-line parser in the tlob monitor.
Cases cover valid inputs, malformed paths and offsets (including
negative values), out-of-range thresholds, and valid and invalid
remove lines.
Suggested-by: Gabriele Monaco <gmonaco@redhat.com>
Signed-off-by: Wen Yang <wen.yang@linux.dev>
---
kernel/trace/rv/monitors/tlob/tlob.c | 11 ++
kernel/trace/rv/monitors/tlob/tlob_kunit.c | 151 +++++++++++++++++++++
kernel/trace/rv/monitors/tlob/tlob_kunit.h | 18 +++
kernel/trace/rv/rv_monitors_test.c | 2 +
4 files changed, 182 insertions(+)
create mode 100644 kernel/trace/rv/monitors/tlob/tlob_kunit.c
create mode 100644 kernel/trace/rv/monitors/tlob/tlob_kunit.h
diff --git a/kernel/trace/rv/monitors/tlob/tlob.c b/kernel/trace/rv/monitors/tlob/tlob.c
index 066a2f0663d5..159fc9a2c49e 100644
--- a/kernel/trace/rv/monitors/tlob/tlob.c
+++ b/kernel/trace/rv/monitors/tlob/tlob.c
@@ -863,6 +863,17 @@ static int tlob_parse_remove_line(char *buf, char **name_out)
return 0;
}
+#if IS_ENABLED(CONFIG_RV_MONITORS_KUNIT_TEST)
+#include <kunit/visibility.h>
+#include "tlob_kunit.h"
+
+const struct rv_tlob_kunit_ops rv_tlob_kunit_ops = {
+ .parse_uprobe_line = tlob_parse_uprobe_line,
+ .parse_remove_line = tlob_parse_remove_line,
+};
+EXPORT_SYMBOL_IF_KUNIT(rv_tlob_kunit_ops);
+#endif
+
static int tlob_create_or_delete_uprobe(char *buf)
{
loff_t offset_start, offset_stop;
diff --git a/kernel/trace/rv/monitors/tlob/tlob_kunit.c b/kernel/trace/rv/monitors/tlob/tlob_kunit.c
new file mode 100644
index 000000000000..06b212d1103b
--- /dev/null
+++ b/kernel/trace/rv/monitors/tlob/tlob_kunit.c
@@ -0,0 +1,151 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <linux/kernel.h>
+#include <linux/string.h>
+#include "tlob_kunit.h"
+
+#if IS_REACHABLE(CONFIG_RV_MON_TLOB)
+
+/* Valid "p:NAME PATH:START STOP threshold=NS" lines and what they decode to. */
+static const struct {
+ const char *line;
+ const char *name;
+ const char *path;
+ loff_t start;
+ loff_t stop;
+ u64 thr;
+} tlob_parse_valid[] = {
+ { "p:region /usr/bin/myapp:4768 4848 threshold=5000000",
+ "region", "/usr/bin/myapp", 4768, 4848, 5000000 },
+ /* Base 0: hex offsets must not decode as decimal. */
+ { "p:my_region_2 /usr/bin/myapp:0x12a0 0x12f0 threshold=10000000",
+ "my_region_2", "/usr/bin/myapp", 0x12a0, 0x12f0, 10000000 },
+ /* The last ':' separates the offset, so a ':' in PATH is fine. */
+ { "p:_r3 /opt/my:app/bin:0x100 0x200 threshold=1000000",
+ "_r3", "/opt/my:app/bin", 0x100, 0x200, 1000000 },
+ /* TLOB_MAX_NAME - 1 characters: the longest name accepted. */
+ { "p:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa /bin/a:0x100 0x200 threshold=5000",
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "/bin/a", 0x100, 0x200, 5000 },
+ /* The accepted threshold bounds themselves. */
+ { "p:lo /bin/a:0x100 0x200 threshold=1000",
+ "lo", "/bin/a", 0x100, 0x200, 1000 },
+ { "p:hi /bin/a:0x100 0x200 threshold=3600000000000",
+ "hi", "/bin/a", 0x100, 0x200, 3600000000000ULL },
+};
+
+/* Malformed "p:..." lines that must be rejected with -EINVAL. */
+static const char * const tlob_parse_invalid[] = {
+ "p /usr/bin/myapp:0x100 0x200 threshold=5000", /* no name */
+ "p:", /* empty name */
+ "p: /usr/bin/myapp:0x100 0x200 threshold=5000", /* name is a path */
+ "p:r /bin/a:0x100junk 0x200 threshold=5000", /* trailing junk */
+ "p:1region /usr/bin/myapp:0x100 0x200 threshold=5000", /* digit lead */
+ "p:my-win /usr/bin/myapp:0x100 0x200 threshold=5000", /* bad char */
+ "p:my.win /usr/bin/myapp:0x100 0x200 threshold=5000", /* bad char */
+ /* TLOB_MAX_NAME characters: one over the limit. */
+ "p:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa /bin/a:0x100 0x200 threshold=5000",
+ "p:region :0x100 0x200 threshold=5000", /* empty path */
+ "p:region /usr/bin/myapp:0x100 threshold=5000", /* missing stop */
+ "p:region /usr/bin/myapp:-1 0x200 threshold=5000", /* negative start */
+ "p:region /usr/bin/myapp:0x100 -1 threshold=5000000", /* negative stop */
+ "p:region /usr/bin/myapp:0x100 0x200", /* missing threshold */
+ "p:region /usr/bin/myapp:0x100 0x100 threshold=5000", /* start == stop */
+ /* Duplicate threshold=, like a duplicate offset, is an error. */
+ "p:region /bin/a:0x100 0x200 threshold=5000 threshold=9000",
+};
+
+/* threshold_ns out of valid range => -ERANGE. */
+static const char * const tlob_parse_out_of_range[] = {
+ "p:region /usr/bin/myapp:0x100 0x200 threshold=0",
+ "p:region /usr/bin/myapp:0x100 0x200 threshold=999",
+ "p:region /usr/bin/myapp:0x100 0x200 threshold=3600000000001",
+};
+
+/* Valid "-:NAME" remove lines. */
+static const char * const tlob_remove_valid[] = {
+ "-:region",
+ "-:my_region",
+};
+
+/* Malformed remove lines that must be rejected with -EINVAL. */
+static const char * const tlob_remove_invalid[] = {
+ "-", /* no name */
+ "-:", /* empty name */
+ "-region", /* missing ':' */
+ "-:my region", /* bad char */
+ "-:1region", /* digit lead */
+ "-:my-region", /* bad char */
+ "-:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", /* TLOB_MAX_NAME, one too many */
+};
+
+static void rv_test_tlob(struct kunit *test)
+{
+ u64 thr;
+ char *name, *path;
+ loff_t start, stop;
+ char buf[128];
+ int i, ret;
+
+ /* NAME and PATH come back NUL-terminated inside buf. */
+ strscpy(buf, "p:region /usr/bin/myapp:0x100 0x200 threshold=5000",
+ sizeof(buf));
+ ret = rv_tlob_kunit_ops.parse_uprobe_line(buf, &name, &path,
+ &start, &stop, &thr);
+ KUNIT_EXPECT_EQ(test, ret, 0);
+ KUNIT_EXPECT_STREQ(test, name, "region");
+ KUNIT_EXPECT_STREQ(test, path, "/usr/bin/myapp");
+
+ strscpy(buf, "-:region", sizeof(buf));
+ ret = rv_tlob_kunit_ops.parse_remove_line(buf, &name);
+ KUNIT_EXPECT_EQ(test, ret, 0);
+ KUNIT_EXPECT_STREQ(test, name, "region");
+
+ for (i = 0; i < ARRAY_SIZE(tlob_parse_valid); i++) {
+ strscpy(buf, tlob_parse_valid[i].line, sizeof(buf));
+ ret = rv_tlob_kunit_ops.parse_uprobe_line(buf, &name, &path,
+ &start, &stop,
+ &thr);
+ KUNIT_EXPECT_EQ(test, ret, 0);
+ if (ret)
+ continue;
+ KUNIT_EXPECT_STREQ(test, name, tlob_parse_valid[i].name);
+ KUNIT_EXPECT_STREQ(test, path, tlob_parse_valid[i].path);
+ KUNIT_EXPECT_EQ(test, start, tlob_parse_valid[i].start);
+ KUNIT_EXPECT_EQ(test, stop, tlob_parse_valid[i].stop);
+ KUNIT_EXPECT_EQ(test, thr, tlob_parse_valid[i].thr);
+ }
+
+ for (i = 0; i < ARRAY_SIZE(tlob_parse_invalid); i++) {
+ strscpy(buf, tlob_parse_invalid[i], sizeof(buf));
+ ret = rv_tlob_kunit_ops.parse_uprobe_line(buf, &name, &path,
+ &start, &stop,
+ &thr);
+ KUNIT_EXPECT_EQ(test, ret, -EINVAL);
+ }
+
+ for (i = 0; i < ARRAY_SIZE(tlob_parse_out_of_range); i++) {
+ strscpy(buf, tlob_parse_out_of_range[i], sizeof(buf));
+ ret = rv_tlob_kunit_ops.parse_uprobe_line(buf, &name, &path,
+ &start, &stop,
+ &thr);
+ KUNIT_EXPECT_EQ(test, ret, -ERANGE);
+ }
+
+ for (i = 0; i < ARRAY_SIZE(tlob_remove_valid); i++) {
+ strscpy(buf, tlob_remove_valid[i], sizeof(buf));
+ ret = rv_tlob_kunit_ops.parse_remove_line(buf, &name);
+ KUNIT_EXPECT_EQ(test, ret, 0);
+ if (!ret)
+ KUNIT_EXPECT_STREQ(test, name,
+ tlob_remove_valid[i] + 2);
+ }
+
+ for (i = 0; i < ARRAY_SIZE(tlob_remove_invalid); i++) {
+ strscpy(buf, tlob_remove_invalid[i], sizeof(buf));
+ ret = rv_tlob_kunit_ops.parse_remove_line(buf, &name);
+ KUNIT_EXPECT_EQ(test, ret, -EINVAL);
+ }
+}
+
+#else
+#define rv_test_tlob rv_test_stub
+#endif
diff --git a/kernel/trace/rv/monitors/tlob/tlob_kunit.h b/kernel/trace/rv/monitors/tlob/tlob_kunit.h
new file mode 100644
index 000000000000..c0c80c34f17b
--- /dev/null
+++ b/kernel/trace/rv/monitors/tlob/tlob_kunit.h
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __TLOB_KUNIT_H
+#define __TLOB_KUNIT_H
+
+#if IS_ENABLED(CONFIG_RV_MONITORS_KUNIT_TEST)
+
+#include <linux/types.h>
+
+extern const struct rv_tlob_kunit_ops {
+ int (*parse_uprobe_line)(char *buf, char **name_out, char **path_out,
+ loff_t *start_out, loff_t *stop_out,
+ u64 *thr_out);
+ int (*parse_remove_line)(char *buf, char **name_out);
+} rv_tlob_kunit_ops;
+
+#endif
+
+#endif /* __TLOB_KUNIT_H */
diff --git a/kernel/trace/rv/rv_monitors_test.c b/kernel/trace/rv/rv_monitors_test.c
index b30e49419e34..ee9fde63b291 100644
--- a/kernel/trace/rv/rv_monitors_test.c
+++ b/kernel/trace/rv/rv_monitors_test.c
@@ -309,6 +309,7 @@ static void rv_test_rvtest_arm_after_destroy(struct kunit *test)
#include "monitors/sts/sts_kunit.c"
#include "monitors/opid/opid_kunit.c"
#include "monitors/nomiss/nomiss_kunit.c"
+#include "monitors/tlob/tlob_kunit.c"
#include "monitors/pagefault/pagefault_kunit.c"
#include "monitors/sleep/sleep_kunit.c"
@@ -323,6 +324,7 @@ static struct kunit_case rv_mon_test_cases[] = {
KUNIT_CASE(rv_test_sleep),
KUNIT_CASE(rv_test_rvtest_underflow),
KUNIT_CASE(rv_test_rvtest_arm_after_destroy),
+ KUNIT_CASE(rv_test_tlob),
{}
};
--
2.25.1
next prev parent reply other threads:[~2026-10-11 19:40 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-11 19:39 [PATCH v7 00/14] rv: Add task latency over budget RV monitor wen.yang
2026-10-11 19:39 ` [PATCH v7 01/14] rv: Force environment reset action on HA monitor start wen.yang
2026-10-11 19:39 ` [PATCH v7 02/14] rv: Fix ha_monitor timer and invariant underflow wen.yang
2026-10-11 19:39 ` [PATCH v7 03/14] rv: Add a KUnit test for the HA timer underflow wen.yang
2026-10-12 7:47 ` kernel test robot
2026-10-11 19:39 ` [PATCH v7 04/14] rv: Disarm HA timers on the storage free path wen.yang
2026-10-11 19:39 ` [PATCH v7 05/14] rv: Add a KUnit test for " wen.yang
2026-10-11 19:39 ` [PATCH v7 06/14] rv: Make da_monitor_reset_hook and EVENT_NONE_LBL overridable wen.yang
2026-10-11 19:39 ` [PATCH v7 07/14] rv: Introduce DA_MON_ALLOCATION_STRATEGY wen.yang
2026-10-11 19:39 ` [PATCH v7 08/14] rv: Add per-object teardown hook da_extra_cleanup wen.yang
2026-10-11 19:39 ` [PATCH v7 09/14] rv: Add generic uprobe infrastructure for RV monitors wen.yang
2026-10-11 19:39 ` [PATCH v7 10/14] rv: Add tlob model DOT file wen.yang
2026-10-11 19:39 ` [PATCH v7 11/14] rv: Add tlob hybrid automaton monitor wen.yang
2026-10-11 19:39 ` wen.yang [this message]
2026-10-11 19:39 ` [PATCH v7 13/14] selftests/verification: Add tlob selftests wen.yang
2026-10-11 19:39 ` [PATCH v7 14/14] selftests/ftrace: Walk up parent dirs to find test.d/functions wen.yang
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=74239f278c36fe9b5cb2cf42869843cd8eca4f36.1791745088.git.wen.yang@linux.dev \
--to=wen.yang@linux.dev \
--cc=gmonaco@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=namcao@linutronix.de \
/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
all inboxes | Powered by JetHome®