3636import sys
3737import os
3838import sh
39+ import re
3940import errno
4041import platform
4142import unittest
5051# config file should be in the same directory of this script
5152LH_CFG = "lh_test_cfg.yaml"
5253# lockhammer.c has these parameters
53- LH_ARGU_LIST = ['t' , 'a' , 'c' , 'p' ]
54+ LH_ARGU_LIST = ['t' , 'a' , 'c' , 'p' , 'i' , 'o' ]
5455
5556
5657# python unittest framework container class
@@ -130,6 +131,30 @@ def full_func_name(cmdName, paramList, fillZero):
130131 fullName += str (random .random ())
131132 return fullName
132133
134+ # convert lstopo output to special cpu core order string, used by sweeptest -o
135+ def parse_lstopo ():
136+ result = ''
137+ try :
138+ lst = sh .Command ("lstopo" )
139+ out = str (sh .grep (lst ("--no-io" , "--no-cache" ), "PU" ))
140+ except sh .CommandNotFound :
141+ print ("Error, cannot find lstopo, need to install hwloc package first." )
142+ sys .exit (2 )
143+ else :
144+ for line in out .splitlines ():
145+ match = re .search ("P#(\d+)" , line .strip ())
146+ if match :
147+ result += (match .group (1 ) + ',' )
148+ finally :
149+ if result [- 1 ] == ',' :
150+ result = result [:- 1 ]
151+
152+ # sample output for single-socket EPYC 7601 server:
153+ #0,32,8,40,16,48,24,56,4,36,12,44,20,52,28,60,1,33,9,41,17,49,25,57,5,37,\
154+ #13,45,21,53,29,61,2,34,10,42,18,50,26,58,6,38,14,46,22,54,30,62,3,35,11,\
155+ #43,19,51,27,59,7,39,15,47,23,55,31,63
156+ return result
157+
133158# convert parameter from {key:value} to string list
134159def expand_param (ctrl , valueList ):
135160 outParam = []
@@ -146,6 +171,11 @@ def expand_param(ctrl, valueList):
146171 outParam .append (['-t' , multiprocessing .cpu_count ()])
147172 else :
148173 outParam .append (['-' + ctrl , valueList ])
174+ elif isinstance (valueList , str ):
175+ if ctrl == 'o' and valueList == 'lstopo' :
176+ outParam .append (['-o' , parse_lstopo ()])
177+ else :
178+ outParam .append (['-' + ctrl , valueList ])
149179 else :
150180 outParam .append (['-' + ctrl , valueList ])
151181 return outParam
@@ -189,7 +219,10 @@ def prepare_param(arguList):
189219 for elem in arguList :
190220 paramList = []
191221 for key in elem :
192- paramList .extend (['-' + key , elem [key ]])
222+ if key == 'o' and str (elem [key ]) == 'lstopo' :
223+ paramList .extend (['-o' , parse_lstopo ()])
224+ else :
225+ paramList .extend (['-' + key , elem [key ]])
193226 arguLL .append (paramList )
194227 return arguLL
195228
0 commit comments