diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 42b00cf..91161c2 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -25,6 +25,41 @@ jobs: # kle tests not triggered from main, # must figure out how to properly zig test - run: | + zig build zig build test zig test src/kle.zig zig test src/spsc_queue.zig + - uses: actions/upload-artifact@v4 + if: always() + with: + name: klawa + path: zig-out/bin/klawa + retention-days: 2 + if-no-files-found: error + + run-functional-tests: + name: Run functional tests + needs: + - build-and-test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/download-artifact@v4 + with: + name: klawa + path: zig-out/bin/klawa +# - name: Install dependencies +# shell: bash +# run: | +# sudo apt-get install libxi-dev + - name: Run tests + shell: bash + run: | + cd tests && ./test.sh + - uses: actions/upload-artifact@v4 + if: always() + with: + name: output.webm + path: tests/output.webm + retention-days: 2 + if-no-files-found: error diff --git a/.justfile b/.justfile index 7143de7..17b9ebd 100644 --- a/.justfile +++ b/.justfile @@ -37,3 +37,6 @@ test-kle: test-queue: zig test src/spsc_queue.zig + +functional-tests: + cd tests && ./test.sh diff --git a/tests/test.sh b/tests/test.sh new file mode 100755 index 0000000..971d790 --- /dev/null +++ b/tests/test.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +set -e +set -u + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +# TODO: should check if free: +FAKE_DISPLAY=:99 +APP=${SCRIPT_DIR}/../zig-out/bin/klawa +TEST_EVENTS=test_events.bin +TEST_RENDER_DIR=render-out + +Xephyr -br -ac -noreset -screen 960x320 $FAKE_DISPLAY & +XEPHYR_PID=$! + +# wait for Xephyr +sleep 1 + +DISPLAY=$FAKE_DISPLAY $APP --record $TEST_EVENTS & +APP_PID=$! + +# wait for tested app +sleep 1 + +# simulate some input +DISPLAY=$FAKE_DISPLAY xdotool type --delay 500 "this is klawa app" +kill -9 $APP_PID + +mkdir $TEST_RENDER_DIR +DISPLAY=$FAKE_DISPLAY $APP --replay $TEST_EVENTS --render $TEST_RENDER_DIR +kill -9 $XEPHYR_PID + +rm $TEST_EVENTS + +cd $TEST_RENDER_DIR && ffmpeg -y -framerate 60 -s 960x320 -pix_fmt rgba -i "frame%05d.raw" -c:v libvpx-vp9 ../output1.webm +cd - + +rm -rf $TEST_RENDER_DIR