aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/bpf/urandom_read.c
diff options
context:
space:
mode:
authorSong Liu <songliubraving@fb.com>2018-03-14 10:23:22 -0700
committerDaniel Borkmann <daniel@iogearbox.net>2018-03-15 01:10:02 +0100
commit81f77fd0deeb866d65ccc79733df8d2af5217c82 (patch)
treebebe74af6f86ad63719e1d50442482a51a6beedf /tools/testing/selftests/bpf/urandom_read.c
parentbpf: extend stackmap to save binary_build_id+offset instead of address (diff)
downloadlinux-dev-81f77fd0deeb866d65ccc79733df8d2af5217c82.tar.xz
linux-dev-81f77fd0deeb866d65ccc79733df8d2af5217c82.zip
bpf: add selftest for stackmap with BPF_F_STACK_BUILD_ID
test_stacktrace_build_id() is added. It accesses tracepoint urandom_read with "dd" and "urandom_read" and gathers stack traces. Then it reads the stack traces from the stackmap. urandom_read is a statically link binary that reads from /dev/urandom. test_stacktrace_build_id() calls readelf to read build ID of urandom_read and compares it with build ID from the stackmap. Signed-off-by: Song Liu <songliubraving@fb.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to '')
-rw-r--r--tools/testing/selftests/bpf/urandom_read.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/urandom_read.c b/tools/testing/selftests/bpf/urandom_read.c
new file mode 100644
index 000000000000..4acfdebf36fa
--- /dev/null
+++ b/tools/testing/selftests/bpf/urandom_read.c
@@ -0,0 +1,22 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdlib.h>
+
+#define BUF_SIZE 256
+int main(void)
+{
+ int fd = open("/dev/urandom", O_RDONLY);
+ int i;
+ char buf[BUF_SIZE];
+
+ if (fd < 0)
+ return 1;
+ for (i = 0; i < 4; ++i)
+ read(fd, buf, BUF_SIZE);
+
+ close(fd);
+ return 0;
+}