-
Notifications
You must be signed in to change notification settings - Fork 43
add: support Ubuntu/Debian kernel config sources #567
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -928,14 +928,71 @@ find_test_case_script_by_name() { | |
| # CONFIG_BAZ=m | ||
| # passes only when the exact expected value matches | ||
| # Logs PASS or FAIL for each config and returns 0 on success, 1 on first mismatch. | ||
|
|
||
| kernel_config_source() { | ||
| kcs_kver="$(uname -r 2>/dev/null)" | ||
|
|
||
| if [ -r /proc/config.gz ]; then | ||
| kcs_gz_ok=0 | ||
|
|
||
| if command -v gzip >/dev/null 2>&1; then | ||
| if gzip -t /proc/config.gz >/dev/null 2>&1; then | ||
| kcs_gz_ok=1 | ||
| fi | ||
| elif command -v zgrep >/dev/null 2>&1; then | ||
| # No gzip binary available to run "gzip -t" with; fall back to a | ||
| # lightweight decompression probe using zgrep itself. | ||
| if zgrep -m 1 -qE '^CONFIG_' /proc/config.gz 2>/dev/null; then | ||
| kcs_gz_ok=1 | ||
| fi | ||
| fi | ||
|
|
||
| if [ "$kcs_gz_ok" -eq 1 ]; then | ||
| printf '%s|%s\n' "/proc/config.gz" "gz" | ||
| return 0 | ||
| fi | ||
| fi | ||
|
|
||
| for kcs_cand in \ | ||
| "/boot/config-${kcs_kver}" \ | ||
| "/lib/modules/${kcs_kver}/build/.config" \ | ||
| "/usr/src/linux-headers-${kcs_kver}/.config" | ||
| do | ||
| if [ -n "$kcs_kver" ] && [ -r "$kcs_cand" ]; then | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Runner/utils/functestlib.sh:961 — Readability alone does not make a plain-text candidate usable. An empty or malformed /boot/config-* is selected permanently and blocks valid build/header fallbacks, causing every requested option to appear missing. Please validate that each candidate contains recognizable kernel-config records before returning it. |
||
| printf '%s|%s\n' "$kcs_cand" "plain" | ||
| return 0 | ||
| fi | ||
| done | ||
|
|
||
| return 1 | ||
| } | ||
|
|
||
| check_kernel_config() { | ||
| cfgs=$1 | ||
| kver="$(uname -r 2>/dev/null)" | ||
|
|
||
| if [ ! -r /proc/config.gz ]; then | ||
| log_fail "Kernel config source /proc/config.gz is not available" | ||
| cfg_info="$(kernel_config_source 2>/dev/null)" | ||
| if [ -z "$cfg_info" ]; then | ||
| log_fail "No readable/usable kernel config source found (checked /proc/config.gz [requires zgrep or gzip], /boot/config-${kver:-<unknown>}, /lib/modules/${kver:-<unknown>}/build/.config, /usr/src/linux-headers-${kver:-<unknown>}/.config)" | ||
| return 1 | ||
| fi | ||
|
|
||
| cfg_source="${cfg_info%%|*}" | ||
| cfg_format="${cfg_info#*|}" | ||
| cfg_is_gz=0 | ||
| [ "$cfg_format" = "gz" ] && cfg_is_gz=1 | ||
|
|
||
| if command -v detect_platform >/dev/null 2>&1; then | ||
| detect_platform >/dev/null 2>&1 || true | ||
| fi | ||
| cfg_os_family="${PLATFORM_OS_FAMILY:-unknown}" | ||
|
|
||
| if [ -n "${PLATFORM_OS_NAME:-}" ]; then | ||
| log_info "Using kernel config source: $cfg_source (OS: $PLATFORM_OS_NAME, family: $cfg_os_family)" | ||
| else | ||
| log_info "Using kernel config source: $cfg_source (family: $cfg_os_family)" | ||
| fi | ||
|
|
||
| for cfg in $cfgs; do | ||
| [ -n "$cfg" ] || continue | ||
|
|
||
|
|
@@ -952,20 +1009,23 @@ check_kernel_config() { | |
| ;; | ||
| esac | ||
|
|
||
| if command -v zgrep >/dev/null 2>&1; then | ||
| if zgrep -qE "$pattern" /proc/config.gz 2>/dev/null; then | ||
| log_pass "$pass_msg" | ||
| cfg_matched=0 | ||
|
|
||
| if [ "$cfg_is_gz" -eq 1 ]; then | ||
| if command -v zgrep >/dev/null 2>&1; then | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The source may have been validated with gzip -t, but this consumer switches to zgrep based only on command presence. A present but incompatible zgrep then causes false missing-config failures even though the validated gzip reader works. Please return the validated reader from kernel_config_source() or centralize config queries in one helper and use that reader consistently in both consumers. |
||
| zgrep -qE "$pattern" "$cfg_source" 2>/dev/null && cfg_matched=1 | ||
| else | ||
| log_fail "$fail_msg" | ||
| return 1 | ||
| gzip -dc "$cfg_source" 2>/dev/null | grep -qE "$pattern" && cfg_matched=1 | ||
| fi | ||
| else | ||
| if gzip -dc /proc/config.gz 2>/dev/null | grep -qE "$pattern"; then | ||
| log_pass "$pass_msg" | ||
| else | ||
| log_fail "$fail_msg" | ||
| return 1 | ||
| fi | ||
| grep -qE "$pattern" "$cfg_source" 2>/dev/null && cfg_matched=1 | ||
| fi | ||
|
|
||
| if [ "$cfg_matched" -eq 1 ]; then | ||
| log_pass "$pass_msg" | ||
| else | ||
| log_fail "$fail_msg" | ||
| return 1 | ||
| fi | ||
| done | ||
|
|
||
|
|
@@ -977,41 +1037,44 @@ check_kernel_config() { | |
| # Prints CONFIG_NAME=value from the running kernel configuration, including | ||
| # CONFIG_NAME=n for an explicitly disabled option. Returns 0 when found, 1 | ||
| # when unavailable or absent, and 3 when the name is omitted. | ||
| # | ||
| # Uses kernel_config_source() for source discovery, the same shared helper | ||
| # used by check_kernel_config(), so precedence and decompressor handling | ||
| # cannot drift between the two. | ||
| ############################################################################### | ||
| kernel_config_value() { | ||
| config_name="$1" | ||
| [ -n "$config_name" ] || return 3 | ||
|
|
||
| if [ -r /proc/config.gz ]; then | ||
| kcv_info="$(kernel_config_source 2>/dev/null)" | ||
| [ -n "$kcv_info" ] || return 1 | ||
|
|
||
| kcv_source="${kcv_info%%|*}" | ||
| kcv_format="${kcv_info#*|}" | ||
| kcv_is_gz=0 | ||
| [ "$kcv_format" = "gz" ] && kcv_is_gz=1 | ||
|
|
||
| if [ "$kcv_is_gz" -eq 1 ]; then | ||
| if command -v zgrep >/dev/null 2>&1; then | ||
| config_line=$(zgrep -m 1 -E "^${config_name}=" /proc/config.gz 2>/dev/null || true) | ||
| config_disabled=$(zgrep -m 1 -E "^# ${config_name} is not set$" /proc/config.gz 2>/dev/null || true) | ||
| kcv_line=$(zgrep -m 1 -E "^${config_name}=" "$kcv_source" 2>/dev/null || true) | ||
| kcv_disabled=$(zgrep -m 1 -E "^# ${config_name} is not set$" "$kcv_source" 2>/dev/null || true) | ||
| else | ||
| config_line=$(gzip -dc /proc/config.gz 2>/dev/null | grep -m 1 -E "^${config_name}=" || true) | ||
| config_disabled=$(gzip -dc /proc/config.gz 2>/dev/null | grep -m 1 -E "^# ${config_name} is not set$" || true) | ||
| kcv_line=$(gzip -dc "$kcv_source" 2>/dev/null | grep -m 1 -E "^${config_name}=" || true) | ||
| kcv_disabled=$(gzip -dc "$kcv_source" 2>/dev/null | grep -m 1 -E "^# ${config_name} is not set$" || true) | ||
| fi | ||
| else | ||
| kcv_line=$(grep -m 1 -E "^${config_name}=" "$kcv_source" 2>/dev/null || true) | ||
| kcv_disabled=$(grep -m 1 -E "^# ${config_name} is not set$" "$kcv_source" 2>/dev/null || true) | ||
| fi | ||
|
|
||
| if [ -n "$config_line" ]; then | ||
| printf '%s\n' "$config_line" | ||
| return 0 | ||
| fi | ||
| if [ -n "$config_disabled" ]; then | ||
| printf '%s=n\n' "$config_name" | ||
| return 0 | ||
| fi | ||
| if [ -n "$kcv_line" ]; then | ||
| printf '%s\n' "$kcv_line" | ||
| return 0 | ||
| fi | ||
|
|
||
| boot_config="/boot/config-$(uname -r 2>/dev/null)" | ||
| if [ -r "$boot_config" ]; then | ||
| config_line=$(grep -m 1 -E "^${config_name}=" "$boot_config" 2>/dev/null || true) | ||
| if [ -n "$config_line" ]; then | ||
| printf '%s\n' "$config_line" | ||
| return 0 | ||
| fi | ||
| if grep -q -E "^# ${config_name} is not set$" "$boot_config" 2>/dev/null; then | ||
| printf '%s=n\n' "$config_name" | ||
| return 0 | ||
| fi | ||
| if [ -n "$kcv_disabled" ]; then | ||
| printf '%s=n\n' "$config_name" | ||
| return 0 | ||
| fi | ||
|
|
||
| return 1 | ||
|
|
@@ -6795,6 +6858,8 @@ log_soc_info() { | |
| # PLATFORM_SOC_MACHINE, PLATFORM_SOC_ID, PLATFORM_SOC_FAMILY | ||
| # PLATFORM_DT_MODEL, PLATFORM_DT_COMPAT | ||
| # PLATFORM_OS_LIKE, PLATFORM_OS_NAME | ||
| # PLATFORM_OS_ID (lowercased /etc/os-release ID, e.g. ubuntu/debian/poky) | ||
| # PLATFORM_OS_FAMILY (normalized: ubuntu | debian | yocto | unknown) | ||
| # PLATFORM_TARGET, PLATFORM_MACHINE | ||
| ############################################################################### | ||
| detect_platform() { | ||
|
|
@@ -6841,9 +6906,16 @@ detect_platform() { | |
| fi | ||
|
|
||
| # --- OS (parse, do not source /etc/os-release) --- | ||
| PLATFORM_OS_ID="" | ||
| PLATFORM_OS_LIKE="" | ||
| PLATFORM_OS_NAME="" | ||
| PLATFORM_OS_FAMILY="unknown" | ||
| _os_cpe_name="" | ||
| if [ -r /etc/os-release ]; then | ||
| PLATFORM_OS_ID="$( | ||
| awk -F= '$1=="ID"{gsub(/"/,"",$2); print $2}' /etc/os-release 2>/dev/null | | ||
| tr '[:upper:]' '[:lower:]' | ||
| )" | ||
| PLATFORM_OS_LIKE="$( | ||
| awk -F= '$1=="ID_LIKE"{gsub(/"/,"",$2); print $2}' /etc/os-release 2>/dev/null | ||
| )" | ||
|
|
@@ -6855,7 +6927,44 @@ detect_platform() { | |
| PLATFORM_OS_NAME="$( | ||
| awk -F= '$1=="PRETTY_NAME"{gsub(/"/,"",$2); print $2}' /etc/os-release 2>/dev/null | ||
| )" | ||
| _os_cpe_name="$( | ||
| awk -F= '$1=="CPE_NAME"{gsub(/"/,"",$2); print $2}' /etc/os-release 2>/dev/null | | ||
| tr '[:upper:]' '[:lower:]' | ||
| )" | ||
| fi | ||
|
|
||
| _os_like_lc="$(printf '%s' "$PLATFORM_OS_LIKE" | tr '[:upper:]' '[:lower:]')" | ||
| case "$PLATFORM_OS_ID" in | ||
| ubuntu) | ||
| PLATFORM_OS_FAMILY="ubuntu" | ||
| ;; | ||
| debian) | ||
| PLATFORM_OS_FAMILY="debian" | ||
| ;; | ||
| poky) | ||
| PLATFORM_OS_FAMILY="yocto" | ||
| ;; | ||
| *) | ||
| case "$_os_like_lc" in | ||
| *debian*) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An Ubuntu derivative commonly reports ID_LIKE="ubuntu debian", but this ordering classifies it as Debian. Please check for the Ubuntu token before the Debian fallback so Ubuntu-compatible package policy remains accurate. |
||
| # Debian derivatives other than Ubuntu (e.g. Raspbian, Devuan). | ||
| PLATFORM_OS_FAMILY="debian" | ||
| ;; | ||
| *poky*) | ||
| PLATFORM_OS_FAMILY="yocto" | ||
| ;; | ||
| *) | ||
| case "$_os_cpe_name" in | ||
| *openembedded*) | ||
| # Covers qcom-distro and other Yocto/OpenEmbedded | ||
| # builds that set neither ID=poky nor ID_LIKE. | ||
| PLATFORM_OS_FAMILY="yocto" | ||
| ;; | ||
| esac | ||
| ;; | ||
| esac | ||
| ;; | ||
| esac | ||
|
|
||
| # --- Target guess (mutually-exclusive; generic names only) --- | ||
| lc_compat="$(printf '%s %s' "$PLATFORM_DT_MODEL" "$PLATFORM_DT_COMPAT" \ | ||
|
|
@@ -6903,6 +7012,7 @@ detect_platform() { | |
| PLATFORM_KERNEL PLATFORM_ARCH PLATFORM_UNAME_S PLATFORM_HOSTNAME \ | ||
| PLATFORM_SOC_MACHINE PLATFORM_SOC_ID PLATFORM_SOC_FAMILY \ | ||
| PLATFORM_DT_MODEL PLATFORM_DT_COMPAT PLATFORM_OS_LIKE PLATFORM_OS_NAME \ | ||
| PLATFORM_OS_ID PLATFORM_OS_FAMILY \ | ||
| PLATFORM_TARGET PLATFORM_MACHINE | ||
|
|
||
| return 0 | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not select /proc/config.gz solely because it is readable. On a minimal image it can exist while neither zgrep nor gzip is available, even when /boot/config-$(uname -r) is readable.
This reports every requested config as missing instead of trying the new fallback sources. Validate compressed-config readability with an available decompressor, otherwise continue to plain-text candidates.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated