From d8ad99d8684e0e7c88fa8b1f344ac709a61c5a0f Mon Sep 17 00:00:00 2001 From: Daniel Benusovich Date: Fri, 8 Mar 2019 18:50:02 -0800 Subject: [PATCH] Update assert functions to remove duplicated code via assert_op in test_helper.py --- TLB/test/test_cam.py | 17 ++++------------- TLB/test/test_cam_entry.py | 12 +++--------- TestUtil/test_helper.py | 13 ++++++++++++- 3 files changed, 19 insertions(+), 23 deletions(-) diff --git a/TLB/test/test_cam.py b/TLB/test/test_cam.py index 4bd1cfe9..de2bdcf4 100644 --- a/TLB/test/test_cam.py +++ b/TLB/test/test_cam.py @@ -6,7 +6,7 @@ from nmigen.compat.sim import run_simulation from Cam import Cam -from test_helper import assert_eq, assert_ne +from test_helper import assert_eq, assert_ne, assert_op def set_cam(dut, e, we, a, d): yield dut.enable.eq(e) @@ -17,24 +17,15 @@ def set_cam(dut, e, we, a, d): def check_multiple_match(dut, mm, op): out_mm = yield dut.multiple_match - if op == 0: - assert_eq("Multiple Match", out_mm, mm) - else: - assert_ne("Multiple Match", out_mm, mm) + assert_op("Multiple Match", out_mm, mm, op) def check_single_match(dut, sm, op): out_sm = yield dut.single_match - if op == 0: - assert_eq("Single Match", out_sm, sm) - else: - assert_ne("Single Match", out_sm, sm) + assert_op("Single Match", out_sm, sm, op) def check_match_address(dut, ma, op): out_ma = yield dut.match_address - if op == 0: - assert_eq("Match Address", out_ma, ma) - else: - assert_ne("Match Address", out_ma, ma) + assert_op("Match Address", out_ma, ma, op) def check_all(dut, multiple_match, single_match, match_address, mm_op, sm_op, ma_op): yield from check_multiple_match(dut, multiple_match, mm_op) diff --git a/TLB/test/test_cam_entry.py b/TLB/test/test_cam_entry.py index 1ed48f50..68a34c73 100644 --- a/TLB/test/test_cam_entry.py +++ b/TLB/test/test_cam_entry.py @@ -4,7 +4,7 @@ sys.path.append("../../TestUtil") from nmigen.compat.sim import run_simulation -from test_helper import assert_eq, assert_ne +from test_helper import assert_eq, assert_ne, assert_op from CamEntry import CamEntry # This function allows for the easy setting of values to the Cam Entry @@ -30,10 +30,7 @@ def set_cam_entry(dut, c, d): # op (Operation): (0 => ==), (1 => !=) def check_data(dut, d, op): out_d = yield dut.data - if op == 0: - assert_eq("Data", out_d, d) - else: - assert_ne("Data", out_d, d) + assert_op("Data", out_d, d, op) # Checks the match state of the CAM entry # Arguments: @@ -42,10 +39,7 @@ def check_data(dut, d, op): # op (Operation): (0 => ==), (1 => !=) def check_match(dut, m, op): out_m = yield dut.match - if op == 0: - assert_eq("Match", out_m, m) - else: - assert_ne("Match", out_m, m) + assert_op("Match", out_m, m, op) # Checks the state of the CAM entry # Arguments: diff --git a/TestUtil/test_helper.py b/TestUtil/test_helper.py index 5e60ab98..d22124b8 100644 --- a/TestUtil/test_helper.py +++ b/TestUtil/test_helper.py @@ -1,9 +1,20 @@ -# Verifies the given values are equal +# Verifies the given values given the particular operand # Arguments: # p (Prefix): Appended to the front of the assert statement # e (Expected): The expected value # o (Output): The output result # op (Operation): (0 => ==), (1 => !=) +def assert_op(pre, o, e, op): + if op == 0: + assert_eq(pre, o, e) + else: + assert_ne(pre, o, e) + +# Verifies the given values are equal +# Arguments: +# p (Prefix): Appended to the front of the assert statement +# e (Expected): The expected value +# o (Output): The output result def assert_eq(p, o, e): assert o == e, p + " Output " + str(o) + " Expected " + str(e) -- 2.30.2