blob: 8396ca0587e0a6845f18a53f446df8b30e51bcb5 [file] [log] [blame]
Richard Burtondc0c6ed2020-04-08 16:39:05 +01001# Copyright © 2020 Arm Ltd. All rights reserved.
2# SPDX-License-Identifier: MIT
3import os
4import sys
5import shutil
6
7import pytest
8
9sys.path.append(os.path.abspath('..'))
10from setup import find_armnn, find_includes, linux_gcc_lib_search, check_armnn_version
11
12
13@pytest.fixture(autouse=True)
14def _setup_armnn(tmpdir):
15 includes = str(os.path.join(tmpdir, 'include'))
16 libs = str(os.path.join(tmpdir, 'lib'))
17 os.environ["TEST_ARMNN_INCLUDE"] = includes
18 os.environ["TEST_ARMNN_LIB"] = libs
19 os.environ["EMPTY_ARMNN_INCLUDE"] = ''
20
21 os.mkdir(includes)
22 os.mkdir(libs)
23
24 with open(os.path.join(libs, "libarmnn.so"), "w"):
25 pass
26
27 with open(os.path.join(libs, "libarmnnSomeThing1.so"), "w"):
28 pass
29 with open(os.path.join(libs, "libarmnnSomeThing1.so.1"), "w"):
30 pass
31 with open(os.path.join(libs, "libarmnnSomeThing1.so.1.2"), "w"):
32 pass
33
34 with open(os.path.join(libs, "libarmnnSomeThing2.so"), "w"):
35 pass
36
37 with open(os.path.join(libs, "libSomeThing3.so"), "w"):
38 pass
39
40 yield
41
42 del os.environ["TEST_ARMNN_INCLUDE"]
43 del os.environ["TEST_ARMNN_LIB"]
44 del os.environ["EMPTY_ARMNN_INCLUDE"]
45 shutil.rmtree(includes)
46 shutil.rmtree(libs)
47
48
49def test_find_armnn(tmpdir):
50 lib_names, lib_paths = find_armnn(lib_name='libarmnn*.so',
51 armnn_libs_env="TEST_ARMNN_LIB",
52 default_lib_search=("/lib",))
53 armnn_includes = find_includes(armnn_include_env="TEST_ARMNN_INCLUDE")
54
55 assert [':libarmnn.so', ':libarmnnSomeThing1.so', ':libarmnnSomeThing2.so'] == sorted(lib_names)
56 assert [os.path.join(tmpdir, 'lib')] == lib_paths
57 assert [os.path.join(tmpdir, 'include')] == armnn_includes
58
59
60def test_find_armnn_default_path(tmpdir):
61 lib_names, lib_paths = find_armnn(lib_name='libarmnn*.so',
62 armnn_libs_env="RUBBISH_LIB",
63 default_lib_search=(os.environ["TEST_ARMNN_LIB"],))
64 armnn_includes = find_includes('TEST_ARMNN_INCLUDE')
65 assert [':libarmnn.so', ':libarmnnSomeThing1.so', ':libarmnnSomeThing2.so'] == sorted(lib_names)
66 assert [os.path.join(tmpdir, 'lib')] == lib_paths
67 assert [os.path.join(tmpdir, 'include')] == armnn_includes
68
69
70def test_not_find_armnn(tmpdir):
71 with pytest.raises(RuntimeError) as err:
72 find_armnn(lib_name='libarmnn*.so', armnn_libs_env="RUBBISH_LIB",
73 default_lib_search=("/lib",))
74
75 assert 'ArmNN library libarmnn*.so was not found in (\'/lib\',)' in str(err.value)
76
77
78@pytest.mark.parametrize("env", ["RUBBISH_INCLUDE", "EMPTY_ARMNN_INCLUDE"])
79def test_rubbish_armnn_include(tmpdir, env):
80 includes = find_includes(armnn_include_env=env)
81 assert includes == ['/usr/local/include', '/usr/include']
82
83
84def test_gcc_serch_path():
85 assert linux_gcc_lib_search()
86
87
88def test_armnn_version():
89 check_armnn_version('20190800', '20190800')
90
91
92def test_incorrect_armnn_version():
93 with pytest.raises(AssertionError) as err:
94 check_armnn_version('20190800', '20190500')
95
96 assert 'Expected ArmNN version is 201905 but installed ArmNN version is 201908' in str(err.value)
97
98
99def test_armnn_version_patch_does_not_matter():
100 check_armnn_version('20190800', '20190801')