-
Notifications
You must be signed in to change notification settings - Fork 3
/
test_librain_legacy.c
91 lines (74 loc) · 2.26 KB
/
test_librain_legacy.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/* Librain, an erasure code library.
* Copyright (C) 2011 Worldline, original work.
* Copyright (C) 2015 OpenIO, modified as part of its software defined storage solution.
* All rights reserved.
*
* This software may be modified and distributed under the terms
* of the BSD license. See the LICENSE file for details.
*/
#include <stdlib.h>
#include <string.h>
#include "./librain.h"
#include "./test_utils.h"
static void
test_erasure_code_recovery (size_t length,
const char *algo, unsigned int k, unsigned int m)
{
uint8_t *buf0=NULL, *buf1=NULL;
int rc;
rc = posix_memalign((void**)&buf0, sizeof(long), length);
assert(rc == 0 && buf0 != NULL);
rc = posix_memalign((void**)&buf1, sizeof(long), length);
assert(rc == 0 && buf1 != NULL);
randomize(buf0, length);
memcpy(buf1, buf0, length);
uint8_t **parity = rain_get_coding_chunks(buf0, length, k, m, algo);
assert(parity != NULL);
for (unsigned int i=0; i<m ;++i) {
assert(parity[i] != NULL);
free(parity[i]);
}
free(parity);
assert(0 == memcmp(buf0, buf1, length));
free(buf0);
free(buf1);
}
static void
test_erasure_code_sizes (size_t length, const char *algo,
unsigned int k, unsigned int m)
{
struct timespec pre, post;
uint8_t *buf;
int rc = posix_memalign((void**)&buf, sizeof(long), length);
assert(rc == 0 && buf != NULL);
randomize(buf, length);
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &pre);
uint8_t **parity = rain_get_coding_chunks(buf, length, k, m, algo);
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &post);
assert(parity != NULL);
for (unsigned int i=0; i<m ;++i) {
assert(parity[i] != NULL);
free(parity[i]);
}
free(parity);
free(buf);
PRINTF("%-10s %2u %2u %9lu %lu\n", algo, k, m, length, _elapsed_msec(pre, post));
}
int
main(int argc, char **argv)
{
(void) argc, (void) argv;
for (size_t length = 64*kiB; length <= 8*MiB ; length*=2) {
for (unsigned int k=2; k<8 ;++k)
test_erasure_code_recovery (length, "liber8tion", k, 2);
for (unsigned int k=4; k<11 ;++k)
test_erasure_code_recovery (length, "crs", k, 4);
}
for (size_t length = 1*MiB; length <= 256*MiB ; length*=2) {
for (unsigned int k=2; k<8 ;++k)
test_erasure_code_sizes (length, "liber8tion", k, 2);
for (unsigned int k=4; k<11 ;++k)
test_erasure_code_sizes (length, "crs", k, 4);
}
return 0;
}