From 917b82955ba8fdbd3c52bb898c01e4f43fc3ca75 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sat, 30 Jan 2021 09:57:01 +0100 Subject: add tests --- test/compile.sh | 3 +++ test/deflate | 18 ++++++++++++++++++ test/inflate-app.c | 34 ++++++++++++++++++++++++++++++++++ test/test.sh | 17 +++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100755 test/compile.sh create mode 100755 test/deflate create mode 100644 test/inflate-app.c create mode 100755 test/test.sh diff --git a/test/compile.sh b/test/compile.sh new file mode 100755 index 0000000..3d6306f --- /dev/null +++ b/test/compile.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +exec gcc -ggdb -Wall -Wextra -pedantic -I../src -o inflate inflate-app.c ../src/inflate.c diff --git a/test/deflate b/test/deflate new file mode 100755 index 0000000..0271d59 --- /dev/null +++ b/test/deflate @@ -0,0 +1,18 @@ +#!/usr/bin/env python3 + +import sys +import zlib + +level = -1 +if len(sys.argv) > 2: + level = int(sys.argv[2]) + +try: + with open(sys.argv[1], "rb") as f: + input_data = f.read() +except FileNotFoundError: + input_data = sys.argv[1].encode("utf-8") + +output = zlib.compress(input_data, level=level) + +sys.stdout.buffer.write(output) diff --git a/test/inflate-app.c b/test/inflate-app.c new file mode 100644 index 0000000..dddc807 --- /dev/null +++ b/test/inflate-app.c @@ -0,0 +1,34 @@ +#include +#include + +#include "inflate.h" + +unsigned char *inbuf; +unsigned char *outbuf; + +int main(void) +{ + // 16 MB + inbuf = malloc(4096 * 4096); + outbuf = malloc(4096 * 4096); + + if (inbuf == NULL || outbuf == NULL) { + return 1; + } + + size_t in_size = fread(inbuf, 1, 4096 * 4096, stdin); + + if (in_size == 0) { + return 1; + } + + int16_t out_size = inflate_zlib(inbuf, in_size, outbuf, 65535); + + if (out_size < 0) { + return -out_size; + } + + fwrite(outbuf, 1, out_size, stdout); + + return 0; +} diff --git a/test/test.sh b/test/test.sh new file mode 100755 index 0000000..e60aaa0 --- /dev/null +++ b/test/test.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +set -eu + +cd "$(dirname "$0")" + +./compile.sh + +for file in $(find .. -type f -size -65000c); do + if ! ./deflate $file | ./inflate > tmp; then + echo "inflate error at $file" + ./deflate $file | ./inflate > tmp + fi + diff $file tmp +done + +rm -f tmp -- cgit v1.2.3