🔧 Use imagemagick for comparisons [run-ci]

This commit is contained in:
Simon Schneegans
2022-03-03 21:25:47 +01:00
parent 31fa0f54bd
commit 0facae304b
+26 -9
View File
@@ -58,11 +58,24 @@ cd "$( cd "$( dirname "$0" )" && pwd )/.." || \
IMAGE="ghcr.io/schneegans/gnome-shell-pod-${FEDORA_VERSION}" IMAGE="ghcr.io/schneegans/gnome-shell-pod-${FEDORA_VERSION}"
EXTENSION="burn-my-windows@schneegans.github.com" 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. # 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}") 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. # Properly shutdown podman when this script is exited.
quit() { quit() {
rm -r "${WORK_DIR}"
podman kill "${POD}" podman kill "${POD}"
wait wait
} }
@@ -86,13 +99,18 @@ fail() {
exit 1 exit 1
} }
# This searches the virtual screen of the container for a given target image (first # This captures the center of the virtual screen in the container and cmopares it to the
# parameter). If it is not found, an error message (second paramter) is printed and the # given target image (first parameter). If it is not found, an error message (second
# script exits via the fail() method above. # paramter) is printed and the script exits via the fail() method above.
find_target() { compare_with_target() {
echo "Looking for ${1} on the screen." 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}" fail "${2}"
fi fi
} }
@@ -126,10 +144,10 @@ test_effect() {
sleep 2 sleep 2
do_in_pod gnome-extensions prefs "${EXTENSION}" do_in_pod gnome-extensions prefs "${EXTENSION}"
sleep 2 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" send_keystroke "Alt+F4"
sleep 2 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 sleep 2
} }
@@ -142,7 +160,6 @@ do_in_pod wait-user-bus.sh > /dev/null 2>&1
# ----------------------------------------------------- install the to-be-tested extension # ----------------------------------------------------- install the to-be-tested extension
echo "Installing extension." echo "Installing extension."
podman cp "tests/references" "${POD}:/home/gnomeshell/references"
podman cp "${EXTENSION}.zip" "${POD}:/home/gnomeshell" podman cp "${EXTENSION}.zip" "${POD}:/home/gnomeshell"
do_in_pod gnome-extensions install "${EXTENSION}.zip" do_in_pod gnome-extensions install "${EXTENSION}.zip"