xref: /aosp_15_r20/external/zstd/tests/test-variants.sh (revision 01826a4963a0d8a59bc3812d29bdf0fb76416722)
1#!/bin/sh
2set -e
3set -u
4set -x
5
6
7SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
8PROG_DIR="$SCRIPT_DIR/../programs"
9
10ZSTD="$PROG_DIR/zstd"
11ZSTD_COMPRESS="$PROG_DIR/zstd-compress"
12ZSTD_DECOMPRESS="$PROG_DIR/zstd-decompress"
13ZSTD_NOLEGACY="$PROG_DIR/zstd-nolegacy"
14ZSTD_DICTBUILDER="$PROG_DIR/zstd-dictBuilder"
15ZSTD_FRUGAL="$PROG_DIR/zstd-frugal"
16ZSTD_NOMT="$PROG_DIR/zstd-nomt"
17
18println() {
19    printf '%b\n' "${*}"
20}
21
22die() {
23    println "$@" 1>&2
24    exit 1
25}
26
27symbol_present() {
28	(nm $1 || echo "symbol_present $@ failed") | grep $2
29}
30
31symbol_not_present() {
32	symbol_present $@ && die "Binary '$1' mistakenly contains symbol '$2'" ||:
33}
34
35compress_not_present() {
36	symbol_not_present "$1" ZSTD_compress
37}
38
39decompress_not_present() {
40	symbol_not_present "$1" ZSTD_decompress
41}
42
43dict_not_present() {
44	symbol_not_present "$1" ZDICT_
45	symbol_not_present "$1" COVER_
46}
47
48cliextra_not_present() {
49	symbol_not_present "$1" TRACE_
50	symbol_not_present "$1" BMK_
51}
52
53legacy_not_present() {
54	symbol_not_present "$1" ZSTDv0
55}
56
57test_help() {
58	"$1" --help | grep -- "$2"
59}
60
61test_no_help() {
62	test_help $@ && die "'$1' supports '$2' when it shouldn't" ||:
63}
64
65extras_not_present() {
66	dict_not_present $@
67	legacy_not_present $@
68	cliextra_not_present $@
69	test_no_help $@ "--train"
70	test_no_help $@ "-b#"
71}
72
73test_compress() {
74	echo "hello" | "$1" | "$ZSTD" -t
75}
76
77test_decompress() {
78	echo "hello" | "$ZSTD" | "$1" -t
79}
80
81test_zstd() {
82	test_compress $@
83	test_decompress $@
84}
85
86extras_not_present "$ZSTD_FRUGAL"
87extras_not_present "$ZSTD_COMPRESS"
88extras_not_present "$ZSTD_DECOMPRESS"
89
90compress_not_present "$ZSTD_DECOMPRESS"
91
92decompress_not_present "$ZSTD_COMPRESS"
93decompress_not_present "$ZSTD_DICTBUILDER"
94
95cliextra_not_present "$ZSTD_DICTBUILDER"
96
97legacy_not_present "$ZSTD_DICTBUILDER"
98legacy_not_present "$ZSTD_NOLEGACY"
99
100symbol_not_present "$ZSTD" ZSTDv01
101symbol_not_present "$ZSTD" ZSTDv02
102symbol_not_present "$ZSTD" ZSTDv03
103symbol_not_present "$ZSTD" ZSTDv04
104
105test_compress "$ZSTD_COMPRESS"
106test_decompress "$ZSTD_DECOMPRESS"
107
108test_zstd "$ZSTD_FRUGAL"
109test_zstd "$ZSTD_NOLEGACY"
110
111test_help "$ZSTD" '-b#'
112test_help "$ZSTD" --train
113test_help "$ZSTD_DICTBUILDER" --train
114
115println "Success!"
116