#include <test/UnitTests.hpp>
+#include <string>
+
#include <boost/test/unit_test.hpp>
+#include <boost/filesystem.hpp>
+
+static std::string g_TestSharedObjectSubDir = "src/backends/backendsCommon/test/";
+static std::string g_TestSharedObjectFileName = "libarmnnTestSharedObject.so";
+
+std::string GetTestFilePath(const std::string& fileName)
+{
+ using namespace boost::filesystem;
+
+ path currentPath(current_path());
+ path sharedObjectPath = currentPath.append(g_TestSharedObjectSubDir);
+ path sharedObjectFile = sharedObjectPath.append(fileName);
+ BOOST_TEST(exists(sharedObjectFile));
+
+ return sharedObjectFile.string();
+}
+
+void OpenCloseHandleTestImpl()
+{
+ using namespace armnn;
+
+ std::string sharedObjectFilePath = GetTestFilePath(g_TestSharedObjectFileName);
+
+ void* sharedObjectHandle = nullptr;
+ BOOST_CHECK_NO_THROW(sharedObjectHandle = DynamicBackendUtils::OpenHandle(sharedObjectFilePath));
+ BOOST_TEST((sharedObjectHandle != nullptr));
+
+ DynamicBackendUtils::CloseHandle(sharedObjectHandle);
+}
+
+void CloseInvalidHandleTestImpl()
+{
+ using namespace armnn;
+
+ // This calls must silently handle invalid handles and complete successfully (no segfaults, etc.)
+ DynamicBackendUtils::CloseHandle(nullptr);
+}
+
+void OpenEmptyFileNameTestImpl()
+{
+ using namespace armnn;
+
+ void* sharedObjectHandle = nullptr;
+ BOOST_CHECK_THROW(sharedObjectHandle = DynamicBackendUtils::OpenHandle(""), RuntimeException);
+ BOOST_TEST((sharedObjectHandle == nullptr));
+}
+
+void OpenNotExistingFileTestImpl()
+{
+ using namespace armnn;
+
+ void* sharedObjectHandle = nullptr;
+ BOOST_CHECK_THROW(sharedObjectHandle = DynamicBackendUtils::OpenHandle("NotExistingFileName"), RuntimeException);
+ BOOST_TEST((sharedObjectHandle == nullptr));
+}
+
+void OpenNotSharedObjectTestImpl()
+{
+ using namespace armnn;
+
+ std::string notSharedObjectFilePath = GetTestFilePath("libarmnnNoSharedObject.txt");
+
+ void* sharedObjectHandle = nullptr;
+ BOOST_CHECK_THROW(sharedObjectHandle = DynamicBackendUtils::OpenHandle(notSharedObjectFilePath), RuntimeException);
+ BOOST_TEST((sharedObjectHandle == nullptr));
+}
+
+void GetValidEntryPointTestImpl()
+{
+ using namespace armnn;
+
+ std::string sharedObjectFilePath = GetTestFilePath(g_TestSharedObjectFileName);
+
+ void* sharedObjectHandle = nullptr;
+ BOOST_CHECK_NO_THROW(sharedObjectHandle = DynamicBackendUtils::OpenHandle(sharedObjectFilePath));
+ BOOST_TEST((sharedObjectHandle != nullptr));
+
+ using TestFunctionType = int(*)(int);
+ TestFunctionType testFunctionPointer = nullptr;
+ BOOST_CHECK_NO_THROW(testFunctionPointer = DynamicBackendUtils::GetEntryPoint<TestFunctionType>(sharedObjectHandle,
+ "TestFunction1"));
+ BOOST_TEST((testFunctionPointer != nullptr));
+ BOOST_TEST(testFunctionPointer(7) == 7);
+
+ DynamicBackendUtils::CloseHandle(sharedObjectHandle);
+}
+
+void GetNameMangledEntryPointTestImpl()
+{
+ using namespace armnn;
+
+ std::string sharedObjectFilePath = GetTestFilePath(g_TestSharedObjectFileName);
+
+ void* sharedObjectHandle = nullptr;
+ BOOST_CHECK_NO_THROW(sharedObjectHandle = DynamicBackendUtils::OpenHandle(sharedObjectFilePath));
+ BOOST_TEST((sharedObjectHandle != nullptr));
+
+ using TestFunctionType = int(*)(int);
+ TestFunctionType testFunctionPointer = nullptr;
+ BOOST_CHECK_THROW(testFunctionPointer = DynamicBackendUtils::GetEntryPoint<TestFunctionType>(sharedObjectHandle,
+ "TestFunction2"),
+ RuntimeException);
+ BOOST_TEST((testFunctionPointer == nullptr));
+
+ DynamicBackendUtils::CloseHandle(sharedObjectHandle);
+}
+
+void GetNoExternEntryPointTestImpl()
+{
+ using namespace armnn;
+
+ std::string sharedObjectFilePath = GetTestFilePath(g_TestSharedObjectFileName);
+
+ void* sharedObjectHandle = nullptr;
+ BOOST_CHECK_NO_THROW(sharedObjectHandle = DynamicBackendUtils::OpenHandle(sharedObjectFilePath));
+ BOOST_TEST((sharedObjectHandle != nullptr));
+
+ using TestFunctionType = int(*)(int);
+ TestFunctionType testFunctionPointer = nullptr;
+ BOOST_CHECK_THROW(testFunctionPointer = DynamicBackendUtils::GetEntryPoint<TestFunctionType>(sharedObjectHandle,
+ "TestFunction3"),
+ RuntimeException);
+ BOOST_TEST((testFunctionPointer == nullptr));
+
+ DynamicBackendUtils::CloseHandle(sharedObjectHandle);
+}
+
+void GetNotExistingEntryPointTestImpl()
+{
+ using namespace armnn;
+
+ std::string sharedObjectFilePath = GetTestFilePath(g_TestSharedObjectFileName);
+
+ void* sharedObjectHandle = nullptr;
+ BOOST_CHECK_NO_THROW(sharedObjectHandle = DynamicBackendUtils::OpenHandle(sharedObjectFilePath));
+ BOOST_TEST((sharedObjectHandle != nullptr));
+
+ using TestFunctionType = int(*)(int);
+ TestFunctionType testFunctionPointer = nullptr;
+ BOOST_CHECK_THROW(testFunctionPointer = DynamicBackendUtils::GetEntryPoint<TestFunctionType>(sharedObjectHandle,
+ "TestFunction4"),
+ RuntimeException);
+ BOOST_TEST((testFunctionPointer == nullptr));
+
+ DynamicBackendUtils::CloseHandle(sharedObjectHandle);
+}
void BackendVersioningTestImpl()
{
- class TestDynamicBackendUtils : public armnn::DynamicBackendUtils
+ using namespace armnn;
+
+ class TestDynamicBackendUtils : public DynamicBackendUtils
{
public:
- static bool IsBackendCompatibleTest(const armnn::BackendVersion& backendApiVersion,
- const armnn::BackendVersion& backendVersion)
+ static bool IsBackendCompatibleTest(const BackendVersion& backendApiVersion,
+ const BackendVersion& backendVersion)
{
return IsBackendCompatibleImpl(backendApiVersion, backendVersion);
}
};
// The backend API version used for the tests
- armnn::BackendVersion backendApiVersion{ 2, 4 };
+ BackendVersion backendApiVersion{ 2, 4 };
// Same backend and backend API versions are compatible with the backend API
- armnn::BackendVersion sameBackendVersion{ 2, 4 };
+ BackendVersion sameBackendVersion{ 2, 4 };
BOOST_TEST(sameBackendVersion == backendApiVersion);
BOOST_TEST(sameBackendVersion <= backendApiVersion);
BOOST_TEST(TestDynamicBackendUtils::IsBackendCompatibleTest(backendApiVersion, sameBackendVersion) == true);
// Backend versions that differ from the backend API version by major revision are not compatible
// with the backend API
- armnn::BackendVersion laterMajorBackendVersion{ 3, 4 };
+ BackendVersion laterMajorBackendVersion{ 3, 4 };
BOOST_TEST(!(laterMajorBackendVersion == backendApiVersion));
BOOST_TEST(!(laterMajorBackendVersion <= backendApiVersion));
BOOST_TEST(TestDynamicBackendUtils::IsBackendCompatibleTest(backendApiVersion, laterMajorBackendVersion) == false);
- armnn::BackendVersion earlierMajorBackendVersion{ 1, 4 };
+ BackendVersion earlierMajorBackendVersion{ 1, 4 };
BOOST_TEST(!(earlierMajorBackendVersion == backendApiVersion));
BOOST_TEST(earlierMajorBackendVersion <= backendApiVersion);
BOOST_TEST(TestDynamicBackendUtils::IsBackendCompatibleTest(backendApiVersion,
// Backend versions with the same major revision but later minor revision than
// the backend API version are not compatible with the backend API
- armnn::BackendVersion laterMinorBackendVersion{ 2, 5 };
+ BackendVersion laterMinorBackendVersion{ 2, 5 };
BOOST_TEST(!(laterMinorBackendVersion == backendApiVersion));
BOOST_TEST(!(laterMinorBackendVersion <= backendApiVersion));
BOOST_TEST(TestDynamicBackendUtils::IsBackendCompatibleTest(backendApiVersion, laterMinorBackendVersion) == false);
// Backend versions with the same major revision but earlier minor revision than
// the backend API version are compatible with the backend API
- armnn::BackendVersion earlierMinorBackendVersion{ 2, 3 };
+ BackendVersion earlierMinorBackendVersion{ 2, 3 };
BOOST_TEST(!(earlierMinorBackendVersion == backendApiVersion));
BOOST_TEST(earlierMinorBackendVersion <= backendApiVersion);
BOOST_TEST(TestDynamicBackendUtils::IsBackendCompatibleTest(backendApiVersion, earlierMinorBackendVersion) == true);