44import json
55import os
66import unittest
7-
7+ import subprocess
88import requests
99
1010unittest .TestLoader .sortTestMethodsUsing = None
1111
12-
1312# unittest.TestLoader.sortTestMethodsUsing = lambda self, a, b: (a < b) - (a > b)
1413class RunCmd :
15- def run (self , cmd ):
16- import subprocess
17- p = subprocess .Popen (cmd , stdout = subprocess .PIPE , shell = True )
18- (output , err ) = p .communicate ()
14+ def run (self , cmd , env_vars = None ):
15+ # Ensure cmd is a list of arguments
16+ if isinstance (cmd , str ):
17+ import shlex
18+ cmd = shlex .split (cmd )
19+
20+ # Print the command and environment variables for debugging
21+ print ("Running command:" , cmd )
22+ if env_vars :
23+ print ("With environment variables:" , env_vars )
24+
25+ # Execute the command with the environment variables
26+ p = subprocess .Popen (cmd , stdout = subprocess .PIPE , stderr = subprocess .PIPE , shell = False , env = env_vars )
27+ output , err = p .communicate ()
1928 p_status = p .wait ()
20- # print("Command exit status/return code : ", p_status)
29+
30+ # Return the status and output
2131 return p_status , output
2232
2333class PerfUtility :
@@ -65,7 +75,8 @@ def model_test(self, data, perf_report):
6575 import shutil
6676 import os
6777 cmd = data ["run_cmd" ]
68- status , output = RunCmd ().run (cmd )
78+ env = data ["env_vars" ]
79+ status , output = RunCmd ().run (cmd , env )
6980 output = output .decode ("utf-8" )
7081 print (cmd )
7182 # 0.1.1 copy generated hqt_output(dst) to HQT folder(src)
@@ -81,9 +92,10 @@ def model_test(self, data, perf_report):
8192
8293 # 1.Run the instruction
8394 cmd = data ["run_cmd" ]
95+ env = data ["env_vars" ]
8496 #print(cmd)
8597 #return 0
86- status , output = RunCmd ().run (cmd )
98+ status , output = RunCmd ().run (cmd , env )
8799 output = output .decode ("utf-8" )
88100
89101 # 2.Parsing the run log
@@ -277,8 +289,9 @@ def test_0_system(self):
277289 def test_1_perfspect (self ):
278290 # PerfSpect Report
279291 if not os .path .exists ("./perfspect" ):
280- cmd = 'wget -qO- https://github.com/intel/PerfSpect/releases/latest/download/perfspect.tgz | tar xvz'
281- status , output = RunCmd ().run (cmd )
292+ p = subprocess .Popen ('wget -qO- https://github.com/intel/PerfSpect/releases/latest/download/perfspect.tgz | tar xvz' , stdout = subprocess .PIPE , shell = True )
293+ output , err = p .communicate ()
294+ status = p .wait ()
282295 cmd = './perfspect/perfspect report --gaudi --output ' + self .perf_report .result_folder_name
283296 status , output = RunCmd ().run (cmd )
284297 import socket
0 commit comments