Coverage for hdl_registers/generator/cpp/test/test_register_cpp_generator.py: 100%
15 statements
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-19 20:51 +0000
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-19 20:51 +0000
1# --------------------------------------------------------------------------------------------------
2# Copyright (c) Lukas Vik. All rights reserved.
3#
4# This file is part of the hdl-registers project, an HDL register generator fast enough to run
5# in real time.
6# https://hdl-registers.com
7# https://github.com/hdl-registers/hdl-registers
8# --------------------------------------------------------------------------------------------------
10# Some limited unit tests that check the generated code.
11# Note that the generated C++ code is also functionally tested in the
12# file 'test_compiled_cpp_code.py'.
13# That test generates C++ code from an example register set, compiles it and performs some
14# run-time assertions in a C program.
15# That test is considered more meaningful and exhaustive than a unit test would be.
17# Third party libraries
18import pytest
19from tsfpga.system_utils import read_file
21# First party libraries
22from hdl_registers import HDL_REGISTERS_TESTS
23from hdl_registers.generator.cpp.interface import CppInterfaceGenerator
24from hdl_registers.parser.toml import from_toml
27@pytest.fixture
28def cpp_test_toml_code(tmp_path):
29 registers = from_toml("test", HDL_REGISTERS_TESTS / "regs_test.toml")
31 return read_file(
32 CppInterfaceGenerator(register_list=registers, output_folder=tmp_path).create()
33 )
36# False positive for pytest fixtures
37# pylint: disable=redefined-outer-name
40def test_read_only_register_has_no_setters(cpp_test_toml_code):
41 assert "get_status" in cpp_test_toml_code
42 assert "set_status" not in cpp_test_toml_code
45def test_write_only_register_has_no_setters(cpp_test_toml_code):
46 assert "set_command" in cpp_test_toml_code
47 assert "get_command" not in cpp_test_toml_code