From 33db93f61733e493525fbd7d837093bbf9decebd Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Tue, 26 Dec 2023 10:56:22 +1100 Subject: [PATCH] script: add print-mzcat-checksums.sh --- build-all.sh | 12 +++++++ script/print-mzcat-checksums.sh | 62 ++++++++++++++++++++++++++++++++ test/mzcat-checksums-of-data.txt | 19 ++++++++++ 3 files changed, 93 insertions(+) create mode 100755 script/print-mzcat-checksums.sh create mode 100644 test/mzcat-checksums-of-data.txt diff --git a/build-all.sh b/build-all.sh index 1574aeb5..260ab0ef 100755 --- a/build-all.sh +++ b/build-all.sh @@ -106,6 +106,18 @@ set -e # ---- +echo "Running gen/bin/example-mzcat" +set +e +script/print-mzcat-checksums.sh | \ + diff --unified test/mzcat-checksums-of-data.txt /dev/stdin +if [ $? != 0 ]; then + echo "Unexpected change in test/mzcat-checksums-of-data.txt" + exit 1 +fi +set -e + +# ---- + for f in gen/bin/fuzz-*; do echo "Running $f" $f test/data > /dev/null diff --git a/script/print-mzcat-checksums.sh b/script/print-mzcat-checksums.sh new file mode 100755 index 00000000..d366622e --- /dev/null +++ b/script/print-mzcat-checksums.sh @@ -0,0 +1,62 @@ +#!/bin/bash -eu +# Copyright 2023 The Wuffs Authors. +# +# Licensed under the Apache License, Version 2.0 or the MIT license +# , at your +# option. This file may not be copied, modified, or distributed +# except according to those terms. +# +# SPDX-License-Identifier: Apache-2.0 OR MIT + +# ---------------- + +# This script prints the CRC-32 checksum of the decompressed data of every file +# given as a command line argument: if a file then itself, if a directory then +# the files under it. It skips any non-compressed file found (non-compressed +# meaning not decodable by Wuffs' standard library). +# +# It is not perfect. It can have false positives and false negatives. +# Nonetheless, running it regularly (compiled against the in-development +# release/c/wuffs-unsupported-snapshot.c) can help detect regressions. + +if [ ! -e wuffs-root-directory.txt ]; then + echo "$0 should be run from the Wuffs root directory." + exit 1 +elif [ ! -e gen/bin/example-mzcat ]; then + echo "Run \"./build-example.sh example/mzcat\" first." + exit 1 +elif [ ! -e gen/bin/example-crc32 ]; then + echo "Run \"./build-example.sh example/crc32\" first." + exit 1 +fi + +sources=$@ +if [ $# -eq 0 ]; then + sources=test/data +fi + +# ---- + +handle() { + local c=$(gen/bin/example-mzcat <$1 2>/dev/null | gen/bin/example-crc32) + if [ "$c" != "00000000" ]; then + echo $c $1 + fi +} + +# ---- + +echo "# Generated by script/print-mzcat-checksums.sh" +for f in $sources; do + if [ -f $f ]; then + handle $f + elif [ -d $f ]; then + for g in `find $f -type f | LANG=C sort`; do + handle $g + done + else + echo "Could not open $f" + exit 1 + fi +done diff --git a/test/mzcat-checksums-of-data.txt b/test/mzcat-checksums-of-data.txt new file mode 100644 index 00000000..09d4a88f --- /dev/null +++ b/test/mzcat-checksums-of-data.txt @@ -0,0 +1,19 @@ +# Generated by script/print-mzcat-checksums.sh +29058c73 test/data/256.bytes.bz2 +29058c73 test/data/256.bytes.gz +6ddef9db test/data/abraca.txt.bz2 +b19df306 test/data/archive.tar.bz2 +b19df306 test/data/archive.tar.gz +6ddef9db test/data/artificial-bzip2/abraca.txt.bz2 +6ddef9db test/data/artificial-bzip2/huffman-258.bz2 +acef87f1 test/data/enwik5.lzma +acef87f1 test/data/enwik5.xz +3db2cdc6 test/data/midsummer.txt.bz2 +3db2cdc6 test/data/midsummer.txt.gz +519e8b87 test/data/pi.txt.bz2 +519e8b87 test/data/pi.txt.gz +abe507ef test/data/romeo.txt.bz2 +abe507ef test/data/romeo.txt.gz +abe507ef test/data/romeo.txt.litonlylzma +abe507ef test/data/romeo.txt.lzma +abe507ef test/data/romeo.txt.xz