diff options
author | Steven Koo <steven.koo@ni.com> | 2022-06-14 09:27:41 -0500 |
---|---|---|
committer | skooNI <60897865+skooNI@users.noreply.github.com> | 2022-07-20 15:57:20 -0500 |
commit | 8d05b1cda1b26b4ba134f114b9424446b410ac76 (patch) | |
tree | ec80f93b3a5a478674d8032149d825f33eccfcd5 /.ci/utils | |
parent | ce000955aea05802a00a8c47b6b8d1819d6fa0bc (diff) | |
download | uhd-8d05b1cda1b26b4ba134f114b9424446b410ac76.tar.gz uhd-8d05b1cda1b26b4ba134f114b9424446b410ac76.tar.bz2 uhd-8d05b1cda1b26b4ba134f114b9424446b410ac76.zip |
ci: Add n310 into devtests
This commit adds support for reimaging n3xx devices and running
devtest against a n310. This uses Labgrid to control an sdmux,
which we then reimage the device. In the future, other devices can
use this support to run other tests.
Signed-off-by: Steven Koo <steven.koo@ni.com>
Diffstat (limited to '.ci/utils')
-rw-r--r-- | .ci/utils/mutex_hardware.py | 75 |
1 files changed, 71 insertions, 4 deletions
diff --git a/.ci/utils/mutex_hardware.py b/.ci/utils/mutex_hardware.py index 4c05bf50b..e6fece61f 100644 --- a/.ci/utils/mutex_hardware.py +++ b/.ci/utils/mutex_hardware.py @@ -4,6 +4,7 @@ # into a state where it can be used for testing. import argparse +import labgrid import os import pathlib import shlex @@ -17,7 +18,7 @@ from redis import Redis bitfile_name = "usrp_{}_fpga_{}.bit" -def jtag_x3xx(jtag_server, jtag_serial, dev_model, fpga_folder, fpga, redis_server): +def jtag_x3xx(dev_type, dev_model, jtag_server, jtag_serial, fpga_folder, fpga, redis_server): remote_working_dir = "pipeline_fpga" vivado_program_jtag = "/opt/Xilinx/Vivado_Lab/2020.1/bin/vivado_lab -mode batch -source {}/viv_hardware_utils.tcl -nolog -nojournal -tclargs program".format( remote_working_dir) @@ -40,12 +41,69 @@ def jtag_x3xx(jtag_server, jtag_serial, dev_model, fpga_folder, fpga, redis_serv print("Waiting 15 seconds for device to come back up and for Vivado to close", flush=True) time.sleep(15) +def set_sfp_addrs(mgmt_addr, sfp_addrs): + with Connection(host=mgmt_addr,user='root',connect_kwargs={"password":"", "timeout":120, "banner_timeout":120, "auth_timeout":120}) as dut: + for idx, sfp_addr in enumerate(sfp_addrs): + dut.run(f"ip link set sfp{idx} down") + dut.run(f"ip addr add {sfp_addr}/24 dev sfp{idx}") + dut.run(f"ip link set sfp{idx} up") + time.sleep(30) + +def flash_sdimage(dev_model, sdimage_path, labgrid_device_yaml, mgmt_addr, sfp_addrs): + subprocess.run(shlex.split(f"labgrid-client -c {labgrid_device_yaml} release --kick")) + subprocess.run(shlex.split(f"labgrid-client -c {labgrid_device_yaml} acquire")) + env = labgrid.Environment(labgrid_device_yaml) + target = env.get_target() + + print("Powering down DUT", flush=True) + cp = target.get_driver(labgrid.protocol.ConsoleProtocol, name="scu_serial_driver") + cp.write("\napshutdown\n".encode()) + + print("Switching SDMux to Host", flush=True) + sdmux = target.get_driver(labgrid.driver.USBSDMuxDriver) + sdmux.set_mode('host') + + print(f"Writing SDMux using {sdimage_path}", flush=True) + massstore = target.get_driver(labgrid.driver.USBStorageDriver) + # This uses bmaptool in --nobmap mode to write the sdimg, + # since it automatically decompresses the image. Do not + # include the .bmap file since it can cause corruption with mender. + # See: https://github.com/mendersoftware/meta-mender/pull/1076 + massstore.write_image(sdimage_path, mode=labgrid.driver.usbstoragedriver.Mode.BMAPTOOL) + time.sleep(30) + + print("Switching SDMux to DUT", flush=True) + sdmux.set_mode('dut') + time.sleep(30) + + print("Powering on DUT", flush=True) + cp.write("\npowerbtn\n".encode()) + + print("Waiting 2 minutes for device to boot", flush=True) + time.sleep(120) + known_hosts_path = os.path.expanduser("~/.ssh/known_hosts") + subprocess.run(shlex.split(f"ssh-keygen -f \"{known_hosts_path}\" -R \"{mgmt_addr}\"")) + + if sfp_addrs: + set_sfp_addrs(mgmt_addr, sfp_addrs) + + subprocess.run(shlex.split(f"labgrid-client -c {labgrid_device_yaml} release")) + def main(args): redis_server = {Redis.from_url( "redis://{}:6379/0".format(args.redis_server))} print("Waiting to acquire mutex for {}".format(args.dut_name), flush=True) with Redlock(key=args.dut_name, masters=redis_server, auto_release_time=1000 * 60 * args.dut_timeout): print("Got mutex for {}".format(args.dut_name), flush=True) + + if args.sdimage: + dev_type, dev_model, sdimage_path, labgrid_device_yaml, mgmt_addr = args.sdimage.split(',') + if args.sfp_addrs: + sfp_addrs = args.sfp_addrs.split(',') + else: + sfp_addrs = None + flash_sdimage(dev_model, sdimage_path, labgrid_device_yaml, mgmt_addr, sfp_addrs) + if args.fpgas: working_dir = os.getcwd() return_code = 0 @@ -54,8 +112,13 @@ def main(args): os.chdir(os.path.join(working_dir, fpga)) if args.jtag_x3xx: - jtag_server, jtag_serial, dev_model, fpga_folder = args.jtag_x3xx.split(',') - jtag_x3xx(jtag_server, jtag_serial, dev_model, fpga_folder, fpga, redis_server) + dev_type, dev_model, jtag_server, jtag_serial, fpga_folder = args.jtag_x3xx.split(',') + jtag_x3xx(dev_type, dev_model, jtag_server, jtag_serial, fpga_folder, fpga, redis_server) + + if dev_type and dev_type in ["n3xx", "e3xx"]: + subprocess.run(shlex.split(f"uhd_image_loader --args=mgmt_addr={mgmt_addr},type={dev_type},fpga={fpga}")) + if sfp_addrs: + set_sfp_addrs(mgmt_addr, sfp_addrs) for command in args.test_commands: result = subprocess.run(shlex.split(command)) @@ -76,7 +139,11 @@ if __name__ == "__main__": # Provide fpga_path as a local path and it will be copied # to jtag_server. parser.add_argument("--jtag_x3xx", type=str, - help="user@jtag_server,jtag_serial,dev_model,fpga_folder") + help="dev_type,dev_model,user@jtag_server,jtag_serial,fpga_folder") + parser.add_argument("--sdimage", type=str, + help="dev_type,dev_model,sdimg_path,labgrid_device_yaml,mgmt_addr") + parser.add_argument("--sfp_addrs", type=str, + help="sfp0ip,sfp1ip,...") parser.add_argument("--fpgas", type=str, help="Comma delimited list of FPGAs to test") parser.add_argument("--dut_timeout", type=int, default=60, |