static struct fmap *fmap_create_test(void) { struct fmap *fmap; uint64_t base = 0; uint32_t size = 0x100000; char name[] = "test_fmap"; status = fail; fmap = fmap_create(base, size, (uint8_t *)name); if (!fmap) return NULL; if (memcmp(&fmap->signature, FMAP_SIGNATURE, strlen(FMAP_SIGNATURE))) { printf("FAILURE: signature is incorrect\n"); goto fmap_create_test_exit; } if ((fmap->ver_major != FMAP_VER_MAJOR) || (fmap->ver_minor != FMAP_VER_MINOR)) { printf("FAILURE: version is incorrect\n"); goto fmap_create_test_exit; } if (fmap->base != base) { printf("FAILURE: base is incorrect\n"); goto fmap_create_test_exit; } if (fmap->size != 0x100000) { printf("FAILURE: size is incorrect\n"); goto fmap_create_test_exit; } if (strcmp((char *)fmap->name, "test_fmap")) { printf("FAILURE: name is incorrect\n"); goto fmap_create_test_exit; } if (fmap->nareas != 0) { printf("FAILURE: number of areas is incorrect\n"); goto fmap_create_test_exit; } status = pass; fmap_create_test_exit: /* preserve fmap if all went well */ if (status == fail) { fmap_destroy(fmap); fmap = NULL; } return fmap; }
int fmap_test() { int rc = EXIT_SUCCESS; struct fmap *my_fmap; /* * This test has two parts: Creation of an fmap with one or more * area(s), and other stuff. Since a valid fmap is required to run * many tests, we abort if fmap creation fails in any way. * * Also, fmap_csum_test() makes some assumptions based on the areas * appended. See fmap_append_area_test() for details. */ if ((my_fmap = fmap_create_test()) == NULL) { rc = EXIT_FAILURE; goto fmap_test_exit; } if (fmap_find_test(my_fmap)) { rc = EXIT_FAILURE; goto fmap_test_exit; } if (fmap_append_area_test(&my_fmap)) { rc = EXIT_FAILURE; goto fmap_test_exit; } rc |= fmap_find_area_test(my_fmap); rc |= fmap_get_csum_test(my_fmap); rc |= fmap_size_test(my_fmap); rc |= fmap_flags_to_string_test(); rc |= fmap_print_test(my_fmap); fmap_test_exit: fmap_destroy(my_fmap); if (rc) printf("FAILED\n"); return rc; }