From 245d64c60d0ea30f5080ff53225b5169927e24d6 Mon Sep 17 00:00:00 2001 From: Matthew Bentham Date: Mon, 2 Dec 2019 12:59:43 +0000 Subject: Work in progress of python bindings for Arm NN Not built or tested in any way Signed-off-by: Matthew Bentham Change-Id: Ie7f92b529aa5087130f0c5cc8c17db1581373236 --- python/pyarmnn/test/test_setup.py | 100 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 python/pyarmnn/test/test_setup.py (limited to 'python/pyarmnn/test/test_setup.py') diff --git a/python/pyarmnn/test/test_setup.py b/python/pyarmnn/test/test_setup.py new file mode 100644 index 0000000000..8061f26054 --- /dev/null +++ b/python/pyarmnn/test/test_setup.py @@ -0,0 +1,100 @@ +# Copyright © 2019 Arm Ltd. All rights reserved. +# SPDX-License-Identifier: MIT +import os +import sys +import shutil + +import pytest + +sys.path.append(os.path.abspath('..')) +from setup import find_armnn, find_includes, linux_gcc_lib_search, check_armnn_version + + +@pytest.fixture(autouse=True) +def _setup_armnn(tmpdir): + includes = str(os.path.join(tmpdir, 'include')) + libs = str(os.path.join(tmpdir, 'lib')) + os.environ["TEST_ARMNN_INCLUDE"] = includes + os.environ["TEST_ARMNN_LIB"] = libs + os.environ["EMPTY_ARMNN_INCLUDE"] = '' + + os.mkdir(includes) + os.mkdir(libs) + + with open(os.path.join(libs, "libarmnn.so"), "w"): + pass + + with open(os.path.join(libs, "libarmnnSomeThing1.so"), "w"): + pass + with open(os.path.join(libs, "libarmnnSomeThing1.so.1"), "w"): + pass + with open(os.path.join(libs, "libarmnnSomeThing1.so.1.2"), "w"): + pass + + with open(os.path.join(libs, "libarmnnSomeThing2.so"), "w"): + pass + + with open(os.path.join(libs, "libSomeThing3.so"), "w"): + pass + + yield + + del os.environ["TEST_ARMNN_INCLUDE"] + del os.environ["TEST_ARMNN_LIB"] + del os.environ["EMPTY_ARMNN_INCLUDE"] + shutil.rmtree(includes) + shutil.rmtree(libs) + + +def test_find_armnn(tmpdir): + lib_names, lib_paths = find_armnn(lib_name='libarmnn*.so', + armnn_libs_env="TEST_ARMNN_LIB", + default_lib_search=("/lib",)) + armnn_includes = find_includes(armnn_include_env="TEST_ARMNN_INCLUDE") + + assert [':libarmnn.so', ':libarmnnSomeThing1.so', ':libarmnnSomeThing2.so'] == sorted(lib_names) + assert [os.path.join(tmpdir, 'lib')] == lib_paths + assert [os.path.join(tmpdir, 'include')] == armnn_includes + + +def test_find_armnn_default_path(tmpdir): + lib_names, lib_paths = find_armnn(lib_name='libarmnn*.so', + armnn_libs_env="RUBBISH_LIB", + default_lib_search=(os.environ["TEST_ARMNN_LIB"],)) + armnn_includes = find_includes('TEST_ARMNN_INCLUDE') + assert [':libarmnn.so', ':libarmnnSomeThing1.so', ':libarmnnSomeThing2.so'] == sorted(lib_names) + assert [os.path.join(tmpdir, 'lib')] == lib_paths + assert [os.path.join(tmpdir, 'include')] == armnn_includes + + +def test_not_find_armnn(tmpdir): + with pytest.raises(RuntimeError) as err: + find_armnn(lib_name='libarmnn*.so', armnn_libs_env="RUBBISH_LIB", + default_lib_search=("/lib",)) + + assert 'ArmNN library libarmnn*.so was not found in (\'/lib\',)' in str(err.value) + + +@pytest.mark.parametrize("env", ["RUBBISH_INCLUDE", "EMPTY_ARMNN_INCLUDE"]) +def test_rubbish_armnn_include(tmpdir, env): + includes = find_includes(armnn_include_env=env) + assert includes == ['/usr/local/include', '/usr/include'] + + +def test_gcc_serch_path(): + assert linux_gcc_lib_search() + + +def test_armnn_version(): + check_armnn_version('20190800', '20190800') + + +def test_incorrect_armnn_version(): + with pytest.raises(AssertionError) as err: + check_armnn_version('20190800', '20190500') + + assert 'Expected ArmNN version is 201905 but installed ArmNN version is 201908' in str(err.value) + + +def test_armnn_version_patch_does_not_matter(): + check_armnn_version('20190800', '20190801') -- cgit v1.2.1