summaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/bpf/progs/trace_printk.c
diff options
context:
space:
mode:
authorAlan Maguire <alan.maguire@oracle.com>2020-07-13 12:52:34 +0100
committerAlexei Starovoitov <ast@kernel.org>2020-07-13 16:55:49 -0700
commit59e8b60bf068180fcadb0ae06ce8f6f835132ce6 (patch)
tree9add8fdea634ba08ed2a57cae8da34e497eed9e5 /tools/testing/selftests/bpf/progs/trace_printk.c
parentac5a72ea5c8989871e61f6bb0852e0f91de51ebe (diff)
downloadlinux-stable-59e8b60bf068180fcadb0ae06ce8f6f835132ce6.tar.gz
linux-stable-59e8b60bf068180fcadb0ae06ce8f6f835132ce6.tar.bz2
linux-stable-59e8b60bf068180fcadb0ae06ce8f6f835132ce6.zip
selftests/bpf: Add selftests verifying bpf_trace_printk() behaviour
Simple selftests that verifies bpf_trace_printk() returns a sensible value and tracing messages appear. Signed-off-by: Alan Maguire <alan.maguire@oracle.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Andrii Nakryiko <andriin@fb.com> Link: https://lore.kernel.org/bpf/1594641154-18897-3-git-send-email-alan.maguire@oracle.com
Diffstat (limited to 'tools/testing/selftests/bpf/progs/trace_printk.c')
-rw-r--r--tools/testing/selftests/bpf/progs/trace_printk.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/progs/trace_printk.c b/tools/testing/selftests/bpf/progs/trace_printk.c
new file mode 100644
index 000000000000..8ca7f399b670
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/trace_printk.c
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2020, Oracle and/or its affiliates.
+
+#include "vmlinux.h"
+#include <bpf/bpf_helpers.h>
+#include <bpf/bpf_tracing.h>
+
+char _license[] SEC("license") = "GPL";
+
+int trace_printk_ret = 0;
+int trace_printk_ran = 0;
+
+SEC("tp/raw_syscalls/sys_enter")
+int sys_enter(void *ctx)
+{
+ static const char fmt[] = "testing,testing %d\n";
+
+ trace_printk_ret = bpf_trace_printk(fmt, sizeof(fmt),
+ ++trace_printk_ran);
+ return 0;
+}