Skip to content

Commit

Permalink
tests: interrupt: sw_isr_table: use devicetree/Kconfig as ground truth
Browse files Browse the repository at this point in the history
Updated the tests to use info from the devicetree or Kconfig as
ground truth and compare that with the output from the
functions under test.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
  • Loading branch information
ycsin authored and cfriedt committed Dec 8, 2023
1 parent f3da086 commit 7934a47
Showing 1 changed file with 33 additions and 25 deletions.
58 changes: 33 additions & 25 deletions tests/kernel/interrupt/src/sw_isr_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@

extern const struct _irq_parent_entry _lvl2_irq_list[];

#define PARENT_IRQ_FN(i, _) CONFIG_2ND_LVL_INTR_0##i##_OFFSET
#if DT_HAS_COMPAT_STATUS_OKAY(sifive_plic_1_0_0)
#define PARENT_DEV_FN(i, _) DEVICE_DT_GET(DT_INST(i, sifive_plic_1_0_0))
#define INTC_SUPPORTS_MULTI_INSTANCE 1
#else
#define PARENT_DEV_FN(i, _) (NULL)
#endif

/**
Expand All @@ -22,22 +26,21 @@ extern const struct _irq_parent_entry _lvl2_irq_list[];
*/
ZTEST(interrupt_feature, test_sw_isr_irq_parent_table_idx)
{
unsigned int parent_irq;
unsigned int parent_isr_offset;
unsigned int test_irq;
unsigned int test_isr_offset;
/* ground truths */
const unsigned int parent_irq[CONFIG_NUM_2ND_LEVEL_AGGREGATORS] = {
LISTIFY(CONFIG_NUM_2ND_LEVEL_AGGREGATORS, PARENT_IRQ_FN, (,)),
};
const unsigned int l2_isr_offset = CONFIG_2ND_LVL_ISR_TBL_OFFSET;

for (size_t i = 0; i < CONFIG_NUM_2ND_LEVEL_AGGREGATORS; i++) {
parent_irq = _lvl2_irq_list[i].irq;
parent_isr_offset = _lvl2_irq_list[i].offset;

for (unsigned int local_irq = 0;
local_irq < CONFIG_MAX_IRQ_PER_AGGREGATOR; local_irq++) {
test_irq = irq_to_level_2(local_irq) | parent_irq;
test_isr_offset = z_get_sw_isr_table_idx(test_irq);
zassert_equal(parent_isr_offset + local_irq, test_isr_offset,
"expected offset: %d, got: %d", parent_isr_offset + local_irq,
test_isr_offset);
unsigned int test_irq = irq_to_level_2(local_irq) | parent_irq[i];
unsigned int test_isr_offset = z_get_sw_isr_table_idx(test_irq);

zassert_equal(l2_isr_offset + local_irq, test_isr_offset,
"%d: expected offset: %d, got: %d", i,
l2_isr_offset + local_irq, test_isr_offset);
}
}
}
Expand All @@ -53,27 +56,32 @@ ZTEST(interrupt_feature, test_sw_isr_irq_parent_table_idx)
*/
ZTEST(interrupt_feature, test_sw_isr_irq_parent_table_dev)
{
const struct device *parent_dev;
unsigned int parent_irq;
const struct device *test_dev;
unsigned int test_irq;

Z_TEST_SKIP_IFNDEF(INTC_SUPPORTS_MULTI_INSTANCE);

/* ground truths */
const struct device *parent_dev[CONFIG_NUM_2ND_LEVEL_AGGREGATORS] = {
LISTIFY(CONFIG_NUM_2ND_LEVEL_AGGREGATORS, PARENT_DEV_FN, (,)),
};
const unsigned int parent_irq[CONFIG_NUM_2ND_LEVEL_AGGREGATORS] = {
LISTIFY(CONFIG_NUM_2ND_LEVEL_AGGREGATORS, PARENT_IRQ_FN, (,)),
};

for (size_t i = 0; i < CONFIG_NUM_2ND_LEVEL_AGGREGATORS; i++) {
parent_dev = _lvl2_irq_list[i].dev;
parent_irq = _lvl2_irq_list[i].irq;
const struct device *test_dev;
unsigned int test_irq;

zassert_not_null(parent_dev[i]);

for (unsigned int local_irq = 0;
local_irq < CONFIG_MAX_IRQ_PER_AGGREGATOR; local_irq++) {
test_irq = irq_to_level_2(local_irq) | parent_irq;
test_irq = irq_to_level_2(local_irq) | parent_irq[i];
test_dev = z_get_sw_isr_device_from_irq(test_irq);
zassert_equal_ptr(parent_dev, test_dev, "expected dev: %p, got: %p",
parent_dev, test_dev);
zassert_equal_ptr(parent_dev[i], test_dev, "%d: expected dev: %p, got: %p",
i, parent_dev[i], test_dev);
}

test_irq = z_get_sw_isr_irq_from_device(parent_dev);
zassert_equal(parent_irq, test_irq, "expected offset: %d, got: %d", parent_irq,
test_irq);
test_irq = z_get_sw_isr_irq_from_device(parent_dev[i]);
zassert_equal(parent_irq[i], test_irq, "%d: expected offset: %d, got: %d", i,
parent_irq[i], test_irq);
}
}

0 comments on commit 7934a47

Please sign in to comment.