Coverage for tests/integration_tests/test_packages_checker.py: 100%

21 statements  

« prev     ^ index     » next       coverage.py v7.17.2, created at 2026-11-07 05:08 +0000

1# This file is part of the Apio project 

2# (C) 2016-present FPGAwars 

3# Project authors: 

4# * Jesús Arroyo (Jesus89) (2016-2019) 

5# * Juan Gonzalez (obijuan) (2019-2024) 

6# * The Apio Team (2024-present) 

7# License: GPLv2 

8 

9""" 

10Test the package checking functionality. This is a sanity checker that is 

11implemented by packages.check_packages() and invoked from a few places. 

12""" 

13 

14import os 

15import json 

16import shutil 

17from tests.conftest import ApioRunner 

18from apio.commands.apio import apio_top_cli as apio 

19 

20 

21def test_yosys_release_tag_mismatch(apio_runner: ApioRunner): 

22 """Test the verification that the apio 'oss-cad-suite' and 'openxc7' 

23 use the same Yosys release.""" 

24 

25 with apio_runner.in_sandbox() as sb: 

26 

27 # -- Fetch an example, this also verifies that the apio packages are 

28 # -- installed. 

29 result = sb.invoke_apio_cmd( 

30 apio, ["examples", "fetch", "basys3/blinky"] 

31 ) 

32 sb.assert_result_ok(result) 

33 

34 # -- Make a copy of the packages dir so we don't disturb the original. 

35 # -- This is because the packages are cached and shared between tests. 

36 # -- We create the fake package dir under the private sandbox of this 

37 # -- test instance which is deleted at the end of the test. 

38 fake_packages_dir = sb.sandbox_dir / "fake_packages_dir" 

39 shutil.copytree( 

40 sb.packages_dir, fake_packages_dir, dirs_exist_ok=False 

41 ) 

42 

43 # -- Set the fake packages dir as the default packages dir for apio. 

44 # -- This env is also cleared automatically by conftest.py at the end 

45 # -- of this test. 

46 os.environ["APIO_PACKAGES"] = str(fake_packages_dir) 

47 

48 # -- Modify of the 'yosys-release-tag' of the 'oss-cad-suite' to 

49 # -- create a fake mismatch. 

50 build_info_path = ( 

51 fake_packages_dir / "oss-cad-suite" / "BUILD-INFO.json" 

52 ) 

53 

54 with open(build_info_path, encoding="utf-8") as f: 

55 build_info_data = json.load(f) 

56 

57 build_info_data["yosys-release-tag"] = "2026-01-01" 

58 

59 with open(build_info_path, "w", encoding="utf-8") as f: 

60 json.dump(build_info_data, f, indent=2) 

61 

62 # -- Now run the apio build and it should check and fail on 

63 # -- yosys-release-tag mismatch, even if the build is already up to 

64 # -- date. 

65 result = sb.invoke_apio_cmd(apio, ["build"]) 

66 assert result.exit_code == 1 

67 assert 'were built with different "yosys-release-tag"' in result.output