Skip to content

Commit f6c2ec2

Browse files
committed
Use scenario runner for auto subimage regression
Add XML scenario support and runner invocation for auto subimage regression: write imiv scenario XML, implement _run_scenario to execute the scenario runner, and read per-step state outputs. Refactor previous key-chord based calls to use the scenario file and runtime output paths, and fix zoom expectation to use the enabled step's reported zoom. Add helper _path_for_imiv_output and ensure runtime/config dirs are created. Update upload corpus tooling and tests: move generated corpus paths under build_u/testsuite/imiv/upload_corpus, make oiiotool generate images with explicit constant colors and alpha values, parse channel/color entries properly, set OIIOTOOL_BIN default in ctest wrapper, and only regenerate images when the images directory is missing or empty. Adjust smoke test defaults to the new testsuite paths. Signed-off-by: Vlad (Kuzmin) Erium <libalias@gmail.com>
1 parent b25ebb2 commit f6c2ec2

File tree

4 files changed

+123
-39
lines changed

4 files changed

+123
-39
lines changed

src/imiv/tools/imiv_auto_subimage_regression.py

Lines changed: 102 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import shutil
1212
import subprocess
1313
import sys
14+
import xml.etree.ElementTree as ET
1415
from pathlib import Path
1516

1617

@@ -177,6 +178,99 @@ def _run_case(
177178
return state
178179

179180

181+
def _path_for_imiv_output(path: Path, run_cwd: Path) -> str:
182+
try:
183+
return os.path.relpath(path, run_cwd)
184+
except ValueError:
185+
return str(path)
186+
187+
188+
def _write_scenario(path: Path, runtime_dir_rel: str) -> None:
189+
root = ET.Element("imiv-scenario")
190+
root.set("out_dir", runtime_dir_rel)
191+
192+
step = ET.SubElement(root, "step")
193+
step.set("name", "enable_auto")
194+
step.set("key_chord", "shift+comma")
195+
step.set("state", "true")
196+
step.set("post_action_delay_frames", "2")
197+
198+
step = ET.SubElement(root, "step")
199+
step.set("name", "zoom_out")
200+
step.set("key_chord", "ctrl+minus")
201+
step.set("state", "true")
202+
step.set("post_action_delay_frames", "3")
203+
204+
path.parent.mkdir(parents=True, exist_ok=True)
205+
ET.ElementTree(root).write(path, encoding="utf-8", xml_declaration=True)
206+
207+
208+
def _run_scenario(
209+
repo_root: Path,
210+
runner: Path,
211+
exe: Path,
212+
cwd: Path,
213+
backend: str,
214+
image_path: Path,
215+
out_dir: Path,
216+
scenario_path: Path,
217+
env: dict[str, str],
218+
trace: bool,
219+
) -> dict[str, dict]:
220+
runtime_dir = out_dir / "runtime"
221+
runtime_dir.mkdir(parents=True, exist_ok=True)
222+
config_home = out_dir / "cfg_scenario"
223+
shutil.rmtree(config_home, ignore_errors=True)
224+
cmd = [
225+
sys.executable,
226+
str(runner),
227+
"--bin",
228+
str(exe),
229+
"--cwd",
230+
str(cwd),
231+
]
232+
if backend:
233+
cmd.extend(["--backend", backend])
234+
cmd.extend(
235+
[
236+
"--open",
237+
str(image_path),
238+
"--scenario",
239+
str(scenario_path),
240+
]
241+
)
242+
if trace:
243+
cmd.append("--trace")
244+
245+
case_env = dict(env)
246+
case_env["IMIV_CONFIG_HOME"] = str(config_home)
247+
248+
with (out_dir / "scenario.log").open("w", encoding="utf-8") as log_handle:
249+
proc = subprocess.run(
250+
cmd,
251+
cwd=str(repo_root),
252+
env=case_env,
253+
check=False,
254+
stdout=log_handle,
255+
stderr=subprocess.STDOUT,
256+
timeout=90,
257+
)
258+
if proc.returncode != 0:
259+
raise RuntimeError(f"scenario: runner exited with code {proc.returncode}")
260+
261+
result: dict[str, dict] = {}
262+
for step_name in ("enable_auto", "zoom_out"):
263+
state_path = runtime_dir / f"{step_name}.state.json"
264+
if not state_path.exists():
265+
raise RuntimeError(f"scenario: missing state output for {step_name}")
266+
with state_path.open("r", encoding="utf-8") as handle:
267+
state = json.load(handle)
268+
state["_state_path"] = str(state_path)
269+
state["_log_path"] = str(out_dir / "scenario.log")
270+
result[step_name] = state
271+
return result
272+
273+
180274
def _calc_expected_subimage_from_zoom(
181275
current_subimage: int, nsubimages: int, zoom: float
182276
) -> tuple[int, float]:
@@ -258,42 +352,23 @@ def main() -> int:
258352
env,
259353
args.trace,
260354
)
261-
enabled = _run_case(
262-
repo_root,
263-
runner,
264-
exe,
265-
cwd,
266-
args.backend,
267-
image_path,
268-
out_dir,
269-
"enable_auto",
270-
["--key-chord", "shift+comma"],
271-
env,
272-
args.trace,
273-
)
274-
auto_zoom = _run_case(
355+
scenario_path = out_dir / "auto_subimage.scenario.xml"
356+
runtime_dir = out_dir / "runtime"
357+
_write_scenario(scenario_path, _path_for_imiv_output(runtime_dir, cwd))
358+
scenario_states = _run_scenario(
275359
repo_root,
276360
runner,
277361
exe,
278362
cwd,
279363
args.backend,
280364
image_path,
281365
out_dir,
282-
"auto_zoom_out",
283-
[
284-
"--key-chord",
285-
"shift+comma",
286-
"--mouse-pos-window-rel",
287-
"0.5",
288-
"0.5",
289-
"--mouse-click",
290-
"1",
291-
"--post-action-delay-frames",
292-
"3",
293-
],
366+
scenario_path,
294367
env,
295368
args.trace,
296369
)
370+
enabled = scenario_states["enable_auto"]
371+
auto_zoom = scenario_states["zoom_out"]
297372
except (RuntimeError, subprocess.SubprocessError) as exc:
298373
return _fail(str(exc))
299374

@@ -319,7 +394,7 @@ def main() -> int:
319394
return _fail(f"enable_auto changed subimage unexpectedly: {enabled['subimage']}")
320395

321396
expected_subimage, expected_zoom = _calc_expected_subimage_from_zoom(
322-
current_subimage=0, nsubimages=4, zoom=baseline_zoom * 0.5
397+
current_subimage=0, nsubimages=4, zoom=float(enabled["zoom"]) * 0.5
323398
)
324399
actual_subimage = int(auto_zoom["subimage"])
325400
actual_zoom = float(auto_zoom["zoom"])

src/imiv/tools/imiv_generate_upload_corpus.sh

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
set -euo pipefail
77

88
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd)"
9-
out_dir="${1:-$repo_root/build_u/imiv_upload_corpus/images}"
10-
manifest_csv="${2:-$repo_root/build_u/imiv_upload_corpus/corpus_manifest.csv}"
9+
out_dir="${1:-$repo_root/build_u/testsuite/imiv/upload_corpus/images}"
10+
manifest_csv="${2:-$repo_root/build_u/testsuite/imiv/upload_corpus/corpus_manifest.csv}"
1111
oiiotool_bin="${OIIOTOOL_BIN:-$repo_root/build_u/bin/oiiotool}"
1212

1313
if [[ ! -x "$oiiotool_bin" ]]; then
@@ -35,8 +35,8 @@ dimensions=(
3535
)
3636

3737
channels=(
38-
"rgb:3"
39-
"rgba:4"
38+
"rgb:3:0.85,0.35,0.15"
39+
"rgba:4:0.10,0.80,0.95,0.75"
4040
)
4141

4242
depths=(
@@ -54,7 +54,9 @@ for dim in "${dimensions[@]}"; do
5454
height="${dim#*x}"
5555
for ch_entry in "${channels[@]}"; do
5656
ch_name="${ch_entry%%:*}"
57-
ch_count="${ch_entry#*:}"
57+
rest="${ch_entry#*:}"
58+
ch_count="${rest%%:*}"
59+
color="${rest#*:}"
5860
for depth_entry in "${depths[@]}"; do
5961
depth_tag="${depth_entry%%:*}"
6062
rest="${depth_entry#*:}"
@@ -64,8 +66,9 @@ for dim in "${dimensions[@]}"; do
6466
file_name="${ch_name}_${depth_tag}_${width}x${height}.${extension}"
6567
file_path="${out_dir}/${file_name}"
6668

67-
"$oiiotool_bin" --create "${width}x${height}" "${ch_count}" \
68-
-d "${depth_name}" -o "${file_path}"
69+
"$oiiotool_bin" \
70+
--pattern "constant:color=${color}" "${width}x${height}" \
71+
"${ch_count}" -d "${depth_name}" -o "${file_path}"
6972

7073
printf '%s,%s,%s,%s,%s,%s\n' \
7174
"$file_path" "$width" "$height" "$ch_count" "$depth_name" \

src/imiv/tools/imiv_upload_corpus_ctest.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ set -euo pipefail
77

88
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd)"
99
build_dir="${1:-$repo_root/build_u}"
10-
11-
corpus_root="${build_dir}/imiv_upload_corpus"
10+
corpus_root="${build_dir}/testsuite/imiv/upload_corpus"
1211
images_dir="${corpus_root}/images"
1312
manifest_csv="${corpus_root}/corpus_manifest.csv"
1413
results_dir="${corpus_root}/results"
@@ -19,9 +18,16 @@ smoke_script="${repo_root}/src/imiv/tools/imiv_upload_corpus_smoke_test.sh"
1918
if [[ -z "${IMIV_ENV_SCRIPT:-}" ]]; then
2019
export IMIV_ENV_SCRIPT="${build_dir}/imiv_env.sh"
2120
fi
21+
if [[ -z "${OIIOTOOL_BIN:-}" ]]; then
22+
export OIIOTOOL_BIN="${build_dir}/bin/oiiotool"
23+
fi
2224

2325
export PER_CASE_TIMEOUT="${PER_CASE_TIMEOUT:-90s}"
2426
export RUNNER_TRACE="${RUNNER_TRACE:-0}"
2527

26-
"${generate_script}" "${images_dir}" "${manifest_csv}"
28+
if ! [[ -d "${images_dir}" ]] \
29+
|| ! find "${images_dir}" -maxdepth 1 -type f | read -r _; then
30+
"${generate_script}" "${images_dir}" "${manifest_csv}"
31+
fi
32+
2733
"${smoke_script}" "${images_dir}" "${results_dir}"

src/imiv/tools/imiv_upload_corpus_smoke_test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
set -euo pipefail
77

88
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd)"
9-
corpus_dir="${1:-$repo_root/build_u/imiv_upload_corpus/images}"
10-
result_dir="${2:-$repo_root/build_u/imiv_upload_corpus/results}"
9+
corpus_dir="${1:-$repo_root/build_u/testsuite/imiv/upload_corpus/images}"
10+
result_dir="${2:-$repo_root/build_u/testsuite/imiv/upload_corpus/results}"
1111
runner_py="${RUNNER_PY:-$repo_root/src/imiv/tools/imiv_gui_test_run.py}"
1212
python_bin="${PYTHON_BIN:-python3}"
1313
env_script="${IMIV_ENV_SCRIPT:-$repo_root/build_u/imiv_env.sh}"

0 commit comments

Comments
 (0)