Skip to content

Commit 1a3d370

Browse files
buie1anandaravuri
authored andcommitted
Add checks to ensure commands in system path (#282) (#378)
* Add checks to ensure commands in system path * remove hardcoded path to lspci (cherry picked from commit d8efb60)
1 parent 7a42de7 commit 1a3d370

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

tools/extra/fpgabist/bist_common.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,28 @@
3232

3333
# TODO: Use AFU IDs vs. names of AFUs
3434
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\nTerminating BIST")
3551

3652

3753
# Return a list of all available bus numbers
3854
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])')
4157
bdf_pattern = re.compile(pattern)
4258
bdf_list = []
4359
for fpga in glob.glob('/sys/class/fpga/*'):
@@ -51,8 +67,8 @@ def get_all_fpga_bdfs():
5167

5268

5369
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]).*?.')
5672
pattern += vars(args)['device_id']
5773
bdf_pattern = re.compile(pattern)
5874
bdf_list = []
@@ -63,7 +79,7 @@ def get_bdf_from_args(args):
6379
if vars(args)['device'] else '',
6480
hex(int(vars(args)['function'], 16))
6581
if vars(args)['function'] else '')
66-
host = subprocess.check_output(['/usr/sbin/lspci', '-s', param])
82+
host = subprocess.check_output(['lspci', '-s', param])
6783
matches = re.findall(bdf_pattern, host)
6884
for bus, device, function in matches:
6985
bdf_list.append({'bus': bus, 'device': device,

tools/extra/fpgabist/fpgabist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,5 @@ if __name__ == "__main__":
8484
parser = argparse.ArgumentParser()
8585
bist_common.global_arguments(parser)
8686
args = parser.parse_args()
87+
bist_common.check_required_cmds()
8788
main(args)

0 commit comments

Comments
 (0)