Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CI #12

Merged
merged 20 commits into from
Jan 29, 2025
91 changes: 28 additions & 63 deletions .github/workflows/builtAndTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,92 +6,57 @@ on:
pull_request:

env:
BUILD_DIR: build
PCAPPLUSPLUS_LATEST_VERSION: 24.09

jobs:
build-and-test:
strategy:
matrix:
include:
- run-on-os: ubuntu-latest
target: armeabi-v7a
api-version: 35
# - run-on-os: ubuntu-20.04
# target: x86
# api-version: 30
# - run-on-os: macos-15
# target: arm64-v8a
# cmake_configure: "-DCMAKE_OSX_ARCHITECTURES=arm64"
# api-version: 30
# - run-on-os: macos-15
# target: x86_64
# cmake_configure: "-DCMAKE_OSX_ARCHITECTURES=x86_64"
# api-version: 30
api-level: [30, 33, 35]

runs-on: ${{ matrix.run-on-os }}
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Checkout lipbcap for Android
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # main
with:
repository: seladb/libpcap-android
path: ./libpcap-android

- name: Configure PcapPlusPlus
run: |
LIBPCAP_PATH=$(pwd)/libpcap-android
cmake -DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK}/build/cmake/android.toolchain.cmake" -DANDROID_PLATFORM="${{ matrix.api-version}}" -DANDROID_ABI="${{ matrix.target }}" -DPCAP_INCLUDE_DIR="${LIBPCAP_PATH}/include/" -DPCAP_LIBRARY="${LIBPCAP_PATH}/${{ matrix.target }}/${{ matrix.api-version}}/libpcap.a" -S . -B "$BUILD_DIR"

- name: Build PcapPlusPlus
run: cmake --build "$BUILD_DIR" -j
submodules: true

- name: Checkout ToyVpn-PcapPlusPlus
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # master
- name: Download PcapPlusPlus
uses: robinraju/release-downloader@v1
with:
repository: seladb/ToyVpn-PcapPlusPlus
path: ./ToyVpn-PcapPlusPlus
submodules: true
repository: "seladb/PcapPlusPlus"
tag: "v${{env.PCAPPLUSPLUS_LATEST_VERSION}}"
fileName: "pcapplusplus-${{env.PCAPPLUSPLUS_LATEST_VERSION}}-android.tar.gz"
out-file-path: "app/libs"
tarBall: true
extract: true

- name: Install locally PcapPlusPlus
# CMake install library in $prefix/lib ToyVpn want $prefix/$target/$api-version
run: |
TOYVPN_PCAPPLUSPLUS="./ToyVpn-PcapPlusPlus/app/libs/pcapplusplus"
PCAPPLUSPLUS_LIBS_PATH="$TOYVPN_PCAPPLUSPLUS/${{ matrix.target }}/${{ matrix.api-version }}"
PCAPPLUSPLUS_INCLUDE_PATH="$TOYVPN_PCAPPLUSPLUS/include"
cmake -DPCAPPP_BUILD_COVERAGE=OFF -S . -B "$BUILD_DIR"
cmake --build "$BUILD_DIR" -j
cmake --install "$BUILD_DIR" --prefix ${TOYVPN_PCAPPLUSPLUS}
mkdir -p ${PCAPPLUSPLUS_LIBS_PATH} ${PCAPPLUSPLUS_INCLUDE_PATH}
mv ${TOYVPN_PCAPPLUSPLUS}/lib/*.a ${PCAPPLUSPLUS_LIBS_PATH}/
mv ${TOYVPN_PCAPPLUSPLUS}/include/pcapplusplus/*.h ${PCAPPLUSPLUS_INCLUDE_PATH}/
- name: Rename PcapPlusPlus directory
run: mv $GITHUB_WORKSPACE/app/libs/pcapplusplus-${PCAPPLUSPLUS_LATEST_VERSION}-android $GITHUB_WORKSPACE/app/libs/pcapplusplus

- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: "11"
java-version: "17"
distribution: "zulu"
cache: "gradle"

- name: Change wrapper permissions
run: chmod +x ./gradlew

- name: Build gradle project
- name: Build gradle project and run tests
run: ./gradlew build

# - name: Build ToyVpn-PcapPlusPlus
# working-directory: ./ToyVpn-PcapPlusPlus
# run: |
# NDK_VERSION=$(echo "$ANDROID_NDK" | awk -F'/' '{print $NF}')
# sed -i.bak "s|abiFilters.*$|abiFilters '${{ matrix.target }}'|g" app/build.gradle
# if [[ "${{ matrix.run-on-os }}" == "macos"* ]]; then
# sed -i.bak "/defaultConfig {/a\\
# ndkVersion \"$NDK_VERSION\"
# " app/build.gradle
# else
# sed -i "/defaultConfig {/a\\ ndkVersion \"$NDK_VERSION\"" app/build.gradle
# fi
# chmod +x gradlew
# ./gradlew assembleDebug
- name: Enable KVM
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm

- name: Run instrumentation tests
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ matrix.api-level }}
arch: x86_64
script: ./gradlew -is connectedCheck
5 changes: 5 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,9 @@ dependencies {

tasks.withType<Test> {
useJUnitPlatform()
testLogging {
showStandardStreams = true
events("passed", "skipped", "failed")
exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.pcapplusplus.toyvpn

import kotlinx.coroutines.delay

suspend fun waitFor(condition: () -> Boolean, timeoutMillis: Long = 5000L) {
suspend fun waitFor(condition: () -> Boolean, timeoutMillis: Long = 10000L) {
var elapsedTime = 0L
while (!condition() && elapsedTime < timeoutMillis) {
delay(10)
Expand Down
Loading