From e67e3a3f4a43ad08115b4fcebce39fb487728eb3 Mon Sep 17 00:00:00 2001 From: Janne Grunau Date: Tue, 31 Jan 2012 21:39:48 +0100 Subject: [PATCH] fate-golomb: extend golomb-test to get_ue_golomb_long() get_ue_golomb_long() is only tested for values up to 2^15 - 2 since we can not write larger values. Silence the test on success and return a non-zero value on error. Use an heap scratch buffer instead of large stack buffer. Remove unneeded includes. --- libavcodec/golomb-test.c | 60 ++++++++++++++++++++++++++++----------- tests/fate/libavcodec.mak | 1 + tests/ref/fate/golomb | 2 -- 3 files changed, 45 insertions(+), 18 deletions(-) delete mode 100644 tests/ref/fate/golomb diff --git a/libavcodec/golomb-test.c b/libavcodec/golomb-test.c index 3dbf9d14cb..bc90f36baf 100644 --- a/libavcodec/golomb-test.c +++ b/libavcodec/golomb-test.c @@ -19,52 +19,80 @@ #include #include -#include "avcodec.h" -#include "dsputil.h" +#include "libavutil/mem.h" + #include "get_bits.h" #include "golomb.h" #include "put_bits.h" -#undef printf -#define COUNT 8000 -#define SIZE (COUNT * 40) +#undef fprintf +#define COUNT 8191 +#define SIZE (COUNT * 4) int main(void) { - int i; - uint8_t temp[SIZE]; + int i, ret = 0; + uint8_t *temp; PutBitContext pb; GetBitContext gb; + temp = av_malloc(SIZE); + if (!temp) + return 2; + init_put_bits(&pb, temp, SIZE); - printf("testing unsigned exp golomb\n"); for (i = 0; i < COUNT; i++) set_ue_golomb(&pb, i); flush_put_bits(&pb); init_get_bits(&gb, temp, 8 * SIZE); for (i = 0; i < COUNT; i++) { - int j, s = show_bits(&gb, 24); + int j, s = show_bits(&gb, 25); j = get_ue_golomb(&gb); - if (j != i) - printf("mismatch at %d (%d should be %d) bits: %6X\n", i, j, i, s); + if (j != i) { + fprintf(stderr, "get_ue_golomb: expected %d, got %d. bits: %7x\n", + i, j, s); + ret = 1; + } + } + +#define EXTEND(i) (i << 3 | i & 7) + init_put_bits(&pb, temp, SIZE); + for (i = 0; i < COUNT; i++) + set_ue_golomb(&pb, EXTEND(i)); + flush_put_bits(&pb); + + init_get_bits(&gb, temp, 8 * SIZE); + for (i = 0; i < COUNT; i++) { + int j, s = show_bits_long(&gb, 32); + + j = get_ue_golomb_long(&gb); + if (j != EXTEND(i)) { + fprintf(stderr, "get_ue_golomb_long: expected %d, got %d. " + "bits: %8x\n", EXTEND(i), j, s); + ret = 1; + } } init_put_bits(&pb, temp, SIZE); - printf("testing signed exp golomb\n"); for (i = 0; i < COUNT; i++) set_se_golomb(&pb, i - COUNT / 2); flush_put_bits(&pb); init_get_bits(&gb, temp, 8 * SIZE); for (i = 0; i < COUNT; i++) { - int j, s = show_bits(&gb, 24); + int j, s = show_bits(&gb, 25); j = get_se_golomb(&gb); - if (j != i - COUNT / 2) - printf("mismatch at %d (%d should be %d) bits: %6X\n", i, j, i, s); + if (j != i - COUNT / 2) { + fprintf(stderr, "get_se_golomb: expected %d, got %d. bits: %7x\n", + i - COUNT / 2, j, s); + ret = 1; + } } - return 0; + av_free(temp); + + return ret; } diff --git a/tests/fate/libavcodec.mak b/tests/fate/libavcodec.mak index 90c817812f..ec4012ebb6 100644 --- a/tests/fate/libavcodec.mak +++ b/tests/fate/libavcodec.mak @@ -1,6 +1,7 @@ FATE_TESTS += fate-golomb fate-golomb: libavcodec/golomb-test$(EXESUF) fate-golomb: CMD = run libavcodec/golomb-test +fate-golomb: REF = /dev/null FATE_TESTS += fate-iirfilter fate-iirfilter: libavcodec/iirfilter-test$(EXESUF) diff --git a/tests/ref/fate/golomb b/tests/ref/fate/golomb deleted file mode 100644 index 652e97b305..0000000000 --- a/tests/ref/fate/golomb +++ /dev/null @@ -1,2 +0,0 @@ -testing unsigned exp golomb -testing signed exp golomb