diff --git a/src/cloudai/workloads/sleep/standalone_command_gen_strategy.py b/src/cloudai/workloads/sleep/standalone_command_gen_strategy.py index aa99a6461..b4494b971 100644 --- a/src/cloudai/workloads/sleep/standalone_command_gen_strategy.py +++ b/src/cloudai/workloads/sleep/standalone_command_gen_strategy.py @@ -1,5 +1,5 @@ # SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES -# Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: Apache-2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,16 +16,28 @@ from typing import cast +import toml + from cloudai.core import CommandGenStrategy +from cloudai.models.scenario import TestRunDetails -from .sleep import SleepCmdArgs, SleepTestDefinition +from .sleep import SleepTestDefinition class SleepStandaloneCommandGenStrategy(CommandGenStrategy): """Command generation strategy for the Sleep test on standalone systems.""" - def gen_exec_command(self) -> str: + def _generate_sleep_command(self) -> str: tdef: SleepTestDefinition = cast(SleepTestDefinition, self.test_run.test) - tdef_cmd_args: SleepCmdArgs = tdef.cmd_args - sec = tdef_cmd_args.seconds - return f"sleep {sec}" + return f"sleep {tdef.cmd_args.seconds}" + + def store_test_run(self) -> None: + test_cmd = self._generate_sleep_command() + self.test_run.output_path.mkdir(parents=True, exist_ok=True) + with (self.test_run.output_path / self.TEST_RUN_DUMP_FILE_NAME).open("w", encoding="utf-8") as f: + trd = TestRunDetails.from_test_run(self.test_run, test_cmd=test_cmd, full_cmd=test_cmd) + toml.dump(trd.model_dump(), f) + + def gen_exec_command(self) -> str: + self.store_test_run() + return self._generate_sleep_command() diff --git a/tests/workloads/sleep/test_command_gen_strategy_standalone.py b/tests/workloads/sleep/test_command_gen_strategy_standalone.py new file mode 100644 index 000000000..95964f422 --- /dev/null +++ b/tests/workloads/sleep/test_command_gen_strategy_standalone.py @@ -0,0 +1,45 @@ +# SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES +# Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from pathlib import Path + +import toml + +from cloudai.core import CommandGenStrategy, TestRun +from cloudai.models.scenario import TestRunDetails +from cloudai.systems.standalone import StandaloneSystem +from cloudai.workloads.sleep import SleepCmdArgs, SleepStandaloneCommandGenStrategy, SleepTestDefinition + + +def test_gen_exec_command_writes_test_run_details(tmp_path: Path, standalone_system: StandaloneSystem) -> None: + tdef = SleepTestDefinition( + name="sleep_test", + description="Simple sleep test", + test_template_name="Sleep", + cmd_args=SleepCmdArgs(seconds=60), + ) + tr = TestRun(name="sleep-job", test=tdef, num_nodes=1, nodes=[], output_path=tmp_path / "output") + + strategy = SleepStandaloneCommandGenStrategy(standalone_system, tr) + command = strategy.gen_exec_command() + + assert command == "sleep 60" + + dump_path = tr.output_path / CommandGenStrategy.TEST_RUN_DUMP_FILE_NAME + assert dump_path.is_file() + details = TestRunDetails.model_validate(toml.load(dump_path)) + assert details.test_cmd == "sleep 60" + assert details.full_cmd == "sleep 60"