|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -e |
| 3 | + |
| 4 | +show_help() { |
| 5 | + me=$(basename "$0") |
| 6 | + cat <<EOF |
| 7 | +$me: Run all of the examples in test mode |
| 8 | +
|
| 9 | +Usage: $me --os <os> --config <config> --bin-dir <path> --skip-file <path> [--dry-run] |
| 10 | +
|
| 11 | +Options: |
| 12 | + --help Show this help message |
| 13 | + --dry-run Skip running the examples. |
| 14 | + --bin-dir <path> Path to binary directory. |
| 15 | + Must contain all of the example binaries. |
| 16 | + --skip-file <path> Path to file containing skip patterns. |
| 17 | + See the 'Skip file' section, below. |
| 18 | + --os <os> Operating system. |
| 19 | + Valid <os> values: 'macos', 'windows', 'linux' |
| 20 | + --config <config> Build configuration. |
| 21 | + Valid <config> values: 'debug', 'release'. |
| 22 | +
|
| 23 | + --platform <platform> Target platform. |
| 24 | + Valid <platform> values: 'x86_64', 'aarch64'. |
| 25 | +
|
| 26 | +Skip file: |
| 27 | +
|
| 28 | + The skip patterns are regexp patterns on the following format: |
| 29 | + <os>:<platform>:<config>:<sample> # Some comment describing why test is disabled |
| 30 | +
|
| 31 | + For example: |
| 32 | + # Bug 123: foo-example fails (both debug and release) |
| 33 | + windows:x86_64(debug|release):foo-example |
| 34 | + # Bug 456: bar-example fails in release mode on Linux |
| 35 | + linux:aarch64:release:bar-example |
| 36 | +
|
| 37 | +EOF |
| 38 | +} |
| 39 | + |
| 40 | +function user_error() { |
| 41 | + echo "error: $1" >&2 |
| 42 | + echo "" >&2 |
| 43 | + show_help >&2 |
| 44 | + exit 1 |
| 45 | +} |
| 46 | + |
| 47 | +while [[ "$#" -gt 0 ]]; do |
| 48 | + case $1 in |
| 49 | + -h | --help) |
| 50 | + show_help |
| 51 | + exit 0 |
| 52 | + ;; |
| 53 | + --dry-run) |
| 54 | + dry_run=true |
| 55 | + ;; |
| 56 | + --bin-dir) |
| 57 | + bin_dir="$2" |
| 58 | + shift |
| 59 | + ;; |
| 60 | + --skip-file) |
| 61 | + skip_file="$2" |
| 62 | + shift |
| 63 | + ;; |
| 64 | + --os) |
| 65 | + case $2 in |
| 66 | + windows | linux | macos) ;; |
| 67 | + *) |
| 68 | + user_error "Unrecognized os: '$2'" |
| 69 | + ;; |
| 70 | + esac |
| 71 | + os="$2" |
| 72 | + shift |
| 73 | + ;; |
| 74 | + --config) |
| 75 | + case $2 in |
| 76 | + debug | release) ;; |
| 77 | + *) |
| 78 | + user_error "Unrecognized config: '$2'" |
| 79 | + ;; |
| 80 | + esac |
| 81 | + config="$2" |
| 82 | + shift |
| 83 | + ;; |
| 84 | + --platform) |
| 85 | + case $2 in |
| 86 | + x86_64 | aarch64) ;; |
| 87 | + *) |
| 88 | + user_error "Unrecognized platform: '$2'" |
| 89 | + ;; |
| 90 | + esac |
| 91 | + platform="$2" |
| 92 | + shift |
| 93 | + ;; |
| 94 | + *) |
| 95 | + user_error "Unrecognized argument: '$1'" |
| 96 | + ;; |
| 97 | + esac |
| 98 | + shift |
| 99 | +done |
| 100 | + |
| 101 | +if [[ "$os" == "" ]]; then |
| 102 | + user_error "No OS specified." |
| 103 | +fi |
| 104 | + |
| 105 | +if [[ "$config" == "" ]]; then |
| 106 | + user_error "No build configuration specified." |
| 107 | +fi |
| 108 | + |
| 109 | +if [[ "$bin_dir" == "" ]]; then |
| 110 | + user_error "No binary directory specified." |
| 111 | +fi |
| 112 | + |
| 113 | +if [[ "$skip_file" == "" ]]; then |
| 114 | + user_error "No skip file specified." |
| 115 | +fi |
| 116 | + |
| 117 | +if [[ "$platform" == "" ]]; then |
| 118 | + user_error "No platform specified." |
| 119 | +fi |
| 120 | + |
| 121 | +if [[ ! -f "$skip_file" ]]; then |
| 122 | + user_error "Skip file '$skip_file' does not exist." |
| 123 | +fi |
| 124 | + |
| 125 | +if [[ ! -d "$bin_dir" ]]; then |
| 126 | + user_error "Binary directory '$bin_dir' does not exist." |
| 127 | +fi |
| 128 | + |
| 129 | +summary=() |
| 130 | +failure_count=0 |
| 131 | +skip_count=0 |
| 132 | +sample_count=0 |
| 133 | + |
| 134 | +function skip { |
| 135 | + local p |
| 136 | + local line_index |
| 137 | + p="$1" |
| 138 | + line_index=1 |
| 139 | + while read -r pattern; do |
| 140 | + pat=$pattern |
| 141 | + if [[ ! $pat =~ .*# ]]; then |
| 142 | + user_error "Skip pattern on line $line_index is missing a comment!" |
| 143 | + fi |
| 144 | + pat="${pattern%% *#*}" |
| 145 | + if [[ $p =~ ^$pat$ ]]; then |
| 146 | + return 0 |
| 147 | + fi |
| 148 | + line_index=$((line_index + 1)) |
| 149 | + done <"$skip_file" |
| 150 | + |
| 151 | + return 1 |
| 152 | +} |
| 153 | + |
| 154 | +function run_sample { |
| 155 | + local sample |
| 156 | + local args |
| 157 | + sample="$1" |
| 158 | + shift |
| 159 | + args=("$@") |
| 160 | + sample_count=$((sample_count + 1)) |
| 161 | + summary=("${summary[@]}" "$sample: ") |
| 162 | + if skip "$os:$platform:$config:$sample"; then |
| 163 | + echo "Skipping $sample..." |
| 164 | + summary=("${summary[@]}" " skipped") |
| 165 | + skip_count=$((skip_count + 1)) |
| 166 | + return |
| 167 | + fi |
| 168 | + echo "Running '$sample ${args[*]}'..." |
| 169 | + result=0 |
| 170 | + pushd "$bin_dir" 1>/dev/null 2>&1 |
| 171 | + if [[ ! "$dry_run" = true ]]; then |
| 172 | + ./"$sample" "${args[@]}" || result=$? |
| 173 | + if [[ -f ./"log-$sample.txt" ]]; then |
| 174 | + cat ./"log-$sample.txt" |
| 175 | + fi |
| 176 | + fi |
| 177 | + if [[ $result -eq 0 ]]; then |
| 178 | + summary=("${summary[@]}" " success") |
| 179 | + else |
| 180 | + summary=("${summary[@]}" " failure (exit code: $result)") |
| 181 | + failure_count=$((failure_count + 1)) |
| 182 | + fi |
| 183 | + popd 1>/dev/null 2>&1 |
| 184 | +} |
| 185 | + |
| 186 | +sample_commands=( |
| 187 | + 'platform-test --test-mode' |
| 188 | + 'ray-tracing-pipeline --test-mode' |
| 189 | + 'ray-tracing --test-mode' |
| 190 | + 'shader-toy --test-mode' |
| 191 | + 'triangle --test-mode' |
| 192 | + 'model-viewer --test-mode' |
| 193 | + 'shader-object' |
| 194 | + 'reflection-api' |
| 195 | + 'hello-world' |
| 196 | + 'gpu-printing' |
| 197 | + 'cpu-hello-world' |
| 198 | + 'cpu-com-example' |
| 199 | +) |
| 200 | + |
| 201 | +for sample_command in "${sample_commands[@]}"; do |
| 202 | + run_sample ${sample_command} |
| 203 | + echo "" |
| 204 | +done |
| 205 | + |
| 206 | +echo "" |
| 207 | +echo "Summary: " |
| 208 | +echo |
| 209 | +for line in "${summary[@]}"; do |
| 210 | + printf ' %s\n' "$line" |
| 211 | +done |
| 212 | +echo "" |
| 213 | +echo "$failure_count failed, and $skip_count skipped, out of $sample_count tests" |
| 214 | +if [[ $failure_count -ne 0 ]]; then |
| 215 | + exit 1 |
| 216 | +fi |
0 commit comments