Your browser sucks, JavaScript disabled! Gunnar's console needs JavaScript and WebAssembly. Git over SSH on port 2222 does not.

nordisk/heimdall

crates/heimdall-cli/tests/kernel_needs.rs

// SPDX-License-Identifier: AGPL-3.0-only
//! `heimdall kernel needs [--json]` (KTOOL fix 7): the kconfig lines a strict
//! runner needs, each with its reason, as `nornir.kernel-runtime-needs/1`.
//! Heimdall is a defensive sandbox; this verb only describes what it needs.

use std::process::Command;

use heimdall_container::kernel::{KernelNeeds, KERNEL_NEEDS_SCHEMA};

fn heimdall(args: &[&str]) -> std::process::Output {
    Command::new(env!("CARGO_BIN_EXE_heimdall"))
        .args(args)
        .output()
        .unwrap()
}

#[test]
fn kernel_needs_json_is_the_strict_document_and_validates() {
    let o = heimdall(&["kernel", "needs", "--json"]);
    assert_eq!(
        o.status.code(),
        Some(0),
        "{}",
        String::from_utf8_lossy(&o.stderr)
    );
    let doc: KernelNeeds = serde_json::from_slice(&o.stdout).unwrap();
    assert_eq!(doc.schema, KERNEL_NEEDS_SCHEMA);
    doc.validate().unwrap();
    assert_eq!(doc, KernelNeeds::strict());
}

#[test]
fn kernel_needs_text_names_each_line_with_its_reason() {
    let o = heimdall(&["kernel", "needs"]);
    assert_eq!(o.status.code(), Some(0));
    let t = String::from_utf8_lossy(&o.stdout);
    for n in KernelNeeds::strict().needs {
        let line = t
            .lines()
            .find(|l| l.contains(&n.symbol))
            .unwrap_or_else(|| panic!("{} not in\n{t}", n.symbol));
        assert!(t.contains(&n.reason), "{line}");
    }
    assert!(t.contains("CONFIG_LSM"), "{t}");
}

#[test]
fn kernel_needs_refuses_an_unknown_mode() {
    let o = heimdall(&["kernel", "needs", "--mode", "lax"]);
    assert_eq!(o.status.code(), Some(2));
}