Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Brotli Test Files #4

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

.vs/
build/
build/CPotree.sln
17 changes: 17 additions & 0 deletions libs/brotli/tests/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#brotli/tests

BROTLI = ..

all: test

test: deps
./compatibility_test.sh
./roundtrip_test.sh

deps :
$(MAKE) -C $(BROTLI) brotli

clean :
rm -f testdata/*.{br,unbr,uncompressed}
rm -f $(BROTLI)/{enc,dec,tools}/*.{un,}br
$(MAKE) -C $(BROTLI)/tools clean
25 changes: 25 additions & 0 deletions libs/brotli/tests/compatibility_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash
#
# Test that the brotli command-line tool can decompress old brotli-compressed
# files.
#
# The first argument may be a wrapper for brotli, such as 'qemu-arm'.

set -o errexit

BROTLI_WRAPPER=$1
BROTLI="${BROTLI_WRAPPER} bin/brotli"
TMP_DIR=bin/tmp

for file in tests/testdata/*.compressed*; do
echo "Testing decompression of file $file"
expected=${file%.compressed*}
uncompressed=${TMP_DIR}/${expected##*/}.uncompressed
echo $uncompressed
$BROTLI $file -fdo $uncompressed
diff -q $uncompressed $expected
# Test the streaming version
cat $file | $BROTLI -dc > $uncompressed
diff -q $uncompressed $expected
rm -f $uncompressed
done
36 changes: 36 additions & 0 deletions libs/brotli/tests/roundtrip_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bash
#
# Roundtrip test for the brotli command-line tool.
#
# The first argument may be a wrapper for brotli, such as 'qemu-arm'.

set -o errexit

BROTLI_WRAPPER=$1
BROTLI="${BROTLI_WRAPPER} bin/brotli"
TMP_DIR=bin/tmp
INPUTS="""
tests/testdata/alice29.txt
tests/testdata/asyoulik.txt
tests/testdata/lcet10.txt
tests/testdata/plrabn12.txt
c/enc/encode.c
c/common/dictionary.h
c/dec/decode.c
"""

for file in $INPUTS; do
if [ -f $file ]; then
for quality in 1 6 9 11; do
echo "Roundtrip testing $file at quality $quality"
compressed=${TMP_DIR}/${file##*/}.br
uncompressed=${TMP_DIR}/${file##*/}.unbr
$BROTLI -fq $quality $file -o $compressed
$BROTLI $compressed -fdo $uncompressed
diff -q $file $uncompressed
# Test the streaming version
cat $file | $BROTLI -cq $quality | $BROTLI -cd >$uncompressed
diff -q $file $uncompressed
done
fi
done
31 changes: 31 additions & 0 deletions libs/brotli/tests/run-compatibility-test.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
string(REGEX REPLACE "([a-zA-Z0-9\\.]+)\\.compressed(\\.[0-9]+)?$" "\\1" REFERENCE_DATA "${INPUT}")
string(REGEX REPLACE "\\.compressed" "" OUTPUT_FILE "${INPUT}")
get_filename_component(OUTPUT_NAME "${OUTPUT_FILE}" NAME)

set(ENV{QEMU_LD_PREFIX} "${BROTLI_WRAPPER_LD_PREFIX}")

execute_process(
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMAND ${BROTLI_WRAPPER} ${BROTLI_CLI} --force --decompress ${INPUT} --output=${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_NAME}.unbr
RESULT_VARIABLE result)
if(result)
message(FATAL_ERROR "Decompression failed")
endif()

function(test_file_equality f1 f2)
if(NOT CMAKE_VERSION VERSION_LESS 2.8.7)
file(SHA512 "${f1}" f1_cs)
file(SHA512 "${f2}" f2_cs)
if(NOT "${f1_cs}" STREQUAL "${f2_cs}")
message(FATAL_ERROR "Files do not match")
endif()
else()
file(READ "${f1}" f1_contents)
file(READ "${f2}" f2_contents)
if(NOT "${f1_contents}" STREQUAL "${f2_contents}")
message(FATAL_ERROR "Files do not match")
endif()
endif()
endfunction()

test_file_equality("${REFERENCE_DATA}" "${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_NAME}.unbr")
36 changes: 36 additions & 0 deletions libs/brotli/tests/run-roundtrip-test.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
set(ENV{QEMU_LD_PREFIX} "${BROTLI_WRAPPER_LD_PREFIX}")

execute_process(
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMAND ${BROTLI_WRAPPER} ${BROTLI_CLI} --force --quality=${QUALITY} ${INPUT} --output=${OUTPUT}.br
RESULT_VARIABLE result
ERROR_VARIABLE result_stderr)
if(result)
message(FATAL_ERROR "Compression failed: ${result_stderr}")
endif()

execute_process(
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMAND ${BROTLI_WRAPPER} ${BROTLI_CLI} --force --decompress ${OUTPUT}.br --output=${OUTPUT}.unbr
RESULT_VARIABLE result)
if(result)
message(FATAL_ERROR "Decompression failed")
endif()

function(test_file_equality f1 f2)
if(NOT CMAKE_VERSION VERSION_LESS 2.8.7)
file(SHA512 "${f1}" f1_cs)
file(SHA512 "${f2}" f2_cs)
if(NOT "${f1_cs}" STREQUAL "${f2_cs}")
message(FATAL_ERROR "Files do not match")
endif()
else()
file(READ "${f1}" f1_contents)
file(READ "${f2}" f2_contents)
if(NOT "${f1_contents}" STREQUAL "${f2_contents}")
message(FATAL_ERROR "Files do not match")
endif()
endif()
endfunction()

test_file_equality("${INPUT}" "${OUTPUT}.unbr")
1 change: 1 addition & 0 deletions libs/brotli/tests/testdata/10x10y
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
XXXXXXXXXXYYYYYYYYYY
Binary file added libs/brotli/tests/testdata/10x10y.compressed
Binary file not shown.
1 change: 1 addition & 0 deletions libs/brotli/tests/testdata/64x
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Binary file added libs/brotli/tests/testdata/64x.compressed
Binary file not shown.
Loading