forked from LadybirdBrowser/ladybird
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WPT.sh
executable file
·303 lines (264 loc) · 8.67 KB
/
WPT.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
#!/usr/bin/env bash
set -e
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# shellcheck source=/dev/null
. "${DIR}/shell_include.sh"
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"}
BUILD_PRESET=${BUILD_PRESET:-default}
BUILD_DIR=$(get_build_dir "$BUILD_PRESET")
default_binary_path() {
if [ "$(uname -s)" = "Darwin" ]; then
echo "${BUILD_DIR}/bin/Ladybird.app/Contents/MacOS"
else
echo "${BUILD_DIR}/bin"
fi
}
ladybird_git_hash() {
pushd "${LADYBIRD_SOURCE_DIR}" > /dev/null
git rev-parse --short HEAD
popd > /dev/null
}
LADYBIRD_BINARY=${LADYBIRD_BINARY:-"$(default_binary_path)/Ladybird"}
WEBDRIVER_BINARY=${WEBDRIVER_BINARY:-"$(default_binary_path)/WebDriver"}
HEADLESS_BROWSER_BINARY=${HEADLESS_BROWSER_BINARY:-"$(default_binary_path)/headless-browser"}
WPT_PROCESSES=${WPT_PROCESSES:-$(get_number_of_processing_units)}
WPT_CERTIFICATES=(
"tools/certs/cacert.pem"
"${BUILD_DIR}/Lagom/cacert.pem"
)
WPT_ARGS=( "--webdriver-binary=${WEBDRIVER_BINARY}"
"--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.
import: $NAME import [PATHS...]
Fetch the given test file(s) from https://wpt.live/ and create an in-tree test and expectation files.
list-tests: $NAME list-tests [PATHS..]
List the tests in the given PATHS.
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.
$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.
$NAME run --debug-process WebContent http://wpt.live/dom/historical.html
Run the 'dom/historical.html' test, attaching the debugger to the WebContent process when the browser is launched.
$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.
$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.
$NAME list-tests css/CSS2 dom
Show a list of all tests in the 'css/CSS2' and 'dom' directories.
EOF
}
usage() {
>&2 print_help
exit 1
}
CMD=$1
[ -n "$CMD" ] || usage
shift
if [ "$CMD" = "--help" ] || [ "$CMD" = "help" ]; then
print_help
exit 0
fi
set_logging_flags()
{
[ -n "${1}" ] || usage;
[ -n "${2}" ] || usage;
log_type="${1}"
log_name="$(absolutize_path "${2}")"
WPT_ARGS+=( "${log_type}=${log_name}" )
}
headless=1
ARG=$1
while [[ "$ARG" =~ ^(--show-window|--debug-process|(--log(-(raw|unittest|xunit|html|mach|tbpl|grouped|chromium|wptreport|wptscreenshot))?))$ ]]; do
case "$ARG" in
--show-window)
headless=0
;;
--debug-process)
process_name="${2}"
shift
WPT_ARGS+=( "--webdriver-arg=--debug-process=${process_name}" )
;;
--log)
set_logging_flags "--log-raw" "${2}"
shift
;;
*)
set_logging_flags "${ARG}" "${2}"
shift
;;
esac
shift
ARG=$1
done
if [ $headless -eq 1 ]; then
WPT_ARGS+=( "--binary=${HEADLESS_BROWSER_BINARY}" )
WPT_ARGS+=( "--webdriver-arg=--headless" )
else
WPT_ARGS+=( "--binary=${LADYBIRD_BINARY}" )
fi
TEST_LIST=( "$@" )
for i in "${!TEST_LIST[@]}"; do
item="${TEST_LIST[i]}"
item="${item#"$WPT_SOURCE_DIR"/}"
item="${item#*Tests/LibWeb/WPT/wpt/}"
item="${item#http://wpt.live/}"
item="${item#https://wpt.live/}"
TEST_LIST[i]="$item"
done
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
# 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
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
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[@]}"
popd > /dev/null
}
run_wpt() {
ensure_wpt_repository
build_ladybird_and_webdriver
execute_wpt
}
serve_wpt()
{
ensure_wpt_repository
pushd "${WPT_SOURCE_DIR}" > /dev/null
./wpt serve
popd > /dev/null
}
list_tests_wpt()
{
ensure_wpt_repository
pushd "${WPT_SOURCE_DIR}" > /dev/null
./wpt run --list-tests ladybird "${TEST_LIST[@]}"
popd > /dev/null
}
import_wpt()
{
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
TESTS=()
while IFS= read -r test_file; do
TESTS+=("$test_file")
done < <(
"${ARG0}" list-tests "${INPUT_PATHS[@]}"
)
if [ "${#TESTS[@]}" -eq 0 ]; then
echo "No tests found for the given paths"
exit 1
fi
pushd "${LADYBIRD_SOURCE_DIR}" > /dev/null
./Meta/ladybird.sh build headless-browser
set +e
for path in "${TESTS[@]}"; do
echo "Importing test from ${path}"
if [ ! "$(./Meta/import-wpt-test.py https://wpt.live/"${path}")" ]; then
continue
fi
"${HEADLESS_BROWSER_BINARY}" --run-tests ./Tests/LibWeb --rebaseline -f "$path"
done
set -e
popd > /dev/null
}
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}"
}
if [[ "$CMD" =~ ^(update|run|serve|compare|import|list-tests)$ ]]; then
case "$CMD" in
update)
update_wpt
;;
run)
run_wpt
;;
serve)
serve_wpt
;;
import)
if [ $# -eq 0 ]; then
usage
fi
INPUT_PATHS=( "$@" )
import_wpt
;;
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
;;
list-tests)
list_tests_wpt
;;
esac
else
>&2 echo "Unknown command: $CMD"
usage
fi