From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Ingo Molnar <mingo@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
Beau Belgrave <beaub@linux.microsoft.com>
Subject: [for-next][PATCH 12/16] user_events: Add self-test for dynamic_events integration
Date: Fri, 18 Feb 2022 19:54:42 -0500 [thread overview]
Message-ID: <20220219005514.487353331@goodmis.org> (raw)
In-Reply-To: <20220219005430.848118506@goodmis.org>
From: Beau Belgrave <beaub@linux.microsoft.com>
Tests matching deletes, creation of basic and complex types. Ensures
common patterns work correctly when interacting with dynamic_events
file.
Link: https://lkml.kernel.org/r/20220118204326.2169-9-beaub@linux.microsoft.com
Acked-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Beau Belgrave <beaub@linux.microsoft.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
tools/testing/selftests/user_events/Makefile | 2 +-
.../testing/selftests/user_events/dyn_test.c | 130 ++++++++++++++++++
2 files changed, 131 insertions(+), 1 deletion(-)
create mode 100644 tools/testing/selftests/user_events/dyn_test.c
diff --git a/tools/testing/selftests/user_events/Makefile b/tools/testing/selftests/user_events/Makefile
index d66c551a6fe3..e824b9c2cae7 100644
--- a/tools/testing/selftests/user_events/Makefile
+++ b/tools/testing/selftests/user_events/Makefile
@@ -2,7 +2,7 @@
CFLAGS += -Wl,-no-as-needed -Wall -I../../../../usr/include
LDLIBS += -lrt -lpthread -lm
-TEST_GEN_PROGS = ftrace_test
+TEST_GEN_PROGS = ftrace_test dyn_test
TEST_FILES := settings
diff --git a/tools/testing/selftests/user_events/dyn_test.c b/tools/testing/selftests/user_events/dyn_test.c
new file mode 100644
index 000000000000..d6265d14cd51
--- /dev/null
+++ b/tools/testing/selftests/user_events/dyn_test.c
@@ -0,0 +1,130 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * User Events Dyn Events Test Program
+ *
+ * Copyright (c) 2021 Beau Belgrave <beaub@linux.microsoft.com>
+ */
+
+#include <errno.h>
+#include <linux/user_events.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include "../kselftest_harness.h"
+
+const char *dyn_file = "/sys/kernel/debug/tracing/dynamic_events";
+const char *clear = "!u:__test_event";
+
+static int Append(const char *value)
+{
+ int fd = open(dyn_file, O_RDWR | O_APPEND);
+ int ret = write(fd, value, strlen(value));
+
+ close(fd);
+ return ret;
+}
+
+#define CLEAR() \
+do { \
+ int ret = Append(clear); \
+ if (ret == -1) \
+ ASSERT_EQ(ENOENT, errno); \
+} while (0)
+
+#define TEST_PARSE(x) \
+do { \
+ ASSERT_NE(-1, Append(x)); \
+ CLEAR(); \
+} while (0)
+
+#define TEST_NPARSE(x) ASSERT_EQ(-1, Append(x))
+
+FIXTURE(user) {
+};
+
+FIXTURE_SETUP(user) {
+ CLEAR();
+}
+
+FIXTURE_TEARDOWN(user) {
+ CLEAR();
+}
+
+TEST_F(user, basic_types) {
+ /* All should work */
+ TEST_PARSE("u:__test_event u64 a");
+ TEST_PARSE("u:__test_event u32 a");
+ TEST_PARSE("u:__test_event u16 a");
+ TEST_PARSE("u:__test_event u8 a");
+ TEST_PARSE("u:__test_event char a");
+ TEST_PARSE("u:__test_event unsigned char a");
+ TEST_PARSE("u:__test_event int a");
+ TEST_PARSE("u:__test_event unsigned int a");
+ TEST_PARSE("u:__test_event short a");
+ TEST_PARSE("u:__test_event unsigned short a");
+ TEST_PARSE("u:__test_event char[20] a");
+ TEST_PARSE("u:__test_event unsigned char[20] a");
+ TEST_PARSE("u:__test_event char[0x14] a");
+ TEST_PARSE("u:__test_event unsigned char[0x14] a");
+ /* Bad size format should fail */
+ TEST_NPARSE("u:__test_event char[aa] a");
+ /* Large size should fail */
+ TEST_NPARSE("u:__test_event char[9999] a");
+ /* Long size string should fail */
+ TEST_NPARSE("u:__test_event char[0x0000000000001] a");
+}
+
+TEST_F(user, loc_types) {
+ /* All should work */
+ TEST_PARSE("u:__test_event __data_loc char[] a");
+ TEST_PARSE("u:__test_event __data_loc unsigned char[] a");
+ TEST_PARSE("u:__test_event __rel_loc char[] a");
+ TEST_PARSE("u:__test_event __rel_loc unsigned char[] a");
+}
+
+TEST_F(user, size_types) {
+ /* Should work */
+ TEST_PARSE("u:__test_event struct custom a 20");
+ /* Size not specified on struct should fail */
+ TEST_NPARSE("u:__test_event struct custom a");
+ /* Size specified on non-struct should fail */
+ TEST_NPARSE("u:__test_event char a 20");
+}
+
+TEST_F(user, flags) {
+ /* Should work */
+ TEST_PARSE("u:__test_event:BPF_ITER u32 a");
+ /* Forward compat */
+ TEST_PARSE("u:__test_event:BPF_ITER,FLAG_FUTURE u32 a");
+}
+
+TEST_F(user, matching) {
+ /* Register */
+ ASSERT_NE(-1, Append("u:__test_event struct custom a 20"));
+ /* Should not match */
+ TEST_NPARSE("!u:__test_event struct custom b");
+ /* Should match */
+ TEST_PARSE("!u:__test_event struct custom a");
+ /* Multi field reg */
+ ASSERT_NE(-1, Append("u:__test_event u32 a; u32 b"));
+ /* Non matching cases */
+ TEST_NPARSE("!u:__test_event u32 a");
+ TEST_NPARSE("!u:__test_event u32 b");
+ TEST_NPARSE("!u:__test_event u32 a; u32 ");
+ TEST_NPARSE("!u:__test_event u32 a; u32 a");
+ /* Matching case */
+ TEST_PARSE("!u:__test_event u32 a; u32 b");
+ /* Register */
+ ASSERT_NE(-1, Append("u:__test_event u32 a; u32 b"));
+ /* Ensure trailing semi-colon case */
+ TEST_PARSE("!u:__test_event u32 a; u32 b;");
+}
+
+int main(int argc, char **argv)
+{
+ return test_harness_run(argc, argv);
+}
--
2.34.1
next prev parent reply other threads:[~2022-02-19 0:57 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-19 0:54 [for-next][PATCH 00/16] tracing: Updates for 5.18 Steven Rostedt
2022-02-19 0:54 ` [for-next][PATCH 01/16] tracing: Remove size restriction on tracing_log_err cmd strings Steven Rostedt
2022-02-19 0:54 ` [for-next][PATCH 02/16] tracing: Remove size restriction on hist trigger cmd error logging Steven Rostedt
2022-02-19 0:54 ` [for-next][PATCH 03/16] tracing: Remove size restriction on synthetic event " Steven Rostedt
2022-02-19 0:54 ` [for-next][PATCH 04/16] tracing: Save both wakee and current on wakeup events Steven Rostedt
2022-02-19 0:54 ` [for-next][PATCH 05/16] user_events: Add minimal support for trace_event into ftrace Steven Rostedt
2022-02-19 0:54 ` [for-next][PATCH 06/16] user_events: Add print_fmt generation support for basic types Steven Rostedt
2022-02-19 0:54 ` [for-next][PATCH 07/16] user_events: Handle matching arguments from dyn_events Steven Rostedt
2022-02-19 0:54 ` [for-next][PATCH 08/16] user_events: Add basic perf and eBPF support Steven Rostedt
2022-02-19 0:54 ` [for-next][PATCH 09/16] user_events: Optimize writing events by only copying data once Steven Rostedt
2022-02-19 0:54 ` [for-next][PATCH 10/16] user_events: Validate user payloads for size and null termination Steven Rostedt
2022-02-19 0:54 ` [for-next][PATCH 11/16] user_events: Add self-test for ftrace integration Steven Rostedt
2022-02-19 0:54 ` Steven Rostedt [this message]
2022-02-19 0:54 ` [for-next][PATCH 13/16] user_events: Add self-test for perf_event integration Steven Rostedt
2022-02-19 0:54 ` [for-next][PATCH 14/16] user_events: Add self-test for validator boundaries Steven Rostedt
2022-02-19 0:54 ` [for-next][PATCH 15/16] user_events: Add sample code for typical usage Steven Rostedt
2022-02-19 0:54 ` [for-next][PATCH 16/16] user_events: Add documentation file Steven Rostedt
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=20220219005514.487353331@goodmis.org \
--to=rostedt@goodmis.org \
--cc=akpm@linux-foundation.org \
--cc=beaub@linux.microsoft.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=mingo@kernel.org \
/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®