2 """Test LZ4 interoperability between versions"""
18 repo_url =
'https://github.com/lz4/lz4.git'
19 tmp_dir_name =
'tests/versionsTest'
22 test_dat_src =
'README.md'
26 def proc(cmd_args, pipe=True, dummy=False):
30 subproc = subprocess.Popen(cmd_args,
31 stdout=subprocess.PIPE,
32 stderr=subprocess.PIPE)
34 subproc = subprocess.Popen(cmd_args)
35 return subproc.communicate()
38 return proc([make_cmd] + args, pipe)
40 def git(args, pipe=True):
41 return proc([git_cmd] + args, pipe)
44 stdout, stderr =
git([
'tag',
'-l',
'r[0-9][0-9][0-9]'])
45 tags = stdout.decode(
'utf-8').split()
46 stdout, stderr =
git([
'tag',
'-l',
'v[1-9].[0-9].[0-9]'])
47 tags += stdout.decode(
'utf-8').split()
52 with open(filepath,
'rb')
as f:
53 return hashlib.sha1(f.read()).hexdigest()
55 if __name__ ==
'__main__':
57 base_dir = os.getcwd() +
'/..'
58 tmp_dir = base_dir +
'/' + tmp_dir_name
59 clone_dir = tmp_dir +
'/' +
'lz4'
60 programs_dir = base_dir +
'/programs'
61 os.makedirs(tmp_dir, exist_ok=
True)
64 if not os.path.isdir(clone_dir):
65 git([
'clone', repo_url, clone_dir])
67 shutil.copy2(base_dir +
'/' + test_dat_src, tmp_dir +
'/' + test_dat)
70 print(
'Retrieve all release tags :')
78 dst_lz4c =
'{}/lz4c.{}' .format(tmp_dir, tag)
79 dst_lz4c32 =
'{}/lz4c32.{}'.format(tmp_dir, tag)
80 if not os.path.isfile(dst_lz4c)
or not os.path.isfile(dst_lz4c32)
or tag == head:
82 r_dir =
'{}/{}'.format(tmp_dir, tag)
83 os.makedirs(r_dir, exist_ok=
True)
85 git([
'--work-tree=' + r_dir,
'checkout', tag,
'--',
'.'],
False)
86 os.chdir(r_dir +
'/programs')
88 os.chdir(programs_dir)
89 make([
'clean',
'lz4c'],
False)
90 shutil.copy2(
'lz4c', dst_lz4c)
91 make([
'clean',
'lz4c32'],
False)
92 shutil.copy2(
'lz4c32', dst_lz4c32)
95 print(
'Compress test.dat by all released lz4c and lz4c32')
97 for lz4
in glob.glob(
"*.lz4"):
100 proc([
'./lz4c.' + tag,
'-1fz', test_dat, test_dat +
'_1_64_' + tag +
'.lz4'])
101 proc([
'./lz4c.' + tag,
'-9fz', test_dat, test_dat +
'_9_64_' + tag +
'.lz4'])
102 proc([
'./lz4c32.' + tag,
'-1fz', test_dat, test_dat +
'_1_32_' + tag +
'.lz4'])
103 proc([
'./lz4c32.' + tag,
'-9fz', test_dat, test_dat +
'_9_32_' + tag +
'.lz4'])
105 print(
'Full list of compressed files')
106 lz4s = sorted(glob.glob(
'*.lz4'))
108 print(lz4 +
' : ' + repr(os.path.getsize(lz4)))
112 print(
'Duplicated files')
113 lz4s = sorted(glob.glob(
'*.lz4'))
114 for i, lz4
in enumerate(lz4s):
115 if not os.path.isfile(lz4):
119 if not os.path.isfile(lz4t):
121 if filecmp.cmp(lz4, lz4t):
123 print(
'{} == {}'.format(lz4, lz4t))
125 print(
'Enumerate only different compressed files')
126 lz4s = sorted(glob.glob(
'*.lz4'))
128 print(lz4 +
' : ' + repr(os.path.getsize(lz4)) +
', ' +
sha1_of_file(lz4))
131 print(
'Decompression tests and verifications')
132 lz4s = sorted(glob.glob(
'*.lz4'))
133 for dec
in glob.glob(
"*.dec"):
139 proc([
'./lz4c.' + tag,
'-df', lz4, lz4 +
'_d64_' + tag +
'.dec'])
140 proc([
'./lz4c32.' + tag,
'-df', lz4, lz4 +
'_d32_' + tag +
'.dec'])
144 decs = glob.glob(
'*.dec')
146 if not filecmp.cmp(dec, test_dat):
147 print(
'ERR : ' + dec)
def make(args, pipe=True)
def sha1_of_file(filepath)
def proc(cmd_args, pipe=True, dummy=False)