]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
test/librados_test_stub: deterministically load cls shared libraries 21524/head
authorJason Dillaman <dillaman@redhat.com>
Thu, 19 Apr 2018 13:43:14 +0000 (09:43 -0400)
committerJason Dillaman <dillaman@redhat.com>
Sat, 21 Apr 2018 13:50:38 +0000 (09:50 -0400)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/test/librados_test_stub/TestClassHandler.cc

index b8a32dfc5047cfb00430d7bf150ad6bee532cf24..b61abfe76a8399db6caf11c4dd7962e0202b6e2c 100644 (file)
@@ -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<void (*)()>(
-      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<std::string> 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<Class*>(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;