Skip to content

Commit

Permalink
ci: compliance: Update Kconfig check
Browse files Browse the repository at this point in the history
Take into account the Kconfig symbols in tests and samples that are
defined using the logging template.

This avoid using the `UNDEF_KCONFIG_WHITELIST` for those symbols.

Update the list to remove the symbols that were added for that reason.

Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
  • Loading branch information
theob-pro authored and nashif committed Apr 13, 2024
1 parent 5518b0c commit 4a30aab
Showing 1 changed file with 37 additions and 9 deletions.
46 changes: 37 additions & 9 deletions scripts/ci/check_compliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,39 @@ def parse_kconfig(self, filename="Kconfig", hwm=None):
# Clean up the temporary directory
shutil.rmtree(kconfiglib_dir)

def get_logging_syms(self, kconf):
# Returns a set() with the names of the Kconfig symbols generated with
# logging template in samples/tests folders. The Kconfig symbols doesn't
# include `CONFIG_` and for each module declared there is one symbol
# per suffix created.

suffixes = [
"_LOG_LEVEL",
"_LOG_LEVEL_DBG",
"_LOG_LEVEL_ERR",
"_LOG_LEVEL_INF",
"_LOG_LEVEL_WRN",
"_LOG_LEVEL_OFF",
"_LOG_LEVEL_INHERIT",
"_LOG_LEVEL_DEFAULT",
]

# Warning: Needs to work with both --perl-regexp and the 're' module.
regex = r"^\s*(?:module\s*=\s*)([A-Z0-9_]+)\s*(?:#|$)"

# Grep samples/ and tests/ for symbol definitions
grep_stdout = git("grep", "-I", "-h", "--perl-regexp", regex, "--",
":samples", ":tests", cwd=ZEPHYR_BASE)

names = re.findall(regex, grep_stdout, re.MULTILINE)

kconf_syms = []
for name in names:
for suffix in suffixes:
kconf_syms.append(f"{name}{suffix}")

return set(kconf_syms)

def get_defined_syms(self, kconf):
# Returns a set() with the names of all defined Kconfig symbols (with no
# 'CONFIG_' prefix). This is complicated by samples and tests defining
Expand All @@ -582,8 +615,10 @@ def get_defined_syms(self, kconf):

# Symbols from the main Kconfig tree + grepped definitions from samples
# and tests
return set([sym.name for sym in kconf_syms]
+ re.findall(regex, grep_stdout, re.MULTILINE))
return set(
[sym.name for sym in kconf_syms]
+ re.findall(regex, grep_stdout, re.MULTILINE)
).union(self.get_logging_syms(kconf))

def check_top_menu_not_too_long(self, kconf):
"""
Expand Down Expand Up @@ -829,8 +864,6 @@ def check_no_undef_outside_kconfig(self, kconf):
"BOOT_SIGNATURE_TYPE_RSA", # MCUboot setting used by sysbuild
"BOOT_VALIDATE_SLOT0", # Used in (sysbuild-based) test
"BOOT_WATCHDOG_FEED", # Used in (sysbuild-based) test
"BTTESTER_LOG_LEVEL", # Used in tests/bluetooth/tester
"BTTESTER_LOG_LEVEL_DBG", # Used in tests/bluetooth/tester
"CDC_ACM_PORT_NAME_",
"CHRE", # Optional module
"CHRE_LOG_LEVEL_DBG", # Optional module
Expand Down Expand Up @@ -868,8 +901,6 @@ def check_no_undef_outside_kconfig(self, kconf):
"MCUBOOT_CLEANUP_ARM_CORE", # Used in (sysbuild-based) test
"MCUBOOT_SERIAL", # Used in (sysbuild-based) test/
# documentation
"MCUMGR_GRP_EXAMPLE", # Used in documentation
"MCUMGR_GRP_EXAMPLE_LOG_LEVEL", # Used in documentation
"MCUMGR_GRP_EXAMPLE_OTHER_HOOK", # Used in documentation
"MISSING",
"MODULES",
Expand All @@ -882,8 +913,6 @@ def check_no_undef_outside_kconfig(self, kconf):
"REG1",
"REG2",
"RIMAGE_SIGNING_SCHEMA", # Optional module
"SAMPLE_MODULE_LOG_LEVEL", # Used as an example in samples/subsys/logging
"SAMPLE_MODULE_LOG_LEVEL_DBG", # Used in tests/subsys/logging/log_api
"LOG_BACKEND_MOCK_OUTPUT_DEFAULT", #Referenced in tests/subsys/logging/log_syst
"LOG_BACKEND_MOCK_OUTPUT_SYST", #Referenced in testcase.yaml of log_syst test
"SEL",
Expand All @@ -897,7 +926,6 @@ def check_no_undef_outside_kconfig(self, kconf):
"SRAM2", # Referenced in a comment in samples/application_development
"STACK_SIZE", # Used as an example in the Kconfig docs
"STD_CPP", # Referenced in CMake comment
"TAGOIO_HTTP_POST_LOG_LEVEL", # Used as in samples/net/cloud/tagoio
"TEST1",
"TOOLCHAIN_ARCMWDT_SUPPORTS_THREAD_LOCAL_STORAGE", # The symbol is defined in the toolchain
# Kconfig which is sourced based on Zephyr
Expand Down

0 comments on commit 4a30aab

Please sign in to comment.