static void VbUnlockDeviceTest(void) { ResetMocks(); TEST_EQ(VbUnlockDevice(), 0, "unlock success"); ResetMocks(); virtual_dev_mode_fail = 1; TEST_EQ(VbUnlockDevice(), VBERROR_TPM_SET_BOOT_MODE_STATE, "set dev fail"); }
/** * Test PCR funcs * * TODO: check params/data read/written. */ static void PcrTest(void) { uint8_t buf[kPcrDigestLength], buf2[kPcrDigestLength]; ResetMocks(); TEST_EQ(TlclPCRRead(1, buf, kPcrDigestLength), 0, "PCRRead"); TEST_EQ(calls[0].req_cmd, TPM_ORD_PcrRead, " cmd"); ResetMocks(); TEST_EQ(TlclPCRRead(1, buf, kPcrDigestLength - 1), TPM_E_IOERROR, "PCRRead too small"); ResetMocks(); TEST_EQ(TlclExtend(1, buf, buf2), 0, "Extend"); TEST_EQ(calls[0].req_cmd, TPM_ORD_Extend, " cmd"); }
/** * NV spaces test * * TODO: check params/data read/written. */ static void ReadWriteTest(void) { uint8_t buf[32]; ResetMocks(); TEST_EQ(TlclDefineSpace(1, 2, 3), 0, "DefineSpace"); TEST_EQ(calls[0].req_cmd, TPM_ORD_NV_DefineSpace, " cmd"); ResetMocks(); TEST_EQ(TlclSetNvLocked(), 0, "SetNvLocked"); TEST_EQ(calls[0].req_cmd, TPM_ORD_NV_DefineSpace, " cmd"); ResetMocks(); TEST_EQ(TlclWrite(1, buf, 3), 0, "Write"); TEST_EQ(calls[0].req_cmd, TPM_ORD_NV_WriteValue, " cmd"); ResetMocks(); TEST_EQ(TlclRead(1, buf, 3), 0, "Read"); TEST_EQ(calls[0].req_cmd, TPM_ORD_NV_ReadValue, " cmd"); ResetMocks(); TEST_EQ(TlclWriteLock(1), 0, "WriteLock"); TEST_EQ(calls[0].req_cmd, TPM_ORD_NV_WriteValue, " cmd"); ResetMocks(); TEST_EQ(TlclReadLock(1), 0, "ReadLock"); TEST_EQ(calls[0].req_cmd, TPM_ORD_NV_ReadValue, " cmd"); ResetMocks(); TEST_EQ(TlclSetGlobalLock(), 0, "SetGlobalLock"); TEST_EQ(calls[0].req_cmd, TPM_ORD_NV_WriteValue, " cmd"); }
/* Test display key checking */ static void DisplayKeyTest(void) { uint32_t u; ResetMocks(); VbCheckDisplayKey(&cparams, 'q', &vnc); TEST_EQ(*debug_info, '\0', "DisplayKey q = does nothing"); VbApiKernelFree(&cparams); ResetMocks(); VbCheckDisplayKey(&cparams, '\t', &vnc); TEST_NEQ(*debug_info, '\0', "DisplayKey tab = display"); VbApiKernelFree(&cparams); /* Toggle localization */ ResetMocks(); VbNvSet(&vnc, VBNV_LOCALIZATION_INDEX, 0); VbNvTeardown(&vnc); VbCheckDisplayKey(&cparams, VB_KEY_DOWN, &vnc); VbNvGet(&vnc, VBNV_LOCALIZATION_INDEX, &u); TEST_EQ(u, 2, "DisplayKey up"); VbCheckDisplayKey(&cparams, VB_KEY_LEFT, &vnc); VbNvGet(&vnc, VBNV_LOCALIZATION_INDEX, &u); TEST_EQ(u, 1, "DisplayKey left"); VbCheckDisplayKey(&cparams, VB_KEY_RIGHT, &vnc); VbNvGet(&vnc, VBNV_LOCALIZATION_INDEX, &u); TEST_EQ(u, 2, "DisplayKey right"); VbCheckDisplayKey(&cparams, VB_KEY_UP, &vnc); VbNvGet(&vnc, VBNV_LOCALIZATION_INDEX, &u); TEST_EQ(u, 0, "DisplayKey up"); VbApiKernelFree(&cparams); /* Reset localization if localization count is invalid */ ResetMocks(); VbNvSet(&vnc, VBNV_LOCALIZATION_INDEX, 1); VbNvTeardown(&vnc); bhdr->signature[0] ^= 0x5a; VbCheckDisplayKey(&cparams, VB_KEY_UP, &vnc); VbNvGet(&vnc, VBNV_LOCALIZATION_INDEX, &u); TEST_EQ(u, 0, "DisplayKey invalid"); VbApiKernelFree(&cparams); }
static void VbRegionReadTest(void) { /* Should read GBB */ ResetMocks(); TEST_TRUE(1, "Normal call"); TEST_EQ(VbSelectFirmware(&cparams, &fparams), VBERROR_SUCCESS, " Success"); TEST_EQ(mock_seen_region, 1 << VB_REGION_GBB, " GBB region"); TEST_PTR_EQ(cparams.gbb, NULL, " GBB free"); ResetMocks(); TEST_EQ(VbSelectAndLoadKernel(&cparams, &kparams), VBERROR_NO_DISK_FOUND, "Kernel"); TEST_PTR_EQ(cparams.gbb, NULL, " GBB free"); TEST_PTR_EQ(cparams.bmp, NULL, " BMP free"); ResetMocks(); shared->flags |= VBSD_BOOT_DEV_SWITCH_ON; TEST_EQ(VbSelectAndLoadKernel(&cparams, &kparams), VBERROR_NO_DISK_FOUND, "Kernel"); }
/** * Test random * * TODO: check params/data read/written. * TODO: check overflow tests. */ static void RandomTest(void) { uint8_t buf[32]; uint32_t size; ResetMocks(); size = sizeof(buf); TEST_EQ(TlclGetRandom(buf, sizeof(buf), &size), 0, "GetRandom"); TEST_EQ(calls[0].req_cmd, TPM_ORD_GetRandom, " cmd"); TEST_EQ(size, 0, " size 0"); }
/** * Test flags / capabilities * * TODO: check params/data read/written. */ static void FlagsTest(void) { TPM_PERMANENT_FLAGS pflags; TPM_STCLEAR_FLAGS vflags; uint8_t disable = 0, deactivated = 0, nvlocked = 0; uint32_t u; uint8_t buf[32]; ResetMocks(); TEST_EQ(TlclGetPermanentFlags(&pflags), 0, "GetPermanentFlags"); TEST_EQ(calls[0].req_cmd, TPM_ORD_GetCapability, " cmd"); ResetMocks(); TEST_EQ(TlclGetSTClearFlags(&vflags), 0, "GetSTClearFlags"); TEST_EQ(calls[0].req_cmd, TPM_ORD_GetCapability, " cmd"); ResetMocks(); TEST_EQ(TlclGetFlags(NULL, NULL, NULL), 0, "GetFlags NULL"); TEST_EQ(calls[0].req_cmd, TPM_ORD_GetCapability, " cmd"); ResetMocks(); TEST_EQ(TlclGetFlags(&disable, &deactivated, &nvlocked), 0, "GetFlags"); ResetMocks(); TEST_EQ(TlclGetPermissions(1, &u), 0, "GetPermissions"); TEST_EQ(calls[0].req_cmd, TPM_ORD_GetCapability, " cmd"); ResetMocks(); TEST_EQ(TlclGetOwnership(buf), 0, "GetOwnership"); TEST_EQ(calls[0].req_cmd, TPM_ORD_GetCapability, " cmd"); }
/* Test localization */ static void LocalizationTest(void) { uint32_t count = 6; ResetMocks(); cparams.gbb->bmpfv_size = 0; TEST_EQ(VbGetLocalizationCount(&cparams, &count), VBERROR_UNKNOWN, "VbGetLocalizationCount bad gbb"); TEST_EQ(count, 0, " count"); VbApiKernelFree(&cparams); ResetMocks(); bhdr->signature[0] ^= 0x5a; TEST_EQ(VbGetLocalizationCount(&cparams, &count), VBERROR_UNKNOWN, "VbGetLocalizationCount bad bmpfv"); VbApiKernelFree(&cparams); ResetMocks(); TEST_EQ(VbGetLocalizationCount(&cparams, &count), 0, "VbGetLocalizationCount()"); TEST_EQ(count, 3, " count"); VbApiKernelFree(&cparams); }
/* Test display key checking */ static void DisplayKeyTest(void) { ResetMocks(); VbCheckDisplayKey(&ctx, 'q', NULL); TEST_EQ(*debug_info, '\0', "DisplayKey q = does nothing"); ResetMocks(); VbCheckDisplayKey(&ctx, '\t', NULL); TEST_NEQ(*debug_info, '\0', "DisplayKey tab = display"); /* Toggle localization */ ResetMocks(); vb2_nv_set(&ctx, VB2_NV_LOCALIZATION_INDEX, 0); VbCheckDisplayKey(&ctx, VB_KEY_DOWN, NULL); TEST_EQ(vb2_nv_get(&ctx, VB2_NV_LOCALIZATION_INDEX), 2, "DisplayKey up"); VbCheckDisplayKey(&ctx, VB_KEY_LEFT, NULL); vb2_nv_get(&ctx, VB2_NV_LOCALIZATION_INDEX); TEST_EQ(vb2_nv_get(&ctx, VB2_NV_LOCALIZATION_INDEX), 1, "DisplayKey left"); VbCheckDisplayKey(&ctx, VB_KEY_RIGHT, NULL); vb2_nv_get(&ctx, VB2_NV_LOCALIZATION_INDEX); TEST_EQ(vb2_nv_get(&ctx, VB2_NV_LOCALIZATION_INDEX), 2, "DisplayKey right"); VbCheckDisplayKey(&ctx, VB_KEY_UP, NULL); vb2_nv_get(&ctx, VB2_NV_LOCALIZATION_INDEX); TEST_EQ(vb2_nv_get(&ctx, VB2_NV_LOCALIZATION_INDEX), 0, "DisplayKey up"); /* Reset localization if localization count is invalid */ ResetMocks(); vb2_nv_set(&ctx, VB2_NV_LOCALIZATION_INDEX, 1); mock_localization_count = 0xffffffff; VbCheckDisplayKey(&ctx, VB_KEY_UP, NULL); TEST_EQ(vb2_nv_get(&ctx, VB2_NV_LOCALIZATION_INDEX), 0, "DisplayKey invalid"); }
/** * Test assorted tlcl functions */ static void TlclTest(void) { uint8_t buf[32], buf2[32]; ResetMocks(); TEST_EQ(TlclLibInit(), VBERROR_SUCCESS, "Init"); ResetMocks(); mock_retval = VBERROR_SIMULATED; TEST_EQ(TlclLibInit(), mock_retval, "Init bad"); ResetMocks(); TEST_EQ(TlclLibClose(), VBERROR_SUCCESS, "Close"); ResetMocks(); mock_retval = VBERROR_SIMULATED; TEST_EQ(TlclLibClose(), mock_retval, "Close bad"); ResetMocks(); ToTpmUint32(buf + 2, 123); TEST_EQ(TlclPacketSize(buf), 123, "TlclPacketSize"); ResetMocks(); ToTpmUint32(buf + 2, 10); TEST_EQ(TlclSendReceive(buf, buf2, sizeof(buf2)), 0, "SendReceive"); TEST_PTR_EQ(calls[0].req, buf, "SendReceive req ptr"); TEST_EQ(calls[0].req_size, 10, "SendReceive size"); ResetMocks(); calls[0].retval = VBERROR_SIMULATED; ToTpmUint32(buf + 2, 10); TEST_EQ(TlclSendReceive(buf, buf2, sizeof(buf2)), VBERROR_SIMULATED, "SendReceive fail"); ResetMocks(); SetResponse(0, 123, 10); ToTpmUint32(buf + 2, 10); TEST_EQ(TlclSendReceive(buf, buf2, sizeof(buf2)), 123, "SendReceive error response"); // TODO: continue self test (if needed or doing) // TODO: then retry doing self test }
static void VbTryLoadKernelTest(void) { int i; int num_tests = sizeof(test) / sizeof(test[0]); for (i = 0; i < num_tests; i++) { printf("Test case: %s ...\n", test[i].name); ResetMocks(i); TEST_EQ(VbTryLoadKernel(0, &lkparams, test[i].want_flags), t->expected_return_val, " return value"); TEST_EQ(got_recovery_request_val, t->expected_recovery_request_val, " recovery_request"); if (t->expected_to_find_disk != DONT_CARE) { TEST_PTR_EQ(got_find_disk, t->expected_to_find_disk, " find disk"); TEST_PTR_EQ(got_load_disk, t->expected_to_load_disk, " load disk"); } TEST_EQ(got_external_mismatch, 0, " external GPT errors"); } }
/* Test displaying debug info */ static void DebugInfoTest(void) { char hwid[VB_REGION_HWID_LEN]; int i; /* Recovery string should be non-null for any code */ for (i = 0; i < 0x100; i++) TEST_PTR_NEQ(RecoveryReasonString(i), NULL, "Non-null reason"); /* HWID should come from the gbb */ ResetMocks(); VbRegionReadHWID(&cparams, hwid, sizeof(hwid)); TEST_EQ(strcmp(hwid, "Test HWID"), 0, "HWID"); VbApiKernelFree(&cparams); ResetMocks(); cparams.gbb_size = 0; VbRegionReadHWID(&cparams, hwid, sizeof(hwid)); TEST_EQ(strcmp(hwid, "{INVALID}"), 0, "HWID bad gbb"); VbApiKernelFree(&cparams); ResetMocks(); cparams.gbb->hwid_size = 0; VbRegionReadHWID(&cparams, hwid, sizeof(hwid)); TEST_EQ(strcmp(hwid, "{INVALID}"), 0, "HWID missing"); VbApiKernelFree(&cparams); ResetMocks(); cparams.gbb->hwid_offset = cparams.gbb_size + 1; VbRegionReadHWID(&cparams, hwid, sizeof(hwid)); TEST_EQ(strcmp(hwid, "{INVALID}"), 0, "HWID past end"); VbApiKernelFree(&cparams); ResetMocks(); cparams.gbb->hwid_size = cparams.gbb_size; VbRegionReadHWID(&cparams, hwid, sizeof(hwid)); TEST_EQ(strcmp(hwid, "{INVALID}"), 0, "HWID overflow"); VbApiKernelFree(&cparams); /* Display debug info */ ResetMocks(); VbDisplayDebugInfo(&cparams, &vnc); TEST_NEQ(*debug_info, '\0', "Some debug info was displayed"); VbApiKernelFree(&cparams); }
/* Test displaying debug info */ static void DebugInfoTest(void) { char hwid[256]; int i; /* Recovery string should be non-null for any code */ for (i = 0; i < 0x100; i++) TEST_PTR_NEQ(RecoveryReasonString(i), NULL, "Non-null reason"); /* HWID should come from the gbb */ ResetMocks(); VbGbbReadHWID(&ctx, hwid, sizeof(hwid)); TEST_EQ(strcmp(hwid, "Test HWID"), 0, "HWID"); ResetMocks(); sd->gbb_size = 0; VbGbbReadHWID(&ctx, hwid, sizeof(hwid)); TEST_EQ(strcmp(hwid, "{INVALID}"), 0, "HWID bad gbb"); ResetMocks(); sd->gbb->hwid_size = 0; VbGbbReadHWID(&ctx, hwid, sizeof(hwid)); TEST_EQ(strcmp(hwid, "{INVALID}"), 0, "HWID missing"); ResetMocks(); sd->gbb->hwid_offset = sd->gbb_size + 1; VbGbbReadHWID(&ctx, hwid, sizeof(hwid)); TEST_EQ(strcmp(hwid, "{INVALID}"), 0, "HWID past end"); ResetMocks(); sd->gbb->hwid_size = sd->gbb_size; VbGbbReadHWID(&ctx, hwid, sizeof(hwid)); TEST_EQ(strcmp(hwid, "{INVALID}"), 0, "HWID overflow"); /* Display debug info */ ResetMocks(); VbDisplayDebugInfo(&ctx); TEST_NEQ(*debug_info, '\0', "Some debug info was displayed"); }
static void VbSoftwareSyncTest(void) { /* Recovery cases */ ResetMocks(); shared->recovery_reason = 123; test_ssync(0, 0, "In recovery, EC-RO"); TEST_EQ(ec_rw_protected, 0, " ec rw protected"); ResetMocks(); shared->recovery_reason = 123; mock_in_rw = 1; test_ssync(VBERROR_EC_REBOOT_TO_RO_REQUIRED, 123, "Recovery needs EC-RO"); /* AP-RO cases */ ResetMocks(); in_rw_retval = VBERROR_SIMULATED; test_ssync(VBERROR_EC_REBOOT_TO_RO_REQUIRED, VBNV_RECOVERY_EC_UNKNOWN_IMAGE, "Unknown EC image"); ResetMocks(); shared->flags |= VBSD_LF_USE_RO_NORMAL; mock_in_rw = 1; test_ssync(VBERROR_EC_REBOOT_TO_RO_REQUIRED, 0, "AP-RO needs EC-RO"); ResetMocks(); shared->flags |= VBSD_LF_USE_RO_NORMAL; test_ssync(0, 0, "AP-RO, EC-RO"); TEST_EQ(ec_rw_protected, 1, " ec rw protected"); TEST_EQ(ec_run_image, 0, " ec run image"); ResetMocks(); shared->flags |= VBSD_LF_USE_RO_NORMAL; run_retval = VBERROR_SIMULATED; test_ssync(VBERROR_EC_REBOOT_TO_RO_REQUIRED, VBNV_RECOVERY_EC_SOFTWARE_SYNC, "Stay in RO fail"); ResetMocks(); shared->flags |= VBSD_LF_USE_RO_NORMAL; protect_retval = VBERROR_SIMULATED; test_ssync(VBERROR_SIMULATED, VBNV_RECOVERY_EC_PROTECT, "Protect error"); /* No longer check for shutdown requested */ ResetMocks(); shared->flags |= VBSD_LF_USE_RO_NORMAL; shutdown_request_calls_left = 0; test_ssync(0, 0, "AP-RO shutdown requested"); /* Calculate hashes */ ResetMocks(); mock_ec_rw_hash_size = 0; test_ssync(VBERROR_EC_REBOOT_TO_RO_REQUIRED, VBNV_RECOVERY_EC_HASH_FAILED, "Bad EC hash"); ResetMocks(); mock_ec_rw_hash_size = 16; test_ssync(VBERROR_EC_REBOOT_TO_RO_REQUIRED, VBNV_RECOVERY_EC_HASH_SIZE, "Bad EC hash size"); ResetMocks(); want_ec_hash_size = 0; test_ssync(VBERROR_EC_REBOOT_TO_RO_REQUIRED, VBNV_RECOVERY_EC_EXPECTED_HASH, "Bad precalculated hash"); ResetMocks(); want_ec_hash_size = 16; test_ssync(VBERROR_EC_REBOOT_TO_RO_REQUIRED, VBNV_RECOVERY_EC_EXPECTED_HASH, "Bad precalculated hash size"); ResetMocks(); mock_in_rw = 1; want_ec_hash_size = -1; test_ssync(0, 0, "No precomputed hash"); ResetMocks(); want_ec_hash_size = -1; get_expected_retval = VBERROR_SIMULATED; test_ssync(VBERROR_EC_REBOOT_TO_RO_REQUIRED, VBNV_RECOVERY_EC_EXPECTED_IMAGE, "Can't fetch image"); /* Updates required */ ResetMocks(); mock_in_rw = 1; want_ec_hash[0]++; test_ssync(VBERROR_EC_REBOOT_TO_RO_REQUIRED, VBNV_RECOVERY_EC_HASH_MISMATCH, "Precalculated hash mismatch"); ResetMocks(); mock_in_rw = 1; mock_ec_rw_hash[0]++; test_ssync(VBERROR_EC_REBOOT_TO_RO_REQUIRED, 0, "Pending update needs reboot"); ResetMocks(); mock_ec_rw_hash[0]++; VbNvSet(VbApiKernelGetVnc(), VBNV_TRY_RO_SYNC, 1); test_ssync(0, 0, "Update rw without reboot"); TEST_EQ(ec_rw_protected, 1, " ec rw protected"); TEST_EQ(ec_run_image, 1, " ec run image"); TEST_EQ(ec_rw_updated, 1, " ec rw updated"); TEST_EQ(ec_ro_protected, 1, " ec ro protected"); TEST_EQ(ec_ro_updated, 0, " ec ro updated"); ResetMocks(); mock_ec_rw_hash[0]++; mock_ec_ro_hash[0]++; VbNvSet(VbApiKernelGetVnc(), VBNV_TRY_RO_SYNC, 1); test_ssync(0, 0, "Update rw and ro images without reboot"); TEST_EQ(ec_rw_protected, 1, " ec rw protected"); TEST_EQ(ec_run_image, 1, " ec run image"); TEST_EQ(ec_rw_updated, 1, " ec rw updated"); TEST_EQ(ec_ro_protected, 1, " ec ro protected"); TEST_EQ(ec_ro_updated, 1, " ec ro updated"); ResetMocks(); shared->flags |= VBSD_BOOT_FIRMWARE_WP_ENABLED; VbNvSet(VbApiKernelGetVnc(), VBNV_TRY_RO_SYNC, 1); mock_ec_rw_hash[0]++; mock_ec_ro_hash[0]++; test_ssync(0, 0, "WP enabled"); TEST_EQ(ec_rw_protected, 1, " ec rw protected"); TEST_EQ(ec_run_image, 1, " ec run image"); TEST_EQ(ec_rw_updated, 1, " ec rw updated"); TEST_EQ(ec_ro_protected, 1, " ec ro protected"); TEST_EQ(ec_ro_updated, 0, " ec ro updated"); ResetMocks(); VbNvSet(VbApiKernelGetVnc(), VBNV_TRY_RO_SYNC, 1); mock_ec_ro_hash[0]++; test_ssync(0, 0, "rw update not needed"); TEST_EQ(ec_rw_protected, 1, " ec rw protected"); TEST_EQ(ec_run_image, 1, " ec run image"); TEST_EQ(ec_rw_updated, 0, " ec rw not updated"); TEST_EQ(ec_ro_protected, 1, " ec ro protected"); TEST_EQ(ec_ro_updated, 1, " ec ro updated"); ResetMocks(); mock_ec_rw_hash[0]++; mock_ec_ro_hash[0]++; test_ssync(0, 0, "ro update not requested"); TEST_EQ(ec_rw_protected, 1, " ec rw protected"); TEST_EQ(ec_run_image, 1, " ec run image"); TEST_EQ(ec_rw_updated, 1, " ec rw updated"); TEST_EQ(ec_ro_protected, 1, " ec ro protected"); TEST_EQ(ec_ro_updated, 0, " ec ro updated"); ResetMocks(); mock_ec_rw_hash[0]++; update_hash++; test_ssync(VBERROR_EC_REBOOT_TO_RO_REQUIRED, VBNV_RECOVERY_EC_UPDATE, "updated hash mismatch"); TEST_EQ(ec_rw_protected, 0, " ec rw protected"); TEST_EQ(ec_run_image, 0, " ec run image"); TEST_EQ(ec_rw_updated, 1, " ec rw updated"); TEST_EQ(ec_ro_protected, 0, " ec ro protected"); TEST_EQ(ec_ro_updated, 0, " ec ro updated"); ResetMocks(); mock_ec_rw_hash[0]++; update_retval = VBERROR_EC_REBOOT_TO_RO_REQUIRED; test_ssync(VBERROR_EC_REBOOT_TO_RO_REQUIRED, 0, "Reboot after rw update"); TEST_EQ(ec_rw_updated, 1, " ec rw updated"); TEST_EQ(ec_ro_updated, 0, " ec rw updated"); ResetMocks(); mock_ec_rw_hash[0]++; update_retval = VBERROR_SIMULATED; test_ssync(VBERROR_EC_REBOOT_TO_RO_REQUIRED, VBNV_RECOVERY_EC_UPDATE, "Update failed"); ResetMocks(); mock_ec_rw_hash[0]++; shared->flags |= VBSD_EC_SLOW_UPDATE; test_ssync(0, 0, "Slow update"); TEST_EQ(screens_displayed[0], VB_SCREEN_WAIT, " wait screen"); /* RW cases, no update */ ResetMocks(); mock_in_rw = 1; test_ssync(0, 0, "AP-RW, EC-RW"); ResetMocks(); test_ssync(0, 0, "AP-RW, EC-RO -> EC-RW"); TEST_EQ(ec_rw_protected, 1, " ec rw protected"); TEST_EQ(ec_run_image, 1, " ec run image"); TEST_EQ(ec_rw_updated, 0, " ec rw updated"); TEST_EQ(ec_ro_protected, 1, " ec ro protected"); TEST_EQ(ec_ro_updated, 0, " ec ro updated"); ResetMocks(); run_retval = VBERROR_SIMULATED; test_ssync(VBERROR_EC_REBOOT_TO_RO_REQUIRED, VBNV_RECOVERY_EC_JUMP_RW, "Jump to RW fail"); ResetMocks(); run_retval = VBERROR_EC_REBOOT_TO_RO_REQUIRED; test_ssync(VBERROR_EC_REBOOT_TO_RO_REQUIRED, 0, "Jump to RW fail because locked"); ResetMocks(); protect_retval = VBERROR_SIMULATED; test_ssync(VBERROR_SIMULATED, VBNV_RECOVERY_EC_PROTECT, "Protect error"); /* No longer check for shutdown requested */ ResetMocks(); shutdown_request_calls_left = 0; test_ssync(0, 0, "AP-RW, EC-RO -> EC-RW shutdown requested"); ResetMocks(); mock_in_rw = 1; shutdown_request_calls_left = 0; test_ssync(0, 0, "AP-RW shutdown requested"); }
static void VbLockDeviceTest(void) { ResetMocks(); TEST_EQ(VbLockDevice(), 0, "lock success"); }
/** * Test send-command functions */ static void SendCommandTest(void) { ResetMocks(); TEST_EQ(TlclStartup(), 0, "SaveState"); TEST_EQ(calls[0].req_cmd, TPM_ORD_Startup, " cmd"); ResetMocks(); TEST_EQ(TlclSaveState(), 0, "SaveState"); TEST_EQ(calls[0].req_cmd, TPM_ORD_SaveState, " cmd"); ResetMocks(); TEST_EQ(TlclResume(), 0, "Resume"); TEST_EQ(calls[0].req_cmd, TPM_ORD_Startup, " cmd"); ResetMocks(); TEST_EQ(TlclSelfTestFull(), 0, "SelfTestFull"); TEST_EQ(calls[0].req_cmd, TPM_ORD_SelfTestFull, " cmd"); ResetMocks(); TEST_EQ(TlclContinueSelfTest(), 0, "ContinueSelfTest"); TEST_EQ(calls[0].req_cmd, TPM_ORD_ContinueSelfTest, " cmd"); ResetMocks(); TEST_EQ(TlclAssertPhysicalPresence(), 0, "AssertPhysicalPresence"); TEST_EQ(calls[0].req_cmd, TSC_ORD_PhysicalPresence, " cmd"); ResetMocks(); TEST_EQ(TlclPhysicalPresenceCMDEnable(), 0, "PhysicalPresenceCMDEnable"); TEST_EQ(calls[0].req_cmd, TSC_ORD_PhysicalPresence, " cmd"); ResetMocks(); TEST_EQ(TlclFinalizePhysicalPresence(), 0, "FinalizePhysicalPresence"); TEST_EQ(calls[0].req_cmd, TSC_ORD_PhysicalPresence, " cmd"); ResetMocks(); TEST_EQ(TlclAssertPhysicalPresenceResult(), 0, "AssertPhysicalPresenceResult"); TEST_EQ(calls[0].req_cmd, TSC_ORD_PhysicalPresence, " cmd"); ResetMocks(); TEST_EQ(TlclLockPhysicalPresence(), 0, "LockPhysicalPresence"); TEST_EQ(calls[0].req_cmd, TSC_ORD_PhysicalPresence, " cmd"); ResetMocks(); TEST_EQ(TlclIsOwned(), 0, "IsOwned"); TEST_EQ(calls[0].req_cmd, TPM_ORD_ReadPubek, " cmd"); ResetMocks(); calls[0].retval = VBERROR_SIMULATED; TEST_NEQ(TlclIsOwned(), 0, "IsOwned"); ResetMocks(); TEST_EQ(TlclForceClear(), 0, "ForceClear"); TEST_EQ(calls[0].req_cmd, TPM_ORD_ForceClear, " cmd"); ResetMocks(); TEST_EQ(TlclSetEnable(), 0, "SetEnable"); TEST_EQ(calls[0].req_cmd, TPM_ORD_PhysicalEnable, " cmd"); ResetMocks(); TEST_EQ(TlclClearEnable(), 0, "ClearEnable"); TEST_EQ(calls[0].req_cmd, TPM_ORD_PhysicalDisable, " cmd"); ResetMocks(); TEST_EQ(TlclSetDeactivated(0), 0, "SetDeactivated"); TEST_EQ(calls[0].req_cmd, TPM_ORD_PhysicalSetDeactivated, " cmd"); }