Coverage for tsfpga/vivado/test/test_common.py: 100%
29 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-02-21 20:51 +0000
« prev ^ index » next coverage.py v7.6.12, created at 2025-02-21 20:51 +0000
1# --------------------------------------------------------------------------------------------------
2# Copyright (c) Lukas Vik. All rights reserved.
3#
4# This file is part of the tsfpga project, a project platform for modern FPGA development.
5# https://tsfpga.com
6# https://github.com/tsfpga/tsfpga
7# --------------------------------------------------------------------------------------------------
9from pathlib import Path
10from unittest.mock import patch
12from tsfpga.vivado.common import get_git_sha_slv, get_vivado_version, run_vivado_tcl
14THIS_DIR = Path(__file__).parent
17def test_run_vivado_tcl():
18 vivado_path = THIS_DIR / "vivado.exe"
19 tcl_file = THIS_DIR / "script.tcl"
20 expected_cmd = [
21 str(vivado_path.resolve()),
22 "-mode",
23 "batch",
24 "-notrace",
25 "-source",
26 str(tcl_file.resolve()),
27 ]
29 with patch("tsfpga.vivado.common.Process") as mocked_process:
30 mocked_process.NonZeroExitCode = ValueError
31 assert run_vivado_tcl(vivado_path, tcl_file)
32 mocked_process.assert_called_once_with(args=expected_cmd, cwd=THIS_DIR)
34 with patch("tsfpga.vivado.common.Process") as mocked_process:
35 mocked_process.NonZeroExitCode = ValueError
36 assert run_vivado_tcl(vivado_path, tcl_file, no_log_file=True)
37 mocked_process.assert_called_once_with(
38 args=[*expected_cmd, "-nojournal", "-nolog"], cwd=THIS_DIR
39 )
41 with patch("tsfpga.vivado.common.Process") as mocked_process:
42 mocked_process.NonZeroExitCode = ValueError
43 mocked_process.return_value.consume_output.side_effect = ValueError("Non-zero exit code!")
44 assert not run_vivado_tcl(vivado_path, tcl_file, no_log_file=True)
47def test_get_vivado_version():
48 assert (
49 get_vivado_version(vivado_path=Path("/home/lukas/work/Xilinx/Vivado/2021.2/bin/vivado"))
50 == "2021.2"
51 )
54def test_get_git_sha_slv():
55 with patch("tsfpga.vivado.common.get_git_sha") as get_git_sha:
56 get_git_sha.return_value = "abcdef0123456789"
57 assert get_git_sha_slv(git_directory=None) == (
58 "10101011110011011110111100000001",
59 "00100011010001010110011110001001",
60 )
62 with patch("tsfpga.vivado.common.get_git_sha") as get_git_sha:
63 get_git_sha.return_value = "00abcdef00123400"
64 assert get_git_sha_slv(git_directory=None) == (
65 "00000000101010111100110111101111",
66 "00000000000100100011010000000000",
67 )