-
Notifications
You must be signed in to change notification settings - Fork 132
Expand file tree
/
Copy pathrun_tests.sh
More file actions
executable file
·286 lines (264 loc) · 9.94 KB
/
run_tests.sh
File metadata and controls
executable file
·286 lines (264 loc) · 9.94 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
#!/usr/bin/env bash
set -e
# ============================================================================
# Hailo Apps Infrastructure Test Runner
# ============================================================================
# This script runs the test suite for hailo-apps.
#
# Test Execution Order:
# 1. Sanity checks (environment validation + config integrity)
# 2. Installation tests (resource validation)
# 3. Pipeline tests (functional tests)
# 4. Standalone app tests (smoke tests)
# 5. GenAI tests
#
# Usage:
# ./run_tests.sh # Run all tests (sanity + install + pipelines)
# ./run_tests.sh --sanity # Run only sanity checks
# ./run_tests.sh --install # Run only installation tests
# ./run_tests.sh --pipelines # Run only pipeline tests
# ./run_tests.sh --standalone # Run only standalone app tests
# ./run_tests.sh --genai # Run only GenAI tests
# ./run_tests.sh --no-download # Skip resource download
# ./run_tests.sh --apps detection,pose_estimation # Run only selected apps
# ./run_tests.sh --help # Show help
# ============================================================================
# Directories
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TESTS_DIR="${SCRIPT_DIR}/tests"
LOG_DIR="${TESTS_DIR}/tests_logs"
# Default options
RUN_SANITY=true
RUN_INSTALL=true
RUN_PIPELINES=true
RUN_STANDALONE=true
RUN_GENAI=false
DOWNLOAD_RESOURCES=true
APPS_FILTER=""
PYTEST_K_EXPR=""
EXPLICIT_SUITE_SELECTION=false
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
--sanity)
if [ "$EXPLICIT_SUITE_SELECTION" = false ]; then
RUN_SANITY=false; RUN_INSTALL=false; RUN_PIPELINES=false
RUN_STANDALONE=false; RUN_GENAI=false
EXPLICIT_SUITE_SELECTION=true
fi
RUN_SANITY=true
shift
;;
--install)
if [ "$EXPLICIT_SUITE_SELECTION" = false ]; then
RUN_SANITY=false; RUN_INSTALL=false; RUN_PIPELINES=false
RUN_STANDALONE=false; RUN_GENAI=false
EXPLICIT_SUITE_SELECTION=true
fi
RUN_INSTALL=true
shift
;;
--pipelines)
if [ "$EXPLICIT_SUITE_SELECTION" = false ]; then
RUN_SANITY=false; RUN_INSTALL=false; RUN_PIPELINES=false
RUN_STANDALONE=false; RUN_GENAI=false
EXPLICIT_SUITE_SELECTION=true
fi
RUN_PIPELINES=true
shift
;;
--standalone)
if [ "$EXPLICIT_SUITE_SELECTION" = false ]; then
RUN_SANITY=false; RUN_INSTALL=false; RUN_PIPELINES=false
RUN_STANDALONE=false; RUN_GENAI=false
EXPLICIT_SUITE_SELECTION=true
fi
RUN_STANDALONE=true
shift
;;
--genai)
if [ "$EXPLICIT_SUITE_SELECTION" = false ]; then
RUN_SANITY=false; RUN_INSTALL=false; RUN_PIPELINES=false
RUN_STANDALONE=false; RUN_GENAI=false
EXPLICIT_SUITE_SELECTION=true
fi
RUN_GENAI=true
shift
;;
--no-download)
DOWNLOAD_RESOURCES=false
shift
;;
--apps)
if [[ -z "${2:-}" ]]; then
echo "Error: --apps requires a comma-separated list (e.g. --apps detection,pose_estimation)"
exit 1
fi
APPS_FILTER="$2"
if [ "$EXPLICIT_SUITE_SELECTION" = false ]; then
RUN_SANITY=false; RUN_INSTALL=false; RUN_PIPELINES=false
RUN_STANDALONE=false; RUN_GENAI=false
EXPLICIT_SUITE_SELECTION=true
fi
RUN_PIPELINES=true
RUN_STANDALONE=true
shift 2
;;
--help|-h)
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " --sanity Run only sanity checks (environment validation)"
echo " --install Run only installation tests (resource validation)"
echo " --pipelines Run only pipeline tests (functional tests)"
echo " --standalone Run standalone app smoke tests"
echo " --genai Run GenAI app tests"
echo " --apps LIST Run only selected pipeline + standalone apps (comma-separated)"
echo " --no-download Skip resource download step"
echo " --help, -h Show this help message"
echo ""
echo "Examples:"
echo " $0 --apps detection"
echo " $0 --apps detection,pose_estimation"
echo " $0 --standalone"
echo " $0 --genai"
echo " $0 --pipelines --standalone"
echo ""
echo "Without options, runs: sanity -> install -> pipelines"
exit 0
;;
*)
echo "Unknown option: $1"
echo "Use --help for usage information"
exit 1
;;
esac
done
# Build optional pytest app filter expression for pipeline/standalone tests
if [[ -n "$APPS_FILTER" ]]; then
IFS=',' read -r -a APPS_ARRAY <<< "$APPS_FILTER"
for raw_app in "${APPS_ARRAY[@]}"; do
app="$(echo "$raw_app" | xargs)"
if [[ -n "$app" ]]; then
if [[ -z "$PYTEST_K_EXPR" ]]; then
PYTEST_K_EXPR="$app"
else
PYTEST_K_EXPR+=" or $app"
fi
fi
done
if [[ -z "$PYTEST_K_EXPR" ]]; then
echo "Error: --apps provided but no valid app names were parsed"
exit 1
fi
fi
# Create log directory
mkdir -p "${LOG_DIR}"
echo "============================================================================"
echo "Hailo Apps Infrastructure Test Runner"
echo "============================================================================"
echo ""
# Activate the virtual environment
echo "Activating virtual environment..."
source "${SCRIPT_DIR}/setup_env.sh"
# Install pytest and test dependencies
echo "Installing test requirements..."
python -m pip install --upgrade pip --quiet
python -m pip install -r "${TESTS_DIR}/test_resources/requirements.txt" --quiet
# Download resources for detected architecture only
if [ "$DOWNLOAD_RESOURCES" = true ]; then
echo ""
echo "============================================================================"
echo "Downloading resources for detected architecture..."
echo "============================================================================"
# Download default models for all apps (for detected architecture only)
# Note: This does NOT download hailo8l resources automatically.
# If you need hailo8l models for h8l_on_h8 tests, run manually:
# python -m hailo_apps.installation.download_resources --arch hailo8l
python -m hailo_apps.installation.download_resources
fi
# Run tests
echo ""
echo "============================================================================"
echo "Running Tests"
echo "============================================================================"
FAILED_TESTS=0
# 1. Sanity Checks - Environment validation + config integrity
if [ "$RUN_SANITY" = true ]; then
echo ""
echo "--- Running Sanity Checks (Environment Validation) ---"
if python -m pytest "${TESTS_DIR}/test_sanity_check.py" "${TESTS_DIR}/test_config_integrity.py" -v --log-cli-level=INFO; then
echo "✓ Sanity checks passed"
else
echo "✗ Sanity checks failed (continuing with remaining tests)"
FAILED_TESTS=$((FAILED_TESTS + 1))
fi
fi
# 2. Installation Tests - Resource validation
if [ "$RUN_INSTALL" = true ]; then
echo ""
echo "--- Running Installation Tests (Resource Validation) ---"
if python -m pytest "${TESTS_DIR}/test_installation.py" -v --log-cli-level=INFO; then
echo "✓ Installation tests passed"
else
echo "✗ Installation tests failed (continuing with remaining tests)"
FAILED_TESTS=$((FAILED_TESTS + 1))
fi
fi
# 3. Pipeline Tests - Functional tests
if [ "$RUN_PIPELINES" = true ]; then
echo ""
echo "--- Running Pipeline Tests (Functional Tests) ---"
PIPELINE_PYTEST_ARGS=("${TESTS_DIR}/test_runner.py" -v --log-cli-level=INFO)
if [[ -n "$PYTEST_K_EXPR" ]]; then
echo "Filtering pipeline tests to apps: ${APPS_FILTER}"
PIPELINE_PYTEST_ARGS+=( -k "$PYTEST_K_EXPR" )
fi
if python -m pytest "${PIPELINE_PYTEST_ARGS[@]}"; then
echo "✓ Pipeline tests passed"
else
echo "✗ Pipeline tests failed"
FAILED_TESTS=$((FAILED_TESTS + 1))
fi
fi
# 4. Standalone App Tests - Functional smoke tests
if [ "$RUN_STANDALONE" = true ]; then
echo ""
echo "--- Running Standalone App Tests ---"
STANDALONE_PYTEST_ARGS=("${TESTS_DIR}/test_standalone_runner.py" -v --log-cli-level=INFO)
if [[ -n "$PYTEST_K_EXPR" ]]; then
echo "Filtering standalone tests to apps: ${APPS_FILTER}"
STANDALONE_PYTEST_ARGS+=( -k "$PYTEST_K_EXPR" )
fi
if python -m pytest "${STANDALONE_PYTEST_ARGS[@]}"; then
echo "✓ Standalone tests passed"
else
echo "✗ Standalone tests failed"
FAILED_TESTS=$((FAILED_TESTS + 1))
fi
fi
# 5. GenAI Tests
if [ "$RUN_GENAI" = true ]; then
echo ""
echo "--- Running GenAI Tests ---"
if python -m pytest "${TESTS_DIR}/test_gen_ai.py" "${TESTS_DIR}/voice_assistant_unit_tests.py" -v --log-cli-level=INFO; then
echo "✓ GenAI tests passed"
else
echo "✗ GenAI tests failed"
FAILED_TESTS=$((FAILED_TESTS + 1))
fi
fi
# Summary
echo ""
echo "============================================================================"
echo "Test Summary"
echo "============================================================================"
if [ $FAILED_TESTS -eq 0 ]; then
echo "✓ All tests completed successfully!"
exit 0
else
echo "✗ ${FAILED_TESTS} test suite(s) failed"
echo ""
echo "Check the logs in ${LOG_DIR} for details."
exit 1
fi