diff --git a/avocado/utils/linux_modules.py b/avocado/utils/linux_modules.py index 16baed8d18d5b4efde168a97db34282d6c2b2530..7da5a341e7d20acfc8a0863ae34d6ed07c869878 100644 --- a/avocado/utils/linux_modules.py +++ b/avocado/utils/linux_modules.py @@ -13,18 +13,31 @@ # # client/base_utils.py # Original author: Ross Brattain +# +# Copyright: 2016 IBM +# Authors : Praveen K Pandey """ -APIs to list and load/unload linux kernel modules. +Linux kernel modules APIs """ import re import logging +import platform from . import process LOG = logging.getLogger('avocado.test') +#: Config commented out or not set +NOT_SET = 0 + +#: Config compiled as loadable module (`=m`) +MODULE = 1 + +#: Config built-in to kernel (`=y`) +BUILTIN = 2 + def load_module(module_name): # Checks if a module has already been loaded @@ -153,3 +166,32 @@ def module_is_loaded(module_name): def get_loaded_modules(): lsmod_output = process.system_output('/sbin/lsmod').splitlines()[1:] return [line.split(None, 1)[0] for line in lsmod_output] + + +def check_kernel_config(config_name): + """ + Reports the configuration of $config_name of the current kernel + + :param config_name: Name of kernel config to search + :type config_name: str + :return: Config status in running kernel (NOT_SET, BUILTIN, MODULE) + :rtype: int + """ + + kernel_version = platform.uname()[2] + + config_file = '/boot/config-' + kernel_version + for line in open(config_file, 'r'): + line = line.split('=') + + if len(line) != 2: + continue + + config = line[0].strip() + if config == config_name: + option = line[1].strip() + if option == "m": + return MODULE + else: + return BUILTIN + return NOT_SET