Skip to content

Commit

Permalink
Use DynamicLibraryManager to find library
Browse files Browse the repository at this point in the history
Signed-off-by: Shreyas Atre <[email protected]>
  • Loading branch information
SAtacker committed Feb 16, 2024
1 parent f991b6b commit 9a693a6
Showing 1 changed file with 7 additions and 20 deletions.
27 changes: 7 additions & 20 deletions unittests/CppInterOp/DynamicLibraryManagerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "../../lib/Interpreter/Paths.h"

#include <filesystem>
#include "../../lib/Interpreter/DynamicLibraryManager.h"

// This function isn't referenced outside its translation unit, but it
// can't use the "static" keyword because its address is used for
Expand Down Expand Up @@ -61,27 +61,14 @@ TEST(DynamicLibraryManagerTest, Sanity) {

TEST(UtilsPlatform, DLTest) {
std::string err = "";
std::string path = "";
for (auto const& dir_entry : std::filesystem::recursive_directory_iterator(
std::filesystem::current_path())) {
if (std::string(dir_entry.path()).find("libTestSharedLib.") !=
std::string::npos) {
path = dir_entry.path();
break;
}
}
std::string BinaryPath = GetExecutablePath(/*Argv0=*/nullptr);
llvm::StringRef Dir = llvm::sys::path::parent_path(BinaryPath);
Cpp::AddSearchPath(Dir.str().c_str());
std::string path =
(new Cpp::DynamicLibraryManager)->lookupLibrary("libTestSharedLib");
EXPECT_FALSE(path.empty());
std::cout<<path<<"\n";
#if defined(__APPLE__)
auto dlopen_handle =
Cpp::utils::platform::DLOpen("./libTestSharedLib.dylib", err);
#elif defined(_WIN32)
auto dlopen_handle =
Cpp::utils::platform::DLOpen("./libTestSharedLib.dll", err);
#else
auto dlopen_handle =
Cpp::utils::platform::DLOpen("./libTestSharedLib.so", err);
#endif
auto dlopen_handle = Cpp::utils::platform::DLOpen(path, err);
EXPECT_TRUE(dlopen_handle);
EXPECT_TRUE(err.empty());
Cpp::utils::platform::DLOpen("missing", err);
Expand Down

0 comments on commit 9a693a6

Please sign in to comment.