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