Skip to content

Commit

Permalink
Async FPU test
Browse files Browse the repository at this point in the history
  • Loading branch information
tilk committed Nov 13, 2024
1 parent 1c0ab96 commit 5822a49
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 45 deletions.
53 changes: 27 additions & 26 deletions test/func_blocks/fu/fpu/test_fpu_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ def __init__(self, params: FPUParams):
def test_special_cases(self, params: FPUParams, help_values: HelpValues):
fpue = TestFPUError.FPUErrorModule(params)

def other_cases_test():
async def other_cases_test(sim: TestbenchContext):
test_cases = [
# No errors
{
"sign": 0,
"sig": help_values.not_max_norm_even_sig,
"exp": help_values.not_max_norm_exp,
"inexact": 0,
"rounding_mode": RoundingModes.ROUND_NEAREST_AWAY,
"rounding_mode": RoundingModes.ROUND_NEAREST_AWAY.value,
"invalid_operation": 0,
"division_by_zero": 0,
"input_inf": 0,
Expand All @@ -64,7 +64,7 @@ def other_cases_test():
"sig": help_values.not_max_norm_even_sig,
"exp": help_values.not_max_norm_exp,
"inexact": 1,
"rounding_mode": RoundingModes.ROUND_NEAREST_AWAY,
"rounding_mode": RoundingModes.ROUND_NEAREST_AWAY.value,
"invalid_operation": 0,
"division_by_zero": 0,
"input_inf": 0,
Expand All @@ -75,7 +75,7 @@ def other_cases_test():
"sig": help_values.sub_norm_sig,
"exp": 0,
"inexact": 1,
"rounding_mode": RoundingModes.ROUND_NEAREST_AWAY,
"rounding_mode": RoundingModes.ROUND_NEAREST_AWAY.value,
"invalid_operation": 0,
"division_by_zero": 0,
"input_inf": 0,
Expand All @@ -86,7 +86,7 @@ def other_cases_test():
"sig": help_values.qnan,
"exp": help_values.max_exp,
"inexact": 1,
"rounding_mode": RoundingModes.ROUND_NEAREST_AWAY,
"rounding_mode": RoundingModes.ROUND_NEAREST_AWAY.value,
"invalid_operation": 1,
"division_by_zero": 0,
"input_inf": 0,
Expand All @@ -97,7 +97,7 @@ def other_cases_test():
"sig": 0,
"exp": help_values.max_exp,
"inexact": 1,
"rounding_mode": RoundingModes.ROUND_NEAREST_AWAY,
"rounding_mode": RoundingModes.ROUND_NEAREST_AWAY.value,
"invalid_operation": 0,
"division_by_zero": 1,
"input_inf": 0,
Expand All @@ -108,7 +108,7 @@ def other_cases_test():
"sig": 0,
"exp": help_values.max_exp,
"inexact": 0,
"rounding_mode": RoundingModes.ROUND_NEAREST_AWAY,
"rounding_mode": RoundingModes.ROUND_NEAREST_AWAY.value,
"invalid_operation": 0,
"division_by_zero": 0,
"input_inf": 0,
Expand All @@ -119,7 +119,7 @@ def other_cases_test():
"sig": help_values.sub_norm_sig,
"exp": 0,
"inexact": 0,
"rounding_mode": RoundingModes.ROUND_NEAREST_AWAY,
"rounding_mode": RoundingModes.ROUND_NEAREST_AWAY.value,
"invalid_operation": 0,
"division_by_zero": 0,
"input_inf": 0,
Expand All @@ -130,7 +130,7 @@ def other_cases_test():
"sig": help_values.qnan,
"exp": help_values.max_exp,
"inexact": 1,
"rounding_mode": RoundingModes.ROUND_NEAREST_AWAY,
"rounding_mode": RoundingModes.ROUND_NEAREST_AWAY.value,
"invalid_operation": 0,
"division_by_zero": 0,
"input_inf": 0,
Expand All @@ -141,7 +141,7 @@ def other_cases_test():
"sig": 0,
"exp": help_values.max_exp,
"inexact": 1,
"rounding_mode": RoundingModes.ROUND_NEAREST_AWAY,
"rounding_mode": RoundingModes.ROUND_NEAREST_AWAY.value,
"invalid_operation": 0,
"division_by_zero": 0,
"input_inf": 1,
Expand All @@ -152,7 +152,7 @@ def other_cases_test():
"sig": help_values.min_norm_sig,
"exp": 0,
"inexact": 1,
"rounding_mode": RoundingModes.ROUND_NEAREST_AWAY,
"rounding_mode": RoundingModes.ROUND_NEAREST_AWAY.value,
"invalid_operation": 0,
"division_by_zero": 0,
"input_inf": 0,
Expand Down Expand Up @@ -188,17 +188,17 @@ def other_cases_test():
]
for i in range(len(test_cases)):

resp = yield from fpue.error_checking_request_adapter.call(test_cases[i])
assert resp["sign"] == expected_results[i]["sign"]
assert resp["exp"] == expected_results[i]["exp"]
assert resp["sig"] == expected_results[i]["sig"]
assert resp["errors"] == expected_results[i]["errors"]
resp = await fpue.error_checking_request_adapter.call(sim, test_cases[i])
assert resp.sign == expected_results[i]["sign"]
assert resp.exp == expected_results[i]["exp"]
assert resp.sig == expected_results[i]["sig"]
assert resp.errors == expected_results[i]["errors"]

def test_process():
yield from other_cases_test()
async def test_process(sim: TestbenchContext):
await other_cases_test(sim)

with self.run_simulation(fpue) as sim:
sim.add_process(test_process)
sim.add_testbench(test_process)

@parameterized.expand(
[
Expand Down Expand Up @@ -261,14 +261,15 @@ def test_rounding(
):
fpue = TestFPUError.FPUErrorModule(params)

def one_rounding_mode_test():
async def one_rounding_mode_test(sim: TestbenchContext):
rm_int = rm.value # TODO: workaround for amaranth bug
test_cases = [
# overflow detection
{
"sign": 0,
"sig": 0,
"exp": help_values.max_exp,
"rounding_mode": rm,
"rounding_mode": rm_int,
"inexact": 0,
"invalid_operation": 0,
"division_by_zero": 0,
Expand All @@ -278,7 +279,7 @@ def one_rounding_mode_test():
"sign": 1,
"sig": 0,
"exp": help_values.max_exp,
"rounding_mode": rm,
"rounding_mode": rm_int,
"inexact": 0,
"invalid_operation": 0,
"division_by_zero": 0,
Expand All @@ -292,14 +293,14 @@ def one_rounding_mode_test():
]

for i in range(len(test_cases)):
resp = yield from fpue.error_checking_request_adapter.call(test_cases[i])
resp = await fpue.error_checking_request_adapter.call(sim, test_cases[i])
assert resp["sign"] == expected_results[i]["sign"]
assert resp["exp"] == expected_results[i]["exp"]
assert resp["sig"] == expected_results[i]["sig"]
assert resp["errors"] == expected_results[i]["errors"]

def test_process():
yield from one_rounding_mode_test()
async def test_process(sim: TestbenchContext):
await one_rounding_mode_test(sim)

with self.run_simulation(fpue) as sim:
sim.add_process(test_process)
sim.add_testbench(test_process)
39 changes: 20 additions & 19 deletions test/func_blocks/fu/fpu/test_fpu_rounding.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ def test_rounding(
):
fpurt = TestFPURounding.FPURoundingModule(params)

def one_rounding_mode_test():
async def one_rounding_mode_test(sim: TestbenchContext):
rm_int = rm.value # TODO: workaround for Amaranth bug
test_cases = [
# carry after increment
{
Expand All @@ -104,7 +105,7 @@ def one_rounding_mode_test():
"exp": help_values.not_max_norm_exp,
"round_bit": 1,
"sticky_bit": 1,
"rounding_mode": rm,
"rounding_mode": rm_int,
},
# no overflow 00
{
Expand All @@ -113,15 +114,15 @@ def one_rounding_mode_test():
"exp": help_values.not_max_norm_exp,
"round_bit": 0,
"sticky_bit": 0,
"rounding_mode": rm,
"rounding_mode": rm_int,
},
{
"sign": 1,
"sig": help_values.not_max_norm_sig,
"exp": help_values.not_max_norm_exp,
"round_bit": 0,
"sticky_bit": 0,
"rounding_mode": rm,
"rounding_mode": rm_int,
},
# no overflow 10
{
Expand All @@ -130,15 +131,15 @@ def one_rounding_mode_test():
"exp": help_values.not_max_norm_exp,
"round_bit": 1,
"sticky_bit": 0,
"rounding_mode": rm,
"rounding_mode": rm_int,
},
{
"sign": 1,
"sig": help_values.not_max_norm_sig,
"exp": help_values.not_max_norm_exp,
"round_bit": 1,
"sticky_bit": 0,
"rounding_mode": rm,
"rounding_mode": rm_int,
},
# no overflow 01
{
Expand All @@ -147,15 +148,15 @@ def one_rounding_mode_test():
"exp": help_values.not_max_norm_exp,
"round_bit": 0,
"sticky_bit": 1,
"rounding_mode": rm,
"rounding_mode": rm_int,
},
{
"sign": 1,
"sig": help_values.not_max_norm_sig,
"exp": help_values.not_max_norm_exp,
"round_bit": 0,
"sticky_bit": 1,
"rounding_mode": rm,
"rounding_mode": rm_int,
},
# no overflow 11
{
Expand All @@ -164,15 +165,15 @@ def one_rounding_mode_test():
"exp": help_values.not_max_norm_exp,
"round_bit": 1,
"sticky_bit": 1,
"rounding_mode": rm,
"rounding_mode": rm_int,
},
{
"sign": 1,
"sig": help_values.not_max_norm_sig,
"exp": help_values.not_max_norm_exp,
"round_bit": 1,
"sticky_bit": 1,
"rounding_mode": rm,
"rounding_mode": rm_int,
},
# Round to nearest tie to even
{
Expand All @@ -181,15 +182,15 @@ def one_rounding_mode_test():
"exp": help_values.not_max_norm_exp,
"round_bit": 1,
"sticky_bit": 0,
"rounding_mode": rm,
"rounding_mode": rm_int,
},
{
"sign": 0,
"sig": help_values.not_max_norm_even_sig,
"exp": help_values.not_max_norm_exp,
"round_bit": 1,
"sticky_bit": 0,
"rounding_mode": rm,
"rounding_mode": rm_int,
},
]
expected_results = [
Expand Down Expand Up @@ -264,13 +265,13 @@ def one_rounding_mode_test():

for i in range(num_of_test_cases):

resp = yield from fpurt.rounding_request_adapter.call(test_cases[i])
assert resp["exp"] == expected_results[i]["exp"]
assert resp["sig"] == expected_results[i]["sig"]
assert resp["inexact"] == expected_results[i]["inexact"]
resp = await fpurt.rounding_request_adapter.call(sim, test_cases[i])
assert resp.exp == expected_results[i]["exp"]
assert resp.sig == expected_results[i]["sig"]
assert resp.inexact == expected_results[i]["inexact"]

def test_process():
yield from one_rounding_mode_test()
async def test_process(sim: TestbenchContext):
await one_rounding_mode_test(sim)

with self.run_simulation(fpurt) as sim:
sim.add_process(test_process)
sim.add_testbench(test_process)

0 comments on commit 5822a49

Please sign in to comment.