-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathrun_tests.sh
More file actions
executable file
·98 lines (89 loc) · 2.55 KB
/
run_tests.sh
File metadata and controls
executable file
·98 lines (89 loc) · 2.55 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
#!/bin/bash -e
set -e
export SHELL="$1"
if [ "$SHELL" = "" ]; then
echo "need to specify shell to test"
exit 1
fi
. /etc/os-release
if [ "$SHELL" = dash ] && ! ( [ "$ID" = debian ] || [ "$ID_LIKE" = debian ] ); then
exit 0
fi
if [ "$SHELL" = busybox ]; then
export TEST_SHELL="busybox sh";
else
export TEST_SHELL="$SHELL"
fi
# Create temporary directory for test outputs
output_dir="$(mktemp -d)"
declare -a test_files=()
declare -a test_pids=()
declare -a test_outputs=()
# Collect all test files
for dir in unit sdk auto integration; do
while IFS= read -r file; do
test_files+=("$file")
done < <({ find $dir -iname 'test_*.sh'; find $dir -iname 'test_*.'"$SHELL"; } | sort -u)
done
# Run all tests in parallel
for file in "${test_files[@]}"; do
(
rm /tmp/opentelemetry_shell_*_instrumentation_cache_*.aliases 2> /dev/null || true
export OTEL_EXPORT_LOCATION="$(mktemp -u)".sdk.out
export OTEL_SHELL_SDK_STDOUT_REDIRECT="$(mktemp -u -p "$(mktemp -d)")".pipe
export OTEL_TRACES_EXPORTER=console
export OTEL_METRICS_EXPORTER=console
export OTEL_LOGS_EXPORTER=console
mkfifo -m 666 "$OTEL_SHELL_SDK_STDOUT_REDIRECT"
( while true; do cat "$OTEL_SHELL_SDK_STDOUT_REDIRECT" >> "$OTEL_EXPORT_LOCATION"; done & )
options='-f -u'
if [ "$TEST_SHELL" = bash ]; then
options="$options -p -o pipefail"
fi
stdout="$(mktemp -u -p "$(mktemp -d)").out"
stderr="$(mktemp -u -p "$(mktemp -d)").err"
touch "$stdout" "$stderr"
chmod 0666 "$stdout" "$stderr"
export OTEL_SHELL_SDK_STDERR_REDIRECT="$stderr"
# Run test and capture result
test_output="$output_dir/$(basename "$file").output"
if timeout $((60 * 60 * 3)) "$TEST_SHELL" $options "$file" 1> "$stdout"; then
echo "$file SUCCEEDED" > "$test_output"
exit 0
else
{
echo "$file FAILED"
echo "stdout:"
cat "$stdout"
echo "stderr:"
cat "$stderr"
echo "otlp:"
cat "$OTEL_EXPORT_LOCATION"
} > "$test_output"
exit 1
fi
) &
test_pids+=($!)
test_outputs+=("$output_dir/$(basename "$file").output")
done
# Wait for all tests to complete and track failures
failed=0
for i in "${!test_pids[@]}"; do
if ! wait "${test_pids[$i]}"; then
failed=1
fi
done
# Print all outputs sequentially
for i in "${!test_files[@]}"; do
echo "running ${test_files[$i]}"
if [ -f "${test_outputs[$i]}" ]; then
cat "${test_outputs[$i]}"
fi
done
# Clean up
rm -rf "$output_dir"
# Exit with failure if any test failed
if [ "$failed" -eq 1 ]; then
exit 1
fi
echo "ALL TESTS SUCCESSFUL"