From ca61b98ff0d16b137ec3c88778980df75115ad95 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Thu, 19 Apr 2018 09:43:14 -0400 Subject: [PATCH] test/librados_test_stub: deterministically load cls shared libraries Signed-off-by: Jason Dillaman --- .../librados_test_stub/TestClassHandler.cc | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/src/test/librados_test_stub/TestClassHandler.cc b/src/test/librados_test_stub/TestClassHandler.cc index b8a32dfc504..b61abfe76a8 100644 --- a/src/test/librados_test_stub/TestClassHandler.cc +++ b/src/test/librados_test_stub/TestClassHandler.cc @@ -30,17 +30,30 @@ void TestClassHandler::open_class(const std::string& name, const std::string& path) { void *handle = dlopen(path.c_str(), RTLD_NOW); if (handle == NULL) { - derr << "Failed to load class: " << dlerror() << dendl; + std::cerr << "Failed to load class: " << name << " (" << path << "): " + << dlerror() << std::endl; return; } - m_class_handles.push_back(handle); + + // clear any existing error + dlerror(); // initialize void (*cls_init)() = reinterpret_cast( - dlsym(handle, "__cls_init")); - if (cls_init) { + dlsym(handle, "__cls_init")); + + char* error = nullptr; + if ((error = dlerror()) != nullptr) { + std::cerr << "Error locating initializer: " << error << std::endl; + } else if (cls_init) { + m_class_handles.push_back(handle); cls_init(); + return; } + + std::cerr << "Class: " << name << " (" << path << ") missing initializer" + << std::endl; + dlclose(handle); } void TestClassHandler::open_all_classes() { @@ -53,6 +66,7 @@ void TestClassHandler::open_all_classes() { ceph_abort();; } + std::set names; struct dirent *pde = nullptr; while ((pde = ::readdir(dir))) { std::string name(pde->d_name); @@ -60,6 +74,10 @@ void TestClassHandler::open_all_classes() { !boost::algorithm::ends_with(name, ".so")) { continue; } + names.insert(name); + } + + for (auto& name : names) { std::string class_name = name.substr(7, name.size() - 10); open_class(class_name, CEPH_LIB + "/" + name); } @@ -68,6 +86,7 @@ void TestClassHandler::open_all_classes() { int TestClassHandler::create(const std::string &name, cls_handle_t *handle) { if (m_classes.find(name) != m_classes.end()) { + std::cerr << "Class " << name << " already exists" << std::endl; return -EEXIST; } @@ -83,6 +102,8 @@ int TestClassHandler::create_method(cls_handle_t hclass, cls_method_handle_t *handle) { Class *cls = reinterpret_cast(hclass); if (cls->methods.find(name) != cls->methods.end()) { + std::cerr << "Class method " << hclass << ":" << name << " already exists" + << std::endl; return -EEXIST; } @@ -96,12 +117,15 @@ cls_method_cxx_call_t TestClassHandler::get_method(const std::string &cls, const std::string &method) { Classes::iterator c_it = m_classes.find(cls); if (c_it == m_classes.end()) { + std::cerr << "Failed to located class " << cls << std::endl; return NULL; } SharedClass scls = c_it->second; Methods::iterator m_it = scls->methods.find(method); if (m_it == scls->methods.end()) { + std::cerr << "Failed to located class method" << cls << "." << method + << std::endl; return NULL; } return m_it->second->class_call; -- 2.39.5