1616from pathlib import Path
1717
1818import pytest
19+ from cloudai .schema .test_template .nccl_test .slurm_command_gen_strategy import NcclTestSlurmCommandGenStrategy
1920from cloudai .schema .test_template .nemo_launcher .slurm_command_gen_strategy import (
2021 NeMoLauncherSlurmCommandGenStrategy ,
2122)
@@ -39,6 +40,7 @@ def slurm_system(tmp_path: Path) -> SlurmSystem:
3940 SlurmNode (name = "node4" , partition = "main" , state = SlurmNodeState .IDLE ),
4041 ]
4142 },
43+ mpi = "fake-mpi" ,
4244 )
4345 Path (slurm_system .install_path ).mkdir ()
4446 Path (slurm_system .output_path ).mkdir ()
@@ -112,6 +114,51 @@ def test_only_nodes(strategy_fixture: SlurmCommandGenStrategy):
112114 assert slurm_args ["num_nodes" ] == len (nodes )
113115
114116
117+ class TestGenerateSrunCommand__CmdGeneration :
118+ def test_generate_test_command (self , strategy_fixture : SlurmCommandGenStrategy ):
119+ test_command = strategy_fixture .generate_test_command ({}, {}, {}, "" )
120+ assert test_command == []
121+
122+ def test_generate_srun_command (self , strategy_fixture : SlurmCommandGenStrategy ):
123+ srun_command = strategy_fixture .generate_srun_command ({}, {}, {}, "" )
124+ assert srun_command == ["srun" , f"--mpi={ strategy_fixture .slurm_system .mpi } " ]
125+
126+ def test_generate_srun_command_with_container_image (self , strategy_fixture : SlurmCommandGenStrategy ):
127+ slurm_args = {"image_path" : "fake_image_path" }
128+ srun_command = strategy_fixture .generate_srun_command (slurm_args , {}, {}, "" )
129+ assert srun_command == [
130+ "srun" ,
131+ f"--mpi={ strategy_fixture .slurm_system .mpi } " ,
132+ "--container-image=fake_image_path" ,
133+ ]
134+
135+ def test_generate_srun_command_with_container_image_and_mounts (self , strategy_fixture : SlurmCommandGenStrategy ):
136+ slurm_args = {"image_path" : "fake_image_path" , "container_mounts" : "fake_mounts" }
137+ srun_command = strategy_fixture .generate_srun_command (slurm_args , {}, {}, "" )
138+ assert srun_command == [
139+ "srun" ,
140+ f"--mpi={ strategy_fixture .slurm_system .mpi } " ,
141+ "--container-image=fake_image_path" ,
142+ "--container-mounts=fake_mounts" ,
143+ ]
144+
145+ def test_generate_srun_empty_str (self , strategy_fixture : SlurmCommandGenStrategy ):
146+ slurm_args = {"image_path" : "" , "container_mounts" : "" }
147+ srun_command = strategy_fixture .generate_srun_command (slurm_args , {}, {}, "" )
148+ assert srun_command == ["srun" , f"--mpi={ strategy_fixture .slurm_system .mpi } " ]
149+
150+ slurm_args = {"image_path" : "fake" , "container_mounts" : "" }
151+ srun_command = strategy_fixture .generate_srun_command (slurm_args , {}, {}, "" )
152+ assert srun_command == ["srun" , f"--mpi={ strategy_fixture .slurm_system .mpi } " , "--container-image=fake" ]
153+
154+ def test_generate_full_srun_command (self , strategy_fixture : SlurmCommandGenStrategy ):
155+ strategy_fixture .generate_srun_command = lambda * _ , ** __ : ["srun" , "--test" , "test_arg" ]
156+ strategy_fixture .generate_test_command = lambda * _ , ** __ : ["test_command" ]
157+
158+ full_srun_command = strategy_fixture .generate_full_srun_command ({}, {}, {}, "" )
159+ assert full_srun_command == " \\ \n " .join (["srun" , "--test" , "test_arg" , "test_command" ])
160+
161+
115162class TestNeMoLauncherSlurmCommandGenStrategy__GenExecCommand :
116163 @pytest .fixture
117164 def nemo_cmd_gen (self , slurm_system : SlurmSystem ) -> NeMoLauncherSlurmCommandGenStrategy :
@@ -305,3 +352,37 @@ def test_disable_output_and_error(self, add_arg: str, strategy_fixture: SlurmCom
305352
306353 self .assert_positional_lines (file_contents .splitlines ())
307354 assert f"--{ add_arg } =" not in file_contents
355+
356+
357+ class TestNCCLSlurmCommandGen :
358+ def get_cmd (self , slurm_system : SlurmSystem , slurm_args : dict , cmd_args : dict ) -> str :
359+ return NcclTestSlurmCommandGenStrategy (slurm_system , {}, {}).generate_full_srun_command (
360+ slurm_args , {}, cmd_args , ""
361+ )
362+
363+ def test_only_mandatory (self , slurm_system : SlurmSystem ) -> None :
364+ slurm_args = {"image_path" : "fake_image_path" }
365+ cmd_args = {"subtest_name" : "fake_subtest_name" }
366+ cmd = self .get_cmd (slurm_system , slurm_args , cmd_args )
367+ assert cmd == " \\ \n " .join (
368+ [
369+ "srun" ,
370+ f"--mpi={ slurm_system .mpi } " ,
371+ f"--container-image={ slurm_args ['image_path' ]} " ,
372+ f"/usr/local/bin/{ cmd_args ['subtest_name' ]} " ,
373+ ]
374+ )
375+
376+ def test_with_container_mounts (self , slurm_system : SlurmSystem ) -> None :
377+ slurm_args = {"image_path" : "fake_image_path" , "container_mounts" : "fake_mounts" }
378+ cmd_args = {"subtest_name" : "fake_subtest_name" }
379+ cmd = self .get_cmd (slurm_system , slurm_args , cmd_args )
380+ assert cmd == " \\ \n " .join (
381+ [
382+ "srun" ,
383+ f"--mpi={ slurm_system .mpi } " ,
384+ f"--container-image={ slurm_args ['image_path' ]} " ,
385+ f"--container-mounts={ slurm_args ['container_mounts' ]} " ,
386+ f"/usr/local/bin/{ cmd_args ['subtest_name' ]} " ,
387+ ]
388+ )
0 commit comments