From 5822a49aed5e43b11a2bd05c0d38cbfc275926e2 Mon Sep 17 00:00:00 2001 From: Marek Materzok Date: Wed, 13 Nov 2024 14:23:18 +0100 Subject: [PATCH] Async FPU test --- test/func_blocks/fu/fpu/test_fpu_error.py | 53 ++++++++++---------- test/func_blocks/fu/fpu/test_fpu_rounding.py | 39 +++++++------- 2 files changed, 47 insertions(+), 45 deletions(-) diff --git a/test/func_blocks/fu/fpu/test_fpu_error.py b/test/func_blocks/fu/fpu/test_fpu_error.py index 6938bfd17..fb4310131 100644 --- a/test/func_blocks/fu/fpu/test_fpu_error.py +++ b/test/func_blocks/fu/fpu/test_fpu_error.py @@ -45,7 +45,7 @@ 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 { @@ -53,7 +53,7 @@ def other_cases_test(): "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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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( [ @@ -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, @@ -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, @@ -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) diff --git a/test/func_blocks/fu/fpu/test_fpu_rounding.py b/test/func_blocks/fu/fpu/test_fpu_rounding.py index 0b1e40865..86a132f3d 100644 --- a/test/func_blocks/fu/fpu/test_fpu_rounding.py +++ b/test/func_blocks/fu/fpu/test_fpu_rounding.py @@ -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 { @@ -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 { @@ -113,7 +114,7 @@ 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, @@ -121,7 +122,7 @@ 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, }, # no overflow 10 { @@ -130,7 +131,7 @@ 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, @@ -138,7 +139,7 @@ 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, }, # no overflow 01 { @@ -147,7 +148,7 @@ 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, @@ -155,7 +156,7 @@ 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, }, # no overflow 11 { @@ -164,7 +165,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, }, { "sign": 1, @@ -172,7 +173,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, }, # Round to nearest tie to even { @@ -181,7 +182,7 @@ 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, @@ -189,7 +190,7 @@ 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, }, ] expected_results = [ @@ -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)