Skip to content

Commit

Permalink
Move the libtestsharedlib to a more convenient place
Browse files Browse the repository at this point in the history
Signed-off-by: Shreyas Atre <[email protected]>
  • Loading branch information
SAtacker committed Feb 17, 2024
1 parent 9a693a6 commit 01fb500
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions unittests/CppInterOp/DynamicLibraryManagerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

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

#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
// GetMainExecutable (since some platforms don't support taking the
Expand Down Expand Up @@ -44,6 +42,17 @@ TEST(DynamicLibraryManagerTest, Sanity) {
<< "Cannot find: '" << PathToTestSharedLib << "' in '" << Dir.str()
<< "'";

// DLOPEN DLCLOSE Test
std::string err = "";
auto* dlopen_handle = Cpp::utils::platform::DLOpen(PathToTestSharedLib, err);
EXPECT_TRUE(dlopen_handle) << "Error occurred: " << err << "\n";
Cpp::utils::platform::DLClose(dlopen_handle, err);
EXPECT_TRUE(err.empty()) << "Error occurred: " << err << "\n";
Cpp::utils::platform::DLOpen("missing", err);
EXPECT_TRUE(err.find("no such file") != std::string::npos ||
err.find("No such file") != std::string::npos);
// DLOPEN DLCLOSE Test end

EXPECT_TRUE(Cpp::LoadLibrary(PathToTestSharedLib.c_str()));
// Force ExecutionEngine to be created.
Cpp::Process("");
Expand All @@ -58,20 +67,3 @@ TEST(DynamicLibraryManagerTest, Sanity) {
// invalidated...
// EXPECT_FALSE(Cpp::GetFunctionAddress("ret_zero"));
}

TEST(UtilsPlatform, DLTest) {
std::string err = "";
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";
auto dlopen_handle = Cpp::utils::platform::DLOpen(path, err);
EXPECT_TRUE(dlopen_handle);
EXPECT_TRUE(err.empty());
Cpp::utils::platform::DLOpen("missing", err);
EXPECT_TRUE(err.find("no such file") != std::string::npos ||
err.find("No such file") != std::string::npos);
}

0 comments on commit 01fb500

Please sign in to comment.