From 8d0dc52cfa195fca925b50b65f12278e84c81c11 Mon Sep 17 00:00:00 2001 From: Wei Liu Date: Sat, 30 May 2026 15:43:44 -0700 Subject: [PATCH] tpm: add startup response tests Cover the accepted TPM2_Startup(CLEAR) response codes so the swtpm reset handling keeps tolerating already-initialized TPMs. Assisted-by: Copilot:GPT-5.5 Signed-off-by: Wei Liu --- tpm/src/emulator.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tpm/src/emulator.rs b/tpm/src/emulator.rs index 3b4fbf08f..0caeecdc1 100644 --- a/tpm/src/emulator.rs +++ b/tpm/src/emulator.rs @@ -562,3 +562,19 @@ impl Drop for Emulator { } } } + +#[cfg(test)] +mod unit_tests { + use super::*; + + #[test] + fn test_startup_response_accepts_success_and_initialized() { + assert!(startup_response_is_ok(TPM_SUCCESS)); + assert!(startup_response_is_ok(TPM_RC_INITIALIZE)); + } + + #[test] + fn test_startup_response_rejects_other_errors() { + assert!(!startup_response_is_ok(0x101)); + } +}