import subprocess
import unittest
def getFinalPasses(run):
stdout = run.stdout.decode()
stdout = stdout[:stdout.rfind('\n')]
stdout = stdout[stdout.rfind('\n') + 1:]
return stdout
class Test(unittest.TestCase):
def test_0(self):
run_args = [
'./utils/reduce_pipeline.py',
'--opt-binary=./utils/reduce_pipeline_test/fake_opt.py',
'--input=/dev/null', '--passes=a,b,c,A(d,B(e,f),g),h,i',
'-crash-seq=b,d,f'
]
run = subprocess.run(run_args,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
self.assertEqual(run.returncode, 0)
self.assertEqual(getFinalPasses(run), '-passes="b,A(d,B(f))"')
def test_1(self):
run_args = [
'./utils/reduce_pipeline.py',
'--opt-binary=./utils/reduce_pipeline_test/fake_opt.py',
'--input=/dev/null', '--passes=a,b,c,A(d,B(e,f),g),h,i',
'-crash-seq=a,i'
]
run = subprocess.run(run_args,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
self.assertEqual(run.returncode, 0)
self.assertEqual(getFinalPasses(run), '-passes="a,i"')
def test_2_0(self):
run_args = [
'./utils/reduce_pipeline.py',
'--opt-binary=./utils/reduce_pipeline_test/fake_opt.py',
'--input=/dev/null', '--passes=EXPAND_a_to_f', '-crash-seq=b,e'
]
run = subprocess.run(run_args,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
self.assertEqual(run.returncode, 0)
self.assertEqual(getFinalPasses(run), '-passes="b,e"')
def test_2_1(self):
run_args = [
'./utils/reduce_pipeline.py',
'--opt-binary=./utils/reduce_pipeline_test/fake_opt.py',
'--input=/dev/null', '--passes=EXPAND_a_to_f',
'-crash-seq=EXPAND_a_to_f', '--dont-expand-passes'
]
run = subprocess.run(run_args,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
self.assertEqual(run.returncode, 0)
self.assertEqual(getFinalPasses(run), '-passes="EXPAND_a_to_f"')
def test_3(self):
run_args = [
'./utils/reduce_pipeline.py',
'--opt-binary=./utils/reduce_pipeline_test/fake_opt.py',
'--input=/dev/null', '--passes=a,b,c,A(d,B(e,f),g),h,i',
'-crash-seq=b,d,h'
]
run = subprocess.run(run_args,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
self.assertEqual(run.returncode, 0)
self.assertEqual(getFinalPasses(run), '-passes="b,A(d),h"')
def test_4(self):
run_args = [
'./utils/reduce_pipeline.py',
'--opt-binary=./utils/reduce_pipeline_test/fake_opt.py',
'--input=/dev/null', '--passes=a,b,c,A(d,B(e,f),g),h,i',
'-crash-seq=b,d,h', '--dont-remove-empty-pm'
]
run = subprocess.run(run_args,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
self.assertEqual(run.returncode, 0)
self.assertEqual(getFinalPasses(run), '-passes="b,A(d,B()),h"')
unittest.main()
exit(0)