Skip to content

Commit

Permalink
[aes, pre-dv] Pre-dv Verilator testbench for AES
Browse files Browse the repository at this point in the history
This commit contains a comprehensive pre-dv testbench for the AES IP
block, invoking all the possible modes of operations (+GCM) with
different key and inputs sizes. By default, the communication with the
IP happens over the TLUL bus, but if a TLUL/shim adapter is
configured, messages can be relayed through the shim first.

There are two generic modules `tlul_adapter` and `tlul_delayer` that
are agnostic to the actual testbench and can be reused in other
testbenches that require a robust TLUL handler.

This testbench mimics already existing pre-dv suites for Ascon and
KMAC.

Signed-off-by: Andrea Caforio <[email protected]>
  • Loading branch information
andrea-caforio committed Nov 26, 2024
1 parent d759588 commit 26b1dd7
Show file tree
Hide file tree
Showing 14 changed files with 259 additions and 164 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# TLUL/Shim Verilator Testbench

This directory contains the Verilator testbench for the TLUL shim adapter that is attached to the AES IP block.
Out of the box, the testbench contains test vectors for most of the salient use cases, nonetheless extending the testbench with further tests is straightforward as detailed below.
This directory contains the Verilator testbench for the AES IP block.
Out of the box, the testbench contains test vectors for most of the salient use cases, nonetheless extending the testbench with further tests is straightforward as detailed below. By default, communication with the IP happens over the TLUL bus. If a TLUL/shim adapter is available, messages can optionally be relayed by the shim.

## Current Test Vectors

Expand Down Expand Up @@ -37,19 +37,20 @@ Having written a new test vector file, the `fusesoc` configuration needs to be m
To build the testbench, execute from the OpenTitan top level:

```sh
fusesoc --cores-root=. --verbose run --setup --build lowrisc:dv_verilator:aes_tlul_shim_tb
fusesoc --cores-root=. --verbose run --setup --build lowrisc:dv_verilator:aes_tb
```
To execute the obtained Verilator binary and with trace generation, run:

```sh
./build/lowrisc_dv_verilator_aes_tlul_shim_tb_0/default-verilator/Vaes_tlul_shim_tb --trace
./build/lowrisc_dv_verilator_aes_tb_0/default-verilator/Vaes_tb --trace
```

## Details of the testbench

- cpp/aes\_tlul\_shim\_tb.cc: contains main function and instantiation of SimCtrl
- rtl/aes\_tlul\_shim\_tb.sv: contains the testbench logic
- rtl/aes\_tlul\_delayer\_tb.sv: contains an optional delayer module to artificially induce random delays between the Shim and the TLUL bus.
- rtl/aes\_tlul\_shim\_tb_reqs.sv: contains requests (stimuli) that are fed to the testbench.
- rtl/aes\_tlul\_shim\_tb_pkg.sv: contains common parameters and functions.
- cpp/aes\_tb.cc: contains main function and instantiation of SimCtrl
- rtl/aes\_tb.sv: contains the testbench logic
- rtl/tlul\_delayer.sv: contains an optional delayer module to artificially induce random delays in the TLUL bus.
- rtl/tlul\_adapter.sv: is a generic TLUL adapter.
- rtl/aes\_tb_reqs.sv: contains requests (stimuli) that are fed to the testbench.
- rtl/aes\_tb_pkg.sv: contains common parameters and functions.
- data/*: contains test vector files.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ CAPI=2:
# Copyright lowRISC contributors (OpenTitan project).
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0
name: "lowrisc:dv_verilator:aes_tlul_shim_tb"
description: "AES TLUL Shim TB"
name: "lowrisc:dv_verilator:aes_tb"
description: "AES TB"
filesets:
files_rtl:
depend:
Expand All @@ -16,19 +16,20 @@ filesets:
- data/gcm_k128_a0_d16.svh : {is_include_file : true}
- data/gcm_k128_a0_d0.svh : {is_include_file : true}
- data/modes_d64.svh : {is_include_file : true}
- rtl/aes_tlul_shim_tb_pkg.sv
- rtl/aes_tlul_shim_tb_reqs.sv
- rtl/aes_tlul_shim_tb_c_dpi.sv
- rtl/aes_tlul_shim_delayer.sv
- rtl/aes_tlul_shim_tb.sv
- rtl/aes_tb_pkg.sv
- rtl/aes_tb_reqs.sv
- rtl/aes_tb_c_dpi.sv
- rtl/tlul_delayer.sv
- rtl/tlul_adapter.sv
- rtl/aes_tb.sv
file_type: systemVerilogSource

files_dv_verilator:
depend:
- lowrisc:dv_verilator:simutil_verilator

files:
- cpp/aes_tlul_shim_tb.cc
- cpp/aes_tb.cc
file_type: cppSource

targets:
Expand All @@ -37,7 +38,7 @@ targets:
filesets:
- files_rtl
- files_dv_verilator
toplevel: aes_tlul_shim_tb
toplevel: aes_tb
tools:
verilator:
mode: cc
Expand All @@ -55,7 +56,7 @@ targets:
# -O
# Optimization levels have a large impact on the runtime performance of the
# simulation model. -O2 and -O3 are pretty similar, -Os is slower than -O2/-O3
- '-CFLAGS "-std=c++11 -Wall -DVM_TRACE_FMT_FST -DTOPLEVEL_NAME=aes_tlul_shim_tb -g -O0"'
- '-CFLAGS "-std=c++11 -Wall -DVM_TRACE_FMT_FST -DTOPLEVEL_NAME=aes_tb -g -O0"'
- '-LDFLAGS "-pthread -lutil -lelf"'
- "-Wall"
# XXX: Cleanup all warnings and remove this option
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,29 @@
#include <iostream>
#include <signal.h>

#include "Vaes_tlul_shim_tb.h"
#include "Vaes_tb.h"
#include "sim_ctrl_extension.h"
#include "verilated_toplevel.h"
#include "verilator_sim_ctrl.h"

class AesTlulShimTb : public SimCtrlExtension {
class AesTb : public SimCtrlExtension {
using SimCtrlExtension::SimCtrlExtension;

public:
AesTlulShimTb(aes_tlul_shim_tb *top);
AesTb(aes_tb *top);

void OnClock(unsigned long sim_time);

private:
aes_tlul_shim_tb *top_;
aes_tb *top_;
};

// Constructor:
// - Set up top_ ptr
AesTlulShimTb::AesTlulShimTb(aes_tlul_shim_tb *top)
: SimCtrlExtension{}, top_(top) {}
AesTb::AesTb(aes_tb *top) : SimCtrlExtension{}, top_(top) {}

// Function called once every clock cycle from SimCtrl
void AesTlulShimTb::OnClock(unsigned long sim_time) {
void AesTb::OnClock(unsigned long sim_time) {
if (top_->test_done_o) {
VerilatorSimCtrl::GetInstance().RequestStop(top_->test_passed_o);
}
Expand All @@ -39,18 +38,18 @@ int main(int argc, char **argv) {
int ret_code;

// Init verilog instance
aes_tlul_shim_tb top;
aes_tb top;

// Init sim
VerilatorSimCtrl &simctrl = VerilatorSimCtrl::GetInstance();
simctrl.SetTop(&top, &top.clk_i, &top.rst_ni,
VerilatorSimCtrlFlags::ResetPolarityNegative);

// Create and register VerilatorSimCtrl extension
AesTlulShimTb aes_tlul_shim_tb(&top);
simctrl.RegisterExtension(&aes_tlul_shim_tb);
AesTb aes_tb(&top);
simctrl.RegisterExtension(&aes_tb);

std::cout << "Simulation of AES TLUL Shim" << std::endl
std::cout << "Simulation of AES Testbench" << std::endl
<< "=============================" << std::endl
<< std::endl;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
`define DATA_LENGTH 0
`define NUM_REQUESTS 42

`define REQUESTS shim_request_t requests[`NUM_REQUESTS] = '{ \
`define REQUESTS bus_request_t requests[`NUM_REQUESTS] = '{ \
c_dpi_load('{ \
operation: AES_ENC, \
mode: AES_GCM, \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
`define DATA_LENGTH 16
`define NUM_REQUESTS 55

`define REQUESTS shim_request_t requests[`NUM_REQUESTS] = '{ \
`define REQUESTS bus_request_t requests[`NUM_REQUESTS] = '{ \
c_dpi_load('{ \
operation: AES_ENC, \
mode: AES_GCM, \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
`define DATA_LENGTH 60
`define NUM_REQUESTS 370

`define REQUESTS shim_request_t requests[`NUM_REQUESTS] = '{ \
`define REQUESTS bus_request_t requests[`NUM_REQUESTS] = '{ \
\
/*****************************************************************************/ \
/** AES-GCM-128 Encryption **/ \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
`define DATA_LENGTH 64
`define NUM_REQUESTS 110

`define REQUESTS shim_request_t requests[`NUM_REQUESTS] = '{ \
`define REQUESTS bus_request_t requests[`NUM_REQUESTS] = '{ \
c_dpi_load('{ \
operation: AES_ENC, \
mode: AES_GCM, \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
`define DATA_LENGTH 64
`define NUM_REQUESTS 1982

`define REQUESTS shim_request_t requests[`NUM_REQUESTS] = '{ \
`define REQUESTS bus_request_t requests[`NUM_REQUESTS] = '{ \
\
/*****************************************************************************/ \
/** AES-ECB-128 Encryption **/ \
Expand Down
Loading

0 comments on commit 26b1dd7

Please sign in to comment.