Bug 1858509 add thread-safety annotations around MediaSourceDemuxer::mMonitor r=alwu
[gecko.git] / third_party / dav1d / tests / dav1d_argon.bash
blob0c356638341f812962da319f62f59bc859c06f32
1 #!/usr/bin/env bash
3 DAV1D="tools/dav1d"
4 ARGON_DIR='.'
5 FILMGRAIN=1
6 CPUMASK=-1
7 THREADS=0
8 JOBS=1
10 usage() {
11 NAME=$(basename "$0")
13 printf "Usage: %s [-d dav1d] [-a argondir] [-g \$filmgrain] [-c \$cpumask] [-t threads] [-j jobs] [DIRECTORY]...\n" "$NAME"
14 printf "Example: %s -d /path/to/dav1d -a /path/to/argon/ -g 0 -c avx2 profile0_core\n" "$NAME"
15 printf "Used to verify that dav1d can decode the Argon AV1 test vectors correctly.\n\n"
16 printf " DIRECTORY one or more dirs in the argon folder to check against\n"
17 printf " (default: everything except large scale tiles and stress files)\n"
18 printf " -d dav1d path to dav1d executable (default: tools/dav1d)\n"
19 printf " -a dir path to argon dir (default: 'tests/argon' if found; '.' otherwise)\n"
20 printf " -g \$num enable filmgrain (default: 1)\n"
21 printf " -c \$mask use restricted cpumask (default: -1)\n"
22 printf " -t \$num number of threads per dav1d (default: 0)\n"
23 printf " -j \$num number of parallel dav1d processes (default: 1)\n\n"
24 } >&2
25 exit 1
28 error() {
29 printf "\033[1;91m%s\033[0m\n" "$*" >&2
30 exit 1
33 fail() {
34 printf "\033[1K\rMismatch in %s\n" "$1"
35 (( failed++ ))
38 check_pids() {
39 new_pids=()
40 done_pids=()
41 for p in "${pids[@]}"; do
42 if kill -0 "$p" 2>/dev/null; then
43 new_pids+=("$p")
44 else
45 done_pids+=("$p")
47 done
48 pids=("${new_pids[@]}")
51 wait_pids() {
52 pid_list=("$@")
53 for p in "${pid_list[@]}"; do
54 if ! wait "$p"; then
55 local file_varname="file$p"
56 fail "${!file_varname}"
58 done
61 block_pids() {
62 while [ ${#pids[@]} -ge "$JOBS" ]; do
63 check_pids
64 if [ ${#done_pids} -eq 0 ]; then
65 sleep 0.2
66 else
67 wait_pids "${done_pids[@]}"
69 done
72 wait_all_pids() {
73 wait_pids "${pids[@]}"
76 # find tests/argon
77 tests_dir=$(dirname "$(readlink -f "$0")")
78 if [ -d "$tests_dir/argon" ]; then
79 ARGON_DIR="$tests_dir/argon"
82 while getopts ":d:a:g:c:t:j:" opt; do
83 case "$opt" in
85 DAV1D="$OPTARG"
88 ARGON_DIR="$OPTARG"
91 FILMGRAIN="$OPTARG"
94 CPUMASK="$OPTARG"
97 THREADS="$OPTARG"
100 JOBS="$OPTARG"
103 printf "Error! Invalid option: -%s\n" "$OPTARG" >&2
104 usage
107 usage
109 esac
110 done
111 shift $((OPTIND-1))
113 if [ "$#" -eq 0 ]; then
114 # Everything except large scale tiles and stress files.
115 dirs=("$ARGON_DIR/profile0_core" "$ARGON_DIR/profile0_core_special"
116 "$ARGON_DIR/profile0_not_annexb" "$ARGON_DIR/profile0_not_annexb_special"
117 "$ARGON_DIR/profile1_core" "$ARGON_DIR/profile1_core_special"
118 "$ARGON_DIR/profile1_not_annexb" "$ARGON_DIR/profile1_not_annexb_special"
119 "$ARGON_DIR/profile2_core" "$ARGON_DIR/profile2_core_special"
120 "$ARGON_DIR/profile2_not_annexb" "$ARGON_DIR/profile2_not_annexb_special"
121 "$ARGON_DIR/profile_switching")
122 else
123 mapfile -t dirs < <(printf "${ARGON_DIR}/%s\n" "$@" | sort -u)
126 ver_info="dav1d $("$DAV1D" -v 2>&1) filmgrain=$FILMGRAIN cpumask=$CPUMASK" || error "Error! Can't run $DAV1D"
127 files=()
129 for d in "${dirs[@]}"; do
130 if [ -d "$d/streams" ]; then
131 files+=("${d/%\//}"/streams/*.obu)
133 done
135 if [ ${#files[@]} -eq 0 ]; then
136 error "Error! No files found at ${dirs[*]}"
139 failed=0
140 pids=()
141 for i in "${!files[@]}"; do
142 f="${files[i]}"
143 if [ "$FILMGRAIN" -eq 0 ]; then
144 md5=${f/\/streams\//\/md5_no_film_grain\/}
145 else
146 md5=${f/\/streams\//\/md5_ref\/}
148 md5=$(<"${md5/%obu/md5}") || error "Error! Can't read md5 ${md5} for file ${f}"
149 md5=${md5/ */}
151 printf "\033[1K\r[%3d%% %d/%d] Verifying %s" "$(((i+1)*100/${#files[@]}))" "$((i+1))" "${#files[@]}" "$f"
152 cmd=("$DAV1D" -i "$f" --filmgrain "$FILMGRAIN" --verify "$md5" --cpumask "$CPUMASK" --threads "$THREADS" -q)
153 if [ "$JOBS" -gt 1 ]; then
154 "${cmd[@]}" 2>/dev/null &
155 p=$!
156 pids+=("$p")
157 declare "file$p=$f"
158 block_pids
159 else
160 if ! "${cmd[@]}" 2>/dev/null; then
161 fail "$f"
164 done
166 wait_all_pids
168 if [ "$failed" -ne 0 ]; then
169 printf "\033[1K\r%d/%d files \033[1;91mfailed\033[0m to verify" "$failed" "${#files[@]}"
170 else
171 printf "\033[1K\r%d files \033[1;92msuccessfully\033[0m verified" "${#files[@]}"
173 printf " in %dm%ds (%s)\n" "$((SECONDS/60))" "$((SECONDS%60))" "$ver_info"
175 exit $failed