Browse Source

integration-test: avoid reliance on kernel headers

This should allow us to build on any system.
Tamir Duberstein 1 year ago
parent
commit
71bc3ea0b5

+ 1 - 1
test/integration-test/bpf/ext.bpf.c

@@ -1,5 +1,5 @@
 // clang-format off
-#include <linux/bpf.h>
+#include <vmlinux.h>
 #include <bpf/bpf_helpers.h>
 // clang-format on
 

+ 1 - 1
test/integration-test/bpf/main.bpf.c

@@ -1,5 +1,5 @@
 // clang-format off
-#include <linux/bpf.h>
+#include <vmlinux.h>
 #include <bpf/bpf_helpers.h>
 // clang-format on
 

+ 1 - 1
test/integration-test/bpf/multimap-btf.bpf.c

@@ -1,5 +1,5 @@
 // clang-format off
-#include <linux/bpf.h>
+#include <vmlinux.h>
 #include <bpf/bpf_helpers.h>
 // clang-format on
 

+ 1 - 1
test/integration-test/bpf/reloc.bpf.c

@@ -1,5 +1,5 @@
 // clang-format off
-#include <linux/bpf.h>
+#include <vmlinux.h>
 #include <bpf/bpf_helpers.h>
 #include <bpf/bpf_core_read.h>
 // clang-format on

+ 1 - 1
test/integration-test/bpf/reloc.btf.c

@@ -1,5 +1,5 @@
 // clang-format off
-#include <linux/bpf.h>
+#include <vmlinux.h>
 #include <bpf/bpf_helpers.h>
 #include <bpf/bpf_core_read.h>
 // clang-format on

+ 1 - 1
test/integration-test/bpf/text_64_64_reloc.c

@@ -1,5 +1,5 @@
 // clang-format off
-#include <linux/bpf.h>
+#include <vmlinux.h>
 #include <bpf/bpf_helpers.h>
 // clang-format on
 

+ 13 - 1
test/integration-test/build.rs

@@ -116,10 +116,22 @@ fn main() {
             target_arch.push(arch);
         };
 
+        // NB: libbpf's documentation suggests that vmlinux.h be generated by running `bpftool btf
+        // dump file /sys/kernel/btf/vmlinux format c`; this allows CO-RE to work.
+        //
+        // However in our tests we do not make use of kernel data structures, and so any vmlinux.h
+        // which defines the constants we need (e.g. `__u8`, `__u64`, `BPF_MAP_TYPE_ARRAY`,
+        // `BPF_ANY`, `XDP_PASS`, `XDP_DROP`, etc.) will suffice. Since we already have a libbpf
+        // submodule which happens to include such a file, we use it.
+        let libbpf_vmlinux_dir = libbpf_dir.join(".github/actions/build-selftests");
+
         let clang = || {
             let mut cmd = Command::new("clang");
-            cmd.arg("-I")
+            cmd.arg("-nostdlibinc")
+                .arg("-I")
                 .arg(&libbpf_headers_dir)
+                .arg("-I")
+                .arg(&libbpf_vmlinux_dir)
                 .args(["-g", "-O2", "-target", target, "-c"])
                 .arg(&target_arch);
             cmd