88
99#include " gtest/gtest.h"
1010#include " sw/device/lib/base/mock_abs_mmio.h"
11+ #include " sw/device/silicon_creator/lib/base/mock_csr.h"
1112#include " sw/device/silicon_creator/lib/base/mock_sec_mmio.h"
1213#include " sw/device/silicon_creator/testing/rom_test.h"
1314
1415#include " hw/top/rv_core_ibex_regs.h"
1516#include " hw/top_earlgrey/sw/autogen/top_earlgrey.h"
1617
18+ namespace rom_test {
19+ /* This is somewhat of a hack: ibex_time_to_cycles is really just
20+ * an alias for to_cpu_cycles so there is no point in testing it or
21+ * creating a mock just for this. But we need the symbol for the
22+ * linker to be happy.
23+ */
24+ extern " C" uint64_t to_cpu_cycles (uint64_t usec) { abort (); }
25+ } // namespace rom_test
26+
1727namespace ibex_unittest {
1828namespace {
1929
@@ -22,8 +32,47 @@ class IbexTest : public rom_test::RomTest {
2232 uint32_t base_ = TOP_EARLGREY_RV_CORE_IBEX_CFG_BASE_ADDR;
2333 rom_test::MockSecMmio sec_;
2434 rom_test::MockAbsMmio mmio_;
35+ mock_csr::MockCsr csr_;
2536};
2637
38+ class MCycleTest : public IbexTest {};
39+
40+ TEST_F (MCycleTest, MCycle32) {
41+ EXPECT_CSR_READ (CSR_REG_MCYCLE, 978465 );
42+ EXPECT_EQ (ibex_mcycle32 (), 978465 );
43+ }
44+
45+ TEST_F (MCycleTest, MCycleSimple) {
46+ // Simple case where the two reads of MCYCLEH are consistent.
47+ EXPECT_CSR_READ (CSR_REG_MCYCLEH, 0x42 );
48+ EXPECT_CSR_READ (CSR_REG_MCYCLE, 0xabcdef01 );
49+ EXPECT_CSR_READ (CSR_REG_MCYCLEH, 0x42 );
50+ EXPECT_EQ (ibex_mcycle (), 0x42abcdef01 );
51+ }
52+
53+ TEST_F (MCycleTest, MCycleComplex) {
54+ // Complex case where the two reads of MCYCLEH are different.
55+ EXPECT_CSR_READ (CSR_REG_MCYCLEH, 0x42 );
56+ EXPECT_CSR_READ (CSR_REG_MCYCLE, 0xabcdef01 );
57+ EXPECT_CSR_READ (CSR_REG_MCYCLEH, 0x43 );
58+ EXPECT_CSR_READ (CSR_REG_MCYCLEH, 0x44 );
59+ EXPECT_CSR_READ (CSR_REG_MCYCLE, 0x01234567 );
60+ EXPECT_CSR_READ (CSR_REG_MCYCLEH, 0x44 );
61+ EXPECT_EQ (ibex_mcycle (), 0x4401234567 );
62+ }
63+
64+ class RndTest : public IbexTest {};
65+
66+ TEST_F (RndTest, Rnd32) {
67+ EXPECT_ABS_READ32 (base_ + RV_CORE_IBEX_RND_STATUS_REG_OFFSET,
68+ {{RV_CORE_IBEX_RND_STATUS_RND_DATA_VALID_BIT, false }});
69+ EXPECT_ABS_READ32 (base_ + RV_CORE_IBEX_RND_STATUS_REG_OFFSET,
70+ {{RV_CORE_IBEX_RND_STATUS_RND_DATA_VALID_BIT, true }});
71+ EXPECT_ABS_READ32 (base_ + RV_CORE_IBEX_RND_DATA_REG_OFFSET, 12345 );
72+
73+ EXPECT_EQ (ibex_rnd32_read (), 12345 );
74+ }
75+
2776class AddressTranslationTest : public IbexTest {};
2877
2978TEST_F (AddressTranslationTest, Slot0Sucess) {
0 commit comments