Skip to content

Commit

Permalink
Add simple scripts to run WPT
Browse files Browse the repository at this point in the history
  • Loading branch information
rodarima committed Nov 26, 2024
1 parent 18153f6 commit 9761d4a
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/out/
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Dillo test suite

This repository contains the WPT as a git submodule and a set of tools to be
able to run some test on Dillo. There are a lot of tests that we cannot pass
simply because Dillo doesn't support Javascript.

To run the tests, you will need to provide the path to the dillo binary using
the DILLOBIN variable.

```
$ export DILLOBIN=/path/to/dillo
```

Use the `genlist` script to generate a list of all suitable tests for Dillo and
`runtest` to run them:

```
$ ./genlist | ./runlist
```

Use grep or other filters to select a particular subset of tests. You can also
run one specific test by using:

```
$ echo wpt/path/to/the/test.html | ./runlist
```

The result of the tests will be printed to the stdout.
3 changes: 3 additions & 0 deletions genlist
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

find wpt/css/CSS2/ -type f | grep -E '\.(html|xht)$' | grep -v -- '-ref.'
27 changes: 27 additions & 0 deletions runlist
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/sh

if [ ! -e $DILLOBIN ]; then
echo missing dillo binary, set DILLOBIN with the path to dillo
exit 1
fi

ntot=0
nok=0

while read testfile; do
let ntot="$ntot+1"
#./single.sh "$testfile"
./runtest "$testfile" >/dev/null 2>&1
ret=$?
if [ "$ret" == "0" ]; then
echo "OK $testfile"
let nok="$nok+1"
elif [ "$ret" == "100" ]; then
echo "FAIL $testfile"
else
echo "BAD $testfile"
fi
done

echo
echo "Passed tests: $nok/$ntot"
89 changes: 89 additions & 0 deletions runtest
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/bin/sh

# Return errors:
#
# 0 - The test passed
# 1 - Cannot find Dillo binary
# 2 - Cannot find test or reference test
# 3 - Dillo crashed or cannot find window
# 100 - The test doesn't match the reference

set -e
#set -x

if [ ! -e "$DILLOBIN" ]; then
echo missing dillo binary, set DILLOBIN with the path to dillo
exit 1
fi

test_fpath="$1"

# Set the testfile to absolute path
testfile="$PWD/$test_fpath"

if [ ! -e "$testfile" ]; then
echo "cannot find test file: $testfile" >&2
exit 2
fi

testdir=$(dirname "$testfile")

# Get the match file
match=$(xmllint --html --xpath "string(//head/link[@rel='match']/@href)" "$testfile")

if [ -z "$match" ]; then
echo "cannot find link rel=match file" >&2
exit 2
fi

reffile="$testdir/$match"

if [ ! -e "$reffile" ]; then
echo "reference file $reffile not found" >&2
exit 2
fi

magick_bin="convert"
if command -v magick 2>&1 >/dev/null; then
magick_bin="magick"
fi

function render_page() {
htmlfile="$1"
outpic="$2"

"$DILLOBIN" -f "$htmlfile" &
dillopid=$!

# TODO: We need a better system to determine when the page loaded
sleep 0.5

# Capture only Dillo window
winid=$(xwininfo -all -root | awk '/Dillo:/ {print $1}')
if [ -z "$winid" ]; then
echo "cannot find Dillo window" >&2
exit 3
fi
xwd -id "$winid" -silent | ${magick_bin} xwd:- png:${outpic}

kill "$dillopid"
}

mkdir -p out

render_page "$testfile" "out/test.png"
render_page "$reffile" "out/ref.png"

# AE = Absolute Error count of the number of different pixels
diffcount=$(compare -metric AE "out/test.png" "out/ref.png" "out/diff.png" 2>&1 || true)

# The test passes only if both images are identical
if [ "$diffcount" = "0" ]; then
#echo "OK $testfile"
ret=0
else
#echo "FAIL $testfile"
ret=100
fi

exit $ret

0 comments on commit 9761d4a

Please sign in to comment.