-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-all.sh
More file actions
executable file
·352 lines (306 loc) · 10 KB
/
test-all.sh
File metadata and controls
executable file
·352 lines (306 loc) · 10 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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
#!/bin/bash
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Parse arguments
TEST_TYPE="debug"
VERBOSE=0
UNIT_ONLY=0
INTEGRATION_ONLY=0
while [[ $# -gt 0 ]]; do
case $1 in
release)
TEST_TYPE="release"
shift
;;
-v|--verbose)
VERBOSE=1
shift
;;
--unit-only)
UNIT_ONLY=1
shift
;;
--integration-only)
INTEGRATION_ONLY=1
shift
;;
-h|--help)
echo "Usage: $0 [release] [-v|--verbose] [--unit-only|--integration-only] [-h|--help]"
echo " release Test in release mode (default: debug)"
echo " -v,--verbose Show test output"
echo " --unit-only Run only unit tests"
echo " --integration-only Run only integration tests"
echo " -h,--help Show this help"
exit 0
;;
*)
echo "Unknown argument: $1"
echo "Use -h for help"
exit 1
;;
esac
done
TEST_FLAG=""
if [ "$TEST_TYPE" = "release" ]; then
TEST_FLAG="--release"
fi
# Arrays to track test results
declare -a TEST_TARGETS
declare -a TEST_DESCRIPTIONS
declare -a TEST_RESULTS
declare -a TEST_TOOLS
echo -e "${BLUE}=== Cross-Platform Test Script ===${NC}"
echo -e "${BLUE}Test type: $TEST_TYPE${NC}"
if [ $VERBOSE -eq 1 ]; then
echo -e "${BLUE}Verbose mode: enabled${NC}"
fi
if [ $UNIT_ONLY -eq 1 ]; then
echo -e "${BLUE}Running: unit tests only${NC}"
elif [ $INTEGRATION_ONLY -eq 1 ]; then
echo -e "${BLUE}Running: integration tests only${NC}"
else
echo -e "${BLUE}Running: all tests${NC}"
fi
echo
# Function to check if command exists
check_command() {
if command -v "$1" >/dev/null 2>&1; then
echo -e "${GREEN}✓${NC} $1 is installed"
return 0
else
echo -e "${RED}✗${NC} $1 is not installed"
return 1
fi
}
# Function to check if Rust target is installed
check_rust_target() {
if rustup target list --installed | grep -q "$1"; then
echo -e "${GREEN}✓${NC} Rust target $1 is installed"
return 0
else
echo -e "${RED}✗${NC} Rust target $1 is not installed"
return 1
fi
}
# Function to check if Docker is running
check_docker() {
if docker info >/dev/null 2>&1; then
echo -e "${GREEN}✓${NC} Docker is running"
return 0
else
echo -e "${RED}✗${NC} Docker is not running"
return 1
fi
}
# Function to attempt test and record result
attempt_test() {
local tool=$1
local target=$2
local description=$3
local test_cmd_args=$4
TEST_TARGETS+=("$target")
TEST_DESCRIPTIONS+=("$description")
TEST_TOOLS+=("$tool")
echo -e "${YELLOW}Testing $description...${NC}"
# Determine output redirection based on verbose flag
local output_redirect=""
if [ $VERBOSE -eq 0 ]; then
output_redirect=">/dev/null 2>&1"
fi
local full_cmd=""
if [ "$tool" = "cargo" ]; then
full_cmd="cargo test --target $target $TEST_FLAG $test_cmd_args"
elif [ "$tool" = "cross" ]; then
full_cmd="cross test --target $target $TEST_FLAG $test_cmd_args"
fi
echo -e "${BLUE}Running: $full_cmd${NC}"
if [ $VERBOSE -eq 1 ]; then
if eval "$full_cmd"; then
TEST_RESULTS+=("SUCCESS")
echo -e "${GREEN}✓${NC} Successfully tested $description"
else
TEST_RESULTS+=("FAILED")
echo -e "${RED}✗${NC} Failed to test $description"
fi
else
if eval "$full_cmd $output_redirect"; then
TEST_RESULTS+=("SUCCESS")
echo -e "${GREEN}✓${NC} Successfully tested $description"
else
TEST_RESULTS+=("FAILED")
echo -e "${RED}✗${NC} Failed to test $description"
fi
fi
echo
}
# Check prerequisites
echo -e "${BLUE}=== Checking Prerequisites ===${NC}"
MISSING_DEPS=0
# Check basic tools
check_command "rustup" || MISSING_DEPS=1
check_command "cargo" || MISSING_DEPS=1
# Check optional tools (don't fail if missing, just skip those tests)
CROSS_AVAILABLE=0
DOCKER_AVAILABLE=0
LINUX_ARM_AVAILABLE=0
MINGW_AVAILABLE=0
if check_command "cross"; then
CROSS_AVAILABLE=1
fi
if check_docker; then
DOCKER_AVAILABLE=1
fi
if check_command "aarch64-linux-gnu-gcc"; then
LINUX_ARM_AVAILABLE=1
fi
if check_command "x86_64-w64-mingw32-gcc"; then
MINGW_AVAILABLE=1
fi
echo
# Check Rust targets
echo -e "${BLUE}=== Checking Rust Targets ===${NC}"
TARGET_X86_LINUX=0
TARGET_ARM_LINUX=0
TARGET_WIN_GNU=0
TARGET_MAC_X86=0
TARGET_MAC_ARM=0
check_rust_target "x86_64-unknown-linux-gnu" && TARGET_X86_LINUX=1
check_rust_target "aarch64-unknown-linux-gnu" && TARGET_ARM_LINUX=1
check_rust_target "x86_64-pc-windows-gnu" && TARGET_WIN_GNU=1
check_rust_target "x86_64-apple-darwin" && TARGET_MAC_X86=1
check_rust_target "aarch64-apple-darwin" && TARGET_MAC_ARM=1
echo
if [ $MISSING_DEPS -eq 1 ]; then
echo -e "${RED}Critical dependencies missing (rustup/cargo). Cannot continue.${NC}"
exit 1
fi
# Determine test command arguments based on flags
TEST_CMD_ARGS=""
if [ $UNIT_ONLY -eq 1 ]; then
TEST_CMD_ARGS="--lib"
elif [ $INTEGRATION_ONLY -eq 1 ]; then
TEST_CMD_ARGS="--test '*'"
fi
echo -e "${GREEN}Starting tests with available tools...${NC}"
echo
# Cross-based tests (need cross + docker)
CROSS_READY=0
if [ $CROSS_AVAILABLE -eq 1 ] && [ $DOCKER_AVAILABLE -eq 1 ]; then
CROSS_READY=1
fi
# Start testing
echo -e "${BLUE}=== Cross-Platform Tests ===${NC}"
# Native test (always available)
if [ $TARGET_X86_LINUX -eq 1 ]; then
attempt_test "cargo" "x86_64-unknown-linux-gnu" "Linux x86_64 (native)" "$TEST_CMD_ARGS"
else
TEST_TARGETS+=("x86_64-unknown-linux-gnu")
TEST_DESCRIPTIONS+=("Linux x86_64 (native)")
TEST_TOOLS+=("cargo")
TEST_RESULTS+=("SKIPPED - target not installed")
fi
# Linux ARM64 test (requires emulation or cross, so use cross if available)
if [ $TARGET_ARM_LINUX -eq 1 ] && [ $CROSS_READY -eq 1 ]; then
attempt_test "cross" "aarch64-unknown-linux-gnu" "Linux ARM64 (cross-test)" "$TEST_CMD_ARGS"
elif [ $TARGET_ARM_LINUX -eq 0 ]; then
TEST_TARGETS+=("aarch64-unknown-linux-gnu")
TEST_DESCRIPTIONS+=("Linux ARM64 (cross-test)")
TEST_TOOLS+=("cross")
TEST_RESULTS+=("SKIPPED - target not installed")
elif [ $CROSS_READY -eq 0 ]; then
TEST_TARGETS+=("aarch64-unknown-linux-gnu")
TEST_DESCRIPTIONS+=("Linux ARM64 (cross-test)")
TEST_TOOLS+=("cross")
TEST_RESULTS+=("SKIPPED - cross/docker not available")
fi
# Windows GNU test (requires Wine or cross for execution, so use cross if available)
if [ $TARGET_WIN_GNU -eq 1 ] && [ $CROSS_READY -eq 1 ]; then
attempt_test "cross" "x86_64-pc-windows-gnu" "Windows x86_64 GNU (cross-test)" "$TEST_CMD_ARGS"
elif [ $TARGET_WIN_GNU -eq 0 ]; then
TEST_TARGETS+=("x86_64-pc-windows-gnu")
TEST_DESCRIPTIONS+=("Windows x86_64 GNU (cross-test)")
TEST_TOOLS+=("cross")
TEST_RESULTS+=("SKIPPED - target not installed")
elif [ $CROSS_READY -eq 0 ]; then
TEST_TARGETS+=("x86_64-pc-windows-gnu")
TEST_DESCRIPTIONS+=("Windows x86_64 GNU (cross-test)")
TEST_TOOLS+=("cross")
TEST_RESULTS+=("SKIPPED - cross/docker not available")
fi
# macOS tests
if [ $TARGET_MAC_X86 -eq 1 ] && [ $CROSS_READY -eq 1 ]; then
attempt_test "cross" "x86_64-apple-darwin" "macOS Intel" "$TEST_CMD_ARGS"
elif [ $TARGET_MAC_X86 -eq 0 ]; then
TEST_TARGETS+=("x86_64-apple-darwin")
TEST_DESCRIPTIONS+=("macOS Intel")
TEST_TOOLS+=("cross")
TEST_RESULTS+=("SKIPPED - target not installed")
elif [ $CROSS_READY -eq 0 ]; then
TEST_TARGETS+=("x86_64-apple-darwin")
TEST_DESCRIPTIONS+=("macOS Intel")
TEST_TOOLS+=("cross")
TEST_RESULTS+=("SKIPPED - cross/docker not available")
fi
if [ $TARGET_MAC_ARM -eq 1 ] && [ $CROSS_READY -eq 1 ]; then
attempt_test "cross" "aarch64-apple-darwin" "macOS Apple Silicon" "$TEST_CMD_ARGS"
elif [ $TARGET_MAC_ARM -eq 0 ]; then
TEST_TARGETS+=("aarch64-apple-darwin")
TEST_DESCRIPTIONS+=("macOS Apple Silicon")
TEST_TOOLS+=("cross")
TEST_RESULTS+=("SKIPPED - target not installed")
elif [ $CROSS_READY -eq 0 ]; then
TEST_TARGETS+=("aarch64-apple-darwin")
TEST_DESCRIPTIONS+=("macOS Apple Silicon")
TEST_TOOLS+=("cross")
TEST_RESULTS+=("SKIPPED - cross/docker not available")
fi
# Display results table
echo
echo -e "${BLUE}=== Test Results Summary ===${NC}"
echo
printf "%-30s %-25s %-8s %-s\n" "Platform" "Target" "Tool" "Result"
printf "%-30s %-25s %-8s %-s\n" "--------" "------" "----" "------"
SUCCESS_COUNT=0
FAILED_COUNT=0
SKIPPED_COUNT=0
for i in "${!TEST_TARGETS[@]}"; do
target="${TEST_TARGETS[i]}"
description="${TEST_DESCRIPTIONS[i]}"
result="${TEST_RESULTS[i]}"
tool="${TEST_TOOLS[i]}"
if [[ "$result" == "SUCCESS" ]]; then
printf "%-30s %-25s %-8s ${GREEN}%-s${NC}\n" "$description" "$target" "$tool" "$result"
((SUCCESS_COUNT++))
elif [[ "$result" == "FAILED" ]]; then
printf "%-30s %-25s %-8s ${RED}%-s${NC}\n" "$description" "$target" "$tool" "$result"
((FAILED_COUNT++))
else
printf "%-30s %-25s %-8s ${YELLOW}%-s${NC}\n" "$description" "$target" "$tool" "$result"
((SKIPPED_COUNT++))
fi
done
echo
echo -e "${BLUE}Summary: ${GREEN}$SUCCESS_COUNT successful${NC}, ${RED}$FAILED_COUNT failed${NC}, ${YELLOW}$SKIPPED_COUNT skipped${NC}"
# Show test artifacts if any exist
if [ $SUCCESS_COUNT -gt 0 ]; then
echo
echo -e "${BLUE}=== Test Artifacts ===${NC}"
# Look for test reports or coverage files
if [ -d "target" ]; then
find target -name "*.profraw" -o -name "*.gcda" -o -name "test-results.xml" 2>/dev/null | sort | while read artifact; do
if [ -f "$artifact" ]; then
echo -e "${GREEN}✓${NC} $artifact"
fi
done
fi
fi
echo
echo -e "${BLUE}Test script completed!${NC}"
# Exit with failure if any tests failed
if [ $FAILED_COUNT -gt 0 ]; then
exit 1
fi