From ceb5ef155aaa9836777f04c03e5b33a794f8f9d9 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Tue, 5 Apr 2022 13:31:18 -0700 Subject: [PATCH] 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 Tested-by: kokoro Commit-Queue: Daniel Verkamp --- aarch64/src/fdt.rs | 55 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/aarch64/src/fdt.rs b/aarch64/src/fdt.rs index 8d9528fa35..1f3347f1e9 100644 --- a/aarch64/src/fdt.rs +++ b/aarch64/src/fdt.rs @@ -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"] + ); + } +}