blob: 18ecd663055df2f25ec7e6d077cc19a9300ad8ef [file] [log] [blame]
Greg Clayton825ab582015-09-22 16:29:15 +00001#!/usr/bin/env python
2
3"""
4 The LLVM Compiler Infrastructure
5
6 This file is distributed under the University of Illinois Open Source
7 License. See LICENSE.TXT for details.
8
9Configuration options for lldbtest.py set by dotest.py during initialization
10"""
11
12import curses
Greg Clayton414dba52015-09-24 00:19:42 +000013import datetime
Greg Clayton825ab582015-09-22 16:29:15 +000014import lldbcurses
Greg Clayton414dba52015-09-24 00:19:42 +000015import math
Greg Clayton825ab582015-09-22 16:29:15 +000016import sys
17import test_results
Greg Clayton414dba52015-09-24 00:19:42 +000018import time
Greg Clayton825ab582015-09-22 16:29:15 +000019
20class Curses(test_results.ResultsFormatter):
21 """Receives live results from tests that are running and reports them to the terminal in a curses GUI"""
22
23 def __init__(self, out_file, options):
24 # Initialize the parent
25 super(Curses, self).__init__(out_file, options)
26 self.using_terminal = True
27 self.have_curses = True
28 self.initialize_event = None
29 self.jobs = [None] * 64
30 self.job_tests = [None] * 64
31 self.results = list()
Greg Clayton825ab582015-09-22 16:29:15 +000032 try:
Greg Clayton414dba52015-09-24 00:19:42 +000033 self.main_window = lldbcurses.intialize_curses()
34 self.main_window.add_key_action('\t', self.main_window.select_next_first_responder, "Switch between views that can respond to keyboard input")
Greg Clayton825ab582015-09-22 16:29:15 +000035 self.main_window.refresh()
36 self.job_panel = None
37 self.results_panel = None
38 self.status_panel = None
39 self.info_panel = None
Greg Claytond13c4fb2015-09-22 17:18:15 +000040 self.hide_status_list = list()
Greg Clayton414dba52015-09-24 00:19:42 +000041 self.start_time = time.time()
Greg Clayton825ab582015-09-22 16:29:15 +000042 except:
43 self.have_curses = False
44 lldbcurses.terminate_curses()
45 self.using_terminal = False
46 print "Unexpected error:", sys.exc_info()[0]
47 raise
48
49
50 self.line_dict = dict()
51 #self.events_file = open("/tmp/events.txt", "w")
52 # self.formatters = list()
53 # if tee_results_formatter:
54 # self.formatters.append(tee_results_formatter)
55
56 def status_to_short_str(self, status):
57 if status == 'success':
58 return '.'
59 elif status == 'failure':
60 return 'F'
61 elif status == 'unexpected_success':
62 return '?'
63 elif status == 'expected_failure':
64 return 'X'
65 elif status == 'skip':
66 return 'S'
67 elif status == 'error':
68 return 'E'
69 else:
70 return status
71
Greg Clayton414dba52015-09-24 00:19:42 +000072 def show_info_panel(self):
73 selected_idx = self.results_panel.get_selected_idx()
74 if selected_idx >= 0 and selected_idx < len(self.results):
75 if self.info_panel is None:
76 info_frame = self.results_panel.get_contained_rect(top_inset=10, left_inset=10, right_inset=10, height=30)
77 self.info_panel = lldbcurses.BoxedPanel(info_frame, "Result Details")
78 # Add a key action for any key that will hide this panel when any key is pressed
79 self.info_panel.add_key_action(-1, self.hide_info_panel, 'Hide the info panel')
80 self.info_panel.top()
81 else:
82 self.info_panel.show()
83
Greg Clayton37191a22015-10-07 20:00:28 +000084 self.main_window.push_first_responder(self.info_panel)
Greg Clayton414dba52015-09-24 00:19:42 +000085 test_start = self.results[selected_idx][0]
86 test_result = self.results[selected_idx][1]
87 self.info_panel.set_line(0, "File: %s" % (test_start['test_filename']))
88 self.info_panel.set_line(1, "Test: %s.%s" % (test_start['test_class'], test_start['test_name']))
89 self.info_panel.set_line(2, "Time: %s" % (test_result['elapsed_time']))
90 self.info_panel.set_line(3, "Status: %s" % (test_result['status']))
Greg Claytond13c4fb2015-09-22 17:18:15 +000091
Greg Clayton414dba52015-09-24 00:19:42 +000092 def hide_info_panel(self):
Greg Clayton37191a22015-10-07 20:00:28 +000093 self.main_window.pop_first_responder(self.info_panel)
Greg Clayton414dba52015-09-24 00:19:42 +000094 self.info_panel.hide()
Greg Clayton825ab582015-09-22 16:29:15 +000095 self.main_window.refresh()
Greg Clayton825ab582015-09-22 16:29:15 +000096
Greg Clayton414dba52015-09-24 00:19:42 +000097 def toggle_status(self, status):
98 if status:
99 # Toggle showing and hiding results whose status matches "status" in "Results" window
100 if status in self.hide_status_list:
101 self.hide_status_list.remove(status)
Greg Claytond13c4fb2015-09-22 17:18:15 +0000102 else:
Greg Clayton414dba52015-09-24 00:19:42 +0000103 self.hide_status_list.append(status)
104 self.update_results()
Greg Claytond13c4fb2015-09-22 17:18:15 +0000105
106 def update_results(self, update=True):
107 '''Called after a category of test have been show/hidden to update the results list with
108 what the user desires to see.'''
109 self.results_panel.clear(update=False)
110 for result in self.results:
111 test_result = result[1]
112 status = test_result['status']
113 if status in self.hide_status_list:
114 continue
115 name = test_result['test_class'] + '.' + test_result['test_name']
116 self.results_panel.append_line('%s (%6.2f sec) %s' % (self.status_to_short_str(status), test_result['elapsed_time'], name))
117 if update:
118 self.main_window.refresh()
119
Greg Clayton825ab582015-09-22 16:29:15 +0000120 def handle_event(self, test_event):
121 with self.lock:
122 super(Curses, self).handle_event(test_event)
123 # for formatter in self.formatters:
124 # formatter.process_event(test_event)
125 if self.have_curses:
126 worker_index = -1
127 if 'worker_index' in test_event:
128 worker_index = test_event['worker_index']
129 if 'event' in test_event:
130 check_for_one_key = True
131 #print >>self.events_file, str(test_event)
Greg Clayton414dba52015-09-24 00:19:42 +0000132 event = test_event['event']
133 if self.status_panel:
134 self.status_panel.update_status('time', str(datetime.timedelta(seconds=math.floor(time.time() - self.start_time))))
Greg Clayton825ab582015-09-22 16:29:15 +0000135 if event == 'test_start':
136 name = test_event['test_class'] + '.' + test_event['test_name']
137 self.job_tests[worker_index] = test_event
138 if 'pid' in test_event:
139 line = 'pid: %5d ' % (test_event['pid']) + name
140 else:
141 line = name
142 self.job_panel.set_line(worker_index, line)
143 self.main_window.refresh()
144 elif event == 'test_result':
145 status = test_event['status']
146 self.status_panel.increment_status(status)
147 if 'pid' in test_event:
148 line = 'pid: %5d ' % (test_event['pid'])
149 else:
150 line = ''
151 self.job_panel.set_line(worker_index, line)
Greg Clayton825ab582015-09-22 16:29:15 +0000152 name = test_event['test_class'] + '.' + test_event['test_name']
153 elapsed_time = test_event['event_time'] - self.job_tests[worker_index]['event_time']
Greg Claytond13c4fb2015-09-22 17:18:15 +0000154 if not status in self.hide_status_list:
155 self.results_panel.append_line('%s (%6.2f sec) %s' % (self.status_to_short_str(status), elapsed_time, name))
Greg Clayton825ab582015-09-22 16:29:15 +0000156 self.main_window.refresh()
157 # Append the result pairs
158 test_event['elapsed_time'] = elapsed_time
159 self.results.append([self.job_tests[worker_index], test_event])
160 self.job_tests[worker_index] = ''
161 elif event == 'job_begin':
162 self.jobs[worker_index] = test_event
163 if 'pid' in test_event:
164 line = 'pid: %5d ' % (test_event['pid'])
165 else:
166 line = ''
167 self.job_panel.set_line(worker_index, line)
168 elif event == 'job_end':
169 self.jobs[worker_index] = ''
170 self.job_panel.set_line(worker_index, '')
Greg Clayton414dba52015-09-24 00:19:42 +0000171 elif event == 'initialize':
Greg Clayton825ab582015-09-22 16:29:15 +0000172 self.initialize_event = test_event
173 num_jobs = test_event['worker_count']
174 job_frame = self.main_window.get_contained_rect(height=num_jobs+2)
175 results_frame = self.main_window.get_contained_rect(top_inset=num_jobs+2, bottom_inset=1)
176 status_frame = self.main_window.get_contained_rect(height=1, top_inset=self.main_window.get_size().h-1)
Greg Clayton414dba52015-09-24 00:19:42 +0000177 self.job_panel = lldbcurses.BoxedPanel(frame=job_frame, title="Jobs")
178 self.results_panel = lldbcurses.BoxedPanel(frame=results_frame, title="Results")
179
180 self.results_panel.add_key_action(curses.KEY_UP, self.results_panel.select_prev , "Select the previous list entry")
181 self.results_panel.add_key_action(curses.KEY_DOWN, self.results_panel.select_next , "Select the next list entry")
182 self.results_panel.add_key_action(curses.KEY_HOME, self.results_panel.scroll_begin , "Scroll to the start of the list")
183 self.results_panel.add_key_action(curses.KEY_END, self.results_panel.scroll_end , "Scroll to the end of the list")
184 self.results_panel.add_key_action(curses.KEY_ENTER, self.show_info_panel , "Display info for the selected result item")
185 self.results_panel.add_key_action('.', lambda : self.toggle_status('success') , "Toggle showing/hiding tests whose status is 'success'")
186 self.results_panel.add_key_action('e', lambda : self.toggle_status('error') , "Toggle showing/hiding tests whose status is 'error'")
187 self.results_panel.add_key_action('f', lambda : self.toggle_status('failure') , "Toggle showing/hiding tests whose status is 'failure'")
188 self.results_panel.add_key_action('s', lambda : self.toggle_status('skip') , "Toggle showing/hiding tests whose status is 'skip'")
189 self.results_panel.add_key_action('x', lambda : self.toggle_status('expected_failure') , "Toggle showing/hiding tests whose status is 'expected_failure'")
190 self.results_panel.add_key_action('?', lambda : self.toggle_status('unexpected_success'), "Toggle showing/hiding tests whose status is 'unexpected_success'")
Greg Clayton825ab582015-09-22 16:29:15 +0000191 self.status_panel = lldbcurses.StatusPanel(frame=status_frame)
192
193 self.main_window.add_child(self.job_panel)
194 self.main_window.add_child(self.results_panel)
195 self.main_window.add_child(self.status_panel)
196 self.main_window.set_first_responder(self.results_panel)
197
Greg Clayton414dba52015-09-24 00:19:42 +0000198 self.status_panel.add_status_item(name="time", title="Elapsed", format="%s", width=20, value="0:00:00", update=False)
Greg Clayton825ab582015-09-22 16:29:15 +0000199 self.status_panel.add_status_item(name="success", title="Success", format="%u", width=20, value=0, update=False)
200 self.status_panel.add_status_item(name="failure", title="Failure", format="%u", width=20, value=0, update=False)
201 self.status_panel.add_status_item(name="error", title="Error", format="%u", width=20, value=0, update=False)
202 self.status_panel.add_status_item(name="skip", title="Skipped", format="%u", width=20, value=0, update=True)
203 self.status_panel.add_status_item(name="expected_failure", title="Expected Failure", format="%u", width=30, value=0, update=False)
204 self.status_panel.add_status_item(name="unexpected_success", title="Unexpected Success", format="%u", width=30, value=0, update=False)
205 self.main_window.refresh()
206 elif event == 'terminate':
Greg Claytonb877a202015-09-24 16:37:41 +0000207 #self.main_window.key_event_loop()
Greg Clayton825ab582015-09-22 16:29:15 +0000208 lldbcurses.terminate_curses()
209 check_for_one_key = False
210 self.using_terminal = False
211 # Check for 1 keypress with no delay
212
213 # Check for 1 keypress with no delay
214 if check_for_one_key:
215 self.main_window.key_event_loop(0, 1)
216