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 3e2686b commit eea83bc
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions sw/device/lib/dif/dif_rv_plic_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ 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,
EXPECT_DIF_BADARG(dif_rv_plic_irq_set_enabled(nullptr, (dif_rv_plic_irq_id_t)kFirstIrq, kTarget0,
kDifToggleEnabled));
}

Expand All @@ -156,7 +156,7 @@ TEST_F(IrqEnableSetTest, Target0Enable) {
// 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));
dif_rv_plic_irq_set_enabled(&plic_, (dif_rv_plic_irq_id_t)i, kTarget0, kDifToggleEnabled));
}
}

Expand All @@ -166,19 +166,19 @@ 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));
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));
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,
EXPECT_DIF_BADARG(dif_rv_plic_irq_set_priority(nullptr, (dif_rv_plic_irq_id_t)kFirstIrq,
kDifRvPlicMaxPriority + 1));
}

Expand All @@ -189,7 +189,7 @@ TEST_F(IrqPrioritySetTest, Success) {
EXPECT_WRITE32(offset, kDifRvPlicMaxPriority);

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

Expand All @@ -216,13 +216,13 @@ 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 +232,7 @@ 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 +244,7 @@ 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 +282,7 @@ 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 +293,7 @@ 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 eea83bc

Please sign in to comment.