forked from inferno-os/inferno-os
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun-tests.sh
More file actions
executable file
·249 lines (213 loc) · 6.16 KB
/
run-tests.sh
File metadata and controls
executable file
·249 lines (213 loc) · 6.16 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#!/bin/sh
#
# run-tests.sh - InferNode Test Suite Runner
#
# This is the outer harness that runs:
# 1. Host tests (tests/host/*_test.sh) - POSIX sh on host
# 2. Internal tests (tests/runner.dis) - Limbo + Inferno sh inside emu
#
# Usage:
# ./run-tests.sh Run all tests
# ./run-tests.sh -h Run only host tests
# ./run-tests.sh -i Run only internal (emu) tests
# ./run-tests.sh -v Verbose output
#
# Exit codes:
# 0 - All tests passed
# 1 - One or more tests failed
# 77 - Skip (no tests found or prerequisite missing)
#
set -e
# Find root directory
ROOT="$(cd "$(dirname "$0")" && pwd)"
export ROOT
# Platform detection
case "$(uname -s)" in
Darwin) _EMUHOST=MacOSX ;;
Linux) _EMUHOST=Linux ;;
*) echo "Unsupported OS"; exit 1 ;;
esac
# Configuration
HOST_TESTS_DIR="$ROOT/tests/host"
EMU_PATH=""
if [ -x "$ROOT/emu/$_EMUHOST/o.emu" ]; then
EMU_PATH="$ROOT/emu/$_EMUHOST/o.emu"
fi
RUNNER_DIS="/tests/runner.dis"
VERBOSE=0
RUN_HOST=1
RUN_INTERNAL=1
# Counters
HOST_PASSED=0
HOST_FAILED=0
HOST_SKIPPED=0
INTERNAL_PASSED=0
INTERNAL_FAILED=0
INTERNAL_SKIPPED=0
# Colors (if terminal supports it)
if test -t 1; then
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NC='\033[0m'
else
RED=''
GREEN=''
YELLOW=''
NC=''
fi
usage() {
echo "Usage: $0 [-h] [-i] [-v]"
echo " -h Run only host tests"
echo " -i Run only internal (emu) tests"
echo " -v Verbose output"
exit 1
}
# Parse arguments
while getopts "hiv" opt; do
case $opt in
h)
RUN_HOST=1
RUN_INTERNAL=0
;;
i)
RUN_HOST=0
RUN_INTERNAL=1
;;
v)
VERBOSE=1
;;
*)
usage
;;
esac
done
echo "========================================"
echo "InferNode Test Suite"
echo "========================================"
echo ""
# Run host tests
run_host_tests() {
echo "=== HOST TESTS ==="
if [ ! -d "$HOST_TESTS_DIR" ]; then
echo "No host tests directory found at $HOST_TESTS_DIR"
return
fi
# Find all *_test.sh files
for test_script in "$HOST_TESTS_DIR"/*_test.sh; do
[ -f "$test_script" ] || continue
test_name=$(basename "$test_script" _test.sh)
printf '=== HOST %s\n' "$test_name"
# Run the test
if [ "$VERBOSE" = "1" ]; then
if "$test_script"; then
printf '%s--- PASS: %s%s\n' "$GREEN" "$test_name" "$NC"
HOST_PASSED=$((HOST_PASSED + 1))
else
status=$?
if [ "$status" = "77" ]; then
printf '%s--- SKIP: %s%s\n' "$YELLOW" "$test_name" "$NC"
HOST_SKIPPED=$((HOST_SKIPPED + 1))
else
printf '%s--- FAIL: %s%s\n' "$RED" "$test_name" "$NC"
HOST_FAILED=$((HOST_FAILED + 1))
fi
fi
else
if output=$("$test_script" 2>&1); then
printf '%s--- PASS: %s%s\n' "$GREEN" "$test_name" "$NC"
HOST_PASSED=$((HOST_PASSED + 1))
else
status=$?
if [ "$status" = "77" ]; then
printf '%s--- SKIP: %s%s\n' "$YELLOW" "$test_name" "$NC"
HOST_SKIPPED=$((HOST_SKIPPED + 1))
else
printf '%s--- FAIL: %s%s\n' "$RED" "$test_name" "$NC"
HOST_FAILED=$((HOST_FAILED + 1))
# Print output on failure
echo "$output" | sed 's/^/ /'
fi
fi
fi
done
echo ""
}
# Run internal tests via emu
run_internal_tests() {
echo "=== EMU TESTS ==="
# Check if emulator exists
if [ -z "$EMU_PATH" ] || [ ! -x "$EMU_PATH" ]; then
echo "Emulator not found in emu/$_EMUHOST/"
echo "Run 'mk' in emu/$_EMUHOST to build first"
return 1
fi
# Check if runner.dis exists
if [ ! -f "$ROOT/dis/tests/runner.dis" ]; then
echo "runner.dis not found"
echo "Run 'mk' in tests/ to build first"
return 1
fi
# Build emu args
EMU_ARGS="-r$ROOT"
if [ "$VERBOSE" = "1" ]; then
RUNNER_ARGS="-v"
else
RUNNER_ARGS=""
fi
# Run the emulator with the test runner
# Capture output and parse results
echo ""
if output=$("$EMU_PATH" $EMU_ARGS "$RUNNER_DIS" $RUNNER_ARGS 2>&1); then
emu_status=0
else
emu_status=$?
fi
# Print output
echo "$output"
# Parse the summary line to extract counts
# Format: "Total: X passed, Y failed, Z skipped"
if total_line=$(echo "$output" | grep "^Total:"); then
INTERNAL_PASSED=$(echo "$total_line" | sed 's/.*Total:[[:space:]]*\([0-9]*\) passed.*/\1/')
INTERNAL_FAILED=$(echo "$total_line" | sed 's/.*passed, \([0-9]*\) failed.*/\1/')
INTERNAL_SKIPPED=$(echo "$total_line" | sed 's/.*failed, \([0-9]*\) skipped.*/\1/')
fi
echo ""
return $emu_status
}
# Main execution
OVERALL_STATUS=0
if [ "$RUN_HOST" = "1" ]; then
run_host_tests || true
fi
if [ "$RUN_INTERNAL" = "1" ]; then
run_internal_tests || OVERALL_STATUS=1
fi
# Print final summary
echo "========================================"
echo "Summary"
echo "========================================"
if [ "$RUN_HOST" = "1" ]; then
printf 'Host tests: %d passed, %d failed, %d skipped\n' \
"$HOST_PASSED" "$HOST_FAILED" "$HOST_SKIPPED"
fi
if [ "$RUN_INTERNAL" = "1" ]; then
printf 'Internal tests: %d passed, %d failed, %d skipped\n' \
"$INTERNAL_PASSED" "$INTERNAL_FAILED" "$INTERNAL_SKIPPED"
fi
TOTAL_PASSED=$((HOST_PASSED + INTERNAL_PASSED))
TOTAL_FAILED=$((HOST_FAILED + INTERNAL_FAILED))
TOTAL_SKIPPED=$((HOST_SKIPPED + INTERNAL_SKIPPED))
printf 'Total: %d passed, %d failed, %d skipped\n' \
"$TOTAL_PASSED" "$TOTAL_FAILED" "$TOTAL_SKIPPED"
echo ""
if [ "$TOTAL_FAILED" -gt 0 ] || [ "$OVERALL_STATUS" != "0" ]; then
printf '%sFAIL%s\n' "$RED" "$NC"
exit 1
fi
if [ "$TOTAL_PASSED" -eq 0 ]; then
printf '%sNO TESTS%s\n' "$YELLOW" "$NC"
exit 77
fi
printf '%sPASS%s\n' "$GREEN" "$NC"
exit 0