diff options
author | Sage Weil <sage@inktank.com> | 2013-09-24 08:42:49 -0700 |
---|---|---|
committer | Sage Weil <sage@inktank.com> | 2013-09-24 08:42:49 -0700 |
commit | 2cbe93b84025a840de3695df999cb3adf1da6aed (patch) | |
tree | bedbbb6aeb236173af042d7f1a45575b4457547c | |
parent | e1d7c32d8a9b56b047d567cb702e26ff4f8c9ddc (diff) | |
parent | 4bc18189b14d43a48d4cb6eff80bc8e9d3a59e8f (diff) | |
download | ceph-2cbe93b84025a840de3695df999cb3adf1da6aed.tar.gz |
Merge pull request #628 from dachary/wip-erasure-fix-thread-test
ErasureCode: fix plugin loading threaded test
Reviewed-by: Sage Weil <sage@inktank.com>
-rw-r--r-- | src/test/Makefile.am | 7 | ||||
-rw-r--r-- | src/test/osd/ErasureCodeExample.h | 11 | ||||
-rw-r--r-- | src/test/osd/ErasureCodePluginExample.cc | 4 | ||||
-rw-r--r-- | src/test/osd/ErasureCodePluginHangs.cc | 24 | ||||
-rw-r--r-- | src/test/osd/TestErasureCodeExample.cc | 23 | ||||
-rw-r--r-- | src/test/osd/TestErasureCodePlugin.cc | 14 |
6 files changed, 41 insertions, 42 deletions
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<std::string,std::string> ¶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<int> &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 <unistd.h> + #include "osd/ErasureCodePlugin.h" #include "ErasureCodeExample.h" @@ -22,7 +24,7 @@ public: virtual int factory(const map<std::string,std::string> ¶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 <libre.licensing@cloudwatt.com> + * + * Author: Loic Dachary <loic@dachary.org> + * + * 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 <unistd.h> +#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<std::string,std::string> 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<std::string,std::string> parameters; - ErasureCodeExample example(parameters); + ErasureCodeExample example; set<int> available_chunks; set<int> 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<std::string,std::string> parameters; - ErasureCodeExample example(parameters); + ErasureCodeExample example; map<int,int> available; set<int> want_to_read; want_to_read.insert(1); @@ -117,8 +101,7 @@ TEST(ErasureCodeExample, minimum_to_decode_with_cost) TEST(ErasureCodeExample, encode_decode) { - map<std::string,std::string> 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<std::string,std::string> 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) |