Skip to content

Commit 4c99b40

Browse files
Merge pull request #2 from IhsaneTahir/testplan
First version of UVM testplan and README update
2 parents 8389a93 + 094f660 commit 4c99b40

File tree

11 files changed

+258
-45
lines changed

11 files changed

+258
-45
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
*.db
2+
*.bin
3+
*.log
4+
*.d
5+
*.so
6+
*.o
7+
transcript
8+
work/

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[submodule "modules/core-v-verif"]
22
path = modules/core-v-verif
3-
url = https://github.com/openhwgroup/core-v-verif.git
3+
url = https://github.com/openhwgroup/core-v-verif.git
44
[submodule "modules/cva6"]
55
path = modules/cva6
66
url = https://github.com/openhwgroup/cva6.git

README.md

Lines changed: 162 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,69 @@
11
# CVFPU UVM Testbench
22

33
## 1. Project Overview
4-
This repository contains a **UVM testbench** for verifying the **CVFPU (Core-V Floating Point Unit)**. DUT is the CVA6 wrapper of the floating point unit.
4+
This repository contains a UVM Verification Environment for the [CVFPU](https://github.com/openhwgroup/cvfpu.git). DUT is the CVA6 wrapper of the floating-point unit.
55

66
## 2. Testbench Architecture
77

88
![CVA6 Tile Platform](./images/cvfpu_uvm_tb_archi.png)
99

1010
## 3. Project Structure
1111
The repository is organised as follows:
12-
- **env/** Contains UVM environment, scoreboard and top configuration class
13-
- **fpu_agent/** Contains UVM agent, driver, sequencer, monitor, interface, sequences and transaction
12+
- **docs/testplan/** Contains the testplan for the CVFPU UVM environment
13+
- **env/** Contains UVM environment, scoreboard and top configuration classes
14+
- **fpu_agent/** Contains UVM agent, driver, sequencer, monitor, interface, sequences and transaction item
1415
- **fpu_common/** Contains package used accross UVM testbench
15-
- **ref_model_csim/** Contains C++ reference model as well as SV wrapper
16+
- **modules/** Contains dependencies of the project: [cva6](https://github.com/openhwgroup/cva6.git) and [core-v-verif](https://github.com/openhwgroup/core-v-verif.git) repositories. Both are included as git submodules.
17+
- **ref_model_csim/** Contains C++ reference model as well as SystemVerilog wrapper
1618
- **simu/** Contains regression test list and yaml files needed to run simulation and regression scripts. It also holds log files
1719
- **tests/** Contains UVM test classes
18-
- **top/** Contains top-level testbench file.
20+
- **top/** Contains top-level testbench file
21+
- **scripts/** Contains `scan_logs.pl` perl script for parsing log files, reporting errors and warnings, and generating summary reports.
1922

2023
## 4. Getting started
21-
### 4.1. Compile C++ Reference Model
22-
The first step is to build the shared library `refmodel_csim_lib.so` that will be used in the UVM testbench via DPI.
24+
### 4.1 Environment Setup
25+
Before building or running the project, you must configure your environment variables. The testbench requires QuestaSim simulator, so ensure the `QUESTA_PATH` variable is set to your Questa installation directory.
26+
27+
**tcsh**
28+
```
29+
setenv QUESTA_PATH <questa_path>
30+
# ex: setenv QUESTA_PATH <path_to_your_install>/questasim/2025.1
31+
```
32+
**bash**
33+
```
34+
export QUESTA_PATH=<questa_path>
35+
```
36+
We also provide two scripts to setup the project environment, source the one that matches the shell of the machine.
37+
38+
| Shell Type | Command to Run |
39+
| --------------- | -----------------------|
40+
| **csh/tcsh** | `source setup_env.csh` |
41+
| **bash/zsh/sh** | `source setup_env.sh` |
42+
43+
Some of the testbench utilities (compilation, simulation and regression scripts) use Python. Dependencies are listed in `requirements.txt`.
44+
45+
### 4.2. Compile C++ Reference Model
46+
Build the shared library `refmodel_csim_lib.so` used in the UVM testbench via DPI.
2347

2448
#### Dependencies
2549
The following dependencies need to be installed in the system:
2650

2751
- **GMP** (GNU Multiple Precision Arithmetic Library)
2852
- **MPFR** (Multiple Precision Floating-Point Reliable Library): Section [*2.1 How to Install*](https://www.mpfr.org/mpfr-current/mpfr.html) details the steps to follow to install the library, use preferably version **4.2.2**.
2953

30-
Then, set GMP/MPFR directory path variables in the environment
54+
Set GMP/MPFR directory path variables in the environment.
55+
56+
**tcsh**
57+
```
58+
setenv GMP_DIR <gmp_dir_absolute_path>
59+
setenv MPFR_DIR <mpfr_dir_absolute_path>
60+
```
61+
**bash**
3162
```
32-
setenv GMP_DIR <gmp_dir_path>
33-
setenv MPFR_DIR <mpfr_dir_path>
63+
export GMP_DIR=<gmp_dir_absolute_path>
64+
export MPFR_DIR=<mpfr_dir_absolute_path>
3465
```
66+
It is important to note that the reference model includes `dpiheader.h` file that is tool specific to QuestaSim.
3567

3668
#### Compilation
3769
```
@@ -40,43 +72,141 @@ make
4072
```
4173

4274
### 4.2. Build and run simulation
43-
#### Setup
44-
45-
At the root of the project, set the following environment variables.
46-
```
47-
setenv QUESTA_PATH <questa_path>
48-
# ex: setenv QUESTA_PATH <path_to_your_install>/questasim/2025.1
49-
which vsim: <path_to_your_install>/questasim/2025.1/bin/vsim
50-
setenv PATH ${QUESTA_PATH}/bin:$PATH
75+
#### Compile testbench
5176
```
52-
Run the setup script to configure project paths.
53-
```
54-
source setup_env.csh
55-
```
56-
57-
#### Build TB and run simulation
58-
1. Compile testbench
59-
```
60-
cd simu
77+
cd ${PROJECT_DIR}/simu/
6178
python3 ${SCRIPTS_DIR}/compile.py --yaml sim_questa.yaml
6279
```
63-
2. Run a test
80+
#### Run a test
6481

65-
The number of transactions is set by the variable `+NB_TXNS` (passed as simulation option) in the `sim_questa.yaml` script. It is currently fixed to 10 000.
82+
The number of transactions is set by the variable `+NB_TXNS` (passed as simulation option) in the `sim_questa.yaml` file. It is currently fixed to 10 000.
6683
```
6784
python3 ${SCRIPTS_DIR}/run_test.py --yaml sim_questa.yaml --test_name <TEST_NAME> --seed <SEED> --debug <VERBOSITY>
6885
```
6986
For example
7087
```
7188
python3 ${SCRIPTS_DIR}/run_test.py --yaml sim_questa.yaml --test_name fpu_random_test --seed 1 --debug UVM_LOW
7289
```
73-
Simulation logs can be found in the `output/` directory.
90+
Simulation logs can be found in the `output/` folder.
91+
92+
#### Run a regression
93+
The regression suite is defined in the `simu/fpu_reg_list` file. Each line in this file specifies:
94+
- **Test Name:** The UVM test class to run.
95+
- **Number of Runs:** How many times to run that test, each one has a different randomly generated seed
96+
97+
Edit this file to decrease/increase the number of runs. Example of 20 runs/test:
98+
```
99+
fpu_single_op_test 20
100+
fpu_random_test 20
101+
```
74102

75-
3. Run a regression, `fpu_reg_list` contains the regression suite.
103+
Check the `testplan` for more details on the available tests.
76104
```
77105
python3 ${SCRIPTS_DIR}/run_reg.py --yaml reg_questa.yaml --nthreads 3 --reg_list fpu_reg_list
78106
```
79-
Regression logs can be found in the `regression` folder. To parse through them, run the following script which will return result of the tests with either PASS or FAIL.
107+
Regression logs can be found in the `regression/` folder. To parse through them, run the following script which will return result of the tests with either PASS or FAIL.
80108
```
81109
scan_logs.pl -nowarn --pat ${PROJECT_DIR}/scripts/patterns/sim_patterns.pat --waiver ${PROJECT_DIR}/scripts/patterns/sim_waivers.pat regression/fpu_*_test_*.log
82110
```
111+
112+
> **Note:**
113+
> Some regression failures may currently be expected because of known bugs in the DUT. These are being tracked, check [CVFPU Issues](https://github.com/openhwgroup/cvfpu/issues) section to confirm whether it is a known bug or a new issue that should be reported.
114+
115+
### 4.2. Known Limitations
116+
* The current verification environment targets the CVA6 core exclusively.
117+
* `RMM`, `ROD`, and `DYN` rounding modes have not been fully verified.
118+
* Vector floating-point operations are not supported by the current testbench.
119+
* Only `FP32` and `FP64` formats are thoroughly tested. Other formats are verified only within `F2F` (float-to-float) conversion operations.
120+
* For `F2I` (float-to-integer) and `I2F` (integer-to-float) operations, only `INT32` and `INT64` integer formats are tested.
121+
122+
### 4.3 Adding a new test
123+
For users who are not familiar with UVM, here are some simple steps to follow to create a new test to verify a new feature.
124+
125+
---
126+
#### Step 1: Create a New Sequence
127+
A **sequence** generates the transactions (stimulus) that will be driven to the DUT.
128+
129+
Example: create a new sequence class in `fpu_sequences.svh` file:
130+
131+
```systemverilog
132+
class my_feature_seq extends fpu_base_sequence;
133+
134+
`uvm_object_utils(my_feature_seq)
135+
136+
fpu_txn item;
137+
138+
function new(string name = "my_feature_seq");
139+
super.new(name);
140+
endfunction
141+
142+
virtual task body();
143+
super.body();
144+
145+
item = fpu_txn::type_id::create("my_feature_item");
146+
147+
for (int i = 0; i < num_txn; i++) begin
148+
// Randomize or constrain the transaction to target your feature
149+
if (!item.randomize() with {
150+
m_operation == FDIV; // force divide operation
151+
m_fmt == FP32; // force single-precision format
152+
m_operand_a == opA;
153+
m_operand_b == opB;
154+
m_imm == imm;
155+
m_rm == 0; // force round to nearest, ties to even
156+
}) begin
157+
`uvm_fatal("SEQ", "Randomization failed");
158+
end
159+
160+
start_item(item);
161+
finish_item(item);
162+
end
163+
endtask
164+
endclass
165+
```
166+
You can change constraints to target the feature you want to verify. Sequence item fields to randomize are defined in `fpu_txn.svh` file.
167+
168+
---
169+
#### Step 2: Create a New Test Class
170+
171+
The test class instantiates and starts your new sequence.
172+
Create a new file under `tests/` called `my_feature_test.svh`:
173+
174+
```systemverilog
175+
class my_feature_test extends base_test;
176+
177+
`uvm_component_utils(my_feature_test)
178+
179+
my_feature_seq m_seq;
180+
181+
function new(string name, uvm_component parent);
182+
super.new(name, parent);
183+
endfunction
184+
185+
virtual task pre_main_phase(uvm_phase phase);
186+
m_seq = my_feature_seq::type_id::create("seq");
187+
if(!$cast(base_sequence, m_seq))
188+
`uvm_fatal("CAST FAILED", "Cannot cast base sequence");
189+
190+
super.pre_main_phase(phase);
191+
endtask
192+
endclass
193+
```
194+
---
195+
#### Step3: Register the Test
196+
Add the new test to the `fpu_test_pkg.sv` file.
197+
```systemverilog
198+
`include "my_feature_test.svh"
199+
```
200+
---
201+
#### Step 4: Run the Test
202+
From the `simu/` directory, compile and run the simulation by following directions detailed in section [4.2](#42-known-limitations).
203+
204+
---
205+
206+
#### Step 5: Check Results
207+
Review the log file `my_feature_test_1.log` located in the `output/` directory for `UVM_ERROR` messages. You can run the `scan_logs` script to help parse through the file for errors and warnings.
208+
209+
Open the waveform file if needed to inspect DUT behavior.
210+
```
211+
visualizer example.db
212+
```
15.6 KB
Binary file not shown.

modules/core-v-verif

Submodule core-v-verif added at 5557b01

modules/cva6

Submodule cva6 added at 4d823b8

ref_model_csim/cpp/Makefile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ BUILD_DIR = build
3434
INCDIR_MPFR = $(MPFR_DIR)/include
3535
LIBDIR_MPFR = $(MPFR_DIR)/lib
3636

37-
38-
INCDIR_GMP = $(MPFR_DIR)/include
39-
LIBDIR_GMP = $(MPFR_DIR)/lib
37+
INCDIR_GMP = $(GMP_DIR)/include
38+
LIBDIR_GMP = $(GMP_DIR)/lib
4039

4140
INCDIRS = $(addprefix -I,. $(QUESTA_PATH)/include $(INCDIR_MPFR) $(INCDIR_GMP) $(INCDIR_SOFTFLOAT) $(INC_DIR))
4241
LIBDIRS = $(addprefix -L,$(LIBDIR_MPFR) $(LIBDIR_GMP) $(LIBDIR_SOFTFLOAT))

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pyyaml

setup_env.csh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,15 @@ else
5353
setenv PERL5LIB "${PROJECT_DIR}/scripts/perl5"
5454
endif
5555

56+
################################################
5657
# TOOLS
57-
# This is mainly used by the scan_log.pl tool
58-
echo $C_MSG">> Setting scripts"$C_RST
58+
################################################
59+
# Questasim
60+
setenv PATH ${QUESTA_PATH}/bin:$PATH
5961

62+
#SCANLOGS
6063
setenv SCRIPTS $PROJECT_DIR/scripts
61-
prepend PATH ${SCRIPTS}
64+
setenv PATH ${SCRIPTS}:$PATH
6265

6366
setenv TARGET_CFG cv64a60ax
6467
setenv CVA6_REPO_DIR ${PROJECT_DIR}/modules/cva6

setup_env.sh

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/bin/bash
2+
#
3+
# Copyright (c) 2025 CEA*
4+
# *Commissariat a l'Energie Atomique et aux Energies Alternatives (CEA)
5+
#
6+
# SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1
7+
#
8+
# Licensed under the Solderpad Hardware License v 2.1 (the “License”); you
9+
# may not use this file except in compliance with the License, or, at your
10+
# option, the Apache License version 2.0. You may obtain a copy of the
11+
# License at
12+
#
13+
# https://solderpad.org/licenses/SHL-2.1/
14+
#
15+
# Unless required by applicable law or agreed to in writing, any work
16+
# distributed under the License is distributed on an “AS IS” BASIS, WITHOUT
17+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
# License for the specific language governing permissions and limitations
19+
# under the License.
20+
#
21+
#
22+
# Authors : Ihsane TAHIR
23+
# Creation Date : March, 2025
24+
# Description :
25+
# History :
26+
#
27+
C_TOP="\e[1;32m" # Green
28+
C_RST="\e[0m" # Reset
29+
C_MSG="\e[1;34m" # Blue
30+
31+
# Set project root to current working directory
32+
export PROJECT_DIR="$(pwd)"
33+
34+
echo -e "${C_TOP}>>>>>> Initializing Platform <<<<<<${C_RST}"
35+
36+
############################################################
37+
# Update all git submodules
38+
############################################################
39+
echo -e "${C_MSG}Update all git submodules${C_RST}"
40+
git submodule init
41+
git submodule sync
42+
git submodule update --init --recursive
43+
44+
45+
############################################################
46+
# Add the local path to the Perl libraries
47+
############################################################
48+
if [[ -n "$PERL5LIB" ]]; then
49+
export PERL5LIB="${PERL5LIB}:${PROJECT_DIR}/scripts/perl5"
50+
else
51+
export PERL5LIB="${PROJECT_DIR}/scripts/perl5"
52+
fi
53+
54+
# TOOLS
55+
export PATH="${QUESTA_PATH}/bin:$PATH"
56+
57+
#SCANLOGS
58+
export SCRIPTS=$PROJECT_DIR/scripts
59+
export PATH="${SCRIPTS}:$PATH"
60+
61+
############################################################
62+
# Project-specific environment variables
63+
############################################################
64+
export TARGET_CFG="cv64a60ax"
65+
export CVA6_REPO_DIR="${PROJECT_DIR}/modules/cva6"
66+
export CORE_V_VERIF="${PROJECT_DIR}/modules/core-v-verif"
67+
export DV_UTILS_DIR="${CORE_V_VERIF}/lib/cv_dv_utils"
68+
export SCRIPTS_DIR="${DV_UTILS_DIR}/python/sim_cmd"
69+
70+
echo -e "${C_TOP}>>>>>> Initialization Done <<<<<<${C_RST}"

0 commit comments

Comments
 (0)