mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-17 16:32:11 +01:00
Add write and read limits to some tests.
This commit is contained in:
1 parent
c1789e0065
commit
fca0cab724
4 files changed
+256
-111
No files matched your search
+28
-7
@@ -16,7 +16,11 @@
|
||||
|
||||
uint32_t global_mimiclib_flate_unused_u32;
|
||||
|
||||
const char* mimic_adler32(puffs_base_buf1* dst, puffs_base_buf1* src) {
|
||||
const char* mimic_adler32(puffs_base_buf1* dst,
|
||||
puffs_base_buf1* src,
|
||||
uint64_t wlimit,
|
||||
uint64_t rlimit) {
|
||||
// TODO: don't ignore wlimit and rlimit.
|
||||
uint8_t* ptr = src->ptr + src->ri;
|
||||
size_t len = src->wi - src->ri;
|
||||
if (len > 0x7FFFFFFF) {
|
||||
@@ -27,7 +31,11 @@ const char* mimic_adler32(puffs_base_buf1* dst, puffs_base_buf1* src) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* mimic_crc32(puffs_base_buf1* dst, puffs_base_buf1* src) {
|
||||
const char* mimic_crc32(puffs_base_buf1* dst,
|
||||
puffs_base_buf1* src,
|
||||
uint64_t wlimit,
|
||||
uint64_t rlimit) {
|
||||
// TODO: don't ignore wlimit and rlimit.
|
||||
uint8_t* ptr = src->ptr + src->ri;
|
||||
size_t len = src->wi - src->ri;
|
||||
if (len > 0x7FFFFFFF) {
|
||||
@@ -55,7 +63,11 @@ int mimic_flate_write_func(void* ctx, unsigned char* ptr, unsigned int len) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char* mimic_flate_decode(puffs_base_buf1* dst, puffs_base_buf1* src) {
|
||||
const char* mimic_flate_decode(puffs_base_buf1* dst,
|
||||
puffs_base_buf1* src,
|
||||
uint64_t wlimit,
|
||||
uint64_t rlimit) {
|
||||
// TODO: don't ignore wlimit and rlimit.
|
||||
const char* ret = NULL;
|
||||
uint8_t window[32 * 1024];
|
||||
|
||||
@@ -94,7 +106,10 @@ cleanup0:;
|
||||
|
||||
const char* mimic_gzip_zlib_decode(puffs_base_buf1* dst,
|
||||
puffs_base_buf1* src,
|
||||
uint64_t wlimit,
|
||||
uint64_t rlimit,
|
||||
bool gzip_instead_of_zlib) {
|
||||
// TODO: don't ignore wlimit and rlimit.
|
||||
const char* ret = NULL;
|
||||
|
||||
z_stream z = {0};
|
||||
@@ -147,10 +162,16 @@ cleanup0:;
|
||||
return ret;
|
||||
}
|
||||
|
||||
const char* mimic_gzip_decode(puffs_base_buf1* dst, puffs_base_buf1* src) {
|
||||
return mimic_gzip_zlib_decode(dst, src, true);
|
||||
const char* mimic_gzip_decode(puffs_base_buf1* dst,
|
||||
puffs_base_buf1* src,
|
||||
uint64_t wlimit,
|
||||
uint64_t rlimit) {
|
||||
return mimic_gzip_zlib_decode(dst, src, wlimit, rlimit, true);
|
||||
}
|
||||
|
||||
const char* mimic_zlib_decode(puffs_base_buf1* dst, puffs_base_buf1* src) {
|
||||
return mimic_gzip_zlib_decode(dst, src, false);
|
||||
const char* mimic_zlib_decode(puffs_base_buf1* dst,
|
||||
puffs_base_buf1* src,
|
||||
uint64_t wlimit,
|
||||
uint64_t rlimit) {
|
||||
return mimic_gzip_zlib_decode(dst, src, wlimit, rlimit, false);
|
||||
}
|
||||
+103
-40
@@ -113,55 +113,109 @@ golden_test zlib_pi_gt = {
|
||||
|
||||
// ---------------- Flate Tests
|
||||
|
||||
const char* puffs_flate_decode(puffs_base_buf1* dst, puffs_base_buf1* src) {
|
||||
const char* puffs_flate_decode(puffs_base_buf1* dst,
|
||||
puffs_base_buf1* src,
|
||||
uint64_t wlimit,
|
||||
uint64_t rlimit) {
|
||||
puffs_flate_decoder dec;
|
||||
puffs_flate_decoder_initialize(&dec, PUFFS_VERSION, 0);
|
||||
puffs_base_writer1 dst_writer = {.buf = dst};
|
||||
puffs_base_reader1 src_reader = {.buf = src};
|
||||
puffs_flate_status s =
|
||||
puffs_flate_decoder_decode(&dec, dst_writer, src_reader);
|
||||
if (s) {
|
||||
while (true) {
|
||||
uint64_t wlim = wlimit;
|
||||
if (wlimit) {
|
||||
dst_writer.limit.ptr_to_len = &wlim;
|
||||
}
|
||||
uint64_t rlim = rlimit;
|
||||
if (rlimit) {
|
||||
src_reader.limit.ptr_to_len = &rlim;
|
||||
}
|
||||
|
||||
puffs_flate_status s =
|
||||
puffs_flate_decoder_decode(&dec, dst_writer, src_reader);
|
||||
|
||||
if (s == PUFFS_FLATE_STATUS_OK) {
|
||||
return NULL;
|
||||
}
|
||||
if ((wlimit && (s == PUFFS_FLATE_SUSPENSION_SHORT_WRITE)) ||
|
||||
(rlimit && (s == PUFFS_FLATE_SUSPENSION_SHORT_READ))) {
|
||||
continue;
|
||||
}
|
||||
return puffs_flate_status_string(s);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* puffs_zlib_decode(puffs_base_buf1* dst, puffs_base_buf1* src) {
|
||||
const char* puffs_zlib_decode(puffs_base_buf1* dst,
|
||||
puffs_base_buf1* src,
|
||||
uint64_t wlimit,
|
||||
uint64_t rlimit) {
|
||||
puffs_flate_zlib_decoder dec;
|
||||
puffs_flate_zlib_decoder_initialize(&dec, PUFFS_VERSION, 0);
|
||||
puffs_base_writer1 dst_writer = {.buf = dst};
|
||||
puffs_base_reader1 src_reader = {.buf = src};
|
||||
puffs_flate_status s =
|
||||
puffs_flate_zlib_decoder_decode(&dec, dst_writer, src_reader);
|
||||
if (s) {
|
||||
|
||||
while (true) {
|
||||
uint64_t wlim = wlimit;
|
||||
if (wlimit) {
|
||||
dst_writer.limit.ptr_to_len = &wlim;
|
||||
}
|
||||
uint64_t rlim = rlimit;
|
||||
if (rlimit) {
|
||||
src_reader.limit.ptr_to_len = &rlim;
|
||||
}
|
||||
|
||||
puffs_flate_status s =
|
||||
puffs_flate_zlib_decoder_decode(&dec, dst_writer, src_reader);
|
||||
|
||||
if (s == PUFFS_FLATE_STATUS_OK) {
|
||||
return NULL;
|
||||
}
|
||||
if ((wlimit && (s == PUFFS_FLATE_SUSPENSION_SHORT_WRITE)) ||
|
||||
(rlimit && (s == PUFFS_FLATE_SUSPENSION_SHORT_READ))) {
|
||||
continue;
|
||||
}
|
||||
return puffs_flate_status_string(s);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void test_puffs_flate_decode_256_bytes() {
|
||||
proc_funcname = __func__;
|
||||
do_test_buf1_buf1(puffs_flate_decode, &flate_256_bytes_gt);
|
||||
do_test_buf1_buf1(puffs_flate_decode, &flate_256_bytes_gt, 0, 0);
|
||||
}
|
||||
|
||||
void test_puffs_flate_decode_midsummer() {
|
||||
proc_funcname = __func__;
|
||||
do_test_buf1_buf1(puffs_flate_decode, &flate_midsummer_gt);
|
||||
do_test_buf1_buf1(puffs_flate_decode, &flate_midsummer_gt, 0, 0);
|
||||
}
|
||||
|
||||
void test_puffs_flate_decode_pi() {
|
||||
proc_funcname = __func__;
|
||||
do_test_buf1_buf1(puffs_flate_decode, &flate_pi_gt);
|
||||
do_test_buf1_buf1(puffs_flate_decode, &flate_pi_gt, 0, 0);
|
||||
}
|
||||
|
||||
void test_puffs_flate_decode_pi_many_big_reads() {
|
||||
proc_funcname = __func__;
|
||||
do_test_buf1_buf1(puffs_flate_decode, &flate_pi_gt, 0, 4096);
|
||||
}
|
||||
|
||||
void test_puffs_flate_decode_pi_many_medium_reads() {
|
||||
proc_funcname = __func__;
|
||||
do_test_buf1_buf1(puffs_flate_decode, &flate_pi_gt, 0, 599);
|
||||
}
|
||||
|
||||
void test_puffs_flate_decode_pi_many_small_writes_reads() {
|
||||
proc_funcname = __func__;
|
||||
do_test_buf1_buf1(puffs_flate_decode, &flate_pi_gt, 59, 61);
|
||||
}
|
||||
|
||||
void test_puffs_flate_decode_romeo() {
|
||||
proc_funcname = __func__;
|
||||
do_test_buf1_buf1(puffs_flate_decode, &flate_romeo_gt);
|
||||
do_test_buf1_buf1(puffs_flate_decode, &flate_romeo_gt, 0, 0);
|
||||
}
|
||||
|
||||
void test_puffs_flate_decode_romeo_fixed() {
|
||||
proc_funcname = __func__;
|
||||
do_test_buf1_buf1(puffs_flate_decode, &flate_romeo_fixed_gt);
|
||||
do_test_buf1_buf1(puffs_flate_decode, &flate_romeo_fixed_gt, 0, 0);
|
||||
}
|
||||
|
||||
void test_puffs_flate_decode_split_src() {
|
||||
@@ -509,12 +563,12 @@ void test_puffs_flate_table_redirect() {
|
||||
|
||||
void test_puffs_zlib_decode_midsummer() {
|
||||
proc_funcname = __func__;
|
||||
do_test_buf1_buf1(puffs_zlib_decode, &zlib_midsummer_gt);
|
||||
do_test_buf1_buf1(puffs_zlib_decode, &zlib_midsummer_gt, 0, 0);
|
||||
}
|
||||
|
||||
void test_puffs_zlib_decode_pi() {
|
||||
proc_funcname = __func__;
|
||||
do_test_buf1_buf1(puffs_zlib_decode, &zlib_pi_gt);
|
||||
do_test_buf1_buf1(puffs_zlib_decode, &zlib_pi_gt, 0, 0);
|
||||
}
|
||||
|
||||
// ---------------- Mimic Tests
|
||||
@@ -525,47 +579,47 @@ void test_puffs_zlib_decode_pi() {
|
||||
|
||||
void test_mimic_flate_decode_256_bytes() {
|
||||
proc_funcname = __func__;
|
||||
do_test_buf1_buf1(mimic_flate_decode, &flate_256_bytes_gt);
|
||||
do_test_buf1_buf1(mimic_flate_decode, &flate_256_bytes_gt, 0, 0);
|
||||
}
|
||||
|
||||
void test_mimic_flate_decode_midsummer() {
|
||||
proc_funcname = __func__;
|
||||
do_test_buf1_buf1(mimic_flate_decode, &flate_midsummer_gt);
|
||||
do_test_buf1_buf1(mimic_flate_decode, &flate_midsummer_gt, 0, 0);
|
||||
}
|
||||
|
||||
void test_mimic_flate_decode_pi() {
|
||||
proc_funcname = __func__;
|
||||
do_test_buf1_buf1(mimic_flate_decode, &flate_pi_gt);
|
||||
do_test_buf1_buf1(mimic_flate_decode, &flate_pi_gt, 0, 0);
|
||||
}
|
||||
|
||||
void test_mimic_flate_decode_romeo() {
|
||||
proc_funcname = __func__;
|
||||
do_test_buf1_buf1(mimic_flate_decode, &flate_romeo_gt);
|
||||
do_test_buf1_buf1(mimic_flate_decode, &flate_romeo_gt, 0, 0);
|
||||
}
|
||||
|
||||
void test_mimic_flate_decode_romeo_fixed() {
|
||||
proc_funcname = __func__;
|
||||
do_test_buf1_buf1(mimic_flate_decode, &flate_romeo_fixed_gt);
|
||||
do_test_buf1_buf1(mimic_flate_decode, &flate_romeo_fixed_gt, 0, 0);
|
||||
}
|
||||
|
||||
void test_mimic_gzip_decode_midsummer() {
|
||||
proc_funcname = __func__;
|
||||
do_test_buf1_buf1(mimic_gzip_decode, &gzip_midsummer_gt);
|
||||
do_test_buf1_buf1(mimic_gzip_decode, &gzip_midsummer_gt, 0, 0);
|
||||
}
|
||||
|
||||
void test_mimic_gzip_decode_pi() {
|
||||
proc_funcname = __func__;
|
||||
do_test_buf1_buf1(mimic_gzip_decode, &gzip_pi_gt);
|
||||
do_test_buf1_buf1(mimic_gzip_decode, &gzip_pi_gt, 0, 0);
|
||||
}
|
||||
|
||||
void test_mimic_zlib_decode_midsummer() {
|
||||
proc_funcname = __func__;
|
||||
do_test_buf1_buf1(mimic_zlib_decode, &zlib_midsummer_gt);
|
||||
do_test_buf1_buf1(mimic_zlib_decode, &zlib_midsummer_gt, 0, 0);
|
||||
}
|
||||
|
||||
void test_mimic_zlib_decode_pi() {
|
||||
proc_funcname = __func__;
|
||||
do_test_buf1_buf1(mimic_zlib_decode, &zlib_pi_gt);
|
||||
do_test_buf1_buf1(mimic_zlib_decode, &zlib_pi_gt, 0, 0);
|
||||
}
|
||||
|
||||
#endif // PUFFS_MIMIC
|
||||
@@ -574,17 +628,18 @@ void test_mimic_zlib_decode_pi() {
|
||||
|
||||
void bench_puffs_flate_decode_1k() {
|
||||
proc_funcname = __func__;
|
||||
do_bench_buf1_buf1(puffs_flate_decode, tc_dst, &flate_romeo_gt, 200000);
|
||||
do_bench_buf1_buf1(puffs_flate_decode, tc_dst, &flate_romeo_gt, 0, 0, 200000);
|
||||
}
|
||||
|
||||
void bench_puffs_flate_decode_10k() {
|
||||
proc_funcname = __func__;
|
||||
do_bench_buf1_buf1(puffs_flate_decode, tc_dst, &flate_midsummer_gt, 30000);
|
||||
do_bench_buf1_buf1(puffs_flate_decode, tc_dst, &flate_midsummer_gt, 0, 0,
|
||||
30000);
|
||||
}
|
||||
|
||||
void bench_puffs_flate_decode_100k() {
|
||||
proc_funcname = __func__;
|
||||
do_bench_buf1_buf1(puffs_flate_decode, tc_dst, &flate_pi_gt, 3000);
|
||||
do_bench_buf1_buf1(puffs_flate_decode, tc_dst, &flate_pi_gt, 0, 0, 3000);
|
||||
}
|
||||
|
||||
// ---------------- Mimic Benches
|
||||
@@ -593,57 +648,61 @@ void bench_puffs_flate_decode_100k() {
|
||||
|
||||
void bench_mimic_adler32_10k() {
|
||||
proc_funcname = __func__;
|
||||
do_bench_buf1_buf1(mimic_adler32, tc_src, &checksum_midsummer_gt, 30000);
|
||||
do_bench_buf1_buf1(mimic_adler32, tc_src, &checksum_midsummer_gt, 0, 0,
|
||||
30000);
|
||||
}
|
||||
|
||||
void bench_mimic_adler32_100k() {
|
||||
proc_funcname = __func__;
|
||||
do_bench_buf1_buf1(mimic_adler32, tc_src, &checksum_pi_gt, 3000);
|
||||
do_bench_buf1_buf1(mimic_adler32, tc_src, &checksum_pi_gt, 0, 0, 3000);
|
||||
}
|
||||
|
||||
void bench_mimic_crc32_10k() {
|
||||
proc_funcname = __func__;
|
||||
do_bench_buf1_buf1(mimic_crc32, tc_src, &checksum_midsummer_gt, 30000);
|
||||
do_bench_buf1_buf1(mimic_crc32, tc_src, &checksum_midsummer_gt, 0, 0, 30000);
|
||||
}
|
||||
|
||||
void bench_mimic_crc32_100k() {
|
||||
proc_funcname = __func__;
|
||||
do_bench_buf1_buf1(mimic_crc32, tc_src, &checksum_pi_gt, 3000);
|
||||
do_bench_buf1_buf1(mimic_crc32, tc_src, &checksum_pi_gt, 0, 0, 3000);
|
||||
}
|
||||
|
||||
void bench_mimic_flate_decode_1k() {
|
||||
proc_funcname = __func__;
|
||||
do_bench_buf1_buf1(mimic_flate_decode, tc_dst, &flate_romeo_gt, 200000);
|
||||
do_bench_buf1_buf1(mimic_flate_decode, tc_dst, &flate_romeo_gt, 0, 0, 200000);
|
||||
}
|
||||
|
||||
void bench_mimic_flate_decode_10k() {
|
||||
proc_funcname = __func__;
|
||||
do_bench_buf1_buf1(mimic_flate_decode, tc_dst, &flate_midsummer_gt, 30000);
|
||||
do_bench_buf1_buf1(mimic_flate_decode, tc_dst, &flate_midsummer_gt, 0, 0,
|
||||
30000);
|
||||
}
|
||||
|
||||
void bench_mimic_flate_decode_100k() {
|
||||
proc_funcname = __func__;
|
||||
do_bench_buf1_buf1(mimic_flate_decode, tc_dst, &flate_pi_gt, 3000);
|
||||
do_bench_buf1_buf1(mimic_flate_decode, tc_dst, &flate_pi_gt, 0, 0, 3000);
|
||||
}
|
||||
|
||||
void bench_mimic_gzip_decode_10k() {
|
||||
proc_funcname = __func__;
|
||||
do_bench_buf1_buf1(mimic_gzip_decode, tc_dst, &gzip_midsummer_gt, 30000);
|
||||
do_bench_buf1_buf1(mimic_gzip_decode, tc_dst, &gzip_midsummer_gt, 0, 0,
|
||||
30000);
|
||||
}
|
||||
|
||||
void bench_mimic_gzip_decode_100k() {
|
||||
proc_funcname = __func__;
|
||||
do_bench_buf1_buf1(mimic_gzip_decode, tc_dst, &gzip_pi_gt, 3000);
|
||||
do_bench_buf1_buf1(mimic_gzip_decode, tc_dst, &gzip_pi_gt, 0, 0, 3000);
|
||||
}
|
||||
|
||||
void bench_mimic_zlib_decode_10k() {
|
||||
proc_funcname = __func__;
|
||||
do_bench_buf1_buf1(mimic_zlib_decode, tc_dst, &zlib_midsummer_gt, 30000);
|
||||
do_bench_buf1_buf1(mimic_zlib_decode, tc_dst, &zlib_midsummer_gt, 0, 0,
|
||||
30000);
|
||||
}
|
||||
|
||||
void bench_mimic_zlib_decode_100k() {
|
||||
proc_funcname = __func__;
|
||||
do_bench_buf1_buf1(mimic_zlib_decode, tc_dst, &zlib_pi_gt, 3000);
|
||||
do_bench_buf1_buf1(mimic_zlib_decode, tc_dst, &zlib_pi_gt, 0, 0, 3000);
|
||||
}
|
||||
|
||||
#endif // PUFFS_MIMIC
|
||||
@@ -656,6 +715,10 @@ proc tests[] = {
|
||||
test_puffs_flate_decode_256_bytes, //
|
||||
test_puffs_flate_decode_midsummer, //
|
||||
test_puffs_flate_decode_pi, //
|
||||
// TODO: uncomment.
|
||||
// test_puffs_flate_decode_pi_many_big_reads, //
|
||||
// test_puffs_flate_decode_pi_many_medium_reads, //
|
||||
// test_puffs_flate_decode_pi_many_small_writes_reads, //
|
||||
test_puffs_flate_decode_romeo, //
|
||||
test_puffs_flate_decode_romeo_fixed, //
|
||||
test_puffs_flate_decode_split_src, //
|
||||
|
||||
+106
-57
@@ -195,7 +195,8 @@ bool do_test_puffs_gif_lzw_decode(const char* src_filename,
|
||||
uint64_t src_size,
|
||||
const char* want_filename,
|
||||
uint64_t want_size,
|
||||
uint64_t limit) {
|
||||
uint64_t wlimit,
|
||||
uint64_t rlimit) {
|
||||
puffs_base_buf1 got = {.ptr = global_got_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base_buf1 want = {.ptr = global_want_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base_buf1 src = {.ptr = global_src_buffer, .len = BUFFER_SIZE};
|
||||
@@ -231,37 +232,53 @@ bool do_test_puffs_gif_lzw_decode(const char* src_filename,
|
||||
int num_iters = 0;
|
||||
while (true) {
|
||||
num_iters++;
|
||||
uint64_t lim = limit;
|
||||
src_reader.limit.ptr_to_len = &lim;
|
||||
uint64_t wlim = wlimit;
|
||||
if (wlimit) {
|
||||
got_writer.limit.ptr_to_len = &wlim;
|
||||
}
|
||||
uint64_t rlim = rlimit;
|
||||
if (rlimit) {
|
||||
src_reader.limit.ptr_to_len = &rlim;
|
||||
}
|
||||
size_t old_wi = got.wi;
|
||||
size_t old_ri = src.ri;
|
||||
|
||||
puffs_gif_status status =
|
||||
puffs_gif_lzw_decoder_decode(&dec, got_writer, src_reader);
|
||||
if (src.ri == src.wi) {
|
||||
if (status != PUFFS_GIF_STATUS_OK) {
|
||||
FAIL("status: got %" PRIi32 " (%s), want %" PRIi32 " (%s)", status,
|
||||
puffs_gif_status_string(status), PUFFS_GIF_STATUS_OK,
|
||||
puffs_gif_status_string(PUFFS_GIF_STATUS_OK));
|
||||
if (status == PUFFS_GIF_STATUS_OK) {
|
||||
if (src.ri != src.wi) {
|
||||
FAIL("decode returned ok but src was not exhausted");
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (status != PUFFS_GIF_SUSPENSION_SHORT_READ) {
|
||||
FAIL("status: got %" PRIi32 " (%s), want %" PRIi32 " (%s)", status,
|
||||
puffs_gif_status_string(status), PUFFS_GIF_SUSPENSION_SHORT_READ,
|
||||
puffs_gif_status_string(PUFFS_GIF_SUSPENSION_SHORT_READ));
|
||||
if ((status != PUFFS_GIF_SUSPENSION_SHORT_READ) &&
|
||||
(status != PUFFS_GIF_SUSPENSION_SHORT_WRITE)) {
|
||||
FAIL("status: got %" PRIi32 " (%s), want %" PRIi32 " (%s) or %" PRIi32
|
||||
" (%s)",
|
||||
status, puffs_gif_status_string(status),
|
||||
PUFFS_GIF_SUSPENSION_SHORT_READ,
|
||||
puffs_gif_status_string(PUFFS_GIF_SUSPENSION_SHORT_READ),
|
||||
PUFFS_GIF_SUSPENSION_SHORT_WRITE,
|
||||
puffs_gif_status_string(PUFFS_GIF_SUSPENSION_SHORT_WRITE));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (got.wi < old_wi) {
|
||||
FAIL("write index got.wi went backwards");
|
||||
return false;
|
||||
}
|
||||
if (src.ri < old_ri) {
|
||||
FAIL("read index src.ri went backwards");
|
||||
return false;
|
||||
}
|
||||
if (src.ri == old_ri) {
|
||||
if ((got.wi == old_wi) && (src.ri == old_ri)) {
|
||||
FAIL("no progress was made");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (limit < 1000000) {
|
||||
if (wlimit || rlimit) {
|
||||
if (num_iters <= 1) {
|
||||
FAIL("num_iters: got %d, want > 1", num_iters);
|
||||
return false;
|
||||
@@ -276,38 +293,38 @@ bool do_test_puffs_gif_lzw_decode(const char* src_filename,
|
||||
return buf1s_equal("", &got, &want);
|
||||
}
|
||||
|
||||
void test_puffs_gif_lzw_decode_few_big_reads() {
|
||||
void test_puffs_gif_lzw_decode_many_big_reads() {
|
||||
proc_funcname = __func__;
|
||||
do_test_puffs_gif_lzw_decode("../../testdata/bricks-gray.indexes.giflzw",
|
||||
14731, "../../testdata/bricks-gray.indexes",
|
||||
19200, 1 << 30);
|
||||
19200, 0, 4096);
|
||||
}
|
||||
|
||||
void test_puffs_gif_lzw_decode_many_small_reads() {
|
||||
void test_puffs_gif_lzw_decode_many_small_writes_reads() {
|
||||
proc_funcname = __func__;
|
||||
do_test_puffs_gif_lzw_decode("../../testdata/bricks-gray.indexes.giflzw",
|
||||
14731, "../../testdata/bricks-gray.indexes",
|
||||
19200, 100);
|
||||
19200, 41, 43);
|
||||
}
|
||||
|
||||
void test_puffs_gif_lzw_decode_bricks_dither() {
|
||||
proc_funcname = __func__;
|
||||
do_test_puffs_gif_lzw_decode("../../testdata/bricks-dither.indexes.giflzw",
|
||||
14923, "../../testdata/bricks-dither.indexes",
|
||||
19200, 1 << 30);
|
||||
19200, 0, 0);
|
||||
}
|
||||
|
||||
void test_puffs_gif_lzw_decode_bricks_nodither() {
|
||||
proc_funcname = __func__;
|
||||
do_test_puffs_gif_lzw_decode("../../testdata/bricks-nodither.indexes.giflzw",
|
||||
13382, "../../testdata/bricks-nodither.indexes",
|
||||
19200, 1 << 30);
|
||||
19200, 0, 0);
|
||||
}
|
||||
|
||||
void test_puffs_gif_lzw_decode_pi() {
|
||||
proc_funcname = __func__;
|
||||
do_test_puffs_gif_lzw_decode("../../testdata/pi.txt.giflzw", 50550,
|
||||
"../../testdata/pi.txt", 100003, 1 << 30);
|
||||
"../../testdata/pi.txt", 100003, 0, 0);
|
||||
}
|
||||
|
||||
// ---------------- LZW Benches
|
||||
@@ -379,8 +396,9 @@ const char* puffs_gif_decode(puffs_base_buf1* dst, puffs_base_buf1* src) {
|
||||
bool do_test_puffs_gif_decode(const char* filename,
|
||||
const char* palette_filename,
|
||||
const char* indexes_filename,
|
||||
puffs_gif_status want,
|
||||
uint64_t limit) {
|
||||
puffs_gif_status want_status, // TODO: delete.
|
||||
uint64_t wlimit,
|
||||
uint64_t rlimit) {
|
||||
puffs_base_buf1 got = {.ptr = global_got_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base_buf1 src = {.ptr = global_src_buffer, .len = BUFFER_SIZE};
|
||||
|
||||
@@ -395,40 +413,62 @@ bool do_test_puffs_gif_decode(const char* filename,
|
||||
int num_iters = 0;
|
||||
while (true) {
|
||||
num_iters++;
|
||||
uint64_t lim = limit;
|
||||
src_reader.limit.ptr_to_len = &lim;
|
||||
uint64_t wlim = wlimit;
|
||||
if (wlimit) {
|
||||
got_writer.limit.ptr_to_len = &wlim;
|
||||
}
|
||||
uint64_t rlim = rlimit;
|
||||
if (rlimit) {
|
||||
src_reader.limit.ptr_to_len = &rlim;
|
||||
}
|
||||
size_t old_wi = got.wi;
|
||||
size_t old_ri = src.ri;
|
||||
puffs_gif_status got =
|
||||
|
||||
puffs_gif_status status =
|
||||
puffs_gif_decoder_decode(&dec, got_writer, src_reader);
|
||||
if ((src.ri == src.wi) || puffs_gif_status_is_error(got)) {
|
||||
if (got != want) {
|
||||
FAIL("status: got %" PRIi32 " (%s), want %" PRIi32 " (%s)", got,
|
||||
puffs_gif_status_string(got), want, puffs_gif_status_string(want));
|
||||
if (want_status != PUFFS_GIF_STATUS_OK) {
|
||||
if (status != want_status) {
|
||||
FAIL("status: got %" PRIi32 " (%s), want %" PRIi32 " (%s)", status,
|
||||
puffs_gif_status_string(status), want_status,
|
||||
puffs_gif_status_string(want_status));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (status == PUFFS_GIF_STATUS_OK) {
|
||||
if (src.ri != src.wi) {
|
||||
FAIL("decode returned ok but src was not exhausted");
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (got != PUFFS_GIF_SUSPENSION_SHORT_READ) {
|
||||
FAIL("status: got %" PRIi32 " (%s), want %" PRIi32 " (%s)", got,
|
||||
puffs_gif_status_string(got), PUFFS_GIF_SUSPENSION_SHORT_READ,
|
||||
puffs_gif_status_string(PUFFS_GIF_SUSPENSION_SHORT_READ));
|
||||
if ((status != PUFFS_GIF_SUSPENSION_SHORT_READ) &&
|
||||
(status != PUFFS_GIF_SUSPENSION_SHORT_WRITE)) {
|
||||
FAIL("status: got %" PRIi32 " (%s), want %" PRIi32 " (%s) or %" PRIi32
|
||||
" (%s)",
|
||||
status, puffs_gif_status_string(status),
|
||||
PUFFS_GIF_SUSPENSION_SHORT_READ,
|
||||
puffs_gif_status_string(PUFFS_GIF_SUSPENSION_SHORT_READ),
|
||||
PUFFS_GIF_SUSPENSION_SHORT_WRITE,
|
||||
puffs_gif_status_string(PUFFS_GIF_SUSPENSION_SHORT_WRITE));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (got.wi < old_wi) {
|
||||
FAIL("write index got.wi went backwards");
|
||||
return false;
|
||||
}
|
||||
if (src.ri < old_ri) {
|
||||
FAIL("read index src.ri went backwards");
|
||||
return false;
|
||||
}
|
||||
if (src.ri == old_ri) {
|
||||
if ((got.wi == old_wi) && (src.ri == old_ri)) {
|
||||
FAIL("no progress was made");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (want != PUFFS_GIF_STATUS_OK) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (limit < 1000000) {
|
||||
if (wlimit || rlimit) {
|
||||
if (num_iters <= 1) {
|
||||
FAIL("num_iters: got %d, want > 1", num_iters);
|
||||
return false;
|
||||
@@ -468,12 +508,20 @@ bool do_test_puffs_gif_decode(const char* filename,
|
||||
return buf1s_equal("indexes ", &got, &ind_want);
|
||||
}
|
||||
|
||||
void test_puffs_gif_decode_input_is_a_gif_few_big_reads() {
|
||||
void test_puffs_gif_decode_input_is_a_gif() {
|
||||
proc_funcname = __func__;
|
||||
do_test_puffs_gif_decode("../../testdata/bricks-dither.gif",
|
||||
"../../testdata/bricks-dither.palette",
|
||||
"../../testdata/bricks-dither.indexes",
|
||||
PUFFS_GIF_STATUS_OK, 1 << 30);
|
||||
PUFFS_GIF_STATUS_OK, 0, 0);
|
||||
}
|
||||
|
||||
void test_puffs_gif_decode_input_is_a_gif_many_big_reads() {
|
||||
proc_funcname = __func__;
|
||||
do_test_puffs_gif_decode("../../testdata/bricks-dither.gif",
|
||||
"../../testdata/bricks-dither.palette",
|
||||
"../../testdata/bricks-dither.indexes",
|
||||
PUFFS_GIF_STATUS_OK, 0, 4096);
|
||||
}
|
||||
|
||||
void test_puffs_gif_decode_input_is_a_gif_many_medium_reads() {
|
||||
@@ -481,23 +529,23 @@ void test_puffs_gif_decode_input_is_a_gif_many_medium_reads() {
|
||||
do_test_puffs_gif_decode("../../testdata/bricks-dither.gif",
|
||||
"../../testdata/bricks-dither.palette",
|
||||
"../../testdata/bricks-dither.indexes",
|
||||
PUFFS_GIF_STATUS_OK, 4096);
|
||||
PUFFS_GIF_STATUS_OK, 0,
|
||||
787); // 787 tickles being in the middle of a
|
||||
// decode_extension skip32 call.
|
||||
}
|
||||
|
||||
void test_puffs_gif_decode_input_is_a_gif_many_small_reads() {
|
||||
void test_puffs_gif_decode_input_is_a_gif_many_small_writes_reads() {
|
||||
proc_funcname = __func__;
|
||||
do_test_puffs_gif_decode("../../testdata/bricks-dither.gif",
|
||||
"../../testdata/bricks-dither.palette",
|
||||
"../../testdata/bricks-dither.indexes",
|
||||
PUFFS_GIF_STATUS_OK,
|
||||
787); // 787 tickles being in the middle of a
|
||||
// decode_extension skip32 call.
|
||||
PUFFS_GIF_STATUS_OK, 11, 13);
|
||||
}
|
||||
|
||||
void test_puffs_gif_decode_input_is_a_png() {
|
||||
proc_funcname = __func__;
|
||||
do_test_puffs_gif_decode("../../testdata/bricks-dither.png", "", "",
|
||||
PUFFS_GIF_ERROR_BAD_GIF_HEADER, 1 << 30);
|
||||
PUFFS_GIF_ERROR_BAD_GIF_HEADER, 0, 0);
|
||||
}
|
||||
|
||||
// ---------------- Mimic Tests
|
||||
@@ -667,17 +715,18 @@ proc tests[] = {
|
||||
test_basic_sub_struct_initializer, //
|
||||
|
||||
// LZW Tests
|
||||
test_puffs_gif_lzw_decode_few_big_reads, //
|
||||
test_puffs_gif_lzw_decode_many_small_reads, //
|
||||
test_puffs_gif_lzw_decode_bricks_dither, //
|
||||
test_puffs_gif_lzw_decode_bricks_nodither, //
|
||||
test_puffs_gif_lzw_decode_pi, //
|
||||
test_puffs_gif_lzw_decode_many_big_reads, //
|
||||
test_puffs_gif_lzw_decode_many_small_writes_reads, //
|
||||
test_puffs_gif_lzw_decode_bricks_dither, //
|
||||
test_puffs_gif_lzw_decode_bricks_nodither, //
|
||||
test_puffs_gif_lzw_decode_pi, //
|
||||
|
||||
// GIF Tests
|
||||
test_puffs_gif_decode_input_is_a_gif_few_big_reads, //
|
||||
test_puffs_gif_decode_input_is_a_gif_many_medium_reads, //
|
||||
test_puffs_gif_decode_input_is_a_gif_many_small_reads, //
|
||||
test_puffs_gif_decode_input_is_a_png, //
|
||||
test_puffs_gif_decode_input_is_a_gif, //
|
||||
test_puffs_gif_decode_input_is_a_gif_many_big_reads, //
|
||||
test_puffs_gif_decode_input_is_a_gif_many_medium_reads, //
|
||||
test_puffs_gif_decode_input_is_a_gif_many_small_writes_reads, //
|
||||
test_puffs_gif_decode_input_is_a_png, //
|
||||
|
||||
#ifdef PUFFS_MIMIC
|
||||
|
||||
|
||||
@@ -329,9 +329,13 @@ typedef enum {
|
||||
} throughput_counter;
|
||||
|
||||
bool proc_buf1_buf1(const char* (*codec_func)(puffs_base_buf1*,
|
||||
puffs_base_buf1*),
|
||||
puffs_base_buf1*,
|
||||
uint64_t,
|
||||
uint64_t),
|
||||
throughput_counter tc,
|
||||
golden_test* gt,
|
||||
uint64_t wlimit,
|
||||
uint64_t rlimit,
|
||||
uint64_t reps,
|
||||
bool bench) {
|
||||
if (!codec_func) {
|
||||
@@ -373,7 +377,7 @@ bool proc_buf1_buf1(const char* (*codec_func)(puffs_base_buf1*,
|
||||
for (i = 0; i < reps; i++) {
|
||||
got.wi = 0;
|
||||
src.ri = gt->src_offset0;
|
||||
const char* s = codec_func(&got, &src);
|
||||
const char* s = codec_func(&got, &src, wlimit, rlimit);
|
||||
if (s) {
|
||||
FAIL("%s", s);
|
||||
return false;
|
||||
@@ -406,17 +410,25 @@ bool proc_buf1_buf1(const char* (*codec_func)(puffs_base_buf1*,
|
||||
}
|
||||
|
||||
bool do_bench_buf1_buf1(const char* (*codec_func)(puffs_base_buf1*,
|
||||
puffs_base_buf1*),
|
||||
puffs_base_buf1*,
|
||||
uint64_t,
|
||||
uint64_t),
|
||||
throughput_counter tc,
|
||||
golden_test* gt,
|
||||
uint64_t wlimit,
|
||||
uint64_t rlimit,
|
||||
uint64_t reps) {
|
||||
return proc_buf1_buf1(codec_func, tc, gt, reps, true);
|
||||
return proc_buf1_buf1(codec_func, tc, gt, wlimit, rlimit, reps, true);
|
||||
}
|
||||
|
||||
bool do_test_buf1_buf1(const char* (*codec_func)(puffs_base_buf1*,
|
||||
puffs_base_buf1*),
|
||||
golden_test* gt) {
|
||||
return proc_buf1_buf1(codec_func, 0, gt, 1, false);
|
||||
puffs_base_buf1*,
|
||||
uint64_t,
|
||||
uint64_t),
|
||||
golden_test* gt,
|
||||
uint64_t wlimit,
|
||||
uint64_t rlimit) {
|
||||
return proc_buf1_buf1(codec_func, 0, gt, wlimit, rlimit, 1, false);
|
||||
}
|
||||
|
||||
#endif // PUFFS_BASE_HEADER_H
|
||||
Reference in new issue
Block a user