mirror of
https://github.com/torvalds/linux.git
synced 2026-11-06 21:58:01 +01:00
tracing: Add a test for ftrace_parse_event_string()
The parsing logic is a bit complicated and about to become more so. Add a unit test to avoid regressions. Link: https://patch.msgid.link/20260908-tracing-cli-event-filter-v2-5-05396a3fb663@linutronix.de Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
This commit is contained in:
parent
f572b5d914
commit
cc879c2b6c
|
|
@ -151,6 +151,14 @@ config EVENT_TRACING
|
|||
select GLOB
|
||||
bool
|
||||
|
||||
config EVENT_TRACING_TEST
|
||||
tristate "Test for event tracing" if !KUNIT_ALL_TESTS
|
||||
depends on EVENT_TRACING
|
||||
depends on KUNIT
|
||||
default KUNIT_ALL_TESTS
|
||||
help
|
||||
KUnit test for the event tracing implementation.
|
||||
|
||||
config CONTEXT_SWITCH_TRACER
|
||||
bool
|
||||
|
||||
|
|
|
|||
|
|
@ -96,6 +96,7 @@ obj-$(CONFIG_EVENT_TRACING) += blktrace.o
|
|||
endif
|
||||
obj-$(CONFIG_EVENT_TRACING) += trace_events.o
|
||||
obj-$(CONFIG_EVENT_TRACING) += trace_export.o
|
||||
obj-$(CONFIG_EVENT_TRACING_TEST) += trace_events_test.o
|
||||
obj-$(CONFIG_FTRACE_SYSCALLS) += trace_syscalls.o
|
||||
ifeq ($(CONFIG_PERF_EVENTS),y)
|
||||
obj-$(CONFIG_EVENT_TRACING) += trace_event_perf.o
|
||||
|
|
|
|||
|
|
@ -2509,3 +2509,7 @@ static inline int rv_init_interface(void)
|
|||
})
|
||||
|
||||
#endif /* _LINUX_KERNEL_TRACE_H */
|
||||
|
||||
#if IS_ENABLED(CONFIG_KUNIT)
|
||||
void ftrace_parse_event_string(char *buf, char **match, char **sub, char **event, char **mod);
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -25,6 +25,8 @@
|
|||
#include <linux/delay.h>
|
||||
#include <linux/btf.h>
|
||||
|
||||
#include <kunit/visibility.h>
|
||||
|
||||
#include <trace/events/sched.h>
|
||||
#include <trace/syscall.h>
|
||||
|
||||
|
|
@ -1443,7 +1445,7 @@ static int __ftrace_set_clr_event(struct trace_array *tr, const char *match,
|
|||
return ret;
|
||||
}
|
||||
|
||||
static void
|
||||
VISIBLE_IF_KUNIT void
|
||||
ftrace_parse_event_string(char *buf, char **match, char **sub, char **event, char **mod)
|
||||
{
|
||||
*event = NULL;
|
||||
|
|
@ -1485,6 +1487,7 @@ ftrace_parse_event_string(char *buf, char **match, char **sub, char **event, cha
|
|||
*match = NULL;
|
||||
}
|
||||
}
|
||||
EXPORT_SYMBOL_IF_KUNIT(ftrace_parse_event_string);
|
||||
|
||||
int ftrace_set_clr_event(struct trace_array *tr, const char *arg_buf, int set)
|
||||
{
|
||||
|
|
|
|||
102
kernel/trace/trace_events_test.c
Normal file
102
kernel/trace/trace_events_test.c
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
#include <linux/module.h>
|
||||
|
||||
#include <kunit/test.h>
|
||||
|
||||
#include "trace.h"
|
||||
|
||||
struct parse_event_string_test_case {
|
||||
const char *input;
|
||||
|
||||
const char *match, *sub, *event, *mod;
|
||||
};
|
||||
|
||||
static const struct parse_event_string_test_case parse_event_string_test_cases[] = {
|
||||
{
|
||||
"",
|
||||
.match = "",
|
||||
},
|
||||
{
|
||||
"*:event",
|
||||
.event = "event",
|
||||
},
|
||||
{
|
||||
":event",
|
||||
.event = "event",
|
||||
},
|
||||
{
|
||||
"sub:*",
|
||||
.sub = "sub",
|
||||
},
|
||||
{
|
||||
"sub:",
|
||||
.sub = "sub",
|
||||
},
|
||||
{
|
||||
"sub:event",
|
||||
.sub = "sub",
|
||||
.event = "event",
|
||||
},
|
||||
{
|
||||
"match",
|
||||
.match = "match",
|
||||
},
|
||||
{
|
||||
":mod:module",
|
||||
.mod = "module",
|
||||
},
|
||||
{
|
||||
"sub:event:mod:module",
|
||||
.sub = "sub",
|
||||
.event = "event",
|
||||
.mod = "module",
|
||||
},
|
||||
};
|
||||
|
||||
static void
|
||||
parse_event_string_test_desc(const struct parse_event_string_test_case *params, char *desc)
|
||||
{
|
||||
snprintf(desc, KUNIT_PARAM_DESC_SIZE, "'%s'", params->input);
|
||||
}
|
||||
|
||||
KUNIT_ARRAY_PARAM(parse_event_string, parse_event_string_test_cases, parse_event_string_test_desc);
|
||||
|
||||
#define EXPECT_NULL_OR_STR_EQ(test, left, right) \
|
||||
({ \
|
||||
if ((left) != NULL) \
|
||||
KUNIT_EXPECT_STREQ(test, (left), (right)); \
|
||||
else \
|
||||
KUNIT_EXPECT_NULL(test, (right)); \
|
||||
})
|
||||
|
||||
static void parse_event_string(struct kunit *test)
|
||||
{
|
||||
const struct parse_event_string_test_case *params = test->param_value;
|
||||
char *input, *match, *sub, *event, *mod;
|
||||
|
||||
input = kunit_kstrdup(test, params->input, GFP_KERNEL);
|
||||
if (!input)
|
||||
kunit_skip(test, "ENOMEM");
|
||||
|
||||
ftrace_parse_event_string(input, &match, &sub, &event, &mod);
|
||||
|
||||
EXPECT_NULL_OR_STR_EQ(test, match, params->match);
|
||||
EXPECT_NULL_OR_STR_EQ(test, sub, params->sub);
|
||||
EXPECT_NULL_OR_STR_EQ(test, event, params->event);
|
||||
EXPECT_NULL_OR_STR_EQ(test, mod, params->mod);
|
||||
}
|
||||
|
||||
static struct kunit_case trace_events_test_cases[] = {
|
||||
KUNIT_CASE_PARAM(parse_event_string, parse_event_string_gen_params),
|
||||
{}
|
||||
};
|
||||
|
||||
static struct kunit_suite trace_events_test_suite = {
|
||||
.name = "trace-events",
|
||||
.test_cases = trace_events_test_cases,
|
||||
};
|
||||
kunit_test_suite(trace_events_test_suite);
|
||||
|
||||
MODULE_DESCRIPTION("KUnit test for the event tracing implementation");
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_IMPORT_NS("EXPORTED_FOR_KUNIT_TESTING");
|
||||
Loading…
Reference in New Issue
Block a user