From 97d0e6f46b23ce2b8467f37a51804e6de7beddde Mon Sep 17 00:00:00 2001 From: Miical <879754743@qq.com> Date: Thu, 5 Sep 2024 20:35:35 +0800 Subject: [PATCH] Update uftb-with-ftq to mlvp v0.1.0 --- .gitignore | 1 + doc/env_cn.md | 8 ++--- doc/env_en.md | 6 ++-- tests/Makefile | 13 ++------ tests/uFTB-raw/FauFTB.py | 4 +-- tests/uFTB-raw/test_raw.py | 2 +- tests/uFTB-with-ftq/env/bpu_top.py | 1 + tests/uFTB-with-ftq/env/uftb_model.py | 2 +- tests/uFTB-with-ftq/tests/test_with_ftq.py | 38 +++++++++------------- 9 files changed, 31 insertions(+), 44 deletions(-) diff --git a/.gitignore b/.gitignore index ad93b67..9992905 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ split_verilogs **/UT_* NemuBR/ report/ +reports/ diff --git a/doc/env_cn.md b/doc/env_cn.md index 4f144cb..9f749ac 100644 --- a/doc/env_cn.md +++ b/doc/env_cn.md @@ -74,13 +74,13 @@ if __name__ == "__main__": # Create DUT uftb = DUTFauFTB() # Init DUT with clock pin name - uftb.init_clock("clock") + uftb.InitClock("clock") # Your testcases here # ... # Destroy DUT - utb.finalize() + utb.Finish() ``` 其他待验证模块,例如 TAGE-SC,FTB也可以通过类似命令生成。 @@ -166,7 +166,7 @@ def test_mydut(request): # ... # 结束测试,并录入覆盖率信息,覆盖率文件名称应该与上述指定的覆盖率文件名称相同 - my_dut.finalize() + my_dut.Finish() set_func_coverage(request, [g1, g2]) set_line_coverage(request, "my_test_coverage.dat") ``` @@ -218,7 +218,7 @@ def setup_logging( **2. 阅读代码,封装并驱动DUT。** 代码中包含了所有实现细节,基于其可对DUT的基本功能封装为一个个函数。然后测试这些函数功能是否正常。 -**3. 根据测试点编写对应测试用例。** 基于测点和DUT基本功能函数,完成绝大部分功能的测试。(**不要一来就写参考模型**) +**3. 根据测试点编写对应测试用例。** 基于测点和DUT基本功能函数,完成绝大部分功能的测试。(**不要一来就写参考模型**) **4. 编写参考模型。** 当所有基本功能点都测试完成后,再基于自己理解完成参考模型编写。(如果所有功能点都完成测试,且功能、代码行覆盖率已达到要求,可忽略参考模型) diff --git a/doc/env_en.md b/doc/env_en.md index 04b951e..3b965c2 100644 --- a/doc/env_en.md +++ b/doc/env_en.md @@ -74,13 +74,13 @@ if __name__ == "__main__": # Create DUT uftb = DUTFauFTB() # Init DUT with clock pin name - uftb.init_clock("clock") + uftb.InitClock("clock") # Your testcases here # ... # Destroy DUT - utb.finalize() + utb.Finish() ``` Other modules to be verified, such as TAGE-SC, FTB can also be generated by similar commands. @@ -167,7 +167,7 @@ def test_mydut(request): # ... # End the test, and enter the coverage information. The coverage file name should be the same as the coverage file name specified above - my_dut.finalize() + my_dut.Finish() set_func_coverage(request, [g1, g2]) set_line_coverage(request, "my_test_coverage.dat") ``` diff --git a/tests/Makefile b/tests/Makefile index 47949b8..09ce85a 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,18 +1,9 @@ TEST=. TEST_FOLDER=./$(TEST) - PYTHON=python3 -START_CODE="from mlvp.reporter import *;\ -set_meta_info('test_case', '$(TEST)');\ -report = 'report/$(TEST)/report.html';\ -generate_pytest_report(report, args=['-s', '$(TEST_FOLDER)'], );\ -" - run: - @echo "Running test $(TEST)..." - @mkdir report/$(TEST) -p - @$(PYTHON) -c $(START_CODE) + pytest --mlvp-report -sv $(TEST_FOLDER) clean: - rm -rf report/ *.fst *.dat *.log *.hier + rm -rf reports/ diff --git a/tests/uFTB-raw/FauFTB.py b/tests/uFTB-raw/FauFTB.py index c332d59..f75a315 100644 --- a/tests/uFTB-raw/FauFTB.py +++ b/tests/uFTB-raw/FauFTB.py @@ -150,10 +150,10 @@ class FauFTB(DUTFauFTB): self.io_out_s1_full_pred = self.Io_out_s1_full_pred(self) self._io_out_last_stage_meta = self.Io_out_last_stage_meta(self) self.io_update_bits_ftb_entry = self.Io_update_bits_ftb_entry(self) - self.init_clock("clock") + self.InitClock("clock") def finalize(self): - super().finalize() + super().Finish() def check_dup_equation(self, *inputs): return all(i == inputs[0] for i in inputs) diff --git a/tests/uFTB-raw/test_raw.py b/tests/uFTB-raw/test_raw.py index f54bba6..d8440ce 100644 --- a/tests/uFTB-raw/test_raw.py +++ b/tests/uFTB-raw/test_raw.py @@ -57,7 +57,7 @@ def test_raw(request): print("main", pred[0], pred[1].__dict__) uFTB.Step(1) - uFTB.finalize() + uFTB.Finish() set_line_coverage(request, "report/uftb_raw_coverage.dat") diff --git a/tests/uFTB-with-ftq/env/bpu_top.py b/tests/uFTB-with-ftq/env/bpu_top.py index ae15146..1d95d97 100644 --- a/tests/uFTB-with-ftq/env/bpu_top.py +++ b/tests/uFTB-with-ftq/env/bpu_top.py @@ -1,4 +1,5 @@ from mlvp import * +from mlvp.triggers import * from .bundle import * from .ftq import * from .uftb_model import uFTBModel diff --git a/tests/uFTB-with-ftq/env/uftb_model.py b/tests/uFTB-with-ftq/env/uftb_model.py index 7bc1c6f..0d140a7 100644 --- a/tests/uFTB-with-ftq/env/uftb_model.py +++ b/tests/uFTB-with-ftq/env/uftb_model.py @@ -1,4 +1,4 @@ -from mlvp.modules import PLRU, TwoBitsCounter +from mlvp.utils import PLRU, TwoBitsCounter from mlvp import * from .ftb import * diff --git a/tests/uFTB-with-ftq/tests/test_with_ftq.py b/tests/uFTB-with-ftq/tests/test_with_ftq.py index 1d8ebfa..36f7ef7 100644 --- a/tests/uFTB-with-ftq/tests/test_with_ftq.py +++ b/tests/uFTB-with-ftq/tests/test_with_ftq.py @@ -1,5 +1,6 @@ import mlvp -import logging +import pytest +from mlvp.triggers import * import os os.sys.path.append(os.path.dirname(os.path.abspath(__file__)) + "/..") @@ -12,8 +13,6 @@ os.sys.path.append(DUT_PATH) from UT_FauFTB import * - - def set_imm_mode(uFTB): imm_mode = uFTB.io_s0_fire_0.xdata.Imme need_to_write_imm = ["io_s0_fire_0", "io_s0_fire_1", "io_s0_fire_2", "io_s0_fire_3", @@ -23,27 +22,31 @@ def set_imm_mode(uFTB): getattr(uFTB, name).xdata.SetWriteMode(imm_mode) -async def uftb_test(uFTB): +@pytest.mark.mlvp_async +async def test_uftb(mlvp_request): + uFTB = mlvp_request + set_imm_mode(uFTB) + uFTB_update = UpdateBundle.from_prefix("io_update_").set_name("uFTB_update").bind(uFTB) uFTB_out = BranchPredictionResp.from_prefix("io_out_").set_name("uFTB_out").bind(uFTB) pipeline_ctrl = PipelineCtrlBundle.from_prefix("io_").set_name("pipeline_ctrl").bind(uFTB) enable_ctrl = EnableCtrlBundle.from_prefix("io_ctrl_").set_name("enable_ctrl").bind(uFTB) - mlvp.create_task(mlvp.start_clock(uFTB)) + mlvp.start_clock(uFTB) mlvp.create_task(BPUTop(uFTB, uFTB_out, uFTB_update, pipeline_ctrl, enable_ctrl).run()) await ClockCycles(uFTB, MAX_CYCLE) - + pred_stat.summary() import mlvp.funcov as fc from mlvp.reporter import * +from mlvp import PreRequest -def test_uftb(request): - # Create DUT - uFTB = DUTFauFTB(waveform_filename="report/uftb_with_ftq.fst", coverage_filename="report/uftb_with_ftq_coverage.dat") - uFTB.init_clock("clock") - set_imm_mode(uFTB) +@pytest.fixture() +def mlvp_request(mlvp_pre_request: PreRequest): + mlvp.setup_logging(mlvp.INFO) + uFTB = mlvp_pre_request.create_dut(DUTFauFTB, "clock") # Set Coverage g1 = fc.CovGroup("interaction") @@ -63,15 +66,6 @@ def test_uftb(request): g2.add_watch_point(uFTB.io_out_s1_full_pred_0_br_taken_mask_1, { "br_taken_mask_1": fc.Eq(1), "br_taken_mask_1_invalid": fc.Eq(0) }, name="s1_full_pred_0_br_taken_mask_1") g2.add_watch_point(uFTB.io_out_s1_full_pred_0_is_br_sharing, { "is_br_sharing": fc.Eq(1), "is_br_sharing_invalid": fc.Eq(0) }, name="s1_full_pred_0_is_br_sharing") - uFTB.xclock.StepRis(lambda _: g1.sample()) - uFTB.xclock.StepRis(lambda _: g2.sample()) - - # Run the test - mlvp.setup_logging(log_level=logging.INFO, log_file="report/uftb_with_ftq.log") - mlvp.run(uftb_test(uFTB)) - uFTB.finalize() - - pred_stat.summary() - set_func_coverage(request, [g1, g2]) - set_line_coverage(request, "report/uftb_with_ftq_coverage.dat") + mlvp_pre_request.add_cov_groups([g1, g2]) + return uFTB