blob: f2a60c65f30547b8e7b014e4a78638ca337c08c7 [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
Zachary Turnerff890da2015-10-19 23:45:41 +000012from __future__ import print_function
13
Greg Clayton825ab582015-09-22 16:29:15 +000014import curses
Greg Clayton414dba52015-09-24 00:19:42 +000015import datetime
Greg Clayton825ab582015-09-22 16:29:15 +000016import lldbcurses
Greg Clayton414dba52015-09-24 00:19:42 +000017import math
Greg Clayton825ab582015-09-22 16:29:15 +000018import sys
19import test_results
Greg Clayton414dba52015-09-24 00:19:42 +000020import time
Greg Clayton825ab582015-09-22 16:29:15 +000021
22class Curses(test_results.ResultsFormatter):
23 """Receives live results from tests that are running and reports them to the terminal in a curses GUI"""
24
25 def __init__(self, out_file, options):
26 # Initialize the parent
27 super(Curses, self).__init__(out_file, options)
28 self.using_terminal = True
29 self.have_curses = True
30 self.initialize_event = None
31 self.jobs = [None] * 64
32 self.job_tests = [None] * 64
33 self.results = list()
Greg Clayton825ab582015-09-22 16:29:15 +000034 try:
Greg Clayton414dba52015-09-24 00:19:42 +000035 self.main_window = lldbcurses.intialize_curses()
36 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 +000037 self.main_window.refresh()
38 self.job_panel = None
39 self.results_panel = None
40 self.status_panel = None
41 self.info_panel = None
Greg Claytond13c4fb2015-09-22 17:18:15 +000042 self.hide_status_list = list()
Greg Clayton414dba52015-09-24 00:19:42 +000043 self.start_time = time.time()
Greg Clayton825ab582015-09-22 16:29:15 +000044 except:
45 self.have_curses = False
46 lldbcurses.terminate_curses()
47 self.using_terminal = False
Zachary Turnerff890da2015-10-19 23:45:41 +000048 print("Unexpected error:", sys.exc_info()[0])
Greg Clayton825ab582015-09-22 16:29:15 +000049 raise
50
51
52 self.line_dict = dict()
53 #self.events_file = open("/tmp/events.txt", "w")
54 # self.formatters = list()
55 # if tee_results_formatter:
56 # self.formatters.append(tee_results_formatter)
57
58 def status_to_short_str(self, status):
59 if status == 'success':
60 return '.'
61 elif status == 'failure':
62 return 'F'
63 elif status == 'unexpected_success':
64 return '?'
65 elif status == 'expected_failure':
66 return 'X'
67 elif status == 'skip':
68 return 'S'
69 elif status == 'error':
70 return 'E'
71 else:
72 return status
73
Greg Clayton414dba52015-09-24 00:19:42 +000074 def show_info_panel(self):
75 selected_idx = self.results_panel.get_selected_idx()
76 if selected_idx >= 0 and selected_idx < len(self.results):
77 if self.info_panel is None:
78 info_frame = self.results_panel.get_contained_rect(top_inset=10, left_inset=10, right_inset=10, height=30)
79 self.info_panel = lldbcurses.BoxedPanel(info_frame, "Result Details")
80 # Add a key action for any key that will hide this panel when any key is pressed
81 self.info_panel.add_key_action(-1, self.hide_info_panel, 'Hide the info panel')
82 self.info_panel.top()
83 else:
84 self.info_panel.show()
85
Greg Clayton37191a22015-10-07 20:00:28 +000086 self.main_window.push_first_responder(self.info_panel)
Greg Clayton414dba52015-09-24 00:19:42 +000087 test_start = self.results[selected_idx][0]
88 test_result = self.results[selected_idx][1]
89 self.info_panel.set_line(0, "File: %s" % (test_start['test_filename']))
90 self.info_panel.set_line(1, "Test: %s.%s" % (test_start['test_class'], test_start['test_name']))
91 self.info_panel.set_line(2, "Time: %s" % (test_result['elapsed_time']))
92 self.info_panel.set_line(3, "Status: %s" % (test_result['status']))
Greg Claytond13c4fb2015-09-22 17:18:15 +000093
Greg Clayton414dba52015-09-24 00:19:42 +000094 def hide_info_panel(self):
Greg Clayton37191a22015-10-07 20:00:28 +000095 self.main_window.pop_first_responder(self.info_panel)
Greg Clayton414dba52015-09-24 00:19:42 +000096 self.info_panel.hide()
Greg Clayton825ab582015-09-22 16:29:15 +000097 self.main_window.refresh()
Greg Clayton825ab582015-09-22 16:29:15 +000098
Greg Clayton414dba52015-09-24 00:19:42 +000099 def toggle_status(self, status):
100 if status:
101 # Toggle showing and hiding results whose status matches "status" in "Results" window
102 if status in self.hide_status_list:
103 self.hide_status_list.remove(status)
Greg Claytond13c4fb2015-09-22 17:18:15 +0000104 else:
Greg Clayton414dba52015-09-24 00:19:42 +0000105 self.hide_status_list.append(status)
106 self.update_results()
Greg Claytond13c4fb2015-09-22 17:18:15 +0000107
108 def update_results(self, update=True):
109 '''Called after a category of test have been show/hidden to update the results list with
110 what the user desires to see.'''
111 self.results_panel.clear(update=False)
112 for result in self.results:
113 test_result = result[1]
114 status = test_result['status']
115 if status in self.hide_status_list:
116 continue
117 name = test_result['test_class'] + '.' + test_result['test_name']
118 self.results_panel.append_line('%s (%6.2f sec) %s' % (self.status_to_short_str(status), test_result['elapsed_time'], name))
119 if update:
120 self.main_window.refresh()
121
Greg Clayton825ab582015-09-22 16:29:15 +0000122 def handle_event(self, test_event):
123 with self.lock:
124 super(Curses, self).handle_event(test_event)
125 # for formatter in self.formatters:
126 # formatter.process_event(test_event)
127 if self.have_curses:
128 worker_index = -1
129 if 'worker_index' in test_event:
130 worker_index = test_event['worker_index']
131 if 'event' in test_event:
132 check_for_one_key = True
Zachary Turner35d017f2015-10-23 17:04:29 +0000133 #print(str(test_event), file=self.events_file)
Greg Clayton414dba52015-09-24 00:19:42 +0000134 event = test_event['event']
135 if self.status_panel:
136 self.status_panel.update_status('time', str(datetime.timedelta(seconds=math.floor(time.time() - self.start_time))))
Greg Clayton825ab582015-09-22 16:29:15 +0000137 if event == 'test_start':
138 name = test_event['test_class'] + '.' + test_event['test_name']
139 self.job_tests[worker_index] = test_event
140 if 'pid' in test_event:
141 line = 'pid: %5d ' % (test_event['pid']) + name
142 else:
143 line = name
144 self.job_panel.set_line(worker_index, line)
145 self.main_window.refresh()
146 elif event == 'test_result':
147 status = test_event['status']
148 self.status_panel.increment_status(status)
149 if 'pid' in test_event:
150 line = 'pid: %5d ' % (test_event['pid'])
151 else:
152 line = ''
153 self.job_panel.set_line(worker_index, line)
Greg Clayton825ab582015-09-22 16:29:15 +0000154 name = test_event['test_class'] + '.' + test_event['test_name']
155 elapsed_time = test_event['event_time'] - self.job_tests[worker_index]['event_time']
Greg Claytond13c4fb2015-09-22 17:18:15 +0000156 if not status in self.hide_status_list:
157 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 +0000158 self.main_window.refresh()
159 # Append the result pairs
160 test_event['elapsed_time'] = elapsed_time
161 self.results.append([self.job_tests[worker_index], test_event])
162 self.job_tests[worker_index] = ''
163 elif event == 'job_begin':
164 self.jobs[worker_index] = test_event
165 if 'pid' in test_event:
166 line = 'pid: %5d ' % (test_event['pid'])
167 else:
168 line = ''
169 self.job_panel.set_line(worker_index, line)
170 elif event == 'job_end':
171 self.jobs[worker_index] = ''
172 self.job_panel.set_line(worker_index, '')
Greg Clayton414dba52015-09-24 00:19:42 +0000173 elif event == 'initialize':
Greg Clayton825ab582015-09-22 16:29:15 +0000174 self.initialize_event = test_event
175 num_jobs = test_event['worker_count']
176 job_frame = self.main_window.get_contained_rect(height=num_jobs+2)
177 results_frame = self.main_window.get_contained_rect(top_inset=num_jobs+2, bottom_inset=1)
178 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 +0000179 self.job_panel = lldbcurses.BoxedPanel(frame=job_frame, title="Jobs")
180 self.results_panel = lldbcurses.BoxedPanel(frame=results_frame, title="Results")
181
182 self.results_panel.add_key_action(curses.KEY_UP, self.results_panel.select_prev , "Select the previous list entry")
183 self.results_panel.add_key_action(curses.KEY_DOWN, self.results_panel.select_next , "Select the next list entry")
184 self.results_panel.add_key_action(curses.KEY_HOME, self.results_panel.scroll_begin , "Scroll to the start of the list")
185 self.results_panel.add_key_action(curses.KEY_END, self.results_panel.scroll_end , "Scroll to the end of the list")
186 self.results_panel.add_key_action(curses.KEY_ENTER, self.show_info_panel , "Display info for the selected result item")
187 self.results_panel.add_key_action('.', lambda : self.toggle_status('success') , "Toggle showing/hiding tests whose status is 'success'")
188 self.results_panel.add_key_action('e', lambda : self.toggle_status('error') , "Toggle showing/hiding tests whose status is 'error'")
189 self.results_panel.add_key_action('f', lambda : self.toggle_status('failure') , "Toggle showing/hiding tests whose status is 'failure'")
190 self.results_panel.add_key_action('s', lambda : self.toggle_status('skip') , "Toggle showing/hiding tests whose status is 'skip'")
191 self.results_panel.add_key_action('x', lambda : self.toggle_status('expected_failure') , "Toggle showing/hiding tests whose status is 'expected_failure'")
192 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 +0000193 self.status_panel = lldbcurses.StatusPanel(frame=status_frame)
194
195 self.main_window.add_child(self.job_panel)
196 self.main_window.add_child(self.results_panel)
197 self.main_window.add_child(self.status_panel)
198 self.main_window.set_first_responder(self.results_panel)
199
Greg Clayton414dba52015-09-24 00:19:42 +0000200 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 +0000201 self.status_panel.add_status_item(name="success", title="Success", format="%u", width=20, value=0, update=False)
202 self.status_panel.add_status_item(name="failure", title="Failure", format="%u", width=20, value=0, update=False)
203 self.status_panel.add_status_item(name="error", title="Error", format="%u", width=20, value=0, update=False)
204 self.status_panel.add_status_item(name="skip", title="Skipped", format="%u", width=20, value=0, update=True)
205 self.status_panel.add_status_item(name="expected_failure", title="Expected Failure", format="%u", width=30, value=0, update=False)
206 self.status_panel.add_status_item(name="unexpected_success", title="Unexpected Success", format="%u", width=30, value=0, update=False)
207 self.main_window.refresh()
208 elif event == 'terminate':
Greg Claytonb877a202015-09-24 16:37:41 +0000209 #self.main_window.key_event_loop()
Greg Clayton825ab582015-09-22 16:29:15 +0000210 lldbcurses.terminate_curses()
211 check_for_one_key = False
212 self.using_terminal = False
213 # Check for 1 keypress with no delay
214
215 # Check for 1 keypress with no delay
216 if check_for_one_key:
217 self.main_window.key_event_loop(0, 1)
218