def test_body(self):
        console = self.board.console
        if not console:
            raise TaskFailed('No console available')

        received = console.send_and_read('cat /proc/meminfo')
        available_mb = None
        total_mb = None

        try:
            for line in received.splitlines():
                if line.startswith('MemFree:'):
                    available_mb = math.floor(int(line.split()[1]) / 1024)
                if line.startswith('MemTotal:'):
                    total_mb = math.floor(int(line.split()[1]) / 1024)
        except ValueError:
            # Failed to convert to integer
            pass
        except IndexError:
            # Unexpected format
            pass

        if not available_mb or not total_mb:
            raise TaskFailed(
                f'Unexpected output from /proc/meminfo:{os.linesep}{received}')

        if self.total_mb and total_mb != self.total_mb:
            raise TaskFailed(
                f'The system has {total_mb} MB of RAM, but expected {self.total_mb} MB'
            )

        if self.available_mb and available_mb < self.available_mb:
            raise TaskFailed(
                f'The system has {available_mb} MB of RAM available, but expected '
                f'at least {self.available_mb} MB')
示例#2
0
    def test_body(self):
        console = self.board.console
        if not console:
            raise TaskFailed('No console available')

        output = CommandRunner.run(test_name=str(self),
                                   console=console,
                                   command='lsmod',
                                   timeout=3)

        missing_modules = []
        for module in self.modules:
            found = False
            # For some reason, re.MULTILINE fails to match
            for line in output.splitlines():
                if re.match(fr'^{module}\b', line):
                    found = True
                    break

            if not found:
                missing_modules.append(module)

        if missing_modules:
            raise TaskFailed(
                f'The following kernel modules are not loaded: "{missing_modules}"'
            )
示例#3
0
 def log_error(test_name: str, sent: str, output: str, error: str,
               match_regex: List[str] = None, error_regex: List[str] = None):
     message = f'Script test "{test_name}": {error}:{os.linesep}'
     message += CommandRunner.format_command_log(sent=sent, output=output,
                                                 match_regex=match_regex,
                                                 error_regex=error_regex)
     raise TaskFailed(message)
    def execute(self):
        entered = None

        if self.manual_test_name:
            test_title = f'Manual test "{self.manual_test_name}"'
        else:
            test_title = 'Manual test'

        while (entered not in ['y', 'n']):
            log.log(
                f'{os.linesep}{test_title}:'
                f'{os.linesep}  > {self.message}'
                f'{os.linesep}  > Expected: {self.message}'
                f'{os.linesep}Was the test successful? [y/n]: ',
                level=LogLevel.INFO,
                bypass_hold=True,
                newline=False)
            entered = input().lower()

        log.log(f'The user entered: "{entered}"',
                level=LogLevel.INFO,
                bypass_hold=True)
        log.log('Comments: ',
                level=LogLevel.INFO,
                bypass_hold=True,
                newline=False)
        comments = input()
        log.log(f'The user entered: "{comments}"',
                level=LogLevel.INFO,
                bypass_hold=True)

        if entered != 'y':
            raise TaskFailed('Manual test failed')
示例#5
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
 def execute(self):
     self.board.console.read_all()
     matched_output = self.board.console.wait_for_match(
         match=self.pattern, timeout=self.timeout)
     if not matched_output:
         raise TaskFailed(
             f'{str(self)}: Timeout reached while waiting for pattern "{self.pattern}"'
         )
示例#7
0
    def execute(self):
        if self.device_console:
            log.log(f'Setting device console to {self.device_console}')
            console = self.board.get_console(self.device_console)
            if not console:
                raise TaskFailed(
                    'Failed to find console "{self.device_console}"')

            self.board.console = console
示例#8
0
    def execute(self):
        if not self.board.console.support_file_copy:
            raise TaskFailed(
                'Cannot deploy files, current console does not support file copy. '
                'Use or set a different console to be able to deploy files (e.g. SSH)'
            )

        for f in self.files:
            log.log(
                f'Copying {f} to target device destination {self.destination}')
            self.board.console.copy_to_target(source=f,
                                              destination=self.destination,
                                              timeout=self.timeout)
示例#9
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')
示例#10
0
    def _host_mount(self):
        self.board.log("\n=!= HOST MOUNT =!=", bold=True)
        self.board.storage.to_host()

        devnode = None
        for _ in range(1, 5):
            if not self.board.hub.get_part():
                time.sleep(1)
            else:
                devnode = self.board.hub.get_part('devnode')
                break
        if not devnode:
            raise TaskFailed(
                'Cannot mount: No block device partition downstream of hub')

        self.board.storage.mount_host(devnode)
示例#11
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)
示例#12
0
 def _board_login(self):
     self.board.log("\n=!= BOARD LOGIN =!=", bold=True)
     try:
         self.board.login()
     except ConsoleLoginFailedError as e:
         raise TaskFailed(str(e))