This shows how to connect to reven launcher in python, using reven low level api.
And a sample use case using them.
6 from os.path
import basename
9 def open_project(hostname, project_id):
11 Open a project and returns a reven.Project handler to it.
12 @param hostname: hostname to join reven at
13 @param project_id: reven_api.project_id
14 @return a connected reven.Project or None
18 lc = reven_api.launcher_connection(hostname)
21 port = lc.project_details(project_id).reven_server.port
23 print "Project already running on port %s" % port
24 return reven.Project(hostname, port)
27 port = lc.server_launch(project_id)
29 print "Server not started"
32 print "Server started on port %s" % port
38 client = reven.Project(hostname, port)
41 except RuntimeError
as e:
46 def close_project(hostname, project_id):
48 Close a project (kill its running server).
49 @param hostname: hostname to join reven at
50 @param project_id: reven_api.project_id
54 lc = reven_api.launcher_connection(hostname)
57 port = lc.project_details(project_id).reven_server.port
61 if lc.project_details(project_id).reven_server.port:
62 print "Server not killed"
64 print "Project closed"
69 Print configuration of all available virtual machines.
70 @param lc: reven_api.launcher_connection
73 print "Available virtual machines:"
75 for vm
in lc.list_vms():
77 print "[%s]" % vm.name
78 print "vbox_name = %s" % vm.vbox_name
79 print "display = %s" % vm.display
81 print "dynamic_launch = %s" % vm.dynamic_launch
82 print "static_launch = %s" % vm.static_launch
83 print "stopper = %s" % vm.stopper
85 print "os = %s" % vm.os
86 print "segment = %s" % vm.segment
87 print "pdb_path = %s" % vm.pdb_path
89 print "vnc_password = %s" % vm.vnc_password
90 print "vnc_port = %s" % vm.vnc_port
96 @param lc: reven_api.launcher_connection
101 for user
in lc.list_users():
105 def list_projects_for_user(lc, user):
107 List all project for given user.
108 @param lc: reven_api.launcher_connection
109 @param user: username as string
112 print "Projects for user %s:" % user
114 for project
in lc.list_projects(user):
116 print "%s/%s" % (project.user, project.project)
118 def wait_end_of_scenario(lc, project_id):
120 Block until end of scenario generation.
121 @param lc: reven_api.launcher_connection
122 @param project_id: reven_api.project_id
123 @return True if generation is successful
127 progress = lc.project_scenario(project_id)
128 print progress.log_chunk
129 if not progress.is_generating:
135 return progress.is_successful
137 def generate_scenario(lc, project_id, vm, binary, args='', input_files=[], dump_at=''):
140 @param lc: reven_api.launcher_connection
141 @param project_id: reven.project_id
142 @param binary: binary filepath
143 @param args: arguments string for binary launch
144 @param input_files: list of additionnal input files
145 @param dump_at: symbol name or address in binary, start scenario generation when reached
149 binary_name = basename(binary)
150 if not binary
in input_files:
151 input_files.append(binary)
153 for filepath
in input_files:
154 lc.project_upload_file(project_id, filepath)
157 sc = reven_api.scenario_config()
158 sc.vm_config_name = vm
159 sc.binary_name = binary_name
160 sc.binary_arguments = args
or ''
161 sc.binary_dump_hint = dump_at
or ''
162 sc.binary_dump_address = dump_at
or ''
163 sc.system_pdb_path =
''
166 sglc = reven_api.scenario_generation_launch_config()
167 sglc.enable_instruction_tracing =
False
168 sglc.is_interactive =
False
169 sglc.vnc_password =
''
172 scenario_config = reven_api.scenario_generation_config()
173 scenario_config.generation = sglc
174 scenario_config.scenario = sc
176 print "Start scenario generation"
177 lc.project_generate_scenario(project_id, scenario_config)
179 if wait_end_of_scenario(lc, project_id):
180 print "Generation ok"
182 print "Generation failed"
185 if __name__ ==
'__main__':
187 launcher_hostname =
'localhost'
188 sample_user =
'reven'
189 sample_project = reven_api.project_id(sample_user,
'_sample')
190 sample_binary =
'/tmp/lynx32'
191 sample_binary_arguments =
' -dump crash.html'
192 sample_input_files = [
'/tmp/crash.html']
193 sample_vm =
'vm_debian_auto'
195 lc = reven_api.launcher_connection(launcher_hostname)
201 list_projects_for_user(lc, lc.list_users()[0])
204 lc.project_create(sample_project)
208 close_project(launcher_hostname, sample_project)
210 lc.project_stop_scenario_generation(sample_project)
211 wait_end_of_scenario(lc, sample_project)
214 generate_scenario(lc, sample_project, sample_vm, sample_binary, args=sample_binary_arguments, input_files=sample_input_files)
217 client = open_project(launcher_hostname, sample_project)
220 client.start_execution()
222 progress = client.execution_status()
224 print "%s/%s - %s/%s - %s" % (
225 progress.tsc, progress.last_tsc,
226 progress.point_index, progress.last_point_index,
229 if not progress.is_busy:
235 print client.traces()
237 if list(client.traces()[0].search_symbol(
'my_awesome_symbol')):
238 print "Symbol found, could keep project"
239 client.save_execution(
'good')
241 print "Symbol not found, could discard project"
244 close_project(launcher_hostname, sample_project)
247 lc.project_delete(sample_project)