Пример #1
0
    def login(self):
        '''
        Login to the device.
        '''
        SerialDevice.login(self)

        # The JerryScript testsuite does not require Internet connection.
        if self.app == 'jerryscript':
            return

        try:
            # Set up the wifi connection.
            wifi_name = utils.get_environment('ARTIK_WIFI_NAME')
            wifi_pwd = utils.get_environment('ARTIK_WIFI_PWD')

            self.channel.exec_command('wifi startsta')
            self.channel.exec_command('wifi join %s %s' %
                                      (wifi_name, wifi_pwd))
            self.channel.exec_command('ifconfig wl1 dhcp')

            # Set the current date and time on the device.
            # Note: test_tls_ca.js requires the current datetime.
            datetime = utils.current_date('%b %d %H:%M:%S %Y')
            self.channel.exec_command('date -s %s' % datetime)
            time.sleep(1)

        except Exception as e:
            console.fail(str(e))
Пример #2
0
    def login(self):
        '''
        Login to the device.
        '''
        try:
            self.channel.open()

            if self.device in ['artik053', 'stm32f4dis']:
                # Press enters to start the serial communication and
                # go to the test folder because some tests require resources.
                self.channel.exec_command('\n\n')
                self.channel.exec_command('cd /test')

                if self.device == 'artik053' and self.app == 'iotjs':
                    # Set up the wifi connection.
                    wifi_name = utils.get_environment('ARTIK_WIFI_NAME')
                    wifi_pwd = utils.get_environment('ARTIK_WIFI_PWD')

                    self.channel.exec_command('wifi startsta')
                    self.channel.exec_command('wifi join %s %s' % (wifi_name, wifi_pwd))
                    self.channel.exec_command('ifconfig wl1 dhcp')

                    # Set the current date and time on the device.
                    # Note: test_tls_ca.js requires the current datetime.
                    datetime = utils.current_date('%b %d %H:%M:%S %Y')
                    self.channel.exec_command('date -s %s' % datetime)

                    time.sleep(1)

        except Exception as e:
            console.fail(str(e))
Пример #3
0
def execute(cwd, cmd, args=None, quiet=False, strict=True):
    '''
    Run the given command.
    '''
    if args is None:
        args = []

    stdout = None
    stderr = None

    if quiet or os.environ.get('QUIET', ''):
        stdout = subprocess.PIPE
        stderr = subprocess.STDOUT

    if not quiet and os.environ.get('QUIET', ''):
        print_command(cwd, cmd, args)

    try:
        process = subprocess.Popen([cmd] + args,
                                   stdout=stdout,
                                   stderr=stderr,
                                   cwd=cwd)

        output = process.communicate()[0]
        exitcode = process.returncode

        if strict and exitcode:
            raise Exception('Non-zero exit value.')

        return output, exitcode

    except Exception as e:
        console.fail('[Failed - %s %s] %s' % (cmd, ' '.join(args), str(e)))
Пример #4
0
    def iotjs_build_info(self):
        '''
        Get buildinfo from iotjs.
        '''
        if self.device in ['rpi2', 'artik530']:
            iotjs = '%s/iotjs' % self.workdir
            buildinfo = '%s/tests/tools/iotjs_build_info.js' % self.workdir
            command = '%s %s' % (iotjs, buildinfo)

        elif self.device in ['artik053', 'stm32f4dis']:
            buildinfo = '/test/tools/iotjs_build_info.js'
            command = 'iotjs %s' % buildinfo

        # Wait a moment to boot the device.
        time.sleep(2)

        self.login()

        output = self.channel.exec_command(command)
        # Process the output to get the json string and the exitcode.
        build_info, _, exitcode = testrunner_utils.process_output(output)

        if exitcode != 0:
            console.fail('%s returned with exitcode %d' % (buildinfo, exitcode))

        info = json.loads(build_info)

        builtins = set(info['builtins'])
        features = set(info['features'])
        stability = info['stability']

        self.logout()

        return builtins, features, stability
Пример #5
0
def exec_shell(cwd, cmd, args, env, quiet, strict):
    '''
    Execute the shell command.
    '''
    stdout = None
    stderr = None

    if quiet or os.environ.get('QUIET', ''):
        stdout = subprocess.PIPE
        stderr = subprocess.STDOUT

    if not quiet and os.environ.get('QUIET', ''):
        print_command(cwd, cmd, args)

    try:
        process = subprocess.Popen([cmd] + args,
                                   stdout=stdout,
                                   stderr=stderr,
                                   cwd=cwd,
                                   env=env)

        output = process.communicate()[0]
        exitcode = process.returncode

        if strict and exitcode:
            raise Exception('Non-zero exit value.')

        return output, exitcode

    except Exception as e:
        console.fail('[Failed - %s %s] %s' % (cmd, ' '.join(args), str(e)))
Пример #6
0
def get(command):
    '''
    Get a pointer to the given buil-in function.
    '''
    if command not in NATIVES:
        console.fail('%s built-in function is not found.')

    return NATIVES[command]
Пример #7
0
 def open(self):
     '''
     Open the serial port.
     '''
     try:
         self.telnet.open(self.ip)
         self.telnet.read_until(self.prompt)
     except Exception as e:
         console.fail(str(e))
Пример #8
0
    def login(self):
        '''
        Login to the device.
        '''
        try:
            self.channel.open()

        except Exception as e:
            console.fail(str(e))
Пример #9
0
    def check_args(self):
        '''
        Check that all the arguments are established.
        '''
        if self.env.options.emulate:
            return

        if self.device not in ['rpi2', 'rpi3', 'artik053', 'stm32f4dis']:
            console.fail('The selected device is not supported')
Пример #10
0
    def login(self):
        '''
        Login to the device.
        '''
        try:
            self.channel.open()
            self.channel.exec_command('cd /test')

        except Exception as e:
            console.fail(str(e))
Пример #11
0
    def exec_command(self, cmd):
        '''
        Send command over the serial port.
        '''
        if isinstance(cmd, unicode):
            cmd = cmd.encode('utf8')
        try:
            self.telnet.write('%s\n' % cmd)
        except Exception as e:
            console.fail(str(e))

        return self._read_data()
Пример #12
0
def read_port_from_url(url):
    '''
    Parse URL and return with the port number
    '''
    pattern = '(?:http.*://)?(?P<host>[^:/ ]+).?(?P<port>[0-9]*).*'

    match = re.search(pattern, url)

    if not match:
        console.fail('Invalid URL: %s' % url)

    return match.group('port')
Пример #13
0
    def check_args(self):
        '''
        Check that all the arguments are established.
        '''
        if not self.workdir:
            console.fail('Please use --remote-workdir for the device.')
        if not self.ip:
            console.fail('Please define the IP address of the device.')
        if not self.user:
            console.fail('Please define the username of the device.')

        if self.workdir == '/':
            console.fail('Please do not use the root folder as test folder.')
Пример #14
0
    def iotjs_build_info(self):
        '''
        Get buildinfo from iotjs.
        '''
        if not utils.exist_files(self.env.modules.app.paths.tests,
                                 ['testsets.json']):
            return set(), set(), 'stable'

        if self.device in ['rpi2', 'rpi3']:
            tester_py = 'python %s/tester.py ' % self.workdir
            iotjs = '%s/iotjs' % self.workdir
            buildinfo = '%s/tests/tools/iotjs_build_info.js' % self.workdir
            template = '%s --cwd %s --cmd %s --testfile %s --iotjs-build-info'
            command = template % (tester_py, self.workdir, iotjs, buildinfo)

        elif self.device in ['artik053', 'stm32f4dis']:
            buildinfo = '/test/tools/iotjs_build_info.js'
            command = 'iotjs %s' % buildinfo

        # Wait a moment to boot the device.
        time.sleep(2)

        self.login()

        output = self.channel.exec_command(command)
        # Process the output to get the json string and the exitcode.
        build_info, _, exitcode = testrunner_utils.process_output(output)

        if exitcode != 0:
            console.fail('%s returned with exitcode %d' %
                         (buildinfo, exitcode))

        info = json.loads(build_info)

        builtins = set(info['builtins'])
        features = set(info['features'])
        stability = info['stability']

        return builtins, features, stability
Пример #15
0
def patch(project, patch_file, revert=False):
    '''
    Apply the given patch to the given project.
    '''
    patch_options = ['-p1', '-d', project]
    dry_options = ['--dry-run', '-R', '-f', '-s', '-i']

    if not os.path.exists(patch_file):
        console.fail(patch_file + ' does not exist.')

    # First check if the patch can be applied to the project.
    patch_cmd_args = patch_options + dry_options + [patch_file]
    _, patch_applicable = execute('.',
                                  'patch',
                                  patch_cmd_args,
                                  strict=False,
                                  quiet=True)

    # Apply the patch if project is clean and revert flag is not set.
    if not revert and patch_applicable:
        patch_cmd_args = patch_options + ['-i', patch_file]
        _, exitcode = execute('.',
                              'patch',
                              patch_cmd_args,
                              strict=False,
                              quiet=True)
        if exitcode:
            console.fail('Failed to apply ' + patch_file)

    # Revert the patch if the project already contains the modifications.
    if revert and not patch_applicable:
        patch_cmd_args = patch_options + ['-i', patch_file, '-R']
        _, exitcode = execute('.',
                              'patch',
                              patch_cmd_args,
                              strict=False,
                              quiet=True)
        if exitcode:
            console.fail('Failed to revert ' + patch_file)
Пример #16
0
    def check_args(self):
        '''
        Check that all the arguments are established.
        '''
        if self.device in ['rpi2', 'artik530']:
            if not self.workdir:
                console.fail('Please use --remote-workdir for the device.')
            if not self.ip:
                console.fail('Please define the IP address of the device.')
            if not self.user:
                console.fail('Please define the username of the device.')

            if self.workdir == '/':
                console.fail('Please do not use the root folder as test folder.')

        elif self.device in ['artik053', 'stm32f4dis']:
            if not self.env['info']['device_id']:
                console.fail('Please use the --device-id to select the device.')

        else:
            console.fail('The selected device is not supported')
Пример #17
0
 def check_args(self):
     '''
     Check that all the arguments are established.
     '''
     if not self.env.options.device_id:
         console.fail('Please use the --device-id to select the device.')