kunit_kernel.py (3f0a50f345f78183f6e9b39c2f45ca5dcaa511ca) | kunit_kernel.py (0453f984a7b9458f0e469afb039f2841308b1bef) |
---|---|
1# SPDX-License-Identifier: GPL-2.0 2# 3# Runs UML kernel, collects output, and handles errors. 4# 5# Copyright (C) 2019, Google LLC. 6# Author: Felix Guo <felixguoxiuping@gmail.com> 7# Author: Brendan Higgins <brendanhiggins@google.com> 8 --- 24 unchanged lines hidden (view full) --- 33class ConfigError(Exception): 34 """Represents an error trying to configure the Linux kernel.""" 35 36 37class BuildError(Exception): 38 """Represents an error trying to build the Linux kernel.""" 39 40 | 1# SPDX-License-Identifier: GPL-2.0 2# 3# Runs UML kernel, collects output, and handles errors. 4# 5# Copyright (C) 2019, Google LLC. 6# Author: Felix Guo <felixguoxiuping@gmail.com> 7# Author: Brendan Higgins <brendanhiggins@google.com> 8 --- 24 unchanged lines hidden (view full) --- 33class ConfigError(Exception): 34 """Represents an error trying to configure the Linux kernel.""" 35 36 37class BuildError(Exception): 38 """Represents an error trying to build the Linux kernel.""" 39 40 |
41class LinuxSourceTreeOperations(object): | 41class LinuxSourceTreeOperations: |
42 """An abstraction over command line operations performed on a source tree.""" 43 44 def __init__(self, linux_arch: str, cross_compile: Optional[str]): 45 self._linux_arch = linux_arch 46 self._cross_compile = cross_compile 47 48 def make_mrproper(self) -> None: 49 try: 50 subprocess.check_output(['make', 'mrproper'], stderr=subprocess.STDOUT) 51 except OSError as e: 52 raise ConfigError('Could not call make command: ' + str(e)) 53 except subprocess.CalledProcessError as e: 54 raise ConfigError(e.output.decode()) 55 | 42 """An abstraction over command line operations performed on a source tree.""" 43 44 def __init__(self, linux_arch: str, cross_compile: Optional[str]): 45 self._linux_arch = linux_arch 46 self._cross_compile = cross_compile 47 48 def make_mrproper(self) -> None: 49 try: 50 subprocess.check_output(['make', 'mrproper'], stderr=subprocess.STDOUT) 51 except OSError as e: 52 raise ConfigError('Could not call make command: ' + str(e)) 53 except subprocess.CalledProcessError as e: 54 raise ConfigError(e.output.decode()) 55 |
56 def make_arch_qemuconfig(self, kconfig: kunit_config.Kconfig) -> None: | 56 def make_arch_qemuconfig(self, base_kunitconfig: kunit_config.Kconfig) -> None: |
57 pass 58 59 def make_allyesconfig(self, build_dir: str, make_options) -> None: 60 raise ConfigError('Only the "um" arch is supported for alltests') 61 62 def make_olddefconfig(self, build_dir: str, make_options) -> None: 63 command = ['make', 'ARCH=' + self._linux_arch, 'O=' + build_dir, 'olddefconfig'] 64 if self._cross_compile: --- 112 unchanged lines hidden (view full) --- 177 178def get_outfile_path(build_dir: str) -> str: 179 return os.path.join(build_dir, OUTFILE_PATH) 180 181def get_source_tree_ops(arch: str, cross_compile: Optional[str]) -> LinuxSourceTreeOperations: 182 config_path = os.path.join(QEMU_CONFIGS_DIR, arch + '.py') 183 if arch == 'um': 184 return LinuxSourceTreeOperationsUml(cross_compile=cross_compile) | 57 pass 58 59 def make_allyesconfig(self, build_dir: str, make_options) -> None: 60 raise ConfigError('Only the "um" arch is supported for alltests') 61 62 def make_olddefconfig(self, build_dir: str, make_options) -> None: 63 command = ['make', 'ARCH=' + self._linux_arch, 'O=' + build_dir, 'olddefconfig'] 64 if self._cross_compile: --- 112 unchanged lines hidden (view full) --- 177 178def get_outfile_path(build_dir: str) -> str: 179 return os.path.join(build_dir, OUTFILE_PATH) 180 181def get_source_tree_ops(arch: str, cross_compile: Optional[str]) -> LinuxSourceTreeOperations: 182 config_path = os.path.join(QEMU_CONFIGS_DIR, arch + '.py') 183 if arch == 'um': 184 return LinuxSourceTreeOperationsUml(cross_compile=cross_compile) |
185 elif os.path.isfile(config_path): | 185 if os.path.isfile(config_path): |
186 return get_source_tree_ops_from_qemu_config(config_path, cross_compile)[1] 187 188 options = [f[:-3] for f in os.listdir(QEMU_CONFIGS_DIR) if f.endswith('.py')] 189 raise ConfigError(arch + ' is not a valid arch, options are ' + str(sorted(options))) 190 191def get_source_tree_ops_from_qemu_config(config_path: str, 192 cross_compile: Optional[str]) -> Tuple[ 193 str, LinuxSourceTreeOperations]: --- 14 unchanged lines hidden (view full) --- 208 spec.loader.exec_module(config) 209 210 if not hasattr(config, 'QEMU_ARCH'): 211 raise ValueError('qemu_config module missing "QEMU_ARCH": ' + config_path) 212 params: qemu_config.QemuArchParams = config.QEMU_ARCH # type: ignore 213 return params.linux_arch, LinuxSourceTreeOperationsQemu( 214 params, cross_compile=cross_compile) 215 | 186 return get_source_tree_ops_from_qemu_config(config_path, cross_compile)[1] 187 188 options = [f[:-3] for f in os.listdir(QEMU_CONFIGS_DIR) if f.endswith('.py')] 189 raise ConfigError(arch + ' is not a valid arch, options are ' + str(sorted(options))) 190 191def get_source_tree_ops_from_qemu_config(config_path: str, 192 cross_compile: Optional[str]) -> Tuple[ 193 str, LinuxSourceTreeOperations]: --- 14 unchanged lines hidden (view full) --- 208 spec.loader.exec_module(config) 209 210 if not hasattr(config, 'QEMU_ARCH'): 211 raise ValueError('qemu_config module missing "QEMU_ARCH": ' + config_path) 212 params: qemu_config.QemuArchParams = config.QEMU_ARCH # type: ignore 213 return params.linux_arch, LinuxSourceTreeOperationsQemu( 214 params, cross_compile=cross_compile) 215 |
216class LinuxSourceTree(object): | 216class LinuxSourceTree: |
217 """Represents a Linux kernel source tree with KUnit tests.""" 218 219 def __init__( 220 self, 221 build_dir: str, 222 load_config=True, 223 kunitconfig_path='', 224 kconfig_add: Optional[List[str]]=None, --- 138 unchanged lines hidden (view full) --- 363 # Flush any leftover output to the file 364 output.write(process.stdout.read()) 365 output.close() 366 process.stdout.close() 367 368 waiter.join() 369 subprocess.call(['stty', 'sane']) 370 | 217 """Represents a Linux kernel source tree with KUnit tests.""" 218 219 def __init__( 220 self, 221 build_dir: str, 222 load_config=True, 223 kunitconfig_path='', 224 kconfig_add: Optional[List[str]]=None, --- 138 unchanged lines hidden (view full) --- 363 # Flush any leftover output to the file 364 output.write(process.stdout.read()) 365 output.close() 366 process.stdout.close() 367 368 waiter.join() 369 subprocess.call(['stty', 'sane']) 370 |
371 def signal_handler(self, sig, frame) -> None: | 371 def signal_handler(self, unused_sig, unused_frame) -> None: |
372 logging.error('Build interruption occurred. Cleaning console.') 373 subprocess.call(['stty', 'sane']) | 372 logging.error('Build interruption occurred. Cleaning console.') 373 subprocess.call(['stty', 'sane']) |