hwbcc-rust: skip tests in trusty vms
Certain tests were written assuming a specific hard-coded emulator key
and degenerate certs. Don't set the generic-arm-unittest feature when
trusty is running as a vm guest.
Also introduce a separate feature for trusty as a vm guest so that we
can skip tests for unsupported features like TestMode and
ns_deprivilege.
Bug: 405148817
Test: atest TrustyVmUnitTests
Change-Id: Iecc0033bb0d2a92e8de06be001b8656a2b314707
diff --git a/lib/hwbcc/rust/rules.mk b/lib/hwbcc/rust/rules.mk
index a5178e2..3874ac5 100644
--- a/lib/hwbcc/rust/rules.mk
+++ b/lib/hwbcc/rust/rules.mk
@@ -60,10 +60,22 @@
MODULE_BINDGEN_SRC_HEADER := $(LOCAL_DIR)/bindings.h
# Enable tests specific to the generic emulator build,
-# which depend on the device-specific BCC key
+# which depend on the device-specific BCC key.
+# Exclude trusty as a VM guest since on arm those builds run
+# as part of the generic-arm64 platform but do not use the
+# same hardcoded key.
ifeq (generic-arm64, $(PLATFORM))
+ifeq (false,$(call TOBOOL,$(TRUSTY_VM_GUEST)))
MODULE_RUSTFLAGS += --cfg 'feature="generic-arm-unittest"'
endif
+endif
+
+# Some functionality of hwbcc does not exist in VMs
+# like TEST_MODE and ns_deprivilege.
+ifeq (true,$(call TOBOOL,$(TRUSTY_VM_GUEST)))
+MODULE_RUSTFLAGS += --cfg 'feature="trusty_vm_guest"'
+endif
+
MODULE_RUST_TESTS := true
diff --git a/lib/hwbcc/rust/src/test.rs b/lib/hwbcc/rust/src/test.rs
index 80bdb25..7386598 100644
--- a/lib/hwbcc/rust/src/test.rs
+++ b/lib/hwbcc/rust/src/test.rs
@@ -15,10 +15,10 @@
*/
use super::*;
-use ::test::{assert, assert_ne};
+use ::test::assert;
#[cfg(feature = "generic-arm-unittest")]
-use ::test::assert_eq;
+use ::test::{assert_eq, assert_ne};
#[cfg(feature = "generic-arm-unittest")]
use system_state::{SystemState, SystemStateFlag};
@@ -94,6 +94,7 @@
}
}
+#[cfg(not(feature = "trusty_vm_guest"))]
#[test]
fn test_ns_deprivilege() {
ns_deprivilege().expect("could not execute ns deprivilege");
@@ -103,6 +104,7 @@
assert!(get_dice_artifacts(0, dice_artifacts_buf).is_ok());
}
+#[cfg(not(feature = "trusty_vm_guest"))]
#[test]
fn test_get_bcc_test_mode() {
let mut bcc_buf = [0u8; HWBCC_MAX_RESP_PAYLOAD_LENGTH];
@@ -191,6 +193,7 @@
assert_eq!(dk_pub_key, km_pub_key);
}
+#[cfg(not(feature = "trusty_vm_guest"))]
#[test]
fn test_sign_data_test_mode() {
let mut cose_sign1_buf = [0u8; HWBCC_MAX_RESP_PAYLOAD_LENGTH];
@@ -207,7 +210,6 @@
assert!(cose_sign1.len() > 0);
}
-#[cfg(feature = "generic-arm-unittest")]
#[test]
fn test_sign_data() {
let mut cose_sign1_buf = [0u8; HWBCC_MAX_RESP_PAYLOAD_LENGTH];