From ab1a5a47d7fc810506d3ec2b571ce1ce497d9b05 Mon Sep 17 00:00:00 2001 From: Juho Vainio Date: Wed, 21 Oct 2026 11:51:18 +0300 Subject: [PATCH 1/7] fix: replace amdgpu-install with repo-native package installs Replaces the amdgpu-install helper with direct, OS-native package-manager installs for the AMD GPU driver, and brings diagnose/fix/examine in line: - driver_install: build per-distro plans (apt/dnf/zypper) that add repo.radeon.com directly instead of shelling out to amdgpu-install; sanitize VERSION_ID/codename/env overrides before shell interpolation; add --non-interactive/--gpg-auto-import-keys to the SLES zypper flow so it can't hang waiting on a repo-signing-key prompt; document Ubuntu 26.04 returning supported: false (no repo.radeon.com suite yet, amdgpu ships in-tree). - diagnose/fix: widen repo-native detection to the ID_LIKE family, derive the sudo prefix from the escalation mode, and have fix-12's verify step query real dpkg/rpm package state instead of the self-reported rocm_install_method marker (set from repo-marker-file presence before dpkg/rpm is consulted, so it could report success with nothing actually installed). - examine: rename rocm_install_method's repo-native/runfile-or-tarball values to match, detected from repo marker files. - e2e: cover the renamed install-method values and the new driver-install plans. Addresses review feedback across the PR's history, most recently review 5577901255 (fix-12 verify querying the wrong signal, SLES zypper hanging unattended, undocumented Ubuntu 26.04 behavior). Signed-off-by: Juho Vainio --- README.md | 10 +- apps/rocm/src/driver_install.rs | 730 +++++++++++++----- apps/rocm/src/main.rs | 11 +- apps/rocm/src/runtime_install_finalize.rs | 5 +- crates/rocm-core/src/diagnose.rs | 543 ++++++++++++- crates/rocm-core/src/examine.rs | 138 +++- crates/rocm-core/src/fix.rs | 256 +++++- crates/rocm-core/src/openmpi.rs | 6 +- docs/manual-testing.md | 17 + docs/testing.md | 29 + doctor-catalog.json | 2 +- skills/rocm-doctor/SKILL.md | 2 +- skills/rocm-doctor/reference.md | 4 +- .../features/driver_install.feature | 14 + tests/e2e-cucumber/features/examine.feature | 21 +- tests/e2e-cucumber/tests/e2e/driver_steps.rs | 43 ++ tests/e2e-cucumber/tests/e2e/examine_steps.rs | 37 +- 17 files changed, 1584 insertions(+), 284 deletions(-) diff --git a/README.md b/README.md index 7d8f94c1ad..f5988c43cd 100644 --- a/README.md +++ b/README.md @@ -444,7 +444,15 @@ active default runtime, not about what a named prefix loses. #### Driver installation `install driver` installs the AMD kernel driver on Linux, using DKMS or a native -package. +package. On bare metal it defaults to the floating `latest` amdgpu release; +set `ROCM_CLI_AMDGPU_DRIVER_VERSION` to pin a specific one. This replaces the +older `ROCM_CLI_AMDGPU_VERSION`/`ROCM_CLI_AMDGPU_PACKAGE_RELEASE` pair, which +pinned a fixed default and are no longer read. + +On Ubuntu 26.04, the amdgpu driver ships in-tree and `repo.radeon.com` does not +yet publish a matching DKMS repo, so `install driver` reports a non-mutating +`supported: false` plan instead and directs you to `apt install rocm` for the +userspace ROCm stack. #### Updates diff --git a/apps/rocm/src/driver_install.rs b/apps/rocm/src/driver_install.rs index 51f0f08ee6..a3ccf99d8d 100644 --- a/apps/rocm/src/driver_install.rs +++ b/apps/rocm/src/driver_install.rs @@ -327,7 +327,7 @@ struct DriverInstallPlan { os_id: String, version_id: String, codename: String, - repo_version: String, + repo_version_expr: String, reason: String, preflight_checks: Vec, commands: Vec, @@ -464,8 +464,8 @@ struct DriverPassiveCheck { /// Release of ROCDXG installed on WSL2, overridable for trying another build. /// /// Resolved once at plan-build time via [`resolve_shell_default_template`], the -/// same way `ROCM_CLI_AMDGPU_VERSION` is handled for the bare-metal repository -/// pin. The concrete value is baked into the archive name, the release URL and +/// same way `ROCM_CLI_AMDGPU_DRIVER_VERSION` is validated for the bare-metal +/// repository pin. The concrete value is baked into the archive name, the release URL and /// the `repo_version:` line, so the plan a user reviews names the build the /// install will actually fetch rather than an unexpanded `${...}` placeholder. /// @@ -580,6 +580,19 @@ fn sha256_digest_is_well_formed(digest: &str) -> bool { digest.len() == 64 && digest.chars().all(|c| c.is_ascii_hexdigit()) } +/// Whether a string is safe to interpolate into the driver-install plan's +/// shell commands: these values (the `ROCM_CLI_AMDGPU_DRIVER_VERSION` +/// override, and `VERSION_ID`/`VERSION_CODENAME`/`UBUNTU_CODENAME` read from +/// `/etc/os-release`) end up both inside single-quoted `printf` arguments and, +/// for `VERSION_ID` in the SUSEConnect commands, directly unquoted on the +/// command line -- so only letters, digits, and `. _ -` are accepted, the +/// same charset a real amdgpu/distro version or codename is made of. +fn is_safe_shell_token(v: &str) -> bool { + !v.is_empty() + && v.chars() + .all(|c| c.is_ascii_alphanumeric() || "._-".contains(c)) +} + /// How the downloaded ROCDXG package will be authenticated before it is /// installed as root. #[derive(Debug, Clone, Eq, PartialEq)] @@ -652,7 +665,7 @@ fn wsl_rocdxg_refusal_plan(repo_version: String, reason: String) -> DriverInstal os_id: "wsl".to_owned(), version_id: String::new(), codename: String::new(), - repo_version, + repo_version_expr: repo_version, reason, preflight_checks: Vec::new(), commands: Vec::new(), @@ -720,7 +733,7 @@ fn wsl_rocdxg_driver_plan(escalation: PrivilegeEscalation) -> DriverInstallPlan os_id: "wsl".to_owned(), version_id: String::new(), codename: String::new(), - repo_version: version, + repo_version_expr: version, reason: "WSL2 uses the Windows host driver plus ROCDXG, not Linux DKMS; this installs ROCDXG." .to_owned(), @@ -803,9 +816,9 @@ fn wsl_rocdxg_driver_plan(escalation: PrivilegeEscalation) -> DriverInstallPlan /// file that exists but could not be read /// ([`build_driver_install_plan_read`]'s `Unreadable` branch). Both name /// `reason`, never a distro, and differ only in it: shared here, including -/// `repo_version`'s own resolution, so a new early branch — or a bumped -/// default — added to one is not silently absent from the other. -fn unreadable_os_release_plan(reason: String) -> DriverInstallPlan { +/// `repo_version_expr`, so a new early branch added to one is not silently +/// absent from the other. +fn unreadable_os_release_plan(reason: String, repo_version_expr: String) -> DriverInstallPlan { DriverInstallPlan { supported: false, mutating: false, @@ -813,7 +826,7 @@ fn unreadable_os_release_plan(reason: String) -> DriverInstallPlan { os_id: String::new(), version_id: String::new(), codename: String::new(), - repo_version: resolve_shell_default_template("${ROCM_CLI_AMDGPU_VERSION:-7.2.4}"), + repo_version_expr, reason, preflight_checks: Vec::new(), commands: Vec::new(), @@ -822,9 +835,46 @@ fn unreadable_os_release_plan(reason: String) -> DriverInstallPlan { } } -/// The driver install plan for `examine` and the os-release `os_release_text` -/// read from `os_release_path`, naming that path in any unreadable-line -/// message. +/// Resolves and validates `ROCM_CLI_AMDGPU_DRIVER_VERSION`, shared between +/// [`build_driver_install_plan_at`] (reached whenever the os-release text +/// itself was readable) and [`build_driver_install_plan_read`]'s `Unreadable` +/// branch (reached before `_at` is even called), so both report the same +/// `invalid_driver_version_override` plan on a malformed override rather than +/// one of them silently falling back to `latest`. +fn resolve_repo_version_expr() -> Result> { + // Resolved here rather than left as a shell `${VAR:-default}` expression: + // these commands are built with `printf '%s\n' '...'` (single-quoted) so the + // written repo file has a working baseurl regardless of shell. The value is + // interpolated straight into that single-quoted command, so it's restricted + // to a safe URL path segment here rather than trusted verbatim: a value + // containing `'` would otherwise close the quoting and inject shell. An + // invalid override is refused rather than silently falling back to + // `latest`, the same way `wsl_rocdxg_driver_plan` refuses a malformed + // `ROCM_CLI_ROCDXG_VERSION` -- a user who set this expecting a specific + // release should see why it did not take effect, not an unexplained + // `latest`. + match std::env::var("ROCM_CLI_AMDGPU_DRIVER_VERSION") { + Err(_) => Ok("latest".to_owned()), + Ok(v) if is_safe_shell_token(&v) => Ok(v), + Ok(v) => Err(Box::new(DriverInstallPlan { + supported: false, + mutating: false, + policy: "invalid_driver_version_override".to_owned(), + os_id: String::new(), + version_id: String::new(), + codename: String::new(), + repo_version_expr: format!("{v:?}"), + reason: "ROCM_CLI_AMDGPU_DRIVER_VERSION is not a well-formed amdgpu driver release. It is interpolated into privileged shell commands, so only letters, digits, and `. _ -` are accepted.".to_owned(), + preflight_checks: Vec::new(), + commands: Vec::new(), + checks: vec!["rocm examine".to_owned()], + reboot_required: false, + })), + } +} + +/// [`build_driver_install_plan`], naming `os_release_path` instead of always +/// `/etc/os-release` in an unreadable-line message. fn build_driver_install_plan_at( examine: &ExamineSummary, os_release_path: &str, @@ -832,17 +882,6 @@ fn build_driver_install_plan_at( dkms: bool, escalation: PrivilegeEscalation, ) -> DriverInstallPlan { - // Resolve the AMD graphics version and amdgpu-install package release once, - // here at plan-build time, so the concrete values are baked into both the - // human-readable summary and every command the plan runs. Keeping shell - // `${VAR:-default}` templates in the commands used to be load-bearing, but - // AMD's apt `sources.list` line embeds the template inside POSIX single - // quotes, which suppress all expansion — so the literal `${...}` would land - // in the repo file. Resolving up front fixes that and keeps the summary and - // the executed commands in agreement. - let repo_version = resolve_shell_default_template("${ROCM_CLI_AMDGPU_VERSION:-7.2.4}"); - let package_release = - resolve_shell_default_template("${ROCM_CLI_AMDGPU_PACKAGE_RELEASE:-70204}"); if examine.os == "windows" { return DriverInstallPlan { supported: false, @@ -851,7 +890,15 @@ fn build_driver_install_plan_at( os_id: "windows".to_owned(), version_id: String::new(), codename: String::new(), - repo_version, + // Not interpolated into any command on this no-op plan (there are + // none), so an override is not validated before this early return. + // Always "latest" even if `ROCM_CLI_AMDGPU_DRIVER_VERSION` names + // something else or is malformed: unlike the Linux arms below, + // this value has not gone through `resolve_repo_version_expr()`, + // so do not read the printed `repo_version_expr:` line here (or in + // `--dry-run` output) as confirmation that an override was seen or + // accepted. + repo_version_expr: "latest".to_owned(), reason: "Windows driver install is validate-only in rocm-cli; use `rocm examine` to inspect the AMD display driver.".to_owned(), preflight_checks: Vec::new(), commands: Vec::new(), @@ -863,24 +910,60 @@ fn build_driver_install_plan_at( return wsl_rocdxg_driver_plan(escalation); } + let repo_version_expr = match resolve_repo_version_expr() { + Ok(v) => v, + Err(plan) => return *plan, + }; + // An unreadable file is reported as itself, naming the line, rather than // falling through to "this distro is not supported" — which would send the // user looking for a support matrix when the fix is one line of a file. let os_release = match rocm_core::os_release::parse(os_release_text) { Ok(fields) => fields, Err(unreadable) => { - return unreadable_os_release_plan(format!( - "{os_release_path} {unreadable}; no driver commands were planned \ - because the distro cannot be read. To fix it, {}.", - unreadable.fix() - )); + return unreadable_os_release_plan( + format!( + "{os_release_path} {unreadable}; no driver commands were planned \ + because the distro cannot be read. To fix it, {}.", + unreadable.fix() + ), + repo_version_expr, + ); } }; + let field = |key: &str| os_release.get(key).cloned(); - let os_id = field("ID").unwrap_or_default(); - let version_id = field("VERSION_ID").unwrap_or_default(); + // Not interpolated into any shell command today (only matched against and + // stored on the plan), but it goes through the same allow-list as + // `version_id`/`codename`/the env override anyway: centralizing the + // sanitization here means a future `os_id`-based repo path can't + // reintroduce the shell-injection class those fields close. An invalid + // value is treated as absent, falling through to the "unsupported" plan + // the same way the other fields do. + let os_id = field("ID") + .filter(|v| is_safe_shell_token(v)) + .unwrap_or_default(); + // `version_id` is interpolated unsanitized both into the same + // single-quoted `printf '...' | tee` commands as `repo_version_expr` + // above and, on SLES, directly unquoted on the SUSEConnect command line -- + // so it gets the same char allow-list as that override. A value that + // fails it is treated as absent (empty), which cannot match any + // `(os_id, version_id)` arm below and falls through to the safe, + // non-mutating "unsupported" plan, the same way a hostile codename falls + // through to the static mapping rather than being used verbatim. + let version_id = field("VERSION_ID") + .filter(|v| is_safe_shell_token(v)) + .unwrap_or_default(); + // `codename` is interpolated unsanitized into the same single-quoted + // `printf '...' | tee` command as `repo_version_expr` above, so an + // os-release-sourced value gets the same char allow-list: a crafted + // VERSION_CODENAME/UBUNTU_CODENAME (compromised or custom base image) + // could otherwise break out of the quoting and inject shell. An invalid + // value is treated as absent, falling through to the trusted static + // `codename_for_version` mapping rather than being used verbatim. let codename = field("VERSION_CODENAME") .or_else(|| field("UBUNTU_CODENAME")) + .filter(|v| is_safe_shell_token(v)) .or_else(|| codename_for_version(&os_id, &version_id).map(str::to_owned)) .unwrap_or_default(); let id_like = field("ID_LIKE").unwrap_or_default(); @@ -890,25 +973,76 @@ fn build_driver_install_plan_at( os_id, version_id, codename, - repo_version, + repo_version_expr, dkms, true, escalation, ), + // TODO: AMD had not published a repo.radeon.com/amdgpu "resolute" + // suite as of 2026-08; re-check + // https://repo.radeon.com/amdgpu/latest/ubuntu/dists/ and switch this + // to apt_driver_plan(..., true) once it exists, the same way + // 22.04/24.04 are handled. + // + // No Gherkin/e2e scenario covers this arm's output (AGENTS.md #3), + // and that is not one of #3's two named exceptions (a gated lane, or + // a purely internal change) -- this is user-observable `rocm install + // driver` output on a real OS release. The unit level is NOT the gap: + // `build_driver_install_plan` takes `os_release_text: &str` as a + // plain parameter rather than calling `read_os_release()` itself, so + // this arm is already driven by a hand-written fixture in + // `driver_plan_ubuntu_2604_uses_native_archive_guidance` and its two + // neighbors below. The gap is only the e2e path: the real `rocm` + // binary's `read_os_release()` reads `/etc/os-release` with no + // override, so no lane or test host can reach this arm through the + // CLI itself. + ("ubuntu", "26.04") => { + let sudo = escalation.prefix(); + DriverInstallPlan { + supported: false, + mutating: false, + policy: "ubuntu_native_archive".to_owned(), + os_id, + version_id, + // codename_for_version already resolves this to "resolute" when + // VERSION_CODENAME/UBUNTU_CODENAME are absent, so this is never + // empty here -- no fallback needed. + codename, + repo_version_expr, + reason: format!( + "Ubuntu 26.04 LTS ships ROCm natively via the standard archive and \ + includes the amdgpu kernel driver in-tree; AMD's repo.radeon.com/amdgpu \ + tree does not yet publish a 'resolute' suite, so no third-party DKMS repo \ + commands are planned. Run `{sudo}apt install rocm` for the userspace ROCm \ + stack instead." + ), + preflight_checks: Vec::new(), + commands: Vec::new(), + // `checks` renders as `post_reboot_checks:` and, like every other + // arm, holds passive verification targets only -- the mutating + // install command above belongs in `reason`, not here. + checks: vec!["rocm examine".to_owned(), "rocminfo".to_owned()], + // The amdgpu kernel driver ships in-tree with the kernel itself, + // not with this guidance's `apt install rocm` -- that command + // installs the userspace ROCm stack only, so nothing changes on + // the kernel side and no reboot is needed for it to take effect. + reboot_required: false, + } + } ("debian", "12" | "13") => { let repo_codename = if version_id == "13" { "noble" } else { "jammy" }; let mut plan = apt_driver_plan( os_id, version_id, repo_codename.to_owned(), - repo_version, + repo_version_expr, dkms, false, escalation, ); // Debian deliberately reuses AMD's Ubuntu-suite repository: AMD's // documented Debian install maps Debian 12 -> jammy and 13 -> noble - // and serves them from the .../ubuntu graphics tree. Surface that in + // and serves them from the .../ubuntu amdgpu tree. Surface that in // the plan so the Ubuntu codename on a Debian host doesn't read as a // misdetection. plan.reason = format!( @@ -921,8 +1055,7 @@ fn build_driver_install_plan_at( os_id, version_id, codename, - repo_version, - package_release, + repo_version_expr, dkms, DnfDriverDistro::Rhel, escalation, @@ -931,8 +1064,7 @@ fn build_driver_install_plan_at( os_id, version_id, codename, - repo_version, - package_release, + repo_version_expr, dkms, DnfDriverDistro::Oracle, escalation, @@ -941,30 +1073,20 @@ fn build_driver_install_plan_at( os_id, version_id, codename, - repo_version, - package_release, + repo_version_expr, dkms, DnfDriverDistro::Rocky, escalation, ), ("sles" | "sle", "15.7") => { - sles_driver_plan( - os_id, - version_id, - codename, - repo_version, - package_release, - dkms, - escalation, - ) + sles_driver_plan(os_id, version_id, codename, repo_version_expr, dkms, escalation) } _ => driver_plan_via_id_like( &os_id, &version_id, &id_like, &codename, - &repo_version, - &package_release, + &repo_version_expr, dkms, escalation, ) @@ -975,7 +1097,7 @@ fn build_driver_install_plan_at( os_id, version_id, codename, - repo_version, + repo_version_expr, reason: "Linux DKMS driver install is currently planned only for AMD-documented Ubuntu, Debian, RHEL, Oracle Linux, SLES, and Rocky versions; no commands were guessed for this distro.".to_owned(), preflight_checks: Vec::new(), commands: Vec::new(), @@ -1008,10 +1130,17 @@ fn build_driver_install_plan_read( if reaches_os_release_parse && let rocm_core::hardware_root::OsRelease::Unreadable { path, error } = read { - return unreadable_os_release_plan(format!( - "{}; no driver commands were planned because the distro cannot be read.", - rocm_core::hardware_root::unreadable_prefix(path, error) - )); + let repo_version_expr = match resolve_repo_version_expr() { + Ok(v) => v, + Err(plan) => return *plan, + }; + return unreadable_os_release_plan( + format!( + "{}; no driver commands were planned because the distro cannot be read.", + rocm_core::hardware_root::unreadable_prefix(path, error) + ), + repo_version_expr, + ); } build_driver_install_plan_at(examine, read.path(), read.text(), dkms, escalation) } @@ -1033,8 +1162,7 @@ fn driver_plan_via_id_like( version_id: &str, id_like: &str, codename: &str, - repo_version: &str, - package_release: &str, + repo_version_expr: &str, dkms: bool, escalation: PrivilegeEscalation, ) -> Option { @@ -1061,7 +1189,7 @@ fn driver_plan_via_id_like( os_id.to_owned(), version_id.to_owned(), codename, - repo_version.to_owned(), + repo_version_expr.to_owned(), dkms, true, escalation, @@ -1076,7 +1204,7 @@ fn driver_plan_via_id_like( os_id.to_owned(), version_id.to_owned(), repo_codename.to_owned(), - repo_version.to_owned(), + repo_version_expr.to_owned(), dkms, false, escalation, @@ -1097,8 +1225,7 @@ fn driver_plan_via_id_like( os_id.to_owned(), version_id.to_owned(), codename.to_owned(), - repo_version.to_owned(), - package_release.to_owned(), + repo_version_expr.to_owned(), dkms, DnfDriverDistro::Generic, escalation, @@ -1133,7 +1260,7 @@ fn apt_driver_plan( os_id: String, version_id: String, codename: String, - repo_version: String, + repo_version_expr: String, dkms: bool, include_linux_modules_extra: bool, escalation: PrivilegeEscalation, @@ -1175,7 +1302,7 @@ fn apt_driver_plan( driver_command( DriverCommandPhase::Prepare, &format!( - "printf '%s\\n' 'deb [arch=amd64 signed-by=/etc/apt/keyrings/rocm.gpg] https://repo.radeon.com/graphics/{repo_version}/ubuntu {codename} main' | {sudo}tee /etc/apt/sources.list.d/amdgpu.list >/dev/null" + "printf '%s\\n' 'deb [arch=amd64 signed-by=/etc/apt/keyrings/rocm.gpg] https://repo.radeon.com/amdgpu/{repo_version_expr}/ubuntu {codename} main' | {sudo}tee /etc/apt/sources.list.d/amdgpu.list >/dev/null" ), ), driver_command( @@ -1207,7 +1334,7 @@ fn apt_driver_plan( os_id, version_id, codename, - repo_version, + repo_version_expr, reason: if dkms { "Plan uses AMD's package-manager DKMS flow and requires explicit approval before execution." } else { @@ -1242,8 +1369,7 @@ fn dnf_driver_plan( os_id: String, version_id: String, codename: String, - repo_version: String, - package_release: String, + repo_version_expr: String, dkms: bool, distro: DnfDriverDistro, escalation: PrivilegeEscalation, @@ -1276,11 +1402,15 @@ fn dnf_driver_plan( )); } } + commands.push(driver_command( + DriverCommandPhase::Prepare, + &format!("{sudo}rpm --import https://repo.radeon.com/rocm/rocm.gpg.key"), + )); commands.push(driver_command( DriverCommandPhase::Prepare, &format!( - "{sudo}dnf install -y {}", - amdgpu_install_rpm_url(&repo_version, &package_release, &version_id, distro) + "printf '%s\\n' '[amdgpu]' 'name=amdgpu' 'baseurl={}' 'enabled=1' 'priority=50' 'gpgcheck=1' 'gpgkey=https://repo.radeon.com/rocm/rocm.gpg.key' | {sudo}tee /etc/yum.repos.d/amdgpu.repo >/dev/null", + dnf_repo_baseurl(&repo_version_expr, &version_id, distro) ), )); commands.push(driver_command( @@ -1308,7 +1438,7 @@ fn dnf_driver_plan( os_id, version_id, codename, - repo_version, + repo_version_expr, reason: if dkms { "Plan uses AMD's documented DNF DKMS flow and requires explicit approval before execution." } else { @@ -1344,8 +1474,7 @@ fn sles_driver_plan( os_id: String, version_id: String, codename: String, - repo_version: String, - package_release: String, + repo_version_expr: String, dkms: bool, escalation: PrivilegeEscalation, ) -> DriverInstallPlan { @@ -1371,26 +1500,35 @@ fn sles_driver_plan( ), driver_command( DriverCommandPhase::Prepare, - &format!("{sudo}zypper refresh"), + &format!("{sudo}zypper --non-interactive refresh"), + ), + driver_command( + DriverCommandPhase::Prepare, + &format!("{sudo}zypper --non-interactive install -y kernel-default-devel"), ), driver_command( DriverCommandPhase::Prepare, - &format!("{sudo}zypper install -y kernel-default-devel"), + &format!("{sudo}rpm --import https://repo.radeon.com/rocm/rocm.gpg.key"), ), driver_command( DriverCommandPhase::Prepare, &format!( - "{sudo}zypper --no-gpg-checks install -y {}", - amdgpu_install_sles_rpm_url(&repo_version, &package_release, &version_id) + "printf '%s\\n' '[amdgpu]' 'name=amdgpu' 'baseurl={}' 'enabled=1' 'autorefresh=0' 'type=rpm-md' 'gpgcheck=1' 'gpgkey=https://repo.radeon.com/rocm/rocm.gpg.key' | {sudo}tee /etc/zypp/repos.d/amdgpu.repo >/dev/null", + sles_repo_baseurl(&repo_version_expr, &version_id) ), ), driver_command( DriverCommandPhase::Prepare, - &format!("{sudo}zypper refresh"), + // `--gpg-auto-import-keys` is required here: `rpm --import` above + // only seeds the RPM keyring, but zypper tracks trusted + // *repository* signing keys separately and otherwise prompts to + // trust/reject the new repo's key on this refresh -- a prompt + // that would hang this unattended flow (no stdin attached). + &format!("{sudo}zypper --non-interactive --gpg-auto-import-keys refresh"), ), driver_command( DriverCommandPhase::Execute, - &format!("{sudo}zypper install -y amdgpu-dkms"), + &format!("{sudo}zypper --non-interactive install -y amdgpu-dkms"), ), driver_command(DriverCommandPhase::Verify, "dkms status amdgpu"), driver_command(DriverCommandPhase::Verify, "test -e /dev/kfd"), @@ -1408,7 +1546,7 @@ fn sles_driver_plan( os_id, version_id, codename, - repo_version, + repo_version_expr, reason: if dkms { "Plan uses AMD's documented SLES DKMS flow and requires explicit approval before execution." } else { @@ -1455,31 +1593,19 @@ fn rhel_kernel_prepare_commands(version_id: &str, escalation: PrivilegeEscalatio } } -fn amdgpu_install_rpm_url( - repo_version: &str, - package_release: &str, - version_id: &str, - distro: DnfDriverDistro, -) -> String { +fn dnf_repo_baseurl(repo_version_expr: &str, version_id: &str, distro: DnfDriverDistro) -> String { let repo_family = match distro { DnfDriverDistro::Rhel => "rhel", DnfDriverDistro::Oracle | DnfDriverDistro::Rocky | DnfDriverDistro::Generic => "el", }; - let repo_version_path = dnf_repo_version_path(version_id); - let el_major = linux_major_version(version_id); + let repo_version = dnf_repo_version_path(version_id); format!( - "https://repo.radeon.com/amdgpu-install/{repo_version}/{repo_family}/{repo_version_path}/amdgpu-install-{repo_version}.{package_release}-1.el{el_major}.noarch.rpm" + "https://repo.radeon.com/amdgpu/{repo_version_expr}/{repo_family}/{repo_version}/main/x86_64" ) } -fn amdgpu_install_sles_rpm_url( - repo_version: &str, - package_release: &str, - version_id: &str, -) -> String { - format!( - "https://repo.radeon.com/amdgpu-install/{repo_version}/sle/{version_id}/amdgpu-install-{repo_version}.{package_release}-1.noarch.rpm" - ) +fn sles_repo_baseurl(repo_version_expr: &str, version_id: &str) -> String { + format!("https://repo.radeon.com/amdgpu/{repo_version_expr}/sle/{version_id}/main/x86_64") } fn dnf_repo_version_path(version_id: &str) -> String { @@ -1527,7 +1653,7 @@ fn driver_command(phase: DriverCommandPhase, command: &str) -> DriverPlanCommand /// once at plan-build time so the concrete value is baked into both the /// human-readable summary and the commands the plan runs, rather than leaking an /// unexpanded `${...}` placeholder into user-facing output or depending on the -/// runtime shell — which, for the single-quoted apt `sources.list` line, would +/// runtime shell — which, for the single-quoted WSL ROCDXG download command, would /// never expand it at all. /// /// Only a single, flat `${VAR:-default}` template is recognized. Anything else — @@ -1572,7 +1698,7 @@ fn render_driver_install_plan(plan: &DriverInstallPlan, yes: bool, dry_run: bool empty_as_unknown(&plan.version_id) ); let _ = writeln!(output, " codename: {}", empty_as_unknown(&plan.codename)); - let _ = writeln!(output, " repo_version: {}", plan.repo_version); + let _ = writeln!(output, " repo_version: {}", plan.repo_version_expr); let _ = writeln!(output, " reason: {}", plan.reason); if !plan.preflight_checks.is_empty() { let _ = writeln!(output, " preflight_checks:"); @@ -1663,6 +1789,7 @@ fn codename_for_version(os_id: &str, version_id: &str) -> Option<&'static str> { match (os_id, version_id) { ("ubuntu", "22.04") => Some("jammy"), ("ubuntu", "24.04") => Some("noble"), + ("ubuntu", "26.04") => Some("resolute"), ("debian", "12") => Some("jammy"), ("debian", "13") => Some("noble"), _ => None, @@ -2263,6 +2390,66 @@ mod tests { } } + #[test] + fn resolve_shell_default_template_uses_default_when_env_unset() { + let _env = ScopedTestEnv::new(); + // A made-up variable name that nothing else sets, cleared under the lock, + // isolates the default path. + assert_eq!( + resolve_shell_default_template("${ROCM_CLI_TEST_UNSET_REPO_VERSION:-7.2.4}"), + "7.2.4" + ); + } + + #[test] + fn resolve_shell_default_template_prefers_env_value_when_set() { + let mut env = ScopedTestEnv::new(); + let var = "ROCM_CLI_TEST_REPO_VERSION_OVERRIDE"; + env.set(var, "9.9.9"); + assert_eq!( + resolve_shell_default_template(&format!("${{{var}:-7.2.4}}")), + "9.9.9" + ); + } + + #[test] + fn resolve_shell_default_template_treats_empty_env_as_unset() { + let mut env = ScopedTestEnv::new(); + let var = "ROCM_CLI_TEST_REPO_VERSION_EMPTY"; + env.set(var, ""); + assert_eq!( + resolve_shell_default_template(&format!("${{{var}:-7.2.4}}")), + "7.2.4" + ); + } + + #[test] + fn resolve_shell_default_template_passes_through_non_template() { + assert_eq!(resolve_shell_default_template("7.2.4"), "7.2.4"); + } + + #[test] + fn resolve_shell_default_template_leaves_bare_var_untouched() { + let _env = ScopedTestEnv::new(); + // No `:-default`, so there is nothing to resolve to; the input must pass + // through unchanged rather than being partially rewritten. + assert_eq!( + resolve_shell_default_template("${ROCM_CLI_TEST_UNSET_REPO_VERSION}"), + "${ROCM_CLI_TEST_UNSET_REPO_VERSION}" + ); + } + + #[test] + fn resolve_shell_default_template_leaves_nested_default_untouched() { + let _env = ScopedTestEnv::new(); + // A nested default is beyond the flat matcher; returning the literal + // input keeps a `${B:-x}` fragment from leaking as a "resolved" value. + assert_eq!( + resolve_shell_default_template("${ROCM_CLI_TEST_UNSET_A:-${ROCM_CLI_TEST_UNSET_B:-x}}"), + "${ROCM_CLI_TEST_UNSET_A:-${ROCM_CLI_TEST_UNSET_B:-x}}" + ); + } + #[test] fn driver_plan_ubuntu_2404_uses_official_dkms_commands() { let _env = ScopedTestEnv::with_amd_overrides_cleared(); @@ -2304,7 +2491,7 @@ VERSION_CODENAME=noble assert!( commands .iter() - .any(|command| command.contains("repo.radeon.com/graphics")) + .any(|command| command.contains("repo.radeon.com/amdgpu")) ); assert!( commands @@ -2512,6 +2699,185 @@ VERSION_CODENAME=noble Ok(()) } + #[test] + fn driver_plan_ubuntu_2604_uses_native_archive_guidance() { + let _env = ScopedTestEnv::with_amd_overrides_cleared(); + let os_release = r#" +ID=ubuntu +VERSION_ID="26.04" +VERSION_CODENAME=resolute +"#; + let plan = build_driver_install_plan_read( + &test_examine("linux", false), + &os_release_found(os_release), + true, + PrivilegeEscalation::Sudo, + ); + let rendered = render_driver_install_plan(&plan, false, false); + + assert!(!plan.supported); + assert!(!plan.mutating); + assert_eq!(plan.policy, "ubuntu_native_archive"); + assert_eq!(plan.codename, "resolute"); + assert!(rendered.contains("approval: not required")); + assert!(rendered.contains("execution_commands: ")); + assert!(rendered.contains("sudo apt install rocm")); + assert!(!rendered.contains("amdgpu-dkms")); + assert!(plan.commands.is_empty()); + // `checks` renders as `post_reboot_checks:` and must hold verification + // targets only -- the mutating install guidance belongs in `reason`. + assert!( + !plan + .checks + .iter() + .any(|check| check.contains("apt install")) + ); + } + + #[test] + fn driver_plan_ubuntu_2604_root_guidance_drops_sudo() { + // Companion to the Sudo case above: this arm derives its guidance from + // `escalation` rather than hardcoding `sudo`, so a root host must see + // the same command with no `sudo` prefix. + let _env = ScopedTestEnv::with_amd_overrides_cleared(); + let os_release = r#" +ID=ubuntu +VERSION_ID="26.04" +VERSION_CODENAME=resolute +"#; + let plan = build_driver_install_plan_read( + &test_examine("linux", false), + &os_release_found(os_release), + true, + PrivilegeEscalation::AlreadyRoot, + ); + let rendered = render_driver_install_plan(&plan, false, false); + + assert!(rendered.contains("apt install rocm")); + assert!(!plan.reason.contains("sudo")); + assert!(!plan.checks.iter().any(|check| check.contains("sudo"))); + } + + #[test] + fn driver_plan_ubuntu_2604_falls_back_to_resolute_codename() { + let _env = ScopedTestEnv::with_amd_overrides_cleared(); + // No VERSION_CODENAME/UBUNTU_CODENAME in os-release: codename_for_version + // must supply "resolute" on its own, and the policy must still be the + // native-archive one -- pinning both closes the gap where deleting the + // whole ("ubuntu", "26.04") arm would still leave this test green. + let os_release = r#" +ID=ubuntu +VERSION_ID="26.04" +"#; + let plan = build_driver_install_plan_read( + &test_examine("linux", false), + &os_release_found(os_release), + true, + PrivilegeEscalation::Sudo, + ); + + assert_eq!(plan.codename, "resolute"); + assert_eq!(plan.policy, "ubuntu_native_archive"); + } + + #[test] + fn driver_plan_rejects_shell_metacharacters_in_version_override() { + let mut env = ScopedTestEnv::with_amd_overrides_cleared(); + env.set( + "ROCM_CLI_AMDGPU_DRIVER_VERSION", + "'; touch /tmp/pwned; echo '", + ); + let os_release = r#" +ID=ubuntu +VERSION_ID="24.04" +VERSION_CODENAME=noble +"#; + let plan = build_driver_install_plan_read( + &test_examine("linux", false), + &os_release_found(os_release), + true, + PrivilegeEscalation::Sudo, + ); + + assert!(!plan.supported); + assert_eq!(plan.policy, "invalid_driver_version_override"); + assert!(plan.reason.contains("ROCM_CLI_AMDGPU_DRIVER_VERSION")); + assert!(plan.commands.is_empty()); + assert!( + plan.commands + .iter() + .all(|command| !command.command.contains("pwned")) + ); + } + + #[test] + fn driver_plan_accepts_a_valid_version_override_and_uses_it_in_the_url() { + let mut env = ScopedTestEnv::with_amd_overrides_cleared(); + env.set("ROCM_CLI_AMDGPU_DRIVER_VERSION", "30.10"); + let os_release = r#" +ID=ubuntu +VERSION_ID="24.04" +VERSION_CODENAME=noble +"#; + let plan = build_driver_install_plan_read( + &test_examine("linux", false), + &os_release_found(os_release), + true, + PrivilegeEscalation::Sudo, + ); + let rendered = render_driver_install_plan(&plan, false, false); + + assert_eq!(plan.repo_version_expr, "30.10"); + assert!(rendered.contains("amdgpu/30.10/")); + } + + #[test] + fn driver_plan_falls_back_on_a_hostile_codename() { + let _env = ScopedTestEnv::with_amd_overrides_cleared(); + let os_release = r#" +ID=ubuntu +VERSION_ID="24.04" +VERSION_CODENAME='; touch /tmp/pwned; echo ' +"#; + let plan = build_driver_install_plan_read( + &test_examine("linux", false), + &os_release_found(os_release), + true, + PrivilegeEscalation::Sudo, + ); + + assert_eq!(plan.codename, "noble"); + assert!( + plan.commands + .iter() + .all(|command| !command.command.contains("pwned")) + ); + } + + #[test] + fn driver_plan_falls_back_on_a_malformed_version_id() { + let _env = ScopedTestEnv::with_amd_overrides_cleared(); + let os_release = r#" +ID=ubuntu +VERSION_ID="24.04'; touch /tmp/pwned; echo '" +VERSION_CODENAME=noble +"#; + let plan = build_driver_install_plan_read( + &test_examine("linux", false), + &os_release_found(os_release), + true, + PrivilegeEscalation::Sudo, + ); + + assert_eq!(plan.version_id, ""); + assert!(!plan.supported); + assert!( + plan.commands + .iter() + .all(|command| !command.command.contains("pwned")) + ); + } + #[test] fn driver_reconcile_without_state_gives_non_privileged_guidance() -> Result<()> { let (root, paths) = test_paths("driver-reconcile-empty"); @@ -2691,87 +3057,6 @@ VERSION_CODENAME=noble assert!(rendered.contains("add --dkms")); } - #[test] - fn resolve_shell_default_template_uses_default_when_env_unset() { - let _env = ScopedTestEnv::new(); - // A made-up variable name that nothing else sets, cleared under the lock, - // isolates the default path. - assert_eq!( - resolve_shell_default_template("${ROCM_CLI_TEST_UNSET_REPO_VERSION:-7.2.4}"), - "7.2.4" - ); - } - - #[test] - fn resolve_shell_default_template_prefers_env_value_when_set() { - let mut env = ScopedTestEnv::new(); - let var = "ROCM_CLI_TEST_REPO_VERSION_OVERRIDE"; - env.set(var, "9.9.9"); - assert_eq!( - resolve_shell_default_template(&format!("${{{var}:-7.2.4}}")), - "9.9.9" - ); - } - - #[test] - fn resolve_shell_default_template_treats_empty_env_as_unset() { - let mut env = ScopedTestEnv::new(); - let var = "ROCM_CLI_TEST_REPO_VERSION_EMPTY"; - env.set(var, ""); - assert_eq!( - resolve_shell_default_template(&format!("${{{var}:-7.2.4}}")), - "7.2.4" - ); - } - - #[test] - fn resolve_shell_default_template_passes_through_non_template() { - assert_eq!(resolve_shell_default_template("7.2.4"), "7.2.4"); - } - - #[test] - fn resolve_shell_default_template_leaves_bare_var_untouched() { - let _env = ScopedTestEnv::new(); - // No `:-default`, so there is nothing to resolve to; the input must pass - // through unchanged rather than being partially rewritten. - assert_eq!( - resolve_shell_default_template("${ROCM_CLI_TEST_UNSET_REPO_VERSION}"), - "${ROCM_CLI_TEST_UNSET_REPO_VERSION}" - ); - } - - #[test] - fn resolve_shell_default_template_leaves_nested_default_untouched() { - let _env = ScopedTestEnv::new(); - // A nested default is beyond the flat matcher; returning the literal - // input keeps a `${B:-x}` fragment from leaking as a "resolved" value. - assert_eq!( - resolve_shell_default_template("${ROCM_CLI_TEST_UNSET_A:-${ROCM_CLI_TEST_UNSET_B:-x}}"), - "${ROCM_CLI_TEST_UNSET_A:-${ROCM_CLI_TEST_UNSET_B:-x}}" - ); - } - - #[test] - fn driver_plan_dry_run_repo_version_line_is_resolved() { - let _env = ScopedTestEnv::with_amd_overrides_cleared(); - // Regression for the dry-run output leaking the raw shell placeholder on - // the `repo_version:` line instead of the effective version. - let os_release = r#" -ID=rhel -VERSION_ID="9.7" -"#; - let plan = build_driver_install_plan_read( - &test_examine("linux", false), - &os_release_found(os_release), - true, - PrivilegeEscalation::Sudo, - ); - let rendered = render_driver_install_plan(&plan, false, true); - - assert!(rendered.contains("repo_version: 7.2.4")); - assert!(!rendered.contains("repo_version: ${ROCM_CLI_AMDGPU_VERSION:-7.2.4}")); - } - #[test] fn driver_plan_debian_12_omits_linux_modules_extra() { let _env = ScopedTestEnv::with_amd_overrides_cleared(); @@ -2818,8 +3103,12 @@ VERSION_ID="9.7" assert!(rendered.contains("kernel-headers-$(uname -r)")); assert!(rendered.contains("kernel-devel-$(uname -r)")); assert!(rendered.contains("kernel-devel-matched-$(uname -r)")); - assert!(rendered.contains("repo.radeon.com/amdgpu-install/7.2.4/rhel/9.7/")); - assert!(rendered.contains("amdgpu-install-7.2.4.70204-1.el9.noarch.rpm")); + assert!(rendered.contains("sudo rpm --import https://repo.radeon.com/rocm/rocm.gpg.key")); + assert!( + rendered.contains("baseurl=https://repo.radeon.com/amdgpu/latest/rhel/9.7/main/x86_64") + ); + assert!(rendered.contains("gpgcheck=1")); + assert!(rendered.contains("/etc/yum.repos.d/amdgpu.repo")); assert!(rendered.contains("Execute: sudo dnf install -y amdgpu-dkms")); assert!(rendered.contains("approval: required")); } @@ -2842,8 +3131,9 @@ VERSION_ID="10.1" assert!(plan.supported); assert!(rendered.contains("approval: not required")); assert!(rendered.contains("kernel-uek-devel-$(uname -r)")); - assert!(rendered.contains("repo.radeon.com/amdgpu-install/7.2.4/el/10/")); - assert!(rendered.contains("amdgpu-install-7.2.4.70204-1.el10.noarch.rpm")); + assert!( + rendered.contains("baseurl=https://repo.radeon.com/amdgpu/latest/el/10/main/x86_64") + ); assert!(rendered.contains("dry run only")); } @@ -2867,7 +3157,9 @@ VERSION_ID="9.7" rendered .contains("sudo dnf install -y kernel-headers kernel-devel kernel-devel-matched") ); - assert!(rendered.contains("repo.radeon.com/amdgpu-install/7.2.4/el/9.7/")); + assert!( + rendered.contains("baseurl=https://repo.radeon.com/amdgpu/latest/el/9.7/main/x86_64") + ); assert!(rendered.contains("Execute: sudo dnf install -y amdgpu-dkms")); } @@ -2889,8 +3181,9 @@ VERSION_ID="9.4" assert!(plan.supported); assert!(plan.mutating); - assert!(rendered.contains("repo.radeon.com/amdgpu-install/7.2.4/el/9.4/")); - assert!(rendered.contains("amdgpu-install-7.2.4.70204-1.el9.noarch.rpm")); + assert!( + rendered.contains("baseurl=https://repo.radeon.com/amdgpu/latest/el/9.4/main/x86_64") + ); assert!(rendered.contains("Execute: sudo dnf install -y amdgpu-dkms")); } @@ -2919,7 +3212,7 @@ VERSION_ID="9.4" fn driver_plan_debian_uses_intended_ubuntu_suite() { let _env = ScopedTestEnv::with_amd_overrides_cleared(); // AMD's documented Debian install deliberately serves Debian from the - // Ubuntu-suite graphics tree (Debian 12 -> jammy). Lock that in and + // Ubuntu-suite amdgpu tree (Debian 12 -> jammy). Lock that in and // ensure the plan explains the mapping is intentional. let os_release = r#" ID=debian @@ -2936,7 +3229,7 @@ VERSION_CODENAME=bookworm assert!(plan.supported); assert_eq!(plan.codename, "jammy"); - assert!(rendered.contains("https://repo.radeon.com/graphics/7.2.4/ubuntu jammy main")); + assert!(rendered.contains("https://repo.radeon.com/amdgpu/latest/ubuntu jammy main")); assert!( plan.reason .contains("intentionally uses AMD's Ubuntu-suite repository") @@ -2962,10 +3255,19 @@ VERSION_ID="15.7" assert!(rendered.contains("`zypper` package manager is available")); assert!(rendered.contains("SUSEConnect")); assert!(rendered.contains("sle-module-desktop-applications/15.7/x86_64")); - assert!(rendered.contains("sudo zypper install -y kernel-default-devel")); - assert!(rendered.contains("repo.radeon.com/amdgpu-install/7.2.4/sle/15.7/")); - assert!(rendered.contains("sudo zypper --no-gpg-checks install -y")); - assert!(rendered.contains("Execute: sudo zypper install -y amdgpu-dkms")); + assert!(rendered.contains("sudo zypper --non-interactive install -y kernel-default-devel")); + assert!(rendered.contains("sudo rpm --import https://repo.radeon.com/rocm/rocm.gpg.key")); + assert!( + rendered.contains("baseurl=https://repo.radeon.com/amdgpu/latest/sle/15.7/main/x86_64") + ); + assert!(rendered.contains("gpgcheck=1")); + assert!(rendered.contains("/etc/zypp/repos.d/amdgpu.repo")); + assert!( + rendered.contains("sudo zypper --non-interactive --gpg-auto-import-keys refresh"), + "the post-repo-add refresh must auto-trust the new repo's signing key, \ + or zypper would prompt (and hang this unattended flow): {rendered}" + ); + assert!(rendered.contains("Execute: sudo zypper --non-interactive install -y amdgpu-dkms")); assert!(rendered.contains("approval: required")); } @@ -3019,12 +3321,12 @@ VERSION_ID="41" // `dkms: true` is passed deliberately: WSL2 has no kernel module to // build, so the flag must not pull in the bare-metal path. // - // `build_driver_install_plan_at` resolves `${ROCM_CLI_AMDGPU_VERSION:-...}` - // from process env before it reaches the WSL branch, and the WSL branch - // then reads the three ROCDXG vars — an exported + // The WSL branch reads the three ROCDXG vars — an exported // `ROCM_CLI_ROCDXG_VERSION` would steer this plan into a refusal and - // fail the `plan.supported` assertion below. So this reader takes the - // guard that clears both sets. + // fail the `plan.supported` assertion below. `ROCM_CLI_AMDGPU_DRIVER_VERSION` + // is never consulted on this path (the WSL dispatch happens before that + // var is read), but this reader still takes the combined guard so it + // isn't the one test that has to remember which half it needs. let _env = scoped_rocdxg_env(); let plan = build_driver_install_plan_read( &test_examine("linux", true), @@ -3138,10 +3440,10 @@ VERSION_ID="41" /// that is asserting on the default. /// /// Builds on [`ScopedTestEnv::with_amd_overrides_cleared`] rather than - /// `new` because a WSL plan reached through `build_driver_install_plan_read` - /// resolves the bare-metal AMDGPU overrides before it dispatches to the WSL - /// branch: a caller needing one of these two guards needs both, and one - /// helper spares every test from picking the wrong half. + /// `new` so a caller that also exercises the bare-metal AMDGPU override + /// through the same `build_driver_install_plan` call doesn't need a + /// second guard: one helper covers both input sets regardless of which + /// branch actually reads them. fn scoped_rocdxg_env() -> ScopedTestEnv { let mut env = ScopedTestEnv::with_amd_overrides_cleared(); env.clear("ROCM_CLI_ROCDXG_VERSION"); @@ -3377,7 +3679,7 @@ VERSION_ID="41" let _env = scoped_rocdxg_env(); let plan = wsl_rocdxg_driver_plan(PrivilegeEscalation::Sudo); - let version = plan.repo_version.clone(); + let version = plan.repo_version_expr.clone(); let pinned = ROCDXG_PINNED_DIGESTS .iter() .find_map(|(pinned_version, digest)| { @@ -3487,7 +3789,7 @@ VERSION_ID="41" let mut env = scoped_rocdxg_env(); let plan = wsl_rocdxg_driver_plan(PrivilegeEscalation::Sudo); - assert_eq!(plan.repo_version, "1.2.2"); + assert_eq!(plan.repo_version_expr, "1.2.2"); let commands = plan.execution_commands().join("\n"); // The version is resolved here, not deferred to the shell: the plan the // user approves has to name the build the install will actually fetch. @@ -3512,7 +3814,7 @@ VERSION_ID="41" env.set("ROCM_CLI_ROCDXG_VERSION", "9.9.9"); env.set(ROCDXG_SHA256_ENV, &"b".repeat(64)); let overridden = wsl_rocdxg_driver_plan(PrivilegeEscalation::Sudo); - assert_eq!(overridden.repo_version, "9.9.9"); + assert_eq!(overridden.repo_version_expr, "9.9.9"); let commands = overridden.execution_commands().join("\n"); assert!( commands.contains("rocdxg-roct_9.9.9_amd64.deb"), @@ -3558,7 +3860,7 @@ ID_LIKE="ubuntu debian" assert_eq!(plan.policy, "linux_official_amd_dkms_wrapper"); // Ubuntu-family derivatives ship the Ubuntu kernel, so linux-modules-extra applies. assert!(rendered.contains("linux-modules-extra-$(uname -r)")); - assert!(rendered.contains("https://repo.radeon.com/graphics/7.2.4/ubuntu jammy main")); + assert!(rendered.contains("https://repo.radeon.com/amdgpu/latest/ubuntu jammy main")); assert!(rendered.contains("Execute: sudo apt-get install -y amdgpu-dkms")); } @@ -3581,7 +3883,7 @@ ID_LIKE=debian assert!(plan.supported); // Debian-family maps to the Ubuntu jammy repo and omits linux-modules-extra. - assert!(rendered.contains("https://repo.radeon.com/graphics/7.2.4/ubuntu jammy main")); + assert!(rendered.contains("https://repo.radeon.com/amdgpu/latest/ubuntu jammy main")); assert!(!rendered.contains("linux-modules-extra-$(uname -r)")); assert!(rendered.contains("amdgpu-dkms")); } @@ -3607,9 +3909,10 @@ ID_LIKE="rhel centos fedora" assert!(plan.mutating); assert_eq!(plan.policy, "linux_official_amd_dkms_wrapper"); // EL rebuilds use the vendor-neutral el/ repo path, not rhel/. - assert!(rendered.contains("repo.radeon.com/amdgpu-install/7.2.4/el/9.6/")); + assert!( + rendered.contains("baseurl=https://repo.radeon.com/amdgpu/latest/el/9.6/main/x86_64") + ); assert!(!rendered.contains("/rhel/9.6/")); - assert!(rendered.contains("amdgpu-install-7.2.4.70204-1.el9.noarch.rpm")); // el9 uses the version-aware standard-kernel prepare commands. assert!(rendered.contains("kernel-devel-matched-$(uname -r)")); assert!(rendered.contains("Execute: sudo dnf install -y amdgpu-dkms")); @@ -3633,8 +3936,9 @@ ID_LIKE="rhel centos fedora" assert!(plan.supported); // EL 8 is served from the major-version path (el/8), matching AMD docs. - assert!(rendered.contains("repo.radeon.com/amdgpu-install/7.2.4/el/8/")); - assert!(rendered.contains("-1.el8.noarch.rpm")); + assert!( + rendered.contains("baseurl=https://repo.radeon.com/amdgpu/latest/el/8/main/x86_64") + ); // el8 has no kernel-devel-matched package. assert!(!rendered.contains("kernel-devel-matched")); assert!(rendered.contains("kernel-devel-$(uname -r)")); @@ -3682,7 +3986,9 @@ ID_LIKE=fedora let rendered = render_driver_install_plan(&plan, false, false); assert!(plan.supported); - assert!(rendered.contains("repo.radeon.com/amdgpu-install/7.2.4/rhel/9.7/")); + assert!( + rendered.contains("baseurl=https://repo.radeon.com/amdgpu/latest/rhel/9.7/main/x86_64") + ); assert!(!rendered.contains("/el/9.7/")); } diff --git a/apps/rocm/src/main.rs b/apps/rocm/src/main.rs index 37d4c6e426..e39e7c1d36 100644 --- a/apps/rocm/src/main.rs +++ b/apps/rocm/src/main.rs @@ -12012,14 +12012,13 @@ pub(crate) mod tests { } } - /// Clear the two AMD driver-install override vars for the duration of the - /// test, so a value exported in the developer's or runner's shell cannot - /// leak into a plan and make its resolved `repo_version`/package release - /// disagree with the assertion. + /// Clear the AMD driver-version override for the duration of the test, so + /// a value exported in the developer's or runner's shell cannot leak into + /// a plan and make its resolved `repo_version_expr` disagree with the + /// assertion. pub(crate) fn with_amd_overrides_cleared() -> Self { let mut env = Self::new(); - env.clear("ROCM_CLI_AMDGPU_VERSION"); - env.clear("ROCM_CLI_AMDGPU_PACKAGE_RELEASE"); + env.clear("ROCM_CLI_AMDGPU_DRIVER_VERSION"); env } diff --git a/apps/rocm/src/runtime_install_finalize.rs b/apps/rocm/src/runtime_install_finalize.rs index c49d19f5c2..71e64eca50 100644 --- a/apps/rocm/src/runtime_install_finalize.rs +++ b/apps/rocm/src/runtime_install_finalize.rs @@ -152,9 +152,8 @@ pub(crate) const fn empty_as_unknown(value: &str) -> &str { /// when the former is absent (per `os-release(5)`). /// /// Deliberately not routed through `rocm_core::host_path`: every caller builds -/// a package-manager plan (`apt`, `dnf`, `amdgpu-install`) that then runs -/// against the real machine, so a simulated host root must not choose its -/// distro. The descriptive distro name `examine` reports comes from +/// a package-manager plan (`apt`, `dnf`, `zypper`) that then runs against the +/// real machine, so a simulated host root must not choose its distro. The descriptive distro name `examine` reports comes from /// `ExamineSummary::gather`'s `distro` field, which does follow a simulated /// root. pub(crate) fn real_os_release() -> rocm_core::hardware_root::OsRelease { diff --git a/crates/rocm-core/src/diagnose.rs b/crates/rocm-core/src/diagnose.rs index 7f9434a026..8771ddd7c8 100644 --- a/crates/rocm-core/src/diagnose.rs +++ b/crates/rocm-core/src/diagnose.rs @@ -846,7 +846,9 @@ fn check_3_rocm_kernel_unsupported(e: &Examination, symptom: &str) -> Diagnosis "# Compare to the live AMD matrix:".to_owned(), "# https://rocm.docs.amd.com/projects/install-on-linux/en/latest/reference/system-requirements.html".to_owned(), "# If your kernel is above the supported range, install the HWE".to_owned(), - "# kernel that matches ROCm, or rerun amdgpu-install with --no-dkms.".to_owned(), + "# kernel that matches ROCm, then rerun `rocm install driver --dkms`.".to_owned(), + "# To avoid the DKMS build entirely, use `rocm install sdk` instead:".to_owned(), + "# it installs the userspace ROCm stack without touching the kernel module.".to_owned(), ], fix_id: "fix-3-rocm-kernel".to_owned(), needs_reboot: true, @@ -1106,25 +1108,48 @@ fn check_7_stale_repos(e: &Examination, symptom: &str) -> Diagnosis { if score <= 0 { return zero("fix-7-stale-repos", "Stale ROCm repos"); } - let mut commands = - vec!["ls /etc/apt/sources.list.d/ | grep -iE 'rocm|amdgpu|radeon' || true".to_owned()]; + let family = repo_pkg_family(e); + let mut commands = Vec::new(); + match family { + "apt" => commands + .push("ls /etc/apt/sources.list.d/ | grep -iE 'rocm|amdgpu|radeon' || true".to_owned()), + "dnf" => { + commands + .push("ls /etc/yum.repos.d/ | grep -iE 'rocm|amdgpu|radeon' || true".to_owned()); + } + "zypper" => commands + .push("ls /etc/zypp/repos.d/ | grep -iE 'rocm|amdgpu|radeon' || true".to_owned()), + _ => {} + } for r in repos { commands.push(format!( "# sudo mv {r} {r}.bak # quarantine, do not delete yet" )); } - commands.push("sudo apt update".to_owned()); - commands.push("# If apt now resolves, reinstall via the correct method only:".to_owned()); + match family { + "apt" => commands.push("sudo apt update".to_owned()), + "dnf" => commands.push("sudo dnf clean all".to_owned()), + "zypper" => commands.push("sudo zypper refresh".to_owned()), + _ => {} + } commands.push( - "# amdgpu-install --usecase=rocm,hip --no-dkms # if you want amdgpu-install".to_owned(), + "# If the package manager now resolves, reinstall the driver only (review the plan, then approve):" + .to_owned(), ); - commands.push("# or use the distro packages exclusively".to_owned()); + commands.push("# rocm install driver --dkms # review the plan".to_owned()); + commands.push("# rocm install driver --dkms --yes # reinstalls the driver only".to_owned()); + let verify = match family { + "apt" => "sudo apt update 2>&1 | tail -n 20".to_owned(), + "dnf" => "sudo dnf clean all 2>&1 | tail -n 20".to_owned(), + "zypper" => "sudo zypper refresh 2>&1 | tail -n 20".to_owned(), + _ => "rocm examine --json | grep -q '\"rocm_install_method\"'".to_owned(), + }; let fix = Fix { - summary: "Quarantine duplicate ROCm/AMDGPU repo files and resolve apt before re-running any installer.".to_owned(), + summary: "Quarantine duplicate ROCm/AMDGPU repo files and resolve the package manager before re-running any installer.".to_owned(), commands, needs_sudo: true, fix_id: "fix-7-stale-repos".to_owned(), - verify: "sudo apt update 2>&1 | tail -n 20".to_owned(), + verify, ..Fix::default() }; finalize( @@ -1420,43 +1445,131 @@ fn check_11_iommu_hang(e: &Examination, symptom: &str) -> Diagnosis { ) } -fn check_12_amdgpu_install_broken(e: &Examination, symptom: &str) -> Diagnosis { +/// Best-effort package-manager family for this host: prefer the family +/// implied by the repo dir the marker files live under, since that's the +/// config these commands act on, and fall back to the same `ID_LIKE`-aware +/// resolver `openmpi` uses only when no repo file was found -- restricted to +/// apt/dnf/zypper, the only families this check has remediation for: a +/// pacman host (which `openmpi`'s resolver can return, for its own, +/// unrelated library installers) falls back to `"unknown"`, rather than the +/// remediation commands mismatching a real "pacman" answer. +fn repo_pkg_family(e: &Examination) -> &'static str { + if e.rocm_repos_seen.iter().any(|r| r.contains("/etc/apt/")) { + return "apt"; + } + if e.rocm_repos_seen + .iter() + .any(|r| r.contains("/etc/yum.repos.d/")) + { + return "dnf"; + } + if e.rocm_repos_seen.iter().any(|r| r.contains("/etc/zypp/")) { + return "zypper"; + } + // The two `match family` sites below only implement apt/dnf/zypper + // remediation (this check has no pacman-based repo-native ROCm install to + // recover, unlike `openmpi`'s library installers) -- filter the resolver's + // fourth possible answer out here, rather than let it silently fall + // through to a wrong default and print an apt command on a pacman host. + // Both `match family` arms below treat this `"unknown"` sentinel the same + // as their other unhandled cases: no package-manager-specific command. + crate::openmpi::resolve_package_manager( + &e.distro_id.to_ascii_lowercase(), + &e.distro_id_like.to_ascii_lowercase(), + ) + .filter(|pm| { + matches!( + pm, + crate::openmpi::PackageManager::Apt + | crate::openmpi::PackageManager::Dnf + | crate::openmpi::PackageManager::Zypper + ) + }) + .map_or("unknown", crate::openmpi::PackageManager::as_str) +} + +/// Whether `rocm_install_method` indicates a package-manager-driven install, +/// covering both the marker-file-based `"repo-native"` value and the +/// dpkg/rpm-query fallback's `"apt"`/`"dnf"` (see `probe_rocm_install` in +/// `examine.rs`): a host without one of `REPO_NATIVE_INSTALL_MARKERS` present +/// but whose package manager confirms `rocm-hip-runtime` is installed is +/// still repo-native-managed, just detected a different way. +fn is_repo_native_installed(method: &str) -> bool { + matches!(method, "repo-native" | "apt" | "dnf") +} + +fn check_12_repo_native_broken(e: &Examination, symptom: &str) -> Diagnosis { let mut score = 0; let mut evidence = Vec::new(); let method = &e.rocm_install_method; - if method == "amdgpu-install" { - evidence.push("ROCm was installed via amdgpu-install".to_owned()); + if is_repo_native_installed(method) { + evidence.push("ROCm was installed via the repo-native package-manager flow".to_owned()); } let (kw_score, kw_ev) = keyword_score(symptom, KEYWORDS_DPKG_BROKEN); score += kw_score; evidence.extend(kw_ev); - if method == "amdgpu-install" && kw_score > 0 { + if is_repo_native_installed(method) && kw_score > 0 { score += 20; } if score <= 0 { - return zero("fix-12-installer", "amdgpu-install broken state"); + return zero("fix-12-installer", "repo-native install broken state"); + } + let family = repo_pkg_family(e); + let mut commands = vec!["# Clear the half-configured package/DKMS state first.".to_owned()]; + match family { + "apt" => { + commands.push("sudo dpkg --configure -a".to_owned()); + commands.push("sudo apt-get install -f".to_owned()); + commands.push("sudo apt-get purge -y amdgpu-dkms".to_owned()); + } + "dnf" => commands.push("sudo dnf remove -y amdgpu-dkms".to_owned()), + "zypper" => commands.push("sudo zypper remove -y amdgpu-dkms".to_owned()), + _ => {} } + commands.push( + "# Quarantine (do not delete) the repo files, then let the package manager".to_owned(), + ); + commands.push("# forget the broken state before reinstalling.".to_owned()); + if e.rocm_repos_seen.is_empty() { + commands.push( + "# sudo mv /etc/apt/sources.list.d/amdgpu.list /etc/apt/sources.list.d/amdgpu.list.bak # or the yum/zypp equivalent".to_owned(), + ); + } else { + for r in &e.rocm_repos_seen { + commands.push(format!( + "# sudo mv {r} {r}.bak # quarantine, do not delete yet" + )); + } + } + match family { + "apt" => commands.push("sudo apt update".to_owned()), + "dnf" => commands.push("sudo dnf clean all".to_owned()), + "zypper" => commands.push("sudo zypper refresh".to_owned()), + _ => {} + } + commands.push("# Reinstall via rocm-cli's repo-native flow:".to_owned()); + commands.push("rocm install driver --dkms --yes".to_owned()); + let fix = Fix { - summary: "Run amdgpu-install's documented uninstall sequence to clear the half-configured state, THEN reinstall without the flag that broke it.".to_owned(), - commands: vec![ - "sudo amdgpu-install --uninstall".to_owned(), - "sudo apt autoremove --purge -y".to_owned(), - "sudo apt update".to_owned(), - "# Reinstall. Drop --accept-eula if you used it previously; the".to_owned(), - "# newer installer rejects it and leaves a half-configured repo.".to_owned(), - "sudo amdgpu-install --usecase=rocm,hip".to_owned(), - ], + summary: "Clear the half-configured package/DKMS state, quarantine the repo-native install's repo files, THEN reinstall via `rocm install driver --dkms --yes`.".to_owned(), + commands, needs_sudo: true, needs_reboot: true, fix_id: "fix-12-installer".to_owned(), - verify: "dpkg -l | grep -E 'rocm|amdgpu' | head -n 20 && rocminfo | head -n 5".to_owned(), - notes: vec!["If `apt autoremove` warns it will remove unrelated packages, stop and resolve those by hand before continuing.".to_owned()], + // Query the package manager's own records, not `rocm examine`'s + // self-reported `rocm_install_method` marker: that marker is set from + // repo-marker-file presence before dpkg/rpm is consulted (see + // `probe_rocm_install`), so a repo file left behind by a failed + // `install --dkms` keeps the marker true even though the package + // never actually installed. + verify: "(dpkg -l 2>/dev/null | grep -qE 'rocm|amdgpu' || rpm -qa 2>/dev/null | grep -qE 'rocm|amdgpu') && rocminfo | head -n 5".to_owned(), + notes: vec!["If the purge/remove step warns it will take unrelated packages with it, stop and resolve those by hand before continuing.".to_owned()], ..Fix::default() }; finalize( "fix-12-installer", - "amdgpu-install left a broken state (repo regression / partial DKMS)", + "Repo-native install left a broken state (repo regression / partial DKMS)", score, evidence, fix, @@ -2715,7 +2828,7 @@ const CHECKERS: &[Checker] = &[ (check_9_igpu_dgpu_collision, &["linux", "windows"]), (check_10_container_devices, &["linux"]), (check_11_iommu_hang, &["linux"]), - (check_12_amdgpu_install_broken, &["linux"]), + (check_12_repo_native_broken, &["linux"]), (check_13_hip_sdk_missing, &["windows"]), (check_14_adrenalin_too_old, &["windows"]), (check_15_msvc_redist, &["windows"]), @@ -6845,4 +6958,380 @@ mod tests { assert_eq!(v["min_score_for_match"], 50); assert_eq!(v["high_confidence_threshold"], 75); } + + #[test] + fn repo_pkg_family_prefers_seen_repos_over_distro_id() { + let mut e = linux_base(); + e.distro_id = "sles".to_owned(); + e.rocm_repos_seen = vec!["/etc/apt/sources.list.d/amdgpu.list".to_owned()]; + assert_eq!(repo_pkg_family(&e), "apt"); + } + + #[test] + fn repo_pkg_family_detects_dnf_and_zypper_from_seen_repos() { + let mut e = linux_base(); + e.rocm_repos_seen = vec!["/etc/yum.repos.d/amdgpu.repo".to_owned()]; + assert_eq!(repo_pkg_family(&e), "dnf"); + + e.rocm_repos_seen = vec!["/etc/zypp/repos.d/amdgpu.repo".to_owned()]; + assert_eq!(repo_pkg_family(&e), "zypper"); + } + + #[test] + fn repo_pkg_family_falls_back_to_distro_id_when_no_repo_seen() { + let mut e = linux_base(); + e.distro_id = "sles".to_owned(); + assert_eq!(repo_pkg_family(&e), "zypper"); + + e.distro_id = "rocky".to_owned(); + assert_eq!(repo_pkg_family(&e), "dnf"); + + e.distro_id = "ubuntu".to_owned(); + assert_eq!(repo_pkg_family(&e), "apt"); + } + + #[test] + fn repo_pkg_family_fallback_is_id_like_aware() { + // Amazon Linux has no ROCm repo file in this scenario and isn't in + // the old hardcoded list; it must not default to "apt". + let mut e = linux_base(); + e.distro_id = "amzn".to_owned(); + assert_eq!(repo_pkg_family(&e), "dnf"); + + // A RHEL rebuild with an unrecognized ID must still resolve via + // ID_LIKE, same as openmpi's resolver. + let mut e = linux_base(); + e.distro_id = "some-rhel-rebuild".to_owned(); + e.distro_id_like = "rhel fedora".to_owned(); + assert_eq!(repo_pkg_family(&e), "dnf"); + } + + #[test] + fn repo_pkg_family_degrades_to_unknown_on_pacman_hosts() { + // openmpi's resolver can answer "pacman" (it has its own, unrelated + // library installers for Arch et al.), but this check has no pacman + // remediation -- it must not surface "pacman" verbatim, nor coerce to + // "apt" (which would make check_12 print apt/dpkg commands on an Arch + // host); both `match family` arms in check_12 treat "unknown" as "no + // package-manager-specific command". + let mut e = linux_base(); + e.distro_id = "arch".to_owned(); + assert_eq!(repo_pkg_family(&e), "unknown"); + } + + #[test] + fn stale_repos_on_a_sles_host_gets_zypper_commands_not_apt() { + // A SLES host whose repo files now live under /etc/zypp/repos.d/ (the + // new zypp scan this diff adds) must not be told to run apt/dpkg + // commands: `check_7` must branch on `repo_pkg_family` the same way + // `check_12` already does. + let mut e = linux_base(); + e.distro_id = "sles".to_owned(); + e.rocm_repos_seen = vec![ + "/etc/zypp/repos.d/amdgpu.repo".to_owned(), + "/etc/zypp/repos.d/rocm.repo".to_owned(), + ]; + let report = diagnose(&e, "stale repo conflict"); + let hit = report + .matched + .iter() + .find(|d| d.id == "fix-7-stale-repos") + .expect("duplicate repo files should be diagnosed"); + let fix = hit.fix.as_ref().unwrap(); + let commands = fix.commands.join("\n"); + assert!( + commands.contains("/etc/zypp/repos.d/") && commands.contains("sudo zypper refresh"), + "a SLES host must get zypper remediation: {commands}" + ); + assert!( + !commands.contains("apt") && !commands.contains("dpkg"), + "a SLES host must not be told to run apt/dpkg commands: {commands}" + ); + assert!( + fix.verify.contains("sudo zypper refresh"), + "a SLES host's verify step must also use zypper, not apt: {}", + fix.verify + ); + } + + #[test] + fn stale_repos_on_a_dnf_host_gets_dnf_commands_not_apt() { + // Same drift guard as the SLES/zypper test above, for the dnf family. + let mut e = linux_base(); + e.distro_id = "rocky".to_owned(); + e.rocm_repos_seen = vec![ + "/etc/yum.repos.d/amdgpu.repo".to_owned(), + "/etc/yum.repos.d/rocm.repo".to_owned(), + ]; + let report = diagnose(&e, "stale repo conflict"); + let hit = report + .matched + .iter() + .find(|d| d.id == "fix-7-stale-repos") + .expect("duplicate repo files should be diagnosed"); + let fix = hit.fix.as_ref().unwrap(); + let commands = fix.commands.join("\n"); + assert!( + commands.contains("/etc/yum.repos.d/") && commands.contains("sudo dnf clean all"), + "a dnf host must get dnf remediation: {commands}" + ); + assert!( + !commands.contains("apt") && !commands.contains("dpkg") && !commands.contains("zypper"), + "a dnf host must not be told to run apt/dpkg/zypper commands: {commands}" + ); + assert!( + fix.verify.contains("sudo dnf clean all"), + "a dnf host's verify step must also use dnf, not apt: {}", + fix.verify + ); + } + + #[test] + fn stale_repos_emits_no_package_manager_commands_on_pacman_hosts() { + let mut e = linux_base(); + e.distro_id = "arch".to_owned(); + e.rocm_repos_seen = vec!["/some/rocm.repo".to_owned(), "/some/amdgpu.repo".to_owned()]; + let report = diagnose(&e, "stale repo conflict"); + let hit = report + .matched + .iter() + .find(|d| d.id == "fix-7-stale-repos") + .expect("duplicate repo files should be diagnosed"); + let fix = hit.fix.as_ref().unwrap(); + let commands: Vec<&str> = fix + .commands + .iter() + .map(String::as_str) + .filter(|c| !c.trim_start().starts_with('#')) + .collect(); + assert!( + commands.iter().all(|c| !c.contains("apt") + && !c.contains("dpkg") + && !c.contains("dnf") + && !c.contains("zypper")), + "must not print a foreign package manager's commands on an unresolved/pacman host: {commands:?}" + ); + assert!( + !fix.verify.contains("apt") + && !fix.verify.contains("dnf") + && !fix.verify.contains("zypper"), + "verify step must not assume a foreign package manager on a pacman host: {}", + fix.verify + ); + } + + #[test] + fn repo_native_broken_emits_no_package_manager_commands_on_pacman_hosts() { + let mut e = linux_base(); + e.distro_id = "arch".to_owned(); + e.rocm_install_method = "repo-native".to_owned(); + let report = diagnose( + &e, + "dpkg: error processing package amdgpu-dkms (half-configured)", + ); + let hit = report + .matched + .iter() + .find(|d| d.id == "fix-12-installer") + .expect("repo-native broken state should be diagnosed"); + // Only real (non-comment) commands are package-manager-specific here; + // the commented-out quarantine example always names the apt path as a + // generic illustration ("or the yum/zypp equivalent"), unrelated to + // `family` and out of scope for this check. + let commands: Vec<&str> = hit + .fix + .as_ref() + .unwrap() + .commands + .iter() + .map(String::as_str) + .filter(|c| !c.trim_start().starts_with('#')) + .collect(); + assert!( + commands.iter().all(|c| !c.contains("apt") + && !c.contains("dpkg") + && !c.contains("dnf") + && !c.contains("zypper")), + "must not print a foreign package manager's commands on an unresolved/pacman host: {commands:?}" + ); + } + + #[test] + fn repo_native_broken_fires_and_clears_state_before_reinstall() { + let mut e = linux_base(); + e.rocm_install_method = "repo-native".to_owned(); + e.rocm_repos_seen = vec!["/etc/apt/sources.list.d/amdgpu.list".to_owned()]; + let report = diagnose( + &e, + "dpkg: error processing package amdgpu-dkms (half-configured)", + ); + let hit = report + .matched + .iter() + .find(|d| d.id == "fix-12-installer") + .expect("repo-native broken state should be diagnosed"); + let fix = hit.fix.as_ref().unwrap(); + let commands = fix.commands.join("\n"); + assert!( + commands.contains("dpkg --configure -a"), + "must clear the half-configured dpkg state before reinstalling: {commands}" + ); + assert!( + commands.contains("purge -y amdgpu-dkms"), + "must purge the broken driver package: {commands}" + ); + assert!( + commands.contains("# sudo mv /etc/apt/sources.list.d/amdgpu.list"), + "repo quarantine command must be commented out, not ready-to-run: {commands}" + ); + assert!( + commands.contains("rocm install driver --dkms --yes"), + "reinstall command must actually install (bare 'rocm install driver' is a non-mutating preflight no-op): {commands}" + ); + assert!( + fix.verify.contains("dpkg") && fix.verify.contains("rpm"), + "verify must query real dpkg/rpm package state, not the self-reported \ + rocm_install_method marker (set from repo-file presence before the \ + package actually installs): {}", + fix.verify + ); + assert!( + hit.evidence + .iter() + .any(|l| l.contains("installed via the repo-native package-manager flow")), + "positive control: the repo-native evidence line must appear when the method really is repo-native: {:?}", + hit.evidence + ); + } + + #[test] + fn repo_native_broken_on_a_dnf_host_gets_dnf_commands_not_apt() { + let mut e = linux_base(); + e.distro_id = "rocky".to_owned(); + e.rocm_install_method = "repo-native".to_owned(); + e.rocm_repos_seen = vec!["/etc/yum.repos.d/amdgpu.repo".to_owned()]; + let report = diagnose( + &e, + "dpkg: error processing package amdgpu-dkms (half-configured)", + ); + let hit = report + .matched + .iter() + .find(|d| d.id == "fix-12-installer") + .expect("repo-native broken state should be diagnosed"); + let commands = hit.fix.as_ref().unwrap().commands.join("\n"); + assert!( + commands.contains("sudo dnf remove -y amdgpu-dkms") + && commands.contains("sudo dnf clean all"), + "a dnf host must get dnf remediation: {commands}" + ); + assert!( + !commands.contains("apt") && !commands.contains("dpkg") && !commands.contains("zypper"), + "a dnf host must not be told to run apt/dpkg/zypper commands: {commands}" + ); + } + + #[test] + fn repo_native_broken_on_a_zypper_host_gets_zypper_commands_not_apt() { + let mut e = linux_base(); + e.distro_id = "sles".to_owned(); + e.rocm_install_method = "repo-native".to_owned(); + e.rocm_repos_seen = vec!["/etc/zypp/repos.d/amdgpu.repo".to_owned()]; + let report = diagnose( + &e, + "dpkg: error processing package amdgpu-dkms (half-configured)", + ); + let hit = report + .matched + .iter() + .find(|d| d.id == "fix-12-installer") + .expect("repo-native broken state should be diagnosed"); + let commands = hit.fix.as_ref().unwrap().commands.join("\n"); + assert!( + commands.contains("sudo zypper remove -y amdgpu-dkms") + && commands.contains("sudo zypper refresh"), + "a zypper host must get zypper remediation: {commands}" + ); + assert!( + !commands.contains("apt") && !commands.contains("dpkg") && !commands.contains("dnf"), + "a zypper host must not be told to run apt/dpkg/dnf commands: {commands}" + ); + } + + #[test] + fn repo_native_broken_does_not_claim_repo_native_evidence_for_other_install_methods() { + // Regression test: an empty symptom would short-circuit keyword_score to + // 0 before the install-method gate is ever reached, making this pass + // vacuously regardless of whether the gate works. Pass a real dpkg + // symptom instead, matching the positive-control test above, so fix-12 + // still fires (kw_score alone clears MIN_SCORE_FOR_MATCH) but must not + // claim repo-native evidence for a non-repo-native install. + let mut e = linux_base(); + e.rocm_install_method = "runfile-or-tarball".to_owned(); + let report = diagnose( + &e, + "dpkg: error processing package amdgpu-dkms (half-configured)", + ); + let hit = report + .matched + .iter() + .find(|d| d.id == "fix-12-installer") + .expect("dpkg keyword evidence alone should still surface fix-12"); + assert!( + !hit.evidence + .iter() + .any(|l| l.contains("installed via the repo-native package-manager flow")), + "must not claim repo-native evidence for a non-repo-native install: {:?}", + hit.evidence + ); + } + + #[test] + fn repo_native_broken_claims_repo_native_evidence_for_dpkg_rpm_fallback_methods() { + // probe_rocm_install (examine.rs) falls back to the literal "apt"/"dnf" + // when dpkg/rpm confirms the package is installed but no marker file + // was found. Those hosts are still repo-native-managed, so the evidence + // line and +20 score bonus must fire for them too, not just the + // marker-file-detected literal "repo-native" case covered above. + for method in ["apt", "dnf"] { + let mut e = linux_base(); + e.rocm_install_method = method.to_owned(); + let report = diagnose( + &e, + "dpkg: error processing package amdgpu-dkms (half-configured)", + ); + let hit = report + .matched + .iter() + .find(|d| d.id == "fix-12-installer") + .expect("dpkg keyword evidence alone should still surface fix-12"); + assert!( + hit.evidence + .iter() + .any(|l| l.contains("installed via the repo-native package-manager flow")), + "method {method:?} is a repo-native fallback and must claim repo-native evidence: {:?}", + hit.evidence + ); + } + } + + #[test] + fn repo_native_broken_fires_on_dpkg_symptom_regardless_of_install_method() { + // The keyword score alone (half-configured + generic dpkg error = 75) + // clears MIN_SCORE_FOR_MATCH without the +20 repo-native bonus, so + // fix-12 still fires even when rocm_install_method isn't + // "repo-native" -- the method only adds confidence, it doesn't gate + // whether the check fires at all. See the sibling test above for the + // repo-native-evidence-line assertion this used to also make. + let mut e = linux_base(); + e.rocm_install_method = "runfile-or-tarball".to_owned(); + let report = diagnose( + &e, + "dpkg: error processing package amdgpu-dkms (half-configured)", + ); + assert!( + report.matched.iter().any(|d| d.id == "fix-12-installer"), + "dpkg keyword evidence alone should still surface fix-12" + ); + } } diff --git a/crates/rocm-core/src/examine.rs b/crates/rocm-core/src/examine.rs index d0fb7a020d..a02fdac5bc 100644 --- a/crates/rocm-core/src/examine.rs +++ b/crates/rocm-core/src/examine.rs @@ -47,14 +47,19 @@ const TRACKED_ENV_VARS: &[&str] = &[ "PATH", ]; -/// Repo files dropped by the `amdgpu-install` pipeline; their presence marks an -/// amdgpu-install-managed ROCm. -const AMDGPU_INSTALL_MARKERS: &[&str] = &[ +/// AMD ROCm/AMDGPU repo files: `amdgpu.list` / `amdgpu.repo` are written by +/// rocm-cli's own repo-native install flow; `rocm.list` / `radeon.list` / +/// `rocm.repo` are names from AMD's documented manual/legacy setup steps that +/// rocm-cli itself never creates. Either kind marks a package-manager-repo- +/// managed ROCm. +const REPO_NATIVE_INSTALL_MARKERS: &[&str] = &[ "/etc/apt/sources.list.d/amdgpu.list", "/etc/apt/sources.list.d/rocm.list", "/etc/apt/sources.list.d/radeon.list", "/etc/yum.repos.d/amdgpu.repo", "/etc/yum.repos.d/rocm.repo", + "/etc/zypp/repos.d/amdgpu.repo", + "/etc/zypp/repos.d/rocm.repo", ]; /// Marketing-name fragments that identify an AMD APU when `rocminfo` is absent. @@ -209,6 +214,11 @@ pub struct Examination { pub os_version: String, pub distro_id: String, pub distro_version: String, + /// `/etc/os-release` `ID_LIKE`, for `openmpi::resolve_package_manager` + /// fallback matching. Not part of the examine.py wire contract, so it's + /// excluded from JSON. + #[serde(skip)] + pub distro_id_like: String, pub kernel_release: String, pub kernel_cmdline: String, pub is_wsl: bool, @@ -381,6 +391,7 @@ impl Default for Examination { os_version: String::new(), distro_id: String::new(), distro_version: String::new(), + distro_id_like: String::new(), kernel_release: String::new(), kernel_cmdline: String::new(), is_wsl: false, @@ -774,6 +785,7 @@ fn record_distro(e: &mut Examination, read: &crate::hardware_root::OsRelease) { match crate::os_release::parse(read.text()) { Ok(mut fields) => { e.distro_id = fields.remove("ID").unwrap_or_default(); + e.distro_id_like = fields.remove("ID_LIKE").unwrap_or_default(); e.distro_version = fields.remove("VERSION_ID").unwrap_or_default(); } Err(unreadable) => e.probe_failures.push(format!( @@ -1943,6 +1955,36 @@ fn probe_secure_boot(e: &mut Examination) { // ROCm install probe (Linux) // --------------------------------------------------------------------------- +/// Pure marker-path -> install-method mapping, split out from +/// `probe_rocm_install` so it's testable without touching the real +/// filesystem. `existing` is the subset of `REPO_NATIVE_INSTALL_MARKERS` +/// found present on the host; returns `None` when none are present. +fn repo_native_method_from_markers(existing: &[&str]) -> Option<(&'static str, Vec)> { + let seen: Vec = REPO_NATIVE_INSTALL_MARKERS + .iter() + .filter(|m| existing.contains(m)) + .map(|m| (*m).to_owned()) + .collect(); + if seen.is_empty() { + None + } else { + Some(("repo-native", seen)) + } +} + +/// Whether a lowercased repo-directory entry name is a live ROCm/AMDGPU repo +/// file, as opposed to one fix-7/fix-12 already told the user to quarantine +/// (`mv foo foo.bak`). Without this, `amdgpu.list.bak` sitting next to the +/// reinstalled `amdgpu.list` after following that advice counts as a second +/// stale repo and re-triggers the same fix. +// `name` is already lowercased by the caller, so a plain suffix match is fine. +#[allow(clippy::case_sensitive_file_extension_comparisons)] +fn is_live_rocm_repo_file_name(name: &str) -> bool { + let quarantined = + name.ends_with(".bak") || name.ends_with(".save") || name.ends_with(".disabled"); + !quarantined && (name.contains("rocm") || name.contains("amdgpu") || name.contains("radeon")) +} + fn probe_rocm_install(e: &mut Examination) { // Shared with the human `rocm examine` report and the fix-6 PATH runner so // all three agree on which install is the active one. Handles versioned @@ -1957,11 +1999,14 @@ fn probe_rocm_install(e: &mut Examination) { .and_then(|install| install.version) .unwrap_or_default(); - for marker in AMDGPU_INSTALL_MARKERS { - if Path::new(marker).exists() { - e.rocm_install_method = "amdgpu-install".to_owned(); - e.rocm_repos_seen.push((*marker).to_owned()); - } + let existing_markers: Vec<&str> = REPO_NATIVE_INSTALL_MARKERS + .iter() + .copied() + .filter(|m| Path::new(m).exists()) + .collect(); + if let Some((method, seen)) = repo_native_method_from_markers(&existing_markers) { + e.rocm_install_method = method.to_owned(); + e.rocm_repos_seen.extend(seen); } if e.rocm_install_method.is_empty() { @@ -1982,17 +2027,21 @@ fn probe_rocm_install(e: &mut Examination) { e.rocm_install_method = if rocm_dir.is_empty() { "none".to_owned() } else { - "tarball-or-other".to_owned() + "runfile-or-tarball".to_owned() }; } - for dir in ["/etc/apt/sources.list.d", "/etc/yum.repos.d"] { + for dir in [ + "/etc/apt/sources.list.d", + "/etc/yum.repos.d", + "/etc/zypp/repos.d", + ] { let Ok(entries) = std::fs::read_dir(dir) else { continue; }; for entry in entries.flatten() { let name = entry.file_name().to_string_lossy().to_lowercase(); - if name.contains("rocm") || name.contains("amdgpu") || name.contains("radeon") { + if is_live_rocm_repo_file_name(&name) { let full = entry.path().to_string_lossy().into_owned(); if !e.rocm_repos_seen.contains(&full) { e.rocm_repos_seen.push(full); @@ -3261,6 +3310,16 @@ fn oldest_runtime_version(output: &str) -> String { mod tests { use super::*; + #[test] + fn is_live_rocm_repo_file_name_skips_quarantined_files() { + assert!(is_live_rocm_repo_file_name("amdgpu.list")); + assert!(is_live_rocm_repo_file_name("rocm.repo")); + assert!(!is_live_rocm_repo_file_name("amdgpu.list.bak")); + assert!(!is_live_rocm_repo_file_name("amdgpu.list.save")); + assert!(!is_live_rocm_repo_file_name("amdgpu.list.disabled")); + assert!(!is_live_rocm_repo_file_name("unrelated.list")); + } + /// A Linux host with an AMD GPU, so `compute_status` turns on the probe /// failures alone. fn linux_host_with_a_gpu() -> Examination { @@ -3313,6 +3372,22 @@ mod tests { assert!(e.probe_failures.is_empty(), "{:?}", e.probe_failures); } + /// `ID_LIKE` is parsed into `distro_id_like` for + /// `repo_pkg_family`/`openmpi::resolve_package_manager`'s fallback + /// matching, same as `ID`/`VERSION_ID`, even though it's `#[serde(skip)]` + /// and so never shows up by just inspecting the JSON examine output. + #[test] + fn id_like_is_parsed_into_distro_id_like() { + let mut e = linux_host_with_a_gpu(); + record_distro( + &mut e, + &crate::hardware_root::OsRelease::found( + "ID=amzn\nID_LIKE=\"fedora\"\nVERSION_ID=\"2023\"\n", + ), + ); + assert_eq!(e.distro_id_like, "fedora"); + } + /// A file that exists but could not be read is reported as itself — not /// folded into an empty, unreported distro the way `Absent` is, and not /// pointing at the wrong candidate when the fallback was the one that @@ -6214,6 +6289,47 @@ mod tests { assert_eq!(cgroup_only.container_kind, "container"); } + #[test] + fn no_markers_present_yields_no_repo_native_method() { + assert!(repo_native_method_from_markers(&[]).is_none()); + } + + #[test] + fn every_declared_marker_individually_maps_to_repo_native() { + for marker in REPO_NATIVE_INSTALL_MARKERS { + let (method, seen) = + repo_native_method_from_markers(&[marker]).expect("marker should match"); + assert_eq!(method, "repo-native"); + assert_eq!(seen, vec![(*marker).to_owned()]); + } + } + + #[test] + fn multiple_markers_all_recorded_in_declaration_order() { + // Passed in reverse of REPO_NATIVE_INSTALL_MARKERS' declared order to + // confirm the output order tracks the constant, not the input. + let existing = [ + "/etc/zypp/repos.d/amdgpu.repo", + "/etc/apt/sources.list.d/amdgpu.list", + ]; + let (method, seen) = repo_native_method_from_markers(&existing).expect("some"); + assert_eq!(method, "repo-native"); + assert_eq!( + seen, + vec![ + "/etc/apt/sources.list.d/amdgpu.list".to_owned(), + "/etc/zypp/repos.d/amdgpu.repo".to_owned(), + ] + ); + } + + #[test] + fn unrelated_paths_do_not_match_any_marker() { + assert!( + repo_native_method_from_markers(&["/etc/apt/sources.list.d/some-other.list"]).is_none() + ); + } + /// Both `/etc/os-release` reads `rocm examine` makes — the distro fields /// and the distro name — answer from a simulated host root, and through the /// shared parser: a planted file naming a distro no runner has reads as diff --git a/crates/rocm-core/src/fix.rs b/crates/rocm-core/src/fix.rs index a711949429..c4c9a79de3 100644 --- a/crates/rocm-core/src/fix.rs +++ b/crates/rocm-core/src/fix.rs @@ -321,7 +321,7 @@ const RECIPES: &[FixRecipe] = &[ FixRecipe { fix_id: "fix-3-rocm-kernel", title: "ROCm/distro/kernel triple unsupported", - rationale: "ROCm is installed but your kernel/distro combination is outside the supported matrix. Match the kernel to the matrix before reinstalling, or rerun with --no-dkms and accept the risk.", + rationale: "ROCm is installed but your kernel/distro combination is outside the supported matrix. Match the kernel to the matrix first, then rerun `rocm install driver --dkms`. To avoid the DKMS build entirely, use `rocm install sdk` instead: it installs the userspace ROCm stack without touching the kernel module.", commands: &[ "# Cross-check the live AMD matrix before changing anything:", "# https://rocm.docs.amd.com/projects/install-on-linux/en/latest/reference/system-requirements.html", @@ -330,7 +330,7 @@ const RECIPES: &[FixRecipe] = &[ needs_sudo: false, needs_reboot: true, needs_relogin: false, - verify: "lsmod | grep amdgpu && rocminfo | head -n 5", + verify: "lsmod | grep amdgpu && rocminfo | head -n 20", notes: &[], doc_url: Some( "https://rocm.docs.amd.com/projects/install-on-linux/en/latest/reference/system-requirements.html", @@ -406,15 +406,24 @@ const RECIPES: &[FixRecipe] = &[ title: "Quarantine duplicate AMD repos", rationale: "More than one ROCm/AMDGPU repo file exists. The package manager is mixing versions; quarantine the extras before reinstalling.", commands: &[ - "ls /etc/apt/sources.list.d/ | grep -iE 'rocm|amdgpu|radeon'", + "# Run only the line matching your package manager:", + "ls /etc/apt/sources.list.d/ | grep -iE 'rocm|amdgpu|radeon' || true # Debian/Ubuntu", + "ls /etc/yum.repos.d/ | grep -iE 'rocm|amdgpu|radeon' || true # RHEL/Fedora/Rocky/Alma/Oracle", + "ls /etc/zypp/repos.d/ | grep -iE 'rocm|amdgpu|radeon' || true # SLES/openSUSE", "# For each duplicate file:", - "sudo mv /etc/apt/sources.list.d/.list /etc/apt/sources.list.d/.list.bak", - "sudo apt update", + "sudo mv /etc/apt/sources.list.d/.list /etc/apt/sources.list.d/.list.bak # or the yum/zypp equivalent", + "# Run only the line matching your package manager:", + "sudo apt update # Debian/Ubuntu", + "sudo dnf clean all # RHEL/Fedora/Rocky/Alma/Oracle", + "sudo zypper refresh # SLES/openSUSE", ], needs_sudo: true, needs_reboot: false, needs_relogin: false, - verify: "sudo apt update 2>&1 | tail -n 20", + verify: "Run only the line matching your package manager:\n\ + sudo apt update 2>&1 | tail -n 20 # Debian/Ubuntu\n\ + sudo dnf clean all 2>&1 | tail -n 20 # RHEL/Fedora/Rocky/Alma/Oracle\n\ + sudo zypper refresh 2>&1 | tail -n 20 # SLES/openSUSE", notes: &[], doc_url: None, applies_on: PRINT_ON_LINUX, @@ -513,20 +522,30 @@ const RECIPES: &[FixRecipe] = &[ }, FixRecipe { fix_id: "fix-12-installer", - title: "Reset amdgpu-install state and reinstall", - rationale: "amdgpu-install left a half-configured DKMS / repo state. Run the documented uninstall, clean up, and reinstall without the flag that broke things (commonly --accept-eula on newer installers).", + title: "Reset repo-native install state and reinstall", + rationale: "The repo-native package-manager install left a half-configured DKMS / repo state. Clear the broken package state, quarantine the repo files rocm-cli's install wrote, let the package manager forget the broken state, then reinstall via rocm-cli's own repo-native flow.", commands: &[ - "sudo amdgpu-install --uninstall", - "sudo apt autoremove --purge -y", - "sudo apt update", - "sudo amdgpu-install --usecase=rocm,hip", + "# Run only the block matching your package manager. On Debian/Ubuntu, run all", + "# three lines even if an earlier one reports an error -- the purge must not", + "# be skipped just because the half-configured state made `install -f` fail:", + "sudo dpkg --configure -a # Debian/Ubuntu", + "sudo apt-get install -f # Debian/Ubuntu", + "sudo apt-get purge -y amdgpu-dkms # Debian/Ubuntu", + "sudo dnf remove -y amdgpu-dkms # RHEL/Fedora/Rocky/Alma/Oracle", + "sudo zypper remove -y amdgpu-dkms # SLES/openSUSE", + "# sudo mv /etc/apt/sources.list.d/amdgpu.list /etc/apt/sources.list.d/amdgpu.list.bak # or the yum/zypp equivalent; quarantine, do not delete yet", + "# Run only the line matching your package manager:", + "sudo apt update # Debian/Ubuntu", + "sudo dnf clean all # RHEL/Fedora/Rocky/Alma/Oracle", + "sudo zypper refresh # SLES/openSUSE", + "rocm install driver --dkms --yes", ], needs_sudo: true, needs_reboot: true, needs_relogin: false, - verify: "dpkg -l | grep -E 'rocm|amdgpu' | head -n 20 && rocminfo | head -n 5", + verify: "(dpkg -l 2>/dev/null | grep -qE 'rocm|amdgpu' || rpm -qa 2>/dev/null | grep -qE 'rocm|amdgpu') && rocminfo | head -n 5", notes: &[ - "If `apt autoremove --purge` warns it will remove unrelated packages, stop and resolve those by hand before continuing.", + "If the purge/remove step warns it will take unrelated packages with it, stop and resolve those by hand before continuing.", ], doc_url: None, applies_on: PRINT_ON_LINUX, @@ -3640,4 +3659,213 @@ mod tests { has to say it: {named:?}" ); } + + #[test] + fn fix_7_apt_commands_match_the_diagnose_copy_verbatim() { + // Same drift guard as fix_12_apt_commands_match_the_diagnose_copy_verbatim: + // diagnose.rs builds its own per-family command list for fix-7 rather than + // reusing this recipe, so drive diagnose() itself instead of comparing + // against a hardcoded literal that can't detect diagnose.rs drifting. + let e = crate::examine::Examination { + os_family: "linux".to_owned(), + distro_id: "ubuntu".to_owned(), + rocm_repos_seen: vec![ + "/etc/apt/sources.list.d/rocm.list".to_owned(), + "/etc/apt/sources.list.d/amdgpu.list".to_owned(), + ], + ..crate::examine::Examination::default() + }; + let report = crate::diagnose::diagnose(&e, "stale repo conflict"); + let hit = report + .matched + .iter() + .find(|d| d.id == "fix-7-stale-repos") + .expect("duplicate repo files should be diagnosed"); + let diagnose_apt_list_cmd = hit + .fix + .as_ref() + .unwrap() + .commands + .first() + .expect("fix-7 always lists the repo dir first on a recognized family") + .as_str(); + + let recipe = RECIPES + .iter() + .find(|r| r.fix_id == "fix-7-stale-repos") + .expect("fix-7-stale-repos recipe must exist"); + let recipe_apt_list_cmd = recipe + .commands + .iter() + .find(|c| c.trim_end().ends_with("# Debian/Ubuntu") && c.contains("ls /etc/apt")) + .map(|c| c.split('#').next().unwrap().trim_end()) + .expect("recipe must have a commented apt list line"); + assert_eq!( + recipe_apt_list_cmd, diagnose_apt_list_cmd, + "this recipe's apt list command must match what diagnose.rs's apt family actually emits for fix-7-stale-repos" + ); + + // `verify` must also track diagnose.rs's per-family text, not just + // `commands`: diagnose.rs varies `verify` by family too, so compare + // each family's line against what diagnose() actually emits for it. + for (family_repo_dir, marker) in [ + ("/etc/apt/sources.list.d/", "# Debian/Ubuntu"), + ("/etc/yum.repos.d/", "# RHEL/Fedora/Rocky/Alma/Oracle"), + ("/etc/zypp/repos.d/", "# SLES/openSUSE"), + ] { + let e = crate::examine::Examination { + os_family: "linux".to_owned(), + distro_id: "ubuntu".to_owned(), + rocm_repos_seen: vec![ + format!("{family_repo_dir}rocm.repo"), + format!("{family_repo_dir}amdgpu.repo"), + ], + ..crate::examine::Examination::default() + }; + let report = crate::diagnose::diagnose(&e, "stale repo conflict"); + let hit = report + .matched + .iter() + .find(|d| d.id == "fix-7-stale-repos") + .expect("duplicate repo files should be diagnosed"); + let diagnose_verify = hit.fix.as_ref().unwrap().verify.as_str(); + + let recipe_verify_line = recipe + .verify + .lines() + .find(|l| l.trim_end().ends_with(marker)) + .map_or_else( + || panic!("recipe verify must have a line for {marker}"), + |l| l.split('#').next().unwrap().trim(), + ); + assert_eq!( + recipe_verify_line, diagnose_verify, + "this recipe's {marker} verify line must match what diagnose.rs emits for fix-7-stale-repos" + ); + } + } + + #[test] + fn fix_12_recipe_clears_state_before_reinstall_and_keeps_mv_commented() { + let recipe = RECIPES + .iter() + .find(|r| r.fix_id == "fix-12-installer") + .expect("fix-12-installer recipe must exist"); + let commands = recipe.commands.join("\n"); + assert!( + commands.contains("dpkg --configure -a"), + "must clear the half-configured dpkg state before reinstalling: {commands}" + ); + assert!( + commands.contains("purge -y amdgpu-dkms"), + "must purge the broken driver package: {commands}" + ); + assert!( + commands.contains("# sudo mv /etc/apt/sources.list.d/amdgpu.list"), + "repo quarantine command must be commented out, not ready-to-run: {commands}" + ); + assert!( + commands.contains("rocm install driver --dkms --yes"), + "reinstall command must actually install (bare 'rocm install driver' is a non-mutating preflight no-op): {commands}" + ); + assert!( + recipe.verify.contains("dpkg") && recipe.verify.contains("rpm"), + "verify must query real dpkg/rpm package state, not the self-reported \ + rocm_install_method marker (that marker is set from repo-file presence \ + before the package actually installs): {}", + recipe.verify + ); + assert!( + !recipe + .commands + .iter() + .any(|c| c.contains("configure -a &&") || c.contains("install -f &&")), + "the apt block must not chain configure/install -f into the purge with `&&`: \ + a failure there must not skip the purge: {commands}" + ); + } + + #[test] + fn fix_3_verify_matches_the_diagnose_copy_verbatim() { + // No drift guard previously existed between this recipe and + // diagnose.rs's `check_3_rocm_kernel_unsupported` for fix-3 (unlike + // fix-7/fix-12's `commands`, fix-3's `commands` legitimately differ -- + // diagnose.rs injects the host's live kernel/distro/rocm values into a + // comment this host-unaware recipe can't know -- but `verify` has no + // such excuse to diverge). + let e = crate::examine::Examination { + os_family: "linux".to_owned(), + rocm_version: "6.4.1".to_owned(), + amdgpu_loaded: Some(false), + ..crate::examine::Examination::default() + }; + let report = crate::diagnose::diagnose(&e, ""); + let hit = report + .matched + .iter() + .find(|d| d.id == "fix-3-rocm-kernel") + .expect("rocm installed with amdgpu not loaded should be diagnosed"); + let diagnose_verify = hit.fix.as_ref().unwrap().verify.as_str(); + + let recipe = RECIPES + .iter() + .find(|r| r.fix_id == "fix-3-rocm-kernel") + .expect("fix-3-rocm-kernel recipe must exist"); + assert_eq!( + recipe.verify, diagnose_verify, + "this recipe's verify step must match what diagnose.rs emits for fix-3-rocm-kernel" + ); + } + + #[test] + fn fix_12_apt_commands_match_the_diagnose_copy_verbatim() { + // `crate::diagnose` builds its own apt command list for fix-12 rather + // than reusing this recipe (it branches per detected package-manager + // family, which this catalog entry cannot do -- it prints guidance for + // every family at once). Drive `diagnose()` itself so a drift between + // the two copies actually fails this test, rather than comparing + // against a hardcoded literal that can't detect diagnose.rs changing + // out from under it. + let e = crate::examine::Examination { + os_family: "linux".to_owned(), + distro_id: "ubuntu".to_owned(), + rocm_install_method: "repo-native".to_owned(), + ..crate::examine::Examination::default() + }; + let report = crate::diagnose::diagnose( + &e, + "dpkg: error processing package amdgpu-dkms (half-configured)", + ); + let hit = report + .matched + .iter() + .find(|d| d.id == "fix-12-installer") + .expect("repo-native broken state should be diagnosed"); + let diagnose_apt_commands: Vec<&str> = hit + .fix + .as_ref() + .unwrap() + .commands + .iter() + .map(String::as_str) + .filter(|c| !c.trim_start().starts_with('#')) + .take(3) + .collect(); + + let recipe = RECIPES + .iter() + .find(|r| r.fix_id == "fix-12-installer") + .expect("fix-12-installer recipe must exist"); + let apt_commands_without_trailing_comment: Vec<&str> = recipe + .commands + .iter() + .filter(|c| c.trim_end().ends_with("# Debian/Ubuntu")) + .map(|c| c.split('#').next().unwrap().trim_end()) + .take(3) + .collect(); + assert_eq!( + apt_commands_without_trailing_comment, diagnose_apt_commands, + "this recipe's apt lines must match what diagnose.rs's apt family actually emits for fix-12-installer" + ); + } } diff --git a/crates/rocm-core/src/openmpi.rs b/crates/rocm-core/src/openmpi.rs index 3fbbe5b1d6..5c7792ef93 100644 --- a/crates/rocm-core/src/openmpi.rs +++ b/crates/rocm-core/src/openmpi.rs @@ -546,7 +546,7 @@ fn scan_libnuma_path() -> Option { } #[derive(Debug, Clone, Copy, PartialEq, Eq)] -enum PackageManager { +pub(crate) enum PackageManager { Apt, Dnf, Zypper, @@ -554,7 +554,7 @@ enum PackageManager { } impl PackageManager { - const fn as_str(self) -> &'static str { + pub(crate) const fn as_str(self) -> &'static str { match self { Self::Apt => "apt", Self::Dnf => "dnf", @@ -1180,7 +1180,7 @@ pub fn is_protected_rocm_package(package: &str) -> bool { PREFIXES.iter().any(|prefix| package.starts_with(prefix)) } -fn resolve_package_manager(os_id: &str, id_like: &str) -> Option { +pub(crate) fn resolve_package_manager(os_id: &str, id_like: &str) -> Option { const APT: &[&str] = &[ "ubuntu", "debian", diff --git a/docs/manual-testing.md b/docs/manual-testing.md index 99810713c8..9001d7ba48 100644 --- a/docs/manual-testing.md +++ b/docs/manual-testing.md @@ -254,6 +254,23 @@ fallback paired an architecture line with the wrong GPU. On that machine `rocm diagnose` must **not** report `info-20-gpu-no-rocm-support` at all — the discrete card does have ROCm support, so the whole-machine claim is false. +## 2b. Bare-Metal Driver Install + +On a real apt/dnf/zypper Linux host: + +```bash +rocm install driver --dry-run +``` + +Expected result: the plan names the floating `latest` amdgpu release unless +`ROCM_CLI_AMDGPU_DRIVER_VERSION` is set, in which case it names that version +instead. A malformed override (e.g. containing a space or `'`) is refused with +a reason naming `ROCM_CLI_AMDGPU_DRIVER_VERSION`, not silently ignored. + +On an Ubuntu 26.04 host, expect `supported: false` instead: `repo.radeon.com` +has no DKMS repo for it yet (the amdgpu driver ships in-tree), so the plan +directs you to `apt install rocm` rather than naming any DKMS commands. + ## 3. Lemonade GPU Verification Lemonade is the default local assistant/server engine. Serve a small assistant diff --git a/docs/testing.md b/docs/testing.md index d4432a028a..71e205d041 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -1596,6 +1596,35 @@ rocm --bin rocm wsl_rocdxg`). Running it end to end needs a WSL2 host with `/dev/dxg` and dxcore present, since the plan refuses before installing otherwise. +## Bare-metal driver install + +On Linux bare metal, `rocm install driver` defaults to the floating `latest` +amdgpu release; `ROCM_CLI_AMDGPU_DRIVER_VERSION` overrides it (replacing the +retired `ROCM_CLI_AMDGPU_VERSION`/`ROCM_CLI_AMDGPU_PACKAGE_RELEASE` pair). An +override that isn't a plain version token is refused rather than silently +falling back, since it is interpolated into privileged shell commands: + +```bash +cargo test -p rocm --bin rocm driver_install +``` + +`driver-install-04` in +[driver_install.feature](../tests/e2e-cucumber/features/driver_install.feature) +asserts the apt repo file and signing key this plan writes on a real bare-metal +Linux host. `examine --json`'s `rocm_install_method` also renamed +`amdgpu-install` to `repo-native` and `tarball-or-other` to +`runfile-or-tarball`; see `examine-29` in +[examine.feature](../tests/e2e-cucumber/features/examine.feature). + +On Ubuntu 26.04, `repo.radeon.com` does not yet publish a matching `resolute` +DKMS repo (the amdgpu driver ships in-tree instead), so the plan comes back +`supported: false` and directs the user to `apt install rocm`. This arm is +covered at the unit level by +`driver_plan_ubuntu_2604_uses_native_archive_guidance` and its two neighbors in +`driver_install.rs`, but has no e2e/Gherkin coverage: `read_os_release()` reads +the live `/etc/os-release` with no override, so no lane or host running a +different Ubuntu release can reach this arm through the CLI itself. + ## /etc/os-release Every Rust reader of `/etc/os-release` parses it with diff --git a/doctor-catalog.json b/doctor-catalog.json index dbe36976ae..c48bd2c152 100644 --- a/doctor-catalog.json +++ b/doctor-catalog.json @@ -187,7 +187,7 @@ }, { "id": "fix-12-installer", - "title": "Reset amdgpu-install state and reinstall", + "title": "Reset repo-native install state and reinstall", "platforms": [ { "os": "linux", diff --git a/skills/rocm-doctor/SKILL.md b/skills/rocm-doctor/SKILL.md index 120cf49331..f3575e5312 100644 --- a/skills/rocm-doctor/SKILL.md +++ b/skills/rocm-doctor/SKILL.md @@ -11,7 +11,7 @@ description: >- permission denied on /dev/kfd, "ROCk module is NOT loaded", a missing libamdhip64.so / amdhip64_6.dll / hipblas.dll / vcruntime140_1.dll, an HSA_OVERRIDE_GFX_VERSION page fault, an iGPU+dGPU crash, a container that can't - see the GPU, or an amdgpu-install / DKMS failure. Backed by the `rocm` CLI + see the GPU, or a repo-native package-manager install / DKMS failure. Backed by the `rocm` CLI (`rocm examine` / `rocm diagnose` / `rocm fix`); this skill is a thin driver over those commands, not a re-implementation. --- diff --git a/skills/rocm-doctor/reference.md b/skills/rocm-doctor/reference.md index ac22f795e8..84a06220f6 100644 --- a/skills/rocm-doctor/reference.md +++ b/skills/rocm-doctor/reference.md @@ -116,12 +116,12 @@ reporting confident nonsense. | `fix-4-render-group` | linux | User not in `render`/`video` group (or `/dev/kfd` owned by the other group) | cannot open `/dev/kfd`, permission denied | auto | | `fix-5-amdgpu-load` | linux | `amdgpu` module not loaded (or blacklisted) | "ROCk module is NOT loaded", blacklist entry, Secure Boot | print-only | | `fix-6-path` | linux/windows/wsl | ROCm/HIP binaries not on PATH after install | `rocminfo: command not found`, `hipInfo` missing from PATH | auto | -| `fix-7-stale-repos` | linux | Stale/conflicting APT/DNF repos from prior installer runs | apt 404 `repo.radeon.com`, unmet deps, ≥2 ROCm repo files | print-only | +| `fix-7-stale-repos` | linux | Stale/conflicting APT/DNF/zypper repos from prior installer runs | apt 404 `repo.radeon.com`, unmet deps, ≥2 ROCm repo files | print-only | | `fix-8-wheel-rocm` | linux/windows/wsl | Framework wheel built for a different ROCm major than the system | `libamdhip64.so.X` / `amdhip64_X.dll` load failure | print-only | | `fix-9-igpu-dgpu` | linux/windows | iGPU enumerated alongside dGPU, destabilising the runtime | APU + discrete AMD present, `HIP_VISIBLE_DEVICES` unset, crash/segfault | needs-arg | | `fix-10-container` | linux | Container can't see `/dev/kfd` or `/dev/dri/renderD*` | running in docker/podman, kfd/render devices missing | print-only | | `fix-11-iommu` | linux | Multi-GPU hang with IOMMU enabled | ≥2 AMD GPUs, `iommu=` not `pt`, hang/deadlock/timeout | print-only | -| `fix-12-installer` | linux | `amdgpu-install` left a broken DKMS / repo state | dpkg half-configured, DKMS failed, `--accept-eula` | print-only | +| `fix-12-installer` | linux | Repo-native package-manager install left a broken DKMS / repo state | dpkg half-configured, DKMS failed, `--accept-eula` | print-only | | `fix-13-hip-sdk-missing` | windows | HIP SDK not installed | **something on the host actually calls into HIP** — an ambient (non-managed-runtime) PyTorch HIP build, or a `GGML_HIP=ON` llama.cpp, either way with a detected AMD GPU — **and** no HIP SDK under Program Files, or `hipInfo.exe` missing from its `bin`. A paste naming any of `amdhip64` not found, "could not find HIP", `HIP_PATH` not set, or `hipInfo` not recognized counts as calling into HIP on its own, with no GPU required. A Vulkan-backed engine (the Lemonade default) or a managed-runtime wheel needs no system SDK, so its absence is not evidence there | print-only | | `fix-14-adrenalin-too-old` | windows | Adrenalin / kernel-mode driver too old for the HIP SDK | `hipInfo` can't enumerate, "driver too old", HSA "no agents found" | print-only | | `fix-15-msvc-redist` | windows | MSVC runtime missing (programs that link it, such as the HIP SDK DLLs and the llama.cpp server, can't load) | `vcruntime140.dll` / `vcruntime140_1.dll` missing | print-only | diff --git a/tests/e2e-cucumber/features/driver_install.feature b/tests/e2e-cucumber/features/driver_install.feature index ac6c1b551f..a75f512151 100644 --- a/tests/e2e-cucumber/features/driver_install.feature +++ b/tests/e2e-cucumber/features/driver_install.feature @@ -29,3 +29,17 @@ Feature: Driver installation planning Scenario: driver-install-03 - Installing a ROCDXG release with no known digest is refused When the user previews driver installation for a ROCDXG release with no known digest Then the driver plan refuses rather than installing an unverified package + + # Every bare-metal Linux lane in this repo (the GitHub-hosted mock job and + # every self-hosted GPU lane) runs Ubuntu, so this is always the apt plan in + # practice -- not the dnf or zypper arms, which have no CI host to run on. + # `--dry-run` previews the plan without writing anything, so this is safe on + # a shared CI host: it asserts on the real `apt_driver_plan` command text + # this binary would use to write /etc/apt/sources.list.d/amdgpu.list and + # import AMD's signing key, the same commands the unit fixtures in + # `driver_install.rs` exercise with a hand-written os-release rather than a + # real one. + @id:driver-install-apt-repo-file-and-key-content @requires-os:linux @requires-bare-metal + Scenario: driver-install-04 - Previewing the driver install on a real apt host plans the repo file and signing key + When the user previews driver installation on this host + Then the driver plan writes an apt repo file with AMD's signing key diff --git a/tests/e2e-cucumber/features/examine.feature b/tests/e2e-cucumber/features/examine.feature index 00c62c3f37..f7b1157ffc 100644 --- a/tests/e2e-cucumber/features/examine.feature +++ b/tests/e2e-cucumber/features/examine.feature @@ -119,7 +119,7 @@ Feature: GPU detection and system inspection Then the inspection reports Linux as the operating system And the inspection reports that the host is WSL - # The dry-run plan used to print the raw `${ROCM_CLI_AMDGPU_VERSION:-...}` shell + # The dry-run plan used to print the raw `${ROCM_CLI_AMDGPU_VERSION:-7.2.4}` shell # placeholder on its `repo_version:` line instead of the effective version, so # the preview a user reviews before approving disagreed with what the install # would actually pull. The plan is rendered on every Linux host regardless of @@ -428,3 +428,22 @@ Feature: GPU detection and system inspection Given a GPU machine whose release file cannot be read When the user inspects that machine in machine-readable form Then the inspection's verdict is degraded, and its only failure says the release file could not be read + + # `rocm_install_method` used to report "amdgpu-install"/"tarball-or-other"; + # renamed to "repo-native"/"runfile-or-tarball" alongside the switch away + # from the amdgpu-install wrapper. It also drives fix-12's remediation + # choice, so a silent revert of the rename would misfire there without any + # test catching it -- this pins the JSON contract directly rather than only + # asserting the human-readable form (examine-06), which never named it. A + # whitelist rather than one pinned value keeps this hermetic: which method + # actually fires depends on this host's real ROCm repo markers (some + # developer machines and self-hosted GPU runners have them, a clean mock + # lane does not), not just on the install this scenario plants. No GPU + # needed: the install is planted by the harness (`plant_unmanaged_rocm`), + # same as examine-06. Linux/WSL only, like examine-12: `probe_rocm_install` + # only runs there, so `rocm_install_method` is empty on Windows. + @id:examine-reports-a-current-install-method-name @requires-os:linux + Scenario: examine-29 - System inspection reports a current install-method name, not the retired amdgpu-install naming + Given a machine with a ROCm install that was not set up by the CLI + When the user inspects the system in machine-readable form + Then the inspection reports a current install-method name diff --git a/tests/e2e-cucumber/tests/e2e/driver_steps.rs b/tests/e2e-cucumber/tests/e2e/driver_steps.rs index f7ea338b09..1f02de960e 100644 --- a/tests/e2e-cucumber/tests/e2e/driver_steps.rs +++ b/tests/e2e-cucumber/tests/e2e/driver_steps.rs @@ -18,6 +18,49 @@ async fn preview_wsl_driver_install(world: &mut E2eWorld) { world.cli_rc = Some(rc); } +#[when("the user previews driver installation on this host")] +async fn preview_driver_install_on_this_host(world: &mut E2eWorld) { + // `--dkms` is required here: every driver-plan builder gates its entire + // command list (repo setup, signing key, package install) behind + // `dkms`, so a plan built without it is empty and the apt-repo-file/key + // assertion below would have nothing to find. + let (stdout, stderr, rc) = + crate::run_rocm_with_env(world, &["install", "driver", "--dkms", "--dry-run"], &[]); + world.cli_output = Some(stdout); + world.cli_stderr = Some(stderr); + world.cli_rc = Some(rc); +} + +#[then("the driver plan writes an apt repo file with AMD's signing key")] +async fn assert_apt_repo_file_and_key(world: &mut E2eWorld) { + let output = world.cli_output.as_ref().expect("no driver plan output"); + // The runner may already be root (the self-hosted WSL runner always is), + // in which case the plan omits the `sudo ` prefix entirely. + let sudo = if rocm_core::openmpi::running_as_root() { + "" + } else { + "sudo " + }; + assert!( + output.contains("policy: linux_official_amd_dkms_wrapper"), + "{output}" + ); + assert!( + output.contains(&format!( + "curl -fsSL https://repo.radeon.com/rocm/rocm.gpg.key | {sudo}gpg --dearmor -o /etc/apt/keyrings/rocm.gpg" + )), + "{output}" + ); + assert!( + output.contains("signed-by=/etc/apt/keyrings/rocm.gpg] https://repo.radeon.com/amdgpu/"), + "{output}" + ); + assert!( + output.contains("tee /etc/apt/sources.list.d/amdgpu.list >/dev/null"), + "{output}" + ); +} + #[when("the user reviews driver installation on this WSL host without approval")] async fn review_wsl_driver_install_without_approval(world: &mut E2eWorld) { let (stdout, stderr, rc) = crate::run_rocm_with_env(world, &["install", "driver"], &[]); diff --git a/tests/e2e-cucumber/tests/e2e/examine_steps.rs b/tests/e2e-cucumber/tests/e2e/examine_steps.rs index 95f0344aaf..e524d71e8c 100644 --- a/tests/e2e-cucumber/tests/e2e/examine_steps.rs +++ b/tests/e2e-cucumber/tests/e2e/examine_steps.rs @@ -201,11 +201,16 @@ async fn assert_driver_plan_repo_version_resolved(world: &mut E2eWorld) { !repo_version.contains("${"), "repo_version still shows an unresolved shell placeholder: {repo_version:?}\n{output}" ); + // The default, unoverridden value is the literal "latest" (ROCM_CLI_AMDGPU_DRIVER_VERSION + // is unset on a normal test host) -- not a numeric ROCm version -- so only + // non-empty and metacharacter-safe are asserted here, matching the same + // filter build_driver_install_plan applies before this value ever reaches + // a single-quoted shell command. + assert!(!repo_version.is_empty(), "repo_version is empty:\n{output}"); assert!( repo_version .chars() - .next() - .is_some_and(|first| first.is_ascii_digit()), + .all(|c| c.is_ascii_alphanumeric() || "._-".contains(c)), "repo_version is not a concrete version string: {repo_version:?}\n{output}" ); } @@ -432,6 +437,34 @@ fn parsed_json(world: &E2eWorld) -> serde_json::Value { .unwrap_or_else(|e| panic!("`examine --json` did not emit valid JSON ({e}):\n{output}")) } +#[then("the inspection reports a current install-method name")] +async fn assert_install_method_is_current(world: &mut E2eWorld) { + let json = parsed_json(world); + let method = json + .get("rocm_install_method") + .and_then(serde_json::Value::as_str) + .unwrap_or_default(); + // `probe_rocm_install` used to name these "amdgpu-install" and + // "tarball-or-other"; a whitelist (rather than pinning one value) is what + // keeps this hermetic across hosts -- which branch actually fires here + // depends on this machine's real /etc/apt (etc.) ROCm repo markers, not + // just on the CLI-managed install this scenario plants, so a host that + // happens to have a real ROCm repo configured (this includes some + // developer machines and self-hosted GPU runners, not just a clean mock + // lane) legitimately resolves to "repo-native" instead of + // "runfile-or-tarball". Either current name passing and either retired + // name failing is exactly the coverage a revert of the rename needs. + // "zypper" is excluded: `probe_rocm_install` reports SUSE via its `rpm -q` + // branch, so it always yields "dnf", never "zypper". "none" is excluded + // too: this scenario plants an install, so "none" would mean the planted + // install went undetected, which is the regression this scenario exists + // to catch, not a value it should tolerate. + assert!( + matches!(method, "apt" | "dnf" | "repo-native" | "runfile-or-tarball"), + "expected a current rocm_install_method name, got {method:?}: {json}" + ); +} + #[when("the user inspects the system both for reading and for scripting")] async fn user_inspects_both_ways(world: &mut E2eWorld) { let (human, _, _) = crate::run_rocm(world, &["examine"]); From 651a6b54e0099eea878c02c3c4c52c3401457c17 Mon Sep 17 00:00:00 2001 From: Juho Vainio Date: Wed, 21 Oct 2026 16:55:06 +0300 Subject: [PATCH 2/7] fix: address review feedback on repo-native package install PR Fixes 8 blocking findings from review of commit ab1a5a47: - driver_install.rs: treat the Ubuntu 26.04 self-hosted GPU lane as a ubuntu_native_archive host (no published repo.radeon.com/amdgpu suite yet) instead of assuming every host matches the apt-repo-file plan; update driver-install-04 and driver_steps.rs to assert whichever policy the real host actually produces. - diagnose.rs: check_7_stale_repos's fallback verify for non-apt/dnf/ zypper hosts no longer greps a JSON key that's always present; it now asserts each flagged repo file is actually gone. - diagnose.rs, fix.rs: fix-12-installer's verify now requires dpkg's `^ii` installed-status line, not just a name match, so a half-configured package (the fix's own target symptom) no longer satisfies "post-fix" state before any remediation runs. - examine.rs: stop #[serde(skip)]-ing distro_id_like so it survives `rocm remote doctor`'s deserialization of a remote's `examine --json` output; add #[serde(default)] for backward compatibility with older remote CLI versions. - driver_install.rs: treat an empty-but-set ROCM_CLI_AMDGPU_DRIVER_VERSION as unset, consistent with sibling resolvers, and add e2e/unit coverage for the malformed-version refusal path. - docs/testing.md, examine.feature: fix a bare backtick path and a stale comment naming a retired env var and wrong default. Verified with cargo fmt --check, cargo build --workspace, cargo clippy --workspace --all-targets -- -D warnings, and cargo test --workspace --all-targets. Left unchanged, pending author decision (see PR comment): pinned vs. floating driver-version default; RHEL/SLES repo path layout; whether fix-12's applicability condition over-fires on distro-packaged hosts. Signed-off-by: Juho Vainio --- apps/rocm/src/driver_install.rs | 44 +++++++++---- apps/rocm/src/remote/doctor.rs | 15 +++++ crates/rocm-core/src/diagnose.rs | 64 ++++++++++++++++++- crates/rocm-core/src/examine.rs | 25 ++++++-- crates/rocm-core/src/fix.rs | 6 +- docs/testing.md | 3 +- .../features/driver_install.feature | 27 ++++---- tests/e2e-cucumber/features/examine.feature | 6 +- tests/e2e-cucumber/tests/e2e/driver_steps.rs | 19 +++++- 9 files changed, 173 insertions(+), 36 deletions(-) diff --git a/apps/rocm/src/driver_install.rs b/apps/rocm/src/driver_install.rs index a3ccf99d8d..d3d71d6411 100644 --- a/apps/rocm/src/driver_install.rs +++ b/apps/rocm/src/driver_install.rs @@ -854,7 +854,12 @@ fn resolve_repo_version_expr() -> Result> { // release should see why it did not take effect, not an unexplained // `latest`. match std::env::var("ROCM_CLI_AMDGPU_DRIVER_VERSION") { + // Set-but-empty is treated the same as unset, matching every other + // optional override in this file (`resolve_rocdxg_verification`, + // `resolve_shell_default_template`): a blank env var is how an env + // file clears an override, not a request to refuse the plan. Err(_) => Ok("latest".to_owned()), + Ok(v) if v.is_empty() => Ok("latest".to_owned()), Ok(v) if is_safe_shell_token(&v) => Ok(v), Ok(v) => Err(Box::new(DriverInstallPlan { supported: false, @@ -984,18 +989,15 @@ fn build_driver_install_plan_at( // to apt_driver_plan(..., true) once it exists, the same way // 22.04/24.04 are handled. // - // No Gherkin/e2e scenario covers this arm's output (AGENTS.md #3), - // and that is not one of #3's two named exceptions (a gated lane, or - // a purely internal change) -- this is user-observable `rocm install - // driver` output on a real OS release. The unit level is NOT the gap: - // `build_driver_install_plan` takes `os_release_text: &str` as a - // plain parameter rather than calling `read_os_release()` itself, so - // this arm is already driven by a hand-written fixture in + // This arm IS reachable through the CLI on a real host -- this PR's + // own self-hosted bare-metal CI runner's `/etc/os-release` reports + // Ubuntu 26.04, which is exactly how `driver-install-04` in + // `driver_install.feature` caught this arm silently taking over that + // scenario's apt-plan premise mid-review. That scenario now asserts + // whichever arm the real host actually falls into, so this one has + // e2e coverage too, alongside the unit fixture in // `driver_plan_ubuntu_2604_uses_native_archive_guidance` and its two - // neighbors below. The gap is only the e2e path: the real `rocm` - // binary's `read_os_release()` reads `/etc/os-release` with no - // override, so no lane or test host can reach this arm through the - // CLI itself. + // neighbors below. ("ubuntu", "26.04") => { let sudo = escalation.prefix(); DriverInstallPlan { @@ -2810,6 +2812,26 @@ VERSION_CODENAME=noble ); } + #[test] + fn driver_plan_treats_empty_version_override_as_unset() { + let mut env = ScopedTestEnv::with_amd_overrides_cleared(); + env.set("ROCM_CLI_AMDGPU_DRIVER_VERSION", ""); + let os_release = r#" +ID=ubuntu +VERSION_ID="24.04" +VERSION_CODENAME=noble +"#; + let plan = build_driver_install_plan_read( + &test_examine("linux", false), + &os_release_found(os_release), + true, + PrivilegeEscalation::Sudo, + ); + + assert_ne!(plan.policy, "invalid_driver_version_override"); + assert_eq!(plan.repo_version_expr, "latest"); + } + #[test] fn driver_plan_accepts_a_valid_version_override_and_uses_it_in_the_url() { let mut env = ScopedTestEnv::with_amd_overrides_cleared(); diff --git a/apps/rocm/src/remote/doctor.rs b/apps/rocm/src/remote/doctor.rs index aeb8d27254..8414fcf700 100644 --- a/apps/rocm/src/remote/doctor.rs +++ b/apps/rocm/src/remote/doctor.rs @@ -286,6 +286,21 @@ mod tests { assert!(!examination.os_family.is_empty()); } + #[test] + fn distro_id_like_survives_the_remote_round_trip() { + // `repo_pkg_family`'s ID_LIKE fallback only ever runs against a + // deserialized remote examination, never a freshly probed local one -- + // so if this field didn't round-trip through JSON, the fallback would + // silently and permanently never fire for `rocm remote doctor`. + let mut value: serde_json::Value = serde_json::from_str(&examine_json()).unwrap(); + value.as_object_mut().unwrap().insert( + "distro_id_like".to_owned(), + serde_json::json!("rhel fedora"), + ); + let parsed = parse_examination(&value.to_string()).expect("examined"); + assert_eq!(parsed.distro_id_like, "rhel fedora"); + } + #[test] fn a_remote_on_another_version_says_so_instead_of_failing_obscurely() { let error = parse_examination(r#"{"unexpected": true}"#) diff --git a/crates/rocm-core/src/diagnose.rs b/crates/rocm-core/src/diagnose.rs index 8771ddd7c8..8fa6ca41e4 100644 --- a/crates/rocm-core/src/diagnose.rs +++ b/crates/rocm-core/src/diagnose.rs @@ -1142,7 +1142,18 @@ fn check_7_stale_repos(e: &Examination, symptom: &str) -> Diagnosis { "apt" => "sudo apt update 2>&1 | tail -n 20".to_owned(), "dnf" => "sudo dnf clean all 2>&1 | tail -n 20".to_owned(), "zypper" => "sudo zypper refresh 2>&1 | tail -n 20".to_owned(), - _ => "rocm examine --json | grep -q '\"rocm_install_method\"'".to_owned(), + // No package manager to refresh on this host, so the only real + // post-condition the suggested (commented-out) `mv ... .bak` + // commands above leave behind is that the flagged repo files are + // gone from their original paths -- unlike + // `rocm examine --json | grep -q '"rocm_install_method"'`, which is + // present in every `examine --json` output regardless of host state + // and so can never fail. + _ => repos + .iter() + .map(|r| format!("! test -e '{r}'")) + .collect::>() + .join(" && "), }; let fix = Fix { summary: "Quarantine duplicate ROCm/AMDGPU repo files and resolve the package manager before re-running any installer.".to_owned(), @@ -1563,7 +1574,14 @@ fn check_12_repo_native_broken(e: &Examination, symptom: &str) -> Diagnosis { // `probe_rocm_install`), so a repo file left behind by a failed // `install --dkms` keeps the marker true even though the package // never actually installed. - verify: "(dpkg -l 2>/dev/null | grep -qE 'rocm|amdgpu' || rpm -qa 2>/dev/null | grep -qE 'rocm|amdgpu') && rocminfo | head -n 5".to_owned(), + // + // Must check dpkg's *status* column (`^ii`), not just that a + // rocm/amdgpu package name appears at all: a half-configured package + // (the exact symptom this fix targets) still shows up in `dpkg -l` + // under a non-`ii` status (e.g. `iF`), so a bare name grep is already + // true before the fix runs. `rpm -qa` has no equivalent half-broken + // listing, so it's left as a plain name grep. + verify: "(dpkg -l 2>/dev/null | grep -E '^ii' | grep -qE 'rocm|amdgpu' || rpm -qa 2>/dev/null | grep -qE 'rocm|amdgpu') && rocminfo | head -n 5".to_owned(), notes: vec!["If the purge/remove step warns it will take unrelated packages with it, stop and resolve those by hand before continuing.".to_owned()], ..Fix::default() }; @@ -7118,6 +7136,20 @@ mod tests { "verify step must not assume a foreign package manager on a pacman host: {}", fix.verify ); + // Not just "no foreign package manager" -- the verify must be a real, + // falsifiable post-condition. `rocm examine --json | grep -q + // '"rocm_install_method"'` is present in every `examine --json` output + // regardless of host state, so it would pass this assertion too while + // never actually being able to fail. Pin it to the one thing the + // suggested (commented) `mv {r} {r}.bak` commands actually change: the + // flagged repo files no longer existing at their original paths. + for r in &e.rocm_repos_seen { + assert!( + fix.verify.contains(r), + "verify must check each flagged repo file is gone, not a tautology: {}", + fix.verify + ); + } } #[test] @@ -7156,6 +7188,34 @@ mod tests { ); } + #[test] + fn repo_native_broken_verify_requires_dpkg_status_not_just_name_presence() { + // `method == "apt"` here is the exact pre-fix state `is_repo_native_installed` + // treats as already repo-native-installed (see its doc comment): the dpkg/rpm + // query fallback found an amdgpu/rocm package by name, with no distinction + // between a healthy install and a half-configured one. If `verify` only + // re-ran that same bare name grep, it would already be true here, before any + // of this fix's remediation commands run. + let mut e = linux_base(); + e.rocm_install_method = "apt".to_owned(); + let report = diagnose( + &e, + "dpkg: error processing package amdgpu-dkms (half-configured)", + ); + let hit = report + .matched + .iter() + .find(|d| d.id == "fix-12-installer") + .expect("repo-native broken state should be diagnosed"); + let verify = &hit.fix.as_ref().unwrap().verify; + assert!( + verify.contains("grep -E '^ii'"), + "verify must check dpkg's installed-status column (`^ii`), not just that the \ + package name appears -- a half-configured package (this fix's own target \ + symptom) already matches a bare name grep before any remediation runs: {verify}" + ); + } + #[test] fn repo_native_broken_fires_and_clears_state_before_reinstall() { let mut e = linux_base(); diff --git a/crates/rocm-core/src/examine.rs b/crates/rocm-core/src/examine.rs index a02fdac5bc..c3e6c2dcd2 100644 --- a/crates/rocm-core/src/examine.rs +++ b/crates/rocm-core/src/examine.rs @@ -215,9 +215,18 @@ pub struct Examination { pub distro_id: String, pub distro_version: String, /// `/etc/os-release` `ID_LIKE`, for `openmpi::resolve_package_manager` - /// fallback matching. Not part of the examine.py wire contract, so it's - /// excluded from JSON. - #[serde(skip)] + /// fallback matching. Not part of the examine.py wire contract, but + /// included in JSON anyway (like the `comgr_*`/`hip_*` fields below): + /// `rocm remote doctor` diagnoses a remote host by deserializing its + /// `examine --json` output, and `repo_pkg_family`'s fallback needs this + /// field populated on that deserialized value, not just on a freshly + /// probed local `Examination`. + /// + /// `#[serde(default)]`: a remote on an older CLI version won't have + /// printed this field at all, and `parse_examination` must keep accepting + /// that document rather than failing outright over one missing field it + /// can safely fall back to "" (unknown) for. + #[serde(default)] pub distro_id_like: String, pub kernel_release: String, pub kernel_cmdline: String, @@ -3374,8 +3383,9 @@ mod tests { /// `ID_LIKE` is parsed into `distro_id_like` for /// `repo_pkg_family`/`openmpi::resolve_package_manager`'s fallback - /// matching, same as `ID`/`VERSION_ID`, even though it's `#[serde(skip)]` - /// and so never shows up by just inspecting the JSON examine output. + /// matching, same as `ID`/`VERSION_ID`, and round-trips through JSON the + /// same way so `rocm remote doctor` gets it from a deserialized remote + /// `examine --json` output too. #[test] fn id_like_is_parsed_into_distro_id_like() { let mut e = linux_host_with_a_gpu(); @@ -4055,6 +4065,11 @@ mod tests { "os_version", "distro_id", "distro_version", + // CLI addition beyond examine.py, added deliberately: `ID_LIKE`, + // so `rocm remote doctor` can resolve a remote host's package + // manager family from its deserialized `examine --json` output, + // not only from a freshly probed local `Examination`. + "distro_id_like", "kernel_release", "kernel_cmdline", "is_wsl", diff --git a/crates/rocm-core/src/fix.rs b/crates/rocm-core/src/fix.rs index c4c9a79de3..21dc7e2a77 100644 --- a/crates/rocm-core/src/fix.rs +++ b/crates/rocm-core/src/fix.rs @@ -543,7 +543,11 @@ const RECIPES: &[FixRecipe] = &[ needs_sudo: true, needs_reboot: true, needs_relogin: false, - verify: "(dpkg -l 2>/dev/null | grep -qE 'rocm|amdgpu' || rpm -qa 2>/dev/null | grep -qE 'rocm|amdgpu') && rocminfo | head -n 5", + // See the matching comment on this fix's `verify` in diagnose.rs: + // the status column (`^ii`) must be checked, not just that a + // rocm/amdgpu package name appears, or a half-configured package + // (this fix's own target symptom) passes before any remediation. + verify: "(dpkg -l 2>/dev/null | grep -E '^ii' | grep -qE 'rocm|amdgpu' || rpm -qa 2>/dev/null | grep -qE 'rocm|amdgpu') && rocminfo | head -n 5", notes: &[ "If the purge/remove step warns it will take unrelated packages with it, stop and resolve those by hand before continuing.", ], diff --git a/docs/testing.md b/docs/testing.md index 71e205d041..d9b819d51f 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -1621,7 +1621,8 @@ DKMS repo (the amdgpu driver ships in-tree instead), so the plan comes back `supported: false` and directs the user to `apt install rocm`. This arm is covered at the unit level by `driver_plan_ubuntu_2604_uses_native_archive_guidance` and its two neighbors in -`driver_install.rs`, but has no e2e/Gherkin coverage: `read_os_release()` reads +[driver_install.rs](../apps/rocm/src/driver_install.rs), but has no e2e/Gherkin +coverage: `read_os_release()` reads the live `/etc/os-release` with no override, so no lane or host running a different Ubuntu release can reach this arm through the CLI itself. diff --git a/tests/e2e-cucumber/features/driver_install.feature b/tests/e2e-cucumber/features/driver_install.feature index a75f512151..62c2735c2e 100644 --- a/tests/e2e-cucumber/features/driver_install.feature +++ b/tests/e2e-cucumber/features/driver_install.feature @@ -30,16 +30,21 @@ Feature: Driver installation planning When the user previews driver installation for a ROCDXG release with no known digest Then the driver plan refuses rather than installing an unverified package - # Every bare-metal Linux lane in this repo (the GitHub-hosted mock job and - # every self-hosted GPU lane) runs Ubuntu, so this is always the apt plan in - # practice -- not the dnf or zypper arms, which have no CI host to run on. - # `--dry-run` previews the plan without writing anything, so this is safe on - # a shared CI host: it asserts on the real `apt_driver_plan` command text - # this binary would use to write /etc/apt/sources.list.d/amdgpu.list and - # import AMD's signing key, the same commands the unit fixtures in - # `driver_install.rs` exercise with a hand-written os-release rather than a - # real one. + # Every bare-metal Linux lane in this repo runs Ubuntu, but not always the + # same release -- the self-hosted GPU lane's real /etc/os-release reports + # 26.04 ("resolute"), which `build_driver_install_plan` routes to the + # `ubuntu_native_archive` arm instead of the apt one (no repo.radeon.com/ + # amdgpu suite published for "resolute" yet; see the `("ubuntu", "26.04")` + # arm in `driver_install.rs`). `--dry-run` previews the plan without writing + # anything, so this is safe on a shared CI host either way: on an apt-arm + # release it asserts the real `apt_driver_plan` command text this binary + # would use to write /etc/apt/sources.list.d/amdgpu.list and import AMD's + # signing key, the same commands the unit fixtures in `driver_install.rs` + # exercise with a hand-written os-release; on 26.04 it asserts the + # native-archive refusal instead, so the scenario proves the CLI's actual + # output on whichever release the lane happens to run rather than + # hard-coding an apt-arm premise a lane can silently outgrow. @id:driver-install-apt-repo-file-and-key-content @requires-os:linux @requires-bare-metal - Scenario: driver-install-04 - Previewing the driver install on a real apt host plans the repo file and signing key + Scenario: driver-install-04 - Previewing the driver install on a real bare-metal host plans release-appropriate driver setup When the user previews driver installation on this host - Then the driver plan writes an apt repo file with AMD's signing key + Then the driver plan matches this host's actual Ubuntu release diff --git a/tests/e2e-cucumber/features/examine.feature b/tests/e2e-cucumber/features/examine.feature index f7b1157ffc..504a674547 100644 --- a/tests/e2e-cucumber/features/examine.feature +++ b/tests/e2e-cucumber/features/examine.feature @@ -119,9 +119,9 @@ Feature: GPU detection and system inspection Then the inspection reports Linux as the operating system And the inspection reports that the host is WSL - # The dry-run plan used to print the raw `${ROCM_CLI_AMDGPU_VERSION:-7.2.4}` shell - # placeholder on its `repo_version:` line instead of the effective version, so - # the preview a user reviews before approving disagreed with what the install + # The dry-run plan used to print the raw `${ROCM_CLI_AMDGPU_DRIVER_VERSION:-latest}` + # shell placeholder on its `repo_version:` line instead of the effective version, + # so the preview a user reviews before approving disagreed with what the install # would actually pull. The plan is rendered on every Linux host regardless of # GPU (the driver is not yet installed when you preview it), so the mock lane # pins this without hardware. diff --git a/tests/e2e-cucumber/tests/e2e/driver_steps.rs b/tests/e2e-cucumber/tests/e2e/driver_steps.rs index 1f02de960e..99a3c31834 100644 --- a/tests/e2e-cucumber/tests/e2e/driver_steps.rs +++ b/tests/e2e-cucumber/tests/e2e/driver_steps.rs @@ -31,9 +31,24 @@ async fn preview_driver_install_on_this_host(world: &mut E2eWorld) { world.cli_rc = Some(rc); } -#[then("the driver plan writes an apt repo file with AMD's signing key")] -async fn assert_apt_repo_file_and_key(world: &mut E2eWorld) { +#[then("the driver plan matches this host's actual Ubuntu release")] +async fn assert_driver_plan_matches_host_release(world: &mut E2eWorld) { let output = world.cli_output.as_ref().expect("no driver plan output"); + // Most bare-metal lanes are on an Ubuntu release with a published + // repo.radeon.com/amdgpu suite and take the apt-repo-file plan below, but + // the self-hosted GPU lane's real host reports Ubuntu 26.04 ("resolute"), + // which has none yet and takes `ubuntu_native_archive` instead -- see the + // `("ubuntu", "26.04")` arm in `driver_install.rs`. Assert whichever the + // real host actually produced rather than hard-coding one release. + if output.contains("policy: ubuntu_native_archive") { + assert!(output.contains("supported: false"), "{output}"); + assert!( + output.contains("ships ROCm natively via the standard archive"), + "{output}" + ); + return; + } + // The runner may already be root (the self-hosted WSL runner always is), // in which case the plan omits the `sudo ` prefix entirely. let sudo = if rocm_core::openmpi::running_as_root() { From b7be4cbeb21a2f67568e6961f7c6677aca52ea28 Mon Sep 17 00:00:00 2001 From: Juho Vainio Date: Thu, 22 Oct 2026 14:25:32 +0300 Subject: [PATCH 3/7] fix: address jussielo-amd and rominf review feedback on repo-native PR Blocking (jussielo-amd): - check_7_stale_repos: fall back to a real per-file existence check instead of an empty verify string when the package-manager family is unresolved and no repo markers were recorded. Blocking (rominf, pr-review-watcher): - fix-12's verify now queries amdgpu-dkms's actual dpkg/rpm status and DKMS module state via a pipefail-safe subshell, instead of a loose rocm|amdgpu name grep piped through `head` that silently passed on a host with no ROCm installed at all. - Six driver_install.rs tests that build Ubuntu plans now take ScopedTestEnv::with_amd_overrides_cleared(), removing a race against the new override-setting tests sharing the same env var. - Added a confidence-delta assertion for fix-12's +20 score bonus (previously only the evidence line was checked). - Added a test driving the override-refusal path through an unreadable /etc/os-release, matching resolve_repo_version_expr's documented parity between both paths. - Added driver-install-05, a Gherkin scenario for the malformed ROCM_CLI_AMDGPU_DRIVER_VERSION refusal. - driver-install-04 and its step now branch on whichever policy the host actually produces instead of assuming repo-native; docs/testing.md corrected to match (the 26.04 arm does have e2e coverage via the hosted ubuntu-26.04 lane). Non-blocking, picked up: - repo_pkg_family's doc comment no longer claims the pacman filter prevents printing an apt command on a pacman host (the match's `_` arms already no-op on any unhandled family); clarified it's kept only so the returned family always matches what callers handle. - Fixed a broken intra-doc link and two stale repo_version/ repo_version_expr field-name references in comments. - Removed a vacuous test assertion made redundant by a preceding is_empty() check. Left as judgment calls (reply posted on the PR): - Old ROCM_CLI_AMDGPU_VERSION/ROCM_CLI_AMDGPU_PACKAGE_RELEASE overrides are silently ignored with no notice in the plan's reason field. - fix-7's multi-line verify field renders prose in a command slot. Signed-off-by: Juho Vainio --- apps/rocm/src/driver_install.rs | 263 ++++++++++++++++-- crates/rocm-core/src/diagnose.rs | 250 +++++++++++++---- crates/rocm-core/src/examine.rs | 65 ++++- crates/rocm-core/src/fix.rs | 17 +- docs/testing.md | 17 +- .../features/driver_install.feature | 38 ++- tests/e2e-cucumber/features/examine.feature | 4 +- tests/e2e-cucumber/tests/e2e/driver_steps.rs | 66 ++++- 8 files changed, 585 insertions(+), 135 deletions(-) diff --git a/apps/rocm/src/driver_install.rs b/apps/rocm/src/driver_install.rs index d3d71d6411..5b8a6c9430 100644 --- a/apps/rocm/src/driver_install.rs +++ b/apps/rocm/src/driver_install.rs @@ -692,7 +692,7 @@ fn wsl_rocdxg_driver_plan(escalation: PrivilegeEscalation) -> DriverInstallPlan if !rocdxg_version_is_well_formed(&version) { return wsl_rocdxg_refusal_plan( // The rejected value is still rendered into the plan's - // `repo_version:` line so the user can see what was refused — but + // `repo_version_expr:` line so the user can see what was refused — but // that line is part of a plan a human reads to decide, and a raw // value containing a newline could forge further lines in it. The // debug form escapes newlines and makes trailing space visible, @@ -835,6 +835,27 @@ fn unreadable_os_release_plan(reason: String, repo_version_expr: String) -> Driv } } +/// The refusal plan `resolve_repo_version_expr` returns for any +/// `ROCM_CLI_AMDGPU_DRIVER_VERSION` value that cannot be safely interpolated +/// into a shell command -- whether it failed [`is_safe_shell_token`] or could +/// not even be decoded as UTF-8. +fn invalid_driver_version_override_plan(value_debug: String) -> DriverInstallPlan { + DriverInstallPlan { + supported: false, + mutating: false, + policy: "invalid_driver_version_override".to_owned(), + os_id: String::new(), + version_id: String::new(), + codename: String::new(), + repo_version_expr: value_debug, + reason: "ROCM_CLI_AMDGPU_DRIVER_VERSION is not a well-formed amdgpu driver release. It is interpolated into privileged shell commands, so only letters, digits, and `. _ -` are accepted.".to_owned(), + preflight_checks: Vec::new(), + commands: Vec::new(), + checks: vec!["rocm examine".to_owned()], + reboot_required: false, + } +} + /// Resolves and validates `ROCM_CLI_AMDGPU_DRIVER_VERSION`, shared between /// [`build_driver_install_plan_at`] (reached whenever the os-release text /// itself was readable) and [`build_driver_install_plan_read`]'s `Unreadable` @@ -858,27 +879,29 @@ fn resolve_repo_version_expr() -> Result> { // optional override in this file (`resolve_rocdxg_verification`, // `resolve_shell_default_template`): a blank env var is how an env // file clears an override, not a request to refuse the plan. - Err(_) => Ok("latest".to_owned()), + Err(std::env::VarError::NotPresent) => Ok("latest".to_owned()), Ok(v) if v.is_empty() => Ok("latest".to_owned()), Ok(v) if is_safe_shell_token(&v) => Ok(v), - Ok(v) => Err(Box::new(DriverInstallPlan { - supported: false, - mutating: false, - policy: "invalid_driver_version_override".to_owned(), - os_id: String::new(), - version_id: String::new(), - codename: String::new(), - repo_version_expr: format!("{v:?}"), - reason: "ROCM_CLI_AMDGPU_DRIVER_VERSION is not a well-formed amdgpu driver release. It is interpolated into privileged shell commands, so only letters, digits, and `. _ -` are accepted.".to_owned(), - preflight_checks: Vec::new(), - commands: Vec::new(), - checks: vec!["rocm examine".to_owned()], - reboot_required: false, - })), + Ok(v) => Err(Box::new(invalid_driver_version_override_plan(format!( + "{v:?}" + )))), + // A non-UTF-8 value can never pass `is_safe_shell_token` anyway, but + // routing it through the same refusal as a malformed value (instead + // of folding it into the NotPresent/empty "unset" case) keeps the + // same "refuse, don't silently fall back to latest" guarantee for a + // user who set this to something `env::var` cannot even decode. + Err(std::env::VarError::NotUnicode(v)) => { + // Debug, not `v.display()`, is deliberate here: this is the one + // value worth escaping rather than rendering lossily, since the + // whole reason it reached this arm is that it isn't valid UTF-8. + #[allow(clippy::unnecessary_debug_formatting)] + let value_debug = format!("{v:?}"); + Err(Box::new(invalid_driver_version_override_plan(value_debug))) + } } } -/// [`build_driver_install_plan`], naming `os_release_path` instead of always +/// [`build_driver_install_plan_read`], naming `os_release_path` instead of always /// `/etc/os-release` in an unreadable-line message. fn build_driver_install_plan_at( examine: &ExamineSummary, @@ -989,15 +1012,12 @@ fn build_driver_install_plan_at( // to apt_driver_plan(..., true) once it exists, the same way // 22.04/24.04 are handled. // - // This arm IS reachable through the CLI on a real host -- this PR's - // own self-hosted bare-metal CI runner's `/etc/os-release` reports - // Ubuntu 26.04, which is exactly how `driver-install-04` in - // `driver_install.feature` caught this arm silently taking over that - // scenario's apt-plan premise mid-review. That scenario now asserts - // whichever arm the real host actually falls into, so this one has - // e2e coverage too, alongside the unit fixture in - // `driver_plan_ubuntu_2604_uses_native_archive_guidance` and its two - // neighbors below. + // This arm IS reachable through the CLI on a real host: the hosted + // `E2E tests` job's `ubuntu-26.04` image runs `driver-install-04` in + // `driver_install.feature`, which asserts whichever arm the real host + // actually falls into, so this one has e2e coverage too, alongside + // the unit fixture in `driver_plan_ubuntu_2604_uses_native_archive_guidance` + // and its two neighbors below. ("ubuntu", "26.04") => { let sudo = escalation.prefix(); DriverInstallPlan { @@ -2140,6 +2160,34 @@ mod tests { ); } + /// The unreadable-os-release branch resolves `repo_version_expr` via the + /// same [`resolve_repo_version_expr`] call the normal path uses, before + /// it ever builds an `unreadable_os_release_plan`. A malformed override + /// must still be refused here, not silently dropped because the distro + /// itself could not be identified. + #[test] + fn an_unreadable_os_release_still_refuses_a_malformed_version_override() { + let mut env = ScopedTestEnv::with_amd_overrides_cleared(); + env.set( + "ROCM_CLI_AMDGPU_DRIVER_VERSION", + "'; touch /tmp/pwned; echo '", + ); + let read = rocm_core::hardware_root::OsRelease::Unreadable { + path: "/usr/lib/os-release", + error: std::io::Error::new(std::io::ErrorKind::PermissionDenied, "denied"), + }; + let plan = build_driver_install_plan_read( + &test_examine("linux", false), + &read, + true, + PrivilegeEscalation::Sudo, + ); + assert!(!plan.supported); + assert_eq!(plan.policy, "invalid_driver_version_override"); + assert!(plan.reason.contains("ROCM_CLI_AMDGPU_DRIVER_VERSION")); + assert!(plan.commands.is_empty()); + } + /// The same malformed line as /// [`an_unreadable_os_release_names_its_line_and_plans_nothing`], but read /// through the fallback path: the reason must name `/usr/lib/os-release`, @@ -2252,6 +2300,7 @@ mod tests { // before any driver work. This asserts the ABSENCE of `sudo` across every // distro rather than checking known commands one by one — a templating // site missed on some distro fails here instead of shipping. + let _env = ScopedTestEnv::with_amd_overrides_cleared(); for (label, os_release) in dkms_planning_os_releases() { let commands = plan_commands(os_release, PrivilegeEscalation::AlreadyRoot); assert!( @@ -2273,6 +2322,7 @@ mod tests { // it when a normal user runs the same plan. Verify-phase commands are // read-only probes and are deliberately unprivileged, so only the // mutating phases are required to escalate. + let _env = ScopedTestEnv::with_amd_overrides_cleared(); for (label, os_release) in dkms_planning_os_releases() { let plan = build_driver_install_plan_read( &test_examine("linux", false), @@ -2306,6 +2356,7 @@ mod tests { // `sudo` also appears mid-pipeline (`| sudo tee`, `| sudo gpg`), which a // naive "strip a leading prefix" fix would miss. The pipeline must survive // with the escalation removed from the right-hand side only. + let _env = ScopedTestEnv::with_amd_overrides_cleared(); let ubuntu = "ID=ubuntu\nVERSION_ID=\"24.04\"\nVERSION_CODENAME=noble\n"; let commands = plan_commands(ubuntu, PrivilegeEscalation::AlreadyRoot); assert!( @@ -2327,6 +2378,7 @@ mod tests { // `execution_commands()` is what lands in state.json. It must agree with // the escalation the plan was built under, or the recorded history // describes commands that never ran. + let _env = ScopedTestEnv::with_amd_overrides_cleared(); let ubuntu = "ID=ubuntu\nVERSION_ID=\"24.04\"\nVERSION_CODENAME=noble\n"; let as_root = build_driver_install_plan_read( &test_examine("linux", false), @@ -2361,6 +2413,7 @@ mod tests { // The preflight claimed `sudo` must be installed even when the plan no // longer uses it — the same contradiction the bug report called out // between the stated preconditions and what execution actually did. + let _env = ScopedTestEnv::with_amd_overrides_cleared(); for (label, os_release) in dkms_planning_os_releases() { let as_root = build_driver_install_plan_read( &test_examine("linux", false), @@ -2552,6 +2605,7 @@ VERSION_CODENAME=noble #[test] fn driver_plan_executor_defers_verify_when_reboot_is_required() -> Result<()> { + let _env = ScopedTestEnv::with_amd_overrides_cleared(); let plan = build_driver_install_plan_read( &test_examine("linux", false), &os_release_found("ID=ubuntu\nVERSION_ID=\"24.04\"\nVERSION_CODENAME=noble\n"), @@ -2726,6 +2780,9 @@ VERSION_CODENAME=resolute assert!(rendered.contains("sudo apt install rocm")); assert!(!rendered.contains("amdgpu-dkms")); assert!(plan.commands.is_empty()); + // The kernel driver ships in-tree on 26.04, so this arm must not + // claim a reboot is needed for `apt install rocm` (userspace only). + assert!(!plan.reboot_required); // `checks` renders as `post_reboot_checks:` and must hold verification // targets only -- the mutating install guidance belongs in `reason`. assert!( @@ -2782,6 +2839,38 @@ VERSION_ID="26.04" assert_eq!(plan.policy, "ubuntu_native_archive"); } + #[cfg(unix)] + #[test] + fn driver_plan_rejects_a_non_utf8_version_override() { + // `std::env::var` reports a non-UTF-8 value as `Err(VarError::NotUnicode)`, + // which `resolve_repo_version_expr` must not fold into the + // `NotPresent`/empty "unset" case -- that would silently use "latest" + // for a user who explicitly set this to something. + use std::os::unix::ffi::OsStrExt; + let _env = ScopedTestEnv::with_amd_overrides_cleared(); + let invalid = std::ffi::OsStr::from_bytes(&[0x66, 0xFF, 0x66]); + #[allow(unsafe_code)] // std::env::set_var is unsafe in edition 2024 + unsafe { + std::env::set_var("ROCM_CLI_AMDGPU_DRIVER_VERSION", invalid); + } + let os_release = r#" +ID=ubuntu +VERSION_ID="24.04" +VERSION_CODENAME=noble +"#; + let plan = build_driver_install_plan_read( + &test_examine("linux", false), + &os_release_found(os_release), + true, + PrivilegeEscalation::Sudo, + ); + + assert!(!plan.supported); + assert_eq!(plan.policy, "invalid_driver_version_override"); + assert!(plan.reason.contains("ROCM_CLI_AMDGPU_DRIVER_VERSION")); + assert!(plan.commands.is_empty()); + } + #[test] fn driver_plan_rejects_shell_metacharacters_in_version_override() { let mut env = ScopedTestEnv::with_amd_overrides_cleared(); @@ -2804,12 +2893,35 @@ VERSION_CODENAME=noble assert!(!plan.supported); assert_eq!(plan.policy, "invalid_driver_version_override"); assert!(plan.reason.contains("ROCM_CLI_AMDGPU_DRIVER_VERSION")); + // Already proves no command can contain "pwned": a vacuous check over + // commands would be redundant with this. assert!(plan.commands.is_empty()); - assert!( - plan.commands - .iter() - .all(|command| !command.command.contains("pwned")) + } + + #[test] + fn driver_plan_rejects_a_space_free_shell_injection_payload() { + // The metacharacter test above uses a payload full of spaces, which + // `is_safe_shell_token` already rejects on its own -- so it proves + // nothing about whether `$`, backticks, or `()` are actually in the + // denylist. Use a payload with no spaces at all so the rejection can + // only come from the metacharacters themselves. + let mut env = ScopedTestEnv::with_amd_overrides_cleared(); + env.set("ROCM_CLI_AMDGPU_DRIVER_VERSION", "$(id)"); + let os_release = r#" +ID=ubuntu +VERSION_ID="24.04" +VERSION_CODENAME=noble +"#; + let plan = build_driver_install_plan_read( + &test_examine("linux", false), + &os_release_found(os_release), + true, + PrivilegeEscalation::Sudo, ); + + assert!(!plan.supported); + assert_eq!(plan.policy, "invalid_driver_version_override"); + assert!(plan.commands.is_empty()); } #[test] @@ -2900,6 +3012,94 @@ VERSION_CODENAME=noble ); } + #[test] + fn driver_plan_falls_back_on_a_space_free_hostile_codename() { + // The payload above is full of spaces, which `is_safe_shell_token` + // already rejects on its own -- it proves nothing about whether the + // metacharacters themselves are denylisted. Use a space-free payload + // so rejection can only come from the metacharacters. + let _env = ScopedTestEnv::with_amd_overrides_cleared(); + // Single-quoted so the os-release parser (which refuses an unquoted + // `$`/`(`/`)` outright, making the whole file unreadable rather than + // just this field) accepts the line and hands `$(id)` to + // `is_safe_shell_token` to reject on its own merits. + let os_release = r#" +ID=ubuntu +VERSION_ID="24.04" +VERSION_CODENAME='$(id)' +"#; + let plan = build_driver_install_plan_read( + &test_examine("linux", false), + &os_release_found(os_release), + true, + PrivilegeEscalation::Sudo, + ); + + assert_eq!(plan.codename, "noble"); + assert!( + plan.commands + .iter() + .all(|command| !command.command.contains("$(id)")) + ); + } + + #[test] + fn driver_plan_falls_back_on_a_space_free_malformed_version_id() { + let _env = ScopedTestEnv::with_amd_overrides_cleared(); + // Single-quoted for the same reason as the codename test above: a + // bare/double-quoted `$(id)` makes the whole os-release file + // unreadable, which would pass this test's assertions (empty + // version_id, unsupported) without ever reaching `is_safe_shell_token`. + let os_release = r" +ID=ubuntu +VERSION_ID='$(id)' +VERSION_CODENAME=noble +"; + let plan = build_driver_install_plan_read( + &test_examine("linux", false), + &os_release_found(os_release), + true, + PrivilegeEscalation::Sudo, + ); + + assert_eq!(plan.version_id, ""); + assert!(!plan.supported); + assert!( + plan.commands + .iter() + .all(|command| !command.command.contains("$(id)")) + ); + } + + #[test] + fn driver_plan_falls_back_on_a_space_free_hostile_os_id() { + // Closes the gap where `os_id`'s `is_safe_shell_token` filter (the + // `field("ID").filter(...)` call above `codename_for_version`) had no + // dedicated test at all: deleting that filter left every other test + // green, since none of them feed a hostile `ID` value. + let _env = ScopedTestEnv::with_amd_overrides_cleared(); + let os_release = r#" +ID='$(id)' +VERSION_ID="24.04" +VERSION_CODENAME=noble +"#; + let plan = build_driver_install_plan_read( + &test_examine("linux", false), + &os_release_found(os_release), + true, + PrivilegeEscalation::Sudo, + ); + + assert_eq!(plan.os_id, ""); + assert_eq!(plan.policy, "unsupported_linux_dkms_plan"); + assert!(!plan.supported); + assert!( + plan.commands + .iter() + .all(|command| !command.command.contains("$(id)")) + ); + } + #[test] fn driver_reconcile_without_state_gives_non_privileged_guidance() -> Result<()> { let (root, paths) = test_paths("driver-reconcile-empty"); @@ -3153,6 +3353,9 @@ VERSION_ID="10.1" assert!(plan.supported); assert!(rendered.contains("approval: not required")); assert!(rendered.contains("kernel-uek-devel-$(uname -r)")); + // `rpm --import` is pushed once after the distro-specific match, not + // inside the RHEL/Generic arm -- Oracle's flow must get it too. + assert!(rendered.contains("sudo rpm --import https://repo.radeon.com/rocm/rocm.gpg.key")); assert!( rendered.contains("baseurl=https://repo.radeon.com/amdgpu/latest/el/10/main/x86_64") ); diff --git a/crates/rocm-core/src/diagnose.rs b/crates/rocm-core/src/diagnose.rs index 8fa6ca41e4..e5484114fe 100644 --- a/crates/rocm-core/src/diagnose.rs +++ b/crates/rocm-core/src/diagnose.rs @@ -428,7 +428,6 @@ const KEYWORDS_DPKG_BROKEN: KeywordTable = &[ 25, "apt mentions dpkg failure", ), - ("--accept-eula", 40, "user mentions --accept-eula"), ]; const KEYWORDS_PAGE_FAULT: KeywordTable = &[ @@ -839,17 +838,21 @@ fn check_3_rocm_kernel_unsupported(e: &Examination, symptom: &str) -> Diagnosis if score <= 0 { return zero("fix-3-rocm-kernel", "ROCm/distro/kernel triple unsupported"); } + let mut commands = vec![ + format!("# Current: kernel={kernel} distro={distro} {distro_v} rocm={rocm_version}"), + "# Compare to the live AMD matrix:".to_owned(), + "# https://rocm.docs.amd.com/projects/install-on-linux/en/latest/reference/system-requirements.html".to_owned(), + "# If your kernel is above the supported range, install the HWE".to_owned(), + "# kernel that matches ROCm, then rerun `rocm install driver --dkms --yes`.".to_owned(), + "# To avoid the DKMS build entirely, use `rocm install sdk` instead:".to_owned(), + "# it installs the userspace ROCm stack without touching the kernel module.".to_owned(), + ]; + if ubuntu_driver_is_native_archive(e) { + commands.push("# Not on Ubuntu 26.04: the amdgpu driver ships in-tree there, so `rocm install driver --dkms` plans nothing; run `sudo apt install rocm` instead.".to_owned()); + } let fix = Fix { summary: "Cross-check your kernel/distro against the live AMD compatibility matrix before reinstalling.".to_owned(), - commands: vec![ - format!("# Current: kernel={kernel} distro={distro} {distro_v} rocm={rocm_version}"), - "# Compare to the live AMD matrix:".to_owned(), - "# https://rocm.docs.amd.com/projects/install-on-linux/en/latest/reference/system-requirements.html".to_owned(), - "# If your kernel is above the supported range, install the HWE".to_owned(), - "# kernel that matches ROCm, then rerun `rocm install driver --dkms`.".to_owned(), - "# To avoid the DKMS build entirely, use `rocm install sdk` instead:".to_owned(), - "# it installs the userspace ROCm stack without touching the kernel module.".to_owned(), - ], + commands, fix_id: "fix-3-rocm-kernel".to_owned(), needs_reboot: true, verify: "lsmod | grep amdgpu && rocminfo | head -n 20".to_owned(), @@ -1090,6 +1093,20 @@ fn check_6_path_missing(e: &Examination, symptom: &str) -> Diagnosis { ) } +/// The package manager's own "re-resolve the repo metadata" command for +/// `family`, without a `sudo` prefix. Shared by `check_7_stale_repos` and +/// `check_12_repo_native_broken` so a future per-family tweak (e.g. adding +/// `--non-interactive` to one of these) only has one copy to update instead +/// of drifting across the two checks. +fn refresh_command_for_family(family: &str) -> Option<&'static str> { + match family { + "apt" => Some("apt update"), + "dnf" => Some("dnf clean all"), + "zypper" => Some("zypper refresh"), + _ => None, + } +} + fn check_7_stale_repos(e: &Examination, symptom: &str) -> Diagnosis { let mut score = 0; let mut evidence = Vec::new(); @@ -1126,30 +1143,42 @@ fn check_7_stale_repos(e: &Examination, symptom: &str) -> Diagnosis { "# sudo mv {r} {r}.bak # quarantine, do not delete yet" )); } - match family { - "apt" => commands.push("sudo apt update".to_owned()), - "dnf" => commands.push("sudo dnf clean all".to_owned()), - "zypper" => commands.push("sudo zypper refresh".to_owned()), - _ => {} + if let Some(cmd) = refresh_command_for_family(family) { + commands.push(format!("sudo {cmd}")); } commands.push( "# If the package manager now resolves, reinstall the driver only (review the plan, then approve):" .to_owned(), ); - commands.push("# rocm install driver --dkms # review the plan".to_owned()); - commands.push("# rocm install driver --dkms --yes # reinstalls the driver only".to_owned()); - let verify = match family { - "apt" => "sudo apt update 2>&1 | tail -n 20".to_owned(), - "dnf" => "sudo dnf clean all 2>&1 | tail -n 20".to_owned(), - "zypper" => "sudo zypper refresh 2>&1 | tail -n 20".to_owned(), + if ubuntu_driver_is_native_archive(e) { + commands.push("# sudo apt install rocm # Ubuntu 26.04 ships the amdgpu driver in-tree, so there is no DKMS driver to reinstall".to_owned()); + } else { + commands.push("# rocm install driver --dkms # review the plan".to_owned()); + commands + .push("# rocm install driver --dkms --yes # reinstalls the driver only".to_owned()); + } + let verify = match refresh_command_for_family(family) { + // `set -o pipefail` so the exit status reflects `{cmd}` itself, not + // `tail` (which exits 0 regardless) -- otherwise a copy-pasted + // failure of this command silently reads as success. + Some(cmd) => format!("bash -c 'set -o pipefail; sudo {cmd} 2>&1 | tail -n 20'"), // No package manager to refresh on this host, so the only real // post-condition the suggested (commented-out) `mv ... .bak` // commands above leave behind is that the flagged repo files are // gone from their original paths -- unlike // `rocm examine --json | grep -q '"rocm_install_method"'`, which is // present in every `examine --json` output regardless of host state - // and so can never fail. - _ => repos + // and so can never fail. When no repo files were actually flagged + // (the symptom text alone triggered this fix), there is nothing to + // assert about a `mv` command that never ran, so fall back to a + // real, still-falsifiable check: no ROCm/AMDGPU repo file exists + // under any of the three families' repo directories. + None if repos.is_empty() => { + "! ls /etc/apt/sources.list.d/ /etc/yum.repos.d/ /etc/zypp/repos.d/ 2>/dev/null \ + | grep -iE 'rocm|amdgpu|radeon'" + .to_owned() + } + None => repos .iter() .map(|r| format!("! test -e '{r}'")) .collect::>() @@ -1479,11 +1508,13 @@ fn repo_pkg_family(e: &Examination) -> &'static str { } // The two `match family` sites below only implement apt/dnf/zypper // remediation (this check has no pacman-based repo-native ROCm install to - // recover, unlike `openmpi`'s library installers) -- filter the resolver's - // fourth possible answer out here, rather than let it silently fall - // through to a wrong default and print an apt command on a pacman host. - // Both `match family` arms below treat this `"unknown"` sentinel the same - // as their other unhandled cases: no package-manager-specific command. + // recover, unlike `openmpi`'s library installers); their `_` arms already + // treat any unhandled string, including a literal `"pacman"`, as "no + // package-manager-specific command" -- so collapsing pacman to + // `"unknown"` here doesn't change that match's behavior. It's kept so the + // family string this function returns always matches what its callers + // actually handle, rather than leaking a fourth value they merely happen + // to no-op on today. crate::openmpi::resolve_package_manager( &e.distro_id.to_ascii_lowercase(), &e.distro_id_like.to_ascii_lowercase(), @@ -1509,6 +1540,18 @@ fn is_repo_native_installed(method: &str) -> bool { matches!(method, "repo-native" | "apt" | "dnf") } +/// Whether `rocm install driver --dkms` has nothing to reinstall on this +/// host. Ubuntu 26.04 ships the amdgpu kernel driver in-tree and +/// `build_driver_install_plan` in `apps/rocm/src/driver_install.rs` plans no +/// DKMS repo install there (see the `("ubuntu", "26.04")` arm); `rocm-core` +/// can't call that plan builder directly (`apps/rocm` depends on +/// `rocm-core`, not the reverse), so this mirrors just that one condition. +/// WSL hosts never reach `check_3`/`check_7`/`check_12` at all -- see +/// `CHECKERS`'s `&["linux"]` tag on each. +fn ubuntu_driver_is_native_archive(e: &Examination) -> bool { + e.distro_id.eq_ignore_ascii_case("ubuntu") && e.distro_version == "26.04" +} + fn check_12_repo_native_broken(e: &Examination, symptom: &str) -> Diagnosis { let mut score = 0; let mut evidence = Vec::new(); @@ -1553,35 +1596,64 @@ fn check_12_repo_native_broken(e: &Examination, symptom: &str) -> Diagnosis { )); } } - match family { - "apt" => commands.push("sudo apt update".to_owned()), - "dnf" => commands.push("sudo dnf clean all".to_owned()), - "zypper" => commands.push("sudo zypper refresh".to_owned()), - _ => {} + if let Some(cmd) = refresh_command_for_family(family) { + commands.push(format!("sudo {cmd}")); } - commands.push("# Reinstall via rocm-cli's repo-native flow:".to_owned()); - commands.push("rocm install driver --dkms --yes".to_owned()); + let summary = if ubuntu_driver_is_native_archive(e) { + commands + .push("# Ubuntu 26.04 ships the amdgpu kernel driver in-tree; there is no".to_owned()); + commands.push( + "# repo-native DKMS driver to reinstall here. Reinstall the userspace stack:" + .to_owned(), + ); + commands.push("sudo apt install rocm".to_owned()); + "Clear the half-configured package state, quarantine the repo-native install's repo files, THEN reinstall the userspace stack via `sudo apt install rocm` (Ubuntu 26.04 ships the amdgpu kernel driver in-tree, so there is no DKMS driver to reinstall).".to_owned() + } else { + commands.push("# Reinstall via rocm-cli's repo-native flow:".to_owned()); + commands.push("rocm install driver --dkms --yes".to_owned()); + "Clear the half-configured package/DKMS state, quarantine the repo-native install's repo files, THEN reinstall via `rocm install driver --dkms --yes`.".to_owned() + }; + // Query the package manager's own records, not `rocm examine`'s + // self-reported `rocm_install_method` marker: that marker is set from + // repo-marker-file presence before dpkg/rpm is consulted (see + // `probe_rocm_install`), so a repo file left behind by a failed + // `install --dkms` keeps the marker true even though the package + // never actually installed. + // + // Must check the *targeted* package's installed status, not just that + // some `rocm`/`amdgpu` name appears anywhere: a bare `grep -qE + // 'rocm|amdgpu'` also matches unrelated stock packages (e.g. + // `libdrm-amdgpu1`), and matches a healthy `rocm-*` package sitting + // next to the broken `amdgpu-dkms` this fix targets. So query + // `amdgpu-dkms` specifically, via dpkg's full `Status` field + // (`install ok installed`, not a `^ii` substring) or `rpm -q`. Also + // confirm DKMS itself reports the module built, and check + // `rocminfo`'s own exit code directly -- piping through `head` would + // report the pipeline's last stage, masking a missing/failing + // `rocminfo`. + // + // Ubuntu 26.04 has no `amdgpu-dkms`/DKMS module to query (see + // `ubuntu_driver_is_native_archive` above): check the `rocm` package + // dpkg reinstalled instead. + let verify = if ubuntu_driver_is_native_archive(e) { + "dpkg-query -W -f='${Status}' rocm 2>/dev/null | grep -q 'install ok installed' \ + && rocminfo >/dev/null 2>&1" + .to_owned() + } else { + "(dpkg-query -W -f='${Status}' amdgpu-dkms 2>/dev/null | grep -q 'install ok installed' \ + || rpm -q amdgpu-dkms >/dev/null 2>&1) \ + && dkms status amdgpu 2>/dev/null | grep -q installed \ + && rocminfo >/dev/null 2>&1" + .to_owned() + }; let fix = Fix { - summary: "Clear the half-configured package/DKMS state, quarantine the repo-native install's repo files, THEN reinstall via `rocm install driver --dkms --yes`.".to_owned(), + summary, commands, needs_sudo: true, needs_reboot: true, fix_id: "fix-12-installer".to_owned(), - // Query the package manager's own records, not `rocm examine`'s - // self-reported `rocm_install_method` marker: that marker is set from - // repo-marker-file presence before dpkg/rpm is consulted (see - // `probe_rocm_install`), so a repo file left behind by a failed - // `install --dkms` keeps the marker true even though the package - // never actually installed. - // - // Must check dpkg's *status* column (`^ii`), not just that a - // rocm/amdgpu package name appears at all: a half-configured package - // (the exact symptom this fix targets) still shows up in `dpkg -l` - // under a non-`ii` status (e.g. `iF`), so a bare name grep is already - // true before the fix runs. `rpm -qa` has no equivalent half-broken - // listing, so it's left as a plain name grep. - verify: "(dpkg -l 2>/dev/null | grep -E '^ii' | grep -qE 'rocm|amdgpu' || rpm -qa 2>/dev/null | grep -qE 'rocm|amdgpu') && rocminfo | head -n 5".to_owned(), + verify, notes: vec!["If the purge/remove step warns it will take unrelated packages with it, stop and resolve those by hand before continuing.".to_owned()], ..Fix::default() }; @@ -7152,6 +7224,33 @@ mod tests { } } + #[test] + fn stale_repos_verify_is_not_empty_when_symptom_alone_triggers_on_an_unresolved_host() { + // Same unresolved/pacman family as the test above, but this time no + // repo files were ever recorded -- only the symptom text scores the + // fix. `repos.iter().join(" && ")` over an empty `repos` produces an + // empty string, which would make `verify` a blank, always-passing + // check instead of the real repo-marker check below. + let mut e = linux_base(); + e.distro_id = "arch".to_owned(); + let report = diagnose(&e, "404 against repo.radeon.com"); + let hit = report + .matched + .iter() + .find(|d| d.id == "fix-7-stale-repos") + .expect("symptom-only match should still diagnose fix-7"); + let fix = hit.fix.as_ref().unwrap(); + assert!( + !fix.verify.trim().is_empty(), + "verify must not be blank when no repo files were flagged" + ); + assert!( + fix.verify.contains("rocm|amdgpu|radeon"), + "verify must fall back to a real, falsifiable repo-marker check: {}", + fix.verify + ); + } + #[test] fn repo_native_broken_emits_no_package_manager_commands_on_pacman_hosts() { let mut e = linux_base(); @@ -7209,10 +7308,20 @@ mod tests { .expect("repo-native broken state should be diagnosed"); let verify = &hit.fix.as_ref().unwrap().verify; assert!( - verify.contains("grep -E '^ii'"), - "verify must check dpkg's installed-status column (`^ii`), not just that the \ - package name appears -- a half-configured package (this fix's own target \ - symptom) already matches a bare name grep before any remediation runs: {verify}" + verify.contains("grep -q 'install ok installed'"), + "verify must check dpkg's full installed-status field, not just that the \ + package name appears anywhere -- a bare name grep also matches unrelated \ + stock packages (e.g. libdrm-amdgpu1) and a healthy rocm-* package sitting \ + next to the broken amdgpu-dkms this fix targets: {verify}" + ); + assert!( + verify.contains("dkms status amdgpu"), + "verify must also confirm dkms reports the module actually built: {verify}" + ); + assert!( + !verify.contains("| head"), + "verify must not pipe rocminfo through head, which would report head's exit \ + code instead of rocminfo's: {verify}" ); } @@ -7351,8 +7460,10 @@ mod tests { // probe_rocm_install (examine.rs) falls back to the literal "apt"/"dnf" // when dpkg/rpm confirms the package is installed but no marker file // was found. Those hosts are still repo-native-managed, so the evidence - // line and +20 score bonus must fire for them too, not just the - // marker-file-detected literal "repo-native" case covered above. + // line must fire for them too, not just the marker-file-detected + // literal "repo-native" case covered above. The +20 score bonus that + // fires alongside it is asserted separately, in + // `repo_native_broken_score_bonus_actually_raises_confidence`. for method in ["apt", "dnf"] { let mut e = linux_base(); e.rocm_install_method = method.to_owned(); @@ -7375,6 +7486,33 @@ mod tests { } } + #[test] + fn repo_native_broken_score_bonus_actually_raises_confidence() { + // The two tests above only assert the evidence *line*, which fires + // from the same `is_repo_native_installed(method)` check that gates + // the `+20` bonus a few lines later -- so they'd stay green even if + // the bonus itself were deleted. Diagnose the same dpkg symptom on a + // repo-native host and a runfile-or-tarball host and assert the + // former's score is exactly 20 higher. + let symptom = "dpkg: error processing package amdgpu-dkms (half-configured)"; + let score_for = |method: &str| { + let mut e = linux_base(); + e.rocm_install_method = method.to_owned(); + diagnose(&e, symptom) + .matched + .iter() + .find(|d| d.id == "fix-12-installer") + .expect("dpkg keyword evidence alone should still surface fix-12") + .score + }; + assert_eq!( + score_for("apt"), + score_for("runfile-or-tarball") + 20, + "the +20 repo-native score bonus must actually raise the computed score, \ + not just the evidence text" + ); + } + #[test] fn repo_native_broken_fires_on_dpkg_symptom_regardless_of_install_method() { // The keyword score alone (half-configured + generic dpkg error = 75) diff --git a/crates/rocm-core/src/examine.rs b/crates/rocm-core/src/examine.rs index c3e6c2dcd2..dab3935ab8 100644 --- a/crates/rocm-core/src/examine.rs +++ b/crates/rocm-core/src/examine.rs @@ -1989,9 +1989,32 @@ fn repo_native_method_from_markers(existing: &[&str]) -> Option<(&'static str, V // `name` is already lowercased by the caller, so a plain suffix match is fine. #[allow(clippy::case_sensitive_file_extension_comparisons)] fn is_live_rocm_repo_file_name(name: &str) -> bool { - let quarantined = - name.ends_with(".bak") || name.ends_with(".save") || name.ends_with(".disabled"); - !quarantined && (name.contains("rocm") || name.contains("amdgpu") || name.contains("radeon")) + // Allowlist the known repo-file extensions (apt's `.list`, dnf/zypper's + // `.repo`) rather than denylist known quarantine suffixes: quarantining + // appends to the name (`amdgpu.list` -> `amdgpu.list.bak`), so this also + // excludes any quarantine convention this file doesn't know about, and + // stops an unrelated file that merely mentions "rocm"/"amdgpu" in its + // name (a note, a log) from being swept up as a live repo file. + (name.ends_with(".list") || name.ends_with(".repo")) + && (name.contains("rocm") || name.contains("amdgpu") || name.contains("radeon")) +} + +/// Full paths of live (non-quarantined) ROCm/AMDGPU repo files directly inside +/// `dir`, split out from `probe_rocm_install` so the `.bak`/`.save`/`.disabled` +/// skip actually gets exercised against a real directory listing, not just the +/// pure `is_live_rocm_repo_file_name` name check in isolation. Silently empty +/// when `dir` does not exist or is not a directory. +fn live_rocm_repo_paths_in_dir(dir: &str) -> Vec { + let Ok(entries) = std::fs::read_dir(dir) else { + return Vec::new(); + }; + entries + .flatten() + .filter(|entry| { + is_live_rocm_repo_file_name(&entry.file_name().to_string_lossy().to_lowercase()) + }) + .map(|entry| entry.path().to_string_lossy().into_owned()) + .collect() } fn probe_rocm_install(e: &mut Examination) { @@ -2045,16 +2068,9 @@ fn probe_rocm_install(e: &mut Examination) { "/etc/yum.repos.d", "/etc/zypp/repos.d", ] { - let Ok(entries) = std::fs::read_dir(dir) else { - continue; - }; - for entry in entries.flatten() { - let name = entry.file_name().to_string_lossy().to_lowercase(); - if is_live_rocm_repo_file_name(&name) { - let full = entry.path().to_string_lossy().into_owned(); - if !e.rocm_repos_seen.contains(&full) { - e.rocm_repos_seen.push(full); - } + for full in live_rocm_repo_paths_in_dir(dir) { + if !e.rocm_repos_seen.contains(&full) { + e.rocm_repos_seen.push(full); } } } @@ -3327,6 +3343,29 @@ mod tests { assert!(!is_live_rocm_repo_file_name("amdgpu.list.save")); assert!(!is_live_rocm_repo_file_name("amdgpu.list.disabled")); assert!(!is_live_rocm_repo_file_name("unrelated.list")); + // Allowlisted by extension, not just denylisted by quarantine suffix: + // a stray file that merely mentions "rocm" isn't a repo file. + assert!(!is_live_rocm_repo_file_name("rocm-notes.txt")); + } + + #[test] + fn live_rocm_repo_paths_in_dir_skips_a_real_bak_file_on_disk() { + // `is_live_rocm_repo_file_name` above only proves the name filter is + // correct in isolation; this drives an actual `.bak` file (the kind + // fix-7/fix-12 quarantine advice produces) through the directory scan + // `probe_rocm_install` runs, closing the gap where only the live file + // being listed first would still pass if the `.bak` skip were deleted. + let dir = tempfile::tempdir().expect("create temp dir"); + std::fs::write(dir.path().join("amdgpu.list"), "deb ...\n").expect("write live repo"); + std::fs::write(dir.path().join("amdgpu.list.bak"), "deb ...\n") + .expect("write quarantined repo"); + std::fs::write(dir.path().join("unrelated.list"), "deb ...\n").expect("write unrelated"); + + let mut seen = live_rocm_repo_paths_in_dir(&dir.path().to_string_lossy()); + seen.sort(); + + assert_eq!(seen.len(), 1, "seen: {seen:?}"); + assert!(seen[0].ends_with("amdgpu.list")); } /// A Linux host with an AMD GPU, so `compute_status` turns on the probe diff --git a/crates/rocm-core/src/fix.rs b/crates/rocm-core/src/fix.rs index 21dc7e2a77..dfe1bd4a5b 100644 --- a/crates/rocm-core/src/fix.rs +++ b/crates/rocm-core/src/fix.rs @@ -421,9 +421,9 @@ const RECIPES: &[FixRecipe] = &[ needs_reboot: false, needs_relogin: false, verify: "Run only the line matching your package manager:\n\ - sudo apt update 2>&1 | tail -n 20 # Debian/Ubuntu\n\ - sudo dnf clean all 2>&1 | tail -n 20 # RHEL/Fedora/Rocky/Alma/Oracle\n\ - sudo zypper refresh 2>&1 | tail -n 20 # SLES/openSUSE", + bash -c 'set -o pipefail; sudo apt update 2>&1 | tail -n 20' # Debian/Ubuntu\n\ + bash -c 'set -o pipefail; sudo dnf clean all 2>&1 | tail -n 20' # RHEL/Fedora/Rocky/Alma/Oracle\n\ + bash -c 'set -o pipefail; sudo zypper refresh 2>&1 | tail -n 20' # SLES/openSUSE", notes: &[], doc_url: None, applies_on: PRINT_ON_LINUX, @@ -544,10 +544,13 @@ const RECIPES: &[FixRecipe] = &[ needs_reboot: true, needs_relogin: false, // See the matching comment on this fix's `verify` in diagnose.rs: - // the status column (`^ii`) must be checked, not just that a - // rocm/amdgpu package name appears, or a half-configured package - // (this fix's own target symptom) passes before any remediation. - verify: "(dpkg -l 2>/dev/null | grep -E '^ii' | grep -qE 'rocm|amdgpu' || rpm -qa 2>/dev/null | grep -qE 'rocm|amdgpu') && rocminfo | head -n 5", + // must query the targeted amdgpu-dkms package's installed status + // (not a bare rocm/amdgpu name grep), confirm dkms reports the + // module built, and check rocminfo's own exit code directly. + verify: "(dpkg-query -W -f='${Status}' amdgpu-dkms 2>/dev/null | grep -q 'install ok installed' \ + || rpm -q amdgpu-dkms >/dev/null 2>&1) \ + && dkms status amdgpu 2>/dev/null | grep -q installed \ + && rocminfo >/dev/null 2>&1", notes: &[ "If the purge/remove step warns it will take unrelated packages with it, stop and resolve those by hand before continuing.", ], diff --git a/docs/testing.md b/docs/testing.md index d9b819d51f..156b0c8bc9 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -1610,21 +1610,20 @@ cargo test -p rocm --bin rocm driver_install `driver-install-04` in [driver_install.feature](../tests/e2e-cucumber/features/driver_install.feature) -asserts the apt repo file and signing key this plan writes on a real bare-metal -Linux host. `examine --json`'s `rocm_install_method` also renamed -`amdgpu-install` to `repo-native` and `tarball-or-other` to -`runfile-or-tarball`; see `examine-29` in -[examine.feature](../tests/e2e-cucumber/features/examine.feature). +asserts whichever plan a real bare-metal Linux host actually produces: the apt +repo file and signing key on a release with a published +repo.radeon.com/amdgpu suite, or the native-archive refusal below on one +without. On Ubuntu 26.04, `repo.radeon.com` does not yet publish a matching `resolute` DKMS repo (the amdgpu driver ships in-tree instead), so the plan comes back `supported: false` and directs the user to `apt install rocm`. This arm is covered at the unit level by `driver_plan_ubuntu_2604_uses_native_archive_guidance` and its two neighbors in -[driver_install.rs](../apps/rocm/src/driver_install.rs), but has no e2e/Gherkin -coverage: `read_os_release()` reads -the live `/etc/os-release` with no override, so no lane or host running a -different Ubuntu release can reach this arm through the CLI itself. +[driver_install.rs](../apps/rocm/src/driver_install.rs), and at the e2e level +by `driver-install-04` above: the hosted `E2E tests` job's `ubuntu-26.04` image +reaches this arm through the CLI itself, while the self-hosted GPU lane's +24.04 host exercises the apt arm instead. ## /etc/os-release diff --git a/tests/e2e-cucumber/features/driver_install.feature b/tests/e2e-cucumber/features/driver_install.feature index 62c2735c2e..caa0d7a804 100644 --- a/tests/e2e-cucumber/features/driver_install.feature +++ b/tests/e2e-cucumber/features/driver_install.feature @@ -31,20 +31,36 @@ Feature: Driver installation planning Then the driver plan refuses rather than installing an unverified package # Every bare-metal Linux lane in this repo runs Ubuntu, but not always the - # same release -- the self-hosted GPU lane's real /etc/os-release reports + # same release -- the hosted `E2E tests` job's `ubuntu-26.04` image reports # 26.04 ("resolute"), which `build_driver_install_plan` routes to the # `ubuntu_native_archive` arm instead of the apt one (no repo.radeon.com/ # amdgpu suite published for "resolute" yet; see the `("ubuntu", "26.04")` - # arm in `driver_install.rs`). `--dry-run` previews the plan without writing - # anything, so this is safe on a shared CI host either way: on an apt-arm - # release it asserts the real `apt_driver_plan` command text this binary - # would use to write /etc/apt/sources.list.d/amdgpu.list and import AMD's - # signing key, the same commands the unit fixtures in `driver_install.rs` - # exercise with a hand-written os-release; on 26.04 it asserts the - # native-archive refusal instead, so the scenario proves the CLI's actual - # output on whichever release the lane happens to run rather than - # hard-coding an apt-arm premise a lane can silently outgrow. - @id:driver-install-apt-repo-file-and-key-content @requires-os:linux @requires-bare-metal + # arm in `driver_install.rs`), while the self-hosted GPU lane's real + # /etc/os-release reports 24.04 and takes the apt arm. `--dry-run` previews + # the plan without writing anything, so this is safe on a shared CI host + # either way: on an apt-arm release it asserts the real `apt_driver_plan` + # command text this binary would use to write + # /etc/apt/sources.list.d/amdgpu.list and import AMD's signing key, the + # same commands the unit fixtures in `driver_install.rs` exercise with a + # hand-written os-release; on 26.04 it asserts the native-archive refusal + # instead, so the scenario proves the CLI's actual output on whichever + # release the lane happens to run rather than hard-coding an apt-arm + # premise a lane can silently outgrow. + @id:driver-install-bare-metal-host-plan @requires-os:linux @requires-bare-metal Scenario: driver-install-04 - Previewing the driver install on a real bare-metal host plans release-appropriate driver setup When the user previews driver installation on this host Then the driver plan matches this host's actual Ubuntu release + + # The override is interpolated into privileged shell commands, so a value + # that fails the shell-token allow-list must refuse the plan rather than + # silently falling back to "latest" -- user-observable as a + # `supported: false` plan naming the variable. `ROCM_CLI_AMDGPU_DRIVER_VERSION` + # is only consulted by the Linux DKMS arm, though: `build_driver_install_plan_at` + # checks `is_wsl_host()` and returns the WSL/ROCDXG plan before this override is + # ever resolved, so a WSL host has no premise here (it would hit + # `wsl_rocdxg_driver_plan` regardless of the override and the scenario would + # fail by construction) -- same WSL-vs-bare-metal split as driver-install-04. + @id:driver-install-invalid-version-override-refused @requires-os:linux @requires-bare-metal + Scenario: driver-install-05 - An invalid ROCM_CLI_AMDGPU_DRIVER_VERSION override refuses the plan + When the user previews driver installation with an invalid version override + Then the driver plan refuses the invalid version override and plans no commands diff --git a/tests/e2e-cucumber/features/examine.feature b/tests/e2e-cucumber/features/examine.feature index 504a674547..f0dcbf9427 100644 --- a/tests/e2e-cucumber/features/examine.feature +++ b/tests/e2e-cucumber/features/examine.feature @@ -119,8 +119,8 @@ Feature: GPU detection and system inspection Then the inspection reports Linux as the operating system And the inspection reports that the host is WSL - # The dry-run plan used to print the raw `${ROCM_CLI_AMDGPU_DRIVER_VERSION:-latest}` - # shell placeholder on its `repo_version:` line instead of the effective version, + # The dry-run plan used to print the raw `${ROCM_CLI_AMDGPU_VERSION:-7.2.4}` + # shell placeholder on its `repo_version_expr:` line instead of the effective version, # so the preview a user reviews before approving disagreed with what the install # would actually pull. The plan is rendered on every Linux host regardless of # GPU (the driver is not yet installed when you preview it), so the mock lane diff --git a/tests/e2e-cucumber/tests/e2e/driver_steps.rs b/tests/e2e-cucumber/tests/e2e/driver_steps.rs index 99a3c31834..cc8ade3ee0 100644 --- a/tests/e2e-cucumber/tests/e2e/driver_steps.rs +++ b/tests/e2e-cucumber/tests/e2e/driver_steps.rs @@ -33,14 +33,35 @@ async fn preview_driver_install_on_this_host(world: &mut E2eWorld) { #[then("the driver plan matches this host's actual Ubuntu release")] async fn assert_driver_plan_matches_host_release(world: &mut E2eWorld) { + assert_eq!(world.cli_rc, Some(0), "driver dry-run should succeed"); let output = world.cli_output.as_ref().expect("no driver plan output"); - // Most bare-metal lanes are on an Ubuntu release with a published - // repo.radeon.com/amdgpu suite and take the apt-repo-file plan below, but - // the self-hosted GPU lane's real host reports Ubuntu 26.04 ("resolute"), - // which has none yet and takes `ubuntu_native_archive` instead -- see the - // `("ubuntu", "26.04")` arm in `driver_install.rs`. Assert whichever the - // real host actually produced rather than hard-coding one release. - if output.contains("policy: ubuntu_native_archive") { + + // Derived from the host's own `/etc/os-release`, not from `output` -- + // asserting against the very thing being checked would let a change that + // breaks the arm-selection logic pass by construction. The hosted + // `ubuntu-26.04` E2E image reports 26.04 ("resolute"), which has no + // published repo.radeon.com/amdgpu suite yet and takes + // `ubuntu_native_archive`; the self-hosted GPU lane reports 24.04 and + // takes the apt arm. See the `("ubuntu", "26.04")` arm in + // `driver_install.rs`. + let os_release_text = + rocm_core::hardware_root::read_os_release(rocm_core::hardware_root::identity_path_for_str) + .text() + .to_owned(); + let Ok(os_release) = rocm_core::os_release::parse(&os_release_text) else { + panic!("host's /etc/os-release is unreadable:\n{output}"); + }; + if os_release.get("ID").map(String::as_str) != Some("ubuntu") { + // Every bare-metal Linux lane in this repo runs Ubuntu today, but + // this scenario's premise is Ubuntu specifically (every assertion + // below hard-codes Ubuntu's apt/native-archive command text), so a + // future non-Ubuntu bare-metal lane has no premise here rather than + // failing against text it was never meant to produce. + return; + } + + if os_release.get("VERSION_ID").map(String::as_str) == Some("26.04") { + assert!(output.contains("policy: ubuntu_native_archive"), "{output}"); assert!(output.contains("supported: false"), "{output}"); assert!( output.contains("ships ROCm natively via the standard archive"), @@ -199,3 +220,34 @@ async fn assert_driver_plan_refuses_unverified(world: &mut E2eWorld) { "a refusal must not offer install commands:\n{output}" ); } + +#[when("the user previews driver installation with an invalid version override")] +async fn preview_driver_install_invalid_override(world: &mut E2eWorld) { + let (stdout, stderr, rc) = crate::run_rocm_with_env( + world, + &["install", "driver", "--dkms", "--dry-run"], + &[( + "ROCM_CLI_AMDGPU_DRIVER_VERSION", + "'; touch /tmp/pwned; echo '", + )], + ); + world.cli_output = Some(stdout); + world.cli_stderr = Some(stderr); + world.cli_rc = Some(rc); +} + +#[then("the driver plan refuses the invalid version override and plans no commands")] +async fn assert_driver_plan_refuses_invalid_override(world: &mut E2eWorld) { + let output = world.cli_output.as_ref().expect("no driver plan output"); + assert!( + output.contains("policy: invalid_driver_version_override"), + "{output}" + ); + assert!(output.contains("supported: false"), "{output}"); + assert!(output.contains("mutating: false"), "{output}"); + assert!( + output.contains("ROCM_CLI_AMDGPU_DRIVER_VERSION"), + "{output}" + ); + assert!(output.contains("execution_commands: "), "{output}"); +} From d93e56cda3842f3ecca5e7b60826195603e5ac99 Mon Sep 17 00:00:00 2001 From: Juho Vainio Date: Fri, 23 Oct 2026 14:50:11 +0300 Subject: [PATCH 4/7] fix: address rominf review feedback on repo-native PR (CHANGES_REQUESTED) Blocking: - dkms remediation no longer recommends a plan that fixes nothing - cover ubuntu 26.04 native-archive branch - cover dnf/zypper ls arms, zypp repo scan path, dnf/zypper url overrides - close remaining mutation gaps: is_safe_shell_token widening, rpm --import coverage, probe_rocm_install scan loop, fix-12 verify package pinning Non-blocking: - dnf clean/makecache, deb822 .sources filter gap, older-remote fix-12 evidence loss, skill docs, check_3's self-contradicting 26.04 line, fix-7 verify prose-as-command, stale comments/labels - restore driver_plan_dry_run_repo_version_line_is_resolved regression test - fix-3's static recipe verify string in fix.rs now matches diagnose.rs's split "choose your path" verify (rocm install sdk never loads the amdgpu kernel module, so an unconditional lsmod check was wrong on that path); caught by the fix_3_verify_matches_the_diagnose_copy_verbatim drift guard Signed-off-by: Juho Vainio --- apps/rocm/src/driver_install.rs | 97 +++++- crates/rocm-core/src/diagnose.rs | 349 ++++++++++++++++++- crates/rocm-core/src/examine.rs | 118 ++++++- crates/rocm-core/src/fix.rs | 38 +- skills/rocm-doctor/SKILL.md | 3 +- skills/rocm-doctor/reference.md | 2 +- tests/e2e-cucumber/features/examine.feature | 10 +- tests/e2e-cucumber/tests/e2e/driver_steps.rs | 2 +- 8 files changed, 570 insertions(+), 49 deletions(-) diff --git a/apps/rocm/src/driver_install.rs b/apps/rocm/src/driver_install.rs index 5b8a6c9430..aca25ea5c7 100644 --- a/apps/rocm/src/driver_install.rs +++ b/apps/rocm/src/driver_install.rs @@ -692,7 +692,7 @@ fn wsl_rocdxg_driver_plan(escalation: PrivilegeEscalation) -> DriverInstallPlan if !rocdxg_version_is_well_formed(&version) { return wsl_rocdxg_refusal_plan( // The rejected value is still rendered into the plan's - // `repo_version_expr:` line so the user can see what was refused — but + // `repo_version:` line so the user can see what was refused — but // that line is part of a plan a human reads to decide, and a raw // value containing a newline could forge further lines in it. The // debug form escapes newlines and makes trailing space visible, @@ -923,7 +923,7 @@ fn build_driver_install_plan_at( // Always "latest" even if `ROCM_CLI_AMDGPU_DRIVER_VERSION` names // something else or is malformed: unlike the Linux arms below, // this value has not gone through `resolve_repo_version_expr()`, - // so do not read the printed `repo_version_expr:` line here (or in + // so do not read the printed `repo_version:` line here (or in // `--dry-run` output) as confirmation that an override was seen or // accepted. repo_version_expr: "latest".to_owned(), @@ -1318,7 +1318,7 @@ fn apt_driver_plan( driver_command( DriverCommandPhase::Prepare, &format!( - "curl -fsSL https://repo.radeon.com/rocm/rocm.gpg.key | {sudo}gpg --dearmor -o /etc/apt/keyrings/rocm.gpg" + "curl -fsSL https://repo.radeon.com/rocm/rocm.gpg.key | {sudo}gpg --batch --yes --dearmor -o /etc/apt/keyrings/rocm.gpg" ), ), driver_command( @@ -2366,9 +2366,8 @@ mod tests { "the apt-source pipeline must still tee, unprefixed: {commands:?}" ); assert!( - commands - .iter() - .any(|command| command.contains("| gpg --dearmor -o /etc/apt/keyrings/rocm.gpg")), + commands.iter().any(|command| command + .contains("| gpg --batch --yes --dearmor -o /etc/apt/keyrings/rocm.gpg")), "the keyring pipeline must still call gpg, unprefixed: {commands:?}" ); } @@ -2505,6 +2504,28 @@ mod tests { ); } + #[test] + fn driver_plan_dry_run_repo_version_line_is_resolved() { + let _env = ScopedTestEnv::with_amd_overrides_cleared(); + // Regression for the dry-run output leaking the wrong field (or, under + // the old shell-template scheme this replaced, a raw unresolved + // placeholder) on the `repo_version:` line instead of the version the + // plan actually resolved. + let os_release = r#" +ID=rhel +VERSION_ID="9.7" +"#; + let plan = build_driver_install_plan_read( + &test_examine("linux", false), + &os_release_found(os_release), + true, + PrivilegeEscalation::Sudo, + ); + let rendered = render_driver_install_plan(&plan, false, true); + + assert!(rendered.contains(" repo_version: latest"), "{rendered}"); + } + #[test] fn driver_plan_ubuntu_2404_uses_official_dkms_commands() { let _env = ScopedTestEnv::with_amd_overrides_cleared(); @@ -3100,6 +3121,22 @@ VERSION_CODENAME=noble ); } + #[test] + fn is_safe_shell_token_rejects_quote_and_semicolon_payloads() { + // The hostile-codename/version-id/os-id tests above only ever send + // `$(id)` through this filter, which proves the metacharacter + // denylist works for *that* payload -- but a widened character class + // that happened to still reject `$`, `(`, `)` while now accepting + // `'`/`;` would pass every one of them undetected. `'` breaks out of + // this value's enclosing single-quoted shell string outright, and + // `;` chains a second command once out, so both must be checked + // directly against the function itself, not only indirectly. + assert!(!is_safe_shell_token("6.2.1'")); + assert!(!is_safe_shell_token("6.2.1;rm")); + assert!(!is_safe_shell_token("';rm -rf /;'")); + assert!(is_safe_shell_token("6.2.1")); + } + #[test] fn driver_reconcile_without_state_gives_non_privileged_guidance() -> Result<()> { let (root, paths) = test_paths("driver-reconcile-empty"); @@ -3382,6 +3419,10 @@ VERSION_ID="9.7" rendered .contains("sudo dnf install -y kernel-headers kernel-devel kernel-devel-matched") ); + // Rocky is `Generic`, not `Rhel`, in `DnfDriverDistro` -- confirms the + // `rpm --import` push is unconditional across the dnf match arms, not + // only wired for the `Rhel`/`Oracle` arms the other two tests cover. + assert!(rendered.contains("sudo rpm --import https://repo.radeon.com/rocm/rocm.gpg.key")); assert!( rendered.contains("baseurl=https://repo.radeon.com/amdgpu/latest/el/9.7/main/x86_64") ); @@ -3406,6 +3447,7 @@ VERSION_ID="9.4" assert!(plan.supported); assert!(plan.mutating); + assert!(rendered.contains("sudo rpm --import https://repo.radeon.com/rocm/rocm.gpg.key")); assert!( rendered.contains("baseurl=https://repo.radeon.com/amdgpu/latest/el/9.4/main/x86_64") ); @@ -3496,6 +3538,47 @@ VERSION_ID="15.7" assert!(rendered.contains("approval: required")); } + #[test] + fn sles_repo_baseurl_uses_the_given_repo_version_expr_not_a_hardcoded_latest() { + // Mutation-proofs the parameter wiring itself: a mutation that + // hardcoded `latest` into this function's body left every existing + // SLES test green because their default env override also resolves + // to `latest`, so none of them could tell "wired correctly" apart + // from "hardcoded to the same value the default happens to be". + assert_eq!( + sles_repo_baseurl("6.2.1", "15.7"), + "https://repo.radeon.com/amdgpu/6.2.1/sle/15.7/main/x86_64" + ); + assert_eq!( + sles_repo_baseurl("latest", "15.7"), + "https://repo.radeon.com/amdgpu/latest/sle/15.7/main/x86_64" + ); + } + + #[test] + fn driver_plan_sles_overrides_the_repo_version_via_the_driver_version_env() { + let mut env = ScopedTestEnv::with_amd_overrides_cleared(); + env.set("ROCM_CLI_AMDGPU_DRIVER_VERSION", "6.2.1"); + let os_release = r#" +ID=sles +VERSION_ID="15.7" +"#; + let plan = build_driver_install_plan_read( + &test_examine("linux", false), + &os_release_found(os_release), + true, + PrivilegeEscalation::Sudo, + ); + let rendered = render_driver_install_plan(&plan, false, false); + + assert!(plan.supported); + assert!( + rendered.contains("baseurl=https://repo.radeon.com/amdgpu/6.2.1/sle/15.7/main/x86_64"), + "an overridden ROCM_CLI_AMDGPU_DRIVER_VERSION must reach the SLES repo baseurl, \ + not a hardcoded `latest`: {rendered}" + ); + } + #[test] fn driver_plan_unsupported_linux_is_non_mutating() { let _env = ScopedTestEnv::with_amd_overrides_cleared(); @@ -4140,6 +4223,7 @@ ID_LIKE="rhel centos fedora" assert!(!rendered.contains("/rhel/9.6/")); // el9 uses the version-aware standard-kernel prepare commands. assert!(rendered.contains("kernel-devel-matched-$(uname -r)")); + assert!(rendered.contains("sudo rpm --import https://repo.radeon.com/rocm/rocm.gpg.key")); assert!(rendered.contains("Execute: sudo dnf install -y amdgpu-dkms")); } @@ -4167,6 +4251,7 @@ ID_LIKE="rhel centos fedora" // el8 has no kernel-devel-matched package. assert!(!rendered.contains("kernel-devel-matched")); assert!(rendered.contains("kernel-devel-$(uname -r)")); + assert!(rendered.contains("sudo rpm --import https://repo.radeon.com/rocm/rocm.gpg.key")); } #[test] diff --git a/crates/rocm-core/src/diagnose.rs b/crates/rocm-core/src/diagnose.rs index e5484114fe..d9f4c34cbe 100644 --- a/crates/rocm-core/src/diagnose.rs +++ b/crates/rocm-core/src/diagnose.rs @@ -842,20 +842,36 @@ fn check_3_rocm_kernel_unsupported(e: &Examination, symptom: &str) -> Diagnosis format!("# Current: kernel={kernel} distro={distro} {distro_v} rocm={rocm_version}"), "# Compare to the live AMD matrix:".to_owned(), "# https://rocm.docs.amd.com/projects/install-on-linux/en/latest/reference/system-requirements.html".to_owned(), - "# If your kernel is above the supported range, install the HWE".to_owned(), - "# kernel that matches ROCm, then rerun `rocm install driver --dkms --yes`.".to_owned(), - "# To avoid the DKMS build entirely, use `rocm install sdk` instead:".to_owned(), - "# it installs the userspace ROCm stack without touching the kernel module.".to_owned(), ]; if ubuntu_driver_is_native_archive(e) { commands.push("# Not on Ubuntu 26.04: the amdgpu driver ships in-tree there, so `rocm install driver --dkms` plans nothing; run `sudo apt install rocm` instead.".to_owned()); + } else if dkms_driver_plan_is_supported(e) { + commands.push("# If your kernel is above the supported range, install the HWE".to_owned()); + commands.push( + "# kernel that matches ROCm, then rerun `rocm install driver --dkms --yes`.".to_owned(), + ); + } else { + commands.push(format!( + "# `rocm install driver --dkms` plans nothing on {distro} {distro_v}: it isn't one of the AMD-documented distros/versions above, so rerunning it won't fix this." + )); } + commands.push("# To avoid the DKMS build entirely, use `rocm install sdk` instead:".to_owned()); + commands.push( + "# it installs the userspace ROCm stack without touching the kernel module.".to_owned(), + ); let fix = Fix { summary: "Cross-check your kernel/distro against the live AMD compatibility matrix before reinstalling.".to_owned(), commands, fix_id: "fix-3-rocm-kernel".to_owned(), needs_reboot: true, - verify: "lsmod | grep amdgpu && rocminfo | head -n 20".to_owned(), + // `rocm install sdk` deliberately never loads the amdgpu kernel + // module (that's the point of avoiding the DKMS build), so a + // `lsmod | grep amdgpu` requirement would fail that path even when it + // worked; only require it if you took the driver-reinstall path above. + verify: "# Run only the line matching the path you took above:\n\ + lsmod | grep amdgpu && rocminfo | head -n 20 # drive reinstall path\n\ + rocminfo | head -n 20 # `rocm install sdk` (userspace-only) path" + .to_owned(), ..Fix::default() }; finalize( @@ -1101,7 +1117,12 @@ fn check_6_path_missing(e: &Examination, symptom: &str) -> Diagnosis { fn refresh_command_for_family(family: &str) -> Option<&'static str> { match family { "apt" => Some("apt update"), - "dnf" => Some("dnf clean all"), + // `dnf clean all` only deletes the local cache and always exits 0; it + // can't fail even when a repo file is malformed or unreachable, which + // is exactly what `verify` needs to catch. `dnf makecache` re-fetches + // and parses the metadata, so it fails loudly in that case, matching + // `apt update` and `zypper refresh` below. + "dnf" => Some("dnf makecache"), "zypper" => Some("zypper refresh"), _ => None, } @@ -1152,10 +1173,15 @@ fn check_7_stale_repos(e: &Examination, symptom: &str) -> Diagnosis { ); if ubuntu_driver_is_native_archive(e) { commands.push("# sudo apt install rocm # Ubuntu 26.04 ships the amdgpu driver in-tree, so there is no DKMS driver to reinstall".to_owned()); - } else { + } else if dkms_driver_plan_is_supported(e) { commands.push("# rocm install driver --dkms # review the plan".to_owned()); commands .push("# rocm install driver --dkms --yes # reinstalls the driver only".to_owned()); + } else { + commands.push(format!( + "# `rocm install driver --dkms` plans nothing on {} {}: it isn't one of the AMD-documented distros/versions; see https://rocm.docs.amd.com/projects/install-on-linux/en/latest/reference/system-requirements.html", + e.distro_id, e.distro_version + )); } let verify = match refresh_command_for_family(family) { // `set -o pipefail` so the exit status reflects `{cmd}` itself, not @@ -1194,7 +1220,7 @@ fn check_7_stale_repos(e: &Examination, symptom: &str) -> Diagnosis { }; finalize( "fix-7-stale-repos", - "Stale or conflicting APT/DNF repos from prior installer runs", + "Stale or conflicting APT/DNF/zypper repos from prior installer runs", score, evidence, fix, @@ -1536,8 +1562,13 @@ fn repo_pkg_family(e: &Examination) -> &'static str { /// `examine.rs`): a host without one of `REPO_NATIVE_INSTALL_MARKERS` present /// but whose package manager confirms `rocm-hip-runtime` is installed is /// still repo-native-managed, just detected a different way. +/// +/// `"amdgpu-install"` is kept as a legacy alias of `"repo-native"`: an older +/// `rocm remote doctor` client can still send the retired value for a while +/// after this rename, and dropping it here would silently lose fix-12 +/// evidence for that machine rather than just serving a stale label. fn is_repo_native_installed(method: &str) -> bool { - matches!(method, "repo-native" | "apt" | "dnf") + matches!(method, "repo-native" | "amdgpu-install" | "apt" | "dnf") } /// Whether `rocm install driver --dkms` has nothing to reinstall on this @@ -1552,6 +1583,41 @@ fn ubuntu_driver_is_native_archive(e: &Examination) -> bool { e.distro_id.eq_ignore_ascii_case("ubuntu") && e.distro_version == "26.04" } +/// Whether `rocm install driver --dkms` plans any commands at all for this +/// host, mirroring the full `(os_id, version_id)` / `ID_LIKE`-derivative +/// matrix in `apps/rocm/src/driver_install.rs::build_driver_install_plan_at` +/// (`rocm-core` can't call that plan builder directly -- see +/// `ubuntu_driver_is_native_archive` above for why). Ubuntu 26.04 is +/// deliberately excluded here even though its plan is also "no DKMS repo +/// commands": that host has its own guidance (native archive, `apt install +/// rocm`), handled separately via `ubuntu_driver_is_native_archive`, not the +/// "no plan was guessed for this distro at all" case this function reports. +fn dkms_driver_plan_is_supported(e: &Examination) -> bool { + let os_id = e.distro_id.to_ascii_lowercase(); + let version_id = e.distro_version.as_str(); + match (os_id.as_str(), version_id) { + ("ubuntu", "22.04" | "24.04") => true, + ("debian", "12" | "13") => true, + ("rhel", "10.1" | "10.0" | "9.7" | "9.6" | "9.4" | "8.10") => true, + ("ol", "10.1" | "9.7" | "8.10") => true, + ("rocky", "9.4" | "9.6" | "9.7") => true, + ("sles" | "sle", "15.7") => true, + _ => { + let likes: Vec = e + .distro_id_like + .split_whitespace() + .map(str::to_ascii_lowercase) + .collect(); + let mentions = |family: &str| likes.iter().any(|like| like == family); + (mentions("ubuntu") && matches!(version_id, "22.04" | "24.04")) + || (mentions("debian") && matches!(version_id, "12" | "13")) + || (mentions("rhel") + && !matches!(os_id.as_str(), "ol" | "oracle") + && matches!(version_id, "10.1" | "10.0" | "9.7" | "9.6" | "9.4" | "8.10")) + } + } +} + fn check_12_repo_native_broken(e: &Examination, symptom: &str) -> Diagnosis { let mut score = 0; let mut evidence = Vec::new(); @@ -1586,9 +1652,17 @@ fn check_12_repo_native_broken(e: &Examination, symptom: &str) -> Diagnosis { ); commands.push("# forget the broken state before reinstalling.".to_owned()); if e.rocm_repos_seen.is_empty() { - commands.push( - "# sudo mv /etc/apt/sources.list.d/amdgpu.list /etc/apt/sources.list.d/amdgpu.list.bak # or the yum/zypp equivalent".to_owned(), - ); + // No repo file was actually seen on this host, so show an example + // matching the detected package family rather than always the apt + // path -- a dnf/zypper host has no `/etc/apt/` at all. + let example = match family { + "dnf" => "/etc/yum.repos.d/amdgpu.repo", + "zypper" => "/etc/zypp/repos.d/amdgpu.repo", + _ => "/etc/apt/sources.list.d/amdgpu.list", + }; + commands.push(format!( + "# sudo mv {example} {example}.bak # or the equivalent for your package manager" + )); } else { for r in &e.rocm_repos_seen { commands.push(format!( @@ -1608,10 +1682,21 @@ fn check_12_repo_native_broken(e: &Examination, symptom: &str) -> Diagnosis { ); commands.push("sudo apt install rocm".to_owned()); "Clear the half-configured package state, quarantine the repo-native install's repo files, THEN reinstall the userspace stack via `sudo apt install rocm` (Ubuntu 26.04 ships the amdgpu kernel driver in-tree, so there is no DKMS driver to reinstall).".to_owned() - } else { + } else if dkms_driver_plan_is_supported(e) { commands.push("# Reinstall via rocm-cli's repo-native flow:".to_owned()); commands.push("rocm install driver --dkms --yes".to_owned()); "Clear the half-configured package/DKMS state, quarantine the repo-native install's repo files, THEN reinstall via `rocm install driver --dkms --yes`.".to_owned() + } else { + commands.push( + "# rocm-cli has no automated DKMS driver plan for this distro; reinstall the" + .to_owned(), + ); + commands.push("# driver manually per AMD's install docs:".to_owned()); + commands.push("# https://rocm.docs.amd.com/projects/install-on-linux/en/latest/reference/system-requirements.html".to_owned()); + format!( + "Clear the half-configured package/DKMS state and quarantine the repo-native install's repo files; rocm-cli has no automated DKMS driver plan for {} {}, so reinstall the driver manually per AMD's docs.", + e.distro_id, e.distro_version + ) }; // Query the package manager's own records, not `rocm examine`'s @@ -1640,12 +1725,18 @@ fn check_12_repo_native_broken(e: &Examination, symptom: &str) -> Diagnosis { "dpkg-query -W -f='${Status}' rocm 2>/dev/null | grep -q 'install ok installed' \ && rocminfo >/dev/null 2>&1" .to_owned() - } else { + } else if dkms_driver_plan_is_supported(e) { "(dpkg-query -W -f='${Status}' amdgpu-dkms 2>/dev/null | grep -q 'install ok installed' \ || rpm -q amdgpu-dkms >/dev/null 2>&1) \ && dkms status amdgpu 2>/dev/null | grep -q installed \ && rocminfo >/dev/null 2>&1" .to_owned() + } else { + // No AMD-documented package/DKMS name to check on an undocumented + // distro -- the manual reinstall above is on the user, not rocm-cli, + // so the only thing this fix itself can still assert is that the + // GPU stack actually works afterward. + "rocminfo >/dev/null 2>&1".to_owned() }; let fix = Fix { summary, @@ -7109,6 +7200,177 @@ mod tests { assert_eq!(repo_pkg_family(&e), "unknown"); } + #[test] + fn kernel_unsupported_on_ubuntu_26_04_names_the_native_archive_path() { + let mut e = linux_base(); + e.distro_id = "ubuntu".to_owned(); + e.distro_version = "26.04".to_owned(); + e.rocm_version = "7.0.0".to_owned(); + e.amdgpu_loaded = Some(false); + let report = diagnose(&e, "kernel/rocm mismatch"); + let hit = report + .matched + .iter() + .find(|d| d.id == "fix-3-rocm-kernel") + .expect("unsupported kernel triple should be diagnosed"); + let commands = hit.fix.as_ref().unwrap().commands.join("\n"); + assert!( + commands.contains("Not on Ubuntu 26.04") && commands.contains("sudo apt install rocm"), + "Ubuntu 26.04 must be told to use the native archive path, not a DKMS rerun: {commands}" + ); + assert!( + !commands.contains("rerun `rocm install driver --dkms --yes`"), + "Ubuntu 26.04 must not be told to rerun a command that plans nothing there: {commands}" + ); + } + + #[test] + fn kernel_unsupported_on_an_undocumented_distro_does_not_suggest_a_dkms_rerun() { + let mut e = linux_base(); + e.distro_id = "fedora".to_owned(); + e.distro_version = "40".to_owned(); + e.rocm_version = "7.0.0".to_owned(); + e.amdgpu_loaded = Some(false); + let report = diagnose(&e, "kernel/rocm mismatch"); + let hit = report + .matched + .iter() + .find(|d| d.id == "fix-3-rocm-kernel") + .expect("unsupported kernel triple should be diagnosed"); + let commands = hit.fix.as_ref().unwrap().commands.join("\n"); + assert!( + commands.contains("plans nothing on fedora 40"), + "an undocumented distro must be told the dkms command plans nothing, not rerun it: {commands}" + ); + assert!( + !commands.contains("rerun `rocm install driver --dkms --yes`"), + "an undocumented distro must not be told to rerun a command that plans nothing: {commands}" + ); + } + + #[test] + fn stale_repos_on_ubuntu_26_04_suggests_apt_install_rocm_not_a_dkms_reinstall() { + let mut e = linux_base(); + e.distro_id = "ubuntu".to_owned(); + e.distro_version = "26.04".to_owned(); + e.rocm_repos_seen = vec![ + "/etc/apt/sources.list.d/amdgpu.list".to_owned(), + "/etc/apt/sources.list.d/rocm.list".to_owned(), + ]; + let report = diagnose(&e, "stale repo conflict"); + let hit = report + .matched + .iter() + .find(|d| d.id == "fix-7-stale-repos") + .expect("duplicate repo files should be diagnosed"); + let commands = hit.fix.as_ref().unwrap().commands.join("\n"); + assert!( + commands.contains("sudo apt install rocm") + && commands.contains("Ubuntu 26.04 ships the amdgpu driver in-tree"), + "Ubuntu 26.04 must be pointed at the native archive reinstall, not DKMS: {commands}" + ); + assert!( + !commands.contains("rocm install driver --dkms --yes"), + "Ubuntu 26.04 must not be offered a DKMS reinstall that plans nothing there: {commands}" + ); + } + + #[test] + fn stale_repos_on_an_undocumented_dnf_distro_does_not_suggest_a_dkms_reinstall() { + let mut e = linux_base(); + e.distro_id = "fedora".to_owned(); + e.distro_version = "40".to_owned(); + e.rocm_repos_seen = vec![ + "/etc/yum.repos.d/amdgpu.repo".to_owned(), + "/etc/yum.repos.d/rocm.repo".to_owned(), + ]; + let report = diagnose(&e, "stale repo conflict"); + let hit = report + .matched + .iter() + .find(|d| d.id == "fix-7-stale-repos") + .expect("duplicate repo files should be diagnosed"); + let commands = hit.fix.as_ref().unwrap().commands.join("\n"); + assert!( + commands.contains("plans nothing on fedora 40"), + "an undocumented dnf distro must be told the dkms command plans nothing: {commands}" + ); + assert!( + !commands.contains("rocm install driver --dkms --yes") + && !commands.contains("rocm install driver --dkms # review the plan"), + "an undocumented distro must not be offered a DKMS reinstall that plans nothing: {commands}" + ); + } + + #[test] + fn repo_native_broken_on_ubuntu_26_04_reinstalls_the_userspace_stack_not_dkms() { + let mut e = linux_base(); + e.distro_id = "ubuntu".to_owned(); + e.distro_version = "26.04".to_owned(); + e.rocm_install_method = "repo-native".to_owned(); + e.rocm_repos_seen = vec!["/etc/apt/sources.list.d/amdgpu.list".to_owned()]; + let report = diagnose( + &e, + "dpkg: error processing package amdgpu-dkms (half-configured)", + ); + let hit = report + .matched + .iter() + .find(|d| d.id == "fix-12-installer") + .expect("repo-native broken state should be diagnosed"); + let fix = hit.fix.as_ref().unwrap(); + let commands = fix.commands.join("\n"); + assert!( + commands.contains("sudo apt install rocm"), + "Ubuntu 26.04 must reinstall the userspace stack, not a DKMS driver: {commands}" + ); + assert!( + !commands.contains("rocm install driver --dkms --yes"), + "Ubuntu 26.04 must not be offered a DKMS reinstall that plans nothing there: {commands}" + ); + assert!( + fix.verify.contains("dpkg-query -W -f='${Status}' rocm") + && !fix.verify.contains("amdgpu-dkms"), + "Ubuntu 26.04's verify must check the `rocm` package, not a nonexistent DKMS module: {}", + fix.verify + ); + } + + #[test] + fn repo_native_broken_on_an_undocumented_distro_tells_the_user_to_reinstall_manually() { + let mut e = linux_base(); + e.distro_id = "fedora".to_owned(); + e.distro_version = "40".to_owned(); + e.rocm_install_method = "repo-native".to_owned(); + e.rocm_repos_seen = vec!["/etc/yum.repos.d/amdgpu.repo".to_owned()]; + let report = diagnose( + &e, + "dpkg: error processing package amdgpu-dkms (half-configured)", + ); + let hit = report + .matched + .iter() + .find(|d| d.id == "fix-12-installer") + .expect("repo-native broken state should be diagnosed"); + let fix = hit.fix.as_ref().unwrap(); + let commands = fix.commands.join("\n"); + assert!( + commands.contains("no automated DKMS driver plan for this distro") + && commands.contains("system-requirements.html"), + "an undocumented distro must be sent to AMD's manual install docs: {commands}" + ); + assert!( + !commands.contains("rocm install driver --dkms --yes"), + "an undocumented distro must not be offered a DKMS reinstall that plans nothing: {commands}" + ); + assert_eq!( + fix.verify, "rocminfo >/dev/null 2>&1", + "with no AMD-documented package/DKMS name to check, verify must fall back to \ + confirming the GPU stack works, not assert an unknowable package state: {}", + fix.verify + ); + } + #[test] fn stale_repos_on_a_sles_host_gets_zypper_commands_not_apt() { // A SLES host whose repo files now live under /etc/zypp/repos.d/ (the @@ -7162,7 +7424,7 @@ mod tests { let fix = hit.fix.as_ref().unwrap(); let commands = fix.commands.join("\n"); assert!( - commands.contains("/etc/yum.repos.d/") && commands.contains("sudo dnf clean all"), + commands.contains("/etc/yum.repos.d/") && commands.contains("sudo dnf makecache"), "a dnf host must get dnf remediation: {commands}" ); assert!( @@ -7170,7 +7432,7 @@ mod tests { "a dnf host must not be told to run apt/dpkg/zypper commands: {commands}" ); assert!( - fix.verify.contains("sudo dnf clean all"), + fix.verify.contains("sudo dnf makecache"), "a dnf host's verify step must also use dnf, not apt: {}", fix.verify ); @@ -7287,6 +7549,18 @@ mod tests { ); } + #[test] + fn is_repo_native_installed_still_accepts_the_retired_amdgpu_install_value() { + // An older `rocm remote doctor` client can report the pre-rename + // value for a while after this PR; it must still count as + // repo-native-managed, not silently fall through to "not a + // package-manager install" and lose fix-12 evidence. + assert!(is_repo_native_installed("amdgpu-install")); + assert!(is_repo_native_installed("repo-native")); + assert!(!is_repo_native_installed("runfile-or-tarball")); + assert!(!is_repo_native_installed("")); + } + #[test] fn repo_native_broken_verify_requires_dpkg_status_not_just_name_presence() { // `method == "apt"` here is the exact pre-fix state `is_repo_native_installed` @@ -7296,6 +7570,8 @@ mod tests { // re-ran that same bare name grep, it would already be true here, before any // of this fix's remediation commands run. let mut e = linux_base(); + e.distro_id = "ubuntu".to_owned(); + e.distro_version = "22.04".to_owned(); e.rocm_install_method = "apt".to_owned(); let report = diagnose( &e, @@ -7314,6 +7590,13 @@ mod tests { stock packages (e.g. libdrm-amdgpu1) and a healthy rocm-* package sitting \ next to the broken amdgpu-dkms this fix targets: {verify}" ); + assert!( + verify.contains("dpkg-query -W -f='${Status}' amdgpu-dkms"), + "verify must query dpkg's status for amdgpu-dkms by name, not merely contain \ + the right-shaped status-field query against some other package -- pinning \ + the package name closes the gap where the targeted name could be swapped \ + for an unrelated one and this test would still pass: {verify}" + ); assert!( verify.contains("dkms status amdgpu"), "verify must also confirm dkms reports the module actually built: {verify}" @@ -7328,6 +7611,8 @@ mod tests { #[test] fn repo_native_broken_fires_and_clears_state_before_reinstall() { let mut e = linux_base(); + e.distro_id = "ubuntu".to_owned(); + e.distro_version = "22.04".to_owned(); e.rocm_install_method = "repo-native".to_owned(); e.rocm_repos_seen = vec!["/etc/apt/sources.list.d/amdgpu.list".to_owned()]; let report = diagnose( @@ -7391,7 +7676,7 @@ mod tests { let commands = hit.fix.as_ref().unwrap().commands.join("\n"); assert!( commands.contains("sudo dnf remove -y amdgpu-dkms") - && commands.contains("sudo dnf clean all"), + && commands.contains("sudo dnf makecache"), "a dnf host must get dnf remediation: {commands}" ); assert!( @@ -7427,6 +7712,36 @@ mod tests { ); } + #[test] + fn repo_native_broken_quarantine_example_matches_the_family_when_no_repo_was_seen() { + // With no repo file recorded (`rocm_repos_seen` empty), the quarantine + // line falls back to an example path -- it must match the host's own + // package family, not always show the apt path on a dnf/zypper host + // that has no `/etc/apt/` at all. + let mut e = linux_base(); + e.distro_id = "sles".to_owned(); + e.rocm_install_method = "repo-native".to_owned(); + e.rocm_repos_seen = Vec::new(); + let report = diagnose( + &e, + "dpkg: error processing package amdgpu-dkms (half-configured)", + ); + let hit = report + .matched + .iter() + .find(|d| d.id == "fix-12-installer") + .expect("repo-native broken state should be diagnosed"); + let commands = hit.fix.as_ref().unwrap().commands.join("\n"); + assert!( + commands.contains("/etc/zypp/repos.d/amdgpu.repo"), + "a zypper host's fallback quarantine example must show a zypp path: {commands}" + ); + assert!( + !commands.contains("/etc/apt/"), + "a zypper host must not show an apt path as its quarantine example: {commands}" + ); + } + #[test] fn repo_native_broken_does_not_claim_repo_native_evidence_for_other_install_methods() { // Regression test: an empty symptom would short-circuit keyword_score to diff --git a/crates/rocm-core/src/examine.rs b/crates/rocm-core/src/examine.rs index dab3935ab8..12fe77df08 100644 --- a/crates/rocm-core/src/examine.rs +++ b/crates/rocm-core/src/examine.rs @@ -1989,13 +1989,14 @@ fn repo_native_method_from_markers(existing: &[&str]) -> Option<(&'static str, V // `name` is already lowercased by the caller, so a plain suffix match is fine. #[allow(clippy::case_sensitive_file_extension_comparisons)] fn is_live_rocm_repo_file_name(name: &str) -> bool { - // Allowlist the known repo-file extensions (apt's `.list`, dnf/zypper's - // `.repo`) rather than denylist known quarantine suffixes: quarantining - // appends to the name (`amdgpu.list` -> `amdgpu.list.bak`), so this also - // excludes any quarantine convention this file doesn't know about, and - // stops an unrelated file that merely mentions "rocm"/"amdgpu" in its - // name (a note, a log) from being swept up as a live repo file. - (name.ends_with(".list") || name.ends_with(".repo")) + // Allowlist the known repo-file extensions (apt's one-line-style `.list`, + // apt's deb822-style `.sources`, dnf/zypper's `.repo`) rather than + // denylist known quarantine suffixes: quarantining appends to the name + // (`amdgpu.list` -> `amdgpu.list.bak`), so this also excludes any + // quarantine convention this file doesn't know about, and stops an + // unrelated file that merely mentions "rocm"/"amdgpu" in its name (a + // note, a log) from being swept up as a live repo file. + (name.ends_with(".list") || name.ends_with(".repo") || name.ends_with(".sources")) && (name.contains("rocm") || name.contains("amdgpu") || name.contains("radeon")) } @@ -2063,11 +2064,25 @@ fn probe_rocm_install(e: &mut Examination) { }; } - for dir in [ - "/etc/apt/sources.list.d", - "/etc/yum.repos.d", - "/etc/zypp/repos.d", - ] { + merge_live_repo_paths(e, &REPO_SCAN_DIRS); +} + +/// The repo directories `probe_rocm_install` scans for live (non-quarantined) +/// ROCm/AMDGPU repo files, named so a test can assert each family's directory +/// is actually present rather than only being provable by reading real system +/// paths (SLES repo detection via `/etc/zypp/repos.d` is new in this PR). +const REPO_SCAN_DIRS: [&str; 3] = [ + "/etc/apt/sources.list.d", + "/etc/yum.repos.d", + "/etc/zypp/repos.d", +]; + +/// Split out from `probe_rocm_install` so the directory loop itself -- not +/// just `is_live_rocm_repo_file_name` and `live_rocm_repo_paths_in_dir` in +/// isolation -- is driven by a test against real (temp) directories standing +/// in for each family's repo path. +fn merge_live_repo_paths(e: &mut Examination, dirs: &[&str]) { + for dir in dirs { for full in live_rocm_repo_paths_in_dir(dir) { if !e.rocm_repos_seen.contains(&full) { e.rocm_repos_seen.push(full); @@ -3348,6 +3363,16 @@ mod tests { assert!(!is_live_rocm_repo_file_name("rocm-notes.txt")); } + #[test] + fn is_live_rocm_repo_file_name_recognizes_deb822_sources_files() { + // Newer apt defaults to the deb822 `.sources` format (as opposed to + // the one-line-style `.list`); fix-7's own `ls | grep` advice has no + // extension filter and already matches these, so this filter must + // not be the one place that silently misses them. + assert!(is_live_rocm_repo_file_name("amdgpu.sources")); + assert!(!is_live_rocm_repo_file_name("amdgpu.sources.bak")); + } + #[test] fn live_rocm_repo_paths_in_dir_skips_a_real_bak_file_on_disk() { // `is_live_rocm_repo_file_name` above only proves the name filter is @@ -3368,6 +3393,75 @@ mod tests { assert!(seen[0].ends_with("amdgpu.list")); } + #[test] + fn repo_scan_dirs_covers_all_three_package_families() { + // Mutation-proofs the literal dir list `probe_rocm_install` scans: + // deleting the `/etc/zypp/repos.d` entry (SLES repo detection, new in + // this PR) left every existing test green because nothing previously + // asserted this list's contents directly. + assert!(REPO_SCAN_DIRS.contains(&"/etc/apt/sources.list.d")); + assert!(REPO_SCAN_DIRS.contains(&"/etc/yum.repos.d")); + assert!(REPO_SCAN_DIRS.contains(&"/etc/zypp/repos.d")); + } + + #[test] + fn merge_live_repo_paths_scans_every_family_dir_including_zypp() { + // Drives `probe_rocm_install`'s actual scan loop (not just its two + // helpers in isolation) across temp directories standing in for all + // three package families, including the zypp one a mutation run + // showed was silently unscanned by every pre-existing test. + let apt_dir = tempfile::tempdir().expect("create apt temp dir"); + let yum_dir = tempfile::tempdir().expect("create yum temp dir"); + let zypp_dir = tempfile::tempdir().expect("create zypp temp dir"); + std::fs::write(apt_dir.path().join("amdgpu.list"), "deb ...\n").expect("write apt repo"); + std::fs::write(yum_dir.path().join("amdgpu.repo"), "[amdgpu]\n").expect("write yum repo"); + std::fs::write(zypp_dir.path().join("amdgpu.repo"), "[amdgpu]\n").expect("write zypp repo"); + + let mut e = Examination::default(); + let dirs = [ + apt_dir.path().to_string_lossy().into_owned(), + yum_dir.path().to_string_lossy().into_owned(), + zypp_dir.path().to_string_lossy().into_owned(), + ]; + let dir_refs: Vec<&str> = dirs.iter().map(String::as_str).collect(); + merge_live_repo_paths(&mut e, &dir_refs); + + assert_eq!(e.rocm_repos_seen.len(), 3, "seen: {:?}", e.rocm_repos_seen); + assert!( + e.rocm_repos_seen + .iter() + .any(|p| p.starts_with(dirs[0].as_str())) + ); + assert!( + e.rocm_repos_seen + .iter() + .any(|p| p.starts_with(dirs[1].as_str())) + ); + assert!( + e.rocm_repos_seen + .iter() + .any(|p| p.starts_with(dirs[2].as_str())) + ); + } + + #[test] + fn merge_live_repo_paths_does_not_duplicate_an_already_seen_path() { + let dir = tempfile::tempdir().expect("create temp dir"); + std::fs::write(dir.path().join("amdgpu.repo"), "[amdgpu]\n").expect("write repo"); + let dir_str = dir.path().to_string_lossy().into_owned(); + + let mut e = Examination::default(); + e.rocm_repos_seen.push(format!("{dir_str}/amdgpu.repo")); + merge_live_repo_paths(&mut e, &[dir_str.as_str()]); + + assert_eq!( + e.rocm_repos_seen.len(), + 1, + "an already-recorded path must not be duplicated: {:?}", + e.rocm_repos_seen + ); + } + /// A Linux host with an AMD GPU, so `compute_status` turns on the probe /// failures alone. fn linux_host_with_a_gpu() -> Examination { diff --git a/crates/rocm-core/src/fix.rs b/crates/rocm-core/src/fix.rs index dfe1bd4a5b..84b3953fc3 100644 --- a/crates/rocm-core/src/fix.rs +++ b/crates/rocm-core/src/fix.rs @@ -330,7 +330,9 @@ const RECIPES: &[FixRecipe] = &[ needs_sudo: false, needs_reboot: true, needs_relogin: false, - verify: "lsmod | grep amdgpu && rocminfo | head -n 20", + verify: "# Run only the line matching the path you took above:\n\ + lsmod | grep amdgpu && rocminfo | head -n 20 # drive reinstall path\n\ + rocminfo | head -n 20 # `rocm install sdk` (userspace-only) path", notes: &[], doc_url: Some( "https://rocm.docs.amd.com/projects/install-on-linux/en/latest/reference/system-requirements.html", @@ -414,15 +416,15 @@ const RECIPES: &[FixRecipe] = &[ "sudo mv /etc/apt/sources.list.d/.list /etc/apt/sources.list.d/.list.bak # or the yum/zypp equivalent", "# Run only the line matching your package manager:", "sudo apt update # Debian/Ubuntu", - "sudo dnf clean all # RHEL/Fedora/Rocky/Alma/Oracle", + "sudo dnf makecache # RHEL/Fedora/Rocky/Alma/Oracle", "sudo zypper refresh # SLES/openSUSE", ], needs_sudo: true, needs_reboot: false, needs_relogin: false, - verify: "Run only the line matching your package manager:\n\ + verify: "# Run only the line matching your package manager:\n\ bash -c 'set -o pipefail; sudo apt update 2>&1 | tail -n 20' # Debian/Ubuntu\n\ - bash -c 'set -o pipefail; sudo dnf clean all 2>&1 | tail -n 20' # RHEL/Fedora/Rocky/Alma/Oracle\n\ + bash -c 'set -o pipefail; sudo dnf makecache 2>&1 | tail -n 20' # RHEL/Fedora/Rocky/Alma/Oracle\n\ bash -c 'set -o pipefail; sudo zypper refresh 2>&1 | tail -n 20' # SLES/openSUSE", notes: &[], doc_url: None, @@ -523,7 +525,7 @@ const RECIPES: &[FixRecipe] = &[ FixRecipe { fix_id: "fix-12-installer", title: "Reset repo-native install state and reinstall", - rationale: "The repo-native package-manager install left a half-configured DKMS / repo state. Clear the broken package state, quarantine the repo files rocm-cli's install wrote, let the package manager forget the broken state, then reinstall via rocm-cli's own repo-native flow.", + rationale: "The repo-native package-manager install left a half-configured DKMS / repo state. Clear the broken package state, quarantine the ROCm/AMDGPU repo files found on this host, let the package manager forget the broken state, then reinstall via rocm-cli's own repo-native flow.", commands: &[ "# Run only the block matching your package manager. On Debian/Ubuntu, run all", "# three lines even if an earlier one reports an error -- the purge must not", @@ -536,7 +538,7 @@ const RECIPES: &[FixRecipe] = &[ "# sudo mv /etc/apt/sources.list.d/amdgpu.list /etc/apt/sources.list.d/amdgpu.list.bak # or the yum/zypp equivalent; quarantine, do not delete yet", "# Run only the line matching your package manager:", "sudo apt update # Debian/Ubuntu", - "sudo dnf clean all # RHEL/Fedora/Rocky/Alma/Oracle", + "sudo dnf makecache # RHEL/Fedora/Rocky/Alma/Oracle", "sudo zypper refresh # SLES/openSUSE", "rocm install driver --dkms --yes", ], @@ -3715,6 +3717,9 @@ mod tests { // `verify` must also track diagnose.rs's per-family text, not just // `commands`: diagnose.rs varies `verify` by family too, so compare // each family's line against what diagnose() actually emits for it. + // The dnf/zypper `ls` lines get the same treatment as apt above -- + // only asserting the apt one left those two families' list commands + // able to drift from the recipe undetected. for (family_repo_dir, marker) in [ ("/etc/apt/sources.list.d/", "# Debian/Ubuntu"), ("/etc/yum.repos.d/", "# RHEL/Fedora/Rocky/Alma/Oracle"), @@ -3735,7 +3740,26 @@ mod tests { .iter() .find(|d| d.id == "fix-7-stale-repos") .expect("duplicate repo files should be diagnosed"); - let diagnose_verify = hit.fix.as_ref().unwrap().verify.as_str(); + let fix = hit.fix.as_ref().unwrap(); + let diagnose_list_cmd = fix + .commands + .first() + .expect("fix-7 always lists the repo dir first on a recognized family") + .as_str(); + let diagnose_verify = fix.verify.as_str(); + + let recipe_list_cmd = recipe + .commands + .iter() + .find(|c| c.trim_end().ends_with(marker) && c.contains("ls /")) + .map_or_else( + || panic!("recipe must have a commented list line for {marker}"), + |c| c.split('#').next().unwrap().trim_end(), + ); + assert_eq!( + recipe_list_cmd, diagnose_list_cmd, + "this recipe's {marker} list command must match what diagnose.rs emits for fix-7-stale-repos" + ); let recipe_verify_line = recipe .verify diff --git a/skills/rocm-doctor/SKILL.md b/skills/rocm-doctor/SKILL.md index f3575e5312..bc75da173f 100644 --- a/skills/rocm-doctor/SKILL.md +++ b/skills/rocm-doctor/SKILL.md @@ -11,7 +11,8 @@ description: >- permission denied on /dev/kfd, "ROCk module is NOT loaded", a missing libamdhip64.so / amdhip64_6.dll / hipblas.dll / vcruntime140_1.dll, an HSA_OVERRIDE_GFX_VERSION page fault, an iGPU+dGPU crash, a container that can't - see the GPU, or a repo-native package-manager install / DKMS failure. Backed by the `rocm` CLI + see the GPU, or a repo-native package-manager install (formerly `amdgpu-install`) / DKMS + failure. Backed by the `rocm` CLI (`rocm examine` / `rocm diagnose` / `rocm fix`); this skill is a thin driver over those commands, not a re-implementation. --- diff --git a/skills/rocm-doctor/reference.md b/skills/rocm-doctor/reference.md index 84a06220f6..5db0d22b80 100644 --- a/skills/rocm-doctor/reference.md +++ b/skills/rocm-doctor/reference.md @@ -121,7 +121,7 @@ reporting confident nonsense. | `fix-9-igpu-dgpu` | linux/windows | iGPU enumerated alongside dGPU, destabilising the runtime | APU + discrete AMD present, `HIP_VISIBLE_DEVICES` unset, crash/segfault | needs-arg | | `fix-10-container` | linux | Container can't see `/dev/kfd` or `/dev/dri/renderD*` | running in docker/podman, kfd/render devices missing | print-only | | `fix-11-iommu` | linux | Multi-GPU hang with IOMMU enabled | ≥2 AMD GPUs, `iommu=` not `pt`, hang/deadlock/timeout | print-only | -| `fix-12-installer` | linux | Repo-native package-manager install left a broken DKMS / repo state | dpkg half-configured, DKMS failed, `--accept-eula` | print-only | +| `fix-12-installer` | linux | Repo-native package-manager install left a broken DKMS / repo state | dpkg half-configured, DKMS build failure, dpkg/apt error | print-only | | `fix-13-hip-sdk-missing` | windows | HIP SDK not installed | **something on the host actually calls into HIP** — an ambient (non-managed-runtime) PyTorch HIP build, or a `GGML_HIP=ON` llama.cpp, either way with a detected AMD GPU — **and** no HIP SDK under Program Files, or `hipInfo.exe` missing from its `bin`. A paste naming any of `amdhip64` not found, "could not find HIP", `HIP_PATH` not set, or `hipInfo` not recognized counts as calling into HIP on its own, with no GPU required. A Vulkan-backed engine (the Lemonade default) or a managed-runtime wheel needs no system SDK, so its absence is not evidence there | print-only | | `fix-14-adrenalin-too-old` | windows | Adrenalin / kernel-mode driver too old for the HIP SDK | `hipInfo` can't enumerate, "driver too old", HSA "no agents found" | print-only | | `fix-15-msvc-redist` | windows | MSVC runtime missing (programs that link it, such as the HIP SDK DLLs and the llama.cpp server, can't load) | `vcruntime140.dll` / `vcruntime140_1.dll` missing | print-only | diff --git a/tests/e2e-cucumber/features/examine.feature b/tests/e2e-cucumber/features/examine.feature index f0dcbf9427..4744ee3537 100644 --- a/tests/e2e-cucumber/features/examine.feature +++ b/tests/e2e-cucumber/features/examine.feature @@ -120,7 +120,7 @@ Feature: GPU detection and system inspection And the inspection reports that the host is WSL # The dry-run plan used to print the raw `${ROCM_CLI_AMDGPU_VERSION:-7.2.4}` - # shell placeholder on its `repo_version_expr:` line instead of the effective version, + # shell placeholder on its `repo_version:` line instead of the effective version, # so the preview a user reviews before approving disagreed with what the install # would actually pull. The plan is rendered on every Linux host regardless of # GPU (the driver is not yet installed when you preview it), so the mock lane @@ -431,9 +431,11 @@ Feature: GPU detection and system inspection # `rocm_install_method` used to report "amdgpu-install"/"tarball-or-other"; # renamed to "repo-native"/"runfile-or-tarball" alongside the switch away - # from the amdgpu-install wrapper. It also drives fix-12's remediation - # choice, so a silent revert of the rename would misfire there without any - # test catching it -- this pins the JSON contract directly rather than only + # from the amdgpu-install wrapper. It also feeds fix-12's applicability + # score (not which remediation commands it renders -- that comes from the + # package family and distro, not this field), so a silent revert of the + # rename would misfire there without any test catching it -- this pins the + # JSON contract directly rather than only # asserting the human-readable form (examine-06), which never named it. A # whitelist rather than one pinned value keeps this hermetic: which method # actually fires depends on this host's real ROCm repo markers (some diff --git a/tests/e2e-cucumber/tests/e2e/driver_steps.rs b/tests/e2e-cucumber/tests/e2e/driver_steps.rs index cc8ade3ee0..1f9266c016 100644 --- a/tests/e2e-cucumber/tests/e2e/driver_steps.rs +++ b/tests/e2e-cucumber/tests/e2e/driver_steps.rs @@ -83,7 +83,7 @@ async fn assert_driver_plan_matches_host_release(world: &mut E2eWorld) { ); assert!( output.contains(&format!( - "curl -fsSL https://repo.radeon.com/rocm/rocm.gpg.key | {sudo}gpg --dearmor -o /etc/apt/keyrings/rocm.gpg" + "curl -fsSL https://repo.radeon.com/rocm/rocm.gpg.key | {sudo}gpg --batch --yes --dearmor -o /etc/apt/keyrings/rocm.gpg" )), "{output}" ); From 2f4a510e842064c039db39484fa67ad8f2101a84 Mon Sep 17 00:00:00 2001 From: Juho Vainio Date: Mon, 26 Oct 2026 17:16:01 +0200 Subject: [PATCH 5/7] fix: drive-fix advice, matrix drift guard and Windows path in repo-native driver PR - examine: build the already-seen repo path with join() so the test passes on Windows; pin REPO_SCAN_DIRS - diagnose: table test over every dkms_driver_plan_is_supported arm, plus a drift guard in driver_install against the real plan builder - fix-3: drop the 'rocm install sdk' alternative (cannot load a missing module); verify no longer masks a rocminfo failure via '| head' - fix-12: withhold the amdgpu-dkms purge where no reinstall is planned; static recipe carries per-distro caveats - driver_install: refuse a still-set ROCM_CLI_AMDGPU_VERSION / ROCM_CLI_AMDGPU_PACKAGE_RELEASE; add dnf override and '/' rejection tests - wording and function-name fixes in comments and printed advice Signed-off-by: Juho Vainio --- README.md | 3 +- apps/rocm/src/driver_install.rs | 110 +++++++++++++++- apps/rocm/src/main.rs | 2 + crates/rocm-core/src/diagnose.rs | 120 +++++++++++++++--- crates/rocm-core/src/examine.rs | 20 ++- crates/rocm-core/src/fix.rs | 11 +- docs/testing.md | 2 +- .../features/driver_install.feature | 4 +- tests/e2e-cucumber/tests/e2e/examine_steps.rs | 2 +- 9 files changed, 242 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index f5988c43cd..2c74005fb7 100644 --- a/README.md +++ b/README.md @@ -447,7 +447,8 @@ active default runtime, not about what a named prefix loses. package. On bare metal it defaults to the floating `latest` amdgpu release; set `ROCM_CLI_AMDGPU_DRIVER_VERSION` to pin a specific one. This replaces the older `ROCM_CLI_AMDGPU_VERSION`/`ROCM_CLI_AMDGPU_PACKAGE_RELEASE` pair, which -pinned a fixed default and are no longer read. +pinned a fixed default and are no longer read; the plan is refused while either is still set, +so an old pin is never silently turned into `latest`. On Ubuntu 26.04, the amdgpu driver ships in-tree and `repo.radeon.com` does not yet publish a matching DKMS repo, so `install driver` reports a non-mutating diff --git a/apps/rocm/src/driver_install.rs b/apps/rocm/src/driver_install.rs index aca25ea5c7..3e0b290e13 100644 --- a/apps/rocm/src/driver_install.rs +++ b/apps/rocm/src/driver_install.rs @@ -835,6 +835,9 @@ fn unreadable_os_release_plan(reason: String, repo_version_expr: String) -> Driv } } +const RETIRED_DRIVER_VERSION_VARS: [&str; 2] = + ["ROCM_CLI_AMDGPU_VERSION", "ROCM_CLI_AMDGPU_PACKAGE_RELEASE"]; + /// The refusal plan `resolve_repo_version_expr` returns for any /// `ROCM_CLI_AMDGPU_DRIVER_VERSION` value that cannot be safely interpolated /// into a shell command -- whether it failed [`is_safe_shell_token`] or could @@ -863,6 +866,18 @@ fn invalid_driver_version_override_plan(value_debug: String) -> DriverInstallPla /// `invalid_driver_version_override` plan on a malformed override rather than /// one of them silently falling back to `latest`. fn resolve_repo_version_expr() -> Result> { + // The pre-`latest` pin variables are no longer read; refuse rather than + // install a floating `latest` for a user who still exports one. + for retired in RETIRED_DRIVER_VERSION_VARS { + if std::env::var_os(retired).is_some_and(|v| !v.is_empty()) { + let mut plan = invalid_driver_version_override_plan(format!("{retired} is set")); + plan.policy = "retired_driver_version_override".to_owned(); + plan.reason = format!( + "{retired} is no longer read; unset it, and set ROCM_CLI_AMDGPU_DRIVER_VERSION to pin an amdgpu driver release." + ); + return Err(Box::new(plan)); + } + } // Resolved here rather than left as a shell `${VAR:-default}` expression: // these commands are built with `printf '%s\n' '...'` (single-quoted) so the // written repo file has a working baseurl regardless of shell. The value is @@ -3134,6 +3149,9 @@ VERSION_CODENAME=noble assert!(!is_safe_shell_token("6.2.1'")); assert!(!is_safe_shell_token("6.2.1;rm")); assert!(!is_safe_shell_token("';rm -rf /;'")); + // `/` cannot break out of the quotes, but it would let the override + // rewrite the repo URL path. + assert!(!is_safe_shell_token("6.2.1/../x")); assert!(is_safe_shell_token("6.2.1")); } @@ -3555,6 +3573,96 @@ VERSION_ID="15.7" ); } + #[test] + fn driver_plan_dnf_overrides_the_repo_version_via_the_driver_version_env() { + let mut env = ScopedTestEnv::with_amd_overrides_cleared(); + env.set("ROCM_CLI_AMDGPU_DRIVER_VERSION", "30.10"); + let os_release = "ID=rhel\nVERSION_ID=\"9.7\"\n"; + let plan = build_driver_install_plan_read( + &test_examine("linux", false), + &os_release_found(os_release), + true, + PrivilegeEscalation::Sudo, + ); + let rendered = render_driver_install_plan(&plan, false, false); + + assert!(plan.supported); + assert!( + rendered.contains("amdgpu/30.10/rhel/9.7/"), + "an overridden ROCM_CLI_AMDGPU_DRIVER_VERSION must reach the dnf repo baseurl, \ + not a hardcoded `latest`: {rendered}" + ); + } + + #[test] + fn driver_plan_refuses_a_retired_version_pin_variable() { + for retired in RETIRED_DRIVER_VERSION_VARS { + let mut env = ScopedTestEnv::with_amd_overrides_cleared(); + env.set(retired, "7.2.4"); + let plan = build_driver_install_plan_read( + &test_examine("linux", false), + &os_release_found("ID=ubuntu\nVERSION_ID=\"24.04\"\nVERSION_CODENAME=noble\n"), + true, + PrivilegeEscalation::Sudo, + ); + + assert!(!plan.supported && !plan.mutating, "{retired}"); + assert_eq!(plan.policy, "retired_driver_version_override"); + assert!(plan.reason.contains("ROCM_CLI_AMDGPU_DRIVER_VERSION")); + } + } + + #[test] + fn driver_plan_support_matches_rocm_core_diagnose() { + // `rocm-core` cannot call the plan builder, so diagnose keeps its own + // copy of the support matrix (`dkms_driver_plan_is_supported`); this + // fails if the two disagree on any host. + let _env = ScopedTestEnv::with_amd_overrides_cleared(); + let hosts = [ + ("ubuntu", "22.04", "debian"), + ("ubuntu", "24.04", "debian"), + ("ubuntu", "26.04", "debian"), + ("debian", "12", ""), + ("debian", "13", ""), + ("rhel", "9.7", "fedora"), + ("rhel", "10.0", "fedora"), + ("ol", "9.7", "fedora"), + ("ol", "9.7", "rhel fedora"), + ("ol", "9.5", "rhel fedora"), + ("rocky", "9.6", "rhel centos fedora"), + ("almalinux", "9.6", "rhel centos fedora"), + ("sles", "15.7", "suse"), + ("sle", "15.7", "suse"), + ("pop", "24.04", "ubuntu debian"), + ("linuxmint", "22", "ubuntu debian"), + ("fedora", "41", ""), + ("opensuse-leap", "15.7", "suse opensuse"), + ]; + for (id, version, like) in hosts { + let os_release = format!( + "ID={id}\nVERSION_ID=\"{version}\"\nID_LIKE=\"{like}\"\nVERSION_CODENAME=noble\n" + ); + let plan = build_driver_install_plan_read( + &test_examine("linux", false), + &os_release_found(&os_release), + true, + PrivilegeEscalation::Sudo, + ); + let host = rocm_core::examine::Examination { + distro_id: id.to_owned(), + distro_version: version.to_owned(), + distro_id_like: like.to_owned(), + ..rocm_core::examine::Examination::default() + }; + assert_eq!( + plan.supported, + rocm_core::diagnose::dkms_driver_plan_is_supported(&host), + "{id} {version} (ID_LIKE={like}): plan policy {}", + plan.policy + ); + } + } + #[test] fn driver_plan_sles_overrides_the_repo_version_via_the_driver_version_env() { let mut env = ScopedTestEnv::with_amd_overrides_cleared(); @@ -3749,7 +3857,7 @@ VERSION_ID="41" /// /// Builds on [`ScopedTestEnv::with_amd_overrides_cleared`] rather than /// `new` so a caller that also exercises the bare-metal AMDGPU override - /// through the same `build_driver_install_plan` call doesn't need a + /// through the same `build_driver_install_plan_at` call doesn't need a /// second guard: one helper covers both input sets regardless of which /// branch actually reads them. fn scoped_rocdxg_env() -> ScopedTestEnv { diff --git a/apps/rocm/src/main.rs b/apps/rocm/src/main.rs index e39e7c1d36..5c4420033a 100644 --- a/apps/rocm/src/main.rs +++ b/apps/rocm/src/main.rs @@ -12019,6 +12019,8 @@ pub(crate) mod tests { pub(crate) fn with_amd_overrides_cleared() -> Self { let mut env = Self::new(); env.clear("ROCM_CLI_AMDGPU_DRIVER_VERSION"); + env.clear("ROCM_CLI_AMDGPU_VERSION"); + env.clear("ROCM_CLI_AMDGPU_PACKAGE_RELEASE"); env } diff --git a/crates/rocm-core/src/diagnose.rs b/crates/rocm-core/src/diagnose.rs index d9f4c34cbe..d1bf594feb 100644 --- a/crates/rocm-core/src/diagnose.rs +++ b/crates/rocm-core/src/diagnose.rs @@ -844,7 +844,7 @@ fn check_3_rocm_kernel_unsupported(e: &Examination, symptom: &str) -> Diagnosis "# https://rocm.docs.amd.com/projects/install-on-linux/en/latest/reference/system-requirements.html".to_owned(), ]; if ubuntu_driver_is_native_archive(e) { - commands.push("# Not on Ubuntu 26.04: the amdgpu driver ships in-tree there, so `rocm install driver --dkms` plans nothing; run `sudo apt install rocm` instead.".to_owned()); + commands.push("# Note on Ubuntu 26.04: the amdgpu driver ships in-tree there, so `rocm install driver --dkms` plans nothing; run `apt install rocm` (with sudo if not root) instead.".to_owned()); } else if dkms_driver_plan_is_supported(e) { commands.push("# If your kernel is above the supported range, install the HWE".to_owned()); commands.push( @@ -855,23 +855,14 @@ fn check_3_rocm_kernel_unsupported(e: &Examination, symptom: &str) -> Diagnosis "# `rocm install driver --dkms` plans nothing on {distro} {distro_v}: it isn't one of the AMD-documented distros/versions above, so rerunning it won't fix this." )); } - commands.push("# To avoid the DKMS build entirely, use `rocm install sdk` instead:".to_owned()); - commands.push( - "# it installs the userspace ROCm stack without touching the kernel module.".to_owned(), - ); let fix = Fix { summary: "Cross-check your kernel/distro against the live AMD compatibility matrix before reinstalling.".to_owned(), commands, fix_id: "fix-3-rocm-kernel".to_owned(), needs_reboot: true, - // `rocm install sdk` deliberately never loads the amdgpu kernel - // module (that's the point of avoiding the DKMS build), so a - // `lsmod | grep amdgpu` requirement would fail that path even when it - // worked; only require it if you took the driver-reinstall path above. - verify: "# Run only the line matching the path you took above:\n\ - lsmod | grep amdgpu && rocminfo | head -n 20 # drive reinstall path\n\ - rocminfo | head -n 20 # `rocm install sdk` (userspace-only) path" - .to_owned(), + // Check rocminfo's own exit code: piping through `head` would report + // the pipeline's last stage and mask a missing/failing `rocminfo`. + verify: "lsmod | grep amdgpu && rocminfo >/dev/null 2>&1".to_owned(), ..Fix::default() }; finalize( @@ -1573,7 +1564,7 @@ fn is_repo_native_installed(method: &str) -> bool { /// Whether `rocm install driver --dkms` has nothing to reinstall on this /// host. Ubuntu 26.04 ships the amdgpu kernel driver in-tree and -/// `build_driver_install_plan` in `apps/rocm/src/driver_install.rs` plans no +/// `build_driver_install_plan_at` in `apps/rocm/src/driver_install.rs` plans no /// DKMS repo install there (see the `("ubuntu", "26.04")` arm); `rocm-core` /// can't call that plan builder directly (`apps/rocm` depends on /// `rocm-core`, not the reverse), so this mirrors just that one condition. @@ -1583,8 +1574,9 @@ fn ubuntu_driver_is_native_archive(e: &Examination) -> bool { e.distro_id.eq_ignore_ascii_case("ubuntu") && e.distro_version == "26.04" } -/// Whether `rocm install driver --dkms` plans any commands at all for this -/// host, mirroring the full `(os_id, version_id)` / `ID_LIKE`-derivative +/// Whether `rocm install driver --dkms` plans any commands for this host. +/// +/// Mirrors the full `(os_id, version_id)` / `ID_LIKE`-derivative /// matrix in `apps/rocm/src/driver_install.rs::build_driver_install_plan_at` /// (`rocm-core` can't call that plan builder directly -- see /// `ubuntu_driver_is_native_archive` above for why). Ubuntu 26.04 is @@ -1592,7 +1584,7 @@ fn ubuntu_driver_is_native_archive(e: &Examination) -> bool { /// commands": that host has its own guidance (native archive, `apt install /// rocm`), handled separately via `ubuntu_driver_is_native_archive`, not the /// "no plan was guessed for this distro at all" case this function reports. -fn dkms_driver_plan_is_supported(e: &Examination) -> bool { +pub fn dkms_driver_plan_is_supported(e: &Examination) -> bool { let os_id = e.distro_id.to_ascii_lowercase(); let version_id = e.distro_version.as_str(); match (os_id.as_str(), version_id) { @@ -1636,15 +1628,23 @@ fn check_12_repo_native_broken(e: &Examination, symptom: &str) -> Diagnosis { return zero("fix-12-installer", "repo-native install broken state"); } let family = repo_pkg_family(e); + // Purging `amdgpu-dkms` is only the first half of purge-then-reinstall: + // where rocm-cli plans no reinstall (undocumented distro) it would strip + // the driver with nothing to put back, so that step is withheld there. + let reinstall_planned = ubuntu_driver_is_native_archive(e) || dkms_driver_plan_is_supported(e); let mut commands = vec!["# Clear the half-configured package/DKMS state first.".to_owned()]; match family { "apt" => { commands.push("sudo dpkg --configure -a".to_owned()); commands.push("sudo apt-get install -f".to_owned()); - commands.push("sudo apt-get purge -y amdgpu-dkms".to_owned()); + if reinstall_planned { + commands.push("sudo apt-get purge -y amdgpu-dkms".to_owned()); + } + } + "dnf" if reinstall_planned => commands.push("sudo dnf remove -y amdgpu-dkms".to_owned()), + "zypper" if reinstall_planned => { + commands.push("sudo zypper remove -y amdgpu-dkms".to_owned()); } - "dnf" => commands.push("sudo dnf remove -y amdgpu-dkms".to_owned()), - "zypper" => commands.push("sudo zypper remove -y amdgpu-dkms".to_owned()), _ => {} } commands.push( @@ -7215,7 +7215,7 @@ mod tests { .expect("unsupported kernel triple should be diagnosed"); let commands = hit.fix.as_ref().unwrap().commands.join("\n"); assert!( - commands.contains("Not on Ubuntu 26.04") && commands.contains("sudo apt install rocm"), + commands.contains("Note on Ubuntu 26.04") && commands.contains("apt install rocm"), "Ubuntu 26.04 must be told to use the native archive path, not a DKMS rerun: {commands}" ); assert!( @@ -7662,6 +7662,7 @@ mod tests { fn repo_native_broken_on_a_dnf_host_gets_dnf_commands_not_apt() { let mut e = linux_base(); e.distro_id = "rocky".to_owned(); + e.distro_version = "9.6".to_owned(); e.rocm_install_method = "repo-native".to_owned(); e.rocm_repos_seen = vec!["/etc/yum.repos.d/amdgpu.repo".to_owned()]; let report = diagnose( @@ -7689,6 +7690,7 @@ mod tests { fn repo_native_broken_on_a_zypper_host_gets_zypper_commands_not_apt() { let mut e = linux_base(); e.distro_id = "sles".to_owned(); + e.distro_version = "15.7".to_owned(); e.rocm_install_method = "repo-native".to_owned(); e.rocm_repos_seen = vec!["/etc/zypp/repos.d/amdgpu.repo".to_owned()]; let report = diagnose( @@ -7847,4 +7849,80 @@ mod tests { "dpkg keyword evidence alone should still surface fix-12" ); } + + #[test] + fn dkms_driver_plan_support_matrix_covers_every_arm() { + // (distro_id, distro_version, distro_id_like, supported). Kept in step + // with `build_driver_install_plan_at` by + // `driver_plan_support_matches_rocm_core_diagnose` in + // `apps/rocm/src/driver_install.rs`. + let table = [ + ("ubuntu", "22.04", "debian", true), + ("ubuntu", "24.04", "debian", true), + ("ubuntu", "26.04", "debian", false), + ("debian", "12", "", true), + ("debian", "13", "", true), + ("rhel", "9.7", "fedora", true), + ("rhel", "10.0", "fedora", true), + ("ol", "9.7", "fedora", true), + ("rocky", "9.6", "rhel centos fedora", true), + ("sles", "15.7", "suse", true), + ("sle", "15.7", "suse", true), + ("almalinux", "9.6", "rhel centos fedora", true), + ("pop", "24.04", "ubuntu debian", true), + ("ol", "9.7", "rhel fedora", true), + ("ol", "9.5", "rhel fedora", false), + ("fedora", "41", "", false), + ("opensuse-leap", "15.7", "suse opensuse", false), + ("linuxmint", "22", "ubuntu debian", false), + ]; + for (id, version, like, expected) in table { + let mut e = linux_base(); + e.distro_id = id.to_owned(); + e.distro_version = version.to_owned(); + e.distro_id_like = like.to_owned(); + assert_eq!( + dkms_driver_plan_is_supported(&e), + expected, + "{id} {version} (ID_LIKE={like})" + ); + } + } + + #[test] + fn repo_native_broken_on_an_undocumented_distro_does_not_purge_the_driver() { + let mut e = linux_base(); + e.distro_id = "fedora".to_owned(); + e.distro_version = "41".to_owned(); + e.rocm_install_method = "repo-native".to_owned(); + let report = diagnose(&e, "dpkg: error processing package amdgpu-dkms"); + let hit = report + .matched + .iter() + .find(|d| d.id == "fix-12-installer") + .expect("repo-native broken state should be diagnosed"); + let commands = hit.fix.as_ref().unwrap().commands.join("\n"); + assert!( + !commands.contains("amdgpu-dkms") && !commands.contains("rocm install driver"), + "no purge without a planned reinstall: {commands}" + ); + } + + #[test] + fn kernel_unsupported_does_not_offer_the_sdk_install_or_a_maskable_verify() { + let mut e = linux_base(); + e.distro_id = "ubuntu".to_owned(); + e.distro_version = "24.04".to_owned(); + e.rocm_version = "7.0.0".to_owned(); + e.amdgpu_loaded = Some(false); + let report = diagnose(&e, "kernel/rocm mismatch"); + let fix = report + .matched + .iter() + .find(|d| d.id == "fix-3-rocm-kernel") + .and_then(|d| d.fix.as_ref()) + .expect("unsupported kernel triple should be diagnosed"); + assert!(!fix.commands.join("\n").contains("rocm install sdk")); + assert!(!fix.verify.contains("| head"), "{}", fix.verify); + } } diff --git a/crates/rocm-core/src/examine.rs b/crates/rocm-core/src/examine.rs index 12fe77df08..555a42aeb8 100644 --- a/crates/rocm-core/src/examine.rs +++ b/crates/rocm-core/src/examine.rs @@ -3444,6 +3444,17 @@ mod tests { ); } + #[test] + fn repo_scan_dirs_cover_every_package_family() { + for dir in [ + "/etc/apt/sources.list.d", + "/etc/yum.repos.d", + "/etc/zypp/repos.d", + ] { + assert!(REPO_SCAN_DIRS.contains(&dir), "missing {dir}"); + } + } + #[test] fn merge_live_repo_paths_does_not_duplicate_an_already_seen_path() { let dir = tempfile::tempdir().expect("create temp dir"); @@ -3451,7 +3462,14 @@ mod tests { let dir_str = dir.path().to_string_lossy().into_owned(); let mut e = Examination::default(); - e.rocm_repos_seen.push(format!("{dir_str}/amdgpu.repo")); + // `join`, not a hardcoded `/`: the scan records `entry.path()`, which + // uses the platform separator. + e.rocm_repos_seen.push( + dir.path() + .join("amdgpu.repo") + .to_string_lossy() + .into_owned(), + ); merge_live_repo_paths(&mut e, &[dir_str.as_str()]); assert_eq!( diff --git a/crates/rocm-core/src/fix.rs b/crates/rocm-core/src/fix.rs index 84b3953fc3..2100719efd 100644 --- a/crates/rocm-core/src/fix.rs +++ b/crates/rocm-core/src/fix.rs @@ -321,7 +321,7 @@ const RECIPES: &[FixRecipe] = &[ FixRecipe { fix_id: "fix-3-rocm-kernel", title: "ROCm/distro/kernel triple unsupported", - rationale: "ROCm is installed but your kernel/distro combination is outside the supported matrix. Match the kernel to the matrix first, then rerun `rocm install driver --dkms`. To avoid the DKMS build entirely, use `rocm install sdk` instead: it installs the userspace ROCm stack without touching the kernel module.", + rationale: "ROCm is installed but your kernel/distro combination is outside the supported matrix. Match the kernel to the matrix first, then rerun `rocm install driver --dkms`.", commands: &[ "# Cross-check the live AMD matrix before changing anything:", "# https://rocm.docs.amd.com/projects/install-on-linux/en/latest/reference/system-requirements.html", @@ -330,9 +330,7 @@ const RECIPES: &[FixRecipe] = &[ needs_sudo: false, needs_reboot: true, needs_relogin: false, - verify: "# Run only the line matching the path you took above:\n\ - lsmod | grep amdgpu && rocminfo | head -n 20 # drive reinstall path\n\ - rocminfo | head -n 20 # `rocm install sdk` (userspace-only) path", + verify: "lsmod | grep amdgpu && rocminfo >/dev/null 2>&1", notes: &[], doc_url: Some( "https://rocm.docs.amd.com/projects/install-on-linux/en/latest/reference/system-requirements.html", @@ -527,6 +525,10 @@ const RECIPES: &[FixRecipe] = &[ title: "Reset repo-native install state and reinstall", rationale: "The repo-native package-manager install left a half-configured DKMS / repo state. Clear the broken package state, quarantine the ROCm/AMDGPU repo files found on this host, let the package manager forget the broken state, then reinstall via rocm-cli's own repo-native flow.", commands: &[ + "# Applies only where `rocm install driver --dkms` plans a reinstall (AMD-documented", + "# distros). On Ubuntu 26.04 the driver is in-tree: skip the purge/remove, the DKMS", + "# reinstall and the DKMS verify, and run `sudo apt install rocm` instead. On any other", + "# distro it plans nothing: skip the purge/remove and reinstall per AMD's install docs.", "# Run only the block matching your package manager. On Debian/Ubuntu, run all", "# three lines even if an earlier one reports an error -- the purge must not", "# be skipped just because the half-configured state made `install -f` fail:", @@ -3860,6 +3862,7 @@ mod tests { let e = crate::examine::Examination { os_family: "linux".to_owned(), distro_id: "ubuntu".to_owned(), + distro_version: "24.04".to_owned(), rocm_install_method: "repo-native".to_owned(), ..crate::examine::Examination::default() }; diff --git a/docs/testing.md b/docs/testing.md index 156b0c8bc9..78cce44384 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -1600,7 +1600,7 @@ otherwise. On Linux bare metal, `rocm install driver` defaults to the floating `latest` amdgpu release; `ROCM_CLI_AMDGPU_DRIVER_VERSION` overrides it (replacing the -retired `ROCM_CLI_AMDGPU_VERSION`/`ROCM_CLI_AMDGPU_PACKAGE_RELEASE` pair). An +retired `ROCM_CLI_AMDGPU_VERSION`/`ROCM_CLI_AMDGPU_PACKAGE_RELEASE` pair, which the plan refuses while either is still set). An override that isn't a plain version token is refused rather than silently falling back, since it is interpolated into privileged shell commands: diff --git a/tests/e2e-cucumber/features/driver_install.feature b/tests/e2e-cucumber/features/driver_install.feature index caa0d7a804..ec35aaa282 100644 --- a/tests/e2e-cucumber/features/driver_install.feature +++ b/tests/e2e-cucumber/features/driver_install.feature @@ -32,7 +32,7 @@ Feature: Driver installation planning # Every bare-metal Linux lane in this repo runs Ubuntu, but not always the # same release -- the hosted `E2E tests` job's `ubuntu-26.04` image reports - # 26.04 ("resolute"), which `build_driver_install_plan` routes to the + # 26.04 ("resolute"), which `build_driver_install_plan_at` routes to the # `ubuntu_native_archive` arm instead of the apt one (no repo.radeon.com/ # amdgpu suite published for "resolute" yet; see the `("ubuntu", "26.04")` # arm in `driver_install.rs`), while the self-hosted GPU lane's real @@ -56,7 +56,7 @@ Feature: Driver installation planning # silently falling back to "latest" -- user-observable as a # `supported: false` plan naming the variable. `ROCM_CLI_AMDGPU_DRIVER_VERSION` # is only consulted by the Linux DKMS arm, though: `build_driver_install_plan_at` - # checks `is_wsl_host()` and returns the WSL/ROCDXG plan before this override is + # checks `examine.wsl.is_wsl` and returns the WSL/ROCDXG plan before this override is # ever resolved, so a WSL host has no premise here (it would hit # `wsl_rocdxg_driver_plan` regardless of the override and the scenario would # fail by construction) -- same WSL-vs-bare-metal split as driver-install-04. diff --git a/tests/e2e-cucumber/tests/e2e/examine_steps.rs b/tests/e2e-cucumber/tests/e2e/examine_steps.rs index e524d71e8c..3d2a6b82dc 100644 --- a/tests/e2e-cucumber/tests/e2e/examine_steps.rs +++ b/tests/e2e-cucumber/tests/e2e/examine_steps.rs @@ -204,7 +204,7 @@ async fn assert_driver_plan_repo_version_resolved(world: &mut E2eWorld) { // The default, unoverridden value is the literal "latest" (ROCM_CLI_AMDGPU_DRIVER_VERSION // is unset on a normal test host) -- not a numeric ROCm version -- so only // non-empty and metacharacter-safe are asserted here, matching the same - // filter build_driver_install_plan applies before this value ever reaches + // filter build_driver_install_plan_at applies before this value ever reaches // a single-quoted shell command. assert!(!repo_version.is_empty(), "repo_version is empty:\n{output}"); assert!( From 5f1ad7375766d8ea041883dcbdf54a0b86a654ef Mon Sep 17 00:00:00 2001 From: Juho Vainio Date: Tue, 27 Oct 2026 14:54:58 +0200 Subject: [PATCH 6/7] test(driver): close mutation gaps and add scenarios for PR 181 review Route the repo-file scan through the host root and test probe_rocm_install over all three package-family directories; cover the fix-12 purge guards, fix-3/fix-7 supported-distro text, ID_LIKE override paths and the missing distro_id_like key. Lowercase ID in the plan builder to match diagnose. Indent multi-line fix verify output. Add diagnose-42, driver-install-08 and a distro_id_like check in examine-20. Correct CI image wording. Signed-off-by: Juho Vainio --- apps/rocm/src/driver_install.rs | 61 +++++++++- apps/rocm/src/remote/doctor.rs | 15 ++- crates/rocm-core/src/diagnose.rs | 106 ++++++++++++++++++ crates/rocm-core/src/examine.rs | 52 +++++++-- crates/rocm-core/src/fix.rs | 21 +++- docs/testing.md | 15 ++- tests/e2e-cucumber/features/diagnose.feature | 13 +++ .../features/driver_install.feature | 13 ++- tests/e2e-cucumber/features/examine.feature | 1 + .../e2e-cucumber/tests/e2e/diagnose_steps.rs | 84 ++++++++++++++ tests/e2e-cucumber/tests/e2e/driver_steps.rs | 48 +++++++- tests/e2e-cucumber/tests/e2e/examine_steps.rs | 6 + 12 files changed, 414 insertions(+), 21 deletions(-) diff --git a/apps/rocm/src/driver_install.rs b/apps/rocm/src/driver_install.rs index 6b26a35a89..a9d5b8a0a0 100644 --- a/apps/rocm/src/driver_install.rs +++ b/apps/rocm/src/driver_install.rs @@ -1007,9 +1007,12 @@ fn build_driver_install_plan_at( // reintroduce the shell-injection class those fields close. An invalid // value is treated as absent, falling through to the "unsupported" plan // the same way the other fields do. + // Lowercased, as `rocm-core`'s `dkms_driver_plan_is_supported` does, so the + // two copies of the support matrix agree on `ID=Ubuntu`. let os_id = field("ID") .filter(|v| is_safe_shell_token(v)) - .unwrap_or_default(); + .unwrap_or_default() + .to_ascii_lowercase(); // `version_id` is interpolated unsanitized both into the same // single-quoted `printf '...' | tee` commands as `repo_version_expr` // above and, on SLES, directly unquoted on the SUSEConnect command line -- @@ -1052,7 +1055,7 @@ fn build_driver_install_plan_at( // 22.04/24.04 are handled. // // This arm IS reachable through the CLI on a real host: the hosted - // `E2E tests` job's `ubuntu-26.04` image runs `driver-install-06` in + // `E2E tests` job's `ubuntu-latest` image (26.04 once GitHub's migration completes) runs `driver-install-06` in // `driver_install.feature`, which asserts whichever arm the real host // actually falls into, so this one has e2e coverage too, alongside // the unit fixture in `driver_plan_ubuntu_2604_uses_native_archive_guidance` @@ -2224,6 +2227,10 @@ mod tests { ); assert!(!plan.supported); assert_eq!(plan.policy, "invalid_driver_version_override"); + assert!( + !plan.mutating, + "a refused override must not claim to mutate" + ); assert!(plan.reason.contains("ROCM_CLI_AMDGPU_DRIVER_VERSION")); assert!(plan.commands.is_empty()); } @@ -2928,6 +2935,10 @@ VERSION_CODENAME=noble assert!(!plan.supported); assert_eq!(plan.policy, "invalid_driver_version_override"); + assert!( + !plan.mutating, + "a refused override must not claim to mutate" + ); assert!(plan.reason.contains("ROCM_CLI_AMDGPU_DRIVER_VERSION")); assert!(plan.commands.is_empty()); } @@ -2953,6 +2964,10 @@ VERSION_CODENAME=noble assert!(!plan.supported); assert_eq!(plan.policy, "invalid_driver_version_override"); + assert!( + !plan.mutating, + "a refused override must not claim to mutate" + ); assert!(plan.reason.contains("ROCM_CLI_AMDGPU_DRIVER_VERSION")); // Already proves no command can contain "pwned": a vacuous check over // commands would be redundant with this. @@ -2982,6 +2997,10 @@ VERSION_CODENAME=noble assert!(!plan.supported); assert_eq!(plan.policy, "invalid_driver_version_override"); + assert!( + !plan.mutating, + "a refused override must not claim to mutate" + ); assert!(plan.commands.is_empty()); } @@ -3622,6 +3641,43 @@ VERSION_ID="15.7" ); } + #[test] + fn driver_plan_id_like_derivatives_honour_the_driver_version_env() { + // (os-release, expected repo path). Each derivative arm of + // `driver_plan_via_id_like` must thread the override, not `latest`. + let cases = [ + ( + "ID=almalinux\nID_LIKE=\"rhel centos fedora\"\nVERSION_ID=\"9.6\"\n", + "amdgpu/30.10/el/9.6", + ), + ( + "ID=pop\nID_LIKE=\"ubuntu debian\"\nVERSION_ID=\"24.04\"\nVERSION_CODENAME=noble\n", + "amdgpu/30.10/ubuntu", + ), + ( + "ID=devuan\nID_LIKE=debian\nVERSION_ID=\"12\"\n", + "amdgpu/30.10/ubuntu", + ), + ]; + for (os_release, want) in cases { + let mut env = ScopedTestEnv::with_amd_overrides_cleared(); + env.set("ROCM_CLI_AMDGPU_DRIVER_VERSION", "30.10"); + let plan = build_driver_install_plan_read( + &test_examine("linux", false), + &os_release_found(os_release), + true, + PrivilegeEscalation::Sudo, + ); + let rendered = render_driver_install_plan(&plan, false, false); + assert!(plan.supported, "{os_release}"); + assert!(rendered.contains(want), "{os_release}: {rendered}"); + assert!( + !rendered.contains("amdgpu/latest"), + "{os_release}: {rendered}" + ); + } + } + #[test] fn driver_plan_refuses_a_retired_version_pin_variable() { for retired in RETIRED_DRIVER_VERSION_VARS { @@ -3649,6 +3705,7 @@ VERSION_ID="15.7" let hosts = [ ("ubuntu", "22.04", "debian"), ("ubuntu", "24.04", "debian"), + ("Ubuntu", "24.04", "debian"), ("ubuntu", "26.04", "debian"), ("debian", "12", ""), ("debian", "13", ""), diff --git a/apps/rocm/src/remote/doctor.rs b/apps/rocm/src/remote/doctor.rs index 8414fcf700..891db07a21 100644 --- a/apps/rocm/src/remote/doctor.rs +++ b/apps/rocm/src/remote/doctor.rs @@ -288,10 +288,9 @@ mod tests { #[test] fn distro_id_like_survives_the_remote_round_trip() { - // `repo_pkg_family`'s ID_LIKE fallback only ever runs against a - // deserialized remote examination, never a freshly probed local one -- - // so if this field didn't round-trip through JSON, the fallback would - // silently and permanently never fire for `rocm remote doctor`. + // A remote examination is only ever seen through JSON, so if this + // field didn't round-trip, the ID_LIKE fallback would silently never + // fire for `rocm remote doctor`. let mut value: serde_json::Value = serde_json::from_str(&examine_json()).unwrap(); value.as_object_mut().unwrap().insert( "distro_id_like".to_owned(), @@ -301,6 +300,14 @@ mod tests { assert_eq!(parsed.distro_id_like, "rhel fedora"); } + #[test] + fn a_remote_on_an_older_cli_without_distro_id_like_still_parses() { + let mut value: serde_json::Value = serde_json::from_str(&examine_json()).unwrap(); + value.as_object_mut().unwrap().remove("distro_id_like"); + let parsed = parse_examination(&value.to_string()).expect("older remote must parse"); + assert_eq!(parsed.distro_id_like, ""); + } + #[test] fn a_remote_on_another_version_says_so_instead_of_failing_obscurely() { let error = parse_examination(r#"{"unexpected": true}"#) diff --git a/crates/rocm-core/src/diagnose.rs b/crates/rocm-core/src/diagnose.rs index b09b36ed32..327fb73e07 100644 --- a/crates/rocm-core/src/diagnose.rs +++ b/crates/rocm-core/src/diagnose.rs @@ -8095,6 +8095,9 @@ mod tests { ("pop", "24.04", "ubuntu debian", true), ("ol", "9.7", "rhel fedora", true), ("ol", "9.5", "rhel fedora", false), + // OL's own ID_LIKE row must not inherit the `rhel` family's + // versions: OL 9.6 is not in the documented OL list. + ("ol", "9.6", "rhel fedora", false), ("fedora", "41", "", false), ("opensuse-leap", "15.7", "suse opensuse", false), ("linuxmint", "22", "ubuntu debian", false), @@ -8131,6 +8134,109 @@ mod tests { ); } + fn fix_commands(e: &Examination, symptom: &str, id: &str) -> String { + diagnose(e, symptom) + .matched + .iter() + .find(|d| d.id == id) + .unwrap_or_else(|| panic!("{id} should be diagnosed")) + .fix + .as_ref() + .unwrap() + .commands + .join("\n") + } + + #[test] + fn fix_12_purges_the_driver_only_where_a_reinstall_is_planned() { + // (id, version, id_like, repo seen, purge command, expect purge) + let cases = [ + ( + "ubuntu", + "24.04", + "debian", + "/etc/apt/sources.list.d/amdgpu.list", + "sudo apt-get purge -y amdgpu-dkms", + true, + ), + ( + "linuxmint", + "22", + "ubuntu debian", + "/etc/apt/sources.list.d/amdgpu.list", + "sudo apt-get purge -y amdgpu-dkms", + false, + ), + ( + "rhel", + "9.7", + "fedora", + "/etc/yum.repos.d/amdgpu.repo", + "sudo dnf remove -y amdgpu-dkms", + true, + ), + ( + "fedora", + "41", + "", + "/etc/yum.repos.d/amdgpu.repo", + "sudo dnf remove -y amdgpu-dkms", + false, + ), + ( + "sles", + "15.7", + "suse", + "/etc/zypp/repos.d/amdgpu.repo", + "sudo zypper remove -y amdgpu-dkms", + true, + ), + ( + "opensuse-leap", + "15.7", + "suse opensuse", + "/etc/zypp/repos.d/amdgpu.repo", + "sudo zypper remove -y amdgpu-dkms", + false, + ), + ]; + for (id, version, like, repo, purge, expect) in cases { + let mut e = linux_base(); + e.distro_id = id.to_owned(); + e.distro_version = version.to_owned(); + e.distro_id_like = like.to_owned(); + e.rocm_install_method = "repo-native".to_owned(); + e.rocm_repos_seen = vec![repo.to_owned()]; + let commands = fix_commands( + &e, + "dpkg: error processing package amdgpu-dkms", + "fix-12-installer", + ); + assert_eq!( + commands.contains(purge), + expect, + "{id} {version}: {commands}" + ); + } + } + + #[test] + fn supported_distro_fix_3_and_fix_7_name_the_dkms_reinstall() { + let mut e = linux_base(); + e.distro_id = "ubuntu".to_owned(); + e.distro_version = "24.04".to_owned(); + e.rocm_version = "7.0.0".to_owned(); + e.amdgpu_loaded = Some(false); + e.rocm_repos_seen = vec![ + "/etc/apt/sources.list.d/amdgpu.list".to_owned(), + "/etc/apt/sources.list.d/rocm.list".to_owned(), + ]; + let fix3 = fix_commands(&e, "kernel/rocm mismatch", "fix-3-rocm-kernel"); + assert!(fix3.contains("rocm install driver --dkms --yes"), "{fix3}"); + let fix7 = fix_commands(&e, "stale repo conflict", "fix-7-stale-repos"); + assert!(fix7.contains("rocm install driver --dkms --yes"), "{fix7}"); + } + #[test] fn kernel_unsupported_does_not_offer_the_sdk_install_or_a_maskable_verify() { let mut e = linux_base(); diff --git a/crates/rocm-core/src/examine.rs b/crates/rocm-core/src/examine.rs index 3fa53b83a6..d5174f9759 100644 --- a/crates/rocm-core/src/examine.rs +++ b/crates/rocm-core/src/examine.rs @@ -2023,7 +2023,9 @@ fn is_live_rocm_repo_file_name(name: &str) -> bool { /// pure `is_live_rocm_repo_file_name` name check in isolation. Silently empty /// when `dir` does not exist or is not a directory. fn live_rocm_repo_paths_in_dir(dir: &str) -> Vec { - let Ok(entries) = std::fs::read_dir(dir) else { + // Read through `host_path` so a simulated host root re-roots the scan, but + // report the logical `dir/name`, which is what a user would `mv`. + let Ok(entries) = std::fs::read_dir(crate::host_path(dir)) else { return Vec::new(); }; entries @@ -2031,7 +2033,12 @@ fn live_rocm_repo_paths_in_dir(dir: &str) -> Vec { .filter(|entry| { is_live_rocm_repo_file_name(&entry.file_name().to_string_lossy().to_lowercase()) }) - .map(|entry| entry.path().to_string_lossy().into_owned()) + .map(|entry| { + Path::new(dir) + .join(entry.file_name()) + .to_string_lossy() + .into_owned() + }) .collect() } @@ -3454,14 +3461,43 @@ mod tests { ); } + /// `probe_rocm_install` must scan every family's repo directory: narrowing + /// its call to fewer of `REPO_SCAN_DIRS` leaves the constant and + /// `merge_live_repo_paths` tests green, so this drives the probe itself + /// against a simulated host root with a repo file in each directory. + #[cfg(all(feature = "e2e-test-hooks", target_os = "linux"))] #[test] - fn repo_scan_dirs_cover_every_package_family() { - for dir in [ - "/etc/apt/sources.list.d", - "/etc/yum.repos.d", - "/etc/zypp/repos.d", + fn probe_rocm_install_scans_every_repo_family_directory() { + use crate::hardware_root::TEST_HOST_ROOT_ENV; + use crate::test_env::RestoredEnvVar; + + let root = tempfile::tempdir().expect("create host root"); + for (dir, file) in [ + ("etc/apt/sources.list.d", "amdgpu.list"), + ("etc/yum.repos.d", "amdgpu.repo"), + ("etc/zypp/repos.d", "amdgpu.repo"), ] { - assert!(REPO_SCAN_DIRS.contains(&dir), "missing {dir}"); + std::fs::create_dir_all(root.path().join(dir)).expect("create repo dir"); + std::fs::write(root.path().join(dir).join(file), "x\n").expect("write repo file"); + } + let mut e = Examination::default(); + { + let _guard = crate::hardware_root::HOST_ROOT_TEST_LOCK + .lock() + .unwrap_or_else(std::sync::PoisonError::into_inner); + let _root = RestoredEnvVar::set(TEST_HOST_ROOT_ENV, root.path()); + probe_rocm_install(&mut e); + } + for want in [ + "/etc/apt/sources.list.d/amdgpu.list", + "/etc/yum.repos.d/amdgpu.repo", + "/etc/zypp/repos.d/amdgpu.repo", + ] { + assert!( + e.rocm_repos_seen.iter().any(|p| p == want), + "missing {want}: {:?}", + e.rocm_repos_seen + ); } } diff --git a/crates/rocm-core/src/fix.rs b/crates/rocm-core/src/fix.rs index f3a1e8ddb7..6358b23f00 100644 --- a/crates/rocm-core/src/fix.rs +++ b/crates/rocm-core/src/fix.rs @@ -321,7 +321,7 @@ const RECIPES: &[FixRecipe] = &[ FixRecipe { fix_id: "fix-3-rocm-kernel", title: "ROCm/distro/kernel triple unsupported", - rationale: "ROCm is installed but your kernel/distro combination is outside the supported matrix. Match the kernel to the matrix first, then rerun `rocm install driver --dkms`.", + rationale: "ROCm is installed but your kernel/distro combination is outside the supported matrix. Match the kernel to the matrix first, then rerun `rocm install driver --dkms --yes` (documented distros only; Ubuntu 26.04 ships the driver in-tree, use `apt install rocm`).", commands: &[ "# Cross-check the live AMD matrix before changing anything:", "# https://rocm.docs.amd.com/projects/install-on-linux/en/latest/reference/system-requirements.html", @@ -1448,10 +1448,19 @@ fn print_recipe(r: &FixRecipe) { println!("Note: {n}"); } if !r.verify.is_empty() { - println!("Verify: {}", r.verify); + println!( + "Verify: {}", + indent_continuation(r.verify, " ") + ); } } +/// Indent every line after the first so a multi-line `verify` (fix-7 lists one +/// command per package manager) stays under its `Verify:` / `$` label. +fn indent_continuation(text: &str, indent: &str) -> String { + text.replace('\n', &format!("\n{indent}")) +} + /// What `rocm fix` says when it is handed a `rocm diagnose` ranking position /// (`#1`) rather than a fix-id. /// @@ -1580,7 +1589,7 @@ fn act_on(recipe: &FixRecipe, opts: &FixOptions) -> i32 { println!("This fix is print-only (manual change required)."); println!("Copy the commands above, run them yourself, then verify with:"); if !recipe.verify.is_empty() { - println!(" $ {}", recipe.verify); + println!(" $ {}", indent_continuation(recipe.verify, " ")); } exit::OK } @@ -3963,4 +3972,10 @@ mod tests { "this recipe's apt lines must match what diagnose.rs's apt family actually emits for fix-12-installer" ); } + + #[test] + fn indent_continuation_keeps_multi_line_verify_under_its_label() { + assert_eq!(indent_continuation("a\nb\nc", " "), "a\n b\n c"); + assert_eq!(indent_continuation("single", " "), "single"); + } } diff --git a/docs/testing.md b/docs/testing.md index c08a1b0af1..bca3bbc656 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -1785,7 +1785,7 @@ DKMS repo (the amdgpu driver ships in-tree instead), so the plan comes back covered at the unit level by `driver_plan_ubuntu_2604_uses_native_archive_guidance` and its two neighbors in [driver_install.rs](../apps/rocm/src/driver_install.rs), and at the e2e level -by `driver-install-06` above: the hosted `E2E tests` job's `ubuntu-26.04` image +by `driver-install-06` above: the hosted `E2E tests` job's `ubuntu-latest` image (26.04 once GitHub's migration completes) reaches this arm through the CLI itself, while the self-hosted GPU lane's 24.04 host exercises the apt arm instead. @@ -1979,6 +1979,19 @@ does not apply on — and exits 3. cargo xtask e2e -- -n '(diagnose-40)' ``` +`diagnose-42` uses the same simulated-host mechanism for the driver-reinstall +advice: an Ubuntu 24.04 `os-release` and two stale repo files planted under the +root make `fix-7-stale-repos` fire, and the scenario checks that it names both +repo files by their real paths and `rocm install driver --dkms --yes`, and that +`rocm install driver --help` accepts those flags. `driver-install-08` covers the +retired `ROCM_CLI_AMDGPU_VERSION` / `ROCM_CLI_AMDGPU_PACKAGE_RELEASE` refusal +and checks that setting `ROCM_CLI_AMDGPU_DRIVER_VERSION`, as the refusal advises, +clears it. + +```bash +cargo xtask e2e -- -n '(diagnose-42|driver-install-08)' +``` + The other half of the same change — `fix-13-hip-sdk-missing` no longer firing just because no HIP SDK is installed — has **no** end-to-end coverage and cannot have any. `check_13_hip_sdk_missing` returns early on every non-Windows host, so diff --git a/tests/e2e-cucumber/features/diagnose.feature b/tests/e2e-cucumber/features/diagnose.feature index 81ba7dd77b..3ee381eaac 100644 --- a/tests/e2e-cucumber/features/diagnose.feature +++ b/tests/e2e-cucumber/features/diagnose.feature @@ -633,3 +633,16 @@ Feature: Diagnosing failures and listing fixes Given a machine with an AMD GPU When the user diagnoses this machine in machine-readable form, with no symptom Then the diagnosis offers the old display driver advice only when the inspection reports an old driver + + # The remediation text names a command and the files to move aside, so it is + # checked against a simulated Ubuntu 24.04 machine (os-release and two stale + # repo files planted under the host root, as in diagnose-40) rather than the + # runner's own distro: the advice depends on the distro and the runner's is + # not fixed. The named command is then held to existing and accepting the + # flags it is advised with; its behaviour is covered by driver-install-06. + @id:diagnose-stale-repos-advice-names-the-driver-reinstall @requires-os:linux + Scenario: diagnose-42 - Stale repo advice on Ubuntu 24.04 names the planted repo files and a driver reinstall that exists + Given an Ubuntu 24.04 machine with two stale ROCm repo files + When the user diagnoses that machine with a stale repo symptom + Then the stale repo cause names both planted repo files and the driver reinstall command + And the advised driver reinstall command accepts the flags it is advised with diff --git a/tests/e2e-cucumber/features/driver_install.feature b/tests/e2e-cucumber/features/driver_install.feature index 15cf25c0c4..ae55b4a593 100644 --- a/tests/e2e-cucumber/features/driver_install.feature +++ b/tests/e2e-cucumber/features/driver_install.feature @@ -51,7 +51,7 @@ Feature: Driver installation planning And no driver command is shown or run, and no installer state is written # Every bare-metal Linux lane in this repo runs Ubuntu, but not always the - # same release -- the hosted `E2E tests` job's `ubuntu-26.04` image reports + # same release -- the hosted `E2E tests` job's `ubuntu-latest` image (26.04 once GitHub's migration completes) reports # 26.04 ("resolute"), which `build_driver_install_plan_at` routes to the # `ubuntu_native_archive` arm instead of the apt one (no repo.radeon.com/ # amdgpu suite published for "resolute" yet; see the `("ubuntu", "26.04")` @@ -84,3 +84,14 @@ Feature: Driver installation planning Scenario: driver-install-07 - An invalid ROCM_CLI_AMDGPU_DRIVER_VERSION override refuses the plan When the user previews driver installation with an invalid version override Then the driver plan refuses the invalid version override and plans no commands + + # The pre-repo-native pin variables are retired, not ignored: a stale export + # would otherwise turn into the floating `latest` without telling the user. + # The refusal names `ROCM_CLI_AMDGPU_DRIVER_VERSION`, so the scenario also + # runs that remedy and checks it clears the refusal. Bare-metal Linux only, + # for the same reason as driver-install-07. + @id:driver-install-retired-version-variable-refused @requires-os:linux @requires-bare-metal + Scenario: driver-install-08 - A retired version pin variable refuses the plan until the advised variable replaces it + When the user previews driver installation with a retired version pin variable + Then the driver plan refuses the retired variable and plans no commands + And setting the advised variable instead clears the refusal diff --git a/tests/e2e-cucumber/features/examine.feature b/tests/e2e-cucumber/features/examine.feature index 091adfbe6f..e527e46d7e 100644 --- a/tests/e2e-cucumber/features/examine.feature +++ b/tests/e2e-cucumber/features/examine.feature @@ -296,6 +296,7 @@ Feature: GPU detection and system inspection Given a machine whose release file quotes every value in single quotes When the user inspects that machine in machine-readable form Then the inspection reports the distribution "rhel" version "9.4" named "Red Hat Enterprise Linux 9.4 (Plow)" + And the inspection reports the distribution family "fedora" And the inspection reports no trouble reading the release file @id:examine-reads-last-os-release-assignment @requires-os:linux diff --git a/tests/e2e-cucumber/tests/e2e/diagnose_steps.rs b/tests/e2e-cucumber/tests/e2e/diagnose_steps.rs index 0f20f746ff..08e0ae1e85 100644 --- a/tests/e2e-cucumber/tests/e2e/diagnose_steps.rs +++ b/tests/e2e-cucumber/tests/e2e/diagnose_steps.rs @@ -2671,6 +2671,90 @@ async fn user_diagnoses_planted_machine(world: &mut E2eWorld) { world.cli_rc = Some(rc); } +// ── Stale repo advice on a simulated Ubuntu host ─────────────────── + +#[given("an Ubuntu 24.04 machine with two stale ROCm repo files")] +async fn ubuntu_with_stale_repos(world: &mut E2eWorld) { + let host = world + .isolated_root + .as_ref() + .expect("no isolated root") + .path() + .join("host-root"); + std::fs::create_dir_all(host.join("etc/apt/sources.list.d")) + .expect("failed to create planted apt directory"); + std::fs::write( + host.join("etc/os-release"), + "ID=ubuntu\nVERSION_ID=\"24.04\"\nVERSION_CODENAME=noble\nPRETTY_NAME=\"Ubuntu 24.04 LTS\"\n", + ) + .expect("failed to write planted os-release"); + for name in ["amdgpu.list", "rocm.list"] { + std::fs::write( + host.join("etc/apt/sources.list.d").join(name), + "# planted\n", + ) + .expect("failed to plant a repo file"); + } + world + .command_env + .push(("ROCM_CLI_TEST_HOST_ROOT", host.into_os_string())); +} + +#[when("the user diagnoses that machine with a stale repo symptom")] +async fn user_diagnoses_stale_repo_symptom(world: &mut E2eWorld) { + let (stdout, stderr, rc) = crate::run_rocm_with_scenario_env( + world, + &[ + "diagnose", + "--symptom", + "stale repo conflict", + "--top", + "20", + ], + ); + world.cli_output = Some(stdout); + world.cli_stderr = Some(stderr); + world.cli_rc = Some(rc); +} + +#[then("the stale repo cause names both planted repo files and the driver reinstall command")] +async fn assert_stale_repo_advice(world: &mut E2eWorld) { + let output = world.cli_output.as_ref().expect("no diagnose output"); + let cause: Vec<&str> = output + .lines() + .skip_while(|line| !line.contains("(fix-7-stale-repos)")) + .take_while(|line| !line.trim().is_empty()) + .collect(); + let text = cause.join("\n"); + assert!( + !text.is_empty(), + "no stale repo cause was reported:\n{output}" + ); + // The logical paths a user would move, not the scenario's temp host root. + for file in ["amdgpu.list", "rocm.list"] { + assert!( + text.contains(&format!("/etc/apt/sources.list.d/{file}")), + "{file} must be named by its real path:\n{text}" + ); + } + assert!( + text.contains("rocm install driver --dkms --yes"), + "Ubuntu 24.04 has a driver plan, so the advice must name it:\n{text}" + ); +} + +#[then("the advised driver reinstall command accepts the flags it is advised with")] +async fn assert_advised_driver_command_exists(world: &mut E2eWorld) { + let (stdout, _stderr, rc) = crate::run_rocm(world, &["install", "driver", "--help"]); + assert_eq!(rc, 0, "`rocm install driver --help` must exist:\n{stdout}"); + for flag in ["--dkms", "--yes"] { + assert!( + stdout.contains(flag), + "{flag} is advised but not accepted:\n{stdout}" + ); + } +} + // ── Windows display driver advice ────────────────────────────────── #[when("the user diagnoses this machine in machine-readable form, with no symptom")] diff --git a/tests/e2e-cucumber/tests/e2e/driver_steps.rs b/tests/e2e-cucumber/tests/e2e/driver_steps.rs index a9b05b1b17..2a8d34e3a8 100644 --- a/tests/e2e-cucumber/tests/e2e/driver_steps.rs +++ b/tests/e2e-cucumber/tests/e2e/driver_steps.rs @@ -39,7 +39,7 @@ async fn assert_driver_plan_matches_host_release(world: &mut E2eWorld) { // Derived from the host's own `/etc/os-release`, not from `output` -- // asserting against the very thing being checked would let a change that // breaks the arm-selection logic pass by construction. The hosted - // `ubuntu-26.04` E2E image reports 26.04 ("resolute"), which has no + // `ubuntu-latest` E2E image (26.04 once GitHub's migration completes) reports 26.04 ("resolute"), which has no // published repo.radeon.com/amdgpu suite yet and takes // `ubuntu_native_archive`; the self-hosted GPU lane reports 24.04 and // takes the apt arm. See the `("ubuntu", "26.04")` arm in @@ -70,7 +70,7 @@ async fn assert_driver_plan_matches_host_release(world: &mut E2eWorld) { return; } - // The runner may already be root (the self-hosted WSL runner always is), + // The runner may already be root (a self-hosted runner may be), // in which case the plan omits the `sudo ` prefix entirely. let sudo = if rocm_core::openmpi::running_as_root() { "" @@ -256,6 +256,50 @@ async fn ask_windows_driver_install(world: &mut E2eWorld) { world.cli_rc = Some(rc); } +#[when("the user previews driver installation with a retired version pin variable")] +async fn preview_driver_install_retired_variable(world: &mut E2eWorld) { + let (stdout, stderr, rc) = crate::run_rocm_with_env( + world, + &["install", "driver", "--dkms", "--dry-run"], + &[("ROCM_CLI_AMDGPU_VERSION", "7.2.4")], + ); + world.cli_output = Some(stdout); + world.cli_stderr = Some(stderr); + world.cli_rc = Some(rc); +} + +#[then("the driver plan refuses the retired variable and plans no commands")] +async fn assert_driver_plan_refuses_retired_variable(world: &mut E2eWorld) { + let output = world.cli_output.as_ref().expect("no driver plan output"); + assert!( + output.contains("policy: retired_driver_version_override"), + "{output}" + ); + assert!(output.contains("supported: false"), "{output}"); + assert!(output.contains("mutating: false"), "{output}"); + assert!( + output.contains("ROCM_CLI_AMDGPU_DRIVER_VERSION"), + "{output}" + ); + assert!(output.contains("execution_commands: "), "{output}"); +} + +#[then("setting the advised variable instead clears the refusal")] +async fn assert_advised_variable_clears_retired_refusal(world: &mut E2eWorld) { + // The refusal tells the user to unset the retired variable and set this + // one; run exactly that and hold the claim to the resulting plan. + let (stdout, _stderr, _rc) = crate::run_rocm_with_env( + world, + &["install", "driver", "--dkms", "--dry-run"], + &[("ROCM_CLI_AMDGPU_DRIVER_VERSION", "30.10")], + ); + assert!( + !stdout.contains("policy: retired_driver_version_override") + && !stdout.contains("policy: invalid_driver_version_override"), + "{stdout}" + ); +} + #[then("the driver plan refuses the invalid version override and plans no commands")] async fn assert_driver_plan_refuses_invalid_override(world: &mut E2eWorld) { let output = world.cli_output.as_ref().expect("no driver plan output"); diff --git a/tests/e2e-cucumber/tests/e2e/examine_steps.rs b/tests/e2e-cucumber/tests/e2e/examine_steps.rs index 779439a055..42613a6cec 100644 --- a/tests/e2e-cucumber/tests/e2e/examine_steps.rs +++ b/tests/e2e-cucumber/tests/e2e/examine_steps.rs @@ -1541,6 +1541,12 @@ async fn assert_reported_distribution( assert_eq!(inspection_str(&json, "/summary/distro"), name, "{json:#}"); } +#[then(expr = "the inspection reports the distribution family {string}")] +async fn assert_reported_distribution_family(world: &mut E2eWorld, like: String) { + let json = parsed_json(world); + assert_eq!(inspection_str(&json, "/distro_id_like"), like, "{json:#}"); +} + #[then("the inspection reports no trouble reading the release file")] async fn assert_os_release_read_cleanly(world: &mut E2eWorld) { let json = parsed_json(world); From a9ab9abaf2bfbd1d09a9bdfa46011a1f277ed83f Mon Sep 17 00:00:00 2001 From: Juho Vainio Date: Tue, 27 Oct 2026 16:11:22 +0200 Subject: [PATCH 7/7] fix(driver): exit non-zero when approving an unsupported driver plan install driver --yes on a supported:false plan (Ubuntu 26.04, undocumented distro, refused version override) printed the plan and exited 0 although nothing was installed. It now fails after printing the plan; native Windows stays a successful no-op. Qualify the static fix-12 recipe with the hosts its reinstall and verify apply to, and note the missing non-Ubuntu assertion in driver-install-06. Signed-off-by: Juho Vainio --- README.md | 4 +++ apps/rocm/src/driver_install.rs | 35 +++++++++++++++++++ crates/rocm-core/src/fix.rs | 1 + .../features/driver_install.feature | 1 + tests/e2e-cucumber/tests/e2e/driver_steps.rs | 19 +++++++++- 5 files changed, 59 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b6d838b502..971603db19 100644 --- a/README.md +++ b/README.md @@ -577,6 +577,10 @@ yet publish a matching DKMS repo, so `install driver` reports a non-mutating `supported: false` plan instead and directs you to `apt install rocm` for the userspace ROCm stack. +Approving (`--yes`) a plan that is `supported: false` (Ubuntu 26.04, an +undocumented distro, or a refused version override) installs nothing and exits +non-zero, after printing the plan. + On Windows, `install driver` is validate-only: it installs and changes nothing, with or without `--yes`, and it starts no driver command. It prints the AMD display driver version and date, and whether the date is older than the first diff --git a/apps/rocm/src/driver_install.rs b/apps/rocm/src/driver_install.rs index a9d5b8a0a0..156de45835 100644 --- a/apps/rocm/src/driver_install.rs +++ b/apps/rocm/src/driver_install.rs @@ -46,6 +46,14 @@ const fn should_execute(plan: &DriverInstallPlan, yes: bool, dry_run: bool) -> b yes && !dry_run && plan.supported && plan.mutating } +/// Whether an approved (`--yes`) run asks for a plan that installs nothing and +/// should say so with a failing exit status. Native Windows is exempt: its +/// plan only reports and promises to change nothing, so approving it is a +/// successful no-op. +fn approval_of_unsupported_plan(plan: &DriverInstallPlan, yes: bool, dry_run: bool) -> bool { + yes && !dry_run && !plan.supported && plan.policy != "windows_validate_only" +} + pub(crate) fn install_driver( paths: &AppPaths, dkms: bool, @@ -60,6 +68,16 @@ pub(crate) fn install_driver( let plan = build_driver_install_plan_read(&examine, &os_release, dkms, PrivilegeEscalation::detect()); let mut output = render_driver_install_plan(&plan, yes, dry_run); + if approval_of_unsupported_plan(&plan, yes, dry_run) { + return Err(DriverInstallError::new( + anyhow::anyhow!( + "{output}\nnothing was installed: this host has no supported driver plan ({}). {}", + plan.policy, + plan.reason + ), + false, + )); + } if !should_execute(&plan, yes, dry_run) { return Ok(DriverInstallResult { output, @@ -3678,6 +3696,23 @@ VERSION_ID="15.7" } } + #[test] + fn approving_an_unsupported_plan_is_an_error_but_not_a_dry_run_or_windows() { + let mut plan = unsupported_test_plan(); + assert!(approval_of_unsupported_plan(&plan, true, false)); + assert!(!approval_of_unsupported_plan(&plan, false, false)); + assert!(!approval_of_unsupported_plan(&plan, true, true)); + plan.policy = "windows_validate_only".to_owned(); + assert!(!approval_of_unsupported_plan(&plan, true, false)); + plan.policy = "x".to_owned(); + plan.supported = true; + assert!(!approval_of_unsupported_plan(&plan, true, false)); + } + + fn unsupported_test_plan() -> DriverInstallPlan { + invalid_driver_version_override_plan("x".to_owned()) + } + #[test] fn driver_plan_refuses_a_retired_version_pin_variable() { for retired in RETIRED_DRIVER_VERSION_VARS { diff --git a/crates/rocm-core/src/fix.rs b/crates/rocm-core/src/fix.rs index 6358b23f00..6e3ec27269 100644 --- a/crates/rocm-core/src/fix.rs +++ b/crates/rocm-core/src/fix.rs @@ -557,6 +557,7 @@ const RECIPES: &[FixRecipe] = &[ && rocminfo >/dev/null 2>&1", notes: &[ "If the purge/remove step warns it will take unrelated packages with it, stop and resolve those by hand before continuing.", + "The `rocm install driver --dkms --yes` line and the verify below apply only on AMD-documented distros; `rocm install driver --dkms --yes` exits non-zero where it plans nothing (Ubuntu 26.04, undocumented distros). There, verify with `rocminfo` alone, or `dpkg-query -W rocm` after `sudo apt install rocm` on Ubuntu 26.04.", ], doc_url: None, applies_on: PRINT_ON_LINUX, diff --git a/tests/e2e-cucumber/features/driver_install.feature b/tests/e2e-cucumber/features/driver_install.feature index ae55b4a593..c548cb2ab9 100644 --- a/tests/e2e-cucumber/features/driver_install.feature +++ b/tests/e2e-cucumber/features/driver_install.feature @@ -95,3 +95,4 @@ Feature: Driver installation planning When the user previews driver installation with a retired version pin variable Then the driver plan refuses the retired variable and plans no commands And setting the advised variable instead clears the refusal + And approving the install with the retired variable still set fails and installs nothing diff --git a/tests/e2e-cucumber/tests/e2e/driver_steps.rs b/tests/e2e-cucumber/tests/e2e/driver_steps.rs index 2a8d34e3a8..c35d1180e3 100644 --- a/tests/e2e-cucumber/tests/e2e/driver_steps.rs +++ b/tests/e2e-cucumber/tests/e2e/driver_steps.rs @@ -56,7 +56,9 @@ async fn assert_driver_plan_matches_host_release(world: &mut E2eWorld) { // this scenario's premise is Ubuntu specifically (every assertion // below hard-codes Ubuntu's apt/native-archive command text), so a // future non-Ubuntu bare-metal lane has no premise here rather than - // failing against text it was never meant to produce. + // failing against text it was never meant to produce. The harness has + // no per-step skip, so say so rather than passing silently. + eprintln!("driver-install-06: not an Ubuntu host, nothing asserted"); return; } @@ -300,6 +302,21 @@ async fn assert_advised_variable_clears_retired_refusal(world: &mut E2eWorld) { ); } +#[then("approving the install with the retired variable still set fails and installs nothing")] +async fn assert_approving_retired_variable_fails(world: &mut E2eWorld) { + // Safe on a real host: the refusal precedes any command, so `--yes` has + // nothing to execute and no installer state is written. + let (stdout, stderr, rc) = crate::run_rocm_with_env( + world, + &["install", "driver", "--dkms", "--yes"], + &[("ROCM_CLI_AMDGPU_VERSION", "7.2.4")], + ); + assert_ne!(rc, 0, "an approved refused plan must not exit 0:\n{stdout}"); + let all = format!("{stdout}{stderr}"); + assert!(all.contains("nothing was installed"), "{all}"); + assert!(!all.contains("driver install completed"), "{all}"); +} + #[then("the driver plan refuses the invalid version override and plans no commands")] async fn assert_driver_plan_refuses_invalid_override(world: &mut E2eWorld) { let output = world.cli_output.as_ref().expect("no driver plan output");