Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / sanitizer_common / ios_commands / get_pid_from_output.py
blob6569762a5026c3c6fe9ef2de433a97d5c27ebe04
1 """
2 Parses the id of the process that ran with ASAN from the output logs.
3 """
4 import sys, argparse, re
7 def main():
8 parser = argparse.ArgumentParser()
9 parser.add_argument(
10 "--infile",
11 nargs="?",
12 type=argparse.FileType("r"),
13 default=sys.stdin,
14 help="The sanitizer output to get the pid from",
16 parser.add_argument(
17 "--outfile",
18 nargs="?",
19 type=argparse.FileType("r"),
20 default=sys.stdout,
21 help="Where to write the result",
23 args = parser.parse_args()
25 pid = process_file(args.infile)
26 args.outfile.write(pid)
27 args.infile.close()
28 args.outfile.close()
31 def process_file(infile):
32 # check first line is just ==== divider
33 first_line_pattern = re.compile(r"=*")
34 assert first_line_pattern.match(infile.readline())
36 # parse out pid from 2nd line
37 # `==PID==ERROR: SanitizerName: error-type on address...`
38 pid_pattern = re.compile(r"==([0-9]*)==ERROR:")
39 pid = pid_pattern.search(infile.readline()).group(1)
41 # ignore the rest
43 assert pid and pid.isdigit()
45 return pid
48 if __name__ == "__main__":
49 main()