From 01fb500a2f1612d1ceb09c1b3cc07d45730d47ee Mon Sep 17 00:00:00 2001 From: Shreyas Atre Date: Fri, 16 Feb 2024 21:52:09 -0600 Subject: [PATCH] Move the libtestsharedlib to a more convenient place Signed-off-by: Shreyas Atre --- .../CppInterOp/DynamicLibraryManagerTest.cpp | 30 +++++++------------ 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/unittests/CppInterOp/DynamicLibraryManagerTest.cpp b/unittests/CppInterOp/DynamicLibraryManagerTest.cpp index 96ad69af..f61b62fd 100644 --- a/unittests/CppInterOp/DynamicLibraryManagerTest.cpp +++ b/unittests/CppInterOp/DynamicLibraryManagerTest.cpp @@ -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 @@ -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(""); @@ -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<