Example #1
0
    def _init_target(self, force = False):

        if not force and self.target is not None:
            return self.target

        self.__connection_settings = {}

        # Configure username
        if 'username' in self.conf:
            self.__connection_settings['username'] = self.conf['username']
        else:
            self.__connection_settings['username'] = USERNAME_DEFAULT

        # Configure password or SSH keyfile
        if 'keyfile' in self.conf:
            self.__connection_settings['keyfile'] = self.conf['keyfile']
        elif 'password' in self.conf:
            self.__connection_settings['password'] = self.conf['password']
        else:
            self.__connection_settings['password'] = PASSWORD_DEFAULT

        # Configure port
        if 'port' in self.conf:
            self.__connection_settings['port'] = self.conf['port']

        # Configure the host IP/MAC address
        if 'host' in self.conf:
            try:
                if ':' in self.conf['host']:
                    (self.mac, self.ip) = self.resolv_host(self.conf['host'])
                else:
                    self.ip = self.conf['host']
                self.__connection_settings['host'] = self.ip
            except KeyError:
                raise ValueError('Config error: missing [host] parameter')

        try:
            platform_type = self.conf['platform']
        except KeyError:
            raise ValueError('Config error: missing [platform] parameter')


        ########################################################################
        # Board configuration
        ########################################################################

        # Setup board default if not specified by configuration
        platform = None
        self.__modules = []
        if 'board' not in self.conf:
            self.conf['board'] = 'UNKNOWN'

        # Initialize TC2 board
        if self.conf['board'].upper() == 'TC2':
            platform = devlib.platform.arm.TC2()
            self.__modules = ['bl', 'hwmon', 'cpufreq']

        # Initialize JUNO board
        elif self.conf['board'].upper() in ('JUNO', 'JUNO2'):
            platform = devlib.platform.arm.Juno()
            self.__modules = ['bl', 'hwmon', 'cpufreq']

        # Initialize OAK board
        elif self.conf['board'].upper() == 'OAK':
            platform = Platform(model='MT8173')
            self.__modules = ['bl', 'cpufreq']

        elif self.conf['board'] != 'UNKNOWN':
            # Initilize from platform descriptor (if available)
            board = self._load_board(self.conf['board'])
            if board:
                core_names=board['cores']
                platform = Platform(
                    model=self.conf['board'],
                    core_names=core_names,
                    core_clusters = self._get_clusters(core_names),
                    big_core=board.get('big_core', None)
                )
                self.__modules=board.get('modules', [])

        ########################################################################
        # Modules configuration
        ########################################################################

        # Refine modules list based on target.conf options
        if 'modules' in self.conf:
            self.__modules = list(set(
                self.__modules + self.conf['modules']
            ))
        # Merge tests specific modules
        if self.test_conf and 'modules' in self.test_conf and \
           self.test_conf['modules']:
            self.__modules = list(set(
                self.__modules + self.test_conf['modules']
            ))

        # Initialize modules to exclude on the target
        if 'exclude_modules' in self.conf:
            for module in self.conf['exclude_modules']:
                if module in self.__modules:
                    self.__modules.remove(module)
        # Remove tests specific modules
        if self.test_conf and 'exclude_modules' in self.test_conf:
            for module in self.test_conf['exclude_modules']:
                if module in self.__modules:
                    self.__modules.remove(module)

        logging.info(r'%14s - Devlib modules to load: %s',
                'Target', self.__modules)

        ########################################################################
        # Devlib target setup (based on target.config::platform)
        ########################################################################

        # If the target is Android, we need just (eventually) the device
        if platform_type.lower() == 'android':
            self.__connection_settings = None
            device = 'DEFAULT'
            if 'device' in self.conf:
                device = self.conf['device']
                self.__connection_settings = {'device' : device}
            elif 'host' in self.conf:
                host = self.conf['host']
                port = '5555'
                if 'port' in self.conf:
                    port = str(self.conf['port'])
                device = '{}:{}'.format(host, port)
                self.__connection_settings = {'device' : device}
            logging.info(r'%14s - Connecting Android target [%s]',
                         'Target', device)
        else:
            logging.info(r'%14s - Connecting %s target:', 'Target',
                         platform_type)
            for key in self.__connection_settings:
                logging.info(r'%14s - %10s : %s', 'Target',
                             key, self.__connection_settings[key])

        logging.info(r'%14s - Connection settings:', 'Target')
        logging.info(r'%14s -    %s', 'Target', self.__connection_settings)

        if platform_type.lower() == 'linux':
            logging.debug('%14s - Setup LINUX target...', 'Target')
            self.target = devlib.LinuxTarget(
                    platform = platform,
                    connection_settings = self.__connection_settings,
                    load_default_modules = False,
                    modules = self.__modules)
        elif platform_type.lower() == 'android':
            logging.debug('%14s - Setup ANDROID target...', 'Target')
            self.target = devlib.AndroidTarget(
                    platform = platform,
                    connection_settings = self.__connection_settings,
                    load_default_modules = False,
                    modules = self.__modules)
        elif platform_type.lower() == 'host':
            logging.debug('%14s - Setup HOST target...', 'Target')
            self.target = devlib.LocalLinuxTarget(
                    platform = platform,
                    load_default_modules = False,
                    modules = self.__modules)
        else:
            raise ValueError('Config error: not supported [platform] type {}'\
                    .format(platform_type))

        logging.debug('%14s - Checking target connection...', 'Target')
        logging.debug('%14s - Target info:', 'Target')
        logging.debug('%14s -       ABI: %s', 'Target', self.target.abi)
        logging.debug('%14s -      CPUs: %s', 'Target', self.target.cpuinfo)
        logging.debug('%14s -  Clusters: %s', 'Target', self.target.core_clusters)

        logging.info('%14s - Initializing target workdir:', 'Target')
        logging.info('%14s -    %s', 'Target', self.target.working_directory)
        tools_to_install = []
        if self.__tools:
            for tool in self.__tools:
                binary = '{}/tools/scripts/{}'.format(basepath, tool)
                if not os.path.isfile(binary):
                    binary = '{}/tools/{}/{}'\
                            .format(basepath, self.target.abi, tool)
                tools_to_install.append(binary)
        self.target.setup(tools_to_install)

        # Verify that all the required modules have been initialized
        for module in self.__modules:
            logging.debug('%14s - Check for module [%s]...', 'Target', module)
            if not hasattr(self.target, module):
                logging.warning('%14s - Unable to initialize [%s] module',
                        'Target', module)
                logging.error('%14s - Fix your target kernel configuration or '
                        'disable module from configuration', 'Target')
                raise RuntimeError('Failed to initialized [{}] module, '
                        'update your kernel or test configurations'.format(module))
Example #2
0
    def _init_target(self, force = False):

        if not force and self.target is not None:
            return self.target

        self.__connection_settings = {}

        # Configure username
        if 'username' in self.conf:
            self.__connection_settings['username'] = self.conf['username']
        else:
            self.__connection_settings['username'] = USERNAME_DEFAULT

        # Configure password or SSH keyfile
        if 'keyfile' in self.conf:
            self.__connection_settings['keyfile'] = self.conf['keyfile']
        elif 'password' in self.conf:
            self.__connection_settings['password'] = self.conf['password']
        else:
            self.__connection_settings['password'] = PASSWORD_DEFAULT

        # Configure port
        if 'port' in self.conf:
            self.__connection_settings['port'] = self.conf['port']

        # Configure the host IP/MAC address
        if 'host' in self.conf:
            try:
                if ':' in self.conf['host']:
                    (self.mac, self.ip) = self.resolv_host(self.conf['host'])
                else:
                    self.ip = self.conf['host']
                self.__connection_settings['host'] = self.ip
            except KeyError:
                raise ValueError('Config error: missing [host] parameter')

        try:
            platform_type = self.conf['platform']
        except KeyError:
            raise ValueError('Config error: missing [platform] parameter')

        if platform_type.lower() == 'android':
            self.ANDROID_HOME = self.conf.get('ANDROID_HOME',
                                              self.ANDROID_HOME)
            if self.ANDROID_HOME:
                self._adb = os.path.join(self.ANDROID_HOME,
                                         'platform-tools', 'adb')
                self._fastboot = os.path.join(self.ANDROID_HOME,
                                              'platform-tools', 'fastboot')
                os.environ['ANDROID_HOME'] = self.ANDROID_HOME
                os.environ['CATAPULT_HOME'] = self.CATAPULT_HOME
            else:
                raise RuntimeError('Android SDK not found, ANDROID_HOME must be defined!')

            self._log.info('External tools using:')
            self._log.info('   ANDROID_HOME: %s', self.ANDROID_HOME)
            self._log.info('   CATAPULT_HOME: %s', self.CATAPULT_HOME)

            if not os.path.exists(self._adb):
                raise RuntimeError('\nADB binary not found\n\t{}\ndoes not exists!\n\n'
                                   'Please configure ANDROID_HOME to point to '
                                   'a valid Android SDK installation folder.'\
                                   .format(self._adb))

        ########################################################################
        # Board configuration
        ########################################################################

        # Setup board default if not specified by configuration
        self.nrg_model = None
        platform = None
        self.__modules = ['cpufreq', 'cpuidle']
        if 'board' not in self.conf:
            self.conf['board'] = 'UNKNOWN'

        # Initialize TC2 board
        if self.conf['board'].upper() == 'TC2':
            platform = devlib.platform.arm.TC2()
            self.__modules = ['bl', 'hwmon', 'cpufreq']

        # Initialize JUNO board
        elif self.conf['board'].upper() in ('JUNO', 'JUNO2'):
            platform = devlib.platform.arm.Juno()
            self.nrg_model = juno_energy
            self.__modules = ['bl', 'hwmon', 'cpufreq']

        # Initialize OAK board
        elif self.conf['board'].upper() == 'OAK':
            platform = Platform(model='MT8173')
            self.__modules = ['bl', 'cpufreq']

        # Initialized HiKey board
        elif self.conf['board'].upper() == 'HIKEY':
            self.nrg_model = hikey_energy
            self.__modules = [ "cpufreq", "cpuidle" ]
            platform = Platform(model='hikey')

        # Initialize HiKey960 board
        elif self.conf['board'].upper() == 'HIKEY960':
            self.__modules = ['bl', 'cpufreq', 'cpuidle']
            platform = Platform(model='hikey960')

        # Initialize Pixel phone
        elif self.conf['board'].upper() == 'PIXEL':
            self.nrg_model = pixel_energy
            self.__modules = ['bl', 'cpufreq']
            platform = Platform(model='pixel')

        # Initialize gem5 platform
        elif self.conf['board'].upper() == 'GEM5':
            self.nrg_model = None
            self.__modules=['cpufreq']
            platform = self._init_target_gem5()

        elif self.conf['board'] != 'UNKNOWN':
            # Initilize from platform descriptor (if available)
            board = self._load_board(self.conf['board'])
            if board:
                core_names=board['cores']
                platform = Platform(
                    model=self.conf['board'],
                    core_names=core_names,
                    core_clusters = self._get_clusters(core_names),
                    big_core=board.get('big_core', None)
                )
                if 'modules' in board:
                    self.__modules = board['modules']

        ########################################################################
        # Modules configuration
        ########################################################################

        modules = set(self.__modules)

        # Refine modules list based on target.conf
        modules.update(self.conf.get('modules', []))
        # Merge tests specific modules
        modules.update(self.test_conf.get('modules', []))

        remove_modules = set(self.conf.get('exclude_modules', []) +
                             self.test_conf.get('exclude_modules', []))
        modules.difference_update(remove_modules)

        self.__modules = list(modules)
        self._log.info('Devlib modules to load: %s', self.__modules)

        ########################################################################
        # Devlib target setup (based on target.config::platform)
        ########################################################################

        # If the target is Android, we need just (eventually) the device
        if platform_type.lower() == 'android':
            self.__connection_settings = None
            device = 'DEFAULT'

            # Workaround for ARM-software/devlib#225
            if not self.workdir:
                self.workdir = '/data/local/tmp/devlib-target'

            if 'device' in self.conf:
                device = self.conf['device']
                self.__connection_settings = {'device' : device}
            elif 'host' in self.conf:
                host = self.conf['host']
                port = '5555'
                if 'port' in self.conf:
                    port = str(self.conf['port'])
                device = '{}:{}'.format(host, port)
                self.__connection_settings = {'device' : device}
            self._log.info('Connecting Android target [%s]', device)
        else:
            self._log.info('Connecting %s target:', platform_type)
            for key in self.__connection_settings:
                self._log.info('%10s : %s', key,
                               self.__connection_settings[key])

        self._log.info('Connection settings:')
        self._log.info('   %s', self.__connection_settings)

        if platform_type.lower() == 'linux':
            self._log.debug('Setup LINUX target...')
            if "host" not in self.__connection_settings:
                raise ValueError('Missing "host" param in Linux target conf')

            self.target = devlib.LinuxTarget(
                    platform = platform,
                    connection_settings = self.__connection_settings,
                    working_directory = self.workdir,
                    load_default_modules = False,
                    modules = self.__modules)
        elif platform_type.lower() == 'android':
            self._log.debug('Setup ANDROID target...')
            self.target = devlib.AndroidTarget(
                    platform = platform,
                    connection_settings = self.__connection_settings,
                    working_directory = self.workdir,
                    load_default_modules = False,
                    modules = self.__modules)
        elif platform_type.lower() == 'host':
            self._log.debug('Setup HOST target...')
            self.target = devlib.LocalLinuxTarget(
                    platform = platform,
                    working_directory = self.workdir,
                    load_default_modules = False,
                    modules = self.__modules,
                    connection_settings = {'unrooted': True})
        else:
            raise ValueError('Config error: not supported [platform] type {}'\
                    .format(platform_type))

        self._log.debug('Checking target connection...')
        self._log.debug('Target info:')
        self._log.debug('      ABI: %s', self.target.abi)
        self._log.debug('     CPUs: %s', self.target.cpuinfo)
        self._log.debug(' Clusters: %s', self.target.core_clusters)

        self._log.info('Initializing target workdir:')
        self._log.info('   %s', self.target.working_directory)

        self.target.setup()
        self.install_tools(self.__tools)

        # Verify that all the required modules have been initialized
        for module in self.__modules:
            self._log.debug('Check for module [%s]...', module)
            if not hasattr(self.target, module):
                self._log.warning('Unable to initialize [%s] module', module)
                self._log.error('Fix your target kernel configuration or '
                                'disable module from configuration')
                raise RuntimeError('Failed to initialized [{}] module, '
                        'update your kernel or test configurations'.format(module))

        if not self.nrg_model:
            try:
                self._log.info('Attempting to read energy model from target')
                self.nrg_model = EnergyModel.from_target(self.target)
            except (TargetError, RuntimeError, ValueError) as e:
                self._log.error("Couldn't read target energy model: %s", e)
Example #3
0
    def _init_target(self, force=False):

        if not force and self.target is not None:
            return self.target

        self.__connection_settings = {}

        # Configure username
        if 'username' in self.conf:
            self.__connection_settings['username'] = self.conf['username']
        else:
            self.__connection_settings['username'] = USERNAME_DEFAULT

        # Configure password or SSH keyfile
        if 'keyfile' in self.conf:
            self.__connection_settings['keyfile'] = self.conf['keyfile']
        elif 'password' in self.conf:
            self.__connection_settings['password'] = self.conf['password']
        else:
            self.__connection_settings['password'] = PASSWORD_DEFAULT

        # Configure the host IP/MAC address
        if 'host' in self.conf:
            try:
                if ':' in self.conf['host']:
                    (self.mac, self.ip) = self.resolv_host(self.conf['host'])
                else:
                    self.ip = self.conf['host']
                self.__connection_settings['host'] = self.ip
            except KeyError:
                raise ValueError('Config error: missing [host] parameter')

        try:
            platform_type = self.conf['platform']
        except KeyError:
            raise ValueError('Config error: missing [platform] parameter')

        # Setup board default if not specified by configuration
        if 'board' not in self.conf:
            self.conf['board'] = 'UNKNOWN'

        # Initialize a specific board (if known)
        if self.conf['board'].upper() == 'TC2':
            platform = devlib.platform.arm.TC2()
        elif self.conf['board'].upper() == 'JUNO':
            platform = devlib.platform.arm.Juno()
        elif self.conf['board'].upper() == 'OAK':
            platform = Platform(model='MT8173')
        else:
            platform = None

        # If the target is Android, we need just (eventually) the device
        if platform_type.lower() == 'android':
            self.__connection_settings = None
            if 'device' in self.conf:
                self.__connection_settings['device'] = self.conf['device']
            logging.info(r'%14s - Connecing Android target [%s]', 'Target',
                         self.__connection_settings or 'DEFAULT')
        else:
            logging.info(r'%14s - Connecing %s target with: %s', 'Target',
                         platform_type, self.__connection_settings)

        if platform_type.lower() == 'linux':
            logging.debug('%14s - Setup LINUX target...', 'Target')
            self.target = devlib.LinuxTarget(
                platform=platform,
                connection_settings=self.__connection_settings,
                load_default_modules=False,
                modules=self.__modules)
        elif platform_type.lower() == 'android':
            logging.debug('%14s - Setup ANDROID target...', 'Target')
            self.target = devlib.AndroidTarget(
                platform=platform,
                connection_settings=self.__connection_settings,
                load_default_modules=False,
                modules=self.__modules)
        elif platform_type.lower() == 'host':
            logging.debug('%14s - Setup HOST target...', 'Target')
            self.target = devlib.LocalLinuxTarget(platform=platform,
                                                  load_default_modules=False,
                                                  modules=self.__modules)
        else:
            raise ValueError('Config error: not supported [platform] type {}'\
                    .format(platform_type))

        logging.debug('%14s - Checking target connection...', 'Target')
        logging.debug('%14s - Target info:', 'Target')
        logging.debug('%14s -       ABI: %s', 'Target', self.target.abi)
        logging.debug('%14s -      CPUs: %s', 'Target', self.target.cpuinfo)
        logging.debug('%14s -  Clusters: %s', 'Target',
                      self.target.core_clusters)

        # Ensure rootfs is RW mounted
        self.target.execute('mount -o remount,rw /', as_root=True)

        # Verify that all the required modules have been initialized
        for module in self.__modules:
            logging.debug('%14s - Check for module [%s]...', 'Target', module)
            if not hasattr(self.target, module):
                logging.warning('%14s - Unable to initialize [%s] module',
                                'Target', module)
                logging.error(
                    '%14s - Fix your target kernel configuration or '
                    'disable module from configuration', 'Target')
                raise RuntimeError(
                    'Failed to initialized [{}] module, '
                    'update your kernel or test configurations'.format(module))

        logging.info('%14s - Initializing target workdir [%s]', 'Target',
                     self.target.working_directory)
        tools_to_install = []
        if self.__tools:
            for tool in self.__tools:
                binary = '{}/tools/scripts/{}'.format(basepath, tool)
                if not os.path.isfile(binary):
                    binary = '{}/tools/{}/{}'\
                            .format(basepath, self.target.abi, tool)
                tools_to_install.append(binary)
        self.target.setup(tools_to_install)