Skip to content
Snippets Groups Projects
Commit 8355f2c2 authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Merge branch 'master' into exp/fusionmodel

parents 8aea8645 a60fa0b3
No related branches found
No related tags found
1 merge request!358Updates to SDK and alternative fusion
import unittest
class LoadLibrary(unittest.TestCase):
def test_get_instance(self):
import voltu
self.assertIsNotNone(voltu.instance())
# second call to instance() returns None
#self.assertIsNotNone(voltu.instance())
if __name__ == '__main__':
unittest.main()
......@@ -10,10 +10,17 @@
#if defined(WIN32)
#include <windows.h>
#pragma comment(lib, "User32.lib")
#else
#include <dlfcn.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#endif
#include <cstdlib>
#include <iostream>
static bool g_init = false;
typedef void* Library;
......@@ -48,13 +55,50 @@ static void unloadLibrary(Library lib)
#endif
}
static bool is_file(const std::string &path)
{
#ifdef WIN32
WIN32_FIND_DATA ffd;
HANDLE hFind = FindFirstFile(path.c_str(), &ffd);
if (hFind == INVALID_HANDLE_VALUE) return false;
FindClose(hFind);
return true;
#else
struct stat s;
if (::stat(path.c_str(), &s) == 0)
{
return true;
}
else
{
return false;
}
#endif
}
static std::string locateLibrary()
{
// TODO: Use full paths and find correct versions
#if defined(WIN32)
return "voltu.dll";
#else
return "libvoltu.so";
std::string name = "libvoltu.so";
std::string vname = name + std::string(".") + std::to_string(VOLTU_VERSION_MAJOR) + std::string(".") + std::to_string(VOLTU_VERSION_MINOR);
if (const char* env_p = std::getenv("VOLTU_RUNTIME"))
{
if (is_file(env_p)) return env_p;
}
// FIXME: Should eventually not have these...
if (is_file(std::string("./") + vname)) return std::string("./") + vname;
//else if (is_file(std::string("./") + name)) return std::string("./") + name;
else if (is_file(std::string("../") + vname)) return std::string("../") + vname;
/*else if (is_file(std::string("../") + name)) return std::string("../") + name;
else if (is_file(std::string("/usr/local/lib/") + vname)) return std::string("/usr/local/lib/") + vname;
else if (is_file(std::string("/usr/local/lib/") + name)) return std::string("/usr/local/lib/") + name;*/
return vname;
#endif
}
......@@ -63,6 +107,7 @@ std::shared_ptr<voltu::System> voltu::instance()
if (g_init) return nullptr;
std::string name = locateLibrary();
std::cout << "Loading VolTu Runtime: " << name << std::endl;
Library handle = loadLibrary(name.c_str());
if (handle)
......
find_package(Python3 COMPONENTS Interpreter)
function(add_python_test TEST_NAME TEST_SCRIPT)
add_test(NAME ${TEST_NAME}
COMMAND Python3::Interpreter -B -m unittest ${TEST_SCRIPT}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
# binary module directory to PYTHONPATH, additional variables have to be
# separated by semicolon
set_tests_properties(${TEST_NAME} PROPERTIES ENVIRONMENT
"PYTHONPATH=${SDK_BINARY_DIR}/python;LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/..")
set_property(TEST ${TEST_NAME} APPEND PROPERTY DEPENDS voltu_sdk)
endfunction()
add_python_test(Py_TestLoad test_load.py)
File moved
import unittest
import os
class LoadLibrary(unittest.TestCase):
def test_import(self):
import voltu
def test_import_twice(self):
# verify that System instance is created just once, even if module
# imported multiple times
import voltu
import voltu
self.assertIsNotNone(voltu.System)
def test_version(self):
import voltu
major, minor, patch = voltu.version
if __name__ == '__main__':
unittest.main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment