From 5622356121e13556c8f9155a2118dec7aa9d59f4 Mon Sep 17 00:00:00 2001 From: Johannes Bechberger Date: Fri, 26 Jan 2024 18:25:36 +0100 Subject: [PATCH] Add GitHub CI and fix test runner bugs --- .github/workflows/ci.yml | 66 +++++++++++++++++++ README.md | 2 + .../main/java/me/bechberger/ebpf/bcc/BPF.java | 2 + testutil/bin/java | 7 +- testutil/find_and_get_kernel.py | 2 - testutil/run-in-container.sh | 6 ++ testutil/setup-and-run.sh | 10 ++- 7 files changed, 86 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..3749c0a --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,66 @@ +name: ci +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + build: + name: Build + runs-on: ubuntu-22.04 + timeout-minutes: 10 + steps: + - uses: actions/checkout@v4 + + - name: Setup Java 21 + uses: actions/setup-java@v4 + with: + java-version: '21' + distribution: 'adopt' + + - name: mvn package + run: mvn package -DskipTests + + - name: upload bcc/target/bcc.jar + uses: actions/upload-artifact@v4 + with: + name: bcc.jar + path: bcc/target/bcc.jar + + vm-test: + name: Run tests on pre-built kernel + runs-on: ubuntu-22.04 + needs: build + timeout-minutes: 10 + strategy: + matrix: + version: ["6.6"] + env: + HBT_KERNEL_VERSION: "${{ matrix.version }}" + steps: + - uses: actions/checkout@v4 + + - name: Set up Java + uses: actions/setup-java@v4 + with: + java-version: '21' + distribution: 'adopt' + + - run: sudo pip3 install https://github.com/amluto/virtme/archive/beb85146cd91de37ae455eccb6ab67c393e6e290.zip + - name: Test + run: | + sudo apt-get update && sudo apt-get install -y --no-install-recommends qemu-system-x86 bpfcc-tools linux-headers-$(uname -r) linux-cloud-tools-generic + ls /lib*/**/*bcc* + mvn test -Djvm=testutil/bin/java + + - name: Publish Test Report + uses: mikepenz/action-junit-report@v4 + if: always() + with: + check_name: 'Test Report (Kernel ${{ matrix.KERNEL_VERSION }})' + report_paths: '**/build/test-results/test/TEST-*.xml' \ No newline at end of file diff --git a/README.md b/README.md index 2c8b1b5..0462c29 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ Hello eBPF ========== +[![ci](https://github.com/parttimenerd/hello-ebpf/actions/workflows/ci.yml/badge.svg)](https://github.com/parttimenerd/hello-ebpf/actions/workflows/ci.yml) + There are [user land libraries](https://ebpf.io/what-is-ebpf/#development-toolchains) for [eBPF](https://ebpf.io) that allow you to write eBPF applications in C++, Rust, Go, Python and even Lua. But there are none for Java, which is a pity. diff --git a/bcc/src/main/java/me/bechberger/ebpf/bcc/BPF.java b/bcc/src/main/java/me/bechberger/ebpf/bcc/BPF.java index 58f4137..f1adf07 100644 --- a/bcc/src/main/java/me/bechberger/ebpf/bcc/BPF.java +++ b/bcc/src/main/java/me/bechberger/ebpf/bcc/BPF.java @@ -4,7 +4,9 @@ import me.bechberger.ebpf.bcc.raw.Lib; import org.jetbrains.annotations.Nullable; +import java.io.BufferedReader; import java.io.IOException; +import java.io.InputStreamReader; import java.lang.foreign.Arena; import java.lang.foreign.FunctionDescriptor; import java.lang.foreign.MemorySegment; diff --git a/testutil/bin/java b/testutil/bin/java index f72eaa6..e1fe4fe 100755 --- a/testutil/bin/java +++ b/testutil/bin/java @@ -6,7 +6,7 @@ # # Configuration per environment variables: # - `HBT_JAVA_BINARY` - the java binary to use (default: `java`) -# - `HBT_KERNEL_VERSION` - the kernel version to use (default: `6.7`) +# - `HBT_KERNEL_VERSION` - the kernel version to use (default: `6.6`) # see https://ghcr.io/cilium/ci-kernels for available versions # # Has to reside in bin/java so it can be passed to the `-Djvm` maven option. @@ -20,8 +20,7 @@ set -e HBT_JAVA_BINARY=${HBT_JAVA_BINARY:-java} # The kernel version to use -HBT_KERNEL_VERSION=${HBT_KERNEL_VERSION:-6.7} +HBT_KERNEL_VERSION=${HBT_KERNEL_VERSION:-6.6} testutil_dir=$(dirname "$0")/.. -$testutil_dir/run-in-container.sh $HBT_KERNEL_VERSION $HBT_JAVA_BINARY $@ -exit 0 \ No newline at end of file +$testutil_dir/run-in-container.sh $HBT_KERNEL_VERSION $HBT_JAVA_BINARY $@ \ No newline at end of file diff --git a/testutil/find_and_get_kernel.py b/testutil/find_and_get_kernel.py index c21af27..9c1f4d8 100755 --- a/testutil/find_and_get_kernel.py +++ b/testutil/find_and_get_kernel.py @@ -135,8 +135,6 @@ def copy_headers_into_dest(arch: str, version: str, dest_root: Path): argparse.add_argument("version", help="Kernel version") argparse.add_argument("destination", help="Destination folder") args = argparse.parse_args() - print( - f"Downloading headers for {args.version} (arch {get_arch()}) into {args.destination}") copy_headers_into_dest(get_arch(), args.version, Path(args.destination)) diff --git a/testutil/run-in-container.sh b/testutil/run-in-container.sh index 2d87c08..1be35d6 100755 --- a/testutil/run-in-container.sh +++ b/testutil/run-in-container.sh @@ -72,6 +72,12 @@ fi # get exact kernel version which is "$input/lib/modules//updates" kernel_version=$(basename "$(find "${input}/lib/modules" -maxdepth 1 -type d)") +# /lib is a symlink which causes problems +mkdir "$input"/lib2 +cp -r "$input"/lib/modules "$input"/lib2 +rm -r "$input"/lib +mv $input/lib2 $input/lib + "$script_folder"/find_and_get_kernel.py "${kernel_version}" "$input" mkdir -p "$input"/root diff --git a/testutil/setup-and-run.sh b/testutil/setup-and-run.sh index 8b4dd6b..59ef376 100644 --- a/testutil/setup-and-run.sh +++ b/testutil/setup-and-run.sh @@ -9,8 +9,12 @@ if [[ -d "/run/input/usr/src/linux/tools/testing/selftests/bpf" ]]; then export KERNEL_SELFTESTS="/run/input/usr/src/linux/tools/testing/selftests/bpf" fi -if [[ -d "/run/input/lib/modules" ]]; then - find /run/input/lib/modules -type f -name bpf_testmod.ko -exec insmod {} \; -fi +#if [[ -d "/run/input/lib/modules" ]]; then +# find /run/input/lib/modules -type f -name bpf_testmod.ko -exec insmod {} \; +#fi + +# used for debugging to check if bcc works at all +#script_dir="$(dirname "$(realpath "$0")")" +#timeout 5 python3 $script_dir/../pysamples/bcc/hello_world.py $* && touch /run/output/status \ No newline at end of file