Repository navigation
Expand file tree
/
Copy pathtests.sh
More file actions
executable file
·278 lines (259 loc) · 10.3 KB
/
Copy pathtests.sh
File metadata and controls
executable file
·278 lines (259 loc) · 10.3 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
#!/bin/bash
set -euo pipefail
# Category directories intentionally reuse focused module names such as
# test_import_safety.py; importlib mode keeps broad collection collision-free.
export PYTEST_ADDOPTS="${PYTEST_ADDOPTS:-} --import-mode=importlib"
# Native Python chooses the path separator, including nested Git Bash on Windows.
PYTHONPATH="$(python -c 'import os; print(os.getcwd() + (os.pathsep + os.environ["PYTHONPATH"] if os.environ.get("PYTHONPATH") else ""))')"
export PYTHONPATH
phase_matched=0
run_phase() {
local status
if "$@"; then
phase_matched=1
return 0
else
status=$?
fi
if [ "$status" -eq 5 ]; then
return 0
fi
return "$status"
}
finish_phases() {
if [ "$phase_matched" -eq 0 ]; then
echo "No tests matched any runner phase." >&2
return 5
fi
}
coverage_control_args() {
pytest_coverage_args=(--no-cov)
local arg
for arg in "$@"; do
if [[ "$arg" == "--cov" || "$arg" == --cov=* ]]; then
pytest_coverage_args=()
return
fi
done
}
partition_process_state_tests() {
local paths=("$@")
process_state_selected=()
ordinary_selected=()
local path
# Process-sensitive tests require a fresh interpreter so earlier optional
# framework imports cannot invalidate their intentional mode transitions.
for path in "${paths[@]}"; do
[[ "$path" == ./tests/session/* ]] && process_state_selected+=("$path")
done
for path in "${paths[@]}"; do
[[ "$path" == ./tests/runtime/* ]] && process_state_selected+=("$path")
done
for path in "${paths[@]}"; do
[[ "$path" == ./tests/core/test_orchestrator_* ]] && process_state_selected+=("$path")
done
for path in "${paths[@]}"; do
[[ "$path" == ./tests/core/test_execute_worker_context.py ]] && process_state_selected+=("$path")
done
for path in "${paths[@]}"; do
[[ "$path" == ./tests/dispatch/* ]] && process_state_selected+=("$path")
done
for path in "${paths[@]}"; do
[[ "$path" == ./tests/qualification/test_ml_workflow_cpu.py ]] && process_state_selected+=("$path")
done
for path in "${paths[@]}"; do
case "$path" in
./tests/session/*|./tests/runtime/*|./tests/core/test_orchestrator_*|./tests/core/test_execute_worker_context.py|./tests/dispatch/*|./tests/qualification/test_ml_workflow_cpu.py) ;;
*) ordinary_selected+=("$path") ;;
esac
done
}
run_tier() {
local tier_name="$1"
shift
local tiers=()
local tier_filter=""
case "$tier_name" in
smoke)
tiers=(smoke)
tier_filter="smoke"
;;
medium)
tiers=(smoke medium)
tier_filter="smoke,medium"
;;
heavy)
tiers=(heavy)
tier_filter="heavy"
;;
*)
echo "Unknown test tier: $tier_name" >&2
exit 2
;;
esac
prepare_suite_args "$@"
mapfile -t selected < <(python ./tests/tools/test_buckets.py select "${tiers[@]}")
if [ "${#selected[@]}" -eq 0 ]; then
echo "No tests selected for tier: $tier_name" >&2
exit 2
fi
if [ "$tier_name" == "heavy" ]; then
partition_process_state_tests "${selected[@]}"
if [ "${#process_state_selected[@]}" -gt 0 ]; then
run_phase pytest --no-cov --dryml-runner-tiers "$tier_filter" "${process_state_selected[@]}" "${stripped_args[@]}"
fi
if [ "${#ordinary_selected[@]}" -gt 0 ]; then
run_phase env DRYML_TEST_BOOTSTRAP_CONTEXTS=1 pytest --no-cov --dryml-runner-tiers "$tier_filter" "${ordinary_selected[@]}" "${stripped_args[@]}"
fi
else
partition_process_state_tests "${selected[@]}"
if [ "${#process_state_selected[@]}" -gt 0 ]; then
run_phase pytest --no-cov --dryml-runner-tiers "$tier_filter" "${process_state_selected[@]}" "${stripped_args[@]}"
fi
if [ "${#ordinary_selected[@]}" -gt 0 ]; then
run_phase pytest --no-cov --dryml-runner-tiers "$tier_filter" "${ordinary_selected[@]}" "${stripped_args[@]}"
fi
fi
finish_phases
}
prepare_suite_args() {
local root_index
if ! root_index="$(python ./tests/tools/test_buckets.py runner-args -- "$@")"; then
return 2
fi
stripped_args=()
local index=0
for arg in "$@"; do
if [ "$index" -ne "$root_index" ]; then
stripped_args+=("$arg")
fi
index=$((index + 1))
done
}
run_maintained() {
prepare_suite_args "$@"
mapfile -t medium_selected < <(python ./tests/tools/test_buckets.py select smoke medium)
mapfile -t heavy_selected < <(python ./tests/tools/test_buckets.py select heavy)
partition_process_state_tests "${medium_selected[@]}"
run_phase pytest --no-cov --dryml-runner-tiers smoke,medium "${process_state_selected[@]}" "${stripped_args[@]}"
run_phase pytest --no-cov --dryml-runner-tiers smoke,medium "${ordinary_selected[@]}" "${stripped_args[@]}"
partition_process_state_tests "${heavy_selected[@]}"
if [ "${#process_state_selected[@]}" -gt 0 ]; then
run_phase pytest --no-cov --dryml-runner-tiers heavy "${process_state_selected[@]}" "${stripped_args[@]}"
fi
if [ "${#ordinary_selected[@]}" -gt 0 ]; then
run_phase env DRYML_TEST_BOOTSTRAP_CONTEXTS=1 pytest --no-cov --dryml-runner-tiers heavy "${ordinary_selected[@]}" "${stripped_args[@]}"
fi
finish_phases
}
run_good_enough() {
prepare_suite_args "$@"
mapfile -t selected < <(python ./tests/tools/test_buckets.py select-profile good-enough smoke medium)
if [ "${#selected[@]}" -eq 0 ]; then
echo "No test files selected for profile: good-enough" >&2
return 2
fi
echo "DRYML good-enough: smoke+medium with named integration representatives; package and heavy tests excluded." >&2
partition_process_state_tests "${selected[@]}"
if [ "${#process_state_selected[@]}" -gt 0 ]; then
run_phase pytest --no-cov --dryml-runner-tiers smoke,medium --dryml-test-profile good-enough "${process_state_selected[@]}" "${stripped_args[@]}"
fi
if [ "${#ordinary_selected[@]}" -gt 0 ]; then
run_phase pytest --no-cov --dryml-runner-tiers smoke,medium --dryml-test-profile good-enough "${ordinary_selected[@]}" "${stripped_args[@]}"
fi
finish_phases
}
run_coverage() {
prepare_suite_args "$@"
mapfile -t medium_selected < <(python ./tests/tools/test_buckets.py select smoke medium)
mapfile -t heavy_selected < <(python ./tests/tools/test_buckets.py select heavy)
partition_process_state_tests "${medium_selected[@]}"
run_coverage_phase smoke,medium "${process_state_selected[@]}"
run_coverage_phase smoke,medium "${ordinary_selected[@]}"
partition_process_state_tests "${heavy_selected[@]}"
run_coverage_phase heavy "${process_state_selected[@]}"
DRYML_TEST_BOOTSTRAP_CONTEXTS=1 run_coverage_phase heavy "${ordinary_selected[@]}"
finish_phases
}
run_coverage_phase() {
local tier_filter="$1"
shift
local append_args=()
if [ "$phase_matched" -eq 1 ]; then
append_args=(--cov-append)
fi
run_phase pytest --cov=dryml "${append_args[@]}" --dryml-runner-tiers "$tier_filter" "$@" "${stripped_args[@]}"
}
run_package() {
prepare_suite_args "$@"
mapfile -t selected < <(python ./tests/tools/test_buckets.py select-category package)
coverage_control_args "${stripped_args[@]}"
run_phase pytest "${pytest_coverage_args[@]}" "${selected[@]}" "${stripped_args[@]}"
finish_phases
}
run_focused() {
coverage_control_args "$@"
pytest "${pytest_coverage_args[@]}" "$@"
}
run_profile() {
local unknown_only=0
local profile_args=()
for arg in "$@"; do
case "$arg" in
--unknown-only)
unknown_only=1
;;
*)
profile_args+=("$arg")
;;
esac
done
prepare_suite_args "${profile_args[@]}"
local output_dir="/tmp/dryml/profile"
mkdir -p "$output_dir"
local medium_output="$output_dir/test-timings-medium.json"
local process_state_output="$output_dir/test-timings-process-state.json"
local heavy_process_state_output="$output_dir/test-timings-heavy-process-state.json"
local heavy_output="$output_dir/test-timings-heavy.json"
local unknown_args=()
if [ "$unknown_only" -eq 1 ]; then
unknown_args=(--dryml-timing-unknown-only)
fi
mapfile -t medium_selected < <(python ./tests/tools/test_buckets.py select smoke medium)
mapfile -t heavy_selected < <(python ./tests/tools/test_buckets.py select heavy)
partition_process_state_tests "${medium_selected[@]}"
run_phase pytest --no-cov --dryml-runner-tiers smoke,medium "${process_state_selected[@]}" --dryml-timing-output "$process_state_output" --dryml-timing-summary "${unknown_args[@]}" "${stripped_args[@]}"
run_phase pytest --no-cov --dryml-runner-tiers smoke,medium "${ordinary_selected[@]}" --dryml-timing-output "$medium_output" --dryml-timing-summary "${unknown_args[@]}" "${stripped_args[@]}"
partition_process_state_tests "${heavy_selected[@]}"
run_phase pytest --no-cov --dryml-runner-tiers heavy "${process_state_selected[@]}" --dryml-timing-output "$heavy_process_state_output" --dryml-timing-summary "${unknown_args[@]}" "${stripped_args[@]}"
run_phase env DRYML_TEST_BOOTSTRAP_CONTEXTS=1 pytest --no-cov --dryml-runner-tiers heavy "${ordinary_selected[@]}" --dryml-timing-output "$heavy_output" --dryml-timing-summary "${unknown_args[@]}" "${stripped_args[@]}"
finish_phases
python ./tests/tools/test_buckets.py update "$process_state_output" "$medium_output" "$heavy_process_state_output" "$heavy_output"
python ./tests/tools/test_buckets.py summary --all-files
}
if [ "$#" -eq 0 ]; then
run_good_enough
elif [[ "$1" == "smoke" || "$1" == "medium" || "$1" == "heavy" ]]; then
mode="$1"
shift
run_tier "$mode" "$@"
elif [[ "$1" == "good-enough" ]]; then
shift
run_good_enough "$@"
elif [[ "$1" == "full" || "$1" == "exhaustive" ]]; then
shift
run_maintained "$@"
elif [[ "$1" == "coverage" ]]; then
shift
run_coverage "$@"
elif [[ "$1" == "package" ]]; then
shift
run_package "$@"
elif [[ "$1" == "profile" ]]; then
shift
run_profile "$@"
elif [[ "$1" == -* ]]; then
run_good_enough "$@"
else
run_focused "$@"
fi