Last active
May 9, 2024 17:43
-
-
Save zmike/e8eec8fdb6eb1d264828b2affede993b to your computer and use it in GitHub Desktop.
parallel GL conformance runner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
CTS_DIR=~/src/VK-GL-CTS/release/external/openglcts/modules | |
# arg variable init | |
output_dir= | |
run_stress= | |
args=() | |
# by default run one job per cpu thread | |
nr_cpus=$(grep -w processor /proc/cpuinfo|wc -l) | |
while [[ $# -gt 0 ]]; do | |
case $1 in | |
-o|--output-dir) | |
# this outputs the logs for each test to a separate file | |
output_dir="$2" | |
shift | |
shift | |
;; | |
-j|--jobs) | |
# override the default job count | |
nr_cpus=$2 | |
shift | |
shift | |
;; | |
-h|--help) | |
echo "./conformance.sh [-o|--output-dir logfile_dir] [-j|--jobs N] ctstype" | |
exit 1 | |
;; | |
-*|--*) | |
echo "unknown arg $1" | |
;; | |
*) | |
args+=("$1") | |
shift | |
;; | |
esac | |
done | |
set -- "${args[@]}" | |
cts_type="$1" | |
if [[ -z $cts_type ]] ; then | |
echo "Must specify cts type! (e.g., 'gl46')" | |
exit 1 | |
fi | |
tests=($("$CTS_DIR"/cts-runner --type=$cts_type --summary|grep Config|tr -d ','|cut -d: -f2|sed 's/ /asdf/g')) | |
# runtime variable init | |
nr_tests=${#tests[@]} | |
if [ $nr_tests -lt 1 ] ; then | |
echo "No tests detected! Is cts-runner a valid test exe?" | |
exit 1 | |
fi | |
pids=() | |
# the counter for the number of tests running | |
counter=0 | |
# the index for the next test to run | |
test_idx=0 | |
if [[ -n $output_dir ]] ; then | |
mkdir -p "$output_dir" | |
fi | |
# start test processes until $nr_cpus test processes are running | |
run_tests() { | |
while (($counter < $nr_cpus)) ; do | |
# output to /dev/null by default | |
if [ -z "$output_dir" ] ; then | |
eval ./glcts ${tests[$test_idx]//asdf/ } &>/dev/null & | |
else | |
eval ./glcts ${tests[$test_idx]//asdf/ } &> "$output_dir/${tests[$test_idx]}.log" & | |
fi | |
# capture pid of subprocess | |
pids[$test_idx]=${!} | |
#increment running test counter and test index | |
counter=$((counter+1)) | |
test_idx=$((test_idx+1)) | |
done | |
} | |
echo "Running $nr_tests CTS tests..." | |
r=0 | |
fails=() | |
last_notify=$(date +%s) | |
while (($r<$nr_tests)) ; do | |
# run tests if there are more tests to run | |
if [ $test_idx -lt $nr_tests ] ; then | |
run_tests | |
fi | |
# tests are active: wait for one to finish, store pid to $finished | |
wait -n -p finished &>/dev/null | |
retval=$? | |
pid_count=${#pids[@]} | |
# iterate $pids array to find the index matching $finished | |
for ((c=0; c < $pid_count; c++)) ; do | |
if [[ ${pids[$c]} == $finished ]] ; then | |
# failed/crashed tests have $retval!=0 | |
if [[ $retval != 0 ]] ; then | |
# print failure immediately and store for summary | |
fails+=(${tests[$c]}) | |
echo "FAILED ${tests[$c]//asdf/ }" | |
fi | |
# increment the "done" counter | |
r=$((r+1)) | |
# decrement the "running" counter | |
counter=$((counter-1)) | |
break | |
fi | |
done | |
cur_time=$(date +%s) | |
# only notify every 5s | |
if [ $((last_notify+5)) -lt $cur_time ] ; then | |
echo "$r / $nr_tests complete (${#fails[@]} failures)..." | |
last_notify=$cur_time | |
fi | |
done | |
# nice summary output at the end | |
echo "***********************" | |
echo "Finished in ${SECONDS}s!" | |
if [[ "${#fails[@]}" != 0 ]] ; then | |
echo "${#fails[@]} FAILURES:" | |
for fail in "${fails[@]}" ; do | |
echo "${fail//asdf/ }" | |
done | |
else | |
echo "ALL PASSED!" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment