From e8b5a64d8d68c6f379fcd8aa69d934682b9e1a25 Mon Sep 17 00:00:00 2001 From: Kota Tsuyuzaki Date: Tue, 18 Oct 2016 02:10:01 -0700 Subject: [PATCH] Fix liberasurecode skipping a bunch of invalid_args tests Since the commit a01b1818c874a65d1d1fb8f11ea441e9d3e18771, we have been to able to test some parameters for each tests. However, instead, the NULL which means the end of the test parameters causes skipping a bunch of unit tests which doesn't take args (e.g. test_create_backend_invalid_args). That is the worse because we have not tested anymore for the tests since the commit. This patch fixes to make it tested and more, fix a minor bug for a case that corrupted header incomming to get_metadata. Closes-Bug: #1634403 Change-Id: Ib99a8aa6032f02d0c7d1ab94b8da1ebfd9047d74 --- src/erasurecode.c | 3 ++ test/liberasurecode_test.c | 59 +++++++++++++++++++++++--------------- 2 files changed, 39 insertions(+), 23 deletions(-) diff --git a/src/erasurecode.c b/src/erasurecode.c index 31fc884..33acf26 100644 --- a/src/erasurecode.c +++ b/src/erasurecode.c @@ -1072,6 +1072,9 @@ int is_invalid_fragment_header(fragment_header_t *header) { uint32_t *stored_csum = NULL, csum = 0; assert (NULL != header); + if (header->libec_version == 0) + /* libec_version must be bigger than 0 */ + return 1; if (header->libec_version < _VERSION(1,2,0)) /* no metadata checksum support */ return 0; diff --git a/test/liberasurecode_test.c b/test/liberasurecode_test.c index f71ba89..c94c466 100644 --- a/test/liberasurecode_test.c +++ b/test/liberasurecode_test.c @@ -475,10 +475,11 @@ static void test_backend_available(ec_backend_id_t be_id) { assert(1 == liberasurecode_backend_available(be_id)); } -static void test_backend_available_invalid_args(ec_backend_id_t be_id) +static void test_backend_available_invalid_args() { int ret = liberasurecode_backend_available(EC_BACKENDS_MAX); - assert(ret < 0); + // returns 1 if a backend is available; 0 otherwise + assert(0 == ret); } static void test_create_backend_invalid_args() @@ -640,12 +641,13 @@ static void test_decode_invalid_args() rc = liberasurecode_decode(desc, avail_frags, num_avail_frags, strlen(fake_data), 1, &decoded_data, &decoded_data_len); - // force_metadata_checks results in EINSUFFFRAGS - assert(rc == -EINSUFFFRAGS); + // no metadata headers w/ force_metadata_checks results in EBADHEADER + assert(rc == -EBADHEADER); rc = liberasurecode_decode(desc, avail_frags, num_avail_frags, strlen(fake_data), 0, &decoded_data, &decoded_data_len); + // no metadata headers w/o force_metadata_checks also results in EBADHEADER assert(rc == -EBADHEADER); // test with num_fragments < (k) @@ -810,7 +812,7 @@ static void test_get_fragment_metadata_invalid_args() { memset(frag, 0, 1024); //clears magic rc = liberasurecode_get_fragment_metadata(frag, &metadata); - assert(rc < 0); + assert(rc == -EBADHEADER); free(frag); } @@ -2008,25 +2010,36 @@ int main(int argc, char **argv) int max_backend_tests = max_tests_for_backends(); for (i = 0; i < max_backend_tests; i++) { - for (ii = 0; testcases[ii].description != NULL; ++ii) { - const char *testname = get_name_from_backend_id(testcases[ii].be_id); - fflush(stdout); - if (testcases[ii].skip) { - fprintf(stdout, "ok # SKIP %d - %s: %s (idx=%d)\n", num_cases, - testcases[ii].description, - (testname) ? testname : "", i); - continue; - } - struct ec_args *args = create_ec_args(testcases[ii].be_id, testcases[ii].ct, i); + for (ii = 0; testcases[ii].description != NULL; ++ii) { + const char *testname = get_name_from_backend_id(testcases[ii].be_id); + fflush(stdout); + if (testcases[ii].skip) { + fprintf(stdout, "ok # SKIP %d - %s: %s (idx=%d)\n", num_cases, + testcases[ii].description, + (testname) ? testname : "", i); + continue; + } + if (testcases[ii].be_id == EC_BACKENDS_MAX) { + /* EC_BACKEND_MAX basically designed for invalid args tests + * and not takes the args so call the function w/o args here */ + testcases[ii].function(); + fprintf(stdout, "ok %d - %s: %s (idx=%d)\n", num_cases, + testcases[ii].description, + (testname) ? testname : "", i); + fflush(stdout); + num_cases++; + continue; + } + struct ec_args *args = create_ec_args(testcases[ii].be_id, testcases[ii].ct, i); if (NULL != args) { - testcases[ii].function(testcases[ii].be_id, args); - fprintf(stdout, "ok %d - %s: %s (idx=%d)\n", num_cases, - testcases[ii].description, - (testname) ? testname : "", i); - fflush(stdout); - free(args); - num_cases++; - } + testcases[ii].function(testcases[ii].be_id, args); + fprintf(stdout, "ok %d - %s: %s (idx=%d)\n", num_cases, + testcases[ii].description, + (testname) ? testname : "", i); + fflush(stdout); + free(args); + num_cases++; + } } } return 0;