summaryrefslogtreecommitdiff
path: root/test/liberasurecode_test.c
diff options
context:
space:
mode:
authorKota Tsuyuzaki <bloodeagle40234@gmail.com>2015-02-05 20:15:57 -0800
committerKota Tsuyuzaki <bloodeagle40234@gmail.com>2015-02-27 15:44:37 +0900
commit57f5c565e64f8c33d3e299a8542de6d0f083b840 (patch)
tree2560935514eaa6b18c9f7752a6f60c2c3ae861e2 /test/liberasurecode_test.c
parentaa0c9605048153f640b8b871da9e483347e4b70f (diff)
downloadliberasurecode-57f5c565e64f8c33d3e299a8542de6d0f083b840.tar.gz
Ensure fragment pointers passed to cleanup
This patch achieves a couple of things as follows: - Undoing the liberasurecode_encode_cleanup specification to expect "fragment" pointers as its arguments. - Ensuring liberasurecode_encode to pass "fratment" pointers to liberasurecode_encode_cleanup. liberasurecode_encode_cleanup is used also in pyeclib so that it is expected that the argument pointers (i.e. encoded_data and encoded_parity) should be the collection of the heads of "fragment" pointers. However, when the backend encode fails, liberasurecode keeps "data" pointers behind of fragment_header, and then, goes to "out:" statement to cleanup its memories. It causes invalid pointer failure. This patch adds a translation function from "data" pointers to "fragment" pointers and ensure liberasurecode_encode to pass correct pointers to libersurecode_encode_cleanup.
Diffstat (limited to 'test/liberasurecode_test.c')
-rw-r--r--test/liberasurecode_test.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/test/liberasurecode_test.c b/test/liberasurecode_test.c
index 9d826c6..04d06cf 100644
--- a/test/liberasurecode_test.c
+++ b/test/liberasurecode_test.c
@@ -213,6 +213,12 @@ out:
return num_frags;
}
+static int encode_failure_stub(void *desc, char **data,
+ char **parity, int blocksize)
+{
+ return -1;
+}
+
static void validate_fragment_checksum(struct ec_args *args,
fragment_metadata_t *metadata, char *fragment_data)
{
@@ -280,6 +286,8 @@ static void test_encode_invalid_args()
char *orig_data = create_buffer(orig_data_size, 'x');
char **encoded_data = NULL, **encoded_parity = NULL;
uint64_t encoded_fragment_len = 0;
+ ec_backend_t instance = NULL;
+ int (*orig_encode_func)(void *, char **, char **, int);
assert(orig_data != NULL);
rc = liberasurecode_encode(desc, orig_data, orig_data_size,
@@ -308,6 +316,15 @@ static void test_encode_invalid_args()
rc = liberasurecode_encode(desc, orig_data, orig_data_size,
&encoded_data, &encoded_parity, NULL);
assert(rc < 0);
+
+ instance = liberasurecode_backend_instance_get_by_desc(desc);
+ orig_encode_func = instance->common.ops->encode;
+ instance->common.ops->encode = encode_failure_stub;
+ rc = liberasurecode_encode(desc, orig_data, orig_data_size,
+ &encoded_data, &encoded_parity, &encoded_fragment_len);
+ assert(rc < 0);
+ instance->common.ops->encode = orig_encode_func;
+
free(orig_data);
}