tests: drivers: intc_plic: Add tests for register index and offset
Add a test to verify that the regression from
ffb8f31bff
is fixed.
Signed-off-by: Piotr Wojnarowski <pwojnarowski@antmicro.com>
This commit is contained in:
parent
3afe238926
commit
6670dbe834
|
@ -45,6 +45,12 @@
|
|||
#define PLIC_REG_SIZE 32
|
||||
#define PLIC_REG_MASK BIT_MASK(LOG2(PLIC_REG_SIZE))
|
||||
|
||||
#ifdef CONFIG_TEST_INTC_PLIC
|
||||
#define INTC_PLIC_STATIC
|
||||
#else
|
||||
#define INTC_PLIC_STATIC static inline
|
||||
#endif
|
||||
|
||||
typedef void (*riscv_plic_irq_config_func_t)(void);
|
||||
struct plic_config {
|
||||
mem_addr_t prio;
|
||||
|
@ -59,12 +65,12 @@ struct plic_config {
|
|||
static uint32_t save_irq;
|
||||
static const struct device *save_dev;
|
||||
|
||||
static inline uint32_t local_irq_to_reg_index(uint32_t local_irq)
|
||||
INTC_PLIC_STATIC uint32_t local_irq_to_reg_index(uint32_t local_irq)
|
||||
{
|
||||
return local_irq >> LOG2(PLIC_REG_SIZE);
|
||||
}
|
||||
|
||||
static inline uint32_t local_irq_to_reg_offset(uint32_t local_irq)
|
||||
INTC_PLIC_STATIC uint32_t local_irq_to_reg_offset(uint32_t local_irq)
|
||||
{
|
||||
return local_irq_to_reg_index(local_irq) * sizeof(uint32_t);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
cmake_minimum_required(VERSION 3.20.0)
|
||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||
project(intc_plic)
|
||||
|
||||
FILE(GLOB app_sources src/*.c)
|
||||
target_sources(app PRIVATE ${app_sources})
|
10
tests/drivers/interrupt_controller/intc_plic/Kconfig
Normal file
10
tests/drivers/interrupt_controller/intc_plic/Kconfig
Normal file
|
@ -0,0 +1,10 @@
|
|||
# Copyright (c) 2023 Antmicro
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
config TEST_INTC_PLIC
|
||||
bool
|
||||
default y
|
||||
help
|
||||
Declare some intc_plic.c functions in the global scope for verification.
|
||||
|
||||
source "Kconfig"
|
1
tests/drivers/interrupt_controller/intc_plic/prj.conf
Normal file
1
tests/drivers/interrupt_controller/intc_plic/prj.conf
Normal file
|
@ -0,0 +1 @@
|
|||
CONFIG_ZTEST=y
|
31
tests/drivers/interrupt_controller/intc_plic/src/main.c
Normal file
31
tests/drivers/interrupt_controller/intc_plic/src/main.c
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright (c) 2023 Antmicro
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <zephyr/ztest.h>
|
||||
|
||||
uint32_t local_irq_to_reg_index(uint32_t local_irq);
|
||||
uint32_t local_irq_to_reg_offset(uint32_t local_irq);
|
||||
|
||||
ZTEST_SUITE(intc_plic, NULL, NULL, NULL, NULL, NULL);
|
||||
|
||||
/* Test calculating the register index from a local IRQ number */
|
||||
ZTEST(intc_plic, test_local_irq_to_reg_index)
|
||||
{
|
||||
zassert_equal(0, local_irq_to_reg_index(0x1f));
|
||||
zassert_equal(1, local_irq_to_reg_index(0x20));
|
||||
zassert_equal(1, local_irq_to_reg_index(0x3f));
|
||||
zassert_equal(2, local_irq_to_reg_index(0x40));
|
||||
}
|
||||
|
||||
/* Test calculating the register offset from a local IRQ number */
|
||||
ZTEST(intc_plic, test_local_irq_to_reg_offset)
|
||||
{
|
||||
zassert_equal(0, local_irq_to_reg_offset(0x1f));
|
||||
zassert_equal(4, local_irq_to_reg_offset(0x20));
|
||||
zassert_equal(4, local_irq_to_reg_offset(0x3f));
|
||||
zassert_equal(8, local_irq_to_reg_offset(0x40));
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
tests:
|
||||
drivers.interrupt_controller.intc_plic:
|
||||
tags:
|
||||
- drivers
|
||||
- interrupt
|
||||
- plic
|
||||
platform_allow: qemu_riscv64
|
Loading…
Reference in a new issue