forked from shader-slang/slang
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-record-replay.sh
More file actions
executable file
·147 lines (119 loc) · 3.53 KB
/
test-record-replay.sh
File metadata and controls
executable file
·147 lines (119 loc) · 3.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
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