27
27
import os
28
28
import shutil
29
29
import subprocess
30
+ from subprocess import STDOUT , CalledProcessError
30
31
31
32
from collections import namedtuple
32
33
from datetime import datetime
63
64
"distributed/test_distributed_spawn"
64
65
]
65
66
67
+ CONSOLIDATED_LOG_FILE_NAME = "pytorch_unit_tests.log"
68
+
66
69
def parse_xml_reports_as_dict (workflow_run_id , workflow_run_attempt , tag , workflow_name , path = "." ):
67
70
test_cases = {}
68
71
items_list = os .listdir (path )
@@ -198,6 +201,14 @@ def summarize_xml_files(path, workflow_name):
198
201
199
202
return res
200
203
204
+ def run_command_and_capture_output (cmd ):
205
+ try :
206
+ print (f"Running command '{ cmd } '" )
207
+ with open (CONSOLIDATED_LOG_FILE_PATH , "a+" ) as output_file :
208
+ p = subprocess .run (cmd , shell = True , stdout = output_file , stderr = STDOUT , text = True )
209
+ except CalledProcessError as e :
210
+ print (f"ERROR: Cmd { cmd } failed with return code: { e .returncode } !" )
211
+
201
212
def run_entire_tests (workflow_name , test_shell_path , overall_logs_path_current_run , test_reports_src ):
202
213
if os .path .exists (test_reports_src ):
203
214
shutil .rmtree (test_reports_src )
@@ -214,7 +225,7 @@ def run_entire_tests(workflow_name, test_shell_path, overall_logs_path_current_r
214
225
os .environ ['TEST_CONFIG' ] = 'inductor'
215
226
copied_logs_path = overall_logs_path_current_run + "inductor_xml_results_entire_tests/"
216
227
# use test.sh for tests execution
217
- subprocess . call (test_shell_path , shell = True )
228
+ run_command_and_capture_output (test_shell_path )
218
229
copied_logs_path_destination = shutil .copytree (test_reports_src , copied_logs_path )
219
230
entire_results_dict = summarize_xml_files (copied_logs_path_destination , workflow_name )
220
231
return entire_results_dict
@@ -232,7 +243,7 @@ def run_priority_tests(workflow_name, test_run_test_path, overall_logs_path_curr
232
243
# use run_test.py for tests execution
233
244
default_priority_test_suites = " " .join (DEFAULT_CORE_TESTS )
234
245
command = "python " + test_run_test_path + " --include " + default_priority_test_suites + " --exclude-jit-executor --exclude-distributed-tests --verbose"
235
- subprocess . call (command , shell = True )
246
+ run_command_and_capture_output (command )
236
247
del os .environ ['HIP_VISIBLE_DEVICES' ]
237
248
elif workflow_name == "distributed" :
238
249
os .environ ['TEST_CONFIG' ] = 'distributed'
@@ -241,7 +252,7 @@ def run_priority_tests(workflow_name, test_run_test_path, overall_logs_path_curr
241
252
# use run_test.py for tests execution
242
253
distributed_priority_test_suites = " " .join (DISTRIBUTED_CORE_TESTS )
243
254
command = "python " + test_run_test_path + " --include " + distributed_priority_test_suites + " --distributed-tests --verbose"
244
- subprocess . call (command , shell = True )
255
+ run_command_and_capture_output (command )
245
256
del os .environ ['HIP_VISIBLE_DEVICES' ]
246
257
copied_logs_path_destination = shutil .copytree (test_reports_src , copied_logs_path )
247
258
priority_results_dict = summarize_xml_files (copied_logs_path_destination , workflow_name )
@@ -261,7 +272,7 @@ def run_selected_tests(workflow_name, test_run_test_path, overall_logs_path_curr
261
272
# use run_test.py for tests execution
262
273
default_selected_test_suites = " " .join (selected_list )
263
274
command = "python " + test_run_test_path + " --include " + default_selected_test_suites + " --exclude-jit-executor --exclude-distributed-tests --verbose"
264
- subprocess . call (command , shell = True )
275
+ run_command_and_capture_output (command )
265
276
del os .environ ['HIP_VISIBLE_DEVICES' ]
266
277
elif workflow_name == "distributed" :
267
278
os .environ ['TEST_CONFIG' ] = 'distributed'
@@ -270,7 +281,7 @@ def run_selected_tests(workflow_name, test_run_test_path, overall_logs_path_curr
270
281
# use run_test.py for tests execution
271
282
distributed_selected_test_suites = " " .join (selected_list )
272
283
command = "python " + test_run_test_path + " --include " + distributed_selected_test_suites + " --distributed-tests --verbose"
273
- subprocess . call (command , shell = True )
284
+ run_command_and_capture_output (command )
274
285
del os .environ ['HIP_VISIBLE_DEVICES' ]
275
286
elif workflow_name == "inductor" :
276
287
os .environ ['TEST_CONFIG' ] = 'inductor'
@@ -287,11 +298,11 @@ def run_selected_tests(workflow_name, test_run_test_path, overall_logs_path_curr
287
298
if inductor_selected_test_suites != "" :
288
299
inductor_selected_test_suites = inductor_selected_test_suites [:- 1 ]
289
300
command = "python " + test_run_test_path + " --include " + inductor_selected_test_suites + " --verbose"
290
- subprocess . call (command , shell = True )
301
+ run_command_and_capture_output (command )
291
302
if non_inductor_selected_test_suites != "" :
292
303
non_inductor_selected_test_suites = non_inductor_selected_test_suites [:- 1 ]
293
304
command = "python " + test_run_test_path + " --inductor --include " + non_inductor_selected_test_suites + " --verbose"
294
- subprocess . call (command , shell = True )
305
+ run_command_and_capture_output (command )
295
306
copied_logs_path_destination = shutil .copytree (test_reports_src , copied_logs_path )
296
307
selected_results_dict = summarize_xml_files (copied_logs_path_destination , workflow_name )
297
308
@@ -336,6 +347,11 @@ def run_test_and_summarize_results(
336
347
# performed as Job ID
337
348
str_current_datetime = str (current_datetime )
338
349
overall_logs_path_current_run = repo_test_log_folder_path + str_current_datetime + "/"
350
+ os .mkdir (overall_logs_path_current_run )
351
+
352
+ global CONSOLIDATED_LOG_FILE_PATH
353
+ CONSOLIDATED_LOG_FILE_PATH = overall_logs_path_current_run + CONSOLIDATED_LOG_FILE_NAME
354
+
339
355
# Run entire tests for each workflow
340
356
if not priority_tests and not default_list and not distributed_list and not inductor_list :
341
357
# run entire tests for default, distributed and inductor workflows → use test.sh
0 commit comments