Add pytest

This commit is contained in:
Miical 2024-04-28 13:32:14 +08:00
parent 8931e1b246
commit cb39a7518d
14 changed files with 79 additions and 22 deletions

2
.gitignore vendored
View File

@ -3,5 +3,7 @@ split_verilogs
.vscode
**/__pycache__/
*.fst
*.dat
**/UT_*
NemuBR/
report/

16
tests/Makefile Normal file
View File

@ -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)

14
tests/conftest.py Normal file
View File

@ -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)

View File

@ -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:

View File

@ -1,4 +1,4 @@
from config import *
from .config import *
import os
os.sys.path.append(UTILS_PATH)

View File

@ -1,4 +1,4 @@
from utils import *
from .utils import *
class FTBSlot:
def __init__(self):

View File

@ -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"""

View File

@ -1,5 +1,5 @@
from mlvp.utils import PLRU, TwoBitsCounter
from ftb import *
from .ftb import *
class uFTBWay:
def __init__(self):

View File

@ -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)

View File

@ -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()

View File

@ -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 *

View File

@ -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()