mirror of
https://github.com/torvalds/linux.git
synced 2026-04-18 06:44:00 -04:00
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
This commit is contained in:
committed by
Alexei Starovoitov
parent
ac5a72ea5c
commit
59e8b60bf0
21
tools/testing/selftests/bpf/progs/trace_printk.c
Normal file
21
tools/testing/selftests/bpf/progs/trace_printk.c
Normal file
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user