diff --git a/.gitignore b/.gitignore index fc7aa96..dbe330a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,7 @@ split_verilogs .vscode **/__pycache__/ *.fst +*.dat **/UT_* NemuBR/ +report/ diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 0000000..9755f87 --- /dev/null +++ b/tests/Makefile @@ -0,0 +1,16 @@ +TEST_MODULE=FauFTB +TEST=uFTB_raw +TEST_FOLDER=./$(TEST) +COV_FILE_NAME=V$(TEST_MODULE)_coverage.dat + +PYTHON=python3 + +START_CODE="from mlvp.reporter import *;\ +set_meta_info('line_grate', 10);\ +report = 'report/report.html';\ +generate_pytest_report(report, args=['-s', '$(TEST_FOLDER)'], );\ +" + +run: + @echo "Running test $(TEST)..." + @$(PYTHON) -c $(START_CODE) diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..7355049 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,14 @@ +import pytest +from mlvp.reporter import process_context, process_func_coverage + + +@pytest.hookimpl(optionalhook=True) +def pytest_reporter_context(context, config): + process_context(context, config) + + +@pytest.hookimpl(tryfirst=True, hookwrapper=True) +def pytest_runtest_makereport(item, call): + outcome = yield + report = outcome.get_result() + return process_func_coverage(item, call, report) diff --git a/tests/uFTB-with-ftq/uftb-env/bpu_top.py b/tests/uFTB-with-ftq/env/bpu_top.py similarity index 99% rename from tests/uFTB-with-ftq/uftb-env/bpu_top.py rename to tests/uFTB-with-ftq/env/bpu_top.py index e3ff2b7..466024c 100644 --- a/tests/uFTB-with-ftq/uftb-env/bpu_top.py +++ b/tests/uFTB-with-ftq/env/bpu_top.py @@ -1,7 +1,7 @@ from mlvp import * -from bundle import * -from ftq import * -from uftb_model import uFTBModel +from .bundle import * +from .ftq import * +from .uftb_model import uFTBModel def assert_equal(a, b): if a != b: diff --git a/tests/uFTB-with-ftq/uftb-env/bundle.py b/tests/uFTB-with-ftq/env/bundle.py similarity index 100% rename from tests/uFTB-with-ftq/uftb-env/bundle.py rename to tests/uFTB-with-ftq/env/bundle.py diff --git a/tests/uFTB-with-ftq/uftb-env/config.py b/tests/uFTB-with-ftq/env/config.py similarity index 100% rename from tests/uFTB-with-ftq/uftb-env/config.py rename to tests/uFTB-with-ftq/env/config.py diff --git a/tests/uFTB-with-ftq/uftb-env/executor.py b/tests/uFTB-with-ftq/env/executor.py similarity index 99% rename from tests/uFTB-with-ftq/uftb-env/executor.py rename to tests/uFTB-with-ftq/env/executor.py index b8fbe05..6ca14c3 100644 --- a/tests/uFTB-with-ftq/uftb-env/executor.py +++ b/tests/uFTB-with-ftq/env/executor.py @@ -1,4 +1,4 @@ -from config import * +from .config import * import os os.sys.path.append(UTILS_PATH) diff --git a/tests/uFTB-with-ftq/uftb-env/ftb.py b/tests/uFTB-with-ftq/env/ftb.py similarity index 99% rename from tests/uFTB-with-ftq/uftb-env/ftb.py rename to tests/uFTB-with-ftq/env/ftb.py index 4647fce..f23b961 100644 --- a/tests/uFTB-with-ftq/uftb-env/ftb.py +++ b/tests/uFTB-with-ftq/env/ftb.py @@ -1,4 +1,4 @@ -from utils import * +from .utils import * class FTBSlot: def __init__(self): diff --git a/tests/uFTB-with-ftq/uftb-env/ftq.py b/tests/uFTB-with-ftq/env/ftq.py similarity index 99% rename from tests/uFTB-with-ftq/uftb-env/ftq.py rename to tests/uFTB-with-ftq/env/ftq.py index 6fcd426..ab59a41 100644 --- a/tests/uFTB-with-ftq/uftb-env/ftq.py +++ b/tests/uFTB-with-ftq/env/ftq.py @@ -1,9 +1,9 @@ -from bundle import * -from config import * -from utils import * -from executor import Executor -from ftb import * from random import random +from .bundle import * +from .config import * +from .utils import * +from .executor import Executor +from .ftb import * class PredictionStatistician: """Predictive condition statistician for branch instructions""" diff --git a/tests/uFTB-with-ftq/uftb-env/uftb_model.py b/tests/uFTB-with-ftq/env/uftb_model.py similarity index 99% rename from tests/uFTB-with-ftq/uftb-env/uftb_model.py rename to tests/uFTB-with-ftq/env/uftb_model.py index 23116cd..309de75 100644 --- a/tests/uFTB-with-ftq/uftb-env/uftb_model.py +++ b/tests/uFTB-with-ftq/env/uftb_model.py @@ -1,5 +1,5 @@ from mlvp.utils import PLRU, TwoBitsCounter -from ftb import * +from .ftb import * class uFTBWay: def __init__(self): diff --git a/tests/uFTB-with-ftq/uftb-env/utils.py b/tests/uFTB-with-ftq/env/utils.py similarity index 99% rename from tests/uFTB-with-ftq/uftb-env/utils.py rename to tests/uFTB-with-ftq/env/utils.py index 1fe1fbd..cc14a38 100644 --- a/tests/uFTB-with-ftq/uftb-env/utils.py +++ b/tests/uFTB-with-ftq/env/utils.py @@ -1,4 +1,4 @@ -from config import * +from .config import * def get_slot_offset(pc, target): return ((target - pc) >> INST_OFFSET_BITS) & ((1 << PREDICT_WIDTH_OFFSET_BITS) - 1) diff --git a/tests/uFTB-with-ftq/uftb-env/tb.py b/tests/uFTB-with-ftq/tests/test_with_ftq.py similarity index 69% rename from tests/uFTB-with-ftq/uftb-env/tb.py rename to tests/uFTB-with-ftq/tests/test_with_ftq.py index c27a7ba..51c80e5 100644 --- a/tests/uFTB-with-ftq/uftb-env/tb.py +++ b/tests/uFTB-with-ftq/tests/test_with_ftq.py @@ -1,10 +1,12 @@ import mlvp -from bundle import * -from bpu_top import * -from config import MAX_CYCLE - import os +os.sys.path.append(os.path.dirname(os.path.abspath(__file__)) + "/..") + +from env.bundle import * +from env.bpu_top import * +from env.config import * + os.sys.path.append(DUT_PATH) from UT_FauFTB import * @@ -32,8 +34,22 @@ async def uftb_test(): await ClockCycles(uFTB, MAX_CYCLE) -if __name__ == "__main__": - mlvp.run(uftb_test()) - uFTB.finalize() + +import mlvp.funcov as fc +from mlvp.reporter import * + +def test_uftb(request): + g = fc.CovGroup("coverage_group_1") + g.add_watch_point(uFTB.io_s0_fire_0, { + "s0_fire": fc.Eq(1), + }, name="s0_fire_0") + + set_func_coverage(request, g) + set_line_coverage(request, "VFauFTB_coverage.dat") + + mlvp.run(uftb_test()) + g.sample() + + uFTB.finalize() pred_stat.summary() diff --git a/tests/uFTB_raw/FauFTB.py b/tests/uFTB_raw/FauFTB.py index ffea2f7..eaf1975 100644 --- a/tests/uFTB_raw/FauFTB.py +++ b/tests/uFTB_raw/FauFTB.py @@ -1,3 +1,8 @@ +import os +ROOT_PATH = os.path.dirname(os.path.abspath(__file__)) + "/../.." +DUT_PATH = ROOT_PATH + "/out/picker_out_uFTB" +os.sys.path.append(DUT_PATH) + from typing import Any, Tuple from UT_FauFTB import * from FTBEntry import * diff --git a/tests/uFTB_raw/main.py b/tests/uFTB_raw/test_raw.py similarity index 91% rename from tests/uFTB_raw/main.py rename to tests/uFTB_raw/test_raw.py index 0da3220..b689ffb 100644 --- a/tests/uFTB_raw/main.py +++ b/tests/uFTB_raw/test_raw.py @@ -23,7 +23,7 @@ def get_pred(uFTB: FauFTB, pc: int) -> Tuple[int, FTBEntry, bool, bool]: uFTB.io_s1_fire_0.value = 1 uFTB.io_s2_fire_0.value = 1 return uFTB.s1_full_pred() - + def set_update(uFTB: FauFTB, entry: Tuple[int, FTBEntry, bool, bool]): @@ -32,8 +32,12 @@ def set_update(uFTB: FauFTB, entry: Tuple[int, FTBEntry, bool, bool]): # print("set_update", entry[1].brSlot) uFTB.update_ftb_entry(entry[0], entry[1], (entry[2], entry[3])) +import mlvp.funcov as fc +from mlvp.reporter import * -def main(): +def test_raw(request): + + set_line_coverage(request, "VFauFTB_coverage.dat") uFTB: FauFTB = FauFTB() ftb_entry_list() @@ -56,4 +60,4 @@ def main(): if __name__ == "__main__": - main() + test_raw()