Exemplo n.º 1
0
def test_serial_interface(mocker):
    name = "dummy_serial"
    register_plugin(name, "serial", "test_plugin:DummySerial")
    mock_xexpect = mocker.patch("roast.serial.Xexpect",
                                return_value=mocker.Mock("xexpect"))
    mock_xexpect.return_value.expect = mocker.Mock("xexpect",
                                                   return_value="xexpect")
    mock_xexpect.return_value.sendline = mocker.Mock("sendline")
    mock_xexpect.return_value.runcmd = mocker.Mock("runcmd")
    mock_xexpect.return_value.runcmd_list = mocker.Mock("runcmd_list")
    mock_xexpect.return_value.sendcontrol = mocker.Mock("sendcontrol")
    mock_xexpect.return_value.send = mocker.Mock("send")
    mock_xexpect.return_value.output = mocker.Mock("output")
    mock_xexpect.return_value._setup_init = mocker.Mock("setup_init")
    mock_xexpect.return_value.search = mocker.Mock("search")
    mock_xexpect.return_value.sync = mocker.Mock("sync")
    s = Serial(serial_type="dummy_serial", config=config)
    assert isinstance(s, Serial)
    assert s.driver.config == config
    assert s.driver.hostname == "hostname"
    assert s.driver.configure == True
    assert s.driver.connect == True
    s.driver.prompt = "prompt"
    assert s.driver.prompt == "prompt"
    s.exit()
    assert s.driver.exit == True
Exemplo n.º 2
0
def sd_boot(board, boot_device="SD"):
    bootmode_cmd = {"SD": "sd1_ls", "MMC": "emmc"}
    board.serial.mode = True
    board.systest.reboot()
    if not board.xsdb:
        board.xsdb = Xsdb(board.config, hwserver=board.config["systest_host"])
    if "port" in board.config:
        board.serial = Serial("systest",
                              board.config,
                              mode=True,
                              port=board.config["port"]).driver
    else:
        board.serial = Serial("systest",
                              board.config,
                              mode=True,
                              port="serial").driver
    if board.config["platform"] == "zynq":
        board.systest.runcmd("bootmode 'sd'")
        board.serial.mode = True
        board.systest.reset()
    elif board.config["platform"] == "zynqmp":
        if "bootmode_tcl" in board.config:
            board.xsdb.run_tcl(f"{board.config['bootmode_tcl']}")
        else:
            zynqmp_bootmode_sd(board, boot_device)

    elif board.config["platform"] == "versal":
        board.systest.runcmd(f"bootmode '{bootmode_cmd[boot_device]}'")
Exemplo n.º 3
0
def test_host_serial(mocker):
    mock_xexpect = mocker.patch(
        "roast.serial.Xexpect", return_value=mocker.Mock("xexpect")
    )
    mock_xexpect.return_value.expect = mocker.Mock("xexpect", return_value="xexpect")
    mock_xexpect.return_value.sendline = mocker.Mock("sendline")
    mock_xexpect.return_value.runcmd = mocker.Mock("runcmd")
    mock_xexpect.return_value.runcmd_list = mocker.Mock("runcmd_list")
    mock_xexpect.return_value.sendcontrol = mocker.Mock("sendcontrol")
    mock_xexpect.return_value.send = mocker.Mock("send")
    mock_xexpect.return_value.output = mocker.Mock("output")
    mock_xexpect.return_value._setup_init = mocker.Mock("setup_init")
    mock_xexpect.return_value.search = mocker.Mock("search")
    mock_xexpect.return_value.sync = mocker.Mock("sync")
    mock_picom_connect = mocker.patch("roast.component.host_serial.picom_connect")
    mock_picom_disconnect = mocker.patch("roast.component.host_serial.picom_disconnect")
    s = Serial(serial_type="host", config=config)
    assert s.driver.config == config
    assert s.driver.hostname == "remote_host"
    mock_picom_connect.assert_called_with(mocker.ANY, "com", "baudrate")
    s.exit()
    mock_picom_disconnect.assert_called()
Exemplo n.º 4
0
    def start(self) -> None:
        self.interface = self.config.get("board_interface")
        self.relay_type = self.config.get("relay_type")
        if self.interface == "host_target":
            self._setup_host_target()
            self.relay = Relay(self.relay_type,
                               session=self.host_console).driver
            self._reboot()
            self.serial = Serial("host", self.config).driver

        elif self.interface == "network_target":
            self._set_nw_target()
            self.target_console = Xexpect(
                tlog,
                hostip=self.ip,
                userid=self.user,
                password=self.password,
                non_interactive=False,
            )
        elif self.interface == "qemu":
            log.info("Running Qemu Interface")
        else:
            raise Exception(f"ERROR: invalid board_interface {self.interface}")
Exemplo n.º 5
0
def sd_boot(board, boot_device="SD"):
    board.serial.mode = True
    board.systest.reboot()
    if not board.xsdb:
        board.xsdb = Xsdb(board.config, hwserver=board.config["systest_host"])

    board.serial = Serial("systest", board.config, mode=True).driver
    if board.config["platform"] == "zynq":
        board.systest.runcmd("bootmode 'sd'")
        board.serial.mode = True
        board.systest.reset()
    elif board.config["platform"] == "zynqmp":
        if has_key(board.config, "bootmode_tcl"):
            board.xsdb.run_tcl(f"{board.config['bootmode_tcl']}")
        else:
            zynqmp_bootmode_sd(board, boot_device)

    elif board.config["platform"] == "versal":
        board.systest.runcmd("bootmode 'sd1_ls'")
Exemplo n.º 6
0
def test_serial_exception():
    config["board_interface"] = None
    with pytest.raises(Exception, match="invalid serial interface"):
        Serial(serial_type="host", config=config)
Exemplo n.º 7
0
def test_serial_interface(mocker):
    mock_init = mocker.patch("roast.serial.HostSerial.__init__",
                             return_value=None)
    s = Serial(serial_type="host", config=config)
    assert isinstance(s, Serial)
    mock_init.assert_called_with(config)
Exemplo n.º 8
0
def s():
    name = "dummy_serial"
    register_plugin(name, "serial", "tests.test_plugin:DummySerial")
    return Serial(serial_type=name, config=config)
Exemplo n.º 9
0
class TargetBoard(BoardBase):
    def __init__(self) -> None:
        super().__init__()

    def start(self) -> None:
        self.interface = self.config.get("board_interface")
        self.relay_type = self.config.get("relay_type")
        if self.interface == "host_target":
            self._setup_host_target()
            self.relay = Relay(self.relay_type,
                               session=self.host_console).driver
            self._reboot()
            self.serial = Serial("host", self.config).driver

        elif self.interface == "network_target":
            self._set_nw_target()
            self.target_console = Xexpect(
                tlog,
                hostip=self.ip,
                userid=self.user,
                password=self.password,
                non_interactive=False,
            )
        elif self.interface == "qemu":
            log.info("Running Qemu Interface")
        else:
            raise Exception(f"ERROR: invalid board_interface {self.interface}")

    def _setup_host_target(self) -> None:
        self._set_host()
        if not self.isLive:
            self.host_console = Xexpect(
                hlog,
                hostname=self.host,
                non_interactive=False,
            )
            if self.invoke_hwserver:
                self.xsdb_hwserver = Xsdb(self.config,
                                          hostname=self.host,
                                          setup_hwserver=True)
            if self.invoke_xsdb:
                self.xsdb = Xsdb(self.config, hwserver=self.host)
            self.isLive = True
        else:
            self.serial.exit()
            time.sleep(4)
            if self.invoke_xsdb:
                self.xsdb = Xsdb(self.config, hwserver=self.host)

    def _set_nw_target(self) -> None:
        self.ip = self.config["target_ip"]
        self.user = self.config["user"]
        self.password = self.config["password"]

    def _reboot(self) -> None:
        if self.isLive and self.reboot:
            if self.interface == "host_target":
                self.relay.reconnect()

    def put(self, src_file: str, dest_path: str) -> None:
        self._get_target_ip()
        if not self.target_ip:
            assert False, "ERROR: Not a valid target ip"
        if self.interface == "host_target":
            scp_file_transfer(
                self.host_console,
                src_file,
                dest_path,
                target_ip=self.target_ip,
                proxy_server=self.host,
            )

    def get(self, src_file: str, dest_path: str) -> None:
        self._get_target_ip()
        if self.interface == "host_target":
            scp_file_transfer(
                self.host_console,
                src_file,
                host_path=dest_path,
                transfer_to_target=False,
                target_ip=self.target_ip,
                proxy_server=self.host,
            )

    def reset(self) -> None:
        if self.isLive:
            if self.interface == "host_target":
                self.relay.reconnect()
Exemplo n.º 10
0
def test_serial_exception():
    with pytest.raises(Exception, match="No 'roast.serial' driver found"):
        Serial(serial_type="", config=config)