3 # Automatically formatted with yapf (https://github.com/google/yapf)
9 def getFinalPasses(run
):
10 stdout
= run
.stdout
.decode()
11 stdout
= stdout
[: stdout
.rfind("\n")]
12 stdout
= stdout
[stdout
.rfind("\n") + 1 :]
16 class Test(unittest
.TestCase
):
18 """Test all passes are removed except those required to crash. Verify
19 that PM structure is intact."""
21 "./utils/reduce_pipeline.py",
22 "--opt-binary=./utils/reduce_pipeline_test/fake_opt.py",
24 "--passes=a,b,c,A(d,B(e,f),g),h,i",
27 run
= subprocess
.run(run_args
, stdout
=subprocess
.PIPE
, stderr
=subprocess
.PIPE
)
28 self
.assertEqual(run
.returncode
, 0)
29 self
.assertEqual(getFinalPasses(run
), '-passes="b,A(d,B(f))"')
32 """Test all passes are removed except those required to crash. The
33 required passes in this case are the first and last in that order
34 (a bit of a corner-case for the reduction algorithm)."""
36 "./utils/reduce_pipeline.py",
37 "--opt-binary=./utils/reduce_pipeline_test/fake_opt.py",
39 "--passes=a,b,c,A(d,B(e,f),g),h,i",
42 run
= subprocess
.run(run_args
, stdout
=subprocess
.PIPE
, stderr
=subprocess
.PIPE
)
43 self
.assertEqual(run
.returncode
, 0)
44 self
.assertEqual(getFinalPasses(run
), '-passes="a,i"')
47 """Test expansion of EXPAND_a_to_f (expands into 'a,b,c,d,e,f')."""
49 "./utils/reduce_pipeline.py",
50 "--opt-binary=./utils/reduce_pipeline_test/fake_opt.py",
52 "--passes=EXPAND_a_to_f",
55 run
= subprocess
.run(run_args
, stdout
=subprocess
.PIPE
, stderr
=subprocess
.PIPE
)
56 self
.assertEqual(run
.returncode
, 0)
57 self
.assertEqual(getFinalPasses(run
), '-passes="b,e"')
60 """Test EXPAND_a_to_f and the '--dont-expand-passes' option."""
62 "./utils/reduce_pipeline.py",
63 "--opt-binary=./utils/reduce_pipeline_test/fake_opt.py",
65 "--passes=EXPAND_a_to_f",
66 "-crash-seq=EXPAND_a_to_f",
67 "--dont-expand-passes",
69 run
= subprocess
.run(run_args
, stdout
=subprocess
.PIPE
, stderr
=subprocess
.PIPE
)
70 self
.assertEqual(run
.returncode
, 0)
71 self
.assertEqual(getFinalPasses(run
), '-passes="EXPAND_a_to_f"')
74 """Test that empty pass-managers get removed by default."""
76 "./utils/reduce_pipeline.py",
77 "--opt-binary=./utils/reduce_pipeline_test/fake_opt.py",
79 "--passes=a,b,c,A(d,B(e,f),g),h,i",
82 run
= subprocess
.run(run_args
, stdout
=subprocess
.PIPE
, stderr
=subprocess
.PIPE
)
83 self
.assertEqual(run
.returncode
, 0)
84 self
.assertEqual(getFinalPasses(run
), '-passes="b,A(d),h"')
87 """Test the '--dont-remove-empty-pm' option."""
89 "./utils/reduce_pipeline.py",
90 "--opt-binary=./utils/reduce_pipeline_test/fake_opt.py",
92 "--passes=a,b,c,A(d,B(e,f),g),h,i",
94 "--dont-remove-empty-pm",
96 run
= subprocess
.run(run_args
, stdout
=subprocess
.PIPE
, stderr
=subprocess
.PIPE
)
97 self
.assertEqual(run
.returncode
, 0)
98 self
.assertEqual(getFinalPasses(run
), '-passes="b,A(d,B()),h"')