Skip to content

Commit 6a07202

Browse files
committed
tests: drivers: riscv: add AIA (APLIC + IMSIC) driver tests
Add comprehensive test suite for RISC-V Advanced Interrupt Architecture (AIA) drivers, covering both APLIC and IMSIC components. Test Coverage (17 tests): APLIC Tests: - Register offset calculations (sourcecfg, target) - Register address constants validation - DOMAINCFG bit definitions - Source mode constants (inactive, edge, level) - TARGET register field encoding (hart, MSI mode, EIID) - GENMSI register field encoding for software-triggered MSI - MSIADDRCFGH geometry field validation IMSIC Tests: - CSR address definitions (direct and indirect) - MTOPEI register field masks (EIID, priority extraction) - EIDELIVERY mode constants (MMSI, DMSI, DDI) - EIE register indexing (8 registers, 32 IDs each = 256 EIIDs) - EIE bit manipulation for enabling/disabling interrupts - Indirect CSR addressing calculations Integration Tests: - Complete MSI routing encoding (APLIC TARGET + IMSIC EIE) - EIID range boundary tests (0-2047, 11-bit) - Hart index boundary tests (0-16383, 14-bit) Test Pattern: Following the existing PLIC test pattern at tests/drivers/interrupt_controller/intc_plic/, these tests validate constants, helper functions, and register encoding logic without requiring actual AIA hardware. All 17 tests pass successfully on qemu_riscv64. Build and run: west build -p -b qemu_riscv64 tests/drivers/interrupt_controller/intc_riscv_aia west build -t run Signed-off-by: Afonso Oliveira <afonsoo@synopsys.com>
1 parent b7bf6d0 commit 6a07202

File tree

5 files changed

+488
-0
lines changed

5 files changed

+488
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
5+
project(intc_riscv_aia)
6+
7+
FILE(GLOB app_sources src/*.c)
8+
target_sources(app PRIVATE ${app_sources})
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# RISC-V AIA (APLIC + IMSIC) Driver Tests
2+
3+
This test suite validates the RISC-V Advanced Interrupt Architecture (AIA) drivers,
4+
including the APLIC (Advanced Platform-Level Interrupt Controller) and IMSIC
5+
(Incoming Message-Signaled Interrupt Controller).
6+
7+
## Test Coverage
8+
9+
### APLIC Tests
10+
11+
1. **Register Offset Calculations**
12+
- `test_aplic_sourcecfg_offset`: Validates SOURCECFG register offset calculation
13+
- `test_aplic_target_offset`: Validates TARGET register offset calculation
14+
15+
2. **Register Address Constants**
16+
- `test_aplic_register_addresses`: Verifies critical APLIC register offsets per AIA spec
17+
18+
3. **Configuration Bits and Modes**
19+
- `test_aplic_domaincfg_bits`: Tests DOMAINCFG register bit field definitions
20+
- `test_aplic_source_modes`: Validates source mode constants (inactive, edge, level, etc.)
21+
22+
4. **MSI Routing Encoding**
23+
- `test_aplic_target_encoding`: Tests TARGET register field encoding (hart, MSI mode, EIID)
24+
- `test_aplic_genmsi_encoding`: Tests GENMSI register field encoding for software-triggered MSI
25+
- `test_aplic_msi_geometry_fields`: Validates MSIADDRCFGH geometry field encoding
26+
27+
### IMSIC Tests
28+
29+
1. **CSR Address Definitions**
30+
- `test_imsic_csr_addresses`: Validates direct and indirect CSR addresses
31+
32+
2. **Register Field Decoding**
33+
- `test_imsic_mtopei_fields`: Tests MTOPEI register field masks (EIID, priority)
34+
- `test_imsic_eidelivery_modes`: Validates EIDELIVERY mode constants (MMSI, DMSI, DDI)
35+
36+
3. **EIE Register Indexing**
37+
- `test_imsic_eie_indexing`: Tests EIID to EIE register mapping (8 registers, 32 IDs each)
38+
- `test_imsic_eie_bit_operations`: Validates bit manipulation for enabling/disabling EIIDs
39+
- `test_imsic_indirect_csr_addressing`: Tests CSR address calculation for indirect access
40+
41+
### Integration Tests
42+
43+
1. **MSI Routing**
44+
- `test_aia_msi_routing_encoding`: Tests APLIC TARGET + IMSIC EIE encoding for complete MSI route
45+
46+
2. **Boundary Conditions**
47+
- `test_eiid_range_boundaries`: Tests EIID encoding from 0 to 2047 (11-bit)
48+
- `test_hart_index_boundaries`: Tests hart index encoding from 0 to 16383 (14-bit)
49+
50+
## Test Pattern
51+
52+
Following the existing PLIC test pattern at `tests/drivers/interrupt_controller/intc_plic/`,
53+
these tests validate:
54+
- Register offset helper functions
55+
- Bit field definitions and masks
56+
- Encoding/decoding of hardware register values
57+
- Boundary conditions and overflow handling
58+
59+
The tests do NOT require actual AIA hardware - they test the driver API constants,
60+
helper functions, and register encoding logic.
61+
62+
## Running the Tests
63+
64+
```bash
65+
# Build and run tests
66+
west build -p -b qemu_riscv64 tests/drivers/interrupt_controller/intc_riscv_aia
67+
west build -t run
68+
```
69+
70+
## Test Results
71+
72+
All 17 tests pass successfully:
73+
74+
```
75+
SUITE PASS - 100.00% [intc_riscv_aia]: pass = 17, fail = 0, skip = 0, total = 17
76+
```
77+
78+
## Architecture
79+
80+
These tests validate the AIA driver implementation consisting of:
81+
- **APLIC driver** (`drivers/interrupt_controller/intc_riscv_aplic_msi.c`)
82+
- **IMSIC driver** (`drivers/interrupt_controller/intc_riscv_imsic.c`)
83+
- **Unified AIA coordinator** (`drivers/interrupt_controller/intc_riscv_aia.c`)
84+
85+
The tests ensure correct encoding of:
86+
- MSI routing (APLIC → IMSIC)
87+
- Interrupt enable/disable operations
88+
- SMP hart targeting
89+
- Software-triggered MSI injection (GENMSI)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONFIG_ZTEST=y

0 commit comments

Comments
 (0)