alistair23-linux/tools/testing/selftests/bpf/urandom_read.c
Song Liu 81f77fd0de 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>
2018-03-15 01:10:02 +01:00

23 lines
337 B
C

#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;
}