def test_not_subset_throw_exception(self): supersetConfig = kunit_config.Kconfig() subsetConfig = kunit_config.Kconfig() subsetConfig.add_entry(kunit_config.KconfigEntry('TEST','y')) with self.assertRaises(kunit_kernel.ConfigError): kunit_kernel.throw_error_if_not_subset(supersetConfig, subsetConfig)
def test_is_subset_of(self): kconfig0 = kunit_config.Kconfig() self.assertTrue(kconfig0.is_subset_of(kconfig0)) kconfig1 = kunit_config.Kconfig() kconfig1.add_entry(kunit_config.KconfigEntry('TEST', 'y')) self.assertTrue(kconfig1.is_subset_of(kconfig1)) self.assertTrue(kconfig0.is_subset_of(kconfig1)) self.assertFalse(kconfig1.is_subset_of(kconfig0))
def test_read_from_file(self): kconfig = kunit_config.Kconfig() kconfig_path = test_data_path('test_read_from_file.kconfig') kconfig.read_from_file(kconfig_path) expected_kconfig = kunit_config.Kconfig() expected_kconfig.add_entry(kunit_config.KconfigEntry('UML', 'y')) expected_kconfig.add_entry(kunit_config.KconfigEntry('MMU', 'y')) expected_kconfig.add_entry(kunit_config.KconfigEntry('TEST', 'y')) expected_kconfig.add_entry( kunit_config.KconfigEntry('EXAMPLE_TEST', 'y')) expected_kconfig.add_entry(kunit_config.KconfigEntry('MK8', 'n')) self.assertEqual(kconfig.entries(), expected_kconfig.entries())
def __init__(self, build_dir: str, load_config=True, kunitconfig_path='') -> None: signal.signal(signal.SIGINT, self.signal_handler) self._ops = LinuxSourceTreeOperations() if not load_config: return if kunitconfig_path: if os.path.isdir(kunitconfig_path): kunitconfig_path = os.path.join(kunitconfig_path, KUNITCONFIG_PATH) if not os.path.exists(kunitconfig_path): raise ConfigError( f'Specified kunitconfig ({kunitconfig_path}) does not exist' ) else: kunitconfig_path = get_kunitconfig_path(build_dir) if not os.path.exists(kunitconfig_path): shutil.copyfile(DEFAULT_KUNITCONFIG_PATH, kunitconfig_path) self._kconfig = kunit_config.Kconfig() self._kconfig.read_from_file(kunitconfig_path)
def __init__(self, build_dir: str, load_config=True, kunitconfig_path='', arch=None, cross_compile=None, qemu_config_path=None) -> None: signal.signal(signal.SIGINT, self.signal_handler) if qemu_config_path: self._arch, self._ops = get_source_tree_ops_from_qemu_config( qemu_config_path, cross_compile) else: self._arch = 'um' if arch is None else arch self._ops = get_source_tree_ops(self._arch, cross_compile) if not load_config: return if kunitconfig_path: if os.path.isdir(kunitconfig_path): kunitconfig_path = os.path.join(kunitconfig_path, KUNITCONFIG_PATH) if not os.path.exists(kunitconfig_path): raise ConfigError( f'Specified kunitconfig ({kunitconfig_path}) does not exist' ) else: kunitconfig_path = get_kunitconfig_path(build_dir) if not os.path.exists(kunitconfig_path): shutil.copyfile(DEFAULT_KUNITCONFIG_PATH, kunitconfig_path) self._kconfig = kunit_config.Kconfig() self._kconfig.read_from_file(kunitconfig_path)
def get_parsed_kunitconfig( build_dir: str, kunitconfig_paths: Optional[List[str]] = None) -> kunit_config.Kconfig: if not kunitconfig_paths: path = get_kunitconfig_path(build_dir) if not os.path.exists(path): shutil.copyfile(DEFAULT_KUNITCONFIG_PATH, path) return kunit_config.parse_file(path) merged = kunit_config.Kconfig() for path in kunitconfig_paths: if os.path.isdir(path): path = os.path.join(path, KUNITCONFIG_PATH) if not os.path.exists(path): raise ConfigError(f'Specified kunitconfig ({path}) does not exist') partial = kunit_config.parse_file(path) diff = merged.conflicting_options(partial) if diff: diff_str = '\n\n'.join(f'{a}\n vs from {path}\n{b}' for a, b in diff) raise ConfigError( f'Multiple values specified for {len(diff)} options in kunitconfig:\n{diff_str}' ) merged.merge_in_entries(partial) return merged
def test_read_from_file(self): kconfig = kunit_config.Kconfig() kconfig_path = get_absolute_path( 'test_data/test_read_from_file.kconfig') kconfig.read_from_file(kconfig_path) expected_kconfig = kunit_config.Kconfig() expected_kconfig.add_entry(kunit_config.KconfigEntry('CONFIG_UML=y')) expected_kconfig.add_entry(kunit_config.KconfigEntry('CONFIG_MMU=y')) expected_kconfig.add_entry(kunit_config.KconfigEntry('CONFIG_TEST=y')) expected_kconfig.add_entry( kunit_config.KconfigEntry('CONFIG_EXAMPLE_TEST=y')) expected_kconfig.add_entry( kunit_config.KconfigEntry('# CONFIG_MK8 is not set')) self.assertEqual(kconfig.entries(), expected_kconfig.entries())
def test_kconfig_add(self): want_kconfig = kunit_config.Kconfig() want_kconfig.add_entry('NOT_REAL', 'y') tree = kunit_kernel.LinuxSourceTree('', kconfig_add=['CONFIG_NOT_REAL=y']) self.assertTrue(want_kconfig.is_subset_of(tree._kconfig), msg=tree._kconfig)
def test_write_to_file(self): kconfig_path = os.path.join(test_tmpdir, '.config') expected_kconfig = kunit_config.Kconfig() expected_kconfig.add_entry(kunit_config.KconfigEntry('UML', 'y')) expected_kconfig.add_entry(kunit_config.KconfigEntry('MMU', 'y')) expected_kconfig.add_entry(kunit_config.KconfigEntry('TEST', 'y')) expected_kconfig.add_entry( kunit_config.KconfigEntry('EXAMPLE_TEST', 'y')) expected_kconfig.add_entry(kunit_config.KconfigEntry('MK8', 'n')) expected_kconfig.write_to_file(kconfig_path) actual_kconfig = kunit_config.Kconfig() actual_kconfig.read_from_file(kconfig_path) self.assertEqual(actual_kconfig.entries(), expected_kconfig.entries())
def test_write_to_file(self): kconfig_path = os.path.join(test_tmpdir, '.config') expected_kconfig = kunit_config.Kconfig() expected_kconfig.add_entry(kunit_config.KconfigEntry('CONFIG_UML=y')) expected_kconfig.add_entry(kunit_config.KconfigEntry('CONFIG_MMU=y')) expected_kconfig.add_entry(kunit_config.KconfigEntry('CONFIG_TEST=y')) expected_kconfig.add_entry( kunit_config.KconfigEntry('CONFIG_EXAMPLE_TEST=y')) expected_kconfig.add_entry( kunit_config.KconfigEntry('# CONFIG_MK8 is not set')) expected_kconfig.write_to_file(kconfig_path) actual_kconfig = kunit_config.Kconfig() actual_kconfig.read_from_file(kconfig_path) self.assertEqual(actual_kconfig.entries(), expected_kconfig.entries())
def validate_config(self, build_dir): kconfig_path = get_kconfig_path(build_dir) validated_kconfig = kunit_config.Kconfig() validated_kconfig.read_from_file(kconfig_path) if not self._kconfig.is_subset_of(validated_kconfig): invalid = self._kconfig.entries() - validated_kconfig.entries() message = 'Provided Kconfig is not contained in validated .config. Following fields found in kunitconfig, ' \ 'but not in .config: %s' % ( ', '.join([str(e) for e in invalid]) ) logging.error(message) return False return True
def build_um_kernel(self, jobs, build_dir): try: self._ops.make_olddefconfig(build_dir) self._ops.make(jobs, build_dir) except (ConfigError, BuildError) as e: logging.error(e) return False used_kconfig = kunit_config.Kconfig() used_kconfig.read_from_file(get_kconfig_path(build_dir)) if not self._kconfig.is_subset_of(used_kconfig): logging.error('Provided Kconfig is not contained in final config!') return False return True
def build_config(self): self._kconfig.write_to_file(KCONFIG_PATH) try: self._ops.make_olddefconfig() except ConfigError as e: logging.error(e) return False validated_kconfig = kunit_config.Kconfig() validated_kconfig.read_from_file(KCONFIG_PATH) if not self._kconfig.is_subset_of(validated_kconfig): logging.error( 'Provided Kconfig is not contained in validated .config!') return False return True
def build_reconfig(self): """Creates a new .config if it is not a subset of the kunitconfig.""" if os.path.exists(KCONFIG_PATH): existing_kconfig = kunit_config.Kconfig() existing_kconfig.read_from_file(KCONFIG_PATH) if not self._kconfig.is_subset_of(existing_kconfig): print('Regenerating .config ...') os.remove(KCONFIG_PATH) return self.build_config() else: return ConfigResult(ConfigStatus.SUCCESS, 'Already built.') else: print('Generating .config ...') return self.build_config()
def __init__(self, build_dir: str, load_config=True, defconfig=DEFAULT_KUNITCONFIG_PATH) -> None: signal.signal(signal.SIGINT, self.signal_handler) self._ops = LinuxSourceTreeOperations() if not load_config: return kunitconfig_path = get_kunitconfig_path(build_dir) if not os.path.exists(kunitconfig_path): shutil.copyfile(defconfig, kunitconfig_path) self._kconfig = kunit_config.Kconfig() self._kconfig.read_from_file(kunitconfig_path)
def build_reconfig(self, build_dir): """Creates a new .config if it is not a subset of the .kunitconfig.""" kconfig_path = get_kconfig_path(build_dir) if os.path.exists(kconfig_path): existing_kconfig = kunit_config.Kconfig() existing_kconfig.read_from_file(kconfig_path) if not self._kconfig.is_subset_of(existing_kconfig): print('Regenerating .config ...') os.remove(kconfig_path) return self.build_config(build_dir) else: return True else: print('Generating .config ...') return self.build_config(build_dir)
def build_config(self): self._kconfig.write_to_file(KCONFIG_PATH) try: self._ops.make_olddefconfig() except ConfigError as e: logging.error(e) return ConfigResult(ConfigStatus.FAILURE, str(e)) validated_kconfig = kunit_config.Kconfig() validated_kconfig.read_from_file(KCONFIG_PATH) try: throw_error_if_not_subset(expected_subset=self._kconfig, expected_superset=validated_kconfig) except ConfigError as e: logging.error(e) return ConfigResult(ConfigStatus.FAILURE, str(e)) return ConfigResult(ConfigStatus.SUCCESS, 'Build config!')
def build_um_kernel(self, jobs): try: self._ops.make_olddefconfig() self._ops.make(jobs) except (ConfigError, BuildError) as e: logging.error(e) return BuildResult(BuildStatus.FAILURE, str(e)) used_kconfig = kunit_config.Kconfig() used_kconfig.read_from_file(KCONFIG_PATH) try: throw_error_if_not_subset(expected_subset=self._kconfig, expected_superset=used_kconfig) except ConfigError as e: logging.error(e) return ConfigResult(ConfigStatus.FAILURE, str(e)) return BuildResult(BuildStatus.SUCCESS, 'Built kernel!')
def test_multiple_kunitconfig(self): want_kconfig = kunit_config.Kconfig() want_kconfig.add_entry('KUNIT', 'y') want_kconfig.add_entry('KUNIT_TEST', 'm') with tempfile.TemporaryDirectory('') as dir: other = os.path.join(dir, 'otherkunitconfig') with open(os.path.join(dir, '.kunitconfig'), 'w') as f: f.write('CONFIG_KUNIT=y') with open(other, 'w') as f: f.write('CONFIG_KUNIT_TEST=m') pass tree = kunit_kernel.LinuxSourceTree('', kunitconfig_paths=[dir, other]) self.assertTrue(want_kconfig.is_subset_of(tree._kconfig), msg=tree._kconfig)
def test_build_reconfig_add_config_line(self): tempConfig = tempfile.NamedTemporaryFile(delete=False, mode="w+") kconfig = kunit_config.Kconfig() operations = TestLinuxSourceTreeOperationsAddLine(tempConfig.name) with mock.patch.object(kunit_kernel, 'KCONFIG_PATH', tempConfig.name): tree = kunit_kernel.LinuxSourceTree(kconfig_provider = TestConfigProvider(kconfig), linux_build_operations = operations) tempConfig.write(str('CONFIG_TEST=n\nCONFIG_MMU=y\n')) tempConfig.seek(0) returnValue = tree.build_reconfig() self.assertEquals(returnValue.status, kunit_kernel.ConfigStatus.SUCCESS, returnValue.info)
def build_config(self, build_dir): kconfig_path = get_kconfig_path(build_dir) if build_dir and not os.path.exists(build_dir): os.mkdir(build_dir) self._kconfig.write_to_file(kconfig_path) try: self._ops.make_olddefconfig(build_dir) except ConfigError as e: logging.error(e) return False validated_kconfig = kunit_config.Kconfig() validated_kconfig.read_from_file(kconfig_path) if not self._kconfig.is_subset_of(validated_kconfig): logging.error( 'Provided Kconfig is not contained in validated .config!') return False return True
def __init__(self): self._kconfig = kunit_config.Kconfig() self._kconfig.read_from_file(KUNITCONFIG_PATH) self._ops = LinuxSourceTreeOperations()
def test_not_subset_no_exception(self): subsetConfig = kunit_config.Kconfig() supersetConfig = kunit_config.Kconfig() supersetConfig.add_entry(kunit_config.KconfigEntry('TEST','y')) kunit_kernel.throw_error_if_not_subset(supersetConfig, subsetConfig)
def read_kunitconfig(self, build_dir): kunitconfig_path = get_kunitconfig_path(build_dir) self._kconfig = kunit_config.Kconfig() self._kconfig.read_from_file(kunitconfig_path)
def make_arch_qemuconfig(self, base_kunitconfig: kunit_config.Kconfig) -> None: kconfig = kunit_config.Kconfig() kconfig.parse_from_string(self._kconfig) base_kunitconfig.merge_in_entries(kconfig)
def __init__(self): self._kconfig = kunit_config.Kconfig() self._kconfig.read_from_file(kunitconfig_path) self._ops = LinuxSourceTreeOperations() signal.signal(signal.SIGINT, self.signal_handler)
def __init__(self): self._kconfig = kunit_config.Kconfig() self._kconfig.read_from_file(kunitconfig_path) self._ops = LinuxSourceTreeOperations()