AF_XDP-interaction: Add btf_unit_test

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
This commit is contained in:
Jesper Dangaard Brouer
2022-03-21 15:10:46 +01:00
parent f9095c5caf
commit 2b3fcf932d
3 changed files with 53 additions and 1 deletions

View File

@@ -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

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

View File

@@ -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;