aarch64: fdt: add PSCI compatible string tests

Move the PSCI version to compatible code to a function so it can be more
easily tested and add a few basic unit tests.

BUG=b:227142928
TEST=tools/dev_container tools/run_tests --target=vm:aarch64

Change-Id: I383b6e9df76f26995adab6fe980fd29fe1fcdf0a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3573362
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
This commit is contained in:
Daniel Verkamp 2022-04-05 13:31:18 -07:00 committed by Chromeos LUCI
parent 1d1372f742
commit ceb5ef155a

View file

@ -223,7 +223,7 @@ fn create_serial_nodes(fdt: &mut FdtWriter) -> Result<()> {
Ok(())
}
fn create_psci_node(fdt: &mut FdtWriter, version: &PsciVersion) -> Result<()> {
fn psci_compatible(version: &PsciVersion) -> Vec<&str> {
// The PSCI kernel driver only supports compatible strings for the following
// backward-compatible versions.
let supported = [(PSCI_1_0, "arm,psci-1.0"), (PSCI_0_2, "arm,psci-0.2")];
@ -239,6 +239,11 @@ fn create_psci_node(fdt: &mut FdtWriter, version: &PsciVersion) -> Result<()> {
compatible = vec!["arm,psci"];
}
compatible
}
fn create_psci_node(fdt: &mut FdtWriter, version: &PsciVersion) -> Result<()> {
let compatible = psci_compatible(version);
let psci_node = fdt.begin_node("psci")?;
fdt.property_string_list("compatible", &compatible)?;
// Only support aarch64 guest
@ -509,3 +514,51 @@ pub fn create_fdt(
}
Ok(())
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn psci_compatible_v0_1() {
assert_eq!(
psci_compatible(&PsciVersion::new(0, 1).unwrap()),
vec!["arm,psci"]
);
}
#[test]
fn psci_compatible_v0_2() {
assert_eq!(
psci_compatible(&PsciVersion::new(0, 2).unwrap()),
vec!["arm,psci-0.2"]
);
}
#[test]
fn psci_compatible_v0_5() {
// Only the 0.2 version supported by the kernel should be added.
assert_eq!(
psci_compatible(&PsciVersion::new(0, 5).unwrap()),
vec!["arm,psci-0.2"]
);
}
#[test]
fn psci_compatible_v1_0() {
// Both 1.0 and 0.2 should be listed, in that order.
assert_eq!(
psci_compatible(&PsciVersion::new(1, 0).unwrap()),
vec!["arm,psci-1.0", "arm,psci-0.2"]
);
}
#[test]
fn psci_compatible_v1_5() {
// Only the 1.0 and 0.2 versions supported by the kernel should be listed.
assert_eq!(
psci_compatible(&PsciVersion::new(1, 5).unwrap()),
vec!["arm,psci-1.0", "arm,psci-0.2"]
);
}
}