-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·502 lines (440 loc) · 14.5 KB
/
Copy pathtest.sh
File metadata and controls
executable file
·502 lines (440 loc) · 14.5 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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
#!/bin/bash
# Rong Test Runner
# Supports running tests across all JavaScript engines
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Logging helpers
log_info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
log_success() {
echo -e "${GREEN}[PASS]${NC} $1"
}
log_error() {
echo -e "${RED}[FAIL]${NC} $1"
}
log_warning() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
HOST_TLS_BACKEND="${HOST_TLS_BACKEND:-tls-aws-lc}"
SUPPORTED_ENGINES=("quickjs" "jscore" "arkjs")
# Apple's system-framework feature set omits private SPI by default, so that
# production shape remains covered. Source/JSCOnly builds force preemption via
# `jscore-source`; the system path gets a dedicated interrupt-spi run below.
jscore_features() {
local feature_set="jscore,$HOST_TLS_BACKEND"
if [[ -n "${RONG_JSC_SOURCE:-}" ]]; then
feature_set="$feature_set,rong/jscore-source"
fi
echo "$feature_set"
}
# Additionally exercise JSC hard interruption behind the opt-in SPI feature.
run_jscore_interrupt_spi() {
local features
features="$(jscore_features),rong/jscore-interrupt"
log_info "Running interrupt tests with JSC execution-time-limit SPI"
TOTAL_TESTS=$((TOTAL_TESTS + 1))
if run_cargo_test --test=interrupt --no-default-features \
--features="$features" --quiet; then
log_success "JSC execution-time-limit SPI interrupt tests passed"
PASSED_TESTS=$((PASSED_TESTS + 1))
return 0
else
log_error "JSC execution-time-limit SPI interrupt tests failed"
FAILED_TESTS=$((FAILED_TESTS + 1))
if [[ "$FAIL_FAST" == true ]]; then
log_error "Stopping due to fail-fast mode (default); use -k/--continue-on-error to keep going"
print_summary
exit 1
fi
return 1
fi
}
run_cargo_test() {
if [[ -n "${RONG_TEST_TIMEOUT_SECONDS:-}" ]] && command -v perl >/dev/null 2>&1; then
perl -e 'alarm shift; exec @ARGV' "$RONG_TEST_TIMEOUT_SECONDS" cargo test "$@"
else
cargo test "$@"
fi
}
host_is_apple() {
rustc -vV | grep -q '^host: .*apple'
}
jscore_source_configured() {
[[ -n "${RONG_JSC_SOURCE:-}" ]] ||
[[ -n "${RONG_JSC_ROOT:-}" ]]
}
jscore_source_lib_dir() {
local target
target="$(rustc -vV | awk '/^host: / { print $2; exit }')"
if [[ -n "${RONG_JSC_ROOT:-}" ]]; then
local dirs=(
"$RONG_JSC_ROOT/lib"
"$RONG_JSC_ROOT/usr/lib"
"$RONG_JSC_ROOT/WebKitBuild/JSCOnly/Release/lib"
"$RONG_JSC_ROOT/WebKitBuild/Release/lib"
)
local dir
for dir in "${dirs[@]}"; do
if [[ -d "$dir/JavaScriptCore.framework" ]]; then
echo "$dir"
return 0
fi
done
echo "$RONG_JSC_ROOT/lib"
return 0
fi
local cache_base
if [[ -n "${RONG_JSC_CACHE_DIR:-}" ]]; then
cache_base="$RONG_JSC_CACHE_DIR"
else
cache_base="${XDG_CACHE_HOME:-$HOME/.cache}/rong/webkit"
fi
echo "$cache_base/$target/lib"
}
configure_jscore_source_apple_runtime() {
local engine=$1
if [[ "$engine" != "jscore" ]] || ! host_is_apple || ! jscore_source_configured; then
return 0
fi
local lib_dir
lib_dir="$(jscore_source_lib_dir)"
[[ -n "$lib_dir" ]] || return 0
case " ${RUSTFLAGS:-} " in
*"-Wl,-rpath,$lib_dir"*) ;;
*) export RUSTFLAGS="${RUSTFLAGS:+$RUSTFLAGS }-C link-arg=-Wl,-rpath,$lib_dir" ;;
esac
export DYLD_FRAMEWORK_PATH="$lib_dir${DYLD_FRAMEWORK_PATH:+:$DYLD_FRAMEWORK_PATH}"
log_info "Using JSC source framework path: $lib_dir"
}
ENGINES=("quickjs")
if host_is_apple || jscore_source_configured; then
ENGINES+=("jscore")
fi
# Cleanup function to kill child processes
cleanup() {
if [[ "${CLEANED_UP:-false}" == true ]]; then
return 0
fi
CLEANED_UP=true
if pgrep -P $$ >/dev/null 2>&1; then
log_warning "Cleaning up child processes..."
pkill -TERM -P $$ 2>/dev/null || true
sleep 0.2
pkill -KILL -P $$ 2>/dev/null || true
wait 2>/dev/null || true
fi
}
# Set trap to cleanup on exit/signals
trap cleanup EXIT
trap 'cleanup; exit 130' INT
trap 'cleanup; exit 143' TERM
# Auto-discover test categories
get_core_tests() {
if [[ -d "tests" ]]; then
find tests -name "*.rs" -type f | sed 's|tests/||; s|\.rs$||' | sort
fi
}
get_module_tests() {
if [[ -d "modules" ]]; then
find modules -maxdepth 1 -type d | sed 's|modules/||' | grep -v '^$' | grep -v '^modules$' | grep -v '^\.' | sort
fi
}
# Initialize test arrays
CORE_TESTS=($(get_core_tests))
MODULE_TESTS=($(get_module_tests))
# Statistics
TOTAL_TESTS=0
PASSED_TESTS=0
FAILED_TESTS=0
print_header() {
echo -e "${BLUE}================================${NC}"
echo -e "${BLUE} Rong Test Runner${NC}"
echo -e "${BLUE}================================${NC}"
}
print_usage() {
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " -e, --engine ENGINE Run tests for specific engine (quickjs, jscore, arkjs, all)"
echo " -t, --test TEST Run specific test (core test name or module name)"
echo " -c, --core Run only core tests"
echo " -m, --modules Run only module tests"
echo " -k, --continue-on-error Continue running tests after failure (default: stop on error)"
echo " -h, --help Show this help message"
echo ""
echo "Examples:"
echo " $0 # Run all tests, stop on first failure"
echo " $0 -k # Run all tests, continue on failures"
echo " $0 -e quickjs # Run all tests on QuickJS"
echo " $0 -e jscore -c # Run core tests on JavaScriptCore"
echo " $0 -e arkjs # Show how to run ArkJS device-side tests"
echo " $0 -t iterator # Run iterator tests on all engines"
echo " $0 -t rong_http # Run rong_http module tests on all engines"
echo " $0 -k -m # Run all module tests, continue on error"
}
print_arkjs_instructions() {
echo -e "${BLUE}================================${NC}"
echo -e "${BLUE} ArkJS Test Flow${NC}"
echo -e "${BLUE}================================${NC}"
echo "ArkJS tests run on a HarmonyOS device via the smoke app."
echo ""
echo "Run:"
echo " ./testing/harmony/dev.sh test"
echo ""
echo "The script prints the JSON-derived test summary on the PC."
echo "For debug logs only:"
echo " hdc hilog | grep RongSmoke"
echo ""
echo "The device-side smoke run includes the generated tests from tests/*.rs,"
echo "including the Rong worker/runtime cases from tests/rong.rs."
}
run_core_test() {
local test_name=$1
local engine=$2
local feature_set="$engine,$HOST_TLS_BACKEND"
if [[ "$engine" == "jscore" ]]; then
feature_set="$(jscore_features)"
fi
log_info "Running core test: $test_name (engine: $engine)"
TOTAL_TESTS=$((TOTAL_TESTS + 1))
if run_cargo_test --test="$test_name" --no-default-features --features="$feature_set" --quiet; then
log_success "Core test $test_name passed on $engine"
PASSED_TESTS=$((PASSED_TESTS + 1))
return 0
else
log_error "Core test $test_name failed on $engine"
FAILED_TESTS=$((FAILED_TESTS + 1))
if [[ "$FAIL_FAST" == true ]]; then
log_error "Stopping due to fail-fast mode (default); use -k/--continue-on-error to keep going"
print_summary
exit 1
fi
return 1
fi
}
run_module_test() {
local module_name=$1
local engine=$2
log_info "Running module test: $module_name (engine: $engine)"
TOTAL_TESTS=$((TOTAL_TESTS + 1))
local feature_set="$engine,$HOST_TLS_BACKEND"
if [[ "$engine" == "jscore" ]]; then
feature_set="$(jscore_features)"
fi
local cargo_args=(-p "$module_name" --no-default-features --features="$feature_set" --quiet)
if [[ "$module_name" == "rong_timer" ]]; then
# Timer tests share the global host executor and are sensitive to crate-level test overlap.
cargo_args+=(-- --test-threads=1)
fi
if run_cargo_test "${cargo_args[@]}"; then
log_success "Module test $module_name passed on $engine"
PASSED_TESTS=$((PASSED_TESTS + 1))
return 0
else
log_error "Module test $module_name failed on $engine"
FAILED_TESTS=$((FAILED_TESTS + 1))
if [[ "$FAIL_FAST" == true ]]; then
log_error "Stopping due to fail-fast mode (default); use -k/--continue-on-error to keep going"
print_summary
exit 1
fi
return 1
fi
}
feature_set_for() {
local engine=$1
if [[ "$engine" == "jscore" ]]; then
jscore_features
else
echo "$engine,$HOST_TLS_BACKEND"
fi
}
record_suite_result() {
local name=$1
local status=$2
TOTAL_TESTS=$((TOTAL_TESTS + 1))
if [[ "$status" -eq 0 ]]; then
log_success "$name"
PASSED_TESTS=$((PASSED_TESTS + 1))
return 0
fi
log_error "$name"
FAILED_TESTS=$((FAILED_TESTS + 1))
if [[ "$FAIL_FAST" == true ]]; then
log_error "Stopping due to fail-fast mode (default); use -k/--continue-on-error to keep going"
print_summary
exit 1
fi
return 1
}
run_all_core_tests() {
local engine=$1
local feature_set
feature_set="$(feature_set_for "$engine")"
local extra=()
if [[ "$FAIL_FAST" != true ]]; then
extra+=(--no-fail-fast)
fi
echo -e "\n${YELLOW}Running core tests on $engine...${NC}"
log_info "Running rong integration tests as one cargo test ($engine)"
if run_cargo_test -p rong --no-default-features --features="$feature_set" --tests --quiet "${extra[@]}"; then
record_suite_result "Core integration tests on $engine" 0
else
record_suite_result "Core integration tests on $engine" 1 || true
fi
}
run_all_module_tests() {
local engine=$1
local feature_set
feature_set="$(feature_set_for "$engine")"
local extra=()
if [[ "$FAIL_FAST" != true ]]; then
extra+=(--no-fail-fast)
fi
local package_args=()
local has_timer=false
local module
for module in "${MODULE_TESTS[@]}"; do
if [[ "$module" == "rong_timer" ]]; then
has_timer=true
else
package_args+=(-p "$module")
fi
done
echo -e "\n${YELLOW}Running module tests on $engine...${NC}"
if [[ ${#package_args[@]} -gt 0 ]]; then
log_info "Running module lib tests as one cargo test ($engine)"
if run_cargo_test "${package_args[@]}" --no-default-features --features="$feature_set" --quiet "${extra[@]}"; then
record_suite_result "Module tests on $engine" 0
else
record_suite_result "Module tests on $engine" 1 || true
fi
fi
if [[ "$has_timer" == true ]]; then
log_info "Running rong_timer tests single-threaded ($engine)"
if run_cargo_test -p rong_timer --no-default-features --features="$feature_set" --quiet "${extra[@]}" -- --test-threads=1; then
record_suite_result "rong_timer tests on $engine" 0
else
record_suite_result "rong_timer tests on $engine" 1 || true
fi
fi
}
run_specific_test() {
local test_name=$1
local engine=$2
# Check if it's a core test
for core_test in "${CORE_TESTS[@]}"; do
if [[ "$core_test" == "$test_name" ]]; then
run_core_test "$test_name" "$engine"
return $?
fi
done
# Check if it's a module test
for module_test in "${MODULE_TESTS[@]}"; do
if [[ "$module_test" == "$test_name" ]]; then
run_module_test "$test_name" "$engine"
return $?
fi
done
log_error "Unknown test: $test_name"
return 1
}
print_summary() {
echo -e "\n${BLUE}================================${NC}"
echo -e "${BLUE} Test Summary${NC}"
echo -e "${BLUE}================================${NC}"
echo -e "Total tests: $TOTAL_TESTS"
echo -e "${GREEN}Passed: $PASSED_TESTS${NC}"
echo -e "${RED}Failed: $FAILED_TESTS${NC}"
if [[ $FAILED_TESTS -eq 0 ]]; then
echo -e "\n${GREEN}All tests passed! 🎉${NC}"
exit 0
else
echo -e "\n${RED}Some tests failed! ❌${NC}"
exit 1
fi
}
# Parse command line arguments
ENGINE_FILTER=""
TEST_FILTER=""
CORE_ONLY=false
MODULES_ONLY=false
FAIL_FAST=true # Default: stop on first failure
while [[ $# -gt 0 ]]; do
case $1 in
-e|--engine)
ENGINE_FILTER="$2"
shift 2
;;
-t|--test)
TEST_FILTER="$2"
shift 2
;;
-c|--core)
CORE_ONLY=true
shift
;;
-m|--modules)
MODULES_ONLY=true
shift
;;
-k|--continue-on-error)
FAIL_FAST=false
shift
;;
-h|--help)
print_usage
exit 0
;;
*)
echo "Unknown option: $1"
print_usage
exit 1
;;
esac
done
# Validate engine filter
if [[ -n "$ENGINE_FILTER" && "$ENGINE_FILTER" != "all" ]]; then
if [[ ! " ${SUPPORTED_ENGINES[@]} " =~ " ${ENGINE_FILTER} " ]]; then
log_error "Unknown engine: $ENGINE_FILTER"
echo "Available engines: ${SUPPORTED_ENGINES[*]}"
exit 1
fi
if [[ "$ENGINE_FILTER" == "arkjs" ]]; then
print_arkjs_instructions
exit 0
fi
ENGINES=("$ENGINE_FILTER")
fi
print_header
# Main execution
for engine in "${ENGINES[@]}"; do
echo -e "\n${YELLOW}Testing with engine: $engine${NC}"
configure_jscore_source_apple_runtime "$engine"
if [[ -n "$TEST_FILTER" ]]; then
# Run specific test
run_specific_test "$TEST_FILTER" "$engine" || true
elif [[ "$CORE_ONLY" == true ]]; then
# Run only core tests
run_all_core_tests "$engine"
elif [[ "$MODULES_ONLY" == true ]]; then
# Run only module tests
run_all_module_tests "$engine"
else
# Run all tests
run_all_core_tests "$engine"
run_all_module_tests "$engine"
# Source/JSCOnly builds already force preemption. Re-run only Apple's
# system-framework shape with its explicit private-SPI opt-in.
if [[ "$engine" == "jscore" ]] && host_is_apple && [[ -z "${RONG_JSC_SOURCE:-}" ]]; then
run_jscore_interrupt_spi || true
fi
fi
done
print_summary