예제 #1
0
def test_hostconsole_bin_sh_send():
    console = HostConsole('/bin/sh')

    __, matched = console.send_and_expect(cmd='echo $SHELL',
                                          match='/bin/.*sh',
                                          timeout=0.5)

    assert matched
    def test_body(self):
        filepath = ''
        console = None
        temp_folder = None
        if self.run_on_host:
            console = HostConsole('sh')
            filepath = self.executable_file
        else:
            console = self.board.console
            if not console:
                raise ValueError('Current console is null, cannot copy executable')

            if self.host_file:
                self.check_console_supports_copy(console)
                filepath, temp_folder = self.deploy_file_in_tmp_folder(
                    file=self.executable_file, console=console)
            else:
                filepath = self.executable_file

        try:
            CommandRunner.run(test_name=self._test_name, command=filepath,
                              console=console, timeout=self.timeout)
        finally:
            if temp_folder:
                CommandRunner.run(test_name=self._test_name, command=f'rm -r {temp_folder}',
                                  console=console, timeout=self.timeout)
예제 #3
0
    def run_commands(self,
                     console: Optional[ConsoleBase] = None,
                     scripts: List[str] = None,
                     timeout: Optional[int] = None) -> str:
        scripts = scripts or self.scripts

        if console is None:
            if self.run_on_host:
                console = HostConsole('sh')
            else:
                console = self.board.console
                if not console:
                    raise TaskFailed(
                        f'Failed to run script test "{self._test_name}": '
                        'no console available')

        if self.runs_in_shell and self.login_automatically and console.requires_login:
            self.board.login()

        output = ''
        for script in scripts:
            output += self.run_command(console=console,
                                       script=script,
                                       timeout=timeout)

        return output
예제 #4
0
    def test_body(self):
        filepath = ''
        console = None
        temp_folder = None
        if self.run_on_host:
            console = HostConsole('sh')
            filepath = self.executable_file
        else:
            console = self.board.console
            if self.host_file:
                temp_folder = self.random_folder_name()
                CommandRunner.run(test_name=self._test_name,
                                  command=f'mkdir {temp_folder}',
                                  console=console,
                                  timeout=self.timeout)
                destination = os.path.join(
                    temp_folder, os.path.basename(self.executable_file))
                console.copy_to_target(self.executable_file, destination)
                filepath = destination
            else:
                filepath = self.executable_file

        if not console:
            raise TaskFailed(
                f'Failed to run script test "{self}": no console available')

        try:
            CommandRunner.run(test_name=self,
                              command=filepath,
                              console=console,
                              timeout=self.timeout)
        finally:
            if temp_folder:
                CommandRunner.run(test_name=self,
                                  command=f'rm -r {temp_folder}',
                                  console=console,
                                  timeout=self.timeout)
예제 #5
0
    def test_body(self):
        with concurrent.futures.ThreadPoolExecutor() as executor:
            iperf_server = executor.submit(self.run_iperf_server)

            # Wait for the server to start
            time.sleep(2)
            command = f'iperf -c {self.target} --time {self.duration}'
            self.run_commands(console=HostConsole('sh'), scripts=[command])

            target_output = iperf_server.result()

        bandwidth_regex = r'\s+(\d+(\.{0,1}\d+){0,1}) Mbits\/'
        match = re.search(bandwidth_regex, target_output, re.MULTILINE)
        if not match:
            raise TaskFailed('Failed to match iperf bandwidth regex for '
                             f'output:{os.linesep}{target_output}')

        bandwidth = float(match.group(1))
        if bandwidth < self.minimum_mbps:
            raise TaskFailed('Bandwidth is lower than the minimum expected of '
                             f'{self.minimum_mbps} MBps with {bandwidth} MBps.')

        log.info(f'Bandwidth: {bandwidth} MBps')