Software APIs
epmp_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/drivers/epmp.h"
6 
7 #include "gtest/gtest.h"
8 #include "sw/device/silicon_creator/testing/rom_test.h"
9 
10 namespace epmp_unittest {
11 namespace {
12 
13 struct NapotCase {
14  /**
15  * Start / end of the NAPOT region.
16  */
17  uint32_t start;
18  uint32_t end;
19  /**
20  * Encoded NAPOT address.
21  */
22  uint32_t encoded;
23 };
24 
26  public testing::WithParamInterface<NapotCase> {};
27 
28 TEST_P(NapotTest, Codec) {
29  epmp_region_t region = {
30  .start = (uintptr_t)GetParam().start,
31  .end = (uintptr_t)GetParam().end,
32  };
33  EXPECT_EQ(epmp_encode_napot(region), GetParam().encoded);
34 
35  epmp_region_t decoded = epmp_decode_napot(GetParam().encoded);
36  EXPECT_EQ(decoded.start, GetParam().start);
37  EXPECT_EQ(decoded.end, GetParam().end);
38 }
39 
40 INSTANTIATE_TEST_SUITE_P(AllCases, NapotTest,
41  testing::Values(
42  NapotCase{
43  .start = 0b1000010100100100101010100000,
44  .end = 0b1000010100100100101011000000,
45  .encoded = 0b10000101001001001010101011,
46  },
47  NapotCase{
48  .start = 0b101000001101000011100000000000,
49  .end = 0b101000001101000011100100000000,
50  .encoded = 0b1010000011010000111000011111,
51  },
52  NapotCase{
53  .start = 0b10111111111111111111111111111000,
54  .end = 0b11000000000000000000000000000000,
55  .encoded = 0b101111111111111111111111111110,
56  },
57  NapotCase{
58  .start = 0b00000000000000000000000000000000,
59  .end = 0b10000000000000000000000000000000,
60  .encoded = 0b001111111111111111111111111111,
61  }));
62 
63 } // namespace
64 } // namespace epmp_unittest