Software APIs
boot_svc_ownership_activate_unittest.cc
1 // Copyright lowRISC contributors (OpenTitan project).
2 // Licensed under the Apache License, Version 2.0, see LICENSE for details.
3 // SPDX-License-Identifier: Apache-2.0
4 
5 #include "sw/device/silicon_creator/lib/boot_svc/boot_svc_ownership_activate.h"
6 
7 #include <string.h>
8 
9 #include "gtest/gtest.h"
10 #include "sw/device/silicon_creator/lib/boot_svc/mock_boot_svc_header.h"
11 #include "sw/device/silicon_creator/testing/rom_test.h"
12 
13 namespace boot_svc_ownership_activate_unittest {
14 namespace {
15 using ::testing::ElementsAreArray;
16 
18  protected:
19  rom_test::MockBootSvcHeader boot_svc_header_;
20 };
21 
22 TEST_F(BootSvcOwnershipActivateTest, ReqInit) {
24  constexpr uint32_t primary_bl0_slot = 0;
25  constexpr uint32_t erase_previous = 1;
26  constexpr nonce_t nonce = {0x55555555, 0xAAAAAAAA};
27  constexpr owner_signature_t signature = {{100, 101, 102, 103, 104, 105, 106,
28  107, 108, 109, 110, 111, 112, 113,
29  114, 115}};
30  EXPECT_CALL(boot_svc_header_, Finalize(kBootSvcOwnershipActivateReqType,
31  sizeof(msg), &msg.header));
32 
33  boot_svc_ownership_activate_req_init(primary_bl0_slot, erase_previous, nonce,
34  &signature, &msg);
35 
36  EXPECT_EQ(msg.primary_bl0_slot, primary_bl0_slot);
37  EXPECT_EQ(msg.erase_previous, erase_previous);
38  EXPECT_EQ(msg.nonce.value[0], nonce.value[0]);
39  EXPECT_EQ(msg.nonce.value[1], nonce.value[1]);
40  EXPECT_EQ(memcmp(&msg.signature, &signature, sizeof(signature)), 0);
41 }
42 
43 TEST_F(BootSvcOwnershipActivateTest, ResInit) {
45  constexpr rom_error_t kStatus = kErrorOk;
46  EXPECT_CALL(boot_svc_header_, Finalize(kBootSvcOwnershipActivateResType,
47  sizeof(msg), &msg.header));
48 
49  boot_svc_ownership_activate_res_init(kStatus, &msg);
50 
51  EXPECT_EQ(msg.status, kStatus);
52 }
53 
54 } // namespace
55 } // namespace boot_svc_ownership_activate_unittest