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