def main(): parser = argparse.ArgumentParser() parser.add_argument('--segment', '-S', type=hexint, help='Segment number of PCIe device') parser.add_argument('--bus', '-B', type=hexint, help='Bus number of PCIe device') parser.add_argument('--device', '-D', type=hexint, help='Device number of PCIe device') parser.add_argument('--function', '-F', type=hexint, help='Function number of PCIe device') parser.add_argument('--mtu', nargs='?', const='', help='maximum allowable ethernet frame length') parser.add_argument('--port', nargs='*', default='all', help='select specific port (default: %(default)s)') parser.add_argument('--direction', choices=['tx', 'rx', 'both'], default='both', help='select direction of port (default: %(default)s)') parser.add_argument('--side', choices=['line', 'host'], default='host', help='select mac on which side (default: %(default)s)') parser.add_argument('--debug', '-d', action='store_true', help='Output debug information') args, left = parser.parse_known_args() f = FpgaFinder(args.segment, args.bus, args.device, args.function) devs = f.find() if args.debug: for d in devs: s = 'bdf: {segment:04x}:{bus:02x}:{dev:02x}.{func:x}'.format(**d) print(s) if len(devs) > 1: s = '{} FPGAs are found\nplease choose one FPGA'.format(len(devs)) exception_quit(s, 1) if not devs: sys.exit(2) args.fpga_root = devs[0].get('path') args.eth_grps = f.find_eth_group(args.fpga_root) print("args.eth_grps", args.eth_grps) if len(args.eth_grps) == 0: exception_quit("Invalid Eth group MDEV") lp = FPGAMAC(args) lp.eth_group_start()
def main(): parser = argparse.ArgumentParser() parser.add_argument('--segment', '-S', type=hexint, help='Segment number of PCIe device') parser.add_argument('--bus', '-B', type=hexint, help='Bus number of PCIe device') parser.add_argument('--device', '-D', type=hexint, help='Device number of PCIe device') parser.add_argument('--function', '-F', type=hexint, help='Function number of PCIe device') parser.add_argument('--clear', '-c', action='store_true', help='Clear statistics') parser.add_argument('--debug', '-d', action='store_true', help='Output debug information') args, left = parser.parse_known_args() f = FpgaFinder(args.segment, args.bus, args.device, args.function) devs = f.find() for d in devs: if args.debug: s = 'bdf: {segment:04x}:{bus:02x}:{dev:02x}.{func:x}'.format(**d) print(s) if len(devs) > 1: exception_quit('{} FPGAs are found\nplease choose ' 'one FPGA'.format(len(devs))) if not devs: exception_quit('no FPGA found') args.sbdf = '{segment:04x}:{bus:02x}:{dev:02x}.{func:x}'.format(**devs[0]) bitstream_id_path = f.find_node(devs[0].get('path'), 'dfl-fme*/bitstream_id', depth=1) with open(bitstream_id_path[0], 'r') as fd: bitstream_id = fd.read().strip() args.build_flags = (int(bitstream_id, 16) >> 24) & 0xff args.fpga_root = devs[0].get('path') args.eth_grps = f.find_eth_group(args.fpga_root) print("args.eth_grps", args.eth_grps) if len(args.eth_grps) == 0: exception_quit("Invalid Eth group MDEV") f = FPGASTATS(args) if args.clear: f.eth_clear_stats() else: f.eth_group_start()
def main(): parser = argparse.ArgumentParser() parser.add_argument('--segment', '-S', type=hexint, help='Segment number of PCIe device') parser.add_argument('--bus', '-B', type=hexint, help='Bus number of PCIe device') parser.add_argument('--device', '-D', type=hexint, help='Device number of PCIe device') parser.add_argument('--function', '-F', type=hexint, help='Function number of PCIe device') parser.add_argument('--number', '-n', default=DEFAULT_TEST_PKT_NUM, help='Number of the test packets to send per MAC') parser.add_argument('--length', '-s', default=DEFAULT_TEST_PKT_LEN, help='Length of each test packet') parser.add_argument('--loopback', '-l', action='store_true', help='Configure loopback automatically.' 'Loopback is not configured by default.') parser.add_argument('--clear', '-c', action='store_true', help='Clear statistics automatically.' 'Statistics are not cleared by default.') parser.add_argument('--port', '-p', nargs='*', default='all', help='Test on selected MACs') parser.add_argument('--debug', '-d', action='store_true', help='Output debug information') args, left = parser.parse_known_args() setattr(args, 'number', int(getattr(args, 'number'))) if args.number < MIN_TEST_PKT_NUM or args.number > MAX_TEST_PKT_NUM: setattr(args, 'number', DEFAULT_TEST_PKT_NUM) print(('The number of test packets is out of range ({}~{})' ', use {} instead'.format(MIN_TEST_PKT_NUM, MAX_TEST_PKT_NUM, DEFAULT_TEST_PKT_NUM))) setattr(args, 'length', int(getattr(args, 'length'))) if args.length < MIN_TEST_PKT_LEN or args.length > MAX_TEST_PKT_LEN: setattr(args, 'length', DEFAULT_TEST_PKT_LEN) print(('The length of test packet is out of range ({}~{})' ', use {} instead'.format(MIN_TEST_PKT_LEN, MAX_TEST_PKT_LEN, DEFAULT_TEST_PKT_LEN))) f = FpgaFinder(args.segment, args.bus, args.device, args.function) devs = f.find() for d in devs: sbdf = '{segment:04x}:{bus:02x}:{dev:02x}.{func:x}'.format(**d) print('DUT: {}'.format(sbdf)) if len(devs) > 1: exception_quit('{} FPGAs are found\n' 'please choose one FPGA'.format(len(devs)), 1) if not devs: exception_quit('no FPGA found', 2) args.fpga_root = devs[0].get('path') args.eth_grps = f.find_eth_group(args.fpga_root) print("args.eth_grps", args.eth_grps) if len(args.eth_grps) == 0: exception_quit("Invalid Eth group MDEV") get_sbdf_mode_mapping(sbdf, args) lock_file = '/tmp/DUT{}'.format(sbdf) if os.path.exists(lock_file): exception_quit("FPGA {} is already in test".format(sbdf), 0) try: with open(lock_file, 'w') as fd: fd.write(sbdf) enable_loopback(args) fvl_bypass_mode_test(sbdf, args) finally: disable_loopback(args) if os.path.exists(lock_file): os.remove(lock_file) print('Done')