1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2014,2015 FUJITSU LIMITED
8 * Author: Shotaro Kawaguchi <kawaguchi.s@jp.fujitsu.com>
9 * Author: Takanori Nakao <nakao.takanori@jp.fujitsu.com>
10 * Author: Takeshi Miyamae <miyamae.takeshi@jp.fujitsu.com>
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 2.1 of the License, or (at your option) any later version.
19 // SUMMARY: TestErasureCodeShec executes some threads at the same time
25 #include "crush/CrushWrapper.h"
26 #include "osd/osd_types.h"
27 #include "include/stringify.h"
28 #include "erasure-code/shec/ErasureCodeShec.h"
29 #include "erasure-code/ErasureCodePlugin.h"
30 #include "global/global_context.h"
31 #include "gtest/gtest.h"
33 void* thread1(void* pParam);
40 TEST(ErasureCodeShec, thread)
42 TestParam param1, param2, param3, param4, param5;
68 pthread_t tid1, tid2, tid3, tid4, tid5;
69 pthread_create(&tid1, NULL, thread1, (void*) ¶m1);
70 std::cout << "thread1 start " << std::endl;
71 pthread_create(&tid2, NULL, thread1, (void*) ¶m2);
72 std::cout << "thread2 start " << std::endl;
73 pthread_create(&tid3, NULL, thread1, (void*) ¶m3);
74 std::cout << "thread3 start " << std::endl;
75 pthread_create(&tid4, NULL, thread1, (void*) ¶m4);
76 std::cout << "thread4 start " << std::endl;
77 pthread_create(&tid5, NULL, thread1, (void*) ¶m5);
78 std::cout << "thread5 start " << std::endl;
80 pthread_join(tid1, NULL);
81 pthread_join(tid2, NULL);
82 pthread_join(tid3, NULL);
83 pthread_join(tid4, NULL);
84 pthread_join(tid5, NULL);
87 void* thread1(void* pParam)
89 TestParam* param = static_cast<TestParam*>(pParam);
93 ErasureCodePluginRegistry &instance = ErasureCodePluginRegistry::instance();
95 instance.disable_dlclose = true;
97 Mutex::Locker l(instance.lock);
98 __erasure_code_init((char*) "shec", (char*) "");
100 std::cout << "__erasure_code_init finish " << std::endl;
104 set<int> want_to_encode;
105 map<int, bufferlist> encoded;
107 in.append("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" //length = 62
108 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//124
109 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//186
114 int want_to_decode[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
115 map<int, bufferlist> decoded;
116 bufferlist out1, out2, usable;
120 const int kTestSec = 60;
121 ErasureCodeShecTableCache tcache;
123 while (kTestSec >= (end - start)) {
126 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
128 ErasureCodeShec::MULTIPLE);
129 ErasureCodeProfile *profile = new ErasureCodeProfile();
130 (*profile)["plugin"] = "shec";
131 (*profile)["technique"] = "multiple";
132 (*profile)["crush-failure-domain"] = "osd";
133 (*profile)["k"] = param->k;
134 (*profile)["m"] = param->m;
135 (*profile)["c"] = param->c;
136 (*profile)["w"] = param->w;
137 r = shec->init(*profile, &cerr);
139 int i_k = std::atoi(param->k.c_str());
140 int i_m = std::atoi(param->m.c_str());
141 int i_c = std::atoi(param->c.c_str());
142 int i_w = std::atoi(param->w.c_str());
145 EXPECT_EQ(i_k, shec->k);
146 EXPECT_EQ(i_m, shec->m);
147 EXPECT_EQ(i_c, shec->c);
148 EXPECT_EQ(i_w, shec->w);
149 EXPECT_EQ(ErasureCodeShec::MULTIPLE, shec->technique);
150 EXPECT_STREQ("default", shec->rule_root.c_str());
151 EXPECT_STREQ("osd", shec->rule_failure_domain.c_str());
152 EXPECT_TRUE(shec->matrix != NULL);
153 if ((shec->matrix == NULL)) {
154 std::cout << "matrix is null" << std::endl;
160 for (unsigned int i = 0; i < shec->get_chunk_count(); i++) {
161 want_to_encode.insert(i);
163 r = shec->encode(want_to_encode, in, &encoded);
166 EXPECT_EQ(shec->get_chunk_count(), encoded.size());
167 EXPECT_EQ(shec->get_chunk_size(in.length()), encoded[0].length());
170 std::cout << "error in encode" << std::endl;
176 r = shec->decode(set<int>(want_to_decode, want_to_decode + 2),
181 EXPECT_EQ(2u, decoded.size());
182 EXPECT_EQ(shec->get_chunk_size(in.length()), decoded[0].length());
185 std::cout << "error in decode" << std::endl;
191 for (unsigned int i = 0; i < encoded.size(); i++) {
192 out1.append(encoded[i]);
195 shec->decode_concat(encoded, &out2);
196 usable.substr_of(out2, 0, in.length());
197 EXPECT_FALSE(out1 == in);
198 EXPECT_TRUE(usable == in);
199 if (out1 == in || !(usable == in)) {
200 std::cout << "encode(decode) result is not correct" << std::endl;
206 want_to_encode.clear();