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:
Piotr Wojnarowski 2023-11-17 15:36:44 +01:00 committed by Carles Cufí
parent 3afe238926
commit 6670dbe834
6 changed files with 65 additions and 2 deletions

View file

@ -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);
}

View file

@ -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})

View 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"

View file

@ -0,0 +1 @@
CONFIG_ZTEST=y

View 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));
}

View file

@ -0,0 +1,7 @@
tests:
drivers.interrupt_controller.intc_plic:
tags:
- drivers
- interrupt
- plic
platform_allow: qemu_riscv64