summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKota Tsuyuzaki <bloodeagle40234@gmail.com>2015-02-01 23:04:25 -0800
committerKota Tsuyuzaki <bloodeagle40234@gmail.com>2015-02-27 15:24:04 +0900
commitaa0c9605048153f640b8b871da9e483347e4b70f (patch)
treef880589dc2eaa73cbc215ae9b06f15891787eacc
parent289099c43d63f049c75c2e9bfd49eaa545a12847 (diff)
downloadliberasurecode-aa0c9605048153f640b8b871da9e483347e4b70f.tar.gz
Fix get_fragment_partition return value
When num_missing is over than the num of parities (i.e. > m), get_fragment_partition should return -1 as an error code. This patch fixes it and adds a test called "test_get_fragment_partition" into liberasurecode_test.c.
-rw-r--r--src/erasurecode_preprocessing.c5
-rw-r--r--test/liberasurecode_test.c60
2 files changed, 63 insertions, 2 deletions
diff --git a/src/erasurecode_preprocessing.c b/src/erasurecode_preprocessing.c
index 62134ba..b55f635 100644
--- a/src/erasurecode_preprocessing.c
+++ b/src/erasurecode_preprocessing.c
@@ -245,8 +245,9 @@ int get_fragment_partition(
num_missing++;
}
}
-
- return (num_missing > m) ? 1 : 0;
+ // TODO: In general, it is possible to reconstruct one or more fragments
+ // when more than m fragments are missing (e.g. flat XOR codes)
+ return (num_missing > m) ? -1 : 0;
}
int fragments_to_string(int k, int m,
diff --git a/test/liberasurecode_test.c b/test/liberasurecode_test.c
index 18a008f..9d826c6 100644
--- a/test/liberasurecode_test.c
+++ b/test/liberasurecode_test.c
@@ -30,6 +30,7 @@
#include <stdbool.h>
#include "erasurecode.h"
#include "erasurecode_helpers.h"
+#include "erasurecode_preprocessing.h"
#include "erasurecode_backend.h"
#include "alg_sig.h"
#define NULL_BACKEND "null"
@@ -501,6 +502,61 @@ static void test_verify_stripe_metadata_invalid_args() {
}
+static void test_get_fragment_partition()
+{
+ int i;
+ int rc = 0;
+ int desc = -1;
+ int orig_data_size = 1024 * 1024;
+ char *orig_data = create_buffer(orig_data_size, 'x');
+ char **encoded_data = NULL, **encoded_parity = NULL;
+ uint64_t encoded_fragment_len = 0;
+ int num_avail_frags = -1;
+ char **avail_frags = NULL;
+ int *skips = create_skips_array(&null_args, -1);
+ int *missing;
+
+ desc = liberasurecode_instance_create(EC_BACKEND_NULL, &null_args);
+ assert(desc > 0);
+ rc = liberasurecode_encode(desc, orig_data, orig_data_size,
+ &encoded_data, &encoded_parity, &encoded_fragment_len);
+ assert(0 == rc);
+
+ missing = alloc_and_set_buffer(sizeof(char*) * null_args.k, -1);
+
+ for(i = 0; i < null_args.m; i++) skips[i] = 1;
+ num_avail_frags = create_frags_array(&avail_frags, encoded_data,
+ encoded_parity, &null_args, skips);
+
+ rc = get_fragment_partition(null_args.k, null_args.m, avail_frags, num_avail_frags,
+ encoded_data, encoded_parity, missing);
+ assert(0 == rc);
+
+ for(i = 0; i < null_args.m; i++) assert(missing[i] == i);
+ assert(missing[++i] == -1);
+
+ free(missing);
+
+ for(i = 0; i < null_args.m + 1; i++) skips[i] = 1;
+ num_avail_frags = create_frags_array(&avail_frags, encoded_data,
+ encoded_parity, &null_args, skips);
+
+ missing = alloc_and_set_buffer(sizeof(char*) * null_args.k, -1);
+ rc = get_fragment_partition(null_args.k, null_args.m, avail_frags, num_avail_frags,
+ encoded_data, encoded_parity, missing);
+
+ for(i = 0; i < null_args.m + 1; i++) assert(missing[i] == i);
+ assert(missing[++i] == -1);
+
+ assert(rc < 0);
+
+ free(missing);
+ free(skips);
+ liberasurecode_encode_cleanup(desc, encoded_data, encoded_parity);
+ free(avail_frags);
+ free(orig_data);
+}
+
static void encode_decode_test_impl(const ec_backend_id_t be_id,
struct ec_args *args,
int *skip)
@@ -1109,6 +1165,10 @@ struct testcase testcases[] = {
test_fragments_needed_invalid_args,
EC_BACKENDS_MAX, CHKSUM_TYPES_MAX,
.skip = false},
+ {"test_get_fragment_partition",
+ test_get_fragment_partition,
+ EC_BACKENDS_MAX, CHKSUM_TYPES_MAX,
+ .skip = false},
// NULL backend test
{"create_and_destroy_backend",
test_create_and_destroy_backend,