Skip to content

Commit 36e8bf1

Browse files
ShadowBearVRtimothytrippel
authored andcommitted
[rom_ext] Expand unit tests
Adds additional equality checks, formats all unit tests, and ensures similar checks are present in all 7 boot service handler related unit tests. Signed-off-by: Collin MacDonald <[email protected]>
1 parent 116c226 commit 36e8bf1

File tree

1 file changed

+48
-38
lines changed

1 file changed

+48
-38
lines changed

sw/device/silicon_creator/rom_ext/rom_ext_boot_services_unittest.cc

Lines changed: 48 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55
#include "sw/device/silicon_creator/rom_ext/rom_ext_boot_services.h"
66

77
#include "gtest/gtest.h"
8+
#include "sw/device/silicon_creator/lib/boot_svc/mock_boot_svc_header.h"
9+
#include "sw/device/silicon_creator/lib/drivers/mock_flash_ctrl.h"
810
#include "sw/device/silicon_creator/lib/drivers/mock_hmac.h"
911
#include "sw/device/silicon_creator/lib/drivers/mock_lifecycle.h"
1012
#include "sw/device/silicon_creator/lib/drivers/mock_otp.h"
1113
#include "sw/device/silicon_creator/lib/drivers/mock_rnd.h"
1214
#include "sw/device/silicon_creator/lib/mock_boot_data.h"
1315
#include "sw/device/silicon_creator/lib/mock_manifest.h"
14-
#include "sw/device/silicon_creator/lib/drivers/mock_flash_ctrl.h"
16+
#include "sw/device/silicon_creator/lib/ownership/datatypes.h"
1517
#include "sw/device/silicon_creator/lib/ownership/mock_owner_verify.h"
1618
#include "sw/device/silicon_creator/lib/ownership/mock_ownership_key.h"
17-
#include "sw/device/silicon_creator/lib/ownership/datatypes.h"
18-
#include "sw/device/silicon_creator/lib/ownership/ownership_activate.h"
1919
#include "sw/device/silicon_creator/lib/ownership/owner_block.h"
20+
#include "sw/device/silicon_creator/lib/ownership/ownership_activate.h"
2021
#include "sw/device/silicon_creator/rom_ext/mock_rom_ext_boot_policy_ptrs.h"
21-
#include "sw/device/silicon_creator/lib/boot_svc/mock_boot_svc_header.h"
2222
#include "sw/device/silicon_creator/testing/rom_test.h"
2323

2424
namespace boot_services_unittest {
@@ -102,7 +102,7 @@ class RomExtBootServicesTest : public rom_test::RomTest {
102102
TEST_F(RomExtBootServicesTest, BootSvcDefault) {
103103
EXPECT_EQ(
104104
boot_svc_handler(&boot_svc_msg, &boot_data, &boot_log, lc_state, &keyring,
105-
&verify_key, &owner_config, &isfb_check_count),
105+
&verify_key, &owner_config, &isfb_check_count),
106106
kErrorOk);
107107

108108
EXPECT_EQ(boot_svc_msg.header.type, 0);
@@ -122,7 +122,7 @@ TEST_F(RomExtBootServicesTest, BootSvcEmpty) {
122122

123123
EXPECT_EQ(
124124
boot_svc_handler(&boot_svc_msg, &boot_data, &boot_log, lc_state, &keyring,
125-
&verify_key, &owner_config, &isfb_check_count),
125+
&verify_key, &owner_config, &isfb_check_count),
126126
kErrorOk);
127127

128128
EXPECT_EQ(boot_svc_msg.empty.header.identifier, kBootSvcIdentifier);
@@ -136,7 +136,7 @@ TEST_F(RomExtBootServicesTest, BootSvcEnterRescue) {
136136
boot_svc_msg.header.type = kBootSvcEnterRescueReqType;
137137
boot_svc_msg.header.length = sizeof(boot_svc_enter_rescue_req_t);
138138
boot_svc_msg.header.digest = hmac_digest_t{0x1234};
139-
139+
140140
EXPECT_CALL(mock_hmac_, sha256)
141141
.WillOnce(SetArgPointee<2>(hmac_digest_t{0x1234}));
142142

@@ -145,9 +145,14 @@ TEST_F(RomExtBootServicesTest, BootSvcEnterRescue) {
145145

146146
EXPECT_EQ(
147147
boot_svc_handler(&boot_svc_msg, &boot_data, &boot_log, lc_state, &keyring,
148-
&verify_key, &owner_config, &isfb_check_count),
148+
&verify_key, &owner_config, &isfb_check_count),
149149
kErrorOk);
150150

151+
EXPECT_EQ(boot_svc_msg.enter_rescue_res.header.identifier,
152+
kBootSvcIdentifier);
153+
EXPECT_EQ(boot_svc_msg.enter_rescue_res.header.type,
154+
kBootSvcEnterRescueResType);
155+
151156
EXPECT_EQ(boot_svc_msg.enter_rescue_res.status, kErrorOk);
152157
}
153158

@@ -175,7 +180,7 @@ TEST_F(RomExtBootServicesTest, BootSvcNextBl0Slot) {
175180

176181
EXPECT_EQ(
177182
boot_svc_handler(&boot_svc_msg, &boot_data, &boot_log, lc_state, &keyring,
178-
&verify_key, &owner_config, &isfb_check_count),
183+
&verify_key, &owner_config, &isfb_check_count),
179184
kErrorOk);
180185

181186
EXPECT_EQ(boot_svc_msg.next_boot_bl0_slot_res.header.identifier,
@@ -288,7 +293,7 @@ TEST_F(RomExtBootServicesTest, BootSvcMinBl0SecVer) {
288293

289294
EXPECT_EQ(
290295
boot_svc_handler(&boot_svc_msg, &boot_data, &boot_log, lc_state, &keyring,
291-
&verify_key, &owner_config, &isfb_check_count),
296+
&verify_key, &owner_config, &isfb_check_count),
292297
kErrorOk);
293298

294299
EXPECT_EQ(boot_svc_msg.min_bl0_sec_ver_res.header.identifier,
@@ -306,14 +311,13 @@ TEST_F(RomExtBootServicesTest, BootSvcOwnershipUnlock) {
306311
boot_svc_msg.header.length = sizeof(boot_svc_ownership_unlock_req_t);
307312

308313
boot_svc_msg.ownership_unlock_req.unlock_mode = kBootSvcUnlockAbort;
309-
314+
310315
boot_data.ownership_state = kOwnershipStateUnlockedAny;
311316
boot_data.nonce = {0x55555555, 0xAAAAAAAA};
312317
boot_svc_msg.ownership_unlock_req.nonce = boot_data.nonce;
313318
boot_svc_msg.ownership_unlock_req.signature = {{100, 101, 102, 103, 104, 105,
314-
106, 107, 108, 109, 110, 111, 112, 113,
315-
114, 115}};
316-
319+
106, 107, 108, 109, 110, 111,
320+
112, 113, 114, 115}};
317321

318322
EXPECT_CALL(mock_hmac_, sha256)
319323
.WillOnce(SetArgPointee<2>(hmac_digest_t{0x1234}));
@@ -332,9 +336,14 @@ TEST_F(RomExtBootServicesTest, BootSvcOwnershipUnlock) {
332336

333337
EXPECT_EQ(
334338
boot_svc_handler(&boot_svc_msg, &boot_data, &boot_log, lc_state, &keyring,
335-
&verify_key, &owner_config, &isfb_check_count),
339+
&verify_key, &owner_config, &isfb_check_count),
336340
kErrorWriteBootdataThenReboot);
337341

342+
EXPECT_EQ(boot_svc_msg.ownership_unlock_res.header.identifier,
343+
kBootSvcIdentifier);
344+
EXPECT_EQ(boot_svc_msg.ownership_unlock_res.header.type,
345+
kBootSvcOwnershipUnlockResType);
346+
338347
EXPECT_EQ(boot_svc_msg.ownership_unlock_res.status, kErrorOk);
339348
}
340349

@@ -347,10 +356,9 @@ TEST_F(RomExtBootServicesTest, BootSvcOwnershipActivate) {
347356
boot_svc_msg.ownership_activate_req.erase_previous = 1;
348357
boot_svc_msg.ownership_activate_req.primary_bl0_slot = 0;
349358
boot_svc_msg.ownership_activate_req.nonce = {0x55555555, 0xAAAAAAAA};
350-
boot_svc_msg.ownership_activate_req.signature = {{100, 101, 102, 103, 104, 105, 106,
351-
107, 108, 109, 110, 111, 112, 113,
352-
114, 115}};
353-
359+
boot_svc_msg.ownership_activate_req.signature = {
360+
{100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113,
361+
114, 115}};
354362

355363
boot_data.ownership_state = kOwnershipStateUnlockedEndorsed;
356364
boot_data.nonce = {0x55555555, 0xAAAAAAAA};
@@ -371,33 +379,36 @@ TEST_F(RomExtBootServicesTest, BootSvcOwnershipActivate) {
371379
validate(1, kOwnershipKeyActivate, kActivate, _, _, _, _))
372380
.WillOnce(Return(kErrorOk));
373381

374-
EXPECT_CALL(mock_lifecycle_, DeviceId(_))
382+
EXPECT_CALL(mock_lifecycle_, DeviceId(_))
375383
.WillOnce(SetArgPointee<0>((lifecycle_device_id_t){0}));
376384

377-
// Once the new owner page is determined to be valid, the page will be sealed.
385+
// Once the new owner page is determined to be valid, the page will be sealed.
378386
EXPECT_CALL(mock_ownership_key_, seal_page(1));
379387

380-
// The sealed page will be written into flash owner slot 1 first.
388+
// The sealed page will be written into flash owner slot 1 first.
381389
EXPECT_CALL(mock_flash_ctrl_,
382390
InfoErase(&kFlashCtrlInfoPageOwnerSlot1, kFlashCtrlEraseTypePage))
383391
.WillOnce(Return(kErrorOk));
384392

385-
EXPECT_CALL(mock_flash_ctrl_, InfoWrite(&kFlashCtrlInfoPageOwnerSlot1, 0,
386-
sizeof(owner_page[1]) / sizeof(uint32_t),
387-
&owner_page[1]))
393+
EXPECT_CALL(
394+
mock_flash_ctrl_,
395+
InfoWrite(&kFlashCtrlInfoPageOwnerSlot1, 0,
396+
sizeof(owner_page[1]) / sizeof(uint32_t), &owner_page[1]))
388397
.WillOnce(Return(kErrorOk));
389398

390-
EXPECT_CALL(mock_flash_ctrl_,
399+
EXPECT_CALL(mock_flash_ctrl_,
391400
InfoErase(&kFlashCtrlInfoPageOwnerSlot0, kFlashCtrlEraseTypePage))
392401
.WillOnce(Return(kErrorOk));
393402

394-
EXPECT_CALL(mock_flash_ctrl_, InfoWrite(&kFlashCtrlInfoPageOwnerSlot0, 0,
395-
sizeof(owner_page[1]) / sizeof(uint32_t),
396-
&owner_page[1]))
403+
EXPECT_CALL(
404+
mock_flash_ctrl_,
405+
InfoWrite(&kFlashCtrlInfoPageOwnerSlot0, 0,
406+
sizeof(owner_page[1]) / sizeof(uint32_t), &owner_page[1]))
397407
.WillOnce(Return(kErrorOk));
398408

399-
if (boot_data.ownership_state != kOwnershipStateUnlockedSelf) {
400-
EXPECT_CALL(mock_ownership_key_, secret_new(_, _)).WillOnce(Return(kErrorOk));
409+
if (boot_data.ownership_state != kOwnershipStateUnlockedSelf) {
410+
EXPECT_CALL(mock_ownership_key_, secret_new(_, _))
411+
.WillOnce(Return(kErrorOk));
401412
}
402413

403414
EXPECT_CALL(mock_rnd_, Uint32()).WillRepeatedly(Return(99));
@@ -407,17 +418,16 @@ TEST_F(RomExtBootServicesTest, BootSvcOwnershipActivate) {
407418

408419
EXPECT_EQ(
409420
boot_svc_handler(&boot_svc_msg, &boot_data, &boot_log, lc_state, &keyring,
410-
&verify_key, &owner_config, &isfb_check_count),
421+
&verify_key, &owner_config, &isfb_check_count),
411422
kErrorWriteBootdataThenReboot);
412423

413-
EXPECT_EQ(boot_svc_msg.ownership_activate_res.status, kErrorOk);
424+
EXPECT_EQ(boot_svc_msg.ownership_activate_res.header.identifier,
425+
kBootSvcIdentifier);
426+
EXPECT_EQ(boot_svc_msg.ownership_activate_res.header.type,
427+
kBootSvcOwnershipActivateResType);
414428

429+
EXPECT_EQ(boot_svc_msg.ownership_activate_res.status, kErrorOk);
415430
}
416431

417432
} // namespace
418433
} // namespace boot_services_unittest
419-
420-
/*
421-
422-
423-
*/

0 commit comments

Comments
 (0)