Repository navigation
Expand file tree
/
Copy pathcommand_line_test.py
More file actions
274 lines (231 loc) · 14.1 KB
/
Copy pathcommand_line_test.py
File metadata and controls
274 lines (231 loc) · 14.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
import os
import unittest
import subprocess
from vmaf.config import VmafConfig
from vmaf.tools.misc import run_process
from vmaf import ExternalProgram
__copyright__ = "Copyright 2016-2020, Netflix, Inc."
__license__ = "BSD+Patent"
class RunProcessTest(unittest.TestCase):
def test_run_process(self):
ret = run_process('echo hello', shell=True)
self.assertEqual(ret, 0)
def test_run_process_false_cmd(self):
with self.assertRaises(AssertionError) as e:
run_process('echoo hello', shell=True)
self.assertTrue('Process returned 127, cmd: echoo hello' in e.exception.args[0])
self.assertTrue('not found' in e.exception.args[0])
class CommandLineTest(unittest.TestCase):
def setUp(self):
self.dataset_filename = VmafConfig.test_resource_path('example_dataset.py')
self.raw_dataset_filename = VmafConfig.test_resource_path('example_raw_dataset.py')
self.out_model_filepath = VmafConfig.workdir_path('tmp.pkl')
self.param_filename = VmafConfig.test_resource_path('vmaf_v4.py')
self.batch_filename = VmafConfig.workdir_path('test_batch_input')
def tearDown(self):
if os.path.exists(self.out_model_filepath):
os.remove(self.out_model_filepath)
if os.path.exists(self.out_model_filepath + '.model'):
os.remove(self.out_model_filepath + '.model')
if os.path.exists(self.batch_filename):
os.remove(self.batch_filename)
def test_run_testing_vmaf(self):
exe = VmafConfig.root_path('python', 'vmaf', 'script', 'run_testing.py')
cmd = "{exe} VMAF {dataset} --parallelize --suppress-plot".format(
exe=exe, dataset=self.dataset_filename)
ret = run_process(cmd, shell=True)
self.assertEqual(ret, 0)
def test_run_testing_vmaf_raw_dataset(self):
exe = VmafConfig.root_path('python', 'vmaf', 'script', 'run_testing.py')
cmd = "{exe} VMAF {dataset} --parallelize --suppress-plot".format(
exe=exe, dataset=self.raw_dataset_filename)
ret = run_process(cmd, shell=True)
self.assertEqual(ret, 0)
def test_run_testing_psnr(self):
exe = VmafConfig.root_path('python', 'vmaf', 'script', 'run_testing.py')
cmd = "{exe} PSNR {dataset} --parallelize --suppress-plot".format(
exe=exe, dataset=self.dataset_filename)
ret = run_process(cmd, shell=True)
self.assertEqual(ret, 0)
def test_run_vmaf_training(self):
exe = VmafConfig.root_path('python', 'vmaf', 'script', 'run_vmaf_training.py')
cmd = "{exe} {dataset} {param} {param} {output} --parallelize --suppress-plot".format(
exe=exe,
dataset=self.dataset_filename,
param=self.param_filename,
output=self.out_model_filepath)
ret = run_process(cmd, shell=True)
self.assertEqual(ret, 0)
def test_run_vmaf_training_raw_dataset(self):
exe = VmafConfig.root_path('python', 'vmaf', 'script', 'run_vmaf_training.py')
cmd = "{exe} {dataset} {param} {param} {output} --parallelize --suppress-plot".format(
exe=exe,
dataset=self.raw_dataset_filename,
param=self.param_filename,
output=self.out_model_filepath)
ret = run_process(cmd, shell=True)
self.assertEqual(ret, 0)
def test_run_vmaf_in_batch(self):
line = 'yuv420p 576 324 {root}/python/test/resource/yuv/src01_hrc00_576x324.yuv ' \
'{root}/python/test/resource/yuv/src01_hrc01_576x324.yuv'.format(root=VmafConfig.root_path())
cmd = 'echo "{line}" > {batch_filename}'.format(
line=line, batch_filename=self.batch_filename)
ret = run_process(cmd, shell=True)
self.assertEqual(ret, 0)
exe = VmafConfig.root_path('python', 'vmaf', 'script', 'run_vmaf_in_batch.py')
cmd = "{exe} {input} --parallelize >/dev/null 2>&1".format(
exe=exe, input=self.batch_filename)
ret = run_process(cmd, shell=True)
self.assertEqual(ret, 0)
def test_run_vmaf_in_batch_ci(self):
line = 'yuv420p 576 324 {root}/python/test/resource/yuv/src01_hrc00_576x324.yuv ' \
'{root}/python/test/resource/yuv/src01_hrc01_576x324.yuv'.format(root=VmafConfig.root_path())
cmd = 'echo "{line}" > {batch_filename}'.format(
line=line, batch_filename=self.batch_filename)
ret = run_process(cmd, shell=True)
self.assertEqual(ret, 0)
exe = VmafConfig.root_path('python', 'vmaf', 'script', 'run_vmaf_in_batch.py')
cmd = "{exe} {input} --parallelize --ci >/dev/null 2>&1".format(
exe=exe, input=self.batch_filename)
ret = run_process(cmd, shell=True)
self.assertEqual(ret, 0)
def test_run_vmaf(self):
exe = VmafConfig.root_path('python', 'vmaf', 'script', 'run_vmaf.py')
line = 'yuv420p 576 324 {root}/python/test/resource/yuv/src01_hrc00_576x324.yuv ' \
'{root}/python/test/resource/yuv/src01_hrc01_576x324.yuv'.format(root=VmafConfig.root_path())
cmd = "{exe} {line} >/dev/null 2>&1".format(line=line, exe=exe)
ret = run_process(cmd, shell=True)
self.assertEqual(ret, 0)
def test_run_vmaf_ci(self):
exe = VmafConfig.root_path('python', 'vmaf', 'script', 'run_vmaf.py')
line = 'yuv420p 576 324 {root}/python/test/resource/yuv/src01_hrc00_576x324.yuv ' \
'{root}/python/test/resource/yuv/src01_hrc01_576x324.yuv'.format(root=VmafConfig.root_path())
cmd = "{exe} {line} --ci >/dev/null 2>&1".format(line=line, exe=exe)
ret = run_process(cmd, shell=True)
self.assertEqual(ret, 0)
def test_run_vmaf_both_local_explain_and_ci(self):
exe = VmafConfig.root_path('python', 'vmaf', 'script', 'run_vmaf.py')
line = 'yuv420p 576 324 {root}/python/test/resource/yuv/src01_hrc00_576x324.yuv ' \
'{root}/python/test/resource/yuv/src01_hrc01_576x324.yuv'.format(root=VmafConfig.root_path())
cmd = "{exe} {line} --local-explain --ci >/dev/null 2>&1".format(line=line, exe=exe)
ret = subprocess.call(cmd, shell=True)
self.assertEqual(ret, 2)
def test_run_psnr(self):
exe = VmafConfig.root_path('python', 'vmaf', 'script', 'run_psnr.py')
line = 'yuv420p 576 324 {root}/python/test/resource/yuv/src01_hrc00_576x324.yuv ' \
'{root}/python/test/resource/yuv/src01_hrc01_576x324.yuv'.format(root=VmafConfig.root_path())
cmd = "{exe} {line} >/dev/null 2>&1".format(line=line, exe=exe)
ret = run_process(cmd, shell=True)
self.assertEqual(ret, 0)
def test_run_cleaning_cache_psnr(self):
exe = VmafConfig.root_path('python', 'vmaf', 'script', 'run_testing.py')
cmd = "{exe} PSNR {dataset} --parallelize --cache-result --suppress-plot".format(
exe=exe, dataset=self.dataset_filename)
ret = run_process(cmd, shell=True)
self.assertEqual(ret, 0)
exe = VmafConfig.root_path('python', 'vmaf', 'script', 'run_cleaning_cache.py')
cmd = "{exe} PSNR {dataset}".format(
exe=exe, dataset=self.dataset_filename)
ret = run_process(cmd, shell=True)
self.assertEqual(ret, 0)
class VmafossexecCommandLineTest(unittest.TestCase):
RC_SUCCESS = 0
RC_VMAF_EXCEPTION = 256 - 2
RC_RUNTIME_ERROR = 256 - 3
RC_LOGIC_ERROR = 256 - 4
RC_SEGMENTATION_FAULT = 139
RC_ARGUMENT_ISSUE = 1
RC_MORE_ARGUMENT_ISSUE = 256 - 1
def test_run_vmafossexec(self):
exe = ExternalProgram.vmafossexec
cmd = "{exe} yuv420p 576 324 {ref} {dis} {model} --thread 1 --subsample 2".format(
exe=exe, ref=VmafConfig.test_resource_path("yuv", "src01_hrc00_576x324.yuv"),
dis=VmafConfig.test_resource_path("yuv", "src01_hrc01_576x324.yuv"), model=VmafConfig.model_path("other_models", "vmaf_v0.6.0.pkl"))
ret = subprocess.call(cmd, shell=True)
self.assertEqual(ret, self.RC_SUCCESS)
def test_run_vmafossexec_nonexist_model_file(self):
exe = ExternalProgram.vmafossexec
cmd = "{exe} yuv420p 576 324 {ref} {dis} {model} > /dev/null 2>&1".format(
exe=exe, ref=VmafConfig.test_resource_path("yuv", "src01_hrc00_576x324.yuv"),
dis=VmafConfig.test_resource_path("yuv", "src01_hrc01_576x324.yuv"), model=VmafConfig.model_path("other_models", "vmaf_v0.6.0.pkl_XXX"))
ret = subprocess.call(cmd, shell=True)
self.assertEqual(ret, self.RC_VMAF_EXCEPTION)
def test_run_vmafossexec_wrong_model_fmt(self):
exe = ExternalProgram.vmafossexec
cmd = "{exe} yuv420p 576 324 {ref} {dis} {model} > /dev/null 2>&1".format(
exe=exe, ref=VmafConfig.test_resource_path("yuv", "src01_hrc00_576x324.yuv"),
dis=VmafConfig.test_resource_path("yuv", "src01_hrc01_576x324.yuv"), model=VmafConfig.model_path("other_models", "vmaf_v0.6.0.pkl.model"))
ret = subprocess.call(cmd, shell=True)
self.assertEqual(ret, self.RC_LOGIC_ERROR)
def test_run_vmafossexec_nonexist_ref_file(self):
exe = ExternalProgram.vmafossexec
cmd = "{exe} yuv420p 576 324 {ref} {dis} {model} > /dev/null 2>&1".format(
exe=exe, ref=VmafConfig.resource_path("yuv", "src01_hrc00_576x324_XXX.yuv"),
dis=VmafConfig.test_resource_path("yuv", "src01_hrc01_576x324.yuv"), model=VmafConfig.model_path("other_models", "vmaf_v0.6.0.pkl"))
ret = subprocess.call(cmd, shell=True)
self.assertEqual(ret, self.RC_ARGUMENT_ISSUE)
def test_run_vmafossexec_nonexist_dis_file(self):
exe = ExternalProgram.vmafossexec
cmd = "{exe} yuv420p 576 324 {ref} {dis} {model} > /dev/null 2>&1".format(
exe=exe, ref=VmafConfig.test_resource_path("yuv", "src01_hrc00_576x324.yuv"),
dis=VmafConfig.resource_path("yuv", "src01_hrc01_576x324_XXX.yuv"), model=VmafConfig.model_path("other_models", "vmaf_v0.6.0.pkl"))
ret = subprocess.call(cmd, shell=True)
self.assertEqual(ret, self.RC_ARGUMENT_ISSUE)
def test_run_vmafossexec_unknown_yuv_fmt(self):
exe = ExternalProgram.vmafossexec
cmd = "{exe} yuv420p_XXX 576 324 {ref} {dis} {model} > /dev/null 2>&1".format(
exe=exe, ref=VmafConfig.test_resource_path("yuv", "src01_hrc00_576x324.yuv"),
dis=VmafConfig.test_resource_path("yuv", "src01_hrc01_576x324.yuv"), model=VmafConfig.model_path("other_models", "vmaf_v0.6.0.pkl"))
ret = subprocess.call(cmd, shell=True)
self.assertEqual(ret, self.RC_ARGUMENT_ISSUE)
def test_run_vmafossexec_odd_resolution(self):
exe = ExternalProgram.vmafossexec
cmd = "{exe} yuv420p 575 323 {ref} {dis} {model} > /dev/null 2>&1".format(
exe=exe, ref=VmafConfig.test_resource_path("yuv", "src01_hrc00_576x324.yuv"),
dis=VmafConfig.test_resource_path("yuv", "src01_hrc01_576x324.yuv"), model=VmafConfig.model_path("other_models", "vmaf_v0.6.0.pkl"))
ret = subprocess.call(cmd, shell=True)
self.assertEqual(ret, self.RC_ARGUMENT_ISSUE)
def test_run_vmafossexec_wrong_wh_format(self):
exe = ExternalProgram.vmafossexec
cmd = "{exe} yuv420p 576 abc {ref} {dis} {model} > /dev/null 2>&1".format(
exe=exe, ref=VmafConfig.test_resource_path("yuv", "src01_hrc00_576x324.yuv"),
dis=VmafConfig.test_resource_path("yuv", "src01_hrc01_576x324.yuv"), model=VmafConfig.model_path("other_models", "vmaf_v0.6.0.pkl"))
ret = subprocess.call(cmd, shell=True)
self.assertEqual(ret, self.RC_MORE_ARGUMENT_ISSUE)
def test_run_vmafossexec_wrong_width_value(self):
exe = ExternalProgram.vmafossexec
cmd = "{exe} yuv420p 0 324 {ref} {dis} {model} > /dev/null 2>&1".format(
exe=exe, ref=VmafConfig.test_resource_path("yuv", "src01_hrc00_576x324.yuv"),
dis=VmafConfig.test_resource_path("yuv", "src01_hrc01_576x324.yuv"), model=VmafConfig.model_path("other_models", "vmaf_v0.6.0.pkl"))
ret = subprocess.call(cmd, shell=True)
self.assertEqual(ret, self.RC_MORE_ARGUMENT_ISSUE)
def test_run_vmafossexec_unknown_log_fmt(self):
exe = ExternalProgram.vmafossexec
cmd = "{exe} yuv420p 576 324 {ref} {dis} {model} --log-fmt xml_XXX > /dev/null 2>&1".format(
exe=exe, ref=VmafConfig.test_resource_path("yuv", "src01_hrc00_576x324.yuv"),
dis=VmafConfig.test_resource_path("yuv", "src01_hrc01_576x324.yuv"), model=VmafConfig.model_path("other_models", "vmaf_v0.6.0.pkl"))
ret = subprocess.call(cmd, shell=True)
self.assertEqual(ret, self.RC_MORE_ARGUMENT_ISSUE)
def test_run_vmafossexec_unknown_pooling(self):
exe = ExternalProgram.vmafossexec
cmd = "{exe} yuv420p 576 324 {ref} {dis} {model} --pool mean_XXX > /dev/null 2>&1".format(
exe=exe, ref=VmafConfig.test_resource_path("yuv", "src01_hrc00_576x324.yuv"),
dis=VmafConfig.test_resource_path("yuv", "src01_hrc01_576x324.yuv"), model=VmafConfig.model_path("other_models", "vmaf_v0.6.0.pkl"))
ret = subprocess.call(cmd, shell=True)
self.assertEqual(ret, self.RC_MORE_ARGUMENT_ISSUE)
def test_run_vmafossexec_wrong_thread(self):
exe = ExternalProgram.vmafossexec
cmd = "{exe} yuv420p 576 324 {ref} {dis} {model} --thread -1 --subsample 2 > /dev/null 2>&1".format(
exe=exe, ref=VmafConfig.test_resource_path("yuv", "src01_hrc00_576x324.yuv"),
dis=VmafConfig.test_resource_path("yuv", "src01_hrc01_576x324.yuv"), model=VmafConfig.model_path("other_models", "vmaf_v0.6.0.pkl"))
ret = subprocess.call(cmd, shell=True)
self.assertEqual(ret, self.RC_MORE_ARGUMENT_ISSUE)
def test_run_vmafossexec_wrong_subsample(self):
exe = ExternalProgram.vmafossexec
cmd = "{exe} yuv420p 576 324 {ref} {dis} {model} --thread 0 --subsample 0 > /dev/null 2>&1".format(
exe=exe, ref=VmafConfig.test_resource_path("yuv", "src01_hrc00_576x324.yuv"),
dis=VmafConfig.test_resource_path("yuv", "src01_hrc01_576x324.yuv"), model=VmafConfig.model_path("other_models", "vmaf_v0.6.0.pkl"))
ret = subprocess.call(cmd, shell=True)
self.assertEqual(ret, self.RC_MORE_ARGUMENT_ISSUE)
if __name__ == '__main__':
unittest.main(verbosity=2)