Skip to content

Commit

Permalink
[rv_plic,dif,unittest] Add some type casts
Browse files Browse the repository at this point in the history
The DT commit changed the type `dif_rv_plic_irq_id_t` from `uint32_t`
to an enumeration. This makes certain implicit casts in the C++ code
invalid now.

Signed-off-by: Amaury Pouly <[email protected]>
  • Loading branch information
pamaury committed Sep 3, 2024
1 parent 50e18c7 commit b95a519
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions sw/device/lib/dif/dif_rv_plic_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,17 @@ constexpr std::array<IrqTest::Register, RV_PLIC_IP_MULTIREG_COUNT>
class IrqEnableSetTest : public IrqTest {};

TEST_F(IrqEnableSetTest, NullArgs) {
EXPECT_DIF_BADARG(dif_rv_plic_irq_set_enabled(nullptr, kFirstIrq, kTarget0,
kDifToggleEnabled));
EXPECT_DIF_BADARG(dif_rv_plic_irq_set_enabled(
nullptr, (dif_rv_plic_irq_id_t)kFirstIrq, kTarget0, kDifToggleEnabled));
}

TEST_F(IrqEnableSetTest, Target0Enable) {
ExpectIrqSetTests(kEnableRegisters, true);

// Enable every IRQ, one at a time.
for (int i = 0; i < RV_PLIC_PARAM_NUM_SRC; ++i) {
EXPECT_DIF_OK(
dif_rv_plic_irq_set_enabled(&plic_, i, kTarget0, kDifToggleEnabled));
EXPECT_DIF_OK(dif_rv_plic_irq_set_enabled(&plic_, (dif_rv_plic_irq_id_t)i,
kTarget0, kDifToggleEnabled));
}
}

Expand All @@ -165,21 +165,21 @@ TEST_F(IrqEnableSetTest, Target0Disable) {

// Disable every bit, one at a time.
for (int i = 0; i < RV_PLIC_PARAM_NUM_SRC; ++i) {
EXPECT_DIF_OK(
dif_rv_plic_irq_set_enabled(&plic_, i, kTarget0, kDifToggleDisabled));
EXPECT_DIF_OK(dif_rv_plic_irq_set_enabled(&plic_, (dif_rv_plic_irq_id_t)i,
kTarget0, kDifToggleDisabled));
}
}

class IrqPrioritySetTest : public PlicTest {};

TEST_F(IrqPrioritySetTest, NullArgs) {
EXPECT_DIF_BADARG(
dif_rv_plic_irq_set_priority(nullptr, kFirstIrq, kDifRvPlicMaxPriority));
EXPECT_DIF_BADARG(dif_rv_plic_irq_set_priority(
nullptr, (dif_rv_plic_irq_id_t)kFirstIrq, kDifRvPlicMaxPriority));
}

TEST_F(IrqPrioritySetTest, PriorityInvalid) {
EXPECT_DIF_BADARG(dif_rv_plic_irq_set_priority(nullptr, kFirstIrq,
kDifRvPlicMaxPriority + 1));
EXPECT_DIF_BADARG(dif_rv_plic_irq_set_priority(
nullptr, (dif_rv_plic_irq_id_t)kFirstIrq, kDifRvPlicMaxPriority + 1));
}

TEST_F(IrqPrioritySetTest, Success) {
Expand All @@ -188,8 +188,8 @@ TEST_F(IrqPrioritySetTest, Success) {
ptrdiff_t offset = RV_PLIC_PRIO0_REG_OFFSET + (sizeof(uint32_t) * i);
EXPECT_WRITE32(offset, kDifRvPlicMaxPriority);

EXPECT_DIF_OK(
dif_rv_plic_irq_set_priority(&plic_, i, kDifRvPlicMaxPriority));
EXPECT_DIF_OK(dif_rv_plic_irq_set_priority(&plic_, (dif_rv_plic_irq_id_t)i,
kDifRvPlicMaxPriority));
}
}

Expand All @@ -216,13 +216,16 @@ class IrqPendingStatusGetTest : public IrqTest {};

TEST_F(IrqPendingStatusGetTest, NullArgs) {
bool status;
dif_result_t result = dif_rv_plic_irq_is_pending(nullptr, kFirstIrq, &status);
dif_result_t result = dif_rv_plic_irq_is_pending(
nullptr, (dif_rv_plic_irq_id_t)kFirstIrq, &status);
EXPECT_DIF_BADARG(result);

result = dif_rv_plic_irq_is_pending(&plic_, kFirstIrq, nullptr);
result = dif_rv_plic_irq_is_pending(&plic_, (dif_rv_plic_irq_id_t)kFirstIrq,
nullptr);
EXPECT_DIF_BADARG(result);

result = dif_rv_plic_irq_is_pending(nullptr, kFirstIrq, nullptr);
result = dif_rv_plic_irq_is_pending(nullptr, (dif_rv_plic_irq_id_t)kFirstIrq,
nullptr);
EXPECT_DIF_BADARG(result);
}

Expand All @@ -232,7 +235,8 @@ TEST_F(IrqPendingStatusGetTest, Enabled) {
// Get status of every IRQ, one at a time.
for (int i = 0; i < RV_PLIC_PARAM_NUM_SRC; ++i) {
bool status;
dif_result_t result = dif_rv_plic_irq_is_pending(&plic_, i, &status);
dif_result_t result =
dif_rv_plic_irq_is_pending(&plic_, (dif_rv_plic_irq_id_t)i, &status);
EXPECT_DIF_OK(result);
EXPECT_TRUE(status);
}
Expand All @@ -244,7 +248,8 @@ TEST_F(IrqPendingStatusGetTest, Disabled) {
// Get status of every IRQ, one at a time.
for (int i = 0; i < RV_PLIC_PARAM_NUM_SRC; ++i) {
bool status;
dif_result_t result = dif_rv_plic_irq_is_pending(&plic_, i, &status);
dif_result_t result =
dif_rv_plic_irq_is_pending(&plic_, (dif_rv_plic_irq_id_t)i, &status);
EXPECT_DIF_OK(result);
EXPECT_FALSE(status);
}
Expand Down Expand Up @@ -282,7 +287,8 @@ class IrqCompleteTest : public PlicTest {
};

TEST_F(IrqCompleteTest, NullArgs) {
EXPECT_DIF_BADARG(dif_rv_plic_irq_complete(nullptr, kTarget0, 0));
EXPECT_DIF_BADARG(
dif_rv_plic_irq_complete(nullptr, kTarget0, (dif_rv_plic_irq_id_t)0));
}

TEST_F(IrqCompleteTest, Target0Success) {
Expand All @@ -293,7 +299,8 @@ TEST_F(IrqCompleteTest, Target0Success) {

// Complete all of the IRQs.
for (int i = 0; i < RV_PLIC_PARAM_NUM_SRC; ++i) {
EXPECT_DIF_OK(dif_rv_plic_irq_complete(&plic_, kTarget0, i));
EXPECT_DIF_OK(
dif_rv_plic_irq_complete(&plic_, kTarget0, (dif_rv_plic_irq_id_t)i));
}
}

Expand Down

0 comments on commit b95a519

Please sign in to comment.