xref: /aosp_15_r20/external/brotli/tests/roundtrip_test.sh (revision f4ee7fba7774faf2a30f13154332c0a06550dbc4)
1*f4ee7fbaSAndroid Build Coastguard Worker#!/usr/bin/env bash
2*f4ee7fbaSAndroid Build Coastguard Worker#
3*f4ee7fbaSAndroid Build Coastguard Worker# Roundtrip test for the brotli command-line tool.
4*f4ee7fbaSAndroid Build Coastguard Worker#
5*f4ee7fbaSAndroid Build Coastguard Worker# The first argument may be a wrapper for brotli, such as 'qemu-arm'.
6*f4ee7fbaSAndroid Build Coastguard Worker
7*f4ee7fbaSAndroid Build Coastguard Workerset -o errexit
8*f4ee7fbaSAndroid Build Coastguard Worker
9*f4ee7fbaSAndroid Build Coastguard WorkerBROTLI_WRAPPER=$1
10*f4ee7fbaSAndroid Build Coastguard WorkerBROTLI="${BROTLI_WRAPPER} bin/brotli"
11*f4ee7fbaSAndroid Build Coastguard WorkerTMP_DIR=bin/tmp
12*f4ee7fbaSAndroid Build Coastguard WorkerINPUTS="""
13*f4ee7fbaSAndroid Build Coastguard Workertests/testdata/alice29.txt
14*f4ee7fbaSAndroid Build Coastguard Workertests/testdata/asyoulik.txt
15*f4ee7fbaSAndroid Build Coastguard Workertests/testdata/lcet10.txt
16*f4ee7fbaSAndroid Build Coastguard Workertests/testdata/plrabn12.txt
17*f4ee7fbaSAndroid Build Coastguard Workerc/enc/encode.c
18*f4ee7fbaSAndroid Build Coastguard Workerc/common/dictionary.h
19*f4ee7fbaSAndroid Build Coastguard Workerc/dec/decode.c
20*f4ee7fbaSAndroid Build Coastguard Worker"""
21*f4ee7fbaSAndroid Build Coastguard Worker
22*f4ee7fbaSAndroid Build Coastguard Workerfor file in $INPUTS; do
23*f4ee7fbaSAndroid Build Coastguard Worker  if [ -f $file ]; then
24*f4ee7fbaSAndroid Build Coastguard Worker    for quality in 1 6 9 11; do
25*f4ee7fbaSAndroid Build Coastguard Worker      echo "Roundtrip testing $file at quality $quality"
26*f4ee7fbaSAndroid Build Coastguard Worker      compressed=${TMP_DIR}/${file##*/}.br
27*f4ee7fbaSAndroid Build Coastguard Worker      uncompressed=${TMP_DIR}/${file##*/}.unbr
28*f4ee7fbaSAndroid Build Coastguard Worker      $BROTLI -fq $quality $file -o $compressed
29*f4ee7fbaSAndroid Build Coastguard Worker      $BROTLI $compressed -fdo $uncompressed
30*f4ee7fbaSAndroid Build Coastguard Worker      diff -q $file $uncompressed
31*f4ee7fbaSAndroid Build Coastguard Worker      # Test the streaming version
32*f4ee7fbaSAndroid Build Coastguard Worker      cat $file | $BROTLI -cq $quality | $BROTLI -cd >$uncompressed
33*f4ee7fbaSAndroid Build Coastguard Worker      diff -q $file $uncompressed
34*f4ee7fbaSAndroid Build Coastguard Worker    done
35*f4ee7fbaSAndroid Build Coastguard Worker  fi
36*f4ee7fbaSAndroid Build Coastguard Workerdone
37