mirror of
https://github.com/openhwgroup/cvw
synced 2025-02-03 02:05:21 +00:00
testgen-ADD-SUB initial untested
This commit is contained in:
parent
820312bc87
commit
9679345cae
128
wally-pipelined/testgen/testgen-ADD-SUB.py
Normal file → Executable file
128
wally-pipelined/testgen/testgen-ADD-SUB.py
Normal file → Executable file
@ -1,38 +1,124 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
##################################
|
||||||
# testgen-ADD-SUB.py
|
# testgen-ADD-SUB.py
|
||||||
#
|
#
|
||||||
# David_Harris@hmc.edu 19 January 2021
|
# David_Harris@hmc.edu 19 January 2021
|
||||||
#
|
#
|
||||||
# Generate directed and random test vectors for RISC-V Design Validation.
|
# Generate directed and random test vectors for RISC-V Design Validation.
|
||||||
|
##################################
|
||||||
|
|
||||||
|
##################################
|
||||||
# libraries
|
# libraries
|
||||||
#import bitstream as bs
|
##################################
|
||||||
|
from datetime import datetime
|
||||||
|
from random import randint
|
||||||
|
from random import seed
|
||||||
|
from random import getrandbits
|
||||||
|
|
||||||
#corners = [0, 1, 2, 0xFF, 0x624B3E97CC52DD14, 0x7FFFFFFFFFFFFFFE, 0x7FFFFFFFFFFFFFFF,
|
##################################
|
||||||
# 0x8000000000000000, 0x8000000000000001, 0xC365DDEB9173AB42, 0xFFFFFFFFFFFFFFFE, 0xFFFFFFFFFFFFFFFF]
|
# functions
|
||||||
corners = [0, 1, 2, 255]
|
##################################
|
||||||
|
|
||||||
testname = "ADD-SUB"
|
def computeExpected(a, b, test):
|
||||||
fname = "WALLY-" + testname
|
if (test == "ADD"):
|
||||||
testnum = 0;
|
return a + b
|
||||||
|
elif (test == "SUB"):
|
||||||
|
return a - b
|
||||||
|
else:
|
||||||
|
die("bad test name ", test)
|
||||||
|
# exit(1)
|
||||||
|
|
||||||
|
def randRegs():
|
||||||
|
reg1 = randint(1,32)
|
||||||
|
reg2 = randint(1,32)
|
||||||
|
reg3 = randint(1,32)
|
||||||
|
if (reg1 == 6 or reg2 == 6 or reg3 == 6 or reg1 == reg2):
|
||||||
|
return randRegs()
|
||||||
|
else:
|
||||||
|
return reg1, reg2, reg3
|
||||||
|
|
||||||
|
def writeVector(a,b):
|
||||||
|
global testnum
|
||||||
|
expected = computeExpected(a, b, test)
|
||||||
|
expected = expected % 2**xlen # drop carry if necessary
|
||||||
|
if (expected < 0): # take twos complement
|
||||||
|
expected = 2**xlen + expected
|
||||||
|
reg1, reg2, reg3 = randRegs()
|
||||||
|
lines = "\n# Testcase " + str(testnum) + ": rs1:x" + str(reg1) + "(" + formatstr.format(a)
|
||||||
|
lines = lines + "), rs2:x" + str(reg2) + "(" +formatstr.format(b)
|
||||||
|
lines = lines + "), result rd:x" + str(reg3) + "(" + formatstr.format(expected) +")\n"
|
||||||
|
lines = lines + "li x" + str(reg1) + ", MASK_XLEN(" + formatstr.format(a) + ")\n"
|
||||||
|
lines = lines + "li x" + str(reg2) + ", MASK_XLEN(" + formatstr.format(b) + ")\n"
|
||||||
|
lines = lines + test + " x" + str(reg3) + ", x" + str(reg1) + ", x" + str(reg2) + "\n"
|
||||||
|
lines = lines + "sd x" + str(reg3) + ", " + str(8*testnum) + "(x6)\n"
|
||||||
|
lines = lines + "RVTEST_IO_ASSERT_GPR_EQ(x7, " + str(reg3) +", "+formatstr.format(expected)+")\n"
|
||||||
|
f.write(lines)
|
||||||
|
line = formatstr.format(expected)+"\n"
|
||||||
|
r.write(line)
|
||||||
|
testnum = testnum+1
|
||||||
|
|
||||||
|
##################################
|
||||||
|
# main body
|
||||||
|
##################################
|
||||||
|
|
||||||
|
# change these to suite your tests
|
||||||
|
tests = ["ADD", "SUB"]
|
||||||
|
author = "David_Harris@hmc.edu & Katherine Parry"
|
||||||
|
xlens = [32, 64]
|
||||||
|
numrand = 100;
|
||||||
|
|
||||||
# Testcase 0: rs1:x31(0x10fd3dedadea5195), rs2:x16(0xdf7f3844121bcc23), result rd:x1(0xf07c7631c0061db8)
|
# setup
|
||||||
# li x16, MASK_XLEN(0xdf7f3844121bcc23)
|
seed(0) # make tests reproducible
|
||||||
#li x31, MASK_XLEN(0x10fd3dedadea5195)
|
|
||||||
# add x1, x31, x16
|
|
||||||
# sd x1, 0(x6)
|
|
||||||
#RVTEST_IO_ASSERT_GPR_EQ(x7, x1, 0xf07c7631c0061db8)
|
|
||||||
|
|
||||||
|
# generate files for each test
|
||||||
|
for xlen in xlens:
|
||||||
|
formatstrlen = str(int(xlen/4))
|
||||||
|
formatstr = "0x{:0" + formatstrlen + "x}" # format as xlen-bit hexadecimal number
|
||||||
|
for test in tests:
|
||||||
|
corners = [0, 1, 2, 0xFF, 0x624B3E976C52DD14 % 2**xlen, 2**(xlen-1)-2, 2**(xlen-1)-1,
|
||||||
|
2**(xlen-1), 2**(xlen-1)+1, 0xC365DDEB9173AB42 % 2**xlen, 2**(xlen)-2, 2**(xlen)-1]
|
||||||
|
imperaspath = "../../imperas-riscv-tests/riscv-test-suite/rv" + str(xlen) + "i/"
|
||||||
|
basename = "WALLY-" + test
|
||||||
|
fname = imperaspath + "src/" + basename + ".S"
|
||||||
|
refname = imperaspath + "references/" + basename + ".reference_output"
|
||||||
|
testnum = 0
|
||||||
|
|
||||||
f = open(fname, "w")
|
# print custom header part
|
||||||
for a in corners:
|
f = open(fname, "w")
|
||||||
for b in corners:
|
r = open(refname, "w")
|
||||||
tc = "# Testcase " + str(testnum
|
line = "///////////////////////////////////////////\n"
|
||||||
f.write(tc)
|
|
||||||
line = "li x1, MASK_XLEN(" + str(a) + ")"
|
|
||||||
f.write(line)
|
f.write(line)
|
||||||
testnum = testnum+1
|
lines="// "+fname+ "\n// " + author + "\n"
|
||||||
f.close()
|
f.write(lines)
|
||||||
|
line ="// Created " + str(datetime.now())
|
||||||
|
f.write(line)
|
||||||
|
|
||||||
|
# insert generic header
|
||||||
|
h = open("testgen_header.S", "r")
|
||||||
|
for line in h:
|
||||||
|
f.write(line)
|
||||||
|
|
||||||
|
# print directed and random test vectors
|
||||||
|
for a in corners:
|
||||||
|
for b in corners:
|
||||||
|
writeVector(a, b)
|
||||||
|
for i in range(0,numrand):
|
||||||
|
a = getrandbits(xlen)
|
||||||
|
b = getrandbits(xlen)
|
||||||
|
writeVector(a, b)
|
||||||
|
|
||||||
|
|
||||||
|
# print footer
|
||||||
|
h = open("testgen_footer.S", "r")
|
||||||
|
for line in h:
|
||||||
|
f.write(line)
|
||||||
|
|
||||||
|
# Finish
|
||||||
|
line = ".fill " + str(testnum) + ", 8, -1\n"
|
||||||
|
f.write(line)
|
||||||
|
f.close()
|
||||||
|
r.close()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
18
wally-pipelined/testgen/testgen_footer.S
Normal file
18
wally-pipelined/testgen/testgen_footer.S
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# ---------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
RVTEST_IO_WRITE_STR(x31, "Test End\n")
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
RV_COMPLIANCE_HALT
|
||||||
|
|
||||||
|
RV_COMPLIANCE_CODE_END
|
||||||
|
|
||||||
|
# Input data section.
|
||||||
|
.data
|
||||||
|
|
||||||
|
|
||||||
|
# Output data section.
|
||||||
|
RV_COMPLIANCE_DATA_BEGIN
|
||||||
|
|
||||||
|
test_1_res:
|
@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
//
|
//
|
||||||
// Copyright (C) 2021 Harvey Mudd College & Oklahoma State University
|
// Copyright (C) 2021 Harvey Mudd College & Oklahoma State University
|
||||||
|
// Adapted from Imperas RISCV-TEST_SUITE
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
|
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
|
||||||
// files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
|
// files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
|
||||||
@ -30,8 +30,9 @@ RV_COMPLIANCE_CODE_BEGIN
|
|||||||
|
|
||||||
# ---------------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
RVTEST_IO_WRITE_STR(x31, "# Test group 1\n")
|
#RVTEST_IO_WRITE_STR(x31, "# Test group 1\n")
|
||||||
|
|
||||||
|
|
||||||
# address for test results
|
# address for test results
|
||||||
la x6, test_1_res
|
la x6, test_1_res
|
||||||
|
|
Loading…
Reference in New Issue
Block a user