mirror of
https://github.com/xdp-project/bpf-examples.git
synced 2024-05-06 15:54:53 +00:00
AF_XDP-interaction: Add btf_unit_test
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
|
||||
|
||||
USER_TARGETS := af_xdp_user
|
||||
USER_TARGETS += btf_unit_test
|
||||
BPF_TARGETS := af_xdp_kern
|
||||
|
||||
# Define C-code objects USER_TARGETS needs
|
||||
|
51
AF_XDP-interaction/btf_unit_test.c
Normal file
51
AF_XDP-interaction/btf_unit_test.c
Normal file
@@ -0,0 +1,51 @@
|
||||
/* Code exercising BTF userspace decoding */
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include <bpf/bpf.h>
|
||||
#include <bpf/libbpf.h>
|
||||
|
||||
#include <bpf/btf.h> /* provided by libbpf */
|
||||
|
||||
#include "lib_xsk_extend.h"
|
||||
|
||||
/* Exit return codes - can be used by scripts looking at exit code */
|
||||
#define EXIT_OK 0 /* == EXIT_SUCCESS (stdlib.h) man exit(3) */
|
||||
#define EXIT_FAIL 1 /* == EXIT_FAILURE (stdlib.h) man exit(3) */
|
||||
#define EXIT_FAIL_OPTION 2
|
||||
#define EXIT_FAIL_XDP 3
|
||||
#define EXIT_FAIL_BPF 4
|
||||
#define EXIT_FAIL_BTF 5
|
||||
|
||||
struct bpf_object *load_bpf_object() {
|
||||
struct bpf_object *obj;
|
||||
char buf[100];
|
||||
int err;
|
||||
|
||||
obj = bpf_object__open_file("af_xdp_kern.o", NULL);
|
||||
err = libbpf_get_error(obj);
|
||||
if (err) {
|
||||
libbpf_strerror(err, buf, sizeof(buf));
|
||||
printf("Error opening file: %s\n", buf);
|
||||
return NULL;
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct bpf_object *bpf_obj;
|
||||
// int err = 0;
|
||||
|
||||
bpf_obj = load_bpf_object();
|
||||
if (!bpf_obj)
|
||||
return EXIT_FAIL_BPF;
|
||||
|
||||
return EXIT_OK;
|
||||
}
|
||||
|
||||
|
@@ -216,7 +216,7 @@ int xsk_btf__init_xdp_hint(struct btf *btf_obj,
|
||||
if (err)
|
||||
goto error_entry;
|
||||
|
||||
/* TODO: Validate 'btf_id' member is last member */
|
||||
/* TODO: Validate 'btf_id' is last member */
|
||||
|
||||
return 0;
|
||||
|
||||
|
Reference in New Issue
Block a user