Commit 7f9bbc56 authored by Alexandros Frantzis's avatar Alexandros Frantzis

Add tests for basic tracie functionality

Signed-off-by: Alexandros Frantzis's avatarAlexandros Frantzis <alexandros.frantzis@collabora.com>
parent 686f9768
Pipeline #89304 failed with stages
in 18 minutes and 32 seconds
......@@ -126,6 +126,7 @@ mesa-build:
dependencies:
- mesa-build
before_script:
- tests/test.sh
- git clone --no-checkout "$TRACES_DB_REPO" traces-db
- (cd $CI_PROJECT_DIR/traces-db; git reset "$TRACES_DB_COMMIT" || git reset "origin/$TRACES_DB_COMMIT")
- export DISPLAY=:0
......
......@@ -77,7 +77,7 @@ def dump_with_renderdoc(trace, calls, device_name):
run_logged_command(cmd, log_path)
def dump_with_testtrace(trace, calls, device_name):
import png
from PIL import Image
outputdir_path = Path(trace).parent / "test" / device_name
outputdir_path.mkdir(parents=True, exist_ok=True)
with Path(trace).open() as f:
......@@ -86,7 +86,7 @@ def dump_with_testtrace(trace, calls, device_name):
int(rgba[4:6], 16), int(rgba[6:8], 16)]
for c in calls:
outputfile = str(outputdir_path / Path(trace).name) + "-" + c + ".png"
png.from_array([color * 32] * 32, 'RGBA').save(outputfile)
Image.frombytes('RGBA', (32, 32), bytes(color * 32 * 32)).save(outputfile)
def dump_from_trace(trace, device_name):
log("Info", "Dumping trace %s" % trace, end='... ')
......
#!/bin/sh
TRACIE_DIR="$(dirname "$(readlink -f "$0")")/.."
TEST_DIR=""
TEST_EXIT=0
create_repo() {
repo="$(mktemp -d $TEST_DIR/repo.XXXXXXXXXX)"
cp -R "$TEST_DIR"/tests/test-data/* "$repo"
(
cd "$repo";
git init -q .;
git config user.email "me@example.com"
git config user.name "Me me"
git lfs track '*.png' '*.testtrace' > /dev/null;
git add .;
git commit -q -a -m 'initial';
)
echo $repo
}
destroy_repo() {
[ -d "$1"/.git ] && rm -rf "$1"
}
assert() {
if ! $1; then
echo "Assertion failed: \"$1\""
exit 1
fi
}
run_tracie() {
# Run tests for the .testtrace types, using the "test-device" device name.
DEVICE_NAME=test-device CI_PROJECT_DIR="$TEST_DIR" \
"$TRACIE_DIR/.gitlab-ci/run-tests.sh" testtrace
}
cleanup() {
rm -rf "$TEST_DIR"
}
prepare_for_run() {
TEST_DIR="$(mktemp -d -t tracie.test.XXXXXXXXXX)"
# Copy all the tracie scripts to the the test dir and later make that the
# CI_PROJECT_DIR for the run-tests.sh script. This avoids polluting the
# normal working dir with test result artifacts.
cp -R "$TRACIE_DIR"/* "$TEST_DIR"
trap cleanup EXIT
}
run_test() {
log=$(mktemp)
if ($1 > "$log" 2>&1 ;); then
if [ -t 1 ]; then
echo "$1: \e[0;32mSuccess\e[0m"
else
echo "$1: Success"
fi
else
if [ -t 1 ]; then
echo "$1: \e[0;31mFail\e[0m"
else
echo "$1: Fail"
fi
cat "$log"
TEST_EXIT=1
fi
rm "$log"
}
tracie_succeeds_if_all_images_match() {
repo="$(create_repo)"
cd "$repo"
run_tracie
assert "[ $? = 0 ]"
destroy_repo "$repo"
}
tracie_fails_on_image_mismatch() {
repo="$(create_repo)"
cd "$repo"
cp trace1/references/test-device/magenta.testtrace-1.png \
trace2/references/test-device/olive.testtrace-23.png
git commit -a -m 'break'
run_tracie
assert "[ $? != 0 ]"
destroy_repo "$repo"
}
tracie_ignores_unspecified_trace_types() {
repo="$(create_repo)"
cd "$repo"
# For the tests we only scan for the .testtrace type,
# so the .trace file added below should be ignored.
echo "empty" > trace1/empty.trace
cp trace1/references/test-device/magenta.testtrace-1.png \
trace1/references/test-device/empty.trace-1.png
git lfs track '*.trace'
git add trace1
git commit -a -m 'break'
run_tracie
assert "[ $? = 0 ]"
destroy_repo "$repo"
}
tracie_skips_traces_without_reference_images() {
repo="$(create_repo)"
cd "$repo"
# red.testtrace should be skipped, since it doesn't
# have any reference images.
echo "ff0000ff" > trace1/red.testtrace
git add trace1
git commit -a -m 'red'
run_tracie
assert "[ $? = 0 ]"
destroy_repo "$repo"
}
tracie_fails_on_dump_image_error() {
repo="$(create_repo)"
cd "$repo"
# "invalid" should fail to parse as rgba and
# cause an error
echo "invalid" > trace1/magenta.testtrace
git add trace1
git commit -a -m 'invalid'
run_tracie
assert "[ $? != 0 ]"
destroy_repo "$repo"
}
prepare_for_run
run_test tracie_succeeds_if_all_images_match
run_test tracie_fails_on_image_mismatch
run_test tracie_ignores_unspecified_trace_types
run_test tracie_skips_traces_without_reference_images
run_test tracie_fails_on_dump_image_error
exit $TEST_EXIT
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment