# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations from pathlib import Path from typing import List from unittest.mock import MagicMock, patch import pytest from benchmarks.multimodal.sweep.config import BenchmarkConfig, SweepConfig from benchmarks.multimodal.sweep.orchestrator import run_sweep pytestmark = [pytest.mark.unit, pytest.mark.pre_merge, pytest.mark.gpu_0] def _make_config( tmp_path: Path, num_configs: int = 2, num_input_files: int = 2, request_rates: List[int] | None = None, restart_server_every_benchmark: bool = True, ) -> SweepConfig: """Create a SweepConfig with dummy workflow scripts and input files.""" if request_rates is None: request_rates = [4, 8] # Create dummy workflow scripts configs: List[BenchmarkConfig] = [] for i in range(num_configs): script = tmp_path / f"workflow_{i}.sh" script.write_text("#!/bin/bash\necho ok") script.chmod(0o755) configs.append( BenchmarkConfig( label=f"cfg-{i}", workflow=str(script), extra_args=[], ) ) # Create dummy input files input_files: List[str] = [] for i in range(num_input_files): f = tmp_path / f"input_{i}.jsonl" f.write_text("{}\n") input_files.append(str(f)) return SweepConfig( model="test-model", request_rates=request_rates, concurrencies=None, osl=10, request_count=5, warmup_count=1, port=8000, timeout=60, input_files=input_files, configs=configs, output_dir=str(tmp_path / "results"), skip_plots=True, restart_server_every_benchmark=restart_server_every_benchmark, ) @patch("benchmarks.multimodal.sweep.orchestrator.run_aiperf_single") @patch("benchmarks.multimodal.sweep.orchestrator.ServerManager") def test_loop_order_bench_cfg_outer( mock_server_cls: MagicMock, mock_aiperf: MagicMock, tmp_path: Path, ) -> None: """bench_cfg is the outer loop, input_file middle, sweep_values inner.""" config = _make_config(tmp_path) run_sweep(config, repo_root=tmp_path) # Extract (label, input_file_stem, sweep_value) from each aiperf call. calls: list[tuple[str, str, int]] = [] for c in mock_aiperf.call_args_list: artifact_dir = Path(c.kwargs["artifact_dir"]) # Structure: results / /