IVGCVSW-4813 Update semantic versioning of ArmNN to 22.0.0 for 20.08 release
[platform/upstream/armnn.git] / python / pyarmnn / test / test_setup.py
1 # Copyright © 2020 Arm Ltd. All rights reserved.
2 # Copyright 2020 NXP
3 # SPDX-License-Identifier: MIT
4 import os
5 import sys
6 import shutil
7
8 import pytest
9
10 sys.path.append(os.path.abspath('..'))
11 from setup import find_armnn, find_includes, linux_gcc_lib_search, check_armnn_version
12
13
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"] = ''
21
22     os.mkdir(includes)
23     os.mkdir(libs)
24
25     with open(os.path.join(libs, "libarmnn.so"), "w"):
26         pass
27
28     with open(os.path.join(libs, "libarmnnSomeThing1.so"), "w"):
29         pass
30     with open(os.path.join(libs, "libarmnnSomeThing1.so.1"), "w"):
31         pass
32     with open(os.path.join(libs, "libarmnnSomeThing1.so.1.2"), "w"):
33         pass
34
35     with open(os.path.join(libs, "libarmnnSomeThing2.so"), "w"):
36         pass
37
38     with open(os.path.join(libs, "libSomeThing3.so"), "w"):
39         pass
40
41     yield
42
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)
47     shutil.rmtree(libs)
48
49
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")
55
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
59
60
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
69
70
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",))
75
76     assert 'ArmNN library libarmnn*.so was not found in (\'/lib\',)' in str(err.value)
77
78
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']
83
84
85 def test_gcc_serch_path():
86     assert linux_gcc_lib_search()
87
88
89 def test_armnn_version():
90     check_armnn_version('22.0.0', '22.0.0')
91
92
93 def test_incorrect_armnn_version():
94     with pytest.raises(AssertionError) as err:
95         check_armnn_version('22.0.0', '22.1.0')
96
97     assert 'Expected ArmNN version is 22.1.0 but installed ArmNN version is 22.0.0' in str(err.value)
98
99
100 def test_armnn_version_patch_does_not_matter():
101     check_armnn_version('22.0.0', '22.0.1')