Skip to content

Commit ef4c212

Browse files
committed
Add stress tests
1 parent f534826 commit ef4c212

File tree

10 files changed

+823
-0
lines changed

10 files changed

+823
-0
lines changed

verilog/dv/cocotb/cocotb_tests.py

+7
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,10 @@
55
from user_proj_tests.counter_la_reset.counter_la_reset import counter_la_reset
66
from user_proj_tests.counter_la_clk.counter_la_clk import counter_la_clk
77
from gpio_test.gpio_test import gpio_test
8+
9+
from user_proj_tests.stress_tests.stress_test import test_aes_sbox
10+
from user_proj_tests.stress_tests.stress_test import test_hash
11+
from user_proj_tests.stress_tests.stress_test import test_chacha
12+
from user_proj_tests.stress_tests.stress_test import test_stress
13+
from user_proj_tests.stress_tests.stress_test import test_xtea
14+
from user_proj_tests.stress_tests.stress_test import soft_float

verilog/dv/cocotb/stress.h

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef STRESS_H
2+
#define STRESS_H
3+
4+
5+
#include <firmware_apis.h> // include required APIs
6+
7+
8+
void stress_test_start(){
9+
ManagmentGpio_outputEnable();
10+
enableHkSpi(0);
11+
ManagmentGpio_write(1);
12+
}
13+
14+
void stress_test_end(){
15+
ManagmentGpio_write(0);
16+
}
17+
18+
#endif // STRESS_H
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
#include <stress.h>
2+
#include <stdio.h>
3+
#include <math.h>
4+
#include <stdbool.h> // For using the bool type
5+
#include <float.h>
6+
#include <stdint.h>
7+
8+
9+
#define N 3 // Define the size of the input signal
10+
11+
// Function to compute the DCT-II
12+
void dct(float input[N], float output[N]) {
13+
int k, n;
14+
float alpha;
15+
16+
for (k = 0; k < N; k++) {
17+
output[k] = 0.0;
18+
19+
for (n = 0; n < N; n++) {
20+
output[k] += input[n] * cosf(M_PI / N * (n + 0.5) * k);
21+
}
22+
23+
// Scaling factor for normalization
24+
alpha = (k == 0) ? sqrtf(1.0 / N) : sqrtf(2.0 / N);
25+
output[k] *= alpha;
26+
27+
}
28+
}
29+
30+
// Function to compute the Inverse DCT (IDCT)
31+
void idct(float input[N], float output[N]) {
32+
int k, n;
33+
float alpha;
34+
35+
for (n = 0; n < N; n++) {
36+
output[n] = 0.0;
37+
38+
for (k = 0; k < N; k++) {
39+
alpha = (k == 0) ? sqrtf(1.0 / N) : sqrtf(2.0 / N);
40+
output[n] += alpha * input[k] * cosf(M_PI / N * (n + 0.5) * k);
41+
}
42+
}
43+
}
44+
45+
// Function to check if the IDCT output matches the original input within a tolerance
46+
bool check_reconstruction(float input[N], float output[N], float tolerance) {
47+
for (int i = 0; i < N; i++) {
48+
if (fabs(input[i] - output[i]) > tolerance) {
49+
return false; // Failure if the difference exceeds tolerance
50+
}
51+
}
52+
return true; // Success if all values are within tolerance
53+
}
54+
55+
// Main function to test DCT and IDCT implementation
56+
int main() {
57+
stress_test_start();
58+
// float input[N] = {255, 231, 189, 165, 122, 100, 85, 52}; // Example input signal
59+
float input[N] = {255, 231, 189}; // Example input signal
60+
float dct_output[N], idct_output[N];
61+
float tolerance = 1e-4; // Define an acceptable error tolerance
62+
bool failure;
63+
64+
// Perform the DCT
65+
dct(input, dct_output);
66+
67+
// Perform the Inverse DCT
68+
idct(dct_output, idct_output);
69+
70+
// Check if the IDCT output matches the original input
71+
failure = !check_reconstruction(input, idct_output, tolerance);
72+
73+
// Check if reconstruction was successful
74+
if (failure) {
75+
return 1; // Exit with failure code
76+
}
77+
stress_test_end();
78+
return 0; // Exit with success code
79+
}
80+
81+
to run this linker script needs to be changed to
82+
83+
// /* INCLUDE ../../generated/output_format.ld */
84+
85+
// OUTPUT_FORMAT("elf32-littleriscv")
86+
87+
// ENTRY(_start)
88+
89+
// __DYNAMIC = 0;
90+
91+
// /* INCLUDE ../../generated/regions.ld */
92+
93+
// MEMORY {
94+
// vexriscv_debug : ORIGIN = 0xf00f0000, LENGTH = 0x00000100
95+
// dff : ORIGIN = 0x00000000, LENGTH = 0x00000400
96+
// dff2_part1 : ORIGIN = 0x00000400, LENGTH = 0x00000100
97+
// dff2_part2 : ORIGIN = 0x00000500, LENGTH = 0x00000100
98+
// flash : ORIGIN = 0x10000000, LENGTH = 0x01000000
99+
// mprj : ORIGIN = 0x30000000, LENGTH = 0x00100000
100+
// hk : ORIGIN = 0x26000000, LENGTH = 0x00100000
101+
// csr : ORIGIN = 0xf0000000, LENGTH = 0x00010000
102+
// }
103+
104+
// SECTIONS
105+
// {
106+
// .text : {
107+
// _ftext = .;
108+
// *(.vectors)
109+
// *(.text*)
110+
// *(.rodata*)
111+
// *(.srodata.cst16)
112+
// *(.srodata.cst8)
113+
// *(.srodata.cst4)
114+
// *(.srodata.cst2)
115+
// *(.srodata .srodata.*)
116+
// . = ALIGN(8);
117+
// _etext = .;
118+
// } > flash
119+
120+
121+
// .data :
122+
// {
123+
// _fdata = .;
124+
// *(.sdata .sdata.* .gnu.linkonce.s.*)
125+
// *(.data*);
126+
// _edata = .;
127+
// PROVIDE( __global_pointer$ = . + 0x800 );
128+
129+
// } > dff,dff2_part1 AT > flash
130+
131+
// .bss (NOLOAD) :
132+
// {
133+
// _fbss = .;
134+
// *(.bss*)
135+
// *(COMMON)
136+
// _ebss = .;
137+
// _end = .;
138+
// } > dff,dff2_part1
139+
// }
140+
141+
// PROVIDE(_fstack = ORIGIN(dff2_part2) + LENGTH(dff2_part2));
142+
143+
// PROVIDE(_fdata_rom = LOADADDR(.data));
144+
// PROVIDE(_edata_rom = LOADADDR(.data) + SIZEOF(.data));
145+
146+
// and stub function also
147+
148+
149+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
from caravel_cocotb.caravel_interfaces import * # import python APIs
2+
import cocotb
3+
4+
5+
async def base_function(caravelEnv):
6+
await caravelEnv.wait_mgmt_gpio(1)
7+
start_time = cocotb.utils.get_sim_time("ns")
8+
cocotb.log.info(f"[TEST] start test time: {start_time}ns")
9+
await caravelEnv.wait_mgmt_gpio(0)
10+
end_time = cocotb.utils.get_sim_time("ns")
11+
cocotb.log.info(f"[TEST] end test time: {end_time}ns")
12+
clk_period = caravelEnv.get_clock_obj().period/1000
13+
cocotb.log.info(f"[TEST] time: {end_time - start_time}ns number of cycles : {(end_time - start_time)/clk_period} period :{clk_period}")
14+
15+
16+
@cocotb.test()
17+
@report_test
18+
async def test_aes_sbox(dut):
19+
caravelEnv = await test_configure(dut, timeout_cycles=1175080)
20+
await base_function(caravelEnv)
21+
22+
23+
@cocotb.test()
24+
@report_test
25+
async def test_chacha(dut):
26+
caravelEnv = await test_configure(dut, timeout_cycles=1161557)
27+
await base_function(caravelEnv)
28+
29+
30+
@cocotb.test()
31+
@report_test
32+
async def test_hash(dut):
33+
caravelEnv = await test_configure(dut, timeout_cycles=11123843)
34+
await base_function(caravelEnv)
35+
36+
37+
@cocotb.test()
38+
@report_test
39+
async def test_stress(dut):
40+
caravelEnv = await test_configure(dut, timeout_cycles=1161466)
41+
await base_function(caravelEnv)
42+
43+
44+
@cocotb.test()
45+
@report_test
46+
async def test_xtea(dut):
47+
caravelEnv = await test_configure(dut, timeout_cycles=1560380)
48+
await base_function(caravelEnv)
49+
50+
51+
@cocotb.test()
52+
@report_test
53+
async def soft_float(dut):
54+
caravelEnv = await test_configure(dut, timeout_cycles=111789183)
55+
await base_function(caravelEnv)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
# yaml file contain general design information that would mostly need to be updated in the first run only
3+
Tests:
4+
# - {name: test_aes_sbox, sim: RTL}
5+
# - {name: test_chacha, sim: RTL}
6+
# - {name: test_stress, sim: RTL}
7+
- {name: test_xtea, sim: RTL}
8+
# - {name: test_hash, sim: RTL}
9+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include <stdint.h>
2+
#include <stress.h>
3+
4+
static uint8_t aes_sbox[256]; /** AES S-box */
5+
static uint8_t aes_isbox[256]; /** AES iS-box */
6+
void AES_generateSBox(void)
7+
{
8+
uint32_t t[256], i;
9+
uint32_t x;
10+
for (i = 0, x = 1; i < 256; i ++)
11+
{
12+
t[i] = x;
13+
x ^= (x << 1) ^ ((x >> 7) * 0x11B);
14+
}
15+
16+
aes_sbox[0] = 0x63;
17+
for (i = 0; i < 255; i ++)
18+
{
19+
x = t[255 - i];
20+
x |= x << 8;
21+
x ^= (x >> 4) ^ (x >> 5) ^ (x >> 6) ^ (x >> 7);
22+
aes_sbox[t[i]] = (x ^ 0x63) & 0xFF;
23+
}
24+
for (i = 0; i < 256;i++)
25+
{
26+
aes_isbox[aes_sbox[i]]=i;
27+
}
28+
}
29+
30+
31+
main(){
32+
stress_test_start();
33+
unsigned int sum = 0;
34+
AES_generateSBox();
35+
for(int i=0; i<256; i++)
36+
sum += (aes_sbox[i] + aes_isbox[i]);
37+
if(sum == 65280)
38+
stress_test_end();
39+
}

0 commit comments

Comments
 (0)