-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmacrunner.py
91 lines (73 loc) · 2.24 KB
/
macrunner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import datetime
import glob
import os
import shutil
import signal
import subprocess
import sys
import time
from typing import List
from baserunner import Runner, main
class MacRunner(Runner):
"""
Mac runner
"""
def __init__(self, path: str, args: List[str], **kwargs):
super().__init__(path, args, **kwargs)
self.lldb_path = shutil.which('lldb')
if not self.lldb_path:
raise Exception('Could not find lldb')
@classmethod
def get_dump_dir(cls) -> str:
return '/cores'
@classmethod
def get_dump_pattern(cls) -> str:
"""
Get file pattern to find dump files
"""
return "core.*"
@classmethod
def install(cls):
# This is equal to "ulimit -c unlimited"
import resource
val1, val2 = resource.getrlimit(resource.RLIMIT_CORE)
if val1!=resource.RLIM_INFINITY or val2!=resource.RLIM_INFINITY:
cls.info('Setting ulimit -c..')
resource.setrlimit(resource.RLIMIT_CORE,
(resource.RLIM_INFINITY, resource.RLIM_INFINITY))
# Find lldb
errors = []
lldb_path = shutil.which('lldb')
if not lldb_path:
errors.append('Could not find lldb')
if errors:
cls.err('ERROR: ' + ' '.join(errors))
sys.exit(1)
cls.info('Running infrastructure is ready')
#os.system('echo "ulimit -c : `ulimit -c`"')
def warmup(self):
"""
This will be called before run()
"""
self.install()
def get_dump_path(self) -> str:
dump_dir = self.get_dump_dir()
dump_file = f'core.{self.popen.pid}'
return os.path.join(dump_dir, dump_file)
def terminate(self):
"""
Terminate a process and generate dump file
"""
time.sleep(1)
os.kill(self.popen.pid, signal.SIGQUIT)
def process_crash(self):
"""
Process dump file.
"""
cmd = f'''{self.lldb_path} --core {self.get_dump_path()} ''' + \
f'''-o 'bt all' -o quit ''' + \
f'''{self.path}'''
self.info(cmd)
os.system(cmd)
if __name__ == '__main__':
main(MacRunner)