From ccd4d65a7bd2985edb5547daf7df623cda5ab9da Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Thu, 14 Mar 2019 04:33:01 +0000 Subject: [PATCH] make a bit of a mess of the unit tests, getting mul up and running again taking a copy (sigh) of the old version of check_case and get_case --- src/add/test_add.py | 96 ++++++++++++++++++------------------- src/add/test_mul.py | 6 +-- src/add/unit_test_single.py | 83 +++++++++++++++++++++++++------- 3 files changed, 117 insertions(+), 68 deletions(-) diff --git a/src/add/test_add.py b/src/add/test_add.py index d63c26f1..989cf482 100644 --- a/src/add/test_add.py +++ b/src/add/test_add.py @@ -7,54 +7,54 @@ 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_rs_case, check_rs_case, run_test, run_edge_cases, run_corner_cases) def testbench(dut): - yield from check_case(dut, 0x36093399, 0x7f6a12f1, 0x7f6a12f1) - yield from check_case(dut, 0x006CE3EE, 0x806CE3EC, 0x00000002) - yield from check_case(dut, 0x00000047, 0x80000048, 0x80000001) - yield from check_case(dut, 0x000116C2, 0x8001170A, 0x80000048) - yield from check_case(dut, 0x7ed01f25, 0xff559e2c, 0xfedb1d33) - yield from check_case(dut, 0, 0, 0) - yield from check_case(dut, 0xFFFFFFFF, 0xC63B800A, 0x7FC00000) - yield from check_case(dut, 0xFF800000, 0x7F800000, 0x7FC00000) - #yield from check_case(dut, 0xFF800000, 0x7F800000, 0x7FC00000) - yield from check_case(dut, 0x7F800000, 0xFF800000, 0x7FC00000) - yield from check_case(dut, 0x42540000, 0xC2540000, 0x00000000) - yield from check_case(dut, 0xC2540000, 0x42540000, 0x00000000) - yield from check_case(dut, 0xfe34f995, 0xff5d59ad, 0xff800000) - yield from check_case(dut, 0x82471f51, 0x243985f, 0x801c3790) - yield from check_case(dut, 0x40000000, 0xc0000000, 0x00000000) - yield from check_case(dut, 0x3F800000, 0x40000000, 0x40400000) - yield from check_case(dut, 0x40000000, 0x3F800000, 0x40400000) - yield from check_case(dut, 0x447A0000, 0x4488B000, 0x4502D800) - yield from check_case(dut, 0x463B800A, 0x42BA8A3D, 0x463CF51E) - yield from check_case(dut, 0x42BA8A3D, 0x463B800A, 0x463CF51E) - yield from check_case(dut, 0x463B800A, 0xC2BA8A3D, 0x463A0AF6) - yield from check_case(dut, 0xC2BA8A3D, 0x463B800A, 0x463A0AF6) - yield from check_case(dut, 0xC63B800A, 0x42BA8A3D, 0xC63A0AF6) - yield from check_case(dut, 0x42BA8A3D, 0xC63B800A, 0xC63A0AF6) - yield from check_case(dut, 0x7F800000, 0x00000000, 0x7F800000) - yield from check_case(dut, 0x00000000, 0x7F800000, 0x7F800000) - yield from check_case(dut, 0xFF800000, 0x00000000, 0xFF800000) - yield from check_case(dut, 0x00000000, 0xFF800000, 0xFF800000) - yield from check_case(dut, 0x7F800000, 0x7F800000, 0x7F800000) - yield from check_case(dut, 0xFF800000, 0xFF800000, 0xFF800000) - yield from check_case(dut, 0xFF800000, 0x7F800000, 0x7FC00000) - yield from check_case(dut, 0x00018643, 0x00FA72A4, 0x00FBF8E7) - yield from check_case(dut, 0x001A2239, 0x00FA72A4, 0x010A4A6E) - yield from check_case(dut, 0x3F7FFFFE, 0x3F7FFFFE, 0x3FFFFFFE) - yield from check_case(dut, 0x7EFFFFEE, 0x7EFFFFEE, 0x7F7FFFEE) - yield from check_case(dut, 0x7F7FFFEE, 0xFEFFFFEE, 0x7EFFFFEE) - yield from check_case(dut, 0x7F7FFFEE, 0x756CA884, 0x7F7FFFFD) - yield from check_case(dut, 0x7F7FFFEE, 0x758A0CF8, 0x7F7FFFFF) - yield from check_case(dut, 0x42500000, 0x51A7A358, 0x51A7A358) - yield from check_case(dut, 0x51A7A358, 0x42500000, 0x51A7A358) - yield from check_case(dut, 0x4E5693A4, 0x42500000, 0x4E5693A5) - yield from check_case(dut, 0x42500000, 0x4E5693A4, 0x4E5693A5) - #yield from check_case(dut, 1, 0, 1) - #yield from check_case(dut, 1, 1, 1) + yield from check_rs_case(dut, 0x36093399, 0x7f6a12f1, 0x7f6a12f1) + yield from check_rs_case(dut, 0x006CE3EE, 0x806CE3EC, 0x00000002) + yield from check_rs_case(dut, 0x00000047, 0x80000048, 0x80000001) + yield from check_rs_case(dut, 0x000116C2, 0x8001170A, 0x80000048) + yield from check_rs_case(dut, 0x7ed01f25, 0xff559e2c, 0xfedb1d33) + yield from check_rs_case(dut, 0, 0, 0) + yield from check_rs_case(dut, 0xFFFFFFFF, 0xC63B800A, 0x7FC00000) + yield from check_rs_case(dut, 0xFF800000, 0x7F800000, 0x7FC00000) + #yield from check_rs_case(dut, 0xFF800000, 0x7F800000, 0x7FC00000) + yield from check_rs_case(dut, 0x7F800000, 0xFF800000, 0x7FC00000) + yield from check_rs_case(dut, 0x42540000, 0xC2540000, 0x00000000) + yield from check_rs_case(dut, 0xC2540000, 0x42540000, 0x00000000) + yield from check_rs_case(dut, 0xfe34f995, 0xff5d59ad, 0xff800000) + yield from check_rs_case(dut, 0x82471f51, 0x243985f, 0x801c3790) + yield from check_rs_case(dut, 0x40000000, 0xc0000000, 0x00000000) + yield from check_rs_case(dut, 0x3F800000, 0x40000000, 0x40400000) + yield from check_rs_case(dut, 0x40000000, 0x3F800000, 0x40400000) + yield from check_rs_case(dut, 0x447A0000, 0x4488B000, 0x4502D800) + yield from check_rs_case(dut, 0x463B800A, 0x42BA8A3D, 0x463CF51E) + yield from check_rs_case(dut, 0x42BA8A3D, 0x463B800A, 0x463CF51E) + yield from check_rs_case(dut, 0x463B800A, 0xC2BA8A3D, 0x463A0AF6) + yield from check_rs_case(dut, 0xC2BA8A3D, 0x463B800A, 0x463A0AF6) + yield from check_rs_case(dut, 0xC63B800A, 0x42BA8A3D, 0xC63A0AF6) + yield from check_rs_case(dut, 0x42BA8A3D, 0xC63B800A, 0xC63A0AF6) + yield from check_rs_case(dut, 0x7F800000, 0x00000000, 0x7F800000) + yield from check_rs_case(dut, 0x00000000, 0x7F800000, 0x7F800000) + yield from check_rs_case(dut, 0xFF800000, 0x00000000, 0xFF800000) + yield from check_rs_case(dut, 0x00000000, 0xFF800000, 0xFF800000) + yield from check_rs_case(dut, 0x7F800000, 0x7F800000, 0x7F800000) + yield from check_rs_case(dut, 0xFF800000, 0xFF800000, 0xFF800000) + yield from check_rs_case(dut, 0xFF800000, 0x7F800000, 0x7FC00000) + yield from check_rs_case(dut, 0x00018643, 0x00FA72A4, 0x00FBF8E7) + yield from check_rs_case(dut, 0x001A2239, 0x00FA72A4, 0x010A4A6E) + yield from check_rs_case(dut, 0x3F7FFFFE, 0x3F7FFFFE, 0x3FFFFFFE) + yield from check_rs_case(dut, 0x7EFFFFEE, 0x7EFFFFEE, 0x7F7FFFEE) + yield from check_rs_case(dut, 0x7F7FFFEE, 0xFEFFFFEE, 0x7EFFFFEE) + yield from check_rs_case(dut, 0x7F7FFFEE, 0x756CA884, 0x7F7FFFFD) + yield from check_rs_case(dut, 0x7F7FFFEE, 0x758A0CF8, 0x7F7FFFFF) + yield from check_rs_case(dut, 0x42500000, 0x51A7A358, 0x51A7A358) + yield from check_rs_case(dut, 0x51A7A358, 0x42500000, 0x51A7A358) + yield from check_rs_case(dut, 0x4E5693A4, 0x42500000, 0x4E5693A5) + yield from check_rs_case(dut, 0x42500000, 0x4E5693A4, 0x4E5693A5) + #yield from check_rs_case(dut, 1, 0, 1) + #yield from check_rs_case(dut, 1, 1, 1) count = 0 @@ -65,12 +65,12 @@ def testbench(dut): stimulus_b = [0xff800001, 0xadd79efa, 0xC0000000, 0x1c800000, 0xc038ed3a, 0xb328cd45, 0x114f3db, 0x2f642a39, 0xff3807ab] - yield from run_test(dut, stimulus_a, stimulus_b, add) + yield from run_test(dut, stimulus_a, stimulus_b, add, get_rs_case) count += len(stimulus_a) print (count, "vectors passed") - yield from run_corner_cases(dut, count, add) - yield from run_edge_cases(dut, count, add) + yield from run_corner_cases(dut, count, add, get_rs_case) + yield from run_edge_cases(dut, count, add, get_rs_case) if __name__ == '__main__': dut = FPADD(width=32, id_wid=5, single_cycle=True) diff --git a/src/add/test_mul.py b/src/add/test_mul.py index 9706b0b9..21d82528 100644 --- a/src/add/test_mul.py +++ b/src/add/test_mul.py @@ -25,12 +25,12 @@ def testbench(dut): 0x5c75da81, 0x2b017] stimulus_b = [0xee1818c5, 0xc038ed3a, 0xb328cd45, 0x114f3db, 0x2f642a39, 0xff3807ab] - yield from run_test(dut, stimulus_a, stimulus_b, mul) + yield from run_test(dut, stimulus_a, stimulus_b, mul, get_case) count += len(stimulus_a) print (count, "vectors passed") - yield from run_corner_cases(dut, count, mul) - yield from run_edge_cases(dut, count, mul) + yield from run_corner_cases(dut, count, mul, get_case) + yield from run_edge_cases(dut, count, mul, get_case) if __name__ == '__main__': diff --git a/src/add/unit_test_single.py b/src/add/unit_test_single.py index 3c3c6291..c0601288 100644 --- a/src/add/unit_test_single.py +++ b/src/add/unit_test_single.py @@ -36,7 +36,7 @@ def match(x, y): (x == y) ) -def get_case(dut, a, b, mid): +def get_rs_case(dut, a, b, mid): in_a, in_b = dut.rs[0] out_z = dut.res[0] yield dut.ids.in_mid.eq(mid) @@ -75,6 +75,52 @@ def get_case(dut, a, b, mid): return vout_z, mid +def check_rs_case(dut, a, b, z, mid=None): + if mid is None: + mid = randint(0, 6) + mid = 0 + out_z, out_mid = yield from get_rs_case(dut, a, b, mid) + assert out_z == z, "Output z 0x%x not equal to expected 0x%x" % (out_z, z) + assert out_mid == mid, "Output mid 0x%x != expected 0x%x" % (out_mid, mid) + + +def get_case(dut, a, b, mid): + #yield dut.in_mid.eq(mid) + yield dut.in_a.v.eq(a) + yield dut.in_a.stb.eq(1) + yield + yield + yield + yield + a_ack = (yield dut.in_a.ack) + assert a_ack == 0 + + yield dut.in_a.stb.eq(0) + + yield dut.in_b.v.eq(b) + yield dut.in_b.stb.eq(1) + yield + yield + b_ack = (yield dut.in_b.ack) + assert b_ack == 0 + + yield dut.in_b.stb.eq(0) + + yield dut.out_z.ack.eq(1) + + while True: + out_z_stb = (yield dut.out_z.stb) + if not out_z_stb: + yield + continue + out_z = yield dut.out_z.v + #out_mid = yield dut.out_mid + yield dut.out_z.ack.eq(0) + yield + break + + return out_z, mid # TODO: mid + def check_case(dut, a, b, z, mid=None): if mid is None: mid = randint(0, 6) @@ -84,7 +130,7 @@ def check_case(dut, a, b, z, mid=None): assert out_mid == mid, "Output mid 0x%x != expected 0x%x" % (out_mid, mid) -def run_test(dut, stimulus_a, stimulus_b, op): +def run_test(dut, stimulus_a, stimulus_b, op, get_case_fn): expected_responses = [] actual_responses = [] @@ -96,7 +142,7 @@ def run_test(dut, stimulus_a, stimulus_b, op): z = op(af, bf) expected_responses.append((z.get_bits(), mid)) #print (af, bf, z) - actual = yield from get_case(dut, a, b, mid) + actual = yield from get_case_fn(dut, a, b, mid) actual_responses.append(actual) if len(actual_responses) < len(expected_responses): @@ -112,6 +158,8 @@ def run_test(dut, stimulus_a, stimulus_b, op): if not passed: + expected = expected[0] + actual = actual[0] print ("Fail ... expected:", hex(expected), "actual:", hex(actual)) print (hex(a)) @@ -139,20 +187,20 @@ def run_test(dut, stimulus_a, stimulus_b, op): corner_cases = [0x80000000, 0x00000000, 0x7f800000, 0xff800000, 0x7fc00000, 0xffc00000] -def run_corner_cases(dut, count, op): +def run_corner_cases(dut, count, op, get_case_fn): #corner cases from itertools import permutations stimulus_a = [i[0] for i in permutations(corner_cases, 2)] stimulus_b = [i[1] for i in permutations(corner_cases, 2)] - yield from run_test(dut, stimulus_a, stimulus_b, op) + yield from run_test(dut, stimulus_a, stimulus_b, op, get_case_fn) count += len(stimulus_a) print (count, "vectors passed") -def run_test_2(dut, stimulus_a, stimulus_b, op): - yield from run_test(dut, stimulus_a, stimulus_b, op) - yield from run_test(dut, stimulus_b, stimulus_a, op) +def run_test_2(dut, stimulus_a, stimulus_b, op, get_case_fn): + yield from run_test(dut, stimulus_a, stimulus_b, op, get_case_fn) + yield from run_test(dut, stimulus_b, stimulus_a, op, get_case_fn) -def run_cases(dut, count, op, fixed_num, num_entries): +def run_cases(dut, count, op, fixed_num, num_entries, get_case_fn): if isinstance(fixed_num, int): stimulus_a = [fixed_num for i in range(num_entries)] report = hex(fixed_num) @@ -161,47 +209,48 @@ def run_cases(dut, count, op, fixed_num, num_entries): report = "random" stimulus_b = [randint(0, 1<<32) for i in range(num_entries)] - yield from run_test_2(dut, stimulus_a, stimulus_b, op) + yield from run_test_2(dut, stimulus_a, stimulus_b, op, get_case_fn) count += len(stimulus_a) print (count, "vectors passed 2^32", report) # non-canonical NaNs. stimulus_b = [set_exponent(randint(0, 1<<32), 128) \ for i in range(num_entries)] - yield from run_test_2(dut, stimulus_a, stimulus_b, op) + yield from run_test_2(dut, stimulus_a, stimulus_b, op, get_case_fn) count += len(stimulus_a) print (count, "vectors passed Non-Canonical NaN", report) # -127 stimulus_b = [set_exponent(randint(0, 1<<32), -127) \ for i in range(num_entries)] - yield from run_test_2(dut, stimulus_a, stimulus_b, op) + yield from run_test_2(dut, stimulus_a, stimulus_b, op, get_case_fn) count += len(stimulus_a) print (count, "vectors passed exp=-127", report) # nearly zero stimulus_b = [set_exponent(randint(0, 1<<32), -126) \ for i in range(num_entries)] - yield from run_test_2(dut, stimulus_a, stimulus_b, op) + yield from run_test_2(dut, stimulus_a, stimulus_b, op, get_case_fn) count += len(stimulus_a) print (count, "vectors passed exp=-126", report) # nearly inf stimulus_b = [set_exponent(randint(0, 1<<32), 127) \ for i in range(num_entries)] - yield from run_test_2(dut, stimulus_a, stimulus_b, op) + yield from run_test_2(dut, stimulus_a, stimulus_b, op, get_case_fn) count += len(stimulus_a) print (count, "vectors passed exp=127", report) return count -def run_edge_cases(dut, count, op): +def run_edge_cases(dut, count, op, get_case_fn): #edge cases for testme in corner_cases: - count = yield from run_cases(dut, count, op, testme, 10) + count = yield from run_cases(dut, count, op, testme, 10, get_case_fn) for i in range(100000): stimulus_a = [randint(0, 1<<32) for i in range(10)] - count = yield from run_cases(dut, count, op, stimulus_a, 10) + count = yield from run_cases(dut, count, op, stimulus_a, 10, + get_case_fn) return count -- 2.30.2