]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/erasure-code/TestErasureCodeShec_thread.cc
bump version to 18.2.2-pve1
[ceph.git] / ceph / src / test / erasure-code / TestErasureCodeShec_thread.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2014,2015 FUJITSU LIMITED
7 *
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>
11 *
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.
16 *
17 */
18
19 // SUMMARY: TestErasureCodeShec executes some threads at the same time
20
21 #include <errno.h>
22 #include <pthread.h>
23 #include <stdlib.h>
24
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"
32
33 using namespace std;
34
35 void* thread1(void* pParam);
36
37 class TestParam {
38 public:
39 string k, m, c, w;
40 };
41
42 TEST(ErasureCodeShec, thread)
43 {
44 TestParam param1, param2, param3, param4, param5;
45 param1.k = "6";
46 param1.m = "4";
47 param1.c = "3";
48 param1.w = "8";
49
50 param2.k = "4";
51 param2.m = "3";
52 param2.c = "2";
53 param2.w = "16";
54
55 param3.k = "10";
56 param3.m = "8";
57 param3.c = "4";
58 param3.w = "32";
59
60 param4.k = "5";
61 param4.m = "5";
62 param4.c = "5";
63 param4.w = "8";
64
65 param5.k = "9";
66 param5.m = "9";
67 param5.c = "6";
68 param5.w = "16";
69
70 pthread_t tid1, tid2, tid3, tid4, tid5;
71 pthread_create(&tid1, NULL, thread1, (void*) &param1);
72 std::cout << "thread1 start " << std::endl;
73 pthread_create(&tid2, NULL, thread1, (void*) &param2);
74 std::cout << "thread2 start " << std::endl;
75 pthread_create(&tid3, NULL, thread1, (void*) &param3);
76 std::cout << "thread3 start " << std::endl;
77 pthread_create(&tid4, NULL, thread1, (void*) &param4);
78 std::cout << "thread4 start " << std::endl;
79 pthread_create(&tid5, NULL, thread1, (void*) &param5);
80 std::cout << "thread5 start " << std::endl;
81
82 pthread_join(tid1, NULL);
83 pthread_join(tid2, NULL);
84 pthread_join(tid3, NULL);
85 pthread_join(tid4, NULL);
86 pthread_join(tid5, NULL);
87 }
88
89 void* thread1(void* pParam)
90 {
91 TestParam* param = static_cast<TestParam*>(pParam);
92
93 time_t start, end;
94
95 ErasureCodePluginRegistry &instance = ErasureCodePluginRegistry::instance();
96
97 instance.disable_dlclose = true;
98 {
99 std::lock_guard l{instance.lock};
100 __erasure_code_init((char*) "shec", (char*) "");
101 }
102 std::cout << "__erasure_code_init finish " << std::endl;
103
104 //encode
105 bufferlist in;
106 set<int> want_to_encode;
107 map<int, bufferlist> encoded;
108
109 in.append("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" //length = 62
110 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//124
111 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//186
112 "012345"//192
113 );
114
115 //decode
116 int want_to_decode[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
117 map<int, bufferlist> decoded;
118 bufferlist out1, out2, usable;
119
120 time(&start);
121 time(&end);
122 const int kTestSec = 60;
123 ErasureCodeShecTableCache tcache;
124
125 while (kTestSec >= (end - start)) {
126 //init
127 int r;
128 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
129 tcache,
130 ErasureCodeShec::MULTIPLE);
131 ErasureCodeProfile *profile = new ErasureCodeProfile();
132 (*profile)["plugin"] = "shec";
133 (*profile)["technique"] = "multiple";
134 (*profile)["crush-failure-domain"] = "osd";
135 (*profile)["k"] = param->k;
136 (*profile)["m"] = param->m;
137 (*profile)["c"] = param->c;
138 (*profile)["w"] = param->w;
139 r = shec->init(*profile, &cerr);
140
141 int i_k = std::atoi(param->k.c_str());
142 int i_m = std::atoi(param->m.c_str());
143 int i_c = std::atoi(param->c.c_str());
144 int i_w = std::atoi(param->w.c_str());
145
146 EXPECT_EQ(0, r);
147 EXPECT_EQ(i_k, shec->k);
148 EXPECT_EQ(i_m, shec->m);
149 EXPECT_EQ(i_c, shec->c);
150 EXPECT_EQ(i_w, shec->w);
151 EXPECT_EQ(ErasureCodeShec::MULTIPLE, shec->technique);
152 EXPECT_STREQ("default", shec->rule_root.c_str());
153 EXPECT_STREQ("osd", shec->rule_failure_domain.c_str());
154 EXPECT_TRUE(shec->matrix != NULL);
155 if ((shec->matrix == NULL)) {
156 std::cout << "matrix is null" << std::endl;
157 // error
158 break;
159 }
160
161 //encode
162 for (unsigned int i = 0; i < shec->get_chunk_count(); i++) {
163 want_to_encode.insert(i);
164 }
165 r = shec->encode(want_to_encode, in, &encoded);
166
167 EXPECT_EQ(0, r);
168 EXPECT_EQ(shec->get_chunk_count(), encoded.size());
169 EXPECT_EQ(shec->get_chunk_size(in.length()), encoded[0].length());
170
171 if (r != 0) {
172 std::cout << "error in encode" << std::endl;
173 //error
174 break;
175 }
176
177 //decode
178 r = shec->_decode(set<int>(want_to_decode, want_to_decode + 2),
179 encoded,
180 &decoded);
181
182 EXPECT_EQ(0, r);
183 EXPECT_EQ(2u, decoded.size());
184 EXPECT_EQ(shec->get_chunk_size(in.length()), decoded[0].length());
185
186 if (r != 0) {
187 std::cout << "error in decode" << std::endl;
188 //error
189 break;
190 }
191
192 //out1 is "encoded"
193 for (unsigned int i = 0; i < encoded.size(); i++) {
194 out1.append(encoded[i]);
195 }
196 //out2 is "decoded"
197 shec->decode_concat(encoded, &out2);
198 usable.substr_of(out2, 0, in.length());
199 EXPECT_FALSE(out1 == in);
200 EXPECT_TRUE(usable == in);
201 if (out1 == in || !(usable == in)) {
202 std::cout << "encode(decode) result is not correct" << std::endl;
203 break;
204 }
205
206 delete shec;
207 delete profile;
208 want_to_encode.clear();
209 encoded.clear();
210 decoded.clear();
211 out1.clear();
212 out2.clear();
213 usable.clear();
214
215 time(&end);
216 }
217
218 return NULL;
219 }