From 0facae304b4434e94a28f6cd1449229c48cd7fa8 Mon Sep 17 00:00:00 2001 From: Simon Schneegans Date: Thu, 3 Mar 2022 21:25:47 +0100 Subject: [PATCH] :wrench: Use imagemagick for comparisons [run-ci] --- tests/run-test.sh | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/tests/run-test.sh b/tests/run-test.sh index 9be173d..111b47e 100755 --- a/tests/run-test.sh +++ b/tests/run-test.sh @@ -58,11 +58,24 @@ cd "$( cd "$( dirname "$0" )" && pwd )/.." || \ IMAGE="ghcr.io/schneegans/gnome-shell-pod-${FEDORA_VERSION}" EXTENSION="burn-my-windows@schneegans.github.com" +# All references images of the effects are captured at & cropped to this region +# in the center of the screen. This is kind of arbitrary, but has been choosen so that +# something is visible from each effect. +CROP="100x100+910+480" + # Run the container. For more info, visit https://github.com/Schneegans/gnome-shell-pod. POD=$(podman run --rm --cap-add=SYS_NICE --cap-add=IPC_LOCK -td "${IMAGE}") +# Create a temporary directory. +WORK_DIR=$(mktemp -d) +if [[ ! "${WORK_DIR}" || ! -d "${WORK_DIR}" ]]; then + echo "Failed to create tmp directory!" >&2 + exit 1 +fi + # Properly shutdown podman when this script is exited. quit() { + rm -r "${WORK_DIR}" podman kill "${POD}" wait } @@ -86,13 +99,18 @@ fail() { exit 1 } -# This searches the virtual screen of the container for a given target image (first -# parameter). If it is not found, an error message (second paramter) is printed and the -# script exits via the fail() method above. -find_target() { +# This captures the center of the virtual screen in the container and cmopares it to the +# given target image (first parameter). If it is not found, an error message (second +# paramter) is printed and the script exits via the fail() method above. +compare_with_target() { echo "Looking for ${1} on the screen." - POS=$(do_in_pod find-target.sh -f 0.02 "${1}") || true - if [[ -z "${POS}" ]]; then + + do_in_pod import -window root -crop $CROP out.png + podman cp "${POD}":/home/gnomeshell/out.png "${WORK_DIR}/out.png" + + DIFF=$(compare "${WORK_DIR}/out.png" ${1} -metric NCC "${WORK_DIR}/diff.png" 2>&1) || true + + if (( $(echo "$DIFF < 0.9" |bc -l) )); then fail "${2}" fi } @@ -126,10 +144,10 @@ test_effect() { sleep 2 do_in_pod gnome-extensions prefs "${EXTENSION}" sleep 2 - find_target "references/${1}-open-${SESSION}-${FEDORA_VERSION}.png" "Failed to test ${1} window open effect!" + compare_with_target "tests/references/${1}-open-${SESSION}-${FEDORA_VERSION}.png" "Failed to test ${1} window open effect!" send_keystroke "Alt+F4" sleep 2 - find_target "references/${1}-close-${SESSION}-${FEDORA_VERSION}.png" "Failed to test ${1} window close effect!" + compare_with_target "tests/references/${1}-close-${SESSION}-${FEDORA_VERSION}.png" "Failed to test ${1} window close effect!" sleep 2 } @@ -142,7 +160,6 @@ do_in_pod wait-user-bus.sh > /dev/null 2>&1 # ----------------------------------------------------- install the to-be-tested extension echo "Installing extension." -podman cp "tests/references" "${POD}:/home/gnomeshell/references" podman cp "${EXTENSION}.zip" "${POD}:/home/gnomeshell" do_in_pod gnome-extensions install "${EXTENSION}.zip"