From 0a011e052efcd87791dcdc5e99cac9122f68418c Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Mon, 18 Feb 2019 17:37:52 +0000 Subject: [PATCH] split out edge cases from unit tests into common files --- src/add/test_add.py | 84 ++-------------------------------- src/add/test_add64.py | 84 ++-------------------------------- src/add/test_div.py | 90 +++---------------------------------- src/add/unit_test_double.py | 86 +++++++++++++++++++++++++++++++++++ src/add/unit_test_single.py | 89 ++++++++++++++++++++++++++++++++++++ 5 files changed, 187 insertions(+), 246 deletions(-) diff --git a/src/add/test_add.py b/src/add/test_add.py index a79e2473..110a5fea 100644 --- a/src/add/test_add.py +++ b/src/add/test_add.py @@ -9,7 +9,8 @@ from nmigen_add_experiment import FPADD from unit_test_single import (get_mantissa, get_exponent, get_sign, is_nan, is_inf, is_pos_inf, is_neg_inf, - match, get_case, check_case, run_test) + match, get_case, check_case, run_test, + run_edge_cases) def testbench(dut): yield from check_case(dut, 0xfe34f995, 0xff5d59ad, 0xff800000) @@ -65,86 +66,7 @@ def testbench(dut): count += len(stimulus_a) print (count, "vectors passed") - #edge cases - stimulus_a = [0x80000000 for i in range(1000)] - stimulus_b = [randint(0, 1<<32) for i in range(1000)] - yield from run_test(dut, stimulus_a, stimulus_b, add) - count += len(stimulus_a) - print (count, "vectors passed") - - stimulus_a = [0x00000000 for i in range(1000)] - stimulus_b = [randint(0, 1<<32) for i in range(1000)] - yield from run_test(dut, stimulus_a, stimulus_b, add) - count += len(stimulus_a) - print (count, "vectors passed") - - stimulus_b = [0x80000000 for i in range(1000)] - stimulus_a = [randint(0, 1<<32) for i in range(1000)] - yield from run_test(dut, stimulus_a, stimulus_b, add) - count += len(stimulus_a) - print (count, "vectors passed") - - stimulus_b = [0x00000000 for i in range(1000)] - stimulus_a = [randint(0, 1<<32) for i in range(1000)] - yield from run_test(dut, stimulus_a, stimulus_b, add) - count += len(stimulus_a) - print (count, "vectors passed") - - stimulus_a = [0x7F800000 for i in range(1000)] - stimulus_b = [randint(0, 1<<32) for i in range(1000)] - yield from run_test(dut, stimulus_a, stimulus_b, add) - count += len(stimulus_a) - print (count, "vectors passed") - - stimulus_a = [0xFF800000 for i in range(1000)] - stimulus_b = [randint(0, 1<<32) for i in range(1000)] - yield from run_test(dut, stimulus_a, stimulus_b, add) - count += len(stimulus_a) - print (count, "vectors passed") - - stimulus_b = [0x7F800000 for i in range(1000)] - stimulus_a = [randint(0, 1<<32) for i in range(1000)] - yield from run_test(dut, stimulus_a, stimulus_b, add) - count += len(stimulus_a) - print (count, "vectors passed") - - stimulus_b = [0xFF800000 for i in range(1000)] - stimulus_a = [randint(0, 1<<32) for i in range(1000)] - yield from run_test(dut, stimulus_a, stimulus_b, add) - count += len(stimulus_a) - print (count, "vectors passed") - - stimulus_a = [0x7FC00000 for i in range(1000)] - stimulus_b = [randint(0, 1<<32) for i in range(1000)] - yield from run_test(dut, stimulus_a, stimulus_b, add) - count += len(stimulus_a) - print (count, "vectors passed") - - stimulus_a = [0xFFC00000 for i in range(1000)] - stimulus_b = [randint(0, 1<<32) for i in range(1000)] - yield from run_test(dut, stimulus_a, stimulus_b, add) - count += len(stimulus_a) - print (count, "vectors passed") - - stimulus_b = [0x7FC00000 for i in range(1000)] - stimulus_a = [randint(0, 1<<32) for i in range(1000)] - yield from run_test(dut, stimulus_a, stimulus_b, add) - count += len(stimulus_a) - print (count, "vectors passed") - - stimulus_b = [0xFFC00000 for i in range(1000)] - stimulus_a = [randint(0, 1<<32) for i in range(1000)] - yield from run_test(dut, stimulus_a, stimulus_b, add) - count += len(stimulus_a) - print (count, "vectors passed") - - #seed(0) - for i in range(100000): - stimulus_a = [randint(0, 1<<32) for i in range(1000)] - stimulus_b = [randint(0, 1<<32) for i in range(1000)] - yield from run_test(dut, stimulus_a, stimulus_b, add) - count += 1000 - print (count, "random vectors passed") + yield from run_edge_cases(dut, count, add) if __name__ == '__main__': dut = FPADD(width=32, single_cycle=True) diff --git a/src/add/test_add64.py b/src/add/test_add64.py index 75c68bde..71570f53 100644 --- a/src/add/test_add64.py +++ b/src/add/test_add64.py @@ -11,7 +11,8 @@ from random import seed from unit_test_double import (get_mantissa, get_exponent, get_sign, is_nan, is_inf, is_pos_inf, is_neg_inf, - match, get_case, check_case, run_test) + match, get_case, check_case, run_test, + run_edge_cases) def testbench(dut): @@ -56,86 +57,7 @@ def testbench(dut): count += len(stimulus_a) print (count, "vectors passed") - #edge cases - stimulus_a = [0x8000000000000000 for i in range(1000)] - stimulus_b = [randint(0, 1<<64) for i in range(1000)] - yield from run_test(dut, stimulus_a, stimulus_b, add) - count += len(stimulus_a) - print (count, "vectors passed") - - stimulus_a = [0x0000000000000000 for i in range(1000)] - stimulus_b = [randint(0, 1<<64) for i in range(1000)] - yield from run_test(dut, stimulus_a, stimulus_b, add) - count += len(stimulus_a) - print (count, "vectors passed") - - stimulus_b = [0x8000000000000000 for i in range(1000)] - stimulus_a = [randint(0, 1<<64) for i in range(1000)] - yield from run_test(dut, stimulus_a, stimulus_b, add) - count += len(stimulus_a) - print (count, "vectors passed") - - stimulus_b = [0x0000000000000000 for i in range(1000)] - stimulus_a = [randint(0, 1<<64) for i in range(1000)] - yield from run_test(dut, stimulus_a, stimulus_b, add) - count += len(stimulus_a) - print (count, "vectors passed") - - stimulus_a = [0x7FF8000000000000 for i in range(1000)] - stimulus_b = [randint(0, 1<<64) for i in range(1000)] - yield from run_test(dut, stimulus_a, stimulus_b, add) - count += len(stimulus_a) - print (count, "vectors passed") - - stimulus_a = [0xFFF8000000000000 for i in range(1000)] - stimulus_b = [randint(0, 1<<64) for i in range(1000)] - yield from run_test(dut, stimulus_a, stimulus_b, add) - count += len(stimulus_a) - print (count, "vectors passed") - - stimulus_b = [0x7FF8000000000000 for i in range(1000)] - stimulus_a = [randint(0, 1<<64) for i in range(1000)] - yield from run_test(dut, stimulus_a, stimulus_b, add) - count += len(stimulus_a) - print (count, "vectors passed") - - stimulus_b = [0xFFF8000000000000 for i in range(1000)] - stimulus_a = [randint(0, 1<<64) for i in range(1000)] - yield from run_test(dut, stimulus_a, stimulus_b, add) - count += len(stimulus_a) - print (count, "vectors passed") - - stimulus_a = [0x7FF0000000000000 for i in range(1000)] - stimulus_b = [randint(0, 1<<64) for i in range(1000)] - yield from run_test(dut, stimulus_a, stimulus_b, add) - count += len(stimulus_a) - print (count, "vectors passed") - - stimulus_a = [0xFFF0000000000000 for i in range(1000)] - stimulus_b = [randint(0, 1<<64) for i in range(1000)] - yield from run_test(dut, stimulus_a, stimulus_b, add) - count += len(stimulus_a) - print (count, "vectors passed") - - stimulus_b = [0x7FF0000000000000 for i in range(1000)] - stimulus_a = [randint(0, 1<<64) for i in range(1000)] - yield from run_test(dut, stimulus_a, stimulus_b, add) - count += len(stimulus_a) - print (count, "vectors passed") - - stimulus_b = [0xFFF0000000000000 for i in range(1000)] - stimulus_a = [randint(0, 1<<64) for i in range(1000)] - yield from run_test(dut, stimulus_a, stimulus_b, add) - count += len(stimulus_a) - print (count, "vectors passed") - - #seed(0) - for i in range(100000): - stimulus_a = [randint(0, 1<<64) for i in range(1000)] - stimulus_b = [randint(0, 1<<64) for i in range(1000)] - yield from run_test(dut, stimulus_a, stimulus_b, add) - count += 1000 - print (count, "random vectors passed") + yield from run_edge_cases(dut, count, add) if __name__ == '__main__': diff --git a/src/add/test_div.py b/src/add/test_div.py index 85160e91..d6baa024 100644 --- a/src/add/test_div.py +++ b/src/add/test_div.py @@ -1,6 +1,7 @@ import sys from random import randint from random import seed +from operator import truediv from nmigen import Module, Signal from nmigen.compat.sim import run_simulation @@ -9,11 +10,11 @@ from nmigen_div_experiment import FPDIV from unit_test_single import (get_mantissa, get_exponent, get_sign, is_nan, is_inf, is_pos_inf, is_neg_inf, - match, get_case, check_case, run_test) + match, get_case, check_case, run_test, + run_edge_cases) def testbench(dut): - yield from check_case(dut, 0xbf9b1e94, 0xc038ed3a, 0xc0833e42) yield from check_case(dut, 0x40000000, 0x3F800000, 0x40000000) yield from check_case(dut, 0x3F800000, 0x40000000, 0x3F000000) yield from check_case(dut, 0x3F800000, 0x40400000, 0x3EAAAAAB) @@ -29,7 +30,7 @@ def testbench(dut): #regression tests stimulus_a = [0xbf9b1e94, 0x34082401, 0x5e8ef81, 0x5c75da81, 0x2b017] stimulus_b = [0xc038ed3a, 0xb328cd45, 0x114f3db, 0x2f642a39, 0xff3807ab] - yield from run_test(dut, stimulus_a, stimulus_b) + yield from run_test(dut, stimulus_a, stimulus_b, truediv) count += len(stimulus_a) print (count, "vectors passed") @@ -37,90 +38,11 @@ def testbench(dut): from itertools import permutations stimulus_a = [i[0] for i in permutations([0x80000000, 0x00000000, 0x7f800000, 0xff800000, 0x7fc00000, 0xffc00000], 2)] stimulus_b = [i[1] for i in permutations([0x80000000, 0x00000000, 0x7f800000, 0xff800000, 0x7fc00000, 0xffc00000], 2)] - yield from run_test(dut, stimulus_a, stimulus_b) + yield from run_test(dut, stimulus_a, stimulus_b, truediv) count += len(stimulus_a) print (count, "vectors passed") - #edge cases - stimulus_a = [0x80000000 for i in xrange(1000)] - stimulus_b = [randint(0, 1<<32) for i in xrange(1000)] - yield from run_test(dut, stimulus_a, stimulus_b) - count += len(stimulus_a) - print (count, "vectors passed") - - stimulus_a = [0x00000000 for i in xrange(1000)] - stimulus_b = [randint(0, 1<<32) for i in xrange(1000)] - yield from run_test(dut, stimulus_a, stimulus_b) - count += len(stimulus_a) - print (count, "vectors passed") - - stimulus_b = [0x80000000 for i in xrange(1000)] - stimulus_a = [randint(0, 1<<32) for i in xrange(1000)] - yield from run_test(dut, stimulus_a, stimulus_b) - count += len(stimulus_a) - print (count, "vectors passed") - - stimulus_b = [0x00000000 for i in xrange(1000)] - stimulus_a = [randint(0, 1<<32) for i in xrange(1000)] - yield from run_test(dut, stimulus_a, stimulus_b) - count += len(stimulus_a) - print (count, "vectors passed") - - stimulus_a = [0x7F800000 for i in xrange(1000)] - stimulus_b = [randint(0, 1<<32) for i in xrange(1000)] - yield from run_test(dut, stimulus_a, stimulus_b) - count += len(stimulus_a) - print (count, "vectors passed") - - stimulus_a = [0xFF800000 for i in xrange(1000)] - stimulus_b = [randint(0, 1<<32) for i in xrange(1000)] - yield from run_test(dut, stimulus_a, stimulus_b) - count += len(stimulus_a) - print (count, "vectors passed") - - stimulus_b = [0x7F800000 for i in xrange(1000)] - stimulus_a = [randint(0, 1<<32) for i in xrange(1000)] - yield from run_test(dut, stimulus_a, stimulus_b) - count += len(stimulus_a) - print (count, "vectors passed") - - stimulus_b = [0xFF800000 for i in xrange(1000)] - stimulus_a = [randint(0, 1<<32) for i in xrange(1000)] - yield from run_test(dut, stimulus_a, stimulus_b) - count += len(stimulus_a) - print (count, "vectors passed") - - stimulus_a = [0x7FC00000 for i in xrange(1000)] - stimulus_b = [randint(0, 1<<32) for i in xrange(1000)] - yield from run_test(dut, stimulus_a, stimulus_b) - count += len(stimulus_a) - print (count, "vectors passed") - - stimulus_a = [0xFFC00000 for i in xrange(1000)] - stimulus_b = [randint(0, 1<<32) for i in xrange(1000)] - yield from run_test(dut, stimulus_a, stimulus_b) - count += len(stimulus_a) - print (count, "vectors passed") - - stimulus_b = [0x7FC00000 for i in xrange(1000)] - stimulus_a = [randint(0, 1<<32) for i in xrange(1000)] - yield from run_test(dut, stimulus_a, stimulus_b) - count += len(stimulus_a) - print (count, "vectors passed") - - stimulus_b = [0xFFC00000 for i in xrange(1000)] - stimulus_a = [randint(0, 1<<32) for i in xrange(1000)] - yield from run_test(dut, stimulus_a, stimulus_b) - count += len(stimulus_a) - print (count, "vectors passed") - - #seed(0) - for i in xrange(100000): - stimulus_a = [randint(0, 1<<32) for i in xrange(1000)] - stimulus_b = [randint(0, 1<<32) for i in xrange(1000)] - yield from run_test(dut, stimulus_a, stimulus_b) - count += 1000 - print (count, "random vectors passed") + yield from run_edge_cases(dut, count, truediv) if __name__ == '__main__': diff --git a/src/add/unit_test_double.py b/src/add/unit_test_double.py index 25df4b9f..ffab00c4 100644 --- a/src/add/unit_test_double.py +++ b/src/add/unit_test_double.py @@ -1,4 +1,7 @@ import sys +from random import randint +from random import seed + from sfpy import Float64 def get_mantissa(x): @@ -115,3 +118,86 @@ def run_test(dut, stimulus_a, stimulus_b, op): sys.exit(0) + +def run_edge_cases(dut, count, op): + #edge cases + stimulus_a = [0x8000000000000000 for i in range(1000)] + stimulus_b = [randint(0, 1<<64) for i in range(1000)] + yield from run_test(dut, stimulus_a, stimulus_b, op) + count += len(stimulus_a) + print (count, "vectors passed") + + stimulus_a = [0x0000000000000000 for i in range(1000)] + stimulus_b = [randint(0, 1<<64) for i in range(1000)] + yield from run_test(dut, stimulus_a, stimulus_b, op) + count += len(stimulus_a) + print (count, "vectors passed") + + stimulus_b = [0x8000000000000000 for i in range(1000)] + stimulus_a = [randint(0, 1<<64) for i in range(1000)] + yield from run_test(dut, stimulus_a, stimulus_b, op) + count += len(stimulus_a) + print (count, "vectors passed") + + stimulus_b = [0x0000000000000000 for i in range(1000)] + stimulus_a = [randint(0, 1<<64) for i in range(1000)] + yield from run_test(dut, stimulus_a, stimulus_b, op) + count += len(stimulus_a) + print (count, "vectors passed") + + stimulus_a = [0x7FF8000000000000 for i in range(1000)] + stimulus_b = [randint(0, 1<<64) for i in range(1000)] + yield from run_test(dut, stimulus_a, stimulus_b, op) + count += len(stimulus_a) + print (count, "vectors passed") + + stimulus_a = [0xFFF8000000000000 for i in range(1000)] + stimulus_b = [randint(0, 1<<64) for i in range(1000)] + yield from run_test(dut, stimulus_a, stimulus_b, op) + count += len(stimulus_a) + print (count, "vectors passed") + + stimulus_b = [0x7FF8000000000000 for i in range(1000)] + stimulus_a = [randint(0, 1<<64) for i in range(1000)] + yield from run_test(dut, stimulus_a, stimulus_b, op) + count += len(stimulus_a) + print (count, "vectors passed") + + stimulus_b = [0xFFF8000000000000 for i in range(1000)] + stimulus_a = [randint(0, 1<<64) for i in range(1000)] + yield from run_test(dut, stimulus_a, stimulus_b, op) + count += len(stimulus_a) + print (count, "vectors passed") + + stimulus_a = [0x7FF0000000000000 for i in range(1000)] + stimulus_b = [randint(0, 1<<64) for i in range(1000)] + yield from run_test(dut, stimulus_a, stimulus_b, op) + count += len(stimulus_a) + print (count, "vectors passed") + + stimulus_a = [0xFFF0000000000000 for i in range(1000)] + stimulus_b = [randint(0, 1<<64) for i in range(1000)] + yield from run_test(dut, stimulus_a, stimulus_b, op) + count += len(stimulus_a) + print (count, "vectors passed") + + stimulus_b = [0x7FF0000000000000 for i in range(1000)] + stimulus_a = [randint(0, 1<<64) for i in range(1000)] + yield from run_test(dut, stimulus_a, stimulus_b, op) + count += len(stimulus_a) + print (count, "vectors passed") + + stimulus_b = [0xFFF0000000000000 for i in range(1000)] + stimulus_a = [randint(0, 1<<64) for i in range(1000)] + yield from run_test(dut, stimulus_a, stimulus_b, op) + count += len(stimulus_a) + print (count, "vectors passed") + + #seed(0) + for i in range(100000): + stimulus_a = [randint(0, 1<<64) for i in range(1000)] + stimulus_b = [randint(0, 1<<64) for i in range(1000)] + yield from run_test(dut, stimulus_a, stimulus_b, op) + count += 1000 + print (count, "random vectors passed") + diff --git a/src/add/unit_test_single.py b/src/add/unit_test_single.py index a68907ba..b2396131 100644 --- a/src/add/unit_test_single.py +++ b/src/add/unit_test_single.py @@ -1,3 +1,6 @@ +from random import randint +from random import seed + import sys from sfpy import Float32 @@ -111,3 +114,89 @@ def run_test(dut, stimulus_a, stimulus_b, op): sys.exit(0) +def run_edge_cases(dut, count, op): + #edge cases + stimulus_a = [0x80000000 for i in range(1000)] + stimulus_b = [randint(0, 1<<32) for i in range(1000)] + yield from run_test(dut, stimulus_a, stimulus_b, op) + count += len(stimulus_a) + print (count, "vectors passed") + + stimulus_a = [0x00000000 for i in range(1000)] + stimulus_b = [randint(0, 1<<32) for i in range(1000)] + yield from run_test(dut, stimulus_a, stimulus_b, op) + count += len(stimulus_a) + print (count, "vectors passed") + + stimulus_b = [0x80000000 for i in range(1000)] + stimulus_a = [randint(0, 1<<32) for i in range(1000)] + yield from run_test(dut, stimulus_a, stimulus_b, op) + count += len(stimulus_a) + print (count, "vectors passed") + + stimulus_b = [0x00000000 for i in range(1000)] + stimulus_a = [randint(0, 1<<32) for i in range(1000)] + yield from run_test(dut, stimulus_a, stimulus_b, op) + count += len(stimulus_a) + print (count, "vectors passed") + + stimulus_a = [0x7F800000 for i in range(1000)] + stimulus_b = [randint(0, 1<<32) for i in range(1000)] + yield from run_test(dut, stimulus_a, stimulus_b, op) + count += len(stimulus_a) + print (count, "vectors passed") + + stimulus_a = [0xFF800000 for i in range(1000)] + stimulus_b = [randint(0, 1<<32) for i in range(1000)] + yield from run_test(dut, stimulus_a, stimulus_b, op) + count += len(stimulus_a) + print (count, "vectors passed") + + stimulus_b = [0x7F800000 for i in range(1000)] + stimulus_a = [randint(0, 1<<32) for i in range(1000)] + yield from run_test(dut, stimulus_a, stimulus_b, op) + count += len(stimulus_a) + print (count, "vectors passed") + + stimulus_b = [0xFF800000 for i in range(1000)] + stimulus_a = [randint(0, 1<<32) for i in range(1000)] + yield from run_test(dut, stimulus_a, stimulus_b, op) + count += len(stimulus_a) + print (count, "vectors passed") + + stimulus_a = [0x7FC00000 for i in range(1000)] + stimulus_b = [randint(0, 1<<32) for i in range(1000)] + yield from run_test(dut, stimulus_a, stimulus_b, op) + count += len(stimulus_a) + print (count, "vectors passed") + + stimulus_a = [0xFFC00000 for i in range(1000)] + stimulus_b = [randint(0, 1<<32) for i in range(1000)] + yield from run_test(dut, stimulus_a, stimulus_b, op) + count += len(stimulus_a) + print (count, "vectors passed") + + stimulus_b = [0x7FC00000 for i in range(1000)] + stimulus_a = [randint(0, 1<<32) for i in range(1000)] + yield from run_test(dut, stimulus_a, stimulus_b, op) + count += len(stimulus_a) + print (count, "vectors passed") + + stimulus_b = [0xFFC00000 for i in range(1000)] + stimulus_a = [randint(0, 1<<32) for i in range(1000)] + yield from run_test(dut, stimulus_a, stimulus_b, op) + count += len(stimulus_a) + print (count, "vectors passed") + + #seed(0) + for i in range(100000): + stimulus_a = [randint(0, 1<<32) for i in range(1000)] + stimulus_b = [randint(0, 1<<32) for i in range(1000)] + yield from run_test(dut, stimulus_a, stimulus_b, op) + count += 1000 + print (count, "random vectors passed") + +if __name__ == '__main__': + dut = FPADD(width=32, single_cycle=True) + run_simulation(dut, testbench(dut), vcd_name="test_add.vcd") + -- 2.30.2