1 # Copyright © 2020 Arm Ltd. All rights reserved.
3 # SPDX-License-Identifier: MIT
10 sys.path.append(os.path.abspath('..'))
11 from setup import find_armnn, find_includes, linux_gcc_lib_search, check_armnn_version
14 @pytest.fixture(autouse=True)
15 def _setup_armnn(tmpdir):
16 includes = str(os.path.join(tmpdir, 'include'))
17 libs = str(os.path.join(tmpdir, 'lib'))
18 os.environ["TEST_ARMNN_INCLUDE"] = includes
19 os.environ["TEST_ARMNN_LIB"] = libs
20 os.environ["EMPTY_ARMNN_INCLUDE"] = ''
25 with open(os.path.join(libs, "libarmnn.so"), "w"):
28 with open(os.path.join(libs, "libarmnnSomeThing1.so"), "w"):
30 with open(os.path.join(libs, "libarmnnSomeThing1.so.1"), "w"):
32 with open(os.path.join(libs, "libarmnnSomeThing1.so.1.2"), "w"):
35 with open(os.path.join(libs, "libarmnnSomeThing2.so"), "w"):
38 with open(os.path.join(libs, "libSomeThing3.so"), "w"):
43 del os.environ["TEST_ARMNN_INCLUDE"]
44 del os.environ["TEST_ARMNN_LIB"]
45 del os.environ["EMPTY_ARMNN_INCLUDE"]
46 shutil.rmtree(includes)
50 def test_find_armnn(tmpdir):
51 lib_names, lib_paths = find_armnn(lib_name='libarmnn*.so',
52 armnn_libs_env="TEST_ARMNN_LIB",
53 default_lib_search=("/lib",))
54 armnn_includes = find_includes(armnn_include_env="TEST_ARMNN_INCLUDE")
56 assert [':libarmnn.so', ':libarmnnSomeThing1.so', ':libarmnnSomeThing2.so'] == sorted(lib_names)
57 assert [os.path.join(tmpdir, 'lib')] == lib_paths
58 assert [os.path.join(tmpdir, 'include')] == armnn_includes
61 def test_find_armnn_default_path(tmpdir):
62 lib_names, lib_paths = find_armnn(lib_name='libarmnn*.so',
63 armnn_libs_env="RUBBISH_LIB",
64 default_lib_search=(os.environ["TEST_ARMNN_LIB"],))
65 armnn_includes = find_includes('TEST_ARMNN_INCLUDE')
66 assert [':libarmnn.so', ':libarmnnSomeThing1.so', ':libarmnnSomeThing2.so'] == sorted(lib_names)
67 assert [os.path.join(tmpdir, 'lib')] == lib_paths
68 assert [os.path.join(tmpdir, 'include')] == armnn_includes
71 def test_not_find_armnn(tmpdir):
72 with pytest.raises(RuntimeError) as err:
73 find_armnn(lib_name='libarmnn*.so', armnn_libs_env="RUBBISH_LIB",
74 default_lib_search=("/lib",))
76 assert 'ArmNN library libarmnn*.so was not found in (\'/lib\',)' in str(err.value)
79 @pytest.mark.parametrize("env", ["RUBBISH_INCLUDE", "EMPTY_ARMNN_INCLUDE"])
80 def test_rubbish_armnn_include(tmpdir, env):
81 includes = find_includes(armnn_include_env=env)
82 assert includes == ['/usr/local/include', '/usr/include']
85 def test_gcc_serch_path():
86 assert linux_gcc_lib_search()
89 def test_armnn_version():
90 check_armnn_version('22.0.0', '22.0.0')
93 def test_incorrect_armnn_version():
94 with pytest.raises(AssertionError) as err:
95 check_armnn_version('22.0.0', '22.1.0')
97 assert 'Expected ArmNN version is 22.1.0 but installed ArmNN version is 22.0.0' in str(err.value)
100 def test_armnn_version_patch_does_not_matter():
101 check_armnn_version('22.0.0', '22.0.1')