32
32
33
33
# TODO: Use AFU IDs vs. names of AFUs
34
34
BIST_MODES = ['bist_afu' , 'dma_afu' , 'nlb_mode_3' ]
35
+ REQ_CMDS = ['lspci' , 'fpgainfo' , 'fpgaconf' , 'fpgadiag' , 'fpga_dma_test' ,
36
+ 'bist_app' ]
37
+
38
+
39
+ def find_exec (cmd , paths ):
40
+ for p in paths :
41
+ f = os .path .join (p , cmd )
42
+ if os .path .isfile (f ):
43
+ return True
44
+ return False
45
+
46
+
47
+ def check_required_cmds ():
48
+ path = os .environ ['PATH' ].split (os .pathsep )
49
+ if not all ([find_exec (cmd , path ) for cmd in REQ_CMDS ]):
50
+ sys .exit ("Failed to find required BIST commands\n Terminating BIST" )
35
51
36
52
37
53
# Return a list of all available bus numbers
38
54
def get_all_fpga_bdfs ():
39
- pattern = ('\d+:(?P<bus>[a-fA-F0-9]{2}):'
40
- '(?P<device>[a-fA-F0-9]{2})\.(?P<function>[a-fA-F0-9])' )
55
+ pattern = (r '\d+:(?P<bus>[a-fA-F0-9]{2}):'
56
+ r '(?P<device>[a-fA-F0-9]{2})\.(?P<function>[a-fA-F0-9])' )
41
57
bdf_pattern = re .compile (pattern )
42
58
bdf_list = []
43
59
for fpga in glob .glob ('/sys/class/fpga/*' ):
@@ -51,8 +67,8 @@ def get_all_fpga_bdfs():
51
67
52
68
53
69
def get_bdf_from_args (args ):
54
- pattern = ('(?P<bus>[a-fA-F0-9]{2}):'
55
- '(?P<device>[a-fA-F0-9]{2})\.(?P<function>[a-fA-F0-9]).*?.' )
70
+ pattern = (r '(?P<bus>[a-fA-F0-9]{2}):'
71
+ r '(?P<device>[a-fA-F0-9]{2})\.(?P<function>[a-fA-F0-9]).*?.' )
56
72
pattern += vars (args )['device_id' ]
57
73
bdf_pattern = re .compile (pattern )
58
74
bdf_list = []
@@ -63,7 +79,7 @@ def get_bdf_from_args(args):
63
79
if vars (args )['device' ] else '' ,
64
80
hex (int (vars (args )['function' ], 16 ))
65
81
if vars (args )['function' ] else '' )
66
- host = subprocess .check_output (['/usr/sbin/ lspci' , '-s' , param ])
82
+ host = subprocess .check_output (['lspci' , '-s' , param ])
67
83
matches = re .findall (bdf_pattern , host )
68
84
for bus , device , function in matches :
69
85
bdf_list .append ({'bus' : bus , 'device' : device ,
0 commit comments