From 2385588d352f2da3c0816f6ab9db289e33777155 Mon Sep 17 00:00:00 2001
From: Tamir Duberstein <tamird@gmail.com>
Date: Wed, 9 Aug 2023 17:04:03 -0400
Subject: [PATCH] github: run integration tests on local kernel

This tests on 5.15.0-1041-azure.
---
 .github/workflows/ci.yml                       | 6 +++++-
 test/integration-test/src/tests/relocations.rs | 8 +++++++-
 test/integration-test/src/tests/smoke.rs       | 9 +++++----
 3 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index e9eece29..2e61f8b6 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -235,7 +235,11 @@ jobs:
           find test/.tmp -name '*.deb' -print0 | xargs -t -0 -I {} \
             sh -c "dpkg --fsys-tarfile {} | tar -C test/.tmp --wildcards --extract '*vmlinuz*' --file -"
 
-      - name: Run integration tests
+      - name: Run local integration tests
+        if: runner.os == 'Linux'
+        run: cargo xtask integration-test local
+
+      - name: Run virtualized integration tests
         run: find test/.tmp -name 'vmlinuz-*' | xargs -t cargo xtask integration-test vm
 
   # Provides a single status check for the entire build workflow.
diff --git a/test/integration-test/src/tests/relocations.rs b/test/integration-test/src/tests/relocations.rs
index 1b550e9f..98cecfcf 100644
--- a/test/integration-test/src/tests/relocations.rs
+++ b/test/integration-test/src/tests/relocations.rs
@@ -1,6 +1,6 @@
 use std::time::Duration;
 
-use aya::{programs::UProbe, Bpf};
+use aya::{programs::UProbe, util::KernelVersion, Bpf};
 
 #[test]
 fn relocations() {
@@ -17,6 +17,12 @@ fn relocations() {
 
 #[test]
 fn text_64_64_reloc() {
+    let kernel_version = KernelVersion::current().unwrap();
+    if kernel_version < KernelVersion::new(5, 13, 0) {
+        eprintln!("skipping test on kernel {kernel_version:?}, support for bpf_for_each_map_elem was added in 5.13.0; see https://github.com/torvalds/linux/commit/69c087b");
+        return;
+    }
+
     let mut bpf = load_and_attach("test_text_64_64_reloc", crate::TEXT_64_64_RELOC);
 
     let mut m = aya::maps::Array::<_, u64>::try_from(bpf.map_mut("RESULTS").unwrap()).unwrap();
diff --git a/test/integration-test/src/tests/smoke.rs b/test/integration-test/src/tests/smoke.rs
index 78614bd9..64782e94 100644
--- a/test/integration-test/src/tests/smoke.rs
+++ b/test/integration-test/src/tests/smoke.rs
@@ -8,14 +8,14 @@ use crate::utils::NetNsGuard;
 
 #[test]
 fn xdp() {
-    let _netns = NetNsGuard::new();
-
     let kernel_version = KernelVersion::current().unwrap();
     if kernel_version < KernelVersion::new(5, 18, 0) {
         eprintln!("skipping test on kernel {kernel_version:?}, support for BPF_F_XDP_HAS_FRAGS was added in 5.18.0; see https://github.com/torvalds/linux/commit/c2f2cdb");
         return;
     }
 
+    let _netns = NetNsGuard::new();
+
     let mut bpf = Bpf::load(crate::PASS).unwrap();
     let dispatcher: &mut Xdp = bpf.program_mut("pass").unwrap().try_into().unwrap();
     dispatcher.load().unwrap();
@@ -46,13 +46,14 @@ fn two_progs() {
 
 #[test]
 fn extension() {
-    let _netns = NetNsGuard::new();
-
     let kernel_version = KernelVersion::current().unwrap();
     if kernel_version < KernelVersion::new(5, 9, 0) {
         eprintln!("skipping test on kernel {kernel_version:?}, XDP uses netlink");
         return;
     }
+
+    let _netns = NetNsGuard::new();
+
     let mut bpf = Bpf::load(crate::MAIN).unwrap();
     let pass: &mut Xdp = bpf.program_mut("xdp_pass").unwrap().try_into().unwrap();
     pass.load().unwrap();