3 # Automatically formatted with yapf (https://github.com/google/yapf)
5 # Fake 'opt' program that can be made to crash on request. For testing
6 # the 'reduce_pipeline.py' automatic 'opt' NPM pipeline reducer.
13 parser
= argparse
.ArgumentParser()
14 parser
.add_argument("-passes", action
="store", dest
="passes", required
=True)
16 "-print-pipeline-passes", dest
="print_pipeline_passes", action
="store_true"
18 parser
.add_argument("-crash-seq", action
="store", dest
="crash_seq", required
=True)
19 parser
.add_argument("-o", action
="store", dest
="output")
20 parser
.add_argument("input")
21 [args
, unknown_args
] = parser
.parse_known_args()
23 # Expand pipeline if '-print-pipeline-passes'.
24 if args
.print_pipeline_passes
:
25 if args
.passes
== "EXPAND_a_to_f":
34 for c
in args
.crash_seq
:
45 # Parse '-passes' and see if we need to crash.
49 if len(crash_seq
) > 0 and crash_seq
[0] == tok
:
55 if len(crash_seq
) > 0 and crash_seq
[0] == tok
:
60 if len(crash_seq
) > 0 and crash_seq
[0] == tok
:
63 # Copy input to output.
65 shutil
.copy(args
.input, args
.output
)
67 # Crash if all 'crash_seq' passes occurred in right order.
68 if len(crash_seq
) == 0:
70 os
.kill(os
.getpid(), signal
.SIGKILL
)