Fix liberasurecode skipping a bunch of invalid_args tests

Since the commit a01b1818c8,
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
This commit is contained in:
Kota Tsuyuzaki 2016-10-18 02:10:01 -07:00 committed by Pete Zaitcev
parent cb0daba975
commit e8b5a64d8d
2 changed files with 39 additions and 23 deletions

View File

@ -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;

View File

@ -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;