From: Luke Kenneth Casson Leighton Date: Thu, 2 May 2019 22:31:32 +0000 (+0100) Subject: pass in count and num loops to unit test to make it shorter X-Git-Tag: ls180-24jan2020~1062 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=3cd9a94a65be2121db5f95297631a890238f285c;p=ieee754fpu.git pass in count and num loops to unit test to make it shorter --- diff --git a/src/ieee754/fpcommon/test/unit_test_double.py b/src/ieee754/fpcommon/test/unit_test_double.py index 8cc097f2..feed8ffa 100644 --- a/src/ieee754/fpcommon/test/unit_test_double.py +++ b/src/ieee754/fpcommon/test/unit_test_double.py @@ -143,85 +143,85 @@ def run_corner_cases(dut, count, op): print (count, "vectors passed") -def run_edge_cases(dut, count, op): +def run_edge_cases(dut, count, op, maxcount=1000, num_loops=1000): #edge cases - stimulus_a = [0x8000000000000000 for i in range(1000)] - stimulus_b = [randint(0, 1<<64) for i in range(1000)] + stimulus_a = [0x8000000000000000 for i in range(maxcount)] + stimulus_b = [randint(0, 1<<64) for i in range(maxcount)] 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)] + stimulus_a = [0x0000000000000000 for i in range(maxcount)] + stimulus_b = [randint(0, 1<<64) for i in range(maxcount)] 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)] + stimulus_b = [0x8000000000000000 for i in range(maxcount)] + stimulus_a = [randint(0, 1<<64) for i in range(maxcount)] 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)] + stimulus_b = [0x0000000000000000 for i in range(maxcount)] + stimulus_a = [randint(0, 1<<64) for i in range(maxcount)] 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)] + stimulus_a = [0x7FF8000000000000 for i in range(maxcount)] + stimulus_b = [randint(0, 1<<64) for i in range(maxcount)] 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)] + stimulus_a = [0xFFF8000000000000 for i in range(maxcount)] + stimulus_b = [randint(0, 1<<64) for i in range(maxcount)] 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)] + stimulus_b = [0x7FF8000000000000 for i in range(maxcount)] + stimulus_a = [randint(0, 1<<64) for i in range(maxcount)] 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)] + stimulus_b = [0xFFF8000000000000 for i in range(maxcount)] + stimulus_a = [randint(0, 1<<64) for i in range(maxcount)] 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)] + stimulus_a = [0x7FF0000000000000 for i in range(maxcount)] + stimulus_b = [randint(0, 1<<64) for i in range(maxcount)] 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)] + stimulus_a = [0xFFF0000000000000 for i in range(maxcount)] + stimulus_b = [randint(0, 1<<64) for i in range(maxcount)] 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)] + stimulus_b = [0x7FF0000000000000 for i in range(maxcount)] + stimulus_a = [randint(0, 1<<64) for i in range(maxcount)] 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)] + stimulus_b = [0xFFF0000000000000 for i in range(maxcount)] + stimulus_a = [randint(0, 1<<64) for i in range(maxcount)] 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)] + for i in range(num_loops): + stimulus_a = [randint(0, 1<<64) for i in range(maxcount)] + stimulus_b = [randint(0, 1<<64) for i in range(maxcount)] yield from run_test(dut, stimulus_a, stimulus_b, op) - count += 1000 + count += maxcount print (count, "random vectors passed") diff --git a/src/ieee754/fpcommon/test/unit_test_half.py b/src/ieee754/fpcommon/test/unit_test_half.py index 73c9b653..2f072905 100644 --- a/src/ieee754/fpcommon/test/unit_test_half.py +++ b/src/ieee754/fpcommon/test/unit_test_half.py @@ -125,9 +125,8 @@ def run_corner_cases(dut, count, op): print (count, "vectors passed") -def run_edge_cases(dut, count, op): +def run_edge_cases(dut, count, op, maxcount=10, num_loops=1000): maxint16 = 1<<16 - maxcount = 10 #edge cases stimulus_a = [0x8000 for i in range(maxcount)] stimulus_b = [randint(0, maxint16-1) for i in range(maxcount)] @@ -202,7 +201,7 @@ def run_edge_cases(dut, count, op): print (count, "vectors passed") #seed(0) - for i in range(100000): + for i in range(num_loops): stimulus_a = [randint(0, maxint16-1) for i in range(maxcount)] stimulus_b = [randint(0, maxint16-1) for i in range(maxcount)] yield from run_test(dut, stimulus_a, stimulus_b, op) diff --git a/src/ieee754/fpcommon/test/unit_test_single.py b/src/ieee754/fpcommon/test/unit_test_single.py index 2b0d9e56..160ac5b1 100644 --- a/src/ieee754/fpcommon/test/unit_test_single.py +++ b/src/ieee754/fpcommon/test/unit_test_single.py @@ -199,56 +199,57 @@ 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, get_case_fn): +def run_cases(dut, count, op, fixed_num, maxcount, get_case_fn): if isinstance(fixed_num, int): - stimulus_a = [fixed_num for i in range(num_entries)] + stimulus_a = [fixed_num for i in range(maxcount)] report = hex(fixed_num) else: stimulus_a = fixed_num report = "random" - stimulus_b = [randint(0, 1<<32) for i in range(num_entries)] + stimulus_b = [randint(0, 1<<32) for i in range(maxcount)] 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)] + for i in range(maxcount)] 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)] + for i in range(maxcount)] 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)] + for i in range(maxcount)] 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)] + for i in range(maxcount)] 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, get_case_fn): +def run_edge_cases(dut, count, op, get_case_fn, maxcount=10, num_loops=1000): #edge cases for testme in corner_cases: - count = yield from run_cases(dut, count, op, testme, 10, get_case_fn) + count = yield from run_cases(dut, count, op, testme, + maxcount, get_case_fn) - for i in range(100000): - stimulus_a = [randint(0, 1<<32) for i in range(10)] + for i in range(num_loops): + stimulus_a = [randint(0, 1<<32) for i in range(maxcount)] count = yield from run_cases(dut, count, op, stimulus_a, 10, get_case_fn) return count diff --git a/src/ieee754/fpmul/test/test_mul.py b/src/ieee754/fpmul/test/test_mul.py index a1cf8e55..10fe5674 100644 --- a/src/ieee754/fpmul/test/test_mul.py +++ b/src/ieee754/fpmul/test/test_mul.py @@ -14,7 +14,7 @@ from ieee754.fpcommon.test.unit_test_single import (get_mantissa, get_exponent, run_edge_cases, run_corner_cases) -def tbench(dut): +def tbench(dut, maxcount, num_loops): yield from check_case(dut, 0x40000000, 0x40000000, 0x40800000) yield from check_case(dut, 0x41400000, 0x40A00000, 0x42700000) @@ -30,12 +30,13 @@ def tbench(dut): print (count, "vectors passed") yield from run_corner_cases(dut, count, mul, get_case) - yield from run_edge_cases(dut, count, mul, get_case) + yield from run_edge_cases(dut, count, mul, get_case, maxcount, num_loops) -def test1(): +def test1(maxcount=10, num_loops=5): dut = FPMUL(width=32) - run_simulation(dut, tbench(dut), vcd_name="test_mul.vcd") + run_simulation(dut, tbench(dut, maxcount, num_loops), + vcd_name="test_mul.vcd") if __name__ == '__main__': - test1() + test1(maxcount=1000, num_loops=1000)