diff --git a/host/tests/run-tests.sh b/host/tests/run-tests.sh new file mode 100755 index 00000000..c9106e58 --- /dev/null +++ b/host/tests/run-tests.sh @@ -0,0 +1,88 @@ +#!/bin/bash +# Builds and runs the multi-monitor tests. +# +# The unit tests are self contained and always run. The live test needs a +# built host and is skipped if one is not present. +# +# Usage: host/tests/run-tests.sh (from the repository root) + +set -u + +ROOT="$(cd "$(dirname "$0")/../.." && pwd)" +OUT="${TMPDIR:-/tmp}/lg-tests" +mkdir -p "$OUT" +cd "$ROOT" || exit 1 + +RC=0 + +echo "==============================================" +echo " unit tests: layout packing and pixel repack" +echo "==============================================" +# sanitizers are on because these tests are all about buffer arithmetic +if ! gcc -g -fsanitize=address,undefined -I common/include \ + -o "$OUT/test_displays" \ + common/tests/test_displays.c common/src/displays.c common/src/debug.c \ + common/tests/test_stubs.c; then + echo "FAILED to build the unit tests" + exit 1 +fi + +"$OUT/test_displays" || RC=1 + +HOST_BIN="$ROOT/host/build/looking-glass-host" +if [ ! -x "$HOST_BIN" ]; then + echo + echo "skipping the live test: no host built at $HOST_BIN" + exit $RC +fi + +echo +echo "==============================================" +echo " live test: capture, pack and publish a frame" +echo "==============================================" + +# the verifier links against the host's already built libraries +if ! gcc -O2 -msse4.1 -o "$OUT/lg-verify-atlas" host/tests/lg-verify-atlas.c \ + -I common/include -I repos/LGMP/lgmp/include -I host/include -I . \ + -Wl,--start-group \ + host/build/common/liblg_common.a \ + host/build/common/src/platform/linux/liblg_common_platform_code.a \ + host/build/lgmp/liblgmp.a \ + -Wl,--end-group \ + -lpthread -lrt -lbfd 2>"$OUT/verify-build.log"; then + echo "FAILED to build the verifier:" + tail -5 "$OUT/verify-build.log" + exit 1 +fi + +SHM=/dev/shm/looking-glass-selftest +rm -f "$SHM" +truncate -s 512M "$SHM" + +"$HOST_BIN" app:capture=XCB app:shmFile="$SHM" > "$OUT/host.log" 2>&1 & +HOST_PID=$! +sleep 4 + +if ! kill -0 "$HOST_PID" 2>/dev/null; then + echo "host exited early:" + tail -10 "$OUT/host.log" + rm -f "$SHM" + exit 1 +fi + +grep -E "Multi-monitor|monitors," "$OUT/host.log" || true +echo + +"$OUT/lg-verify-atlas" "$SHM" "$OUT" || RC=1 + +kill "$HOST_PID" 2>/dev/null +wait "$HOST_PID" 2>/dev/null +rm -f "$SHM" + +echo +if [ $RC -eq 0 ]; then + echo "ALL TESTS PASSED" +else + echo "TESTS FAILED" +fi +exit $RC