xref: /aosp_15_r20/external/zstd/tests/cli-tests/compression/levels.sh (revision 01826a4963a0d8a59bc3812d29bdf0fb76416722)
1*01826a49SYabin Cui#!/bin/sh
2*01826a49SYabin Cui
3*01826a49SYabin Cuiset -e
4*01826a49SYabin Cuiset -v
5*01826a49SYabin Cui
6*01826a49SYabin Cuidatagen > file
7*01826a49SYabin Cui
8*01826a49SYabin Cui# Compress with various levels and ensure that their sizes are ordered
9*01826a49SYabin Cuizstd --fast=10 file -o file-f10.zst -q
10*01826a49SYabin Cuizstd --fast=1 file -o file-f1.zst -q
11*01826a49SYabin Cuizstd -1 file -o file-1.zst -q
12*01826a49SYabin Cuizstd -19 file -o file-19.zst -q
13*01826a49SYabin Cui
14*01826a49SYabin Cuizstd -t file-f10.zst file-f1.zst file-1.zst file-19.zst
15*01826a49SYabin Cui
16*01826a49SYabin Cuicmp_size -lt file-19.zst file-1.zst
17*01826a49SYabin Cuicmp_size -lt file-1.zst file-f1.zst
18*01826a49SYabin Cuicmp_size -lt file-f1.zst file-f10.zst
19*01826a49SYabin Cui
20*01826a49SYabin Cui# Test default levels
21*01826a49SYabin Cuizstd --fast file -f -q
22*01826a49SYabin Cuicmp file.zst file-f1.zst || die "--fast is not level -1"
23*01826a49SYabin Cui
24*01826a49SYabin Cuizstd -0 file -o file-0.zst -q
25*01826a49SYabin Cuizstd -f file -q
26*01826a49SYabin Cuicmp file.zst file-0.zst || die "Level 0 is not the default level"
27*01826a49SYabin Cui
28*01826a49SYabin Cui# Test level clamping
29*01826a49SYabin Cuizstd -99 file -o file-99.zst -q
30*01826a49SYabin Cuicmp file-19.zst file-99.zst || die "Level 99 is clamped to 19"
31*01826a49SYabin Cuizstd --fast=200000 file -c | zstd -t
32*01826a49SYabin Cui
33*01826a49SYabin Cuizstd -5000000000 -f file       && die "Level too large, must fail" ||:
34*01826a49SYabin Cuizstd --fast=5000000000 -f file && die "Level too large, must fail" ||:
35*01826a49SYabin Cui
36*01826a49SYabin Cui# Test setting a level through the environment variable
37*01826a49SYabin CuiZSTD_CLEVEL=-10 zstd file -o file-f10-env.zst -q
38*01826a49SYabin CuiZSTD_CLEVEL=1 zstd file -o file-1-env.zst -q
39*01826a49SYabin CuiZSTD_CLEVEL=+19 zstd file -o file-19-env.zst -q
40*01826a49SYabin CuiZSTD_CLEVEL=+99 zstd file -o file-99-env.zst -q
41*01826a49SYabin Cui
42*01826a49SYabin Cuicmp file-f10.zst file-f10-env.zst || die "Environment variable failed to set level"
43*01826a49SYabin Cuicmp file-1.zst file-1-env.zst || die "Environment variable failed to set level"
44*01826a49SYabin Cuicmp file-19.zst file-19-env.zst || die "Environment variable failed to set level"
45*01826a49SYabin Cuicmp file-99.zst file-99-env.zst || die "Environment variable failed to set level"
46*01826a49SYabin Cui
47*01826a49SYabin Cui# Test invalid environment clevel is the default level
48*01826a49SYabin Cuizstd -f file -q
49*01826a49SYabin CuiZSTD_CLEVEL=- zstd -f file -o file-env.zst -q      ; cmp file.zst file-env.zst
50*01826a49SYabin CuiZSTD_CLEVEL=+ zstd -f file -o file-env.zst -q      ; cmp file.zst file-env.zst
51*01826a49SYabin CuiZSTD_CLEVEL=a zstd -f file -o file-env.zst -q      ; cmp file.zst file-env.zst
52*01826a49SYabin CuiZSTD_CLEVEL=-a zstd -f file -o file-env.zst -q     ; cmp file.zst file-env.zst
53*01826a49SYabin CuiZSTD_CLEVEL=+a zstd -f file -o file-env.zst -q     ; cmp file.zst file-env.zst
54*01826a49SYabin CuiZSTD_CLEVEL=3a7 zstd -f file -o file-env.zst -q    ; cmp file.zst file-env.zst
55*01826a49SYabin CuiZSTD_CLEVEL=5000000000 zstd -f file -o file-env.zst -q ; cmp file.zst file-env.zst
56*01826a49SYabin Cui
57*01826a49SYabin Cui# Test environment clevel is overridden by command line
58*01826a49SYabin CuiZSTD_CLEVEL=10 zstd -f file -1 -o file-1-env.zst -q
59*01826a49SYabin CuiZSTD_CLEVEL=10 zstd -f file --fast=1 -o file-f1-env.zst -q
60*01826a49SYabin Cui
61*01826a49SYabin Cuicmp file-1.zst file-1-env.zst  || die "Environment variable not overridden"
62*01826a49SYabin Cuicmp file-f1.zst file-f1-env.zst || die "Environment variable not overridden"
63