Skip to content

Commit

Permalink
Base for functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adamws committed Oct 27, 2024
1 parent db953d2 commit d30f24f
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 1 deletion.
38 changes: 37 additions & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,46 @@ jobs:
- name: Install dependencies
shell: bash
run: |
sudo apt-get install libxi-dev
sudo apt-get install libgl-dev libxi-dev \
libx11-dev xserver-xorg-dev xorg-dev
# 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 ffmpeg xdotool xvfb
- 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
3 changes: 3 additions & 0 deletions .justfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ test-kle:

test-queue:
zig test src/spsc_queue.zig

functional-tests:
cd tests && ./test.sh
45 changes: 45 additions & 0 deletions tests/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/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

# TODO: add option to choose display, for local development Xephyr is better
# but on CI Xvfb is required

#Xephyr -br -ac -noreset -screen 960x320 $FAKE_DISPLAY &
#DISPLAY_PID=$!

Xvfb -ac $FAKE_DISPLAY -screen 0 960x320x24 > /dev/null 2>&1 &
DISPLAY_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 $DISPLAY_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

0 comments on commit d30f24f

Please sign in to comment.