@@ -84,16 +84,23 @@ run_test() {
8484
8585 # Clean old results
8686 # Extract exp_dir from config file and clean it
87- local exp_dir=$( grep -E ' ^\s*exp_dir:' " $config_file " | head -1 | sed ' s/.*exp_dir:\s*// ' | tr -d ' " ' | tr -d " '" )
87+ local exp_dir=$( grep -oP ' ^\s*exp_dir:\s*\K\S+ ' " $config_file " | head -1 | tr -d " \ " '" )
8888 if [ -n " $exp_dir " ]; then
8989 log_info " Cleaning old results in: $exp_dir "
9090 rm -rf " $exp_dir " /* 2> /dev/null || true
9191 fi
9292
93- # Run test
94- log_info " Start operation for executing the task: "
95- log_info " python run.py --config-path ${conf_dir} --config-name ${config} action=test"
96- python run.py --config-path ${conf_dir} --config-name ${config} action=test || return 1
93+ # Map task name to flagscale CLI subcommand
94+ # e.g. hetero_train -> train, train -> train, others unchanged
95+ local cli_task=" $task "
96+ case " $task " in
97+ * train* ) cli_task=" train" ;;
98+ esac
99+
100+ # Run test via flagscale CLI
101+ # --config expects the full YAML path
102+ log_info " Running: flagscale $cli_task $model --config $config_file --test"
103+ flagscale " $cli_task " " $model " --config " $config_file " --test || return 1
97104
98105 # Match the corresponding comparison function according to task type
99106 # Matching rules:
@@ -120,44 +127,56 @@ run_test() {
120127 ;;
121128 esac
122129
123- # Validate results if validator exists
124- if [ -f " $PROJECT_ROOT /tests/test_utils/runners/check_results.py" ]; then
125- local validator_cmd=" python -m pytest \" $PROJECT_ROOT /tests/test_utils/runners/check_results.py::$compare_function \" \
126- --path=tests/functional_tests --task=\" $task \" --model=\" $model \" \
127- --case=\" $config \" --platform=\" $PLATFORM \" "
128- [ -n " $CURRENT_DEVICE " ] && validator_cmd=" $validator_cmd --device=\" $CURRENT_DEVICE \" "
129-
130+ # Validate results using pytest-based checker (check_results.py)
131+ # Build command as an array to avoid eval and ensure safe quoting.
132+ local check_results=" $PROJECT_ROOT /tests/test_utils/runners/check_results.py"
133+ if [ -f " $check_results " ]; then
134+ local validator_cmd=(
135+ python -m pytest " ${check_results} ::${compare_function} "
136+ --path=tests/functional_tests
137+ " --task=$task " " --model=$model "
138+ " --case=$config " " --platform=$PLATFORM "
139+ )
140+ [ -n " $CURRENT_DEVICE " ] && validator_cmd+=(" --device=$CURRENT_DEVICE " )
141+
142+ # For serve tasks, wait for the service to be fully ready before validation
130143 if [ " $task " = " serve" ]; then
131144 log_info " Waiting 1 minute for service to be ready..."
132145 sleep 1m
133146 fi
134147
135- if ! eval " $ validator_cmd" ; then
148+ if ! " ${ validator_cmd[@]} " ; then
136149 log_error " Validation failed for $task /$model /$config "
137150 return 1
138151 fi
139152
153+ # Stop the serve process after validation completes
140154 if [ " $task " = " serve" ]; then
141- log_info " Stop operation for executing the serve task: "
142- log_info " python run.py --config-path ${conf_dir} --config-name ${config} action=stop"
143- python run.py --config-path ${conf_dir} --config-name ${config} action=stop
155+ log_info " Stopping serve: flagscale serve $model --config $config_file --stop"
156+ flagscale serve " $model " --config " $config_file " --stop
144157 fi
145158 fi
146159
147160 log_success " Test completed: $task /$model /$config "
148161}
149162
150163# Get tests from platform configuration
164+ # Returns JSON describing which test cases to run for the given device/task/model.
165+ # Uses an array instead of eval to safely handle paths with special characters.
151166get_test_configs () {
152167 local device=" $1 "
153168 local task=" $2 "
154169 local model=" $3 "
155170 local list=" $4 "
156171
157- local cmd=" python \" $SCRIPT_DIR /parse_config.py\" --platform \" $PLATFORM \" --device \" $device \" --type functional --task \" $task \" "
158- [ -n " $model " ] && cmd=" $cmd --model \" $model \" "
159- [ -n " $list " ] && cmd=" $cmd --list \" $list \" "
160- eval " $cmd " 2> /dev/null || echo " "
172+ local cmd=(
173+ python " $SCRIPT_DIR /parse_config.py"
174+ --platform " $PLATFORM " --device " $device "
175+ --type functional --task " $task "
176+ )
177+ [ -n " $model " ] && cmd+=(--model " $model " )
178+ [ -n " $list " ] && cmd+=(--list " $list " )
179+ " ${cmd[@]} " 2> /dev/null || echo " "
161180}
162181
163182# Parse and run tests using helper module
0 commit comments