From: Nathan Moinvaziri Date: Thu, 12 Dec 2019 17:51:14 +0000 (-0800) Subject: Added infcover code coverage test executable to cmake test. X-Git-Tag: 1.9.9-b1~364 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=133fa07e9f13f1687b9147055fabe6cf85358bef;p=thirdparty%2Fzlib-ng.git Added infcover code coverage test executable to cmake test. Modified infcover.c to work with zlib-ng. Fixed compiler warnings in infcover.c. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 352a2d1f..dda5178a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -925,6 +925,9 @@ if (ZLIB_ENABLE_TESTS) add_executable(switchlevels test/switchlevels.c) configure_test_executable(switchlevels) + add_executable(infcover test/infcover.c inftrees.c) + configure_test_executable(infcover) + add_executable(makefixed tools/makefixed.c inftrees.c) target_include_directories(makefixed PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) @@ -1078,6 +1081,9 @@ if (ZLIB_ENABLE_TESTS) ${CMAKE_CURRENT_SOURCE_DIR}/crc32.h ${CMAKE_CURRENT_SOURCE_DIR}/crc32._h) + set(INFCOVER_COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} $) + add_test(NAME infcover COMMAND ${CMAKE_COMMAND}) + set(GH_361_COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} $ -4) add_test(NAME GH-361 COMMAND ${CMAKE_COMMAND} diff --git a/test/infcover.c b/test/infcover.c index febbf13d..8d5418ec 100644 --- a/test/infcover.c +++ b/test/infcover.c @@ -9,12 +9,16 @@ #include #include #include -#include "zlib.h" /* get definition of internal structure so we can mess with it (see pull()), and so we can call inflate_trees() (see cover5()) */ #define ZLIB_INTERNAL #include "zbuild.h" +#ifdef ZLIB_COMPAT +# include "zlib.h" +#else +# include "zlib-ng.h" +#endif #include "inftrees.h" #include "inflate.h" @@ -28,7 +32,7 @@ They are used as follows: - z_stream strm; + PREFIX3(stream) strm; mem_setup(&strm) initializes the memory tracking and sets the zalloc, zfree, and opaque members of strm to use memory tracking for all zlib operations on strm @@ -152,7 +156,7 @@ static void mem_free(void *mem, void *ptr) { /* set up a controlled memory allocation space for monitoring, set the stream parameters to the controlled routines, with opaque pointing to the space */ -static void mem_setup(z_stream *strm) { +static void mem_setup(PREFIX3(stream) *strm) { struct mem_zone *zone; zone = malloc(sizeof(struct mem_zone)); @@ -169,28 +173,28 @@ static void mem_setup(z_stream *strm) { } /* set a limit on the total memory allocation, or 0 to remove the limit */ -static void mem_limit(z_stream *strm, size_t limit) { +static void mem_limit(PREFIX3(stream) *strm, size_t limit) { struct mem_zone *zone = strm->opaque; zone->limit = limit; } /* show the current total requested allocations in bytes */ -static void mem_used(z_stream *strm, char *prefix) { +static void mem_used(PREFIX3(stream) *strm, char *prefix) { struct mem_zone *zone = strm->opaque; fprintf(stderr, "%s: %zu allocated\n", prefix, zone->total); } /* show the high water allocation in bytes */ -static void mem_high(z_stream *strm, char *prefix) { +static void mem_high(PREFIX3(stream) *strm, char *prefix) { struct mem_zone *zone = strm->opaque; fprintf(stderr, "%s: %zu high water mark\n", prefix, zone->highwater); } /* release the memory allocation zone -- if there are any surprises, notify */ -static void mem_done(z_stream *strm, char *prefix) { +static void mem_done(PREFIX3(stream) *strm, char *prefix) { int count = 0; struct mem_item *item, *next; struct mem_zone *zone = strm->opaque; @@ -276,13 +280,13 @@ static void inf(char *hex, char *what, unsigned step, int win, unsigned len, int int ret; unsigned have; unsigned char *in, *out; - z_stream strm, copy; - gz_header head; + PREFIX3(stream) strm, copy; + PREFIX(gz_header) head; mem_setup(&strm); strm.avail_in = 0; strm.next_in = NULL; - ret = inflateInit2(&strm, win); + ret = PREFIX(inflateInit2)(&strm, win); if (ret != Z_OK) { mem_done(&strm, what); return; @@ -295,7 +299,8 @@ static void inf(char *hex, char *what, unsigned step, int win, unsigned len, int head.name_max = len; head.comment = out; head.comm_max = len; - ret = inflateGetHeader(&strm, &head); assert(ret == Z_OK); + ret = PREFIX(inflateGetHeader)(&strm, &head); + assert(ret == Z_OK); } in = h2b(hex, &have); assert(in != NULL); if (step == 0 || step > have) @@ -306,23 +311,26 @@ static void inf(char *hex, char *what, unsigned step, int win, unsigned len, int do { strm.avail_out = len; strm.next_out = out; - ret = inflate(&strm, Z_NO_FLUSH); assert(err == 9 || ret == err); + ret = PREFIX(inflate)(&strm, Z_NO_FLUSH); + assert(err == 9 || ret == err); if (ret != Z_OK && ret != Z_BUF_ERROR && ret != Z_NEED_DICT) break; if (ret == Z_NEED_DICT) { - ret = inflateSetDictionary(&strm, in, 1); + ret = PREFIX(inflateSetDictionary)(&strm, in, 1); assert(ret == Z_DATA_ERROR); mem_limit(&strm, 1); - ret = inflateSetDictionary(&strm, out, 0); + ret = PREFIX(inflateSetDictionary)(&strm, out, 0); assert(ret == Z_MEM_ERROR); mem_limit(&strm, 0); ((struct inflate_state *)strm.state)->mode = DICT; - ret = inflateSetDictionary(&strm, out, 0); + ret = PREFIX(inflateSetDictionary)(&strm, out, 0); assert(ret == Z_OK); - ret = inflate(&strm, Z_NO_FLUSH); assert(ret == Z_BUF_ERROR); + ret = PREFIX(inflate)(&strm, Z_NO_FLUSH); + assert(ret == Z_BUF_ERROR); } - ret = inflateCopy(©, &strm); assert(ret == Z_OK); - ret = inflateEnd(©); assert(ret == Z_OK); + ret = PREFIX(inflateCopy)(©, &strm); + assert(ret == Z_OK); + ret = PREFIX(inflateEnd)(©); assert(ret == Z_OK); err = 9; /* don't care next time around */ have += strm.avail_in; strm.avail_in = step > have ? have : step; @@ -330,26 +338,27 @@ static void inf(char *hex, char *what, unsigned step, int win, unsigned len, int } while (strm.avail_in); free(in); free(out); - ret = inflateReset2(&strm, -8); assert(ret == Z_OK); - ret = inflateEnd(&strm); assert(ret == Z_OK); + ret = PREFIX(inflateReset2)(&strm, -8); assert(ret == Z_OK); + ret = PREFIX(inflateEnd)(&strm); assert(ret == Z_OK); mem_done(&strm, what); + (void)err; } /* cover all of the lines in inflate.c up to inflate() */ static void cover_support(void) { int ret; - z_stream strm; + PREFIX3(stream) strm; mem_setup(&strm); strm.avail_in = 0; strm.next_in = NULL; - ret = inflateInit(&strm); assert(ret == Z_OK); + ret = PREFIX(inflateInit)(&strm); assert(ret == Z_OK); mem_used(&strm, "inflate init"); - ret = inflatePrime(&strm, 5, 31); assert(ret == Z_OK); - ret = inflatePrime(&strm, -1, 0); assert(ret == Z_OK); - ret = inflateSetDictionary(&strm, NULL, 0); + ret = PREFIX(inflatePrime)(&strm, 5, 31); assert(ret == Z_OK); + ret = PREFIX(inflatePrime)(&strm, -1, 0); assert(ret == Z_OK); + ret = PREFIX(inflateSetDictionary)(&strm, NULL, 0); assert(ret == Z_STREAM_ERROR); - ret = inflateEnd(&strm); assert(ret == Z_OK); + ret = PREFIX(inflateEnd)(&strm); assert(ret == Z_OK); mem_done(&strm, "prime"); inf("63 0", "force window allocation", 0, -15, 1, Z_OK); @@ -361,26 +370,27 @@ static void cover_support(void) { mem_setup(&strm); strm.avail_in = 0; strm.next_in = NULL; - ret = inflateInit_(&strm, ZLIB_VERSION + 1, (int)sizeof(z_stream)); + ret = PREFIX(inflateInit_)(&strm, PREFIX2(VERSION) + 1, (int)sizeof(PREFIX3(stream))); assert(ret == Z_VERSION_ERROR); mem_done(&strm, "wrong version"); strm.avail_in = 0; strm.next_in = NULL; - ret = inflateInit(&strm); assert(ret == Z_OK); - ret = inflateEnd(&strm); assert(ret == Z_OK); + ret = PREFIX(inflateInit)(&strm); assert(ret == Z_OK); + ret = PREFIX(inflateEnd)(&strm); assert(ret == Z_OK); fputs("inflate built-in memory routines\n", stderr); + (void)ret; } /* cover all inflate() header and trailer cases and code after inflate() */ static void cover_wrap(void) { int ret; - z_stream strm, copy; + PREFIX3(stream) strm, copy; unsigned char dict[257]; - ret = inflate(NULL, 0); assert(ret == Z_STREAM_ERROR); - ret = inflateEnd(NULL); assert(ret == Z_STREAM_ERROR); - ret = inflateCopy(NULL, NULL); assert(ret == Z_STREAM_ERROR); + ret = PREFIX(inflate)(NULL, 0); assert(ret == Z_STREAM_ERROR); + ret = PREFIX(inflateEnd)(NULL); assert(ret == Z_STREAM_ERROR); + ret = PREFIX(inflateCopy)(NULL, NULL); assert(ret == Z_STREAM_ERROR); fputs("inflate bad parameters\n", stderr); inf("1f 8b 0 0", "bad gzip method", 0, 31, 0, Z_DATA_ERROR); @@ -400,33 +410,33 @@ static void cover_wrap(void) { mem_setup(&strm); strm.avail_in = 0; strm.next_in = NULL; - ret = inflateInit2(&strm, -8); + ret = PREFIX(inflateInit2)(&strm, -8); strm.avail_in = 2; strm.next_in = (void *)"\x63"; strm.avail_out = 1; strm.next_out = (void *)&ret; mem_limit(&strm, 1); - ret = inflate(&strm, Z_NO_FLUSH); assert(ret == Z_MEM_ERROR); - ret = inflate(&strm, Z_NO_FLUSH); assert(ret == Z_MEM_ERROR); + ret = PREFIX(inflate)(&strm, Z_NO_FLUSH); assert(ret == Z_MEM_ERROR); + ret = PREFIX(inflate)(&strm, Z_NO_FLUSH); assert(ret == Z_MEM_ERROR); mem_limit(&strm, 0); memset(dict, 0, 257); - ret = inflateSetDictionary(&strm, dict, 257); + ret = PREFIX(inflateSetDictionary)(&strm, dict, 257); assert(ret == Z_OK); mem_limit(&strm, (sizeof(struct inflate_state) << 1) + 256); - ret = inflatePrime(&strm, 16, 0); assert(ret == Z_OK); + ret = PREFIX(inflatePrime)(&strm, 16, 0); assert(ret == Z_OK); strm.avail_in = 2; strm.next_in = (void *)"\x80"; - ret = inflateSync(&strm); assert(ret == Z_DATA_ERROR); - ret = inflate(&strm, Z_NO_FLUSH); assert(ret == Z_STREAM_ERROR); + ret = PREFIX(inflateSync)(&strm); assert(ret == Z_DATA_ERROR); + ret = PREFIX(inflate)(&strm, Z_NO_FLUSH); assert(ret == Z_STREAM_ERROR); strm.avail_in = 4; strm.next_in = (void *)"\0\0\xff\xff"; - ret = inflateSync(&strm); assert(ret == Z_OK); - (void)inflateSyncPoint(&strm); - ret = inflateCopy(©, &strm); assert(ret == Z_MEM_ERROR); + ret = PREFIX(inflateSync)(&strm); assert(ret == Z_OK); + (void)PREFIX(inflateSyncPoint)(&strm); + ret = PREFIX(inflateCopy)(©, &strm); assert(ret == Z_MEM_ERROR); mem_limit(&strm, 0); - ret = inflateUndermine(&strm, 1); assert(ret == Z_DATA_ERROR); - (void)inflateMark(&strm); - ret = inflateEnd(&strm); assert(ret == Z_OK); + ret = PREFIX(inflateUndermine)(&strm, 1); assert(ret == Z_DATA_ERROR); + (void)PREFIX(inflateMark)(&strm); + ret = PREFIX(inflateEnd)(&strm); assert(ret == Z_OK); mem_done(&strm, "miscellaneous, force memory errors"); } @@ -440,7 +450,7 @@ static unsigned pull(void *desc, const unsigned char **buf) { next = 0; return 0; /* no input (already provided at next_in) */ } - state = (void *)((z_stream *)desc)->state; + state = (void *)((PREFIX3(stream) *)desc)->state; if (state != NULL) state->mode = SYNC; /* force an otherwise impossible situation */ return next < sizeof(dat) ? (*buf = dat + next++, 1) : 0; @@ -454,37 +464,41 @@ static int push(void *desc, unsigned char *buf, unsigned len) { /* cover inflateBack() up to common deflate data cases and after those */ static void cover_back(void) { int ret; - z_stream strm; + PREFIX3(stream) strm; unsigned char win[32768]; - ret = inflateBackInit_(NULL, 0, win, 0, 0); + ret = PREFIX(inflateBackInit_)(NULL, 0, win, 0, 0); assert(ret == Z_VERSION_ERROR); - ret = inflateBackInit(NULL, 0, win); assert(ret == Z_STREAM_ERROR); - ret = inflateBack(NULL, NULL, NULL, NULL, NULL); + ret = PREFIX(inflateBackInit)(NULL, 0, win); assert(ret == Z_STREAM_ERROR); - ret = inflateBackEnd(NULL); assert(ret == Z_STREAM_ERROR); + ret = PREFIX(inflateBack)(NULL, NULL, NULL, NULL, NULL); + assert(ret == Z_STREAM_ERROR); + ret = PREFIX(inflateBackEnd)(NULL); assert(ret == Z_STREAM_ERROR); fputs("inflateBack bad parameters\n", stderr); mem_setup(&strm); - ret = inflateBackInit(&strm, 15, win); assert(ret == Z_OK); + ret = PREFIX(inflateBackInit)(&strm, 15, win); + assert(ret == Z_OK); strm.avail_in = 2; strm.next_in = (void *)"\x03"; - ret = inflateBack(&strm, pull, NULL, push, NULL); + ret = PREFIX(inflateBack)(&strm, pull, NULL, push, NULL); assert(ret == Z_STREAM_END); /* force output error */ strm.avail_in = 3; strm.next_in = (void *)"\x63\x00"; - ret = inflateBack(&strm, pull, NULL, push, &strm); + ret = PREFIX(inflateBack)(&strm, pull, NULL, push, &strm); assert(ret == Z_BUF_ERROR); /* force mode error by mucking with state */ - ret = inflateBack(&strm, pull, &strm, push, NULL); + ret = PREFIX(inflateBack)(&strm, pull, &strm, push, NULL); assert(ret == Z_STREAM_ERROR); - ret = inflateBackEnd(&strm); assert(ret == Z_OK); + ret = PREFIX(inflateBackEnd)(&strm); assert(ret == Z_OK); mem_done(&strm, "inflateBack bad state"); - ret = inflateBackInit(&strm, 15, win); assert(ret == Z_OK); - ret = inflateBackEnd(&strm); assert(ret == Z_OK); + ret = PREFIX(inflateBackInit)(&strm, 15, win); + assert(ret == Z_OK); + ret = PREFIX(inflateBackEnd)(&strm); assert(ret == Z_OK); fputs("inflateBack built-in memory routines\n", stderr); + (void)ret; } /* do a raw inflate of data in hexadecimal with both inflate and inflateBack */ @@ -493,7 +507,7 @@ static int try(char *hex, char *id, int err) { unsigned len, size; unsigned char *in, *out, *win; char *prefix; - z_stream strm; + PREFIX3(stream) strm; /* convert to hex */ in = h2b(hex, &len); @@ -514,14 +528,14 @@ static int try(char *hex, char *id, int err) { mem_setup(&strm); strm.avail_in = 0; strm.next_in = NULL; - ret = inflateInit2(&strm, err < 0 ? 47 : -15); + ret = PREFIX(inflateInit2)(&strm, err < 0 ? 47 : -15); assert(ret == Z_OK); strm.avail_in = len; strm.next_in = in; do { strm.avail_out = size; strm.next_out = out; - ret = inflate(&strm, Z_TREES); + ret = PREFIX(inflate)(&strm, Z_TREES); assert(ret != Z_STREAM_ERROR && ret != Z_MEM_ERROR); if (ret == Z_DATA_ERROR || ret == Z_NEED_DICT) break; @@ -530,7 +544,7 @@ static int try(char *hex, char *id, int err) { assert(ret == Z_DATA_ERROR); assert(strcmp(id, strm.msg) == 0); } - inflateEnd(&strm); + PREFIX(inflateEnd)(&strm); mem_done(&strm, prefix); /* then with inflateBack */ @@ -538,17 +552,17 @@ static int try(char *hex, char *id, int err) { strcpy(prefix, id); strcat(prefix, "-back"); mem_setup(&strm); - ret = inflateBackInit(&strm, 15, win); + ret = PREFIX(inflateBackInit)(&strm, 15, win); assert(ret == Z_OK); strm.avail_in = len; strm.next_in = in; - ret = inflateBack(&strm, pull, NULL, push, NULL); + ret = PREFIX(inflateBack)(&strm, pull, NULL, push, NULL); assert(ret != Z_STREAM_ERROR); if (err) { assert(ret == Z_DATA_ERROR); assert(strcmp(id, strm.msg) == 0); } - inflateBackEnd(&strm); + PREFIX(inflateBackEnd)(&strm); mem_done(&strm, prefix); } @@ -609,13 +623,14 @@ static void cover_trees(void) { lens[15] = 15; next = table; bits = 15; - ret = inflate_table(DISTS, lens, 16, &next, &bits, work); + ret = zng_inflate_table(DISTS, lens, 16, &next, &bits, work); assert(ret == 1); next = table; bits = 1; - ret = inflate_table(DISTS, lens, 16, &next, &bits, work); + ret = zng_inflate_table(DISTS, lens, 16, &next, &bits, work); assert(ret == 1); fputs("inflate_table not enough errors\n", stderr); + (void)ret; } /* cover remaining inffast.c decoding and window copying */ @@ -639,7 +654,7 @@ static void cover_fast(void) { } int main(void) { - fprintf(stderr, "%s\n", zlibVersion()); + fprintf(stderr, "%s\n", zVersion()); cover_support(); cover_wrap(); cover_back();