]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/erasure-code/TestErasureCodeShec.cc
bump version to 18.2.2-pve1
[ceph.git] / ceph / src / test / erasure-code / TestErasureCodeShec.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
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 void* thread2(void* pParam);
37 void* thread3(void* pParam);
38 void* thread4(void* pParam);
39 void* thread5(void* pParam);
40
41 static int g_flag = 0;
42
43 TEST(ErasureCodeShec, init_1)
44 {
45 //all parameters are normal values
46 ErasureCodeShecTableCache tcache;
47 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
48 tcache,
49 ErasureCodeShec::MULTIPLE);
50 ErasureCodeProfile *profile = new ErasureCodeProfile();
51 (*profile)["plugin"] = "shec";
52 (*profile)["technique"] = "";
53 (*profile)["crush-failure-domain"] = "osd";
54 (*profile)["k"] = "4";
55 (*profile)["m"] = "3";
56 (*profile)["c"] = "2";
57
58 int r = shec->init(*profile, &cerr);
59
60 //check profile
61 EXPECT_EQ(4, shec->k);
62 EXPECT_EQ(3, shec->m);
63 EXPECT_EQ(2, shec->c);
64 EXPECT_EQ(8, shec->w);
65 EXPECT_EQ(ErasureCodeShec::MULTIPLE, shec->technique);
66 EXPECT_STREQ("default", shec->rule_root.c_str());
67 EXPECT_STREQ("osd", shec->rule_failure_domain.c_str());
68 EXPECT_TRUE(shec->matrix != NULL);
69 EXPECT_EQ(0, r);
70
71 delete shec;
72 delete profile;
73 }
74
75 TEST(ErasureCodeShec, init_2)
76 {
77 //all parameters are normal values
78 ErasureCodeShecTableCache tcache;
79 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
80 tcache,
81 ErasureCodeShec::MULTIPLE);
82 ErasureCodeProfile *profile = new ErasureCodeProfile();
83 (*profile)["plugin"] = "shec";
84 (*profile)["technique"] = "";
85 (*profile)["crush-root"] = "test";
86 (*profile)["crush-failure-domain"] = "host";
87 (*profile)["k"] = "4";
88 (*profile)["m"] = "3";
89 (*profile)["c"] = "2";
90 (*profile)["w"] = "8";
91
92 int r = shec->init(*profile, &cerr);
93
94 //check profile
95 EXPECT_EQ(4, shec->k);
96 EXPECT_EQ(3, shec->m);
97 EXPECT_EQ(2, shec->c);
98 EXPECT_EQ(8, shec->w);
99 EXPECT_EQ(ErasureCodeShec::MULTIPLE, shec->technique);
100 EXPECT_STREQ("test", shec->rule_root.c_str());
101 EXPECT_STREQ("host", shec->rule_failure_domain.c_str());
102 EXPECT_TRUE(shec->matrix != NULL);
103 EXPECT_EQ(0, r);
104
105 delete shec;
106 delete profile;
107 }
108
109 TEST(ErasureCodeShec, init_3)
110 {
111 //all parameters are normal values
112 ErasureCodeShecTableCache tcache;
113 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
114 tcache,
115 ErasureCodeShec::MULTIPLE);
116 ErasureCodeProfile *profile = new ErasureCodeProfile();
117 (*profile)["plugin"] = "shec";
118 (*profile)["technique"] = "";
119 (*profile)["crush-failure-domain"] = "osd";
120 (*profile)["k"] = "4";
121 (*profile)["m"] = "3";
122 (*profile)["c"] = "2";
123 (*profile)["w"] = "16";
124
125 int r = shec->init(*profile, &cerr);
126
127 //check profile
128 EXPECT_EQ(4, shec->k);
129 EXPECT_EQ(3, shec->m);
130 EXPECT_EQ(2, shec->c);
131 EXPECT_EQ(16, shec->w);
132 EXPECT_EQ(ErasureCodeShec::MULTIPLE, shec->technique);
133 EXPECT_STREQ("default", shec->rule_root.c_str());
134 EXPECT_STREQ("osd", shec->rule_failure_domain.c_str());
135 EXPECT_TRUE(shec->matrix != NULL);
136 EXPECT_EQ(0, r);
137
138 delete shec;
139 delete profile;
140 }
141
142 TEST(ErasureCodeShec, init_4)
143 {
144 //all parameters are normal values
145 ErasureCodeShecTableCache tcache;
146 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
147 tcache,
148 ErasureCodeShec::MULTIPLE);
149 ErasureCodeProfile *profile = new ErasureCodeProfile();
150 (*profile)["plugin"] = "shec";
151 (*profile)["technique"] = "";
152 (*profile)["crush-failure-domain"] = "osd";
153 (*profile)["k"] = "4";
154 (*profile)["m"] = "3";
155 (*profile)["c"] = "2";
156 (*profile)["w"] = "32";
157
158 int r = shec->init(*profile, &cerr);
159
160 //check profile
161 EXPECT_EQ(4, shec->k);
162 EXPECT_EQ(3, shec->m);
163 EXPECT_EQ(2, shec->c);
164 EXPECT_EQ(32, shec->w);
165 EXPECT_EQ(ErasureCodeShec::MULTIPLE, shec->technique);
166 EXPECT_STREQ("default", shec->rule_root.c_str());
167 EXPECT_STREQ("osd", shec->rule_failure_domain.c_str());
168 EXPECT_TRUE(shec->matrix != NULL);
169 EXPECT_EQ(0, r);
170
171 delete shec;
172 delete profile;
173 }
174
175 TEST(ErasureCodeShec, init_5)
176 {
177 ErasureCodeShecTableCache tcache;
178 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
179 tcache,
180 ErasureCodeShec::MULTIPLE);
181 ErasureCodeProfile *profile = new ErasureCodeProfile();
182 //plugin is not specified
183 (*profile)["technique"] = "";
184 (*profile)["crush-failure-domain"] = "osd";
185 (*profile)["k"] = "4";
186 (*profile)["m"] = "3";
187 (*profile)["c"] = "2";
188
189 int r = shec->init(*profile, &cerr);
190
191 EXPECT_TRUE(shec->matrix != NULL);
192 EXPECT_EQ(0, r);
193
194 delete shec;
195 delete profile;
196 }
197
198 TEST(ErasureCodeShec, init_6)
199 {
200 ErasureCodeShecTableCache tcache;
201 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
202 tcache,
203 ErasureCodeShec::MULTIPLE);
204 ErasureCodeProfile *profile = new ErasureCodeProfile();
205 (*profile)["plugin"] = "jerasure"; //unexpected value
206 (*profile)["technique"] = "";
207 (*profile)["crush-failure-domain"] = "osd";
208 (*profile)["k"] = "4";
209 (*profile)["m"] = "3";
210 (*profile)["c"] = "2";
211
212 int r = shec->init(*profile, &cerr);
213
214 EXPECT_TRUE(shec->matrix != NULL);
215 EXPECT_EQ(0, r);
216
217 delete shec;
218 delete profile;
219 }
220
221 TEST(ErasureCodeShec, init_7)
222 {
223 ErasureCodeShecTableCache tcache;
224 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
225 tcache,
226 ErasureCodeShec::MULTIPLE);
227 ErasureCodeProfile *profile = new ErasureCodeProfile();
228 (*profile)["plugin"] = "abc"; //unexpected value
229 (*profile)["technique"] = "";
230 (*profile)["crush-failure-domain"] = "osd";
231 (*profile)["k"] = "4";
232 (*profile)["m"] = "3";
233 (*profile)["c"] = "2";
234
235 int r = shec->init(*profile, &cerr);
236
237 EXPECT_TRUE(shec->matrix != NULL);
238 EXPECT_EQ(0, r);
239
240 delete shec;
241 delete profile;
242 }
243
244 TEST(ErasureCodeShec, init_8)
245 {
246 ErasureCodeShecTableCache tcache;
247 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
248 tcache,
249 ErasureCodeShec::MULTIPLE);
250 ErasureCodeProfile *profile = new ErasureCodeProfile();
251 (*profile)["plugin"] = "shec";
252 (*profile)["technique"] = "";
253 (*profile)["crush-failure-domain"] = "osd";
254 (*profile)["k"] = "4";
255 (*profile)["m"] = "3";
256 (*profile)["c"] = "2";
257
258 int r = shec->init(*profile, &cerr);
259
260 EXPECT_TRUE(shec->matrix != NULL);
261 EXPECT_EQ(0, r);
262
263 delete shec;
264 delete profile;
265 }
266
267 TEST(ErasureCodeShec, init_9)
268 {
269 ErasureCodeShecTableCache tcache;
270 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
271 tcache,
272 ErasureCodeShec::MULTIPLE);
273 ErasureCodeProfile *profile = new ErasureCodeProfile();
274 (*profile)["plugin"] = "shec";
275 (*profile)["technique"] = "";
276 (*profile)["crush-root"] = "abc"; //unexpected value
277 (*profile)["crush-failure-domain"] = "osd";
278 (*profile)["k"] = "4";
279 (*profile)["m"] = "3";
280 (*profile)["c"] = "2";
281
282 int r = shec->init(*profile, &cerr);
283
284 EXPECT_TRUE(shec->matrix != NULL);
285 EXPECT_EQ(0, r);
286
287 delete shec;
288 delete profile;
289 }
290
291 TEST(ErasureCodeShec, init_10)
292 {
293 ErasureCodeShecTableCache tcache;
294 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
295 tcache,
296 ErasureCodeShec::MULTIPLE);
297 ErasureCodeProfile *profile = new ErasureCodeProfile();
298 (*profile)["plugin"] = "shec";
299 (*profile)["technique"] = "";
300 (*profile)["crush-failure-domain"] = "abc"; //unexpected value
301 (*profile)["k"] = "4";
302 (*profile)["m"] = "3";
303 (*profile)["c"] = "2";
304
305 int r = shec->init(*profile, &cerr);
306
307 EXPECT_TRUE(shec->matrix != NULL);
308 EXPECT_EQ(0, r);
309
310 delete shec;
311 delete profile;
312 }
313
314 TEST(ErasureCodeShec, init_11)
315 {
316 ErasureCodeShecTableCache tcache;
317 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
318 tcache,
319 ErasureCodeShec::MULTIPLE);
320 ErasureCodeProfile *profile = new ErasureCodeProfile();
321 (*profile)["plugin"] = "shec";
322 (*profile)["technique"] = "abc"; //unexpected value
323 (*profile)["crush-failure-domain"] = "osd";
324 (*profile)["k"] = "4";
325 (*profile)["m"] = "3";
326 (*profile)["c"] = "2";
327
328 int r = shec->init(*profile, &cerr);
329
330 EXPECT_TRUE(shec->matrix != NULL);
331 EXPECT_EQ(0, r);
332
333 delete shec;
334 delete profile;
335 }
336
337 TEST(ErasureCodeShec, init_12)
338 {
339 ErasureCodeShecTableCache tcache;
340 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
341 tcache,
342 ErasureCodeShec::MULTIPLE);
343 ErasureCodeProfile *profile = new ErasureCodeProfile();
344 (*profile)["plugin"] = "shec";
345 (*profile)["technique"] = "";
346 (*profile)["crush-failure-domain"] = "osd";
347 (*profile)["k"] = "-1"; //unexpected value
348 (*profile)["m"] = "3";
349 (*profile)["c"] = "2";
350
351 int r = shec->init(*profile, &cerr);
352
353 EXPECT_EQ(-EINVAL, r);
354
355 delete shec;
356 delete profile;
357 }
358
359 TEST(ErasureCodeShec, init_13)
360 {
361 ErasureCodeShecTableCache tcache;
362 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
363 tcache,
364 ErasureCodeShec::MULTIPLE);
365 ErasureCodeProfile *profile = new ErasureCodeProfile();
366 (*profile)["plugin"] = "shec";
367 (*profile)["technique"] = "";
368 (*profile)["crush-failure-domain"] = "abc";
369 (*profile)["k"] = "0.1"; //unexpected value
370 (*profile)["m"] = "3";
371 (*profile)["c"] = "2";
372
373 int r = shec->init(*profile, &cerr);
374
375 EXPECT_EQ(-EINVAL, r);
376
377 delete shec;
378 delete profile;
379 }
380
381 TEST(ErasureCodeShec, init_14)
382 {
383 ErasureCodeShecTableCache tcache;
384 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
385 tcache,
386 ErasureCodeShec::MULTIPLE);
387 ErasureCodeProfile *profile = new ErasureCodeProfile();
388 (*profile)["plugin"] = "shec";
389 (*profile)["technique"] = "";
390 (*profile)["crush-failure-domain"] = "osd";
391 (*profile)["k"] = "a"; //unexpected value
392 (*profile)["m"] = "3";
393 (*profile)["c"] = "2";
394
395 int r = shec->init(*profile, &cerr);
396
397 EXPECT_EQ(-EINVAL, r);
398
399 delete shec;
400 delete profile;
401 }
402
403 TEST(ErasureCodeShec, init_15)
404 {
405 ErasureCodeShecTableCache tcache;
406 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
407 tcache,
408 ErasureCodeShec::MULTIPLE);
409 ErasureCodeProfile *profile = new ErasureCodeProfile();
410 (*profile)["plugin"] = "shec";
411 (*profile)["technique"] = "";
412 (*profile)["crush-failure-domain"] = "osd";
413 //k is not specified
414 (*profile)["m"] = "3";
415 (*profile)["c"] = "2";
416
417 int r = shec->init(*profile, &cerr);
418
419 EXPECT_EQ(-EINVAL, r);
420
421 delete shec;
422 delete profile;
423 }
424
425 TEST(ErasureCodeShec, init_16)
426 {
427 ErasureCodeShecTableCache tcache;
428 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
429 tcache,
430 ErasureCodeShec::MULTIPLE);
431 ErasureCodeProfile *profile = new ErasureCodeProfile();
432 (*profile)["plugin"] = "shec";
433 (*profile)["technique"] = "";
434 (*profile)["crush-failure-domain"] = "osd";
435 (*profile)["k"] = "4";
436 (*profile)["m"] = "-1"; //unexpected value
437 (*profile)["c"] = "2";
438
439 int r = shec->init(*profile, &cerr);
440
441 EXPECT_EQ(-EINVAL, r);
442
443 delete shec;
444 delete profile;
445 }
446
447 TEST(ErasureCodeShec, init_17)
448 {
449 ErasureCodeShecTableCache tcache;
450 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
451 tcache,
452 ErasureCodeShec::MULTIPLE);
453 ErasureCodeProfile *profile = new ErasureCodeProfile();
454 (*profile)["plugin"] = "shec";
455 (*profile)["technique"] = "";
456 (*profile)["crush-failure-domain"] = "osd";
457 (*profile)["k"] = "4";
458 (*profile)["m"] = "0.1"; //unexpected value
459 (*profile)["c"] = "2";
460
461 int r = shec->init(*profile, &cerr);
462
463 EXPECT_EQ(-EINVAL, r);
464
465 delete shec;
466 delete profile;
467 }
468
469 TEST(ErasureCodeShec, init_18)
470 {
471 ErasureCodeShecTableCache tcache;
472 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
473 tcache,
474 ErasureCodeShec::MULTIPLE);
475 ErasureCodeProfile *profile = new ErasureCodeProfile();
476 (*profile)["plugin"] = "shec";
477 (*profile)["technique"] = "";
478 (*profile)["crush-failure-domain"] = "osd";
479 (*profile)["k"] = "4";
480 (*profile)["m"] = "a"; //unexpected value
481 (*profile)["c"] = "2";
482
483 int r = shec->init(*profile, &cerr);
484
485 EXPECT_EQ(-EINVAL, r);
486
487 delete shec;
488 delete profile;
489 }
490
491 TEST(ErasureCodeShec, init_19)
492 {
493 ErasureCodeShecTableCache tcache;
494 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
495 tcache,
496 ErasureCodeShec::MULTIPLE);
497 ErasureCodeProfile *profile = new ErasureCodeProfile();
498 (*profile)["plugin"] = "shec";
499 (*profile)["technique"] = "";
500 (*profile)["crush-failure-domain"] = "osd";
501 (*profile)["k"] = "4";
502 //m is not specified
503 (*profile)["c"] = "2";
504
505 int r = shec->init(*profile, &cerr);
506
507 EXPECT_EQ(-EINVAL, r);
508
509 delete shec;
510 delete profile;
511 }
512
513 TEST(ErasureCodeShec, init_20)
514 {
515 ErasureCodeShecTableCache tcache;
516 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
517 tcache,
518 ErasureCodeShec::MULTIPLE);
519 ErasureCodeProfile *profile = new ErasureCodeProfile();
520 (*profile)["plugin"] = "shec";
521 (*profile)["technique"] = "";
522 (*profile)["crush-failure-domain"] = "osd";
523 (*profile)["k"] = "4";
524 (*profile)["m"] = "3";
525 (*profile)["c"] = "-1"; //unexpected value
526
527 int r = shec->init(*profile, &cerr);
528
529 EXPECT_EQ(-EINVAL, r);
530
531 delete shec;
532 delete profile;
533 }
534
535 TEST(ErasureCodeShec, init_21)
536 {
537 ErasureCodeShecTableCache tcache;
538 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
539 tcache,
540 ErasureCodeShec::MULTIPLE);
541 ErasureCodeProfile *profile = new ErasureCodeProfile();
542 (*profile)["plugin"] = "shec";
543 (*profile)["technique"] = "";
544 (*profile)["crush-failure-domain"] = "osd";
545 (*profile)["k"] = "4";
546 (*profile)["m"] = "3";
547 (*profile)["c"] = "0.1"; //unexpected value
548
549 int r = shec->init(*profile, &cerr);
550
551 EXPECT_EQ(-EINVAL, r);
552
553 delete shec;
554 delete profile;
555 }
556
557 TEST(ErasureCodeShec, init_22)
558 {
559 ErasureCodeShecTableCache tcache;
560 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
561 tcache,
562 ErasureCodeShec::MULTIPLE);
563 ErasureCodeProfile *profile = new ErasureCodeProfile();
564 (*profile)["plugin"] = "shec";
565 (*profile)["technique"] = "";
566 (*profile)["crush-failure-domain"] = "osd";
567 (*profile)["k"] = "4";
568 (*profile)["m"] = "3";
569 (*profile)["c"] = "a"; //unexpected value
570
571 int r = shec->init(*profile, &cerr);
572
573 EXPECT_EQ(-EINVAL, r);
574
575 delete shec;
576 delete profile;
577 }
578
579 TEST(ErasureCodeShec, init_23)
580 {
581 ErasureCodeShecTableCache tcache;
582 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
583 tcache,
584 ErasureCodeShec::MULTIPLE);
585 ErasureCodeProfile *profile = new ErasureCodeProfile();
586 (*profile)["plugin"] = "shec";
587 (*profile)["technique"] = "";
588 (*profile)["crush-failure-domain"] = "osd";
589 (*profile)["k"] = "4";
590 (*profile)["m"] = "3";
591 //c is not specified
592
593 int r = shec->init(*profile, &cerr);
594
595 EXPECT_EQ(-EINVAL, r);
596
597 delete shec;
598 delete profile;
599 }
600
601 TEST(ErasureCodeShec, init_24)
602 {
603 ErasureCodeShecTableCache tcache;
604 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
605 tcache,
606 ErasureCodeShec::MULTIPLE);
607 ErasureCodeProfile *profile = new ErasureCodeProfile();
608 (*profile)["plugin"] = "shec";
609 (*profile)["technique"] = "";
610 (*profile)["crush-failure-domain"] = "osd";
611 (*profile)["k"] = "4";
612 (*profile)["m"] = "3";
613 (*profile)["c"] = "2";
614 (*profile)["w"] = "1"; //unexpected value
615
616 int r = shec->init(*profile, &cerr);
617
618 EXPECT_TRUE(shec->matrix != NULL);
619 EXPECT_EQ(0, r);
620 EXPECT_EQ(4, shec->k);
621 EXPECT_EQ(3, shec->m);
622 EXPECT_EQ(2, shec->c);
623 EXPECT_EQ(8, shec->w);
624 //w is default value
625
626 delete shec;
627 delete profile;
628 }
629
630 TEST(ErasureCodeShec, init_25)
631 {
632 ErasureCodeShecTableCache tcache;
633 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
634 tcache,
635 ErasureCodeShec::MULTIPLE);
636 ErasureCodeProfile *profile = new ErasureCodeProfile();
637 (*profile)["plugin"] = "shec";
638 (*profile)["technique"] = "";
639 (*profile)["crush-failure-domain"] = "osd";
640 (*profile)["k"] = "4";
641 (*profile)["m"] = "3";
642 (*profile)["c"] = "2";
643 (*profile)["w"] = "-1"; //unexpected value
644
645 int r = shec->init(*profile, &cerr);
646
647 EXPECT_TRUE(shec->matrix != NULL);
648 EXPECT_EQ(0, r);
649 EXPECT_EQ(4, shec->k);
650 EXPECT_EQ(3, shec->m);
651 EXPECT_EQ(2, shec->c);
652 EXPECT_EQ(8, shec->w);
653 //w is default value
654
655 delete shec;
656 delete profile;
657 }
658
659 TEST(ErasureCodeShec, init_26)
660 {
661 ErasureCodeShecTableCache tcache;
662 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
663 tcache,
664 ErasureCodeShec::MULTIPLE);
665 ErasureCodeProfile *profile = new ErasureCodeProfile();
666 (*profile)["plugin"] = "shec";
667 (*profile)["technique"] = "";
668 (*profile)["crush-failure-domain"] = "osd";
669 (*profile)["k"] = "4";
670 (*profile)["m"] = "3";
671 (*profile)["c"] = "2";
672 (*profile)["w"] = "0.1"; //unexpected value
673
674 int r = shec->init(*profile, &cerr);
675
676 EXPECT_TRUE(shec->matrix != NULL);
677 EXPECT_EQ(0, r);
678 EXPECT_EQ(4, shec->k);
679 EXPECT_EQ(3, shec->m);
680 EXPECT_EQ(2, shec->c);
681 EXPECT_EQ(8, shec->w);
682 //w is default value
683
684 delete shec;
685 delete profile;
686 }
687
688 TEST(ErasureCodeShec, init_27)
689 {
690 ErasureCodeShecTableCache tcache;
691 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
692 tcache,
693 ErasureCodeShec::MULTIPLE);
694 ErasureCodeProfile *profile = new ErasureCodeProfile();
695 (*profile)["plugin"] = "shec";
696 (*profile)["technique"] = "";
697 (*profile)["crush-failure-domain"] = "osd";
698 (*profile)["k"] = "4";
699 (*profile)["m"] = "3";
700 (*profile)["c"] = "2";
701 (*profile)["w"] = "a"; //unexpected value
702
703 int r = shec->init(*profile, &cerr);
704
705 EXPECT_TRUE(shec->matrix != NULL);
706 EXPECT_EQ(0, r);
707 EXPECT_EQ(4, shec->k);
708 EXPECT_EQ(3, shec->m);
709 EXPECT_EQ(2, shec->c);
710 EXPECT_EQ(8, shec->w);
711 //w is default value
712
713 delete shec;
714 delete profile;
715 }
716
717 TEST(ErasureCodeShec, init_28)
718 {
719 ErasureCodeShecTableCache tcache;
720 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
721 tcache,
722 ErasureCodeShec::MULTIPLE);
723 ErasureCodeProfile *profile = new ErasureCodeProfile();
724 (*profile)["plugin"] = "shec";
725 (*profile)["technique"] = "";
726 (*profile)["crush-failure-domain"] = "osd";
727 (*profile)["k"] = "4";
728 (*profile)["m"] = "3";
729 (*profile)["c"] = "10"; //c > m
730
731 int r = shec->init(*profile, &cerr);
732
733 EXPECT_EQ(-EINVAL, r);
734
735 delete shec;
736 delete profile;
737 }
738
739 TEST(ErasureCodeShec, init_29)
740 {
741 ErasureCodeShecTableCache tcache;
742 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
743 tcache,
744 ErasureCodeShec::MULTIPLE);
745 ErasureCodeProfile *profile = new ErasureCodeProfile();
746 (*profile)["plugin"] = "shec";
747 (*profile)["technique"] = "";
748 (*profile)["crush-failure-domain"] = "osd";
749 //k is not specified
750 //m is not specified
751 //c is not specified
752
753 int r = shec->init(*profile, &cerr);
754
755 EXPECT_TRUE(shec->matrix != NULL);
756 EXPECT_EQ(0, r);
757 //k,m,c are default values
758 EXPECT_EQ(4, shec->k);
759 EXPECT_EQ(3, shec->m);
760 EXPECT_EQ(2, shec->c);
761
762 delete shec;
763 delete profile;
764 }
765
766 TEST(ErasureCodeShec, init_30)
767 {
768 ErasureCodeShecTableCache tcache;
769 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
770 tcache,
771 ErasureCodeShec::MULTIPLE);
772 ErasureCodeProfile *profile = new ErasureCodeProfile();
773 (*profile)["plugin"] = "shec";
774 (*profile)["technique"] = "";
775 (*profile)["crush-failure-domain"] = "osd";
776 (*profile)["k"] = "12";
777 (*profile)["m"] = "8";
778 (*profile)["c"] = "8";
779
780 int r = shec->init(*profile, &cerr);
781
782 EXPECT_TRUE(shec->matrix != NULL);
783 EXPECT_EQ(0, r);
784 EXPECT_EQ(12, shec->k);
785 EXPECT_EQ(8, shec->m);
786 EXPECT_EQ(8, shec->c);
787
788 delete shec;
789 delete profile;
790 }
791
792 TEST(ErasureCodeShec, init_31)
793 {
794 ErasureCodeShecTableCache tcache;
795 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
796 tcache,
797 ErasureCodeShec::MULTIPLE);
798 ErasureCodeProfile *profile = new ErasureCodeProfile();
799 (*profile)["plugin"] = "shec";
800 (*profile)["technique"] = "";
801 (*profile)["crush-failure-domain"] = "osd";
802 (*profile)["k"] = "13";
803 (*profile)["m"] = "7";
804 (*profile)["c"] = "7";
805
806 int r = shec->init(*profile, &cerr);
807
808 EXPECT_EQ(-EINVAL, r);
809
810 delete shec;
811 delete profile;
812 }
813
814 TEST(ErasureCodeShec, init_32)
815 {
816 ErasureCodeShecTableCache tcache;
817 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
818 tcache,
819 ErasureCodeShec::MULTIPLE);
820 ErasureCodeProfile *profile = new ErasureCodeProfile();
821 (*profile)["plugin"] = "shec";
822 (*profile)["technique"] = "";
823 (*profile)["crush-failure-domain"] = "osd";
824 (*profile)["k"] = "7";
825 (*profile)["m"] = "13";
826 (*profile)["c"] = "13";
827
828 int r = shec->init(*profile, &cerr);
829
830 EXPECT_EQ(-EINVAL, r);
831
832 delete shec;
833 delete profile;
834 }
835
836 TEST(ErasureCodeShec, init_33)
837 {
838 ErasureCodeShecTableCache tcache;
839 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
840 tcache,
841 ErasureCodeShec::MULTIPLE);
842 ErasureCodeProfile *profile = new ErasureCodeProfile();
843 (*profile)["plugin"] = "shec";
844 (*profile)["technique"] = "";
845 (*profile)["crush-failure-domain"] = "osd";
846 (*profile)["k"] = "12";
847 (*profile)["m"] = "9";
848 (*profile)["c"] = "8";
849
850 int r = shec->init(*profile, &cerr);
851
852 EXPECT_EQ(-EINVAL, r);
853
854 delete shec;
855 delete profile;
856 }
857
858 TEST(ErasureCodeShec, init_34)
859 {
860 ErasureCodeShecTableCache tcache;
861 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
862 tcache,
863 ErasureCodeShec::MULTIPLE);
864 ErasureCodeProfile *profile = new ErasureCodeProfile();
865 (*profile)["plugin"] = "shec";
866 (*profile)["technique"] = "";
867 (*profile)["crush-failure-domain"] = "osd";
868 (*profile)["k"] = "8";
869 (*profile)["m"] = "12";
870 (*profile)["c"] = "12";
871
872 int r = shec->init(*profile, &cerr);
873
874 EXPECT_EQ(-EINVAL, r);
875
876 delete shec;
877 delete profile;
878 }
879
880 TEST(ErasureCodeShec, init2_4)
881 {
882 //all parameters are normal values
883 ErasureCodeShecTableCache tcache;
884 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
885 tcache,
886 ErasureCodeShec::MULTIPLE);
887 ErasureCodeProfile *profile = new ErasureCodeProfile();
888 (*profile)["plugin"] = "shec";
889 (*profile)["technique"] = "";
890 (*profile)["crush-failure-domain"] = "osd";
891 (*profile)["k"] = "4";
892 (*profile)["m"] = "3";
893 (*profile)["c"] = "2";
894 shec->init(*profile, &cerr);
895 int r = shec->init(*profile, &cerr); //init executed twice
896
897 //check profile
898 EXPECT_EQ(4, shec->k);
899 EXPECT_EQ(3, shec->m);
900 EXPECT_EQ(2, shec->c);
901 EXPECT_EQ(8, shec->w);
902 EXPECT_EQ(ErasureCodeShec::MULTIPLE, shec->technique);
903 EXPECT_STREQ("default", shec->rule_root.c_str());
904 EXPECT_STREQ("osd", shec->rule_failure_domain.c_str());
905 EXPECT_TRUE(shec->matrix != NULL);
906 EXPECT_EQ(0, r);
907
908 delete shec;
909 delete profile;
910 }
911
912 TEST(ErasureCodeShec, init2_5)
913 {
914 //all parameters are normal values
915 ErasureCodeShecTableCache tcache;
916 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
917 tcache,
918 ErasureCodeShec::MULTIPLE);
919 ErasureCodeProfile *profile = new ErasureCodeProfile();
920 ErasureCodeProfile *profile2 = new ErasureCodeProfile();
921 (*profile)["plugin"] = "shec";
922 (*profile)["technique"] = "";
923 (*profile)["crush-failure-domain"] = "host";
924 (*profile)["k"] = "10";
925 (*profile)["m"] = "6";
926 (*profile)["c"] = "5";
927 (*profile)["w"] = "16";
928
929 int r = shec->init(*profile, &cerr);
930
931 //reexecute init
932 (*profile2)["plugin"] = "shec";
933 (*profile2)["technique"] = "";
934 (*profile2)["crush-failure-domain"] = "osd";
935 (*profile2)["k"] = "4";
936 (*profile2)["m"] = "3";
937 (*profile2)["c"] = "2";
938 shec->init(*profile2, &cerr);
939
940 EXPECT_EQ(4, shec->k);
941 EXPECT_EQ(3, shec->m);
942 EXPECT_EQ(2, shec->c);
943 EXPECT_EQ(8, shec->w);
944 EXPECT_EQ(ErasureCodeShec::MULTIPLE, shec->technique);
945 EXPECT_STREQ("default", shec->rule_root.c_str());
946 EXPECT_STREQ("osd", shec->rule_failure_domain.c_str());
947 EXPECT_TRUE(shec->matrix != NULL);
948 EXPECT_EQ(0, r);
949
950 delete shec;
951 delete profile;
952 delete profile2;
953 }
954
955 TEST(ErasureCodeShec, minimum_to_decode_8)
956 {
957 //init
958 ErasureCodeShecTableCache tcache;
959 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
960 tcache,
961 ErasureCodeShec::MULTIPLE);
962 ErasureCodeProfile *profile = new ErasureCodeProfile();
963 (*profile)["plugin"] = "shec";
964 (*profile)["technique"] = "";
965 (*profile)["crush-failure-domain"] = "osd";
966 (*profile)["k"] = "4";
967 (*profile)["m"] = "3";
968 (*profile)["c"] = "2";
969 shec->init(*profile, &cerr);
970
971 //minimum_to_decode
972 set<int> want_to_decode;
973 set<int> available_chunks;
974 set<int> minimum_chunks;
975
976 for (int i = 0; i < 8; ++i) {
977 want_to_decode.insert(i);
978 }
979 for (int i = 0; i < 5; ++i) {
980 available_chunks.insert(i);
981 }
982
983 int r = shec->_minimum_to_decode(want_to_decode, available_chunks,
984 &minimum_chunks);
985 EXPECT_EQ(-EINVAL, r);
986
987 delete shec;
988 delete profile;
989 }
990
991 TEST(ErasureCodeShec, minimum_to_decode_9)
992 {
993 //init
994 ErasureCodeShecTableCache tcache;
995 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
996 tcache,
997 ErasureCodeShec::MULTIPLE);
998 ErasureCodeProfile *profile = new ErasureCodeProfile();
999 (*profile)["plugin"] = "shec";
1000 (*profile)["technique"] = "";
1001 (*profile)["crush-failure-domain"] = "osd";
1002 (*profile)["k"] = "4";
1003 (*profile)["m"] = "3";
1004 (*profile)["c"] = "2";
1005 shec->init(*profile, &cerr);
1006
1007 //minimum_to_decode
1008 set<int> want_to_decode;
1009 set<int> available_chunks;
1010 set<int> minimum_chunks;
1011
1012 for (int i = 0; i < 4; ++i) {
1013 want_to_decode.insert(i);
1014 }
1015 for (int i = 0; i < 8; ++i) {
1016 available_chunks.insert(i);
1017 }
1018
1019 int r = shec->_minimum_to_decode(want_to_decode, available_chunks,
1020 &minimum_chunks);
1021 EXPECT_EQ(-EINVAL, r);
1022
1023 delete shec;
1024 delete profile;
1025 }
1026
1027 TEST(ErasureCodeShec, minimum_to_decode_10)
1028 {
1029 //init
1030 ErasureCodeShecTableCache tcache;
1031 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
1032 tcache,
1033 ErasureCodeShec::MULTIPLE);
1034 ErasureCodeProfile *profile = new ErasureCodeProfile();
1035 (*profile)["plugin"] = "shec";
1036 (*profile)["technique"] = "";
1037 (*profile)["crush-failure-domain"] = "osd";
1038 (*profile)["k"] = "4";
1039 (*profile)["m"] = "3";
1040 (*profile)["c"] = "2";
1041 shec->init(*profile, &cerr);
1042
1043 //minimum_to_decode
1044 set<int> want_to_decode;
1045 set<int> available_chunks;
1046 set<int> minimum_chunks;
1047
1048 for (int i = 0; i < 7; ++i) {
1049 want_to_decode.insert(i);
1050 }
1051 for (int i = 4; i < 7; ++i) {
1052 available_chunks.insert(i);
1053 }
1054
1055 int r = shec->_minimum_to_decode(want_to_decode, available_chunks,
1056 &minimum_chunks);
1057 EXPECT_EQ(-EIO, r);
1058
1059 delete shec;
1060 delete profile;
1061 }
1062
1063 TEST(ErasureCodeShec, minimum_to_decode_11)
1064 {
1065 //init
1066 ErasureCodeShecTableCache tcache;
1067 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
1068 tcache,
1069 ErasureCodeShec::MULTIPLE);
1070 ErasureCodeProfile *profile = new ErasureCodeProfile();
1071 (*profile)["plugin"] = "shec";
1072 (*profile)["technique"] = "";
1073 (*profile)["crush-failure-domain"] = "osd";
1074 (*profile)["k"] = "4";
1075 (*profile)["m"] = "3";
1076 (*profile)["c"] = "2";
1077 shec->init(*profile, &cerr);
1078
1079 //minimum_to_decode
1080 set<int> want_to_decode;
1081 set<int> available_chunks;
1082 set<int> minimum_chunks;
1083
1084 for (int i = 0; i < 5; ++i) {
1085 want_to_decode.insert(i);
1086 }
1087 for (int i = 4; i < 7; ++i) {
1088 available_chunks.insert(i);
1089 }
1090
1091 int r = shec->_minimum_to_decode(want_to_decode, available_chunks,
1092 &minimum_chunks);
1093 EXPECT_EQ(-EIO, r);
1094
1095 delete shec;
1096 delete profile;
1097 }
1098
1099 TEST(ErasureCodeShec, minimum_to_decode_12)
1100 {
1101 //init
1102 ErasureCodeShecTableCache tcache;
1103 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
1104 tcache,
1105 ErasureCodeShec::MULTIPLE);
1106 ErasureCodeProfile *profile = new ErasureCodeProfile();
1107 (*profile)["plugin"] = "shec";
1108 (*profile)["technique"] = "";
1109 (*profile)["crush-failure-domain"] = "osd";
1110 (*profile)["k"] = "4";
1111 (*profile)["m"] = "3";
1112 (*profile)["c"] = "2";
1113 shec->init(*profile, &cerr);
1114
1115 //minimum_to_decode
1116 set<int> want_to_decode;
1117 set<int> available_chunks;
1118 //minimum_chunks is NULL
1119
1120 for (int i = 0; i < 7; ++i) {
1121 want_to_decode.insert(i);
1122 available_chunks.insert(i);
1123 }
1124
1125 int r = shec->_minimum_to_decode(want_to_decode, available_chunks, NULL);
1126 EXPECT_EQ(-EINVAL, r);
1127
1128 delete shec;
1129 delete profile;
1130 }
1131
1132 TEST(ErasureCodeShec, minimum_to_decode_13)
1133 {
1134 //init
1135 ErasureCodeShecTableCache tcache;
1136 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
1137 tcache,
1138 ErasureCodeShec::MULTIPLE);
1139 ErasureCodeProfile *profile = new ErasureCodeProfile();
1140 (*profile)["plugin"] = "shec";
1141 (*profile)["technique"] = "";
1142 (*profile)["crush-failure-domain"] = "osd";
1143 (*profile)["k"] = "4";
1144 (*profile)["m"] = "3";
1145 (*profile)["c"] = "2";
1146 shec->init(*profile, &cerr);
1147
1148 //minimum_to_decode
1149 set<int> want_to_decode;
1150 set<int> available_chunks;
1151 set<int> minimum_chunks, minimum;
1152
1153 for (int i = 0; i < 7; ++i) {
1154 want_to_decode.insert(i);
1155 available_chunks.insert(i);
1156 }
1157 shec->_minimum_to_decode(want_to_decode, available_chunks, &minimum_chunks);
1158 minimum = minimum_chunks; //normal value
1159 for (int i = 100; i < 120; ++i) {
1160 minimum_chunks.insert(i); //insert extra data
1161 }
1162
1163 int r = shec->_minimum_to_decode(want_to_decode, available_chunks,
1164 &minimum_chunks);
1165 EXPECT_TRUE(shec->matrix != NULL);
1166 EXPECT_EQ(0, r);
1167 EXPECT_EQ(minimum, minimum_chunks);
1168
1169 delete shec;
1170 delete profile;
1171 }
1172
1173 TEST(ErasureCodeShec, minimum_to_decode2_1)
1174 {
1175 //init
1176 ErasureCodeShecTableCache tcache;
1177 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
1178 tcache,
1179 ErasureCodeShec::MULTIPLE);
1180 ErasureCodeProfile *profile = new ErasureCodeProfile();
1181 (*profile)["plugin"] = "shec";
1182 (*profile)["technique"] = "";
1183 (*profile)["crush-failure-domain"] = "osd";
1184 (*profile)["k"] = "4";
1185 (*profile)["m"] = "3";
1186 (*profile)["c"] = "2";
1187 shec->init(*profile, &cerr);
1188
1189 //minimum_to_decode
1190 set<int> want_to_decode;
1191 set<int> available_chunks;
1192 set<int> minimum_chunks;
1193
1194 want_to_decode.insert(0);
1195 available_chunks.insert(0);
1196 available_chunks.insert(1);
1197 available_chunks.insert(2);
1198
1199 int r = shec->_minimum_to_decode(want_to_decode, available_chunks,
1200 &minimum_chunks);
1201 EXPECT_TRUE(shec->matrix != NULL);
1202 EXPECT_EQ(0, r);
1203 EXPECT_TRUE(minimum_chunks.size());
1204
1205 delete shec;
1206 delete profile;
1207 }
1208
1209 TEST(ErasureCodeShec, minimum_to_decode2_3)
1210 {
1211 //init
1212 ErasureCodeShecTableCache tcache;
1213 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
1214 tcache,
1215 ErasureCodeShec::MULTIPLE);
1216 ErasureCodeProfile *profile = new ErasureCodeProfile();
1217 (*profile)["plugin"] = "shec";
1218 (*profile)["technique"] = "";
1219 (*profile)["crush-failure-domain"] = "osd";
1220 (*profile)["k"] = "4";
1221 (*profile)["m"] = "3";
1222 (*profile)["c"] = "2";
1223 shec->init(*profile, &cerr);
1224
1225 //minimum_to_decode
1226 set<int> want_to_decode;
1227 set<int> available_chunks;
1228 set<int> minimum_chunks;
1229
1230 want_to_decode.insert(0);
1231 want_to_decode.insert(2);
1232 available_chunks.insert(0);
1233 available_chunks.insert(1);
1234 available_chunks.insert(2);
1235 available_chunks.insert(3);
1236
1237 pthread_t tid;
1238 g_flag = 0;
1239 pthread_create(&tid, NULL, thread1, shec);
1240 while (g_flag == 0) {
1241 usleep(1);
1242 }
1243 sleep(1);
1244 printf("*** test start ***\n");
1245 int r = shec->_minimum_to_decode(want_to_decode, available_chunks,
1246 &minimum_chunks);
1247 EXPECT_TRUE(shec->matrix != NULL);
1248 EXPECT_EQ(0, r);
1249 EXPECT_EQ(want_to_decode, minimum_chunks);
1250 printf("*** test end ***\n");
1251 g_flag = 0;
1252 pthread_join(tid, NULL);
1253
1254 delete shec;
1255 delete profile;
1256 }
1257
1258 TEST(ErasureCodeShec, minimum_to_decode_with_cost_1)
1259 {
1260 //init
1261 ErasureCodeShecTableCache tcache;
1262 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
1263 tcache,
1264 ErasureCodeShec::MULTIPLE);
1265 ErasureCodeProfile *profile = new ErasureCodeProfile();
1266 (*profile)["plugin"] = "shec";
1267 (*profile)["technique"] = "";
1268 (*profile)["crush-failure-domain"] = "osd";
1269 (*profile)["k"] = "4";
1270 (*profile)["m"] = "3";
1271 (*profile)["c"] = "2";
1272 shec->init(*profile, &cerr);
1273
1274 //minimum_to_decode_with_cost
1275 set<int> want_to_decode;
1276 map<int, int> available_chunks;
1277 set<int> minimum_chunks;
1278
1279 for (int i = 0; i < 7; ++i) {
1280 want_to_decode.insert(i);
1281 available_chunks.insert(make_pair(i, i));
1282 }
1283
1284 int r = shec->minimum_to_decode_with_cost(want_to_decode, available_chunks,
1285 &minimum_chunks);
1286 EXPECT_TRUE(shec->matrix != NULL);
1287 EXPECT_EQ(0, r);
1288 EXPECT_TRUE(minimum_chunks.size());
1289
1290 delete shec;
1291 delete profile;
1292 }
1293
1294 TEST(ErasureCodeShec, minimum_to_decode_with_cost_2_3)
1295 {
1296 //init
1297 ErasureCodeShecTableCache tcache;
1298 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
1299 tcache,
1300 ErasureCodeShec::MULTIPLE);
1301 ErasureCodeProfile *profile = new ErasureCodeProfile();
1302 (*profile)["plugin"] = "shec";
1303 (*profile)["technique"] = "";
1304 (*profile)["crush-failure-domain"] = "osd";
1305 (*profile)["k"] = "4";
1306 (*profile)["m"] = "3";
1307 (*profile)["c"] = "2";
1308 shec->init(*profile, &cerr);
1309
1310 //minimum_to_decode_with_cost
1311 set<int> want_to_decode;
1312 map<int, int> available_chunks;
1313 set<int> minimum_chunks;
1314
1315 want_to_decode.insert(0);
1316 want_to_decode.insert(2);
1317 available_chunks[0] = 0;
1318 available_chunks[1] = 1;
1319 available_chunks[2] = 2;
1320 available_chunks[3] = 3;
1321
1322 pthread_t tid;
1323 g_flag = 0;
1324 pthread_create(&tid, NULL, thread2, shec);
1325 while (g_flag == 0) {
1326 usleep(1);
1327 }
1328 sleep(1);
1329 printf("*** test start ***\n");
1330 int r = shec->minimum_to_decode_with_cost(want_to_decode, available_chunks,
1331 &minimum_chunks);
1332 EXPECT_TRUE(shec->matrix != NULL);
1333 EXPECT_EQ(0, r);
1334 EXPECT_EQ(want_to_decode, minimum_chunks);
1335 printf("*** test end ***\n");
1336 g_flag = 0;
1337 pthread_join(tid, NULL);
1338
1339 delete shec;
1340 delete profile;
1341 }
1342
1343 TEST(ErasureCodeShec, encode_1)
1344 {
1345 //init
1346 ErasureCodeShecTableCache tcache;
1347 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
1348 tcache,
1349 ErasureCodeShec::MULTIPLE);
1350 ErasureCodeProfile *profile = new ErasureCodeProfile();
1351 (*profile)["plugin"] = "shec";
1352 (*profile)["technique"] = "";
1353 (*profile)["crush-failure-domain"] = "osd";
1354 (*profile)["k"] = "4";
1355 (*profile)["m"] = "3";
1356 (*profile)["c"] = "2";
1357 shec->init(*profile, &cerr);
1358
1359 //encode
1360 bufferlist in;
1361 set<int> want_to_encode;
1362 map<int, bufferlist> encoded;
1363
1364 in.append("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//length = 62
1365 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//124
1366 "0123"//128
1367 );
1368 for (unsigned int i = 0; i < shec->get_chunk_count(); ++i) {
1369 want_to_encode.insert(i);
1370 }
1371
1372 int r = shec->encode(want_to_encode, in, &encoded);
1373 EXPECT_EQ(0, r);
1374 EXPECT_EQ(shec->get_chunk_count(), encoded.size());
1375 EXPECT_EQ(shec->get_chunk_size(in.length()), encoded[0].length());
1376
1377 //decode
1378 int want_to_decode[] = { 0, 1, 2, 3, 4, 5, 6 };
1379 map<int, bufferlist> decoded;
1380 decoded.clear();
1381 r = shec->_decode(set<int>(want_to_decode, want_to_decode + 2),
1382 encoded,
1383 &decoded);
1384 EXPECT_NE(nullptr, shec->matrix);
1385 EXPECT_EQ(0, r);
1386 EXPECT_EQ(2u, decoded.size());
1387 EXPECT_EQ(32u, decoded[0].length());
1388
1389 bufferlist out1, out2, usable;
1390 //out1 is "encoded"
1391 for (unsigned int i = 0; i < encoded.size(); ++i) {
1392 out1.append(encoded[i]);
1393 }
1394 //out2 is "decoded"
1395 r = shec->decode_concat(encoded, &out2);
1396 usable.substr_of(out2, 0, in.length());
1397 EXPECT_FALSE(out1 == in);
1398 EXPECT_TRUE(usable == in);
1399
1400 delete shec;
1401 delete profile;
1402 }
1403
1404 TEST(ErasureCodeShec, encode_2)
1405 {
1406 //init
1407 ErasureCodeShecTableCache tcache;
1408 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
1409 tcache,
1410 ErasureCodeShec::MULTIPLE);
1411 ErasureCodeProfile *profile = new ErasureCodeProfile();
1412 (*profile)["plugin"] = "shec";
1413 (*profile)["technique"] = "";
1414 (*profile)["crush-failure-domain"] = "osd";
1415 (*profile)["k"] = "4";
1416 (*profile)["m"] = "3";
1417 (*profile)["c"] = "2";
1418 shec->init(*profile, &cerr);
1419
1420 //encode
1421 bufferlist in;
1422 set<int> want_to_encode;
1423 map<int, bufferlist> encoded;
1424
1425 in.append("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//length = 62
1426 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//124
1427 );
1428 for (unsigned int i = 0; i < shec->get_chunk_count(); ++i) {
1429 want_to_encode.insert(i);
1430 }
1431
1432 int r = shec->encode(want_to_encode, in, &encoded);
1433 EXPECT_EQ(0, r);
1434 EXPECT_EQ(shec->get_chunk_count(), encoded.size());
1435 EXPECT_EQ(shec->get_chunk_size(in.length()), encoded[0].length());
1436
1437 //decode
1438 int want_to_decode[] = { 0, 1, 2, 3, 4, 5, 6 };
1439 map<int, bufferlist> decoded;
1440 r = shec->_decode(set<int>(want_to_decode, want_to_decode + 2), encoded,
1441 &decoded);
1442 EXPECT_TRUE(shec->matrix != NULL);
1443 EXPECT_EQ(0, r);
1444 EXPECT_EQ(2u, decoded.size());
1445 EXPECT_EQ(32u, decoded[0].length());
1446
1447 bufferlist out1, out2, usable;
1448 //out1 is "encoded"
1449 for (unsigned int i = 0; i < encoded.size(); ++i)
1450 out1.append(encoded[i]);
1451 //out2 is "decoded"
1452 shec->decode_concat(encoded, &out2);
1453 usable.substr_of(out2, 0, in.length());
1454 EXPECT_FALSE(out1 == in);
1455 EXPECT_TRUE(usable == in);
1456
1457 delete shec;
1458 delete profile;
1459 }
1460
1461 TEST(ErasureCodeShec, encode_3)
1462 {
1463 ErasureCodeShecTableCache tcache;
1464 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
1465 tcache,
1466 ErasureCodeShec::MULTIPLE);
1467 ErasureCodeProfile *profile = new ErasureCodeProfile();
1468 (*profile)["plugin"] = "shec";
1469 (*profile)["technique"] = "";
1470 (*profile)["crush-failure-domain"] = "osd";
1471 (*profile)["k"] = "4";
1472 (*profile)["m"] = "3";
1473 (*profile)["c"] = "2";
1474 shec->init(*profile, &cerr);
1475
1476 bufferlist in;
1477 in.append("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//length = 62
1478 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//124
1479 );
1480 set<int> want_to_encode;
1481 for (unsigned int i = 0; i < shec->get_chunk_count(); ++i) {
1482 want_to_encode.insert(i);
1483 }
1484 want_to_encode.insert(10);
1485 want_to_encode.insert(11);
1486 map<int, bufferlist> encoded;
1487 int r = shec->encode(want_to_encode, in, &encoded);
1488 EXPECT_EQ(0, r);
1489 EXPECT_EQ(shec->get_chunk_count(), encoded.size());
1490 EXPECT_EQ(shec->get_chunk_size(in.length()), encoded[0].length());
1491
1492 //decode
1493 int want_to_decode[] = { 0, 1, 2, 3, 4, 5, 6 };
1494 map<int, bufferlist> decoded;
1495 r = shec->_decode(set<int>(want_to_decode, want_to_decode + 2), encoded,
1496 &decoded);
1497 EXPECT_TRUE(shec->matrix != NULL);
1498 EXPECT_EQ(0, r);
1499 EXPECT_EQ(2u, decoded.size());
1500 EXPECT_EQ(shec->get_chunk_size(in.length()), decoded[0].length());
1501
1502 bufferlist out1, out2, usable;
1503 //out1 is "encoded"
1504 for (unsigned int i = 0; i < encoded.size(); ++i) {
1505 out1.append(encoded[i]);
1506 }
1507 //out2 is "decoded"
1508 shec->decode_concat(encoded, &out2);
1509 usable.substr_of(out2, 0, in.length());
1510 EXPECT_FALSE(out1 == in);
1511 EXPECT_TRUE(usable == in);
1512
1513 delete shec;
1514 delete profile;
1515 }
1516
1517 TEST(ErasureCodeShec, encode_4)
1518 {
1519 //init
1520 ErasureCodeShecTableCache tcache;
1521 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
1522 tcache,
1523 ErasureCodeShec::MULTIPLE);
1524 ErasureCodeProfile *profile = new ErasureCodeProfile();
1525 (*profile)["plugin"] = "shec";
1526 (*profile)["technique"] = "";
1527 (*profile)["crush-failure-domain"] = "osd";
1528 (*profile)["k"] = "4";
1529 (*profile)["m"] = "3";
1530 (*profile)["c"] = "2";
1531 shec->init(*profile, &cerr);
1532
1533 //encode
1534 bufferlist in;
1535 set<int> want_to_encode;
1536 map<int, bufferlist> encoded;
1537
1538 in.append("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//length = 62
1539 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//124
1540 );
1541 for (unsigned int i = 0; i < shec->get_chunk_count() - 1; ++i) {
1542 want_to_encode.insert(i);
1543 }
1544 want_to_encode.insert(100);
1545
1546 int r = shec->encode(want_to_encode, in, &encoded);
1547 EXPECT_EQ(0, r);
1548 EXPECT_EQ(shec->get_chunk_count()-1, encoded.size());
1549 EXPECT_EQ(shec->get_chunk_size(in.length()), encoded[0].length());
1550
1551 //decode
1552 int want_to_decode[] = { 0, 1, 2, 3, 4, 5, 6 };
1553 map<int, bufferlist> decoded;
1554 r = shec->_decode(set<int>(want_to_decode, want_to_decode + 2), encoded,
1555 &decoded);
1556 EXPECT_TRUE(shec->matrix != NULL);
1557 EXPECT_EQ(0, r);
1558 EXPECT_EQ(2u, decoded.size());
1559 EXPECT_EQ(shec->get_chunk_size(in.length()), decoded[0].length());
1560
1561 bufferlist out1, out2, usable;
1562 //out1 is "encoded"
1563 for (unsigned int i = 0; i < encoded.size(); ++i) {
1564 out1.append(encoded[i]);
1565 }
1566 //out2 is "decoded"
1567 shec->decode_concat(encoded, &out2);
1568 usable.substr_of(out2, 0, in.length());
1569 EXPECT_FALSE(out1 == in);
1570 EXPECT_TRUE(usable == in);
1571
1572 delete shec;
1573 delete profile;
1574 }
1575
1576 TEST(ErasureCodeShec, encode_8)
1577 {
1578 //init
1579 ErasureCodeShecTableCache tcache;
1580 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
1581 tcache,
1582 ErasureCodeShec::MULTIPLE);
1583 ErasureCodeProfile *profile = new ErasureCodeProfile();
1584 (*profile)["plugin"] = "shec";
1585 (*profile)["technique"] = "";
1586 (*profile)["crush-failure-domain"] = "osd";
1587 (*profile)["k"] = "4";
1588 (*profile)["m"] = "3";
1589 (*profile)["c"] = "2";
1590 shec->init(*profile, &cerr);
1591
1592 //encode
1593 bufferlist in;
1594 set<int> want_to_encode;
1595
1596 in.append("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//length = 62
1597 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//124
1598 );
1599 for (unsigned int i = 0; i < shec->get_chunk_count(); ++i) {
1600 want_to_encode.insert(i);
1601 }
1602
1603 int r = shec->encode(want_to_encode, in, NULL); //encoded = NULL
1604 EXPECT_EQ(-EINVAL, r);
1605
1606 delete shec;
1607 delete profile;
1608 }
1609
1610 TEST(ErasureCodeShec, encode_9)
1611 {
1612 //init
1613 ErasureCodeShecTableCache tcache;
1614 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
1615 tcache,
1616 ErasureCodeShec::MULTIPLE);
1617 ErasureCodeProfile *profile = new ErasureCodeProfile();
1618 (*profile)["plugin"] = "shec";
1619 (*profile)["technique"] = "";
1620 (*profile)["crush-failure-domain"] = "osd";
1621 (*profile)["k"] = "4";
1622 (*profile)["m"] = "3";
1623 (*profile)["c"] = "2";
1624 shec->init(*profile, &cerr);
1625
1626 //encode
1627 bufferlist in;
1628 set<int> want_to_encode;
1629 map<int, bufferlist> encoded;
1630
1631 in.append("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//length = 62
1632 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//124
1633 );
1634 for (unsigned int i = 0; i < shec->get_chunk_count(); ++i) {
1635 want_to_encode.insert(i);
1636 }
1637 for (int i = 0; i < 100; ++i) {
1638 encoded[i].append("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
1639 }
1640
1641 int r = shec->encode(want_to_encode, in, &encoded);
1642 EXPECT_EQ(-EINVAL, r);
1643
1644 delete shec;
1645 delete profile;
1646 }
1647
1648 TEST(ErasureCodeShec, encode2_1)
1649 {
1650 //init
1651 ErasureCodeShecTableCache tcache;
1652 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
1653 tcache,
1654 ErasureCodeShec::MULTIPLE);
1655 ErasureCodeProfile *profile = new ErasureCodeProfile();
1656 (*profile)["plugin"] = "shec";
1657 (*profile)["technique"] = "";
1658 (*profile)["crush-failure-domain"] = "osd";
1659 (*profile)["k"] = "4";
1660 (*profile)["m"] = "3";
1661 (*profile)["c"] = "2";
1662 shec->init(*profile, &cerr);
1663
1664 //encode
1665 bufferlist in;
1666 set<int> want_to_encode;
1667 map<int, bufferlist> encoded;
1668
1669 in.append("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//length = 62
1670 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//124
1671 "0123"//128
1672 );
1673 for (unsigned int i = 0; i < shec->get_chunk_count(); ++i) {
1674 want_to_encode.insert(i);
1675 }
1676
1677 int r = shec->encode(want_to_encode, in, &encoded);
1678 EXPECT_EQ(0, r);
1679 EXPECT_EQ(shec->get_chunk_count(), encoded.size());
1680 EXPECT_EQ(shec->get_chunk_size(in.length()), encoded[0].length());
1681
1682 //decode
1683 int want_to_decode[] = { 0, 1, 2, 3, 4, 5, 6 };
1684 map<int, bufferlist> decoded;
1685 r = shec->_decode(set<int>(want_to_decode, want_to_decode + 2), encoded,
1686 &decoded);
1687 EXPECT_TRUE(shec->matrix != NULL);
1688 EXPECT_EQ(0, r);
1689 EXPECT_EQ(2u, decoded.size());
1690 EXPECT_EQ(32u, decoded[0].length());
1691
1692 bufferlist out1, out2, usable;
1693 //out1 is "encoded"
1694 for (unsigned int i = 0; i < encoded.size(); ++i) {
1695 out1.append(encoded[i]);
1696 }
1697 //out2 is "decoded"
1698 shec->decode_concat(encoded, &out2);
1699 usable.substr_of(out2, 0, in.length());
1700 EXPECT_FALSE(out1 == in);
1701 EXPECT_TRUE(usable == in);
1702
1703 delete shec;
1704 delete profile;
1705 }
1706
1707 TEST(ErasureCodeShec, encode2_3)
1708 {
1709 //init
1710 ErasureCodeShecTableCache tcache;
1711 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
1712 tcache,
1713 ErasureCodeShec::MULTIPLE);
1714 ErasureCodeProfile *profile = new ErasureCodeProfile();
1715 (*profile)["plugin"] = "shec";
1716 (*profile)["technique"] = "";
1717 (*profile)["crush-failure-domain"] = "osd";
1718 (*profile)["k"] = "4";
1719 (*profile)["m"] = "3";
1720 (*profile)["c"] = "2";
1721 shec->init(*profile, &cerr);
1722
1723 //encode
1724 bufferlist in;
1725 set<int> want_to_encode;
1726 map<int, bufferlist> encoded;
1727
1728 in.append("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//length = 62
1729 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//124
1730 "0123"//128
1731 );
1732 for (unsigned int i = 0; i < shec->get_chunk_count(); ++i) {
1733 want_to_encode.insert(i);
1734 }
1735
1736 pthread_t tid;
1737 g_flag = 0;
1738 pthread_create(&tid, NULL, thread4, shec);
1739 while (g_flag == 0) {
1740 usleep(1);
1741 }
1742 sleep(1);
1743 printf("*** test start ***\n");
1744 int r = shec->encode(want_to_encode, in, &encoded);
1745 EXPECT_EQ(0, r);
1746 EXPECT_EQ(shec->get_chunk_count(), encoded.size());
1747 EXPECT_EQ(shec->get_chunk_size(in.length()), encoded[0].length());
1748 printf("*** test end ***\n");
1749 g_flag = 0;
1750 pthread_join(tid, NULL);
1751
1752 //decode
1753 int want_to_decode[] = { 0, 1, 2, 3, 4, 5, 6 };
1754 map<int, bufferlist> decoded;
1755
1756 r = shec->_decode(set<int>(want_to_decode, want_to_decode + 2), encoded,
1757 &decoded);
1758 EXPECT_TRUE(shec->matrix != NULL);
1759 EXPECT_EQ(0, r);
1760 EXPECT_EQ(2u, decoded.size());
1761 EXPECT_EQ(32u, decoded[0].length());
1762
1763 bufferlist out1, out2, usable;
1764 //out1 is "encoded"
1765 for (unsigned int i = 0; i < encoded.size(); ++i) {
1766 out1.append(encoded[i]);
1767 }
1768 //out2 is "decoded"
1769 shec->decode_concat(encoded, &out2);
1770 usable.substr_of(out2, 0, in.length());
1771 EXPECT_FALSE(out1 == in);
1772 EXPECT_TRUE(usable == in);
1773
1774 delete shec;
1775 delete profile;
1776 }
1777
1778 TEST(ErasureCodeShec, decode_1)
1779 {
1780 //init
1781 ErasureCodeShecTableCache tcache;
1782 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
1783 tcache,
1784 ErasureCodeShec::MULTIPLE);
1785 ErasureCodeProfile *profile = new ErasureCodeProfile();
1786 (*profile)["plugin"] = "shec";
1787 (*profile)["technique"] = "";
1788 (*profile)["crush-failure-domain"] = "osd";
1789 (*profile)["k"] = "4";
1790 (*profile)["m"] = "3";
1791 (*profile)["c"] = "2";
1792 shec->init(*profile, &cerr);
1793
1794 //encode
1795 bufferlist in;
1796 set<int> want_to_encode;
1797 map<int, bufferlist> encoded;
1798
1799 in.append("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//length = 62
1800 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//124
1801 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//186
1802 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//248
1803 );
1804 for (unsigned int i = 0; i < shec->get_chunk_count(); ++i) {
1805 want_to_encode.insert(i);
1806 }
1807
1808 int r = shec->encode(want_to_encode, in, &encoded);
1809 EXPECT_EQ(0, r);
1810 EXPECT_EQ(shec->get_chunk_count(), encoded.size());
1811 EXPECT_EQ(shec->get_chunk_size(in.length()), encoded[0].length());
1812
1813 // all chunks are available
1814 //decode
1815 int want_to_decode[] = { 0, 1, 2, 3, 4, 5, 6 };
1816 map<int, bufferlist> decoded;
1817
1818 r = shec->_decode(set<int>(want_to_decode, want_to_decode + 7), encoded,
1819 &decoded);
1820 EXPECT_TRUE(shec->matrix != NULL);
1821 EXPECT_EQ(0, r);
1822 EXPECT_EQ(7u, decoded.size());
1823
1824 bufferlist usable;
1825 int cmp;
1826 unsigned int c_size = shec->get_chunk_size(in.length());
1827 for (unsigned int i = 0; i < shec->get_data_chunk_count(); ++i) {
1828 usable.clear();
1829 EXPECT_EQ(c_size, decoded[i].length());
1830 if ( c_size * (i+1) <= in.length() ) {
1831 usable.substr_of(in, c_size * i, c_size);
1832 cmp = memcmp(decoded[i].c_str(), usable.c_str(), c_size);
1833 } else {
1834 usable.substr_of(in, c_size * i, in.length() % c_size);
1835 cmp = memcmp(decoded[i].c_str(), usable.c_str(), in.length() % c_size);
1836 }
1837 EXPECT_EQ(0, cmp);
1838 }
1839
1840 delete shec;
1841 delete profile;
1842 }
1843
1844 TEST(ErasureCodeShec, decode_8)
1845 {
1846 //init
1847 ErasureCodeShecTableCache tcache;
1848 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
1849 tcache,
1850 ErasureCodeShec::MULTIPLE);
1851 ErasureCodeProfile *profile = new ErasureCodeProfile();
1852 (*profile)["plugin"] = "shec";
1853 (*profile)["technique"] = "";
1854 (*profile)["crush-failure-domain"] = "osd";
1855 (*profile)["k"] = "4";
1856 (*profile)["m"] = "3";
1857 (*profile)["c"] = "2";
1858 shec->init(*profile, &cerr);
1859
1860 //encode
1861 bufferlist in;
1862 set<int> want_to_encode;
1863 map<int, bufferlist> encoded;
1864
1865 in.append("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//length = 62
1866 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//124
1867 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//186
1868 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//248
1869 );
1870 for (unsigned int i = 0; i < shec->get_chunk_count(); ++i) {
1871 want_to_encode.insert(i);
1872 }
1873
1874 int r = shec->encode(want_to_encode, in, &encoded);
1875 EXPECT_EQ(0, r);
1876 EXPECT_EQ(shec->get_chunk_count(), encoded.size());
1877 EXPECT_EQ(shec->get_chunk_size(in.length()), encoded[0].length());
1878
1879 // all chunks are available
1880 //decode
1881 int want_to_decode[] = { 0, 1, 2, 3, 4, 5, 6, 7 }; //more than k+m
1882 map<int, bufferlist> decoded;
1883
1884 r = shec->_decode(set<int>(want_to_decode, want_to_decode + 8), encoded,
1885 &decoded);
1886 EXPECT_EQ(0, r);
1887 EXPECT_EQ(7u, decoded.size());
1888 EXPECT_EQ(shec->get_chunk_size(in.length()), encoded[0].length());
1889
1890 bufferlist usable;
1891 int cmp;
1892 unsigned int c_size = shec->get_chunk_size(in.length());
1893 for (unsigned int i = 0; i < shec->get_data_chunk_count(); ++i) {
1894 usable.clear();
1895 EXPECT_EQ(c_size, decoded[i].length());
1896 if ( c_size * (i+1) <= in.length() ) {
1897 usable.substr_of(in, c_size * i, c_size);
1898 cmp = memcmp(decoded[i].c_str(), usable.c_str(), c_size);
1899 } else {
1900 usable.substr_of(in, c_size * i, in.length() % c_size);
1901 cmp = memcmp(decoded[i].c_str(), usable.c_str(), in.length() % c_size);
1902 }
1903 EXPECT_EQ(0, cmp);
1904 }
1905
1906 delete shec;
1907 delete profile;
1908 }
1909
1910 TEST(ErasureCodeShec, decode_9)
1911 {
1912 //init
1913 ErasureCodeShecTableCache tcache;
1914 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
1915 tcache,
1916 ErasureCodeShec::MULTIPLE);
1917 ErasureCodeProfile *profile = new ErasureCodeProfile();
1918 (*profile)["plugin"] = "shec";
1919 (*profile)["technique"] = "";
1920 (*profile)["crush-failure-domain"] = "osd";
1921 (*profile)["k"] = "4";
1922 (*profile)["m"] = "3";
1923 (*profile)["c"] = "2";
1924 shec->init(*profile, &cerr);
1925
1926 //encode
1927 bufferlist in;
1928 set<int> want_to_encode;
1929 map<int, bufferlist> encoded;
1930
1931 in.append("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//length = 62
1932 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//124
1933 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//186
1934 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//248
1935 );
1936 for (unsigned int i = 0; i < shec->get_chunk_count(); ++i) {
1937 want_to_encode.insert(i);
1938 }
1939
1940 int r = shec->encode(want_to_encode, in, &encoded);
1941 EXPECT_EQ(0, r);
1942 EXPECT_EQ(shec->get_chunk_count(), encoded.size());
1943 EXPECT_EQ(shec->get_chunk_size(in.length()), encoded[0].length());
1944
1945 // all chunks are available
1946 //decode
1947 int want_to_decode[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
1948 map<int, bufferlist> decoded;
1949
1950 //extra data
1951 bufferlist buf;
1952 buf.append("abc");
1953 encoded[100] = buf;
1954
1955 r = shec->_decode(set<int>(want_to_decode, want_to_decode + 10), encoded,
1956 &decoded);
1957 EXPECT_TRUE(shec->matrix != NULL);
1958 EXPECT_EQ(0, r);
1959 EXPECT_EQ(7u, decoded.size());
1960 EXPECT_EQ(shec->get_chunk_size(in.length()), decoded[0].length());
1961
1962 bufferlist out1, usable;
1963 //out1 is "encoded"
1964 for (unsigned int i = 0; i < encoded.size(); ++i) {
1965 out1.append(encoded[i]);
1966 }
1967 EXPECT_FALSE(out1 == in);
1968 //usable is "decoded"
1969 int cmp;
1970 unsigned int c_size = shec->get_chunk_size(in.length());
1971 for (unsigned int i = 0; i < shec->get_data_chunk_count(); ++i) {
1972 usable.clear();
1973 EXPECT_EQ(c_size, decoded[i].length());
1974 if ( c_size * (i+1) <= in.length() ) {
1975 usable.substr_of(in, c_size * i, c_size);
1976 cmp = memcmp(decoded[i].c_str(), usable.c_str(), c_size);
1977 } else {
1978 usable.substr_of(in, c_size * i, in.length() % c_size);
1979 cmp = memcmp(decoded[i].c_str(), usable.c_str(), in.length() % c_size);
1980 }
1981 EXPECT_EQ(0, cmp);
1982 }
1983
1984 delete shec;
1985 delete profile;
1986 }
1987
1988 TEST(ErasureCodeShec, decode_10)
1989 {
1990 //init
1991 ErasureCodeShecTableCache tcache;
1992 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
1993 tcache,
1994 ErasureCodeShec::MULTIPLE);
1995 ErasureCodeProfile *profile = new ErasureCodeProfile();
1996 (*profile)["plugin"] = "shec";
1997 (*profile)["technique"] = "";
1998 (*profile)["crush-failure-domain"] = "osd";
1999 (*profile)["k"] = "4";
2000 (*profile)["m"] = "3";
2001 (*profile)["c"] = "2";
2002 shec->init(*profile, &cerr);
2003
2004 //encode
2005 bufferlist in;
2006 set<int> want_to_encode;
2007 map<int, bufferlist> encoded;
2008
2009 in.append("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//length = 62
2010 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//124
2011 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//186
2012 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//248
2013 );
2014 for (unsigned int i = 0; i < shec->get_chunk_count(); ++i) {
2015 want_to_encode.insert(i);
2016 }
2017
2018 int r = shec->encode(want_to_encode, in, &encoded);
2019 EXPECT_EQ(0, r);
2020 EXPECT_EQ(shec->get_chunk_count(), encoded.size());
2021 EXPECT_EQ(shec->get_chunk_size(in.length()), encoded[0].length());
2022
2023 //decode
2024 int want_to_decode[] = { 0, 1, 2, 3, 4, 5, 6 }; //more than k+m
2025 map<int, bufferlist> decoded, inchunks;
2026
2027 for ( unsigned int i = 0; i < 3; ++i) {
2028 inchunks.insert(make_pair(i, encoded[i]));
2029 }
2030
2031 r = shec->_decode(set<int>(want_to_decode, want_to_decode + 7), inchunks,
2032 &decoded);
2033 EXPECT_EQ(-1, r);
2034
2035 delete shec;
2036 delete profile;
2037 }
2038
2039 TEST(ErasureCodeShec, decode_11)
2040 {
2041 //init
2042 ErasureCodeShecTableCache tcache;
2043 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
2044 tcache,
2045 ErasureCodeShec::MULTIPLE);
2046 ErasureCodeProfile *profile = new ErasureCodeProfile();
2047 (*profile)["plugin"] = "shec";
2048 (*profile)["technique"] = "";
2049 (*profile)["crush-failure-domain"] = "osd";
2050 (*profile)["k"] = "4";
2051 (*profile)["m"] = "3";
2052 (*profile)["c"] = "2";
2053 shec->init(*profile, &cerr);
2054
2055 //encode
2056 bufferlist in;
2057 set<int> want_to_encode;
2058 map<int, bufferlist> encoded;
2059
2060 in.append("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//length = 62
2061 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//124
2062 "ABCD"//128
2063 );
2064 for (unsigned int i = 0; i < shec->get_chunk_count(); ++i) {
2065 want_to_encode.insert(i);
2066 }
2067
2068 int r = shec->encode(want_to_encode, in, &encoded);
2069 EXPECT_EQ(0, r);
2070 EXPECT_EQ(shec->get_chunk_count(), encoded.size());
2071 EXPECT_EQ(shec->get_chunk_size(in.length()), encoded[0].length());
2072
2073 //decode
2074 int want_to_decode[] = { 0, 1, 2, 3, 4 };
2075 map<int, bufferlist> decoded, inchunks;
2076
2077 for ( unsigned int i = 4; i < 7; ++i) {
2078 inchunks.insert(make_pair(i, encoded[i]));
2079 }
2080
2081 r = shec->_decode(set<int>(want_to_decode, want_to_decode + 5), inchunks,
2082 &decoded);
2083 EXPECT_EQ(-1, r);
2084
2085 delete shec;
2086 delete profile;
2087 }
2088
2089 TEST(ErasureCodeShec, decode_12)
2090 {
2091 //init
2092 ErasureCodeShecTableCache tcache;
2093 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
2094 tcache,
2095 ErasureCodeShec::MULTIPLE);
2096 ErasureCodeProfile *profile = new ErasureCodeProfile();
2097 (*profile)["plugin"] = "shec";
2098 (*profile)["technique"] = "";
2099 (*profile)["crush-failure-domain"] = "osd";
2100 (*profile)["k"] = "4";
2101 (*profile)["m"] = "3";
2102 (*profile)["c"] = "2";
2103 shec->init(*profile, &cerr);
2104
2105 //encode
2106 bufferlist in;
2107 set<int> want_to_encode;
2108 map<int, bufferlist> encoded;
2109
2110 in.append("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//length = 62
2111 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//124
2112 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//186
2113 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//248
2114 );
2115 for (unsigned int i = 0; i < shec->get_chunk_count(); ++i) {
2116 want_to_encode.insert(i);
2117 }
2118
2119 int r = shec->encode(want_to_encode, in, &encoded);
2120 EXPECT_EQ(0, r);
2121 EXPECT_EQ(shec->get_chunk_count(), encoded.size());
2122 EXPECT_EQ(shec->get_chunk_size(in.length()), encoded[0].length());
2123
2124 // all chunks are available
2125 //decode
2126 int want_to_decode[] = { 0, 1, 2, 3, 4, 5, 6 };
2127
2128 //decoded = NULL
2129 r = shec->_decode(set<int>(want_to_decode, want_to_decode + 7), encoded,
2130 NULL);
2131 EXPECT_NE(0, r);
2132
2133 delete shec;
2134 delete profile;
2135 }
2136
2137 TEST(ErasureCodeShec, decode_13)
2138 {
2139 //init
2140 ErasureCodeShecTableCache tcache;
2141 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
2142 tcache,
2143 ErasureCodeShec::MULTIPLE);
2144 ErasureCodeProfile *profile = new ErasureCodeProfile();
2145 (*profile)["plugin"] = "shec";
2146 (*profile)["technique"] = "";
2147 (*profile)["crush-failure-domain"] = "osd";
2148 (*profile)["k"] = "4";
2149 (*profile)["m"] = "3";
2150 (*profile)["c"] = "2";
2151 shec->init(*profile, &cerr);
2152
2153 //encode
2154 bufferlist in;
2155 set<int> want_to_encode;
2156 map<int, bufferlist> encoded;
2157
2158 in.append("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//length = 62
2159 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//124
2160 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//186
2161 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//248
2162 );
2163 for (unsigned int i = 0; i < shec->get_chunk_count(); ++i) {
2164 want_to_encode.insert(i);
2165 }
2166
2167 int r = shec->encode(want_to_encode, in, &encoded);
2168 EXPECT_EQ(0, r);
2169 EXPECT_EQ(shec->get_chunk_count(), encoded.size());
2170 EXPECT_EQ(shec->get_chunk_size(in.length()), encoded[0].length());
2171
2172 // all chunks are available
2173 //decode
2174 int want_to_decode[] = { 0, 1, 2, 3, 4, 5, 6 };
2175 map<int, bufferlist> decoded;
2176
2177 //extra data
2178 bufferlist buf;
2179 buf.append("a");
2180 for (int i = 0; i < 100; ++i) {
2181 decoded[i] = buf;
2182 }
2183
2184 r = shec->_decode(set<int>(want_to_decode, want_to_decode + 7), encoded,
2185 &decoded);
2186 EXPECT_NE(0, r);
2187
2188 delete shec;
2189 delete profile;
2190 }
2191
2192 TEST(ErasureCodeShec, decode2_1)
2193 {
2194 //init
2195 ErasureCodeShecTableCache tcache;
2196 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
2197 tcache,
2198 ErasureCodeShec::MULTIPLE);
2199 ErasureCodeProfile *profile = new ErasureCodeProfile();
2200 (*profile)["plugin"] = "shec";
2201 (*profile)["technique"] = "";
2202 (*profile)["crush-failure-domain"] = "osd";
2203 (*profile)["k"] = "4";
2204 (*profile)["m"] = "3";
2205 (*profile)["c"] = "2";
2206 shec->init(*profile, &cerr);
2207
2208 //encode
2209 bufferlist in;
2210 set<int> want_to_encode;
2211 map<int, bufferlist> encoded;
2212
2213 in.append("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//length = 62
2214 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//124
2215 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//186
2216 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//248
2217 );
2218 for (unsigned int i = 0; i < shec->get_chunk_count(); ++i) {
2219 want_to_encode.insert(i);
2220 }
2221
2222 int r = shec->encode(want_to_encode, in, &encoded);
2223 EXPECT_EQ(0, r);
2224 EXPECT_EQ(shec->get_chunk_count(), encoded.size());
2225 EXPECT_EQ(shec->get_chunk_size(in.length()), encoded[0].length());
2226
2227 // all chunks are available
2228 //decode
2229 int want_to_decode[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
2230 map<int, bufferlist> decoded;
2231
2232 r = shec->_decode(set<int>(want_to_decode, want_to_decode + 2), encoded,
2233 &decoded);
2234 EXPECT_TRUE(shec->matrix != NULL);
2235 EXPECT_EQ(0, r);
2236 EXPECT_EQ(2u, decoded.size());
2237
2238 bufferlist out;
2239 shec->decode_concat(encoded, &out);
2240 bufferlist usable;
2241 usable.substr_of(out, 0, in.length());
2242 EXPECT_TRUE(usable == in);
2243
2244 delete shec;
2245 delete profile;
2246 }
2247
2248 TEST(ErasureCodeShec, decode2_3)
2249 {
2250 //init
2251 ErasureCodeShecTableCache tcache;
2252 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
2253 tcache,
2254 ErasureCodeShec::MULTIPLE);
2255 ErasureCodeProfile *profile = new ErasureCodeProfile();
2256 (*profile)["plugin"] = "shec";
2257 (*profile)["technique"] = "";
2258 (*profile)["crush-failure-domain"] = "osd";
2259 (*profile)["k"] = "4";
2260 (*profile)["m"] = "3";
2261 (*profile)["c"] = "2";
2262 shec->init(*profile, &cerr);
2263
2264 //encode
2265 bufferlist in;
2266 set<int> want_to_encode;
2267 map<int, bufferlist> encoded;
2268
2269 in.append("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//length = 62
2270 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//124
2271 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//186
2272 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//248
2273 );
2274 for (unsigned int i = 0; i < shec->get_chunk_count(); ++i) {
2275 want_to_encode.insert(i);
2276 }
2277
2278 int r = shec->encode(want_to_encode, in, &encoded);
2279 EXPECT_EQ(0, r);
2280 EXPECT_EQ(shec->get_chunk_count(), encoded.size());
2281 EXPECT_EQ(shec->get_chunk_size(in.length()), encoded[0].length());
2282
2283 // all chunks are available
2284 //decode
2285 int want_to_decode[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
2286 map<int, bufferlist> decoded;
2287
2288 pthread_t tid;
2289 g_flag = 0;
2290 pthread_create(&tid, NULL, thread4, shec);
2291 while (g_flag == 0) {
2292 usleep(1);
2293 }
2294 sleep(1);
2295 printf("*** test start ***\n");
2296 r = shec->_decode(set<int>(want_to_decode, want_to_decode + 2), encoded,
2297 &decoded);
2298 EXPECT_TRUE(shec->matrix != NULL);
2299 EXPECT_EQ(0, r);
2300 EXPECT_EQ(2u, decoded.size());
2301 printf("*** test end ***\n");
2302 g_flag = 0;
2303 pthread_join(tid, NULL);
2304
2305 bufferlist out;
2306 shec->decode_concat(encoded, &out);
2307 bufferlist usable;
2308 usable.substr_of(out, 0, in.length());
2309 EXPECT_TRUE(usable == in);
2310
2311 delete shec;
2312 delete profile;
2313 }
2314
2315 TEST(ErasureCodeShec, decode2_4)
2316 {
2317 //init
2318 ErasureCodeShecTableCache tcache;
2319 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
2320 tcache,
2321 ErasureCodeShec::MULTIPLE);
2322 ErasureCodeProfile *profile = new ErasureCodeProfile();
2323 (*profile)["plugin"] = "shec";
2324 (*profile)["technique"] = "";
2325 (*profile)["crush-failure-domain"] = "osd";
2326 (*profile)["k"] = "4";
2327 (*profile)["m"] = "3";
2328 (*profile)["c"] = "2";
2329 shec->init(*profile, &cerr);
2330
2331 //encode
2332 bufferlist in;
2333 set<int> want_to_encode;
2334 map<int, bufferlist> encoded;
2335
2336 in.append("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//length = 62
2337 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//124
2338 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//186
2339 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//248
2340 );
2341 for (unsigned int i = 0; i < shec->get_chunk_count(); ++i) {
2342 want_to_encode.insert(i);
2343 }
2344
2345 int r = shec->encode(want_to_encode, in, &encoded);
2346 EXPECT_EQ(0, r);
2347 EXPECT_EQ(shec->get_chunk_count(), encoded.size());
2348 EXPECT_EQ(shec->get_chunk_size(in.length()), encoded[0].length());
2349
2350 //decode
2351 int want_to_decode[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
2352 map<int, bufferlist> decoded;
2353
2354 // cannot recover
2355 bufferlist out;
2356 map<int, bufferlist> degraded;
2357 degraded[0] = encoded[0];
2358
2359 r = shec->_decode(set<int>(want_to_decode, want_to_decode + 2), degraded,
2360 &decoded);
2361 EXPECT_EQ(-1, r);
2362
2363 delete shec;
2364 delete profile;
2365 }
2366
2367 TEST(ErasureCodeShec, create_rule_1_2)
2368 {
2369 //create rule
2370 CrushWrapper *crush = new CrushWrapper;
2371 crush->create();
2372 crush->set_type_name(2, "root");
2373 crush->set_type_name(1, "host");
2374 crush->set_type_name(0, "osd");
2375
2376 int rootno;
2377 crush->add_bucket(0, CRUSH_BUCKET_STRAW, CRUSH_HASH_RJENKINS1, 2, 0, NULL,
2378 NULL, &rootno);
2379 crush->set_item_name(rootno, "default");
2380
2381 map < string, string > loc;
2382 loc["root"] = "default";
2383
2384 int num_host = 2;
2385 int num_osd = 5;
2386 int osd = 0;
2387 for (int h = 0; h < num_host; ++h) {
2388 loc["host"] = string("host-") + stringify(h);
2389 for (int o = 0; o < num_osd; ++o, ++osd) {
2390 crush->insert_item(g_ceph_context, osd, 1.0,
2391 string("osd.") + stringify(osd), loc);
2392 }
2393 }
2394
2395 //init
2396 ErasureCodeShecTableCache tcache;
2397 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
2398 tcache,
2399 ErasureCodeShec::MULTIPLE);
2400 ErasureCodeProfile *profile = new ErasureCodeProfile();
2401 (*profile)["plugin"] = "shec";
2402 (*profile)["technique"] = "";
2403 (*profile)["crush-failure-domain"] = "osd";
2404 (*profile)["k"] = "4";
2405 (*profile)["m"] = "3";
2406 (*profile)["c"] = "2";
2407 shec->init(*profile, &cerr);
2408
2409 //create_rule
2410 stringstream ss;
2411
2412 int r = shec->create_rule("myrule", *crush, &ss);
2413 EXPECT_EQ(0, r);
2414 EXPECT_STREQ("myrule", crush->rule_name_map[0].c_str());
2415
2416 //reexecute create_rule
2417 r = shec->create_rule("myrule", *crush, &ss);
2418 EXPECT_EQ(-EEXIST, r);
2419
2420 delete shec;
2421 delete profile;
2422 delete crush;
2423 }
2424
2425 TEST(ErasureCodeShec, create_rule_4)
2426 {
2427 //create rule
2428 CrushWrapper *crush = new CrushWrapper;
2429 crush->create();
2430 crush->set_type_name(2, "root");
2431 crush->set_type_name(1, "host");
2432 crush->set_type_name(0, "osd");
2433
2434 int rootno;
2435 crush->add_bucket(0, CRUSH_BUCKET_STRAW, CRUSH_HASH_RJENKINS1, 2, 0, NULL,
2436 NULL, &rootno);
2437 crush->set_item_name(rootno, "default");
2438
2439 map < string, string > loc;
2440 loc["root"] = "default";
2441
2442 int num_host = 2;
2443 int num_osd = 5;
2444 int osd = 0;
2445 for (int h = 0; h < num_host; ++h) {
2446 loc["host"] = string("host-") + stringify(h);
2447 for (int o = 0; o < num_osd; ++o, ++osd) {
2448 crush->insert_item(g_ceph_context, osd, 1.0,
2449 string("osd.") + stringify(osd), loc);
2450 }
2451 }
2452
2453 //init
2454 ErasureCodeShecTableCache tcache;
2455 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
2456 tcache,
2457 ErasureCodeShec::MULTIPLE);
2458 ErasureCodeProfile *profile = new ErasureCodeProfile();
2459 (*profile)["plugin"] = "shec";
2460 (*profile)["technique"] = "";
2461 (*profile)["crush-failure-domain"] = "osd";
2462 (*profile)["k"] = "4";
2463 (*profile)["m"] = "3";
2464 (*profile)["c"] = "2";
2465 shec->init(*profile, &cerr);
2466
2467 //create_rule
2468 int r = shec->create_rule("myrule", *crush, NULL); //ss = NULL
2469 EXPECT_EQ(0, r);
2470
2471 delete shec;
2472 delete profile;
2473 delete crush;
2474 }
2475
2476 TEST(ErasureCodeShec, create_rule2_1)
2477 {
2478 //create rule
2479 CrushWrapper *crush = new CrushWrapper;
2480 crush->create();
2481 crush->set_type_name(2, "root");
2482 crush->set_type_name(1, "host");
2483 crush->set_type_name(0, "osd");
2484
2485 int rootno;
2486 crush->add_bucket(0, CRUSH_BUCKET_STRAW, CRUSH_HASH_RJENKINS1, 2, 0, NULL,
2487 NULL, &rootno);
2488 crush->set_item_name(rootno, "default");
2489
2490 map < string, string > loc;
2491 loc["root"] = "default";
2492
2493 int num_host = 2;
2494 int num_osd = 5;
2495 int osd = 0;
2496 for (int h = 0; h < num_host; ++h) {
2497 loc["host"] = string("host-") + stringify(h);
2498 for (int o = 0; o < num_osd; ++o, ++osd) {
2499 crush->insert_item(g_ceph_context, osd, 1.0,
2500 string("osd.") + stringify(osd), loc);
2501 }
2502 }
2503
2504 //init
2505 ErasureCodeShecTableCache tcache;
2506 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
2507 tcache,
2508 ErasureCodeShec::MULTIPLE);
2509 ErasureCodeProfile *profile = new ErasureCodeProfile();
2510 (*profile)["plugin"] = "shec";
2511 (*profile)["technique"] = "";
2512 (*profile)["crush-failure-domain"] = "osd";
2513 (*profile)["k"] = "4";
2514 (*profile)["m"] = "3";
2515 (*profile)["c"] = "2";
2516 shec->init(*profile, &cerr);
2517
2518 //create_rule
2519 stringstream ss;
2520
2521 int r = shec->create_rule("myrule", *crush, &ss);
2522 EXPECT_EQ(0, r);
2523 EXPECT_STREQ("myrule", crush->rule_name_map[0].c_str());
2524
2525 delete shec;
2526 delete profile;
2527 delete crush;
2528 }
2529
2530 struct CreateRuleset2_3_Param_d {
2531 ErasureCodeShec *shec;
2532 CrushWrapper *crush;
2533 };
2534
2535 TEST(ErasureCodeShec, create_rule2_3)
2536 {
2537 //create rule
2538 CrushWrapper *crush = new CrushWrapper;
2539 crush->create();
2540 crush->set_type_name(2, "root");
2541 crush->set_type_name(1, "host");
2542 crush->set_type_name(0, "osd");
2543
2544 int rootno;
2545 crush->add_bucket(0, CRUSH_BUCKET_STRAW, CRUSH_HASH_RJENKINS1, 2, 0, NULL,
2546 NULL, &rootno);
2547 crush->set_item_name(rootno, "default");
2548
2549 map < string, string > loc;
2550 loc["root"] = "default";
2551
2552 int num_host = 2;
2553 int num_osd = 5;
2554 int osd = 0;
2555 for (int h = 0; h < num_host; ++h) {
2556 loc["host"] = string("host-") + stringify(h);
2557 for (int o = 0; o < num_osd; ++o, ++osd) {
2558 crush->insert_item(g_ceph_context, osd, 1.0,
2559 string("osd.") + stringify(osd), loc);
2560 }
2561 }
2562
2563 //init
2564 ErasureCodeShecTableCache tcache;
2565 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
2566 tcache,
2567 ErasureCodeShec::MULTIPLE);
2568 ErasureCodeProfile *profile = new ErasureCodeProfile();
2569 (*profile)["plugin"] = "shec";
2570 (*profile)["technique"] = "";
2571 (*profile)["crush-failure-domain"] = "osd";
2572 (*profile)["k"] = "4";
2573 (*profile)["m"] = "3";
2574 (*profile)["c"] = "2";
2575 shec->init(*profile, &cerr);
2576
2577 //create_rule
2578 stringstream ss;
2579
2580 pthread_t tid;
2581 g_flag = 0;
2582 pthread_create(&tid, NULL, thread3, shec);
2583 while (g_flag == 0) {
2584 usleep(1);
2585 }
2586 sleep(1);
2587 printf("*** test start ***\n");
2588 int r = (shec->create_rule("myrule", *crush, &ss));
2589 EXPECT_TRUE(r >= 0);
2590 printf("*** test end ***\n");
2591 g_flag = 0;
2592 pthread_join(tid, NULL);
2593
2594 delete shec;
2595 delete profile;
2596 delete crush;
2597 }
2598
2599 TEST(ErasureCodeShec, get_chunk_count_1)
2600 {
2601 //init
2602 ErasureCodeShecTableCache tcache;
2603 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
2604 tcache,
2605 ErasureCodeShec::MULTIPLE);
2606 ErasureCodeProfile *profile = new ErasureCodeProfile();
2607 (*profile)["plugin"] = "shec";
2608 (*profile)["technique"] = "";
2609 (*profile)["crush-failure-domain"] = "osd";
2610 (*profile)["k"] = "4";
2611 (*profile)["m"] = "3";
2612 (*profile)["c"] = "2";
2613 shec->init(*profile, &cerr);
2614
2615 //get_chunk_count
2616 EXPECT_EQ(7u, shec->get_chunk_count());
2617
2618 delete shec;
2619 delete profile;
2620 }
2621
2622 TEST(ErasureCodeShec, get_data_chunk_count_1)
2623 {
2624 //init
2625 ErasureCodeShecTableCache tcache;
2626 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
2627 tcache,
2628 ErasureCodeShec::MULTIPLE);
2629 ErasureCodeProfile *profile = new ErasureCodeProfile();
2630 (*profile)["plugin"] = "shec";
2631 (*profile)["technique"] = "";
2632 (*profile)["crush-failure-domain"] = "osd";
2633 (*profile)["k"] = "4";
2634 (*profile)["m"] = "3";
2635 (*profile)["c"] = "2";
2636 shec->init(*profile, &cerr);
2637
2638 //get_data_chunk_count
2639 EXPECT_EQ(4u, shec->get_data_chunk_count());
2640
2641 delete shec;
2642 delete profile;
2643 }
2644
2645 TEST(ErasureCodeShec, get_chunk_size_1_2)
2646 {
2647 //init
2648 ErasureCodeShecTableCache tcache;
2649 ErasureCodeShec* shec = new ErasureCodeShecReedSolomonVandermonde(
2650 tcache,
2651 ErasureCodeShec::MULTIPLE);
2652 ErasureCodeProfile *profile = new ErasureCodeProfile();
2653 (*profile)["plugin"] = "shec";
2654 (*profile)["technique"] = "";
2655 (*profile)["crush-failure-domain"] = "osd";
2656 (*profile)["k"] = "4";
2657 (*profile)["m"] = "3";
2658 (*profile)["c"] = "2";
2659 (*profile)["w"] = "8";
2660 shec->init(*profile, &cerr);
2661
2662 //when there is no padding(128=k*w*4)
2663 EXPECT_EQ(32u, shec->get_chunk_size(128));
2664 //when there is padding(126=k*w*4-2)
2665 EXPECT_EQ(32u, shec->get_chunk_size(126));
2666
2667 delete shec;
2668 delete profile;
2669 }
2670
2671 void* thread1(void* pParam)
2672 {
2673 ErasureCodeShec* shec = (ErasureCodeShec*) pParam;
2674 set<int> want_to_decode;
2675 set<int> available_chunks;
2676 set<int> minimum_chunks;
2677
2678 want_to_decode.insert(0);
2679 want_to_decode.insert(1);
2680 available_chunks.insert(0);
2681 available_chunks.insert(1);
2682 available_chunks.insert(2);
2683
2684 printf("*** thread loop start ***\n");
2685 g_flag = 1;
2686 while (g_flag == 1) {
2687 shec->_minimum_to_decode(want_to_decode, available_chunks, &minimum_chunks);
2688 }
2689 printf("*** thread loop end ***\n");
2690
2691 return NULL;
2692 }
2693
2694 void* thread2(void* pParam)
2695 {
2696 ErasureCodeShec* shec = (ErasureCodeShec*) pParam;
2697 set<int> want_to_decode;
2698 map<int, int> available_chunks;
2699 set<int> minimum_chunks;
2700
2701 want_to_decode.insert(0);
2702 want_to_decode.insert(1);
2703 available_chunks[0] = 0;
2704 available_chunks[1] = 1;
2705 available_chunks[2] = 2;
2706
2707 printf("*** thread loop start ***\n");
2708 g_flag = 1;
2709 while (g_flag == 1) {
2710 shec->minimum_to_decode_with_cost(want_to_decode, available_chunks,
2711 &minimum_chunks);
2712 minimum_chunks.clear();
2713 }
2714 printf("*** thread loop end ***\n");
2715
2716 return NULL;
2717 }
2718
2719 void* thread3(void* pParam)
2720 {
2721 ErasureCodeShec* shec = (ErasureCodeShec*) pParam;
2722
2723 std::unique_ptr<CrushWrapper> crush = std::make_unique<CrushWrapper>();
2724 crush->create();
2725 crush->set_type_name(2, "root");
2726 crush->set_type_name(1, "host");
2727 crush->set_type_name(0, "osd");
2728
2729 int rootno;
2730 crush->add_bucket(0, CRUSH_BUCKET_STRAW, CRUSH_HASH_RJENKINS1, 2, 0, NULL,
2731 NULL, &rootno);
2732 crush->set_item_name(rootno, "default");
2733
2734 map < string, string > loc;
2735 loc["root"] = "default";
2736
2737 int num_host = 2;
2738 int num_osd = 5;
2739 int osd = 0;
2740 for (int h = 0; h < num_host; ++h) {
2741 loc["host"] = string("host-") + stringify(h);
2742 for (int o = 0; o < num_osd; ++o, ++osd) {
2743 crush->insert_item(g_ceph_context, osd, 1.0,
2744 string("osd.") + stringify(osd), loc);
2745 }
2746 }
2747
2748 stringstream ss;
2749 int i = 0;
2750 char name[30];
2751
2752 printf("*** thread loop start ***\n");
2753 g_flag = 1;
2754 while (g_flag == 1) {
2755 sprintf(name, "myrule%d", i);
2756 shec->create_rule(name, *crush, &ss);
2757 ++i;
2758 }
2759 printf("*** thread loop end ***\n");
2760
2761 return NULL;
2762 }
2763
2764 void* thread4(void* pParam)
2765 {
2766 ErasureCodeShec* shec = (ErasureCodeShec*) pParam;
2767
2768 bufferlist in;
2769 in.append("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//length = 62
2770 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//124
2771 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//186
2772 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//248
2773 );
2774 set<int> want_to_encode;
2775 for (unsigned int i = 0; i < shec->get_chunk_count(); ++i) {
2776 want_to_encode.insert(i);
2777 }
2778
2779 map<int, bufferlist> encoded;
2780
2781 printf("*** thread loop start ***\n");
2782 g_flag = 1;
2783 while (g_flag == 1) {
2784 shec->encode(want_to_encode, in, &encoded);
2785 encoded.clear();
2786 }
2787 printf("*** thread loop end ***\n");
2788
2789 return NULL;
2790 }
2791
2792 void* thread5(void* pParam)
2793 {
2794 ErasureCodeShec* shec = (ErasureCodeShec*) pParam;
2795
2796 bufferlist in;
2797 in.append("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//length = 62
2798 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//124
2799 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//186
2800 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//248
2801 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//310
2802 );
2803 set<int> want_to_encode;
2804 for (unsigned int i = 0; i < shec->get_chunk_count(); ++i) {
2805 want_to_encode.insert(i);
2806 }
2807 map<int, bufferlist> encoded;
2808 shec->encode(want_to_encode, in, &encoded);
2809
2810 int want_to_decode[] = { 0, 1, 2, 3, 4, 5 };
2811 map<int, bufferlist> decoded;
2812
2813 printf("*** thread loop start ***\n");
2814 g_flag = 1;
2815 while (g_flag == 1) {
2816 shec->_decode(set<int>(want_to_decode, want_to_decode + 2), encoded,
2817 &decoded);
2818 decoded.clear();
2819 }
2820 printf("*** thread loop end ***\n");
2821
2822 return NULL;
2823 }