From 927778d06a1b86539512186ee66bf44ac6485203 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Mon, 18 Feb 2019 17:30:25 +0000 Subject: [PATCH] add operator argument to unit tests --- src/add/test_add.py | 33 ++++++++++++++++----------------- src/add/test_add64.py | 31 ++++++++++++++++--------------- src/add/test_div.py | 1 + src/add/unit_test_double.py | 4 ++-- src/add/unit_test_single.py | 4 ++-- 5 files changed, 37 insertions(+), 36 deletions(-) diff --git a/src/add/test_add.py b/src/add/test_add.py index 69c5e477..a79e2473 100644 --- a/src/add/test_add.py +++ b/src/add/test_add.py @@ -1,7 +1,6 @@ -import sys -import subprocess from random import randint from random import seed +from operator import add from nmigen import Module, Signal from nmigen.compat.sim import run_simulation @@ -54,7 +53,7 @@ def testbench(dut): #regression tests stimulus_a = [0x22cb525a, 0x40000000, 0x83e73d5c, 0xbf9b1e94, 0x34082401, 0x5e8ef81, 0x5c75da81, 0x2b017] stimulus_b = [0xadd79efa, 0xC0000000, 0x1c800000, 0xc038ed3a, 0xb328cd45, 0x114f3db, 0x2f642a39, 0xff3807ab] - yield from run_test(dut, stimulus_a, stimulus_b) + yield from run_test(dut, stimulus_a, stimulus_b, add) count += len(stimulus_a) print (count, "vectors passed") @@ -62,80 +61,80 @@ 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, add) 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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) + yield from run_test(dut, stimulus_a, stimulus_b, add) count += len(stimulus_a) print (count, "vectors passed") @@ -143,7 +142,7 @@ def testbench(dut): 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) + yield from run_test(dut, stimulus_a, stimulus_b, add) count += 1000 print (count, "random vectors passed") diff --git a/src/add/test_add64.py b/src/add/test_add64.py index ecb5dcc2..75c68bde 100644 --- a/src/add/test_add64.py +++ b/src/add/test_add64.py @@ -1,5 +1,6 @@ from nmigen import Module, Signal from nmigen.compat.sim import run_simulation +from operator import add from nmigen_add_experiment import FPADD @@ -29,7 +30,7 @@ def testbench(dut): #regression tests stimulus_a = [0x3ff00000000000c5, 0xff80000000000000] stimulus_b = [0xbd28a404211fb72b, 0x7f80000000000000] - yield from run_test(dut, stimulus_a, stimulus_b) + yield from run_test(dut, stimulus_a, stimulus_b, add) count += len(stimulus_a) print (count, "vectors passed") @@ -51,80 +52,80 @@ def testbench(dut): 0x7ff0000000000000, 0xfff0000000000000 ], 2)] - yield from run_test(dut, stimulus_a, stimulus_b) + yield from run_test(dut, stimulus_a, stimulus_b, add) 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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) + yield from run_test(dut, stimulus_a, stimulus_b, add) count += len(stimulus_a) print (count, "vectors passed") @@ -132,7 +133,7 @@ def testbench(dut): 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) + yield from run_test(dut, stimulus_a, stimulus_b, add) count += 1000 print (count, "random vectors passed") diff --git a/src/add/test_div.py b/src/add/test_div.py index 80311123..85160e91 100644 --- a/src/add/test_div.py +++ b/src/add/test_div.py @@ -13,6 +13,7 @@ from unit_test_single import (get_mantissa, get_exponent, get_sign, is_nan, 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) diff --git a/src/add/unit_test_double.py b/src/add/unit_test_double.py index 3d69d8e0..25df4b9f 100644 --- a/src/add/unit_test_double.py +++ b/src/add/unit_test_double.py @@ -64,14 +64,14 @@ def check_case(dut, a, b, z): assert out_z == z, "Output z 0x%x not equal to expected 0x%x" % (out_z, z) -def run_test(dut, stimulus_a, stimulus_b): +def run_test(dut, stimulus_a, stimulus_b, op): expected_responses = [] actual_responses = [] for a, b in zip(stimulus_a, stimulus_b): af = Float64.from_bits(a) bf = Float64.from_bits(b) - z = af + bf + z = op(af, bf) expected_responses.append(z.get_bits()) #print (af, bf, z) actual = yield from get_case(dut, a, b) diff --git a/src/add/unit_test_single.py b/src/add/unit_test_single.py index ca33efb1..a68907ba 100644 --- a/src/add/unit_test_single.py +++ b/src/add/unit_test_single.py @@ -64,14 +64,14 @@ def check_case(dut, a, b, z): assert out_z == z, "Output z 0x%x not equal to expected 0x%x" % (out_z, z) -def run_test(dut, stimulus_a, stimulus_b): +def run_test(dut, stimulus_a, stimulus_b, op): expected_responses = [] actual_responses = [] for a, b in zip(stimulus_a, stimulus_b): af = Float32.from_bits(a) bf = Float32.from_bits(b) - z = af + bf + z = op(af, bf) expected_responses.append(z.get_bits()) #print (af, bf, z) actual = yield from get_case(dut, a, b) -- 2.30.2