WPT.sh 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. #!/usr/bin/env bash
  2. set -e
  3. DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
  4. # shellcheck source=/dev/null
  5. . "${DIR}/shell_include.sh"
  6. ensure_ladybird_source_dir
  7. WPT_SOURCE_DIR=${WPT_SOURCE_DIR:-"${LADYBIRD_SOURCE_DIR}/Tests/LibWeb/WPT/wpt"}
  8. WPT_REPOSITORY_URL=${WPT_REPOSITORY_URL:-"https://github.com/web-platform-tests/wpt.git"}
  9. BUILD_PRESET=${BUILD_PRESET:-default}
  10. BUILD_DIR=$(get_build_dir "$BUILD_PRESET")
  11. default_binary_path() {
  12. if [ "$(uname -s)" = "Darwin" ]; then
  13. echo "${BUILD_DIR}/bin/Ladybird.app/Contents/MacOS"
  14. else
  15. echo "${BUILD_DIR}/bin"
  16. fi
  17. }
  18. LADYBIRD_BINARY=${LADYBIRD_BINARY:-"$(default_binary_path)/Ladybird"}
  19. WEBDRIVER_BINARY=${WEBDRIVER_BINARY:-"$(default_binary_path)/WebDriver"}
  20. WPT_PROCESSES=${WPT_PROCESSES:-$(get_number_of_processing_units)}
  21. WPT_CERTIFICATES=(
  22. "tools/certs/cacert.pem"
  23. "${LADYBIRD_SOURCE_DIR}/Build/ladybird/Lagom/cacert.pem"
  24. )
  25. WPT_ARGS=( "--webdriver-binary=${WEBDRIVER_BINARY}"
  26. "--install-webdriver"
  27. "--processes=${WPT_PROCESSES}"
  28. "--webdriver-arg=--force-cpu-painting"
  29. "--no-pause-after-test"
  30. "-f"
  31. "${EXTRA_WPT_ARGS[@]}"
  32. )
  33. ARG0=$0
  34. print_help() {
  35. NAME=$(basename "$ARG0")
  36. cat <<EOF
  37. Usage: $NAME COMMAND [OPTIONS..] [TESTS...]
  38. Supported COMMANDs:
  39. update: Update the Web Platform Tests repository.
  40. run: $NAME run [OPTIONS...] [TESTS...]
  41. Run the Web Platform Tests.
  42. compare: $NAME compare [OPTIONS...] LOG_FILE [TESTS...]
  43. Run the Web Platform Tests comparing the results to the expectations in LOG_FILE.
  44. Examples:
  45. $NAME update
  46. Updates the Web Platform Tests repository.
  47. $NAME run
  48. Run all of the Web Platform Tests.
  49. $NAME run --log expectations.log css dom
  50. Run the Web Platform Tests in the 'css' and 'dom' directories and save the output to expectations.log.
  51. $NAME run --log-wptreport expectations.json --log-wptscreenshot expectations.db css dom
  52. 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.
  53. $NAME compare expectations.log
  54. Run all of the Web Platform Tests comparing the results to the expectations in before.log.
  55. $NAME compare --log results.log expectations.log css/CSS2
  56. 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.
  57. EOF
  58. }
  59. usage() {
  60. >&2 print_help
  61. exit 1
  62. }
  63. CMD=$1
  64. [ -n "$CMD" ] || usage
  65. shift
  66. if [ "$CMD" = "--help" ] || [ "$CMD" = "help" ]; then
  67. print_help
  68. exit 0
  69. fi
  70. set_logging_flags()
  71. {
  72. [ -n "${1}" ] || usage;
  73. [ -n "${2}" ] || usage;
  74. log_type="${1}"
  75. log_name="$(pwd -P)/${2}"
  76. WPT_ARGS+=( "${log_type}=${log_name}" )
  77. }
  78. ARG=$1
  79. while [[ "$ARG" =~ ^(--headless|(--log(-(raw|unittest|xunit|html|mach|tbpl|grouped|chromium|wptreport|wptscreenshot))?))$ ]]; do
  80. case "$ARG" in
  81. --headless)
  82. LADYBIRD_BINARY="$(default_binary_path)/headless-browser"
  83. WPT_ARGS+=( "--webdriver-arg=--headless" )
  84. ;;
  85. --log)
  86. set_logging_flags "--log-raw" "${2}"
  87. shift
  88. ;;
  89. *)
  90. set_logging_flags "${ARG}" "${2}"
  91. shift
  92. ;;
  93. esac
  94. shift
  95. ARG=$1
  96. done
  97. WPT_ARGS+=( "--binary=${LADYBIRD_BINARY}" )
  98. TEST_LIST=( "$@" )
  99. exit_if_running_as_root "Do not run WPT.sh as root"
  100. ensure_wpt_repository() {
  101. mkdir -p "${WPT_SOURCE_DIR}"
  102. pushd "${WPT_SOURCE_DIR}" > /dev/null
  103. if [ ! -d .git ]; then
  104. git clone --depth 1 "${WPT_REPOSITORY_URL}" "${WPT_SOURCE_DIR}"
  105. fi
  106. # Update hosts file if needed
  107. if [ "$(comm -13 <(sort -u /etc/hosts) <(./wpt make-hosts-file | sort -u) | wc -l)" -gt 0 ]; then
  108. echo "Enter superuser password to append wpt hosts to /etc/hosts"
  109. ./wpt make-hosts-file | sudo tee -a /etc/hosts
  110. fi
  111. popd > /dev/null
  112. }
  113. build_ladybird_and_webdriver() {
  114. "${DIR}"/ladybird.sh build WebDriver
  115. }
  116. update_wpt() {
  117. ensure_wpt_repository
  118. pushd "${WPT_SOURCE_DIR}" > /dev/null
  119. git pull
  120. popd > /dev/null
  121. }
  122. execute_wpt() {
  123. pushd "${WPT_SOURCE_DIR}" > /dev/null
  124. for certificate_path in "${WPT_CERTIFICATES[@]}"; do
  125. if [ ! -f "${certificate_path}" ]; then
  126. echo "Certificate not found: \"${certificate_path}\""
  127. exit 1
  128. fi
  129. WPT_ARGS+=( "--webdriver-arg=--certificate=${certificate_path}" )
  130. done
  131. QT_QPA_PLATFORM="offscreen" ./wpt run "${WPT_ARGS[@]}" ladybird "${TEST_LIST[@]}"
  132. popd > /dev/null
  133. }
  134. run_wpt() {
  135. ensure_wpt_repository
  136. build_ladybird_and_webdriver
  137. execute_wpt
  138. }
  139. serve_wpt()
  140. {
  141. ensure_wpt_repository
  142. pushd "${WPT_SOURCE_DIR}" > /dev/null
  143. ./wpt serve
  144. popd > /dev/null
  145. }
  146. compare_wpt() {
  147. ensure_wpt_repository
  148. METADATA_DIR=$(mktemp -d)
  149. pushd "${WPT_SOURCE_DIR}" > /dev/null
  150. ./wpt update-expectations --product ladybird --full --metadata="${METADATA_DIR}" "${INPUT_LOG_NAME}"
  151. popd > /dev/null
  152. WPT_ARGS+=( "--metadata=${METADATA_DIR}" )
  153. build_ladybird_and_webdriver
  154. execute_wpt
  155. rm -rf "${METADATA_DIR}"
  156. }
  157. if [[ "$CMD" =~ ^(update|run|serve|compare)$ ]]; then
  158. case "$CMD" in
  159. update)
  160. update_wpt
  161. ;;
  162. run)
  163. run_wpt
  164. ;;
  165. serve)
  166. serve_wpt
  167. ;;
  168. compare)
  169. INPUT_LOG_NAME="$(pwd -P)/$1"
  170. if [ ! -f "$INPUT_LOG_NAME" ]; then
  171. echo "Log file not found: \"${INPUT_LOG_NAME}\""
  172. usage;
  173. fi
  174. shift
  175. compare_wpt
  176. ;;
  177. esac
  178. else
  179. >&2 echo "Unknown command: $CMD"
  180. usage
  181. fi