From c9cba976913e55ff9aac8a8133cc94416c7c1c9c Mon Sep 17 00:00:00 2001 From: Lasse Collin Date: Fri, 18 Jan 2008 00:50:29 +0200 Subject: [PATCH] Added test_compress.sh and bunch of files needed by it. This new set of tests compress and decompress several test files with many different compression options. This set of tests will be extended later. --- tests/Makefile.am | 30 +++-- tests/bcj_test.c | 66 +++++++++++ tests/compress_prepared_bcj_sparc | Bin 0 -> 6804 bytes tests/compress_prepared_bcj_x86 | Bin 0 -> 4649 bytes tests/create_compress_files.c | 164 ++++++++++++++++++++++++++ tests/test_compress.sh | 183 ++++++++++++++++++++++++++++++ 6 files changed, 433 insertions(+), 10 deletions(-) create mode 100644 tests/bcj_test.c create mode 100644 tests/compress_prepared_bcj_sparc create mode 100644 tests/compress_prepared_bcj_x86 create mode 100644 tests/create_compress_files.c create mode 100755 tests/test_compress.sh diff --git a/tests/Makefile.am b/tests/Makefile.am index d5bb1266..fa78bf81 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -12,7 +12,14 @@ ## Lesser General Public License for more details. ## -EXTRA_DIST = files tests.h test_files.sh +EXTRA_DIST = \ + files \ + tests.h \ + test_files.sh \ + test_compress.sh \ + bcj_test.c \ + compress_prepared_bcj_sparc \ + compress_prepared_bcj_x86 AM_CPPFLAGS = \ -I@top_srcdir@/src/common \ @@ -26,6 +33,7 @@ LDADD += @top_builddir@/lib/libgnu.a endif check_PROGRAMS = \ + create_compress_files \ test_check \ test_stream_flags \ test_filter_flags \ @@ -33,13 +41,15 @@ check_PROGRAMS = \ test_index \ test_info -test_check_SOURCES = test_check.c -test_stream_flags_SOURCES = test_stream_flags.c -test_filter_flags_SOURCES = test_filter_flags.c -test_block_header_SOURCES = test_block_header.c -test_index_SOURCES = test_index.c -test_info_SOURCES = test_info.c - TESTS = \ - $(check_PROGRAMS) \ - test_files.sh + test_check \ + test_stream_flags \ + test_filter_flags \ + test_block_header \ + test_index \ + test_info \ + test_files.sh \ + test_compress.sh + +clean-local: + -rm -f compress_generated_* diff --git a/tests/bcj_test.c b/tests/bcj_test.c new file mode 100644 index 00000000..d64c5a79 --- /dev/null +++ b/tests/bcj_test.c @@ -0,0 +1,66 @@ +/////////////////////////////////////////////////////////////////////////////// +// +/// \file bcj_test.c +/// \brief Source code of compress_prepared_bcj_* +/// +/// This is a simple program that should make the compiler to generate +/// PC-relative branches, jumps, and calls. The compiled files can then +/// be used to test the branch conversion filters. Note that this program +/// itself does nothing useful. +/// +/// Compiling: gcc -std=c99 -fPIC bcj_test.c +/// Don't optimize or strip. +// +// This code has been put into the public domain. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// +/////////////////////////////////////////////////////////////////////////////// + +extern int jump(int a, int b); + + +extern int +call(int a, int b) +{ + if (a < b) + a = jump(a, b); + + return a; +} + + +extern int +jump(int a, int b) +{ + // The loop generates conditional jump backwards. + while (1) { + if (a < b) { + a *= 2; + a += 3 * b; + break; + } else { + // Put enough code here to prevent JMP SHORT on x86. + a += b; + a /= 2; + b += b % 5; + a -= b / 3; + b = 2 * b + a - 1; + a *= b + a + 1; + b += a - 1; + a += b * 2 - a / 5; + } + } + + return a; +} + + +int +main(int argc, char **argv) +{ + int a = call(argc, argc + 1); + return a == 0; +} diff --git a/tests/compress_prepared_bcj_sparc b/tests/compress_prepared_bcj_sparc new file mode 100644 index 0000000000000000000000000000000000000000..ba3ee2977660af414670095980aae748200b7120 GIT binary patch literal 6804 zcmd^EeQZ=&6~FJzl(v-a4uyp(C=X}?Wa(=QU6&w%=@%_*x45*pU{>F}&P?gxd^Gc> zeCQfx%l@I!#7Y27U9+=dBK{%q>yM3YLQ_yl+)c=a7*Z3%3fbKlRQ!k%DVdPxkchHcUfQiYZLUhA^sjfVT^=;u)!H7nZ0J8^tQ| ze&9t?XHYLo3BRN&5K9PjT}tX_sg}c^ZIYFcAM6H0GzS2_&qaD7RKerP9HU(TF_$95>P$pA<)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A1@AO?Rgu8C=E*IJYd+b|j zkNpwaMVZBtzo9|cOHsz-+PU$9XgQ2~lGlRUOj~Qq@OUbn(4d(L`60r~$6Ml=M9blL zoYcJ4Znw8e6whTxQiof-F&8FYF1@8W-e$XAM(l{^G8x>htaK`y+$na@aiKYt-6`yB zZY(L{`9jL}{^OmeWamfS^mx*1KIqzU(K+mSHb`{yGHS~kX?H#+fntosD~ykfzMgn=E;ptc`Im-OMA@*4n() zX>T6RyV>~Yqo{H6V{Tz|)BmhZI6*y;n0KDqSjW>Rsu<(DQ~?r#7_Bkbg;`obja zBXRVoj(jq0r*k+M!bUg+cNn~omz+8f1BN6Mzt_P@cx+b+bu4_R zGZ&`a+u$U=1CY|m!gnl*`6zQ**fGbJR05`szR2;6mw6-Gu2Z=;^KW?NOTbMa_JMbzw8y(vJg#NhT|qTS=G?Sn?nb|~>(Dao zuAv$v?>@9+4({7M0hzJl4#k|G6z2H+LOYhHK-!MEfXWA?M*aA9PY3Mq&Q$Ns1?-r^ z(4VQ^-Rk|lfZY~t$GcV${y_L&!h^zoNxMPxR}H%humgz_$S<_vyd*)q1Hm8fAo3n^ z71)oTyatp7(I4!X3(I_%?fv507f|8bt%e;)-=UPHZ};hdT@&m;3))Qt>^8#=REZ5@ zMgBs-t`&BmiY{pPrGQ;K>_7|JVclgs94~S+ng3a+^NT-@mr$YZpi)CSPN%##^@7um y`{!FA?llX9vJ`e9nNuk&=ZxZaL7YEbmQMmohq}Vo{SY|d?~!xBSF{b8wEG8QC3+G7 literal 0 HcmV?d00001 diff --git a/tests/compress_prepared_bcj_x86 b/tests/compress_prepared_bcj_x86 new file mode 100644 index 0000000000000000000000000000000000000000..48dde27c3638e109bf4d34ef1fc4b488d434f3e3 GIT binary patch literal 4649 zcmcgwZETxI9lytMR}VarrfDgq(kzjR1gTzHWu>qoB~6|**^)NROP4K8pE>rE*u^iI z{kSwA${O5$FeXx@4)z5kDmtkWLc9tM6``c5mJSJ&bP_`Ffg-5nC}GM_Cb^{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b)0Sgr97cVl``F>u zZtGY_N545>4YVHaHW@u{Z&oOs4ozBilJDt?4*B{PR{P6GTYI|N1g~c5r42Fp><(wL zmb~(9c0cfHw_Z47_1WXG46dJT@lYmXXM{C2VMV`$iZ{haUhgd}_n+^Ny!0#lpUx&G zpdHDitY|11iQC!~BjO0;0-_TaNgbOUo-OZ}80Eo32ZQ6bV@-rDCz?%uF*tfw$o~(N G`hNgjV|mp8 literal 0 HcmV?d00001 diff --git a/tests/create_compress_files.c b/tests/create_compress_files.c new file mode 100644 index 00000000..2e394297 --- /dev/null +++ b/tests/create_compress_files.c @@ -0,0 +1,164 @@ +/////////////////////////////////////////////////////////////////////////////// +// +/// \file create_compress_files.c +/// \brief Creates bunch of test files to be compressed +/// +/// Using a test file generator program saves space in the source code +/// package considerably. +// +// Copyright (C) 2008 Lasse Collin +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +/////////////////////////////////////////////////////////////////////////////// + +#include "sysdefs.h" +#include + + +// Avoid re-creating the test files every time the tests are run. +#define create_test(name) \ +do { \ + if (!file_exists("compress_generated_" #name)) { \ + FILE *file = file_create("compress_generated_" #name); \ + write_ ## name(file); \ + file_finish(file, "compress_generated_" #name); \ + } \ +} while (0) + + +static bool +file_exists(const char *filename) +{ + // Trying to be somewhat portable by avoiding stat(). + FILE *file = fopen(filename, "rb"); + bool ret; + + if (file != NULL) { + fclose(file); + ret = true; + } else { + ret = false; + } + + return ret; +} + + +static FILE * +file_create(const char *filename) +{ + FILE *file = fopen(filename, "wb"); + + if (file == NULL) { + perror(filename); + exit(1); + } + + return file; +} + + +static void +file_finish(FILE *file, const char *filename) +{ + const bool ferror_fail = ferror(file); + const bool fclose_fail = fclose(file); + + if (ferror_fail || fclose_fail) { + perror(filename); + exit(1); + } +} + + +// File that repeats "abc\n" a few thousand times. This is targeted +// especially at Subblock filter's run-length encoder. +static void +write_abc(FILE *file) +{ + for (size_t i = 0; i < 12345; ++i) + fwrite("abc\n", 4, 1, file); +} + + +// File that doesn't compress. We always use the same random seed to +// generate identical files on all systems. +static void +write_random(FILE *file) +{ + uint32_t n = 5; + + for (size_t i = 0; i < 123456; ++i) { + n = 101771 * n + 71777; + + putc(n & 0xFF, file); + putc((n >> 8) & 0xFF, file); + putc((n >> 16) & 0xFF, file); + putc(n >> 24, file); + } +} + + +// Text file +static void +write_text(FILE *file) +{ + static const char *lorem[] = { + "Lorem", "ipsum", "dolor", "sit", "amet,", "consectetur", + "adipisicing", "elit,", "sed", "do", "eiusmod", "tempor", + "incididunt", "ut", "labore", "et", "dolore", "magna", + "aliqua.", "Ut", "enim", "ad", "minim", "veniam,", "quis", + "nostrud", "exercitation", "ullamco", "laboris", "nisi", + "ut", "aliquip", "ex", "ea", "commodo", "consequat.", + "Duis", "aute", "irure", "dolor", "in", "reprehenderit", + "in", "voluptate", "velit", "esse", "cillum", "dolore", + "eu", "fugiat", "nulla", "pariatur.", "Excepteur", "sint", + "occaecat", "cupidatat", "non", "proident,", "sunt", "in", + "culpa", "qui", "officia", "deserunt", "mollit", "anim", + "id", "est", "laborum." + }; + + // Let the first paragraph be the original text. + for (size_t w = 0; w < ARRAY_SIZE(lorem); ++w) { + fprintf(file, "%s ", lorem[w]); + + if (w % 7 == 6) + fprintf(file, "\n"); + } + + // The rest shall be (hopefully) meaningless combinations of + // the same words. + uint32_t n = 29; + + for (size_t p = 0; p < 500; ++p) { + fprintf(file, "\n\n"); + + for (size_t w = 0; w < ARRAY_SIZE(lorem); ++w) { + n = 101771 * n + 71777; + + fprintf(file, "%s ", lorem[n % ARRAY_SIZE(lorem)]); + + if (w % 7 == 6) + fprintf(file, "\n"); + } + } +} + + +int +main(void) +{ + create_test(abc); + create_test(random); + create_test(text); + return 0; +} diff --git a/tests/test_compress.sh b/tests/test_compress.sh new file mode 100755 index 00000000..5cf21cf4 --- /dev/null +++ b/tests/test_compress.sh @@ -0,0 +1,183 @@ +#!/bin/sh + +############################################################################### +# +# Copyright (C) 2008 Lasse Collin +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +############################################################################### + +# Find out if our shell supports functions. +eval 'unset foo ; foo() { return 42; } ; foo' +if test $? != 42 ; then + echo "/bin/sh doesn't support functions, skipping this test." + (exit 77) + exit 77 +fi + +test_lzma() { + ################ + # Non-streamed # + ################ + + if $LZMA -c "$@" "$FILE" > tmp_compressed; then + : + else + echo "Non-streamed compressing failed: $* $FILE" + (exit 1) + exit 1 + fi + + if $LZMA -cd tmp_compressed > tmp_uncompressed ; then + : + else + echo "Decoding of non-streamed file failed: $* $FILE" + (exit 1) + exit 1 + fi + + if cmp tmp_uncompressed "$FILE" ; then + : + else + echo "Decoded non-streamed file does not match the original: $* $FILE" + (exit 1) + exit 1 + fi + + if $LZMADEC tmp_compressed > tmp_uncompressed ; then + : + else + echo "Decoding of non-streamed file failed: $* $FILE" + (exit 1) + exit 1 + fi + + if cmp tmp_uncompressed "$FILE" ; then + : + else + echo "Decoded non-streamed file does not match the original: $* $FILE" + (exit 1) + exit 1 + fi + + ############ + # Streamed # + ############ + + if $LZMA -c "$@" < "$FILE" > tmp_compressed; then + : + else + echo "Streamed compressing failed: $* $FILE" + (exit 1) + exit 1 + fi + + if $LZMA -cd < tmp_compressed > tmp_uncompressed ; then + : + else + echo "Decoding of streamed file failed: $* $FILE" + (exit 1) + exit 1 + fi + + if cmp tmp_uncompressed "$FILE" ; then + : + else + echo "Decoded streamed file does not match the original: $* $FILE" + (exit 1) + exit 1 + fi + + if $LZMADEC < tmp_compressed > tmp_uncompressed ; then + : + else + echo "Decoding of streamed file failed: $* $FILE" + (exit 1) + exit 1 + fi + + if cmp tmp_uncompressed "$FILE" ; then + : + else + echo "Decoded streamed file does not match the original: $* $FILE" + (exit 1) + exit 1 + fi + + # Show progress: + echo . | tr -d '\n\r' +} + +LZMA="../src/lzma/lzma --memory=15Mi --threads=1" +LZMADEC="../src/lzmadec/lzmadec --memory=4Mi" +unset LZMA_OPT + +# Create the required input files. +if ./create_compress_files ; then + : +else + rm -f compress_* + echo "Failed to create files to test compression." + (exit 1) + exit 1 +fi + +# Remove temporary now (in case they are something weird), and on exit. +rm -f tmp_compressed tmp_uncompressed +trap 'rm -f tmp_compressed tmp_uncompressed' 0 + +# Encode and decode each file with various filter configurations. +# This takes quite a bit of time. +echo "test_compress.sh:" +for FILE in compress_generated_* "$srcdir"/compress_prepared_* +do + MSG=`echo "x$FILE" | sed 's,^x,,; s,^.*/,,; s,^compress_,,'` + echo " $MSG" | tr -d '\n\r' + + # Don't test with empty arguments; it breaks some ancient + # proprietary /bin/sh versions due to $@ used in test_lzma(). + test_lzma -1 + test_lzma -2 + test_lzma -3 + test_lzma -4 + + for ARGS in \ + --copy \ + --subblock \ + --subblock=size=1 \ + --subblock=size=1,rle=1 \ + --subblock=size=1,rle=4 \ + --subblock=size=4,rle=4 \ + --subblock=size=8,rle=4 \ + --subblock=size=8,rle=8 \ + --subblock=size=4096,rle=12 \ + --delta=distance=1 \ + --delta=distance=4 \ + --delta=distance=256 \ + --x86 \ + --powerpc \ + --ia64 \ + --arm \ + --armthumb \ + --sparc + do + test_lzma $ARGS + test_lzma --subblock $ARGS + test_lzma $ARGS --subblock + test_lzma --subblock $ARGS --subblock + done + + echo +done + +(exit 0) +exit 0