Skip to content

Commit

Permalink
Add testing infrastructure for the DynamicLibraryManager.
Browse files Browse the repository at this point in the history
  • Loading branch information
vgvassilev committed Oct 19, 2023
1 parent 5216155 commit 88f6bd4
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 5 deletions.
1 change: 0 additions & 1 deletion lib/Interpreter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,3 @@ string(REPLACE ";" "\;" _VER CPPINTEROP_VERSION)
set_source_files_properties(CppInterOp.cpp PROPERTIES COMPILE_DEFINITIONS
"LLVM_BINARY_DIR=\"${LLVM_BINARY_DIR}\";CPPINTEROP_VERSION=\"${_VAR}\""
)

11 changes: 7 additions & 4 deletions lib/Interpreter/DynamicLibraryManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,13 @@ namespace Cpp {

// If it is an absolute path, don't try iterate over the paths.
if (llvm::sys::path::is_absolute(libStem)) {
if (isSharedLibrary(libStem))
if (isSharedLibrary(libStem)) {
return normalizePath(libStem);
else
} else {
LLVM_DEBUG(dbgs() << "Dyld::lookupLibrary: '" << libStem.str() << "'"
<< "is not a shared library\n");
return std::string();
}
}

// Subst all known linker variables ($origin, @rpath, etc.)
Expand Down Expand Up @@ -464,7 +467,8 @@ namespace Cpp {
(Magic == file_magic::macho_fixed_virtual_memory_shared_lib
|| Magic == file_magic::macho_dynamically_linked_shared_lib
|| Magic == file_magic::macho_dynamically_linked_shared_lib_stub
|| Magic == file_magic::macho_universal_binary)
|| Magic == file_magic::macho_universal_binary
|| Magic == file_magic::macho_bundle)
#elif defined(LLVM_ON_UNIX)
#ifdef __CYGWIN__
(Magic == file_magic::pecoff_executable)
Expand All @@ -480,7 +484,6 @@ namespace Cpp {
# error "Unsupported platform."
#endif
;

return result;
}

Expand Down
12 changes: 12 additions & 0 deletions unittests/CppInterOp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,15 @@ target_link_libraries(CppInterOpTests
)

export_executable_symbols(CppInterOpTests)

unset(LLVM_LINK_COMPONENTS)

add_cppinterop_unittest(DynamicLibraryManagerTests DynamicLibraryManagerTest.cpp)
target_link_libraries(DynamicLibraryManagerTests
PRIVATE
clangCppInterOp
)

add_dependencies(DynamicLibraryManagerTests TestSharedLib)
#export_executable_symbols_for_plugins(PluginsTests)
add_subdirectory(TestSharedLib)
8 changes: 8 additions & 0 deletions unittests/CppInterOp/DynamicLibraryManagerTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "gtest/gtest.h"

#include "clang/Interpreter/CppInterOp.h"

TEST(DynamicLibraryManagerTest, Sanity) {
EXPECT_TRUE(Cpp::CreateInterpreter());
EXPECT_TRUE(Cpp::LoadLibrary("TestSharedLib"));
}
7 changes: 7 additions & 0 deletions unittests/CppInterOp/TestSharedLib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
add_llvm_library(TestSharedLib MODULE BUILDTREE_ONLY TestSharedLib.cpp)
# Put TestSharedLib next to the unit test executable.
set_output_directory(TestSharedLib
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/../
LIBRARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/../
)
set_target_properties(TestSharedLib PROPERTIES FOLDER "Tests")
3 changes: 3 additions & 0 deletions unittests/CppInterOp/TestSharedLib/TestSharedLib.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "TestSharedLib.h"

int ret_zero() { return 0; }
2 changes: 2 additions & 0 deletions unittests/CppInterOp/TestSharedLib/TestSharedLib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

int ret_zero();

0 comments on commit 88f6bd4

Please sign in to comment.