summaryrefslogtreecommitdiff
path: root/test-record-replay.sh
diff options
context:
space:
mode:
authorkaizhangNV <149626564+kaizhangNV@users.noreply.github.com>2024-08-22 12:18:44 -0500
committerGitHub <noreply@github.com>2024-08-22 10:18:44 -0700
commitb5bb82411cc6101b66283f7d0abca7ceb58aa2f6 (patch)
tree192a522513da30b1a92e6c319693aa541729bea9 /test-record-replay.sh
parenta3fbd8f060317332eae951d4a376e830d058469e (diff)
Feature/capture unit test (#4898)
* record/replay: Add tests Modify the hello-world example to generate the hash code for the entry point spirv code, so that we can compare it with replaying the example. Add the test script to run the example and compare the hash code with replaying it. * Check nullptr for out Diagnostics We need to check whether the output Diagnostics is a nullptr, because it's allowed. * Fix the double free pointers * Add triangle example as the new test for record-replay Change the example base to add the offline rendering path because we don't want to display anything when we're in the test mode. This change involves introducing a TestBase that will parse the command line option. It will decide whether we are in the test mode. Disable all the swapchain and windows related creation, instead we will only create one single framebuffer for the render target. * Address comments TODO: In the follow up patches, I will add more tests and integrate the test flow into slang-unit-test.
Diffstat (limited to 'test-record-replay.sh')
-rwxr-xr-xtest-record-replay.sh147
1 files changed, 147 insertions, 0 deletions
diff --git a/test-record-replay.sh b/test-record-replay.sh
new file mode 100755
index 000000000..2faabe954
--- /dev/null
+++ b/test-record-replay.sh
@@ -0,0 +1,147 @@
+#!/usr/bin/env bash
+
+RED='\033[0;31m'
+Green='\033[0;32m'
+NC='\033[0m'
+matchPattern="entrypoint: [0-9]+, target: [0-9]+, hash: [0-9a-fA-F]+"
+
+getHash()
+{
+ matchedLine=$1
+ local -n outputVar=$2
+
+ entrypointIdx=$(echo $matchedLine | grep -oE "entrypoint: [0-9]+" | grep -oE "[0-9]+")
+ targetIdx=$(echo $matchedLine | grep -oE "target: [0-9]+" | grep -oE "[0-9]+")
+ hashCode=$(echo $matchedLine | grep -oE "hash: .*" | grep -oE ": [0-9a-fA-F]+" | grep -oE "[0-9a-fA-F]+")
+
+ outputVar="$entrypointIdx-$targetIdx-$hashCode"
+}
+
+log()
+{
+ msg=$1
+ color=$2
+ printf "${color}$1${NC}\n"
+}
+
+parseStandardOutput()
+{
+ local -n resultArray=$1
+ lines=$2
+
+ for line in "${lines[@]}"
+ do
+ matchLine=$(echo $line | grep -oE "$matchPattern")
+
+ if [ -n "$matchLine" ]; then
+ result=""
+ getHash "$matchLine" result
+
+ if [ -n "$result" ]; then
+ resultArray+=("$result")
+ fi
+ fi
+ done
+}
+
+resultCheck()
+{
+ local -n inExpectedResults=$1
+ local -n inReplayResults=$2
+ local -n outFailedResults=$3
+
+ found=""
+ for expectedResult in ${inExpectedResults[@]}; do
+
+ for replayResult in ${inReplayResults[@]}; do
+ if [ "$replayResult" == "$expectedResult" ]; then
+ found="1"
+ fi
+ done
+
+ if [ -z "$found" ]; then
+ echo "$expectedResult is not Found in replay"
+ outFailedResults+=("$expectedResult")
+ else
+ echo "$expectedResult is Found in replay"
+ fi
+ done
+}
+
+# TODO: Add more test commands here in this array
+testCommands=("./build/Debug/bin/hello-world" "./build/Debug/bin/triangle")
+
+# Enable hash code generation for the test such that
+# we can have something to compare with replaying the test
+argsToEnableHashCode="--test-mode"
+
+declare -A testStats
+
+for ((i = 0; i < ${#testCommands[@]}; i++))
+do
+ testCommand=${testCommands[$i]}
+ echo "Start running test: $testCommand"
+
+ # Run the test executable
+ export SLANG_RECORD_LAYER=1
+ mapfile -t lines < <(${testCommand} ${argsToEnableHashCode})
+ unset SLANG_RECORD_LAYER
+
+ # parse the output from stdout
+ expectedResults=()
+ parseStandardOutput expectedResults "${lines[@]}"
+
+ echo "Expected Results: ${expectedResults[@]}"
+ if [ ${#expectedResults[@]} -eq 0 ]; then
+ log "No expected results found" $RED
+ rm -rf ./slang-record/*
+ continue
+ fi
+
+ # Replay the record file
+ export SLANG_RECORD_LOG_LEVEL=3
+ replayTestCommand="./build/Debug/bin/slang-replay ./slang-record/*.cap"
+ echo "Start replaying the test ..."
+ mapfile -t lines < <(${replayTestCommand})
+ unset SLANG_RECORD_LOG_LEVEL
+
+ # parse the output from stdout
+ replayResults=()
+ parseStandardOutput replayResults "${lines[@]}"
+
+ echo "Replay Results: ${replayResults[@]}"
+ if [ ${#replayResults[@]} -eq 0 ]; then
+ log "No replay results found" $RED
+ rm -rf ./slang-record/*
+ continue
+ fi
+
+ # Check the results
+ failedResults=()
+ resultCheck expectedResults replayResults failedResults
+
+ rm -rf ./slang-record/*
+
+ if [ ${#failedResults[@]} -eq 0 ]; then
+ testStats[$testCommand]="PASSED"
+ else
+ testStats[$testCommand]="FAILED"
+ fi
+ printf "\n"
+done
+
+for testName in "${!testStats[@]}"
+do
+ if [ "${testStats[$testName]}" == "PASSED" ]; then
+ log "$testName: PASSED" $Green
+ else
+ log "$testName: FAILED" $RED
+ fi
+done
+
+# Notify the CI if any of the tests failed
+if [ ${#testStats[@]} -eq 0 ]; then
+ exit 0
+else
+ exit 1
+fi