103 lines · python
1#!/usr/bin/env python32 3# Automatically formatted with yapf (https://github.com/google/yapf)4 5import subprocess6import unittest7 8 9def getFinalPasses(run):10 stdout = run.stdout.decode()11 stdout = stdout[: stdout.rfind("\n")]12 stdout = stdout[stdout.rfind("\n") + 1 :]13 return stdout14 15 16class Test(unittest.TestCase):17 def test_0(self):18 """Test all passes are removed except those required to crash. Verify19 that PM structure is intact."""20 run_args = [21 "./utils/reduce_pipeline.py",22 "--opt-binary=./utils/reduce_pipeline_test/fake_opt.py",23 "--input=/dev/null",24 "--passes=a,b,c,A(d,B(e,f),g),h,i",25 "-crash-seq=b,d,f",26 ]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))"')30 31 def test_1(self):32 """Test all passes are removed except those required to crash. The33 required passes in this case are the first and last in that order34 (a bit of a corner-case for the reduction algorithm)."""35 run_args = [36 "./utils/reduce_pipeline.py",37 "--opt-binary=./utils/reduce_pipeline_test/fake_opt.py",38 "--input=/dev/null",39 "--passes=a,b,c,A(d,B(e,f),g),h,i",40 "-crash-seq=a,i",41 ]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"')45 46 def test_2_0(self):47 """Test expansion of EXPAND_a_to_f (expands into 'a,b,c,d,e,f')."""48 run_args = [49 "./utils/reduce_pipeline.py",50 "--opt-binary=./utils/reduce_pipeline_test/fake_opt.py",51 "--input=/dev/null",52 "--passes=EXPAND_a_to_f",53 "-crash-seq=b,e",54 ]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"')58 59 def test_2_1(self):60 """Test EXPAND_a_to_f and the '--dont-expand-passes' option."""61 run_args = [62 "./utils/reduce_pipeline.py",63 "--opt-binary=./utils/reduce_pipeline_test/fake_opt.py",64 "--input=/dev/null",65 "--passes=EXPAND_a_to_f",66 "-crash-seq=EXPAND_a_to_f",67 "--dont-expand-passes",68 ]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"')72 73 def test_3(self):74 """Test that empty pass-managers get removed by default."""75 run_args = [76 "./utils/reduce_pipeline.py",77 "--opt-binary=./utils/reduce_pipeline_test/fake_opt.py",78 "--input=/dev/null",79 "--passes=a,b,c,A(d,B(e,f),g),h,i",80 "-crash-seq=b,d,h",81 ]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"')85 86 def test_4(self):87 """Test the '--dont-remove-empty-pm' option."""88 run_args = [89 "./utils/reduce_pipeline.py",90 "--opt-binary=./utils/reduce_pipeline_test/fake_opt.py",91 "--input=/dev/null",92 "--passes=a,b,c,A(d,B(e,f),g),h,i",93 "-crash-seq=b,d,h",94 "--dont-remove-empty-pm",95 ]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"')99 100 101unittest.main()102exit(0)103