2024-08-12 14:33:28 +00:00
#!/usr/bin/env bash
set -e
DIR = " $( cd " $( dirname " ${ BASH_SOURCE [0] } " ) " && pwd ) "
2024-08-15 22:12:40 +00:00
# shellcheck source=/dev/null
. " ${ DIR } /shell_include.sh "
2024-10-09 05:23:42 +00:00
ensure_ladybird_source_dir
WPT_SOURCE_DIR = ${ WPT_SOURCE_DIR :- " ${ LADYBIRD_SOURCE_DIR } /Tests/LibWeb/WPT/wpt " }
WPT_REPOSITORY_URL = ${ WPT_REPOSITORY_URL :- "https://github.com/web-platform-tests/wpt.git" }
2024-10-09 05:32:11 +00:00
BUILD_PRESET = ${ BUILD_PRESET :- default }
BUILD_DIR = $( get_build_dir " $BUILD_PRESET " )
2024-08-15 22:14:04 +00:00
default_binary_path( ) {
if [ " $( uname -s) " = "Darwin" ] ; then
2024-10-21 23:31:05 +00:00
echo " ${ BUILD_DIR } /bin/Ladybird.app/Contents/MacOS "
2024-08-15 22:14:04 +00:00
else
2024-10-21 23:31:05 +00:00
echo " ${ BUILD_DIR } /bin "
2024-08-15 22:14:04 +00:00
fi
}
2024-10-09 05:32:11 +00:00
2024-10-29 09:33:11 +00:00
ladybird_git_hash( ) {
pushd " ${ LADYBIRD_SOURCE_DIR } " > /dev/null
git rev-parse --short HEAD
popd > /dev/null
}
2024-08-15 22:14:04 +00:00
LADYBIRD_BINARY = ${ LADYBIRD_BINARY :- " $( default_binary_path) /Ladybird " }
WEBDRIVER_BINARY = ${ WEBDRIVER_BINARY :- " $( default_binary_path) /WebDriver " }
2024-11-02 06:03:22 +00:00
HEADLESS_BROWSER_BINARY = ${ HEADLESS_BROWSER_BINARY :- " $( default_binary_path) /headless-browser " }
2024-08-15 22:12:40 +00:00
WPT_PROCESSES = ${ WPT_PROCESSES :- $( get_number_of_processing_units) }
2024-08-12 14:33:28 +00:00
WPT_CERTIFICATES = (
"tools/certs/cacert.pem"
2024-10-28 11:48:05 +00:00
" ${ BUILD_DIR } /Lagom/cacert.pem "
2024-08-12 14:33:28 +00:00
)
2024-10-21 23:31:05 +00:00
WPT_ARGS = ( " --webdriver-binary= ${ WEBDRIVER_BINARY } "
2024-08-12 14:33:28 +00:00
"--install-webdriver"
" --processes= ${ WPT_PROCESSES } "
"--webdriver-arg=--force-cpu-painting"
"--no-pause-after-test"
"-f"
" ${ EXTRA_WPT_ARGS [@] } "
)
ARG0 = $0
print_help( ) {
NAME = $( basename " $ARG0 " )
cat <<EOF
Usage: $NAME COMMAND [ OPTIONS..] [ TESTS...]
Supported COMMANDs:
update: Update the Web Platform Tests repository.
run: $NAME run [ OPTIONS...] [ TESTS...]
Run the Web Platform Tests.
compare: $NAME compare [ OPTIONS...] LOG_FILE [ TESTS...]
Run the Web Platform Tests comparing the results to the expectations in LOG_FILE.
2024-11-02 06:03:22 +00:00
import: $NAME import [ TESTS...]
Fetch the given test file( s) from https://wpt.live/ and create an in-tree test and expectation files.
2024-08-12 14:33:28 +00:00
Examples:
$NAME update
Updates the Web Platform Tests repository.
$NAME run
Run all of the Web Platform Tests.
$NAME run --log expectations.log css dom
Run the Web Platform Tests in the 'css' and 'dom' directories and save the output to expectations.log.
2024-09-13 22:50:16 +00:00
$NAME run --log-wptreport expectations.json --log-wptscreenshot expectations.db css dom
Run the Web Platform Tests in the 'css' and 'dom' directories; save the output in wptreport format to expectations.json and save screenshots to expectations.db.
2024-08-12 14:33:28 +00:00
$NAME compare expectations.log
Run all of the Web Platform Tests comparing the results to the expectations in before.log.
$NAME compare --log results.log expectations.log css/CSS2
Run the Web Platform Tests in the 'css/CSS2' directory, comparing the results to the expectations in expectations.log; output the results to results.log.
2024-11-02 06:03:22 +00:00
$NAME import html/dom/aria-attribute-reflection.html
Import the test from https://wpt.live/html/dom/aria-attribute-reflection.html into the Ladybird test suite.
2024-08-12 14:33:28 +00:00
EOF
}
usage( ) {
>& 2 print_help
exit 1
}
CMD = $1
[ -n " $CMD " ] || usage
shift
if [ " $CMD " = "--help" ] || [ " $CMD " = "help" ] ; then
print_help
exit 0
fi
2024-10-21 23:31:05 +00:00
set_logging_flags( )
{
[ -n " ${ 1 } " ] || usage;
[ -n " ${ 2 } " ] || usage;
log_type = " ${ 1 } "
2024-10-29 08:46:43 +00:00
log_name = " $( absolutize_path " ${ 2 } " ) "
2024-10-21 23:31:05 +00:00
WPT_ARGS += ( " ${ log_type } = ${ log_name } " )
}
2024-10-14 19:54:36 +00:00
headless = 1
2024-08-12 14:33:28 +00:00
ARG = $1
2024-10-14 19:54:36 +00:00
while [ [ " $ARG " = ~ ^( --show-window| ( --log( -( raw| unittest| xunit| html| mach| tbpl| grouped| chromium| wptreport| wptscreenshot) ) ?) ) $ ] ] ; do
2024-09-13 22:50:16 +00:00
case " $ARG " in
2024-10-14 19:54:36 +00:00
--show-window)
headless = 0
2024-10-21 23:31:05 +00:00
; ;
2024-09-13 22:50:16 +00:00
--log)
2024-10-21 23:31:05 +00:00
set_logging_flags "--log-raw" " ${ 2 } "
shift
2024-09-13 22:50:16 +00:00
; ;
*)
2024-10-21 23:31:05 +00:00
set_logging_flags " ${ ARG } " " ${ 2 } "
shift
2024-09-13 22:50:16 +00:00
; ;
esac
2024-10-21 23:31:05 +00:00
2024-08-12 14:33:28 +00:00
shift
2024-09-13 22:50:16 +00:00
ARG = $1
done
2024-10-21 23:31:05 +00:00
2024-10-14 19:54:36 +00:00
if [ $headless -eq 1 ] ; then
WPT_ARGS += ( " --binary= ${ HEADLESS_BROWSER_BINARY } " )
WPT_ARGS += ( "--webdriver-arg=--headless" )
else
WPT_ARGS += ( " --binary= ${ LADYBIRD_BINARY } " )
fi
2024-08-12 14:33:28 +00:00
TEST_LIST = ( " $@ " )
2024-11-02 09:26:05 +00:00
for i in " ${ !TEST_LIST[@] } " ; do
item = " ${ TEST_LIST [i] } "
item = " ${ item # " $WPT_SOURCE_DIR " / } "
item = " ${ item #*Tests/LibWeb/WPT/wpt/ } "
2024-11-06 18:08:42 +00:00
item = " ${ item #http : //wpt.live/ } "
item = " ${ item #https : //wpt.live/ } "
2024-11-02 09:26:05 +00:00
TEST_LIST[ i] = " $item "
done
2024-08-12 14:33:28 +00:00
exit_if_running_as_root "Do not run WPT.sh as root"
ensure_wpt_repository( ) {
mkdir -p " ${ WPT_SOURCE_DIR } "
pushd " ${ WPT_SOURCE_DIR } " > /dev/null
if [ ! -d .git ] ; then
git clone --depth 1 " ${ WPT_REPOSITORY_URL } " " ${ WPT_SOURCE_DIR } "
fi
2024-08-15 22:06:36 +00:00
# Update hosts file if needed
if [ " $( comm -13 <( sort -u /etc/hosts) <(./wpt make-hosts-file | sort -u) | wc -l) " -gt 0 ] ; then
echo "Enter superuser password to append wpt hosts to /etc/hosts"
./wpt make-hosts-file | sudo tee -a /etc/hosts
fi
2024-08-12 14:33:28 +00:00
popd > /dev/null
}
build_ladybird_and_webdriver( ) {
" ${ DIR } " /ladybird.sh build WebDriver
}
update_wpt( ) {
ensure_wpt_repository
pushd " ${ WPT_SOURCE_DIR } " > /dev/null
git pull
popd > /dev/null
}
execute_wpt( ) {
pushd " ${ WPT_SOURCE_DIR } " > /dev/null
for certificate_path in " ${ WPT_CERTIFICATES [@] } " ; do
if [ ! -f " ${ certificate_path } " ] ; then
echo " Certificate not found: \" ${ certificate_path } \" "
exit 1
fi
WPT_ARGS += ( " --webdriver-arg=--certificate= ${ certificate_path } " )
done
2024-10-14 19:54:36 +00:00
echo LADYBIRD_GIT_VERSION = " $( ladybird_git_hash) " ./wpt run " ${ WPT_ARGS [@] } " ladybird " ${ TEST_LIST [@] } "
LADYBIRD_GIT_VERSION = " $( ladybird_git_hash) " ./wpt run " ${ WPT_ARGS [@] } " ladybird " ${ TEST_LIST [@] } "
2024-08-12 14:33:28 +00:00
popd > /dev/null
}
run_wpt( ) {
ensure_wpt_repository
build_ladybird_and_webdriver
execute_wpt
}
2024-10-11 18:30:24 +00:00
serve_wpt( )
{
ensure_wpt_repository
pushd " ${ WPT_SOURCE_DIR } " > /dev/null
./wpt serve
popd > /dev/null
}
2024-11-02 06:03:22 +00:00
import_wpt( )
{
2024-11-06 18:08:42 +00:00
for i in " ${ !INPUT_PATHS[@] } " ; do
item = " ${ INPUT_PATHS [i] } "
item = " ${ item #http : //wpt.live/ } "
item = " ${ item #https : //wpt.live/ } "
INPUT_PATHS[ i] = " $item "
done
2024-11-02 06:03:22 +00:00
pushd " ${ LADYBIRD_SOURCE_DIR } " > /dev/null
./Meta/ladybird.sh build headless-browser
for path in " ${ INPUT_PATHS [@] } " ; do
echo " Importing test from ${ path } "
./Meta/import-wpt-test.py https://wpt.live/" ${ path } "
" ${ HEADLESS_BROWSER_BINARY } " --run-tests ./Tests/LibWeb --rebaseline -f " $path "
done
popd > /dev/null
}
2024-08-12 14:33:28 +00:00
compare_wpt( ) {
ensure_wpt_repository
METADATA_DIR = $( mktemp -d)
pushd " ${ WPT_SOURCE_DIR } " > /dev/null
./wpt update-expectations --product ladybird --full --metadata= " ${ METADATA_DIR } " " ${ INPUT_LOG_NAME } "
popd > /dev/null
WPT_ARGS += ( " --metadata= ${ METADATA_DIR } " )
build_ladybird_and_webdriver
execute_wpt
rm -rf " ${ METADATA_DIR } "
}
2024-11-02 06:03:22 +00:00
if [ [ " $CMD " = ~ ^( update| run| serve| compare| import) $ ] ] ; then
2024-08-12 14:33:28 +00:00
case " $CMD " in
update)
update_wpt
; ;
run)
run_wpt
; ;
2024-10-11 18:30:24 +00:00
serve)
serve_wpt
; ;
2024-11-02 06:03:22 +00:00
import)
if [ $# -eq 0 ] ; then
usage
fi
INPUT_PATHS = ( " $@ " )
import_wpt
; ;
2024-08-12 14:33:28 +00:00
compare)
INPUT_LOG_NAME = " $( pwd -P) / $1 "
if [ ! -f " $INPUT_LOG_NAME " ] ; then
echo " Log file not found: \" ${ INPUT_LOG_NAME } \" "
usage;
fi
shift
compare_wpt
; ;
esac
else
>& 2 echo " Unknown command: $CMD "
usage
fi