strace/tests/kernel_version.c
Shankara Pailoor bf195a8455 bpf: honor xlat styles when printing kernel version
* print_kernel_version.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* defs.h (print_kernel_version): New prototype.
* bpf.c (BEGIN_BPF_CMD_DECODER(BPF_PROG_LOAD)):
Use print_kernel_version.
* tests/kernel_version.c: New file.
* tests/kernel_version-Xabbrev.c: Likewise.
* tests/kernel_version-Xraw.c: Likewise.
* tests/kernel_version-Xverbose.c: Likewise.
* tests/gen_tests.in (kernel_version, kernel_version-Xabbrev,
kernel_version-Xraw, kernel_version-Xverbose): New tests.
* tests/pure_executables.list: Add kernel_version,
kernel_version-Xabbrev, kernel_version-Xraw, and kernel_version-Xverbose.
* tests/.gitignore: Likewise.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
2018-12-10 23:45:11 +00:00

99 lines
1.8 KiB
C

/*
* Check kernel version decoding.
*
* Copyright (c) 2015-2018 The strace developers.
* All rights reserved.
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "tests.h"
#include <stddef.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <asm/unistd.h>
#include "scno.h"
#ifdef HAVE_LINUX_BPF_H
# include <linux/bpf.h>
#endif
#include "bpf_attr.h"
#include "print_fields.h"
#include "xlat.h"
#include "xlat/bpf_commands.h"
#define CMD_STR(x) #x
static const char *errstr;
static void
print_bpf_attr(void)
{
#if XLAT_RAW
printf("{prog_type=0x15"
#else
printf("{prog_type=0x15 /* BPF_PROG_TYPE_??? */"
#endif
", insn_cnt=3134983661"
", insns=NULL"
", license=NULL"
", log_level=24"
", log_size=3141592653"
", log_buf=NULL"
#if XLAT_RAW
", kern_version=0xcafef00d"
#elif XLAT_VERBOSE
", kern_version=0xcafef00d"
" /* KERNEL_VERSION(51966, 240, 13) */"
#else
", kern_version=KERNEL_VERSION(51966, 240, 13)"
#endif
", prog_flags=0"
", prog_name=\"\""
", prog_ifindex=0"
", expected_attach_type="
#if XLAT_RAW
"0}"
#elif XLAT_VERBOSE
"0 /* BPF_CGROUP_INET_INGRESS */}"
#else /* XLAT_ABBREV */
"BPF_CGROUP_INET_INGRESS}"
#endif
);
}
int
main(void)
{
long ret;
struct BPF_PROG_LOAD_struct prog = {
.prog_type = 21,
.insn_cnt = 0xbadc0ded,
.insns = 0,
.license = 0,
.log_level = 24,
.log_size = 3141592653U,
.log_buf = 0,
.kern_version = 0xcafef00d,
.prog_flags = 0,
};
ret = syscall(__NR_bpf, BPF_PROG_LOAD, &prog, sizeof(prog));
errstr = sprintrc(ret);
#if XLAT_RAW
printf("bpf(%#x, ", BPF_PROG_LOAD);
#elif XLAT_VERBOSE
printf("bpf(%#x /* %s */, ", BPF_PROG_LOAD, CMD_STR(BPF_PROG_LOAD));
#else
printf("bpf(%s, ", CMD_STR(BPF_PROG_LOAD));
#endif
print_bpf_attr();
printf(", %u) = %s\n", (unsigned int) sizeof(prog), errstr);
puts("+++ exited with 0 +++");
return 0;
}