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 91
|
#!/bin/sh
set -e
BACKEND=$1
cd "$AUTOPKGTEST_TMP"
cat <<TEST_END > encode-decode.c
#include <erasurecode.h>
int main()
{
struct ec_args args = {0};
args.k = 3;
args.m = 3;
args.hd = 3;
const char in[] = "dummy input data";
uint64_t in_len = strlen(in) + 1;
char **out_data;
char **out_parity;
uint64_t out_len;
char *decoded;
uint64_t decoded_len;
int ret;
int e;
setbuf(stdout, NULL);
// Create
printf("create: ");
e = liberasurecode_instance_create($BACKEND, &args);
if (e <= 0) {
printf("ERROR: liberasurecode_instance_create: %d\n", e);
return 1;
}
printf("OK\n");
// Encode
printf("encode: ");
ret = liberasurecode_encode(e, in, in_len, &out_data, &out_parity, &out_len);
if (ret) {
printf("ERROR: liberasurecode_encode: %d\n", ret);
return 1;
}
printf("OK\n");
// Decode
printf("decode: ");
ret = liberasurecode_decode(e, out_data, args.k, out_len, 0, &decoded, &decoded_len);
if (ret) {
printf("ERROR: liberasurecode_decode: %d\n", ret);
return 1;
}
printf("OK\n");
// Compare
printf("compare: ");
if (in_len != decoded_len) {
printf("ERROR: wrong decoded_len: %lu != %lu\n", in_len, decoded_len);
return 1;
}
if (strcmp(in, decoded) != 0) {
printf("ERROR: decoded output is not same as input: '%s' != '%s'\n", in, decoded);
return 1;
}
printf("OK\n");
// Cleanup
printf("cleanup: ");
liberasurecode_encode_cleanup(e, out_data, out_parity);
liberasurecode_decode_cleanup(e, decoded);
printf("OK\n");
// Destroy
printf("destroy: ");
ret = liberasurecode_instance_destroy(e);
if (ret) {
printf("ERROR: liberasurecode_instance_destroy: %d\n", ret);
return 1;
}
printf("OK\n");
return 0;
}
TEST_END
gcc -Wall -o encode-decode.bin encode-decode.c -lerasurecode -ldl
echo "build: OK"
./encode-decode.bin
rm encode-decode.c encode-decode.bin
|