From: Loic Dachary Date: Tue, 24 Sep 2013 13:51:08 +0000 (+0200) Subject: ErasureCode: fix plugin loading threaded test X-Git-Tag: v0.71~87^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=4bc18189b14d43a48d4cb6eff80bc8e9d3a59e8f;p=ceph.git ErasureCode: fix plugin loading threaded test The TEST_F(ErasureCodePluginRegistryTest, factory_mutex) was bugous and only succeeded by chance. The sleep was on the factory constructor which was never called. An erasure code plugin that hangs forever on load is created instead. The sleep_forever.detach is replaced by pthread_cancel to interrupt the thread that hangs forever. If not, gtest will try to join the thread and never exit. Signed-off-by: Loic Dachary --- diff --git a/src/test/Makefile.am b/src/test/Makefile.am index 5b709d248a8..a3127be9455 100644 --- a/src/test/Makefile.am +++ b/src/test/Makefile.am @@ -323,6 +323,13 @@ libec_missing_entry_point_la_LIBADD = $(PTHREAD_LIBS) $(EXTRALIBS) libec_missing_entry_point_la_LDFLAGS = ${AM_LDFLAGS} -export-symbols-regex '.*__erasure_code_.*' erasure_codelib_LTLIBRARIES += libec_missing_entry_point.la +libec_hangs_la_SOURCES = test/osd/ErasureCodePluginHangs.cc +libec_hangs_la_CFLAGS = ${AM_CFLAGS} +libec_hangs_la_CXXFLAGS= ${AM_CXXFLAGS} +libec_hangs_la_LIBADD = $(PTHREAD_LIBS) $(EXTRALIBS) +libec_hangs_la_LDFLAGS = ${AM_LDFLAGS} -export-symbols-regex '.*__erasure_code_.*' +erasure_codelib_LTLIBRARIES += libec_hangs.la + libec_fail_to_initialize_la_SOURCES = test/osd/ErasureCodePluginFailToInitialize.cc libec_fail_to_initialize_la_CFLAGS = ${AM_CFLAGS} libec_fail_to_initialize_la_CXXFLAGS= ${AM_CXXFLAGS} diff --git a/src/test/osd/ErasureCodeExample.h b/src/test/osd/ErasureCodeExample.h index 95d79feb923..0fd55187559 100644 --- a/src/test/osd/ErasureCodeExample.h +++ b/src/test/osd/ErasureCodeExample.h @@ -34,17 +34,6 @@ class ErasureCodeExample : public ErasureCodeInterface { public: - useconds_t delay; - ErasureCodeExample(const map ¶meters) : - delay(0) - { - if (parameters.find("usleep") != parameters.end()) { - std::istringstream ss(parameters.find("usleep")->second); - ss >> delay; - usleep(delay); - } - } - virtual ~ErasureCodeExample() {} virtual int minimum_to_decode(const set &want_to_read, diff --git a/src/test/osd/ErasureCodePluginExample.cc b/src/test/osd/ErasureCodePluginExample.cc index 1543b1cdaed..6ae61c0a18d 100644 --- a/src/test/osd/ErasureCodePluginExample.cc +++ b/src/test/osd/ErasureCodePluginExample.cc @@ -14,6 +14,8 @@ * */ +#include + #include "osd/ErasureCodePlugin.h" #include "ErasureCodeExample.h" @@ -22,7 +24,7 @@ public: virtual int factory(const map ¶meters, ErasureCodeInterfaceRef *erasure_code) { - *erasure_code = ErasureCodeInterfaceRef(new ErasureCodeExample(parameters)); + *erasure_code = ErasureCodeInterfaceRef(new ErasureCodeExample()); return 0; } }; diff --git a/src/test/osd/ErasureCodePluginHangs.cc b/src/test/osd/ErasureCodePluginHangs.cc new file mode 100644 index 00000000000..ea73786b526 --- /dev/null +++ b/src/test/osd/ErasureCodePluginHangs.cc @@ -0,0 +1,24 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2013 Cloudwatt + * + * Author: Loic Dachary + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + */ + +#include +#include "osd/ErasureCodePlugin.h" + +int __erasure_code_init(char *plugin_name) +{ + sleep(1000); + return 0; +} diff --git a/src/test/osd/TestErasureCodeExample.cc b/src/test/osd/TestErasureCodeExample.cc index 6866dfdbb9f..f12e80c8cd0 100644 --- a/src/test/osd/TestErasureCodeExample.cc +++ b/src/test/osd/TestErasureCodeExample.cc @@ -20,24 +20,9 @@ #include "global/global_context.h" #include "gtest/gtest.h" -TEST(ErasureCodeExample, constructor) -{ - map parameters; - { - ErasureCodeExample example(parameters); - EXPECT_EQ(0u, example.delay); - } - parameters["usleep"] = "10"; - { - ErasureCodeExample example(parameters); - EXPECT_EQ(10u, example.delay); - } -} - TEST(ErasureCodeExample, minimum_to_decode) { - map parameters; - ErasureCodeExample example(parameters); + ErasureCodeExample example; set available_chunks; set want_to_read; want_to_read.insert(1); @@ -72,8 +57,7 @@ TEST(ErasureCodeExample, minimum_to_decode) TEST(ErasureCodeExample, minimum_to_decode_with_cost) { - map parameters; - ErasureCodeExample example(parameters); + ErasureCodeExample example; map available; set want_to_read; want_to_read.insert(1); @@ -117,8 +101,7 @@ TEST(ErasureCodeExample, minimum_to_decode_with_cost) TEST(ErasureCodeExample, encode_decode) { - map parameters; - ErasureCodeExample example(parameters); + ErasureCodeExample example; bufferlist in; in.append("ABCDE"); diff --git a/src/test/osd/TestErasureCodePlugin.cc b/src/test/osd/TestErasureCodePlugin.cc index ba7d13fbd2d..46ed4b1730d 100644 --- a/src/test/osd/TestErasureCodePlugin.cc +++ b/src/test/osd/TestErasureCodePlugin.cc @@ -28,19 +28,12 @@ protected: class Thread_factory : public Thread { public: - useconds_t delay; - - Thread_factory(useconds_t _delay) : - delay(_delay) - {} - virtual void *entry() { map parameters; parameters["erasure-code-directory"] = ".libs"; - parameters["usleep"] = delay; ErasureCodePluginRegistry &instance = ErasureCodePluginRegistry::instance(); ErasureCodeInterfaceRef erasure_code; - instance.factory("example", parameters, &erasure_code); + instance.factory("hangs", parameters, &erasure_code); return NULL; } }; @@ -58,7 +51,7 @@ TEST_F(ErasureCodePluginRegistryTest, factory_mutex) { // useconds_t delay = 0; const useconds_t DELAY_MAX = 20 * 1000 * 1000; - Thread_factory sleep_forever(1024 * 1024 * 1024); + Thread_factory sleep_forever; sleep_forever.create(); do { cout << "Trying (1) with delay " << delay << "us\n"; @@ -71,7 +64,8 @@ TEST_F(ErasureCodePluginRegistryTest, factory_mutex) { EXPECT_FALSE(instance.lock.TryLock()); - EXPECT_EQ(0, sleep_forever.detach()); + EXPECT_EQ(0, pthread_cancel(sleep_forever.get_thread_id())); + EXPECT_EQ(0, sleep_forever.join()); } TEST_F(ErasureCodePluginRegistryTest, all)