This class provides methods to run text-based interface of Kconfig
(scripts/kconfig/conf) and retrieve the resulted configuration,
stdout, and stderr. It also provides methods to compare those
results with expectations. """
def __init__(self, request): """Create a new Conf instance.
request: object to introspect the requesting test module """ # the directory of the test being run
self._test_dir = os.path.dirname(str(request.fspath))
# runners def _run_conf(self, mode, dot_config=None, out_file='.config',
interactive=False, in_keys=None, extra_env={}): """Run text-based Kconfig executable and save the result.
mode: input mode option (--oldaskconfig, --defconfig=<file> etc.)
dot_config: .config file to use for configuration base
out_file: file name to contain the output config data
interactive: flag to specify the interactive mode
in_keys: key inputs for interactive modes
extra_env: additional environments
returncode: exit status of the Kconfig executable """
command = [CONF_PATH, mode, 'Kconfig']
# Override 'srctree' environment to make the test as the top directory
extra_env['srctree'] = self._test_dir
# Clear KCONFIG_DEFCONFIG_LIST to keep unit tests from being affected # by the user's environment.
extra_env['KCONFIG_DEFCONFIG_LIST'] = ''
# Run Kconfig in a temporary directory. # This directory is automatically removed when done. with tempfile.TemporaryDirectory() as temp_dir:
# if .config is given, copy it to the working directory if dot_config:
shutil.copyfile(os.path.join(self._test_dir, dot_config),
os.path.join(temp_dir, '.config'))
# If input key sequence is given, feed it to stdin. if in_keys:
ps.stdin.write(in_keys.encode('utf-8'))
while ps.poll() isNone: # For interactive modes such as oldaskconfig, oldconfig, # send 'Enter' key until the program finishes. if interactive:
ps.stdin.write(b'\n')
# Retrieve the resulted config data only when .config is supposed # to exist. If the command fails, the .config does not exist. # 'listnewconfig' does not produce .config in the first place. if self.retcode == 0 and out_file: with open(os.path.join(temp_dir, out_file)) as f:
self.config = f.read() else:
self.config = None
# Logging: # Pytest captures the following information by default. In failure # of tests, the captured log will be displayed. This will be useful to # figure out what has happened.
dot_config: .config file to use for configuration base (optional)
in_key: key inputs (optional)
returncode: exit status of the Kconfig executable """ return self._run_conf('--oldaskconfig', dot_config=dot_config,
interactive=True, in_keys=in_keys)
dot_config: .config file to use for configuration base (optional)
in_key: key inputs (optional)
returncode: exit status of the Kconfig executable """ return self._run_conf('--oldconfig', dot_config=dot_config,
interactive=True, in_keys=in_keys)
dot_config: .config file to use for configuration base (optional)
returncode: exit status of the Kconfig executable """ return self._run_conf('--olddefconfig', dot_config=dot_config)
def defconfig(self, defconfig): """Run defconfig.
defconfig: defconfig file for input
returncode: exit status of the Kconfig executable """
defconfig_path = os.path.join(self._test_dir, defconfig) return self._run_conf('--defconfig={}'.format(defconfig_path))
all_config: fragment config file for KCONFIG_ALLCONFIG (optional)
returncode: exit status of the Kconfig executable """ return self._allconfig('allyes', all_config)
all_config: fragment config file for KCONFIG_ALLCONFIG (optional)
returncode: exit status of the Kconfig executable """ return self._allconfig('allmod', all_config)
all_config: fragment config file for KCONFIG_ALLCONFIG (optional)
returncode: exit status of the Kconfig executable """ return self._allconfig('allno', all_config)
all_config: fragment config file for KCONFIG_ALLCONFIG (optional)
returncode: exit status of the Kconfig executable """ return self._allconfig('alldef', all_config)
all_config: fragment config file for KCONFIG_ALLCONFIG (optional)
seed: the seed for randconfig (optional)
returncode: exit status of the Kconfig executable """ if seed isnotNone:
extra_env = {'KCONFIG_SEED': hex(seed)} else:
extra_env = {}
dot_config: .config file for input
returncode: exit status of the Kconfig executable """ return self._run_conf('--savedefconfig', out_file='defconfig')
dot_config: .config file to use for configuration base (optional)
returncode: exit status of the Kconfig executable """ return self._run_conf('--listnewconfig', dot_config=dot_config,
out_file=None)
# checkers def _read_and_compare(self, compare, expected): """Compare the result with expectation.
compare: function to compare the result with expectation
expected: file that contains the expected data """ with open(os.path.join(self._test_dir, expected)) as f:
expected_data = f.read() return compare(self, expected_data)
def config_contains(self, expected): """Check if resulted configuration contains expected data.
expected: file that contains the expected data
returncode: Trueif result contains the expected data, False otherwise """ return self._contains('config', expected)
expected: file that contains the expected data
returncode: Trueif result matches the expected data, False otherwise """ return self._matches('config', expected)
def stdout_contains(self, expected): """Check if resulted stdout contains expected data.
expected: file that contains the expected data
returncode: Trueif result contains the expected data, False otherwise """ return self._contains('stdout', expected)
expected: file that contains the expected data
returncode: Trueif result matches the expected data, False otherwise """ return self._matches('stdout', expected)
def stderr_contains(self, expected): """Check if resulted stderr contains expected data.
expected: file that contains the expected data
returncode: Trueif result contains the expected data, False otherwise """ return self._contains('stderr', expected)
expected: file that contains the expected data
returncode: Trueif result matches the expected data, False otherwise """ return self._matches('stderr', expected)
@pytest.fixture(scope="module") def conf(request): """Create a Conf instance and provide it to test functions.""" return Conf(request)
Messung V0.5
¤ Dauer der Verarbeitung: 0.21 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.