Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add testing infrastructure for the DynamicLibraryManager #155

Merged
merged 2 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Interpreter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ target_link_libraries(clangCppInterOp PRIVATE
${cling_clang_interp}
clangAST
clangBasic
clangFrontend
clangLex
clangSema
dl
Expand All @@ -45,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}\""
)

6 changes: 4 additions & 2 deletions lib/Interpreter/DynamicLibraryManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,10 @@
if (llvm::sys::path::is_absolute(libStem)) {
if (isSharedLibrary(libStem))
return normalizePath(libStem);
else
return std::string();

LLVM_DEBUG(dbgs() << "Dyld::lookupLibrary: '" << libStem.str() << "'"

Check warning on line 290 in lib/Interpreter/DynamicLibraryManager.cpp

View check run for this annotation

Codecov / codecov/patch

lib/Interpreter/DynamicLibraryManager.cpp#L290

Added line #L290 was not covered by tests
<< "is not a shared library\n");
return std::string();

Check warning on line 292 in lib/Interpreter/DynamicLibraryManager.cpp

View check run for this annotation

Codecov / codecov/patch

lib/Interpreter/DynamicLibraryManager.cpp#L292

Added line #L292 was not covered by tests
}

// Subst all known linker variables ($origin, @rpath, etc.)
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(TestSharedLib)
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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: 'gtest/gtest.h' file not found [clang-diagnostic-error]

#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 SHARED 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; }

Check warning on line 3 in unittests/CppInterOp/TestSharedLib/TestSharedLib.cpp

View check run for this annotation

Codecov / codecov/patch

unittests/CppInterOp/TestSharedLib/TestSharedLib.cpp#L3

Added line #L3 was not covered by tests
6 changes: 6 additions & 0 deletions unittests/CppInterOp/TestSharedLib/TestSharedLib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef UNITTESTS_CPPINTEROP_TESTSHAREDLIB_TESTSHAREDLIB_H
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: header is missing header guard [llvm-header-guard]

Suggested change
#ifndef UNITTESTS_CPPINTEROP_TESTSHAREDLIB_TESTSHAREDLIB_H
#ifndef GITHUB_WORKSPACE_UNITTESTS_CPPINTEROP_TESTSHAREDLIB_TESTSHAREDLIB_H
#define GITHUB_WORKSPACE_UNITTESTS_CPPINTEROP_TESTSHAREDLIB_TESTSHAREDLIB_H

unittests/CppInterOp/TestSharedLib/TestSharedLib.h:-1:

+ 
+ #endif

#define UNITTESTS_CPPINTEROP_TESTSHAREDLIB_TESTSHAREDLIB_H
Comment on lines +1 to +2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: header guard does not follow preferred style [llvm-header-guard]

Suggested change
#ifndef UNITTESTS_CPPINTEROP_TESTSHAREDLIB_TESTSHAREDLIB_H
#define UNITTESTS_CPPINTEROP_TESTSHAREDLIB_TESTSHAREDLIB_H
#ifndef GITHUB_WORKSPACE_UNITTESTS_CPPINTEROP_TESTSHAREDLIB_TESTSHAREDLIB_H
#define GITHUB_WORKSPACE_UNITTESTS_CPPINTEROP_TESTSHAREDLIB_TESTSHAREDLIB_H

unittests/CppInterOp/TestSharedLib/TestSharedLib.h:5:

- #endif // UNITTESTS_CPPINTEROP_TESTSHAREDLIB_TESTSHAREDLIB_H
+ #endif // GITHUB_WORKSPACE_UNITTESTS_CPPINTEROP_TESTSHAREDLIB_TESTSHAREDLIB_H


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: header is missing header guard [llvm-header-guard]

Suggested change
#ifndef GITHUB_WORKSPACE_UNITTESTS_CPPINTEROP_TESTSHAREDLIB_TESTSHAREDLIB_H
#define GITHUB_WORKSPACE_UNITTESTS_CPPINTEROP_TESTSHAREDLIB_TESTSHAREDLIB_H

unittests/CppInterOp/TestSharedLib/TestSharedLib.h:-1:

+ 
+ #endif

int ret_zero();

#endif // UNITTESTS_CPPINTEROP_TESTSHAREDLIB_TESTSHAREDLIB_H
Loading