summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rwxr-xr-xtests/asicworld/run-test.sh14
-rw-r--r--tests/bram/generate.py50
-rw-r--r--tests/bram/run-single.sh2
-rwxr-xr-xtests/bram/run-test.sh17
-rw-r--r--tests/fsm/generate.py12
-rwxr-xr-xtests/fsm/run-test.sh14
-rwxr-xr-xtests/hana/run-test.sh14
-rwxr-xr-xtests/memories/run-test.sh13
-rw-r--r--tests/realmath/generate.py12
-rwxr-xr-xtests/realmath/run-test.sh16
-rw-r--r--tests/share/generate.py12
-rwxr-xr-xtests/share/run-test.sh14
-rwxr-xr-xtests/simple/run-test.sh13
-rw-r--r--tests/tools/autotest.mk7
14 files changed, 184 insertions, 26 deletions
diff --git a/tests/asicworld/run-test.sh b/tests/asicworld/run-test.sh
index 24983f1a..d5708c45 100755
--- a/tests/asicworld/run-test.sh
+++ b/tests/asicworld/run-test.sh
@@ -1,2 +1,14 @@
#!/bin/bash
-exec ${MAKE:-make} -f ../tools/autotest.mk EXTRA_FLAGS="-e" *.v
+
+OPTIND=1
+seed="" # default to no seed specified
+while getopts "S:" opt
+do
+ case "$opt" in
+ S) arg="${OPTARG#"${OPTARG%%[![:space:]]*}"}" # remove leading space
+ seed="SEED=$arg" ;;
+ esac
+done
+shift "$((OPTIND-1))"
+
+exec ${MAKE:-make} -f ../tools/autotest.mk $seed EXTRA_FLAGS="-e" *.v
diff --git a/tests/bram/generate.py b/tests/bram/generate.py
index 05a7ed02..def0b23c 100644
--- a/tests/bram/generate.py
+++ b/tests/bram/generate.py
@@ -1,11 +1,11 @@
#!/usr/bin/env python3
+import argparse
import os
import sys
import random
debug_mode = False
-seed = (int(os.times()[4]*100) + os.getpid()) % 900000 + 100000
def create_bram(dsc_f, sim_f, ref_f, tb_f, k1, k2, or_next):
while True:
@@ -25,12 +25,15 @@ def create_bram(dsc_f, sim_f, ref_f, tb_f, k1, k2, or_next):
if wrmode.count(0) == 0: continue
break
- if random.randrange(2) or True:
+ if random.randrange(2):
maxpol = 4
maxtransp = 1
+ maxclocks = 4
else:
- maxpol = 2
+ maxpol = None
+ clkpol = random.randrange(4)
maxtransp = 2
+ maxclocks = 1
def generate_enable(i):
if wrmode[i]:
@@ -45,11 +48,16 @@ def create_bram(dsc_f, sim_f, ref_f, tb_f, k1, k2, or_next):
return random.randrange(maxtransp)
return 0
- ports = [ random.randrange(1, 3) for i in range(groups) ]
- enable = [ generate_enable(i) for i in range(groups) ]
- transp = [ generate_transp(i) for i in range(groups) ]
- clocks = [ random.randrange(1, 4) for i in range(groups) ]
- clkpol = [ random.randrange(maxpol) for i in range(groups) ]
+ def generate_clkpol(i):
+ if maxpol is None:
+ return clkpol
+ return random.randrange(maxpol)
+
+ ports = [ random.randrange(1, 3) for i in range(groups) ]
+ enable = [ generate_enable(i) for i in range(groups) ]
+ transp = [ generate_transp(i) for i in range(groups) ]
+ clocks = [ random.randrange(maxclocks)+1 for i in range(groups) ]
+ clkpol = [ generate_clkpol(i) for i in range(groups) ]
break
print("bram bram_%02d_%02d" % (k1, k2), file=dsc_f)
@@ -109,11 +117,13 @@ def create_bram(dsc_f, sim_f, ref_f, tb_f, k1, k2, or_next):
if clocks[p1] and not ("CLK%d" % clocks[p1]) in v_ports:
v_ports.add("CLK%d" % clocks[p1])
v_stmts.append("input CLK%d;" % clocks[p1])
- tb_decls.append("reg CLK%d;" % clocks[p1])
+ tb_decls.append("reg CLK%d = 0;" % clocks[p1])
tb_clocks.append("CLK%d" % clocks[p1])
v_ports.add("%sADDR" % pf)
v_stmts.append("input [%d:0] %sADDR;" % (abits-1, pf))
+ if transp[p1]:
+ v_stmts.append("reg [%d:0] %sADDR_Q;" % (abits-1, pf))
tb_decls.append("reg [%d:0] %sADDR;" % (abits-1, pf))
tb_addr.append("%sADDR" % pf)
@@ -159,8 +169,11 @@ def create_bram(dsc_f, sim_f, ref_f, tb_f, k1, k2, or_next):
for i in range(enable[p1]):
enrange = "[%d:%d]" % ((i+1)*dbits/enable[p1]-1, i*dbits/enable[p1])
v_always[last_always_hdr].append((portindex, pf, "if (%sEN[%d]) memory[%sADDR]%s = %sDATA%s;" % (pf, i, pf, enrange, pf, enrange)))
+ elif transp[p1]:
+ v_always[last_always_hdr].append((sum(ports)+1, pf, "%sADDR_Q %s %sADDR;" % (pf, assign_op, pf)))
+ v_stmts.append("always @* %sDATA = memory[%sADDR_Q];" % (pf, pf))
else:
- v_always[last_always_hdr].append((sum(ports)+1 if transp[p1] else 0, pf, "%sDATA %s memory[%sADDR];" % (pf, assign_op, pf)))
+ v_always[last_always_hdr].append((0, pf, "%sDATA %s memory[%sADDR];" % (pf, assign_op, pf)))
for always_hdr in sorted(v_always):
v_stmts.append(always_hdr[1])
@@ -243,10 +256,23 @@ def create_bram(dsc_f, sim_f, ref_f, tb_f, k1, k2, or_next):
print(" end", file=tb_f)
print("endmodule", file=tb_f)
-print("Rng seed: %d" % seed)
+parser = argparse.ArgumentParser(formatter_class = argparse.ArgumentDefaultsHelpFormatter)
+parser.add_argument('-S', '--seed', type = int, help = 'seed for PRNG')
+parser.add_argument('-c', '--count', type = int, default = 5, help = 'number of test cases to generate')
+parser.add_argument('-d', '--debug', action='store_true')
+args = parser.parse_args()
+
+debug_mode = args.debug
+
+if args.seed is not None:
+ seed = args.seed
+else:
+ seed = (int(os.times()[4]*100) + os.getpid()) % 900000 + 100000
+
+print("PRNG seed: %d" % seed)
random.seed(seed)
-for k1 in range(5):
+for k1 in range(args.count):
dsc_f = open("temp/brams_%02d.txt" % k1, "w")
sim_f = open("temp/brams_%02d.v" % k1, "w")
ref_f = open("temp/brams_%02d_ref.v" % k1, "w")
diff --git a/tests/bram/run-single.sh b/tests/bram/run-single.sh
index 19a235c7..98a45b61 100644
--- a/tests/bram/run-single.sh
+++ b/tests/bram/run-single.sh
@@ -2,7 +2,7 @@
set -e
../../yosys -qq -p "proc; opt; memory -nomap -bram temp/brams_${2}.txt; opt -fast -full" \
-l temp/synth_${1}_${2}.log -o temp/synth_${1}_${2}.v temp/brams_${1}.v
-iverilog -Dvcd_file=\"temp/tb_${1}_${2}.vcd\" -DSIMLIB_MEMDELAY=1ns -o temp/tb_${1}_${2}.tb temp/brams_${1}_tb.v \
+iverilog -Dvcd_file=\"temp/tb_${1}_${2}.vcd\" -DSIMLIB_MEMDELAY=1 -o temp/tb_${1}_${2}.tb temp/brams_${1}_tb.v \
temp/brams_${1}_ref.v temp/synth_${1}_${2}.v temp/brams_${2}.v ../../techlibs/common/simlib.v
temp/tb_${1}_${2}.tb > temp/tb_${1}_${2}.txt
if grep -q ERROR temp/tb_${1}_${2}.txt; then
diff --git a/tests/bram/run-test.sh b/tests/bram/run-test.sh
index f0bf0131..d6ba0de4 100755
--- a/tests/bram/run-test.sh
+++ b/tests/bram/run-test.sh
@@ -4,11 +4,26 @@
# MAKE="make -j8" time bash -c 'for ((i=0; i<100; i++)); do echo "-- $i --"; bash run-test.sh || exit 1; done'
set -e
+
+OPTIND=1
+count=5
+seed="" # default to no seed specified
+debug=""
+while getopts "c:dS:" opt
+do
+ case "$opt" in
+ c) count="$OPTARG" ;;
+ d) debug="-d" ;;
+ S) seed="-S $OPTARG" ;;
+ esac
+done
+shift "$((OPTIND-1))"
+
rm -rf temp
mkdir -p temp
echo "generating tests.."
-python3 generate.py
+python3 generate.py $debug -c $count $seed
{
echo -n "all:"
diff --git a/tests/fsm/generate.py b/tests/fsm/generate.py
index 8757d474..c8eda0cd 100644
--- a/tests/fsm/generate.py
+++ b/tests/fsm/generate.py
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
+import argparse
import sys
import random
from contextlib import contextmanager
@@ -30,7 +31,16 @@ def random_expr(variables):
return "%d'd%s" % (bits, random.randint(0, 2**bits-1))
raise AssertionError
-for idx in range(50):
+parser = argparse.ArgumentParser(formatter_class = argparse.ArgumentDefaultsHelpFormatter)
+parser.add_argument('-S', '--seed', type = int, help = 'seed for PRNG')
+parser.add_argument('-c', '--count', type = int, default = 50, help = 'number of test cases to generate')
+args = parser.parse_args()
+
+if args.seed is not None:
+ print("PRNG seed: %d" % args.seed)
+ random.seed(args.seed)
+
+for idx in range(args.count):
with open('temp/uut_%05d.v' % idx, 'w') as f:
with redirect_stdout(f):
rst2 = random.choice([False, True])
diff --git a/tests/fsm/run-test.sh b/tests/fsm/run-test.sh
index 42389233..cf506470 100755
--- a/tests/fsm/run-test.sh
+++ b/tests/fsm/run-test.sh
@@ -5,10 +5,22 @@
set -e
+OPTIND=1
+count=100
+seed="" # default to no seed specified
+while getopts "c:S:" opt
+do
+ case "$opt" in
+ c) count="$OPTARG" ;;
+ S) seed="-S $OPTARG" ;;
+ esac
+done
+shift "$((OPTIND-1))"
+
rm -rf temp
mkdir -p temp
echo "generating tests.."
-python3 generate.py
+python3 generate.py -c $count $seed
{
all_targets="all_targets:"
diff --git a/tests/hana/run-test.sh b/tests/hana/run-test.sh
index fb766eec..878c80b3 100755
--- a/tests/hana/run-test.sh
+++ b/tests/hana/run-test.sh
@@ -1,2 +1,14 @@
#!/bin/bash
-exec ${MAKE:-make} -f ../tools/autotest.mk EXTRA_FLAGS="-l hana_vlib.v -n 300 -e" test_*.v
+
+OPTIND=1
+seed="" # default to no seed specified
+while getopts "S:" opt
+do
+ case "$opt" in
+ S) arg="${OPTARG#"${OPTARG%%[![:space:]]*}"}" # remove leading space
+ seed="SEED=$arg" ;;
+ esac
+done
+shift "$((OPTIND-1))"
+
+exec ${MAKE:-make} -f ../tools/autotest.mk $seed EXTRA_FLAGS="-l hana_vlib.v -n 300 -e" test_*.v
diff --git a/tests/memories/run-test.sh b/tests/memories/run-test.sh
index c3b19618..734a9668 100755
--- a/tests/memories/run-test.sh
+++ b/tests/memories/run-test.sh
@@ -1,7 +1,18 @@
#!/bin/bash
set -e
-bash ../tools/autotest.sh -G *.v
+
+OPTIND=1
+seed="" # default to no seed specified
+while getopts "S:" opt
+do
+ case "$opt" in
+ S) seed="-S $OPTARG" ;;
+ esac
+done
+shift "$((OPTIND-1))"
+
+bash ../tools/autotest.sh $seed -G *.v
for f in `egrep -l 'expect-(wr|rd)-ports' *.v`; do
echo -n "Testing expectations for $f .."
diff --git a/tests/realmath/generate.py b/tests/realmath/generate.py
index 19d01c7c..2bedf38e 100644
--- a/tests/realmath/generate.py
+++ b/tests/realmath/generate.py
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
+import argparse
import sys
import random
from contextlib import contextmanager
@@ -36,7 +37,16 @@ def random_expression(depth = 3, maxparam = 0):
return op + '(' + recursion() + ', ' + recursion() + ')'
raise
-for idx in range(100):
+parser = argparse.ArgumentParser(formatter_class = argparse.ArgumentDefaultsHelpFormatter)
+parser.add_argument('-S', '--seed', type = int, help = 'seed for PRNG')
+parser.add_argument('-c', '--count', type = int, default = 100, help = 'number of test cases to generate')
+args = parser.parse_args()
+
+if args.seed is not None:
+ print("PRNG seed: %d" % args.seed)
+ random.seed(args.seed)
+
+for idx in range(args.count):
with open('temp/uut_%05d.v' % idx, 'w') as f:
with redirect_stdout(f):
print('module uut_%05d(output [63:0] %s);\n' % (idx, ', '.join(['y%02d' % i for i in range(100)])))
diff --git a/tests/realmath/run-test.sh b/tests/realmath/run-test.sh
index f1ec5476..e1a36c69 100755
--- a/tests/realmath/run-test.sh
+++ b/tests/realmath/run-test.sh
@@ -1,14 +1,26 @@
#!/bin/bash
set -e
+OPTIND=1
+count=100
+seed="" # default to no seed specified
+while getopts "c:S:" opt
+do
+ case "$opt" in
+ c) count="$OPTARG" ;;
+ S) seed="-S $OPTARG" ;;
+ esac
+done
+shift "$((OPTIND-1))"
+
rm -rf temp
mkdir -p temp
echo "generating tests.."
-python3 generate.py
+python3 generate.py -c $count $seed
cd temp
echo "running tests.."
-for ((i = 0; i < 100; i++)); do
+for ((i = 0; i < $count; i++)); do
echo -n "[$i]"
idx=$( printf "%05d" $i )
../../../yosys -qq uut_${idx}.ys
diff --git a/tests/share/generate.py b/tests/share/generate.py
index 01a19a8d..7e87bd64 100644
--- a/tests/share/generate.py
+++ b/tests/share/generate.py
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
+import argparse
import sys
import random
from contextlib import contextmanager
@@ -21,7 +22,16 @@ def maybe_plus_x(expr):
else:
return expr
-for idx in range(100):
+parser = argparse.ArgumentParser(formatter_class = argparse.ArgumentDefaultsHelpFormatter)
+parser.add_argument('-S', '--seed', type = int, help = 'seed for PRNG')
+parser.add_argument('-c', '--count', type = int, default = 100, help = 'number of test cases to generate')
+args = parser.parse_args()
+
+if args.seed is not None:
+ print("PRNG seed: %d" % args.seed)
+ random.seed(args.seed)
+
+for idx in range(args.count):
with open('temp/uut_%05d.v' % idx, 'w') as f:
with redirect_stdout(f):
if random.choice(['bin', 'uni']) == 'bin':
diff --git a/tests/share/run-test.sh b/tests/share/run-test.sh
index 18dbbc27..1bcd8e42 100755
--- a/tests/share/run-test.sh
+++ b/tests/share/run-test.sh
@@ -5,10 +5,22 @@
set -e
+OPTIND=1
+count=100
+seed="" # default to no seed specified
+while getopts "c:S:" opt
+do
+ case "$opt" in
+ c) count="$OPTARG" ;;
+ S) seed="-S $OPTARG" ;;
+ esac
+done
+shift "$((OPTIND-1))"
+
rm -rf temp
mkdir -p temp
echo "generating tests.."
-python3 generate.py
+python3 generate.py -c $count $seed
echo "running tests.."
for i in $( ls temp/*.ys | sed 's,[^0-9],,g; s,^0*\(.\),\1,g;' ); do
diff --git a/tests/simple/run-test.sh b/tests/simple/run-test.sh
index 6531d51a..aaa1cf94 100755
--- a/tests/simple/run-test.sh
+++ b/tests/simple/run-test.sh
@@ -1,9 +1,20 @@
#!/bin/bash
+OPTIND=1
+seed="" # default to no seed specified
+while getopts "S:" opt
+do
+ case "$opt" in
+ S) arg="${OPTARG#"${OPTARG%%[![:space:]]*}"}" # remove leading space
+ seed="SEED=$arg" ;;
+ esac
+done
+shift "$((OPTIND-1))"
+
# check for Icarus Verilog
if ! which iverilog > /dev/null ; then
echo "$0: Error: Icarus Verilog 'iverilog' not found."
exit 1
fi
-exec ${MAKE:-make} -f ../tools/autotest.mk *.v
+exec ${MAKE:-make} -f ../tools/autotest.mk $seed *.v
diff --git a/tests/tools/autotest.mk b/tests/tools/autotest.mk
index f65002ce..c6867892 100644
--- a/tests/tools/autotest.mk
+++ b/tests/tools/autotest.mk
@@ -1,8 +1,13 @@
EXTRA_FLAGS=
+SEED=
+
+ifneq ($(strip $(SEED)),)
+SEEDOPT=-S$(SEED)
+endif
$(MAKECMDGOALS):
- @$(basename $(MAKEFILE_LIST)).sh -G -j $(EXTRA_FLAGS) $@
+ @$(basename $(MAKEFILE_LIST)).sh -G -j $(SEEDOPT) $(EXTRA_FLAGS) $@
.PHONY: $(MAKECMDGOALS)