scripts/kconfig/tests/conftest.py
Source file repositories/reference/linux-study-clean/scripts/kconfig/tests/conftest.py
File Facts
- System
- Linux kernel
- Corpus path
scripts/kconfig/tests/conftest.py- Extension
.py- Size
- 11277 bytes
- Lines
- 315
- Domain
- Support Tooling And Documentation
- Bucket
- scripts
- Inferred role
- Support Tooling And Documentation: scripts
- Status
- atlas-only
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
- No top-level syscall, struct, function, initcall, or export declaration detected by the generator.
Annotated Snippet
# SPDX-License-Identifier: GPL-2.0
#
# Copyright (C) 2018 Masahiro Yamada <yamada.masahiro@socionext.com>
#
"""
Kconfig unit testing framework.
This provides fixture functions commonly used from test files.
"""
import os
import pytest
import shutil
import subprocess
import tempfile
CONF_PATH = os.path.abspath(os.path.join('scripts', 'kconfig', 'conf'))
class Conf:
"""Kconfig runner and result checker.
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'))
ps = subprocess.Popen(command,
stdin=subprocess.PIPE,
Annotation
- Atlas domain: Support Tooling And Documentation / scripts.
- Implementation status: atlas-only.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.