From 77901accf27a1ca6a8a5c90b7b0eea3ab78094d8 Mon Sep 17 00:00:00 2001 From: varun-r-mallya Date: Sun, 30 Nov 2025 05:51:06 +0530 Subject: [PATCH] fix xdp test c form test Signed-off-by: varun-r-mallya --- BCC-Examples/disksnoop.py | 3 ++- tests/c-form/Makefile | 4 ++-- tests/c-form/xdp_test.bpf.c | 26 ++++++++++++-------------- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/BCC-Examples/disksnoop.py b/BCC-Examples/disksnoop.py index a068544..73a737b 100644 --- a/BCC-Examples/disksnoop.py +++ b/BCC-Examples/disksnoop.py @@ -1,5 +1,5 @@ from vmlinux import struct_request, struct_pt_regs -from pythonbpf import bpf, section, bpfglobal, compile_to_ir, compile, map +from pythonbpf import bpf, section, bpfglobal, compile, map from pythonbpf.helper import ktime from pythonbpf.maps import HashMap from ctypes import c_int64, c_uint64, c_int32 @@ -54,4 +54,5 @@ def trace_start(ctx1: struct_pt_regs) -> c_int32: def LICENSE() -> str: return "GPL" + compile() diff --git a/tests/c-form/Makefile b/tests/c-form/Makefile index a34deba..d79179f 100644 --- a/tests/c-form/Makefile +++ b/tests/c-form/Makefile @@ -1,5 +1,5 @@ BPF_CLANG := clang -CFLAGS := -emit-llvm -target bpf -c +CFLAGS := -emit-llvm -target bpf -c -D__TARGET_ARCH_x86 SRC := $(wildcard *.bpf.c) LL := $(SRC:.bpf.c=.bpf.ll) @@ -10,7 +10,7 @@ LL0 := $(SRC:.bpf.c=.bpf.o0.ll) all: $(LL) $(OBJ) $(LL0) %.bpf.o: %.bpf.c - $(BPF_CLANG) -O2 -g -target bpf -c $< -o $@ + $(BPF_CLANG) -O2 -D__TARGET_ARCH_x86 -g -target bpf -c $< -o $@ %.bpf.ll: %.bpf.c $(BPF_CLANG) $(CFLAGS) -O2 -g -S $< -o $@ diff --git a/tests/c-form/xdp_test.bpf.c b/tests/c-form/xdp_test.bpf.c index c039e11..9b438ea 100644 --- a/tests/c-form/xdp_test.bpf.c +++ b/tests/c-form/xdp_test.bpf.c @@ -1,18 +1,16 @@ -#include -#include -#include +#include "vmlinux.h" #include struct fake_iphdr { - unsigned short useless; - unsigned short tot_len; - unsigned short id; - unsigned short frag_off; - unsigned char ttl; - unsigned char protocol; - unsigned short check; - unsigned int saddr; - unsigned int daddr; + unsigned short useless; + unsigned short tot_len; + unsigned short id; + unsigned short frag_off; + unsigned char ttl; + unsigned char protocol; + unsigned short check; + unsigned int saddr; + unsigned int daddr; }; SEC("xdp") @@ -25,9 +23,9 @@ int xdp_prog(struct xdp_md *ctx) { } struct fake_iphdr *iph = (void *)data + sizeof(struct ethhdr); - bpf_printk("%d", iph->saddr); + bpf_printk("%d", iph->saddr); - return XDP_PASS; + return XDP_PASS; } char _license[] SEC("license") = "GPL";