Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tests] Fix version test determinism #3422

Merged
merged 1 commit into from
Jan 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions tests/test-zstd-versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,19 @@
test_dat = 'test_dat'
head = 'vdevel'
dict_source = 'dict_source'
dict_files = './zstd/programs/*.c ./zstd/lib/common/*.c ./zstd/lib/compress/*.c ./zstd/lib/decompress/*.c ./zstd/lib/dictBuilder/*.c ./zstd/lib/legacy/*.c '
dict_files += './zstd/programs/*.h ./zstd/lib/common/*.h ./zstd/lib/compress/*.h ./zstd/lib/dictBuilder/*.h ./zstd/lib/legacy/*.h'
dict_globs = [
'programs/*.c',
'lib/common/*.c',
'lib/compress/*.c',
'lib/decompress/*.c',
'lib/dictBuilder/*.c',
'lib/legacy/*.c',
'programs/*.h',
'lib/common/*.h',
'lib/compress/*.h',
'lib/dictBuilder/*.h',
'lib/legacy/*.h'
]


def execute(command, print_output=False, print_error=True, param_shell=False):
Expand Down Expand Up @@ -85,6 +96,7 @@ def create_dict(tag, dict_source_path):
result = execute('./zstd.' + tag + ' -f --train ' + ' '.join(cFiles) + ' ' + ' '.join(hFiles) + ' -o ' + dict_name, print_output=False, param_shell=True)
if result == 0:
print(dict_name + ' created')
assert os.path.isfile(dict_name)
else:
raise RuntimeError('ERROR: creating of ' + dict_name + ' failed')
else:
Expand All @@ -103,12 +115,15 @@ def zstd(tag, args, input_file, output_file):
print("Running: '{}', input={}, output={}" .format(
' '.join(cmd), input_file, output_file
))
subprocess.check_call(cmd, stdin=i, stdout=o)
result = subprocess.run(cmd, stdin=i, stdout=o, stderr=subprocess.PIPE)
print("Stderr: {}".format(result.stderr.decode("ascii")))
result.check_returncode()


def dict_compress_sample(tag, sample):
dict_name = 'dict.' + tag
zstd(tag, ['-D', dict_name, '-1'], sample, sample + '_01_64_' + tag + '_dictio.zst')
verbose = ['-v', '-v', '-v']
zstd(tag, ['-D', dict_name, '-1'] + verbose, sample, sample + '_01_64_' + tag + '_dictio.zst')
zstd(tag, ['-D', dict_name, '-3'], sample, sample + '_03_64_' + tag + '_dictio.zst')
zstd(tag, ['-D', dict_name, '-5'], sample, sample + '_05_64_' + tag + '_dictio.zst')
zstd(tag, ['-D', dict_name, '-9'], sample, sample + '_09_64_' + tag + '_dictio.zst')
Expand Down Expand Up @@ -246,8 +261,12 @@ def decompress_dict(tag):
# copy *.c and *.h to a temporary directory ("dict_source")
if not os.path.isdir(dict_source_path):
os.mkdir(dict_source_path)
print('cp ' + dict_files + ' ' + dict_source_path)
execute('cp ' + dict_files + ' ' + dict_source_path, param_shell=True)
for dict_glob in dict_globs:
files = glob.glob(dict_glob, root_dir=base_dir)
for file in files:
file = os.path.join(base_dir, file)
print("copying " + file + " to " + dict_source_path)
shutil.copy(file, dict_source_path)

print('-----------------------------------------------')
print('Compress test.dat by all released zstd')
Expand Down