blob: e00e26556db3c392018a3da6c4f3a2fbce90c168 [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
Zachary Turnerc1b7cd72015-11-05 19:22:28 +000013from __future__ import absolute_import
Zachary Turnerff890da2015-10-19 23:45:41 +000014
Zachary Turnerc1b7cd72015-11-05 19:22:28 +000015# System modules
Greg Clayton825ab582015-09-22 16:29:15 +000016import curses
Greg Clayton414dba52015-09-24 00:19:42 +000017import datetime
Greg Clayton414dba52015-09-24 00:19:42 +000018import math
Greg Clayton825ab582015-09-22 16:29:15 +000019import sys
20import test_results
Greg Clayton414dba52015-09-24 00:19:42 +000021import time
Greg Clayton825ab582015-09-22 16:29:15 +000022
Zachary Turnerc1b7cd72015-11-05 19:22:28 +000023# Third-party modules
24
25# LLDB modules
26from . import lldbcurses
27
Greg Clayton825ab582015-09-22 16:29:15 +000028class Curses(test_results.ResultsFormatter):
29 """Receives live results from tests that are running and reports them to the terminal in a curses GUI"""
30
31 def __init__(self, out_file, options):
32 # Initialize the parent
33 super(Curses, self).__init__(out_file, options)
34 self.using_terminal = True
35 self.have_curses = True
36 self.initialize_event = None
37 self.jobs = [None] * 64
38 self.job_tests = [None] * 64
39 self.results = list()
Greg Clayton825ab582015-09-22 16:29:15 +000040 try:
Greg Clayton414dba52015-09-24 00:19:42 +000041 self.main_window = lldbcurses.intialize_curses()
42 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 +000043 self.main_window.refresh()
44 self.job_panel = None
45 self.results_panel = None
46 self.status_panel = None
47 self.info_panel = None
Greg Claytond13c4fb2015-09-22 17:18:15 +000048 self.hide_status_list = list()
Greg Clayton414dba52015-09-24 00:19:42 +000049 self.start_time = time.time()
Greg Clayton825ab582015-09-22 16:29:15 +000050 except:
51 self.have_curses = False
52 lldbcurses.terminate_curses()
53 self.using_terminal = False
Zachary Turnerff890da2015-10-19 23:45:41 +000054 print("Unexpected error:", sys.exc_info()[0])
Greg Clayton825ab582015-09-22 16:29:15 +000055 raise
56
57
58 self.line_dict = dict()
59 #self.events_file = open("/tmp/events.txt", "w")
60 # self.formatters = list()
61 # if tee_results_formatter:
62 # self.formatters.append(tee_results_formatter)
63
64 def status_to_short_str(self, status):
65 if status == 'success':
66 return '.'
67 elif status == 'failure':
68 return 'F'
69 elif status == 'unexpected_success':
70 return '?'
71 elif status == 'expected_failure':
72 return 'X'
73 elif status == 'skip':
74 return 'S'
75 elif status == 'error':
76 return 'E'
77 else:
78 return status
79
Greg Clayton414dba52015-09-24 00:19:42 +000080 def show_info_panel(self):
81 selected_idx = self.results_panel.get_selected_idx()
82 if selected_idx >= 0 and selected_idx < len(self.results):
83 if self.info_panel is None:
84 info_frame = self.results_panel.get_contained_rect(top_inset=10, left_inset=10, right_inset=10, height=30)
85 self.info_panel = lldbcurses.BoxedPanel(info_frame, "Result Details")
86 # Add a key action for any key that will hide this panel when any key is pressed
87 self.info_panel.add_key_action(-1, self.hide_info_panel, 'Hide the info panel')
88 self.info_panel.top()
89 else:
90 self.info_panel.show()
91
Greg Clayton37191a22015-10-07 20:00:28 +000092 self.main_window.push_first_responder(self.info_panel)
Greg Clayton414dba52015-09-24 00:19:42 +000093 test_start = self.results[selected_idx][0]
94 test_result = self.results[selected_idx][1]
95 self.info_panel.set_line(0, "File: %s" % (test_start['test_filename']))
96 self.info_panel.set_line(1, "Test: %s.%s" % (test_start['test_class'], test_start['test_name']))
97 self.info_panel.set_line(2, "Time: %s" % (test_result['elapsed_time']))
98 self.info_panel.set_line(3, "Status: %s" % (test_result['status']))
Greg Claytond13c4fb2015-09-22 17:18:15 +000099
Greg Clayton414dba52015-09-24 00:19:42 +0000100 def hide_info_panel(self):
Greg Clayton37191a22015-10-07 20:00:28 +0000101 self.main_window.pop_first_responder(self.info_panel)
Greg Clayton414dba52015-09-24 00:19:42 +0000102 self.info_panel.hide()
Greg Clayton825ab582015-09-22 16:29:15 +0000103 self.main_window.refresh()
Greg Clayton825ab582015-09-22 16:29:15 +0000104
Greg Clayton414dba52015-09-24 00:19:42 +0000105 def toggle_status(self, status):
106 if status:
107 # Toggle showing and hiding results whose status matches "status" in "Results" window
108 if status in self.hide_status_list:
109 self.hide_status_list.remove(status)
Greg Claytond13c4fb2015-09-22 17:18:15 +0000110 else:
Greg Clayton414dba52015-09-24 00:19:42 +0000111 self.hide_status_list.append(status)
112 self.update_results()
Greg Claytond13c4fb2015-09-22 17:18:15 +0000113
114 def update_results(self, update=True):
115 '''Called after a category of test have been show/hidden to update the results list with
116 what the user desires to see.'''
117 self.results_panel.clear(update=False)
118 for result in self.results:
119 test_result = result[1]
120 status = test_result['status']
121 if status in self.hide_status_list:
122 continue
123 name = test_result['test_class'] + '.' + test_result['test_name']
124 self.results_panel.append_line('%s (%6.2f sec) %s' % (self.status_to_short_str(status), test_result['elapsed_time'], name))
125 if update:
126 self.main_window.refresh()
127
Greg Clayton825ab582015-09-22 16:29:15 +0000128 def handle_event(self, test_event):
129 with self.lock:
130 super(Curses, self).handle_event(test_event)
131 # for formatter in self.formatters:
132 # formatter.process_event(test_event)
133 if self.have_curses:
134 worker_index = -1
135 if 'worker_index' in test_event:
136 worker_index = test_event['worker_index']
137 if 'event' in test_event:
138 check_for_one_key = True
Zachary Turner35d017f2015-10-23 17:04:29 +0000139 #print(str(test_event), file=self.events_file)
Greg Clayton414dba52015-09-24 00:19:42 +0000140 event = test_event['event']
141 if self.status_panel:
142 self.status_panel.update_status('time', str(datetime.timedelta(seconds=math.floor(time.time() - self.start_time))))
Greg Clayton825ab582015-09-22 16:29:15 +0000143 if event == 'test_start':
144 name = test_event['test_class'] + '.' + test_event['test_name']
145 self.job_tests[worker_index] = test_event
146 if 'pid' in test_event:
147 line = 'pid: %5d ' % (test_event['pid']) + name
148 else:
149 line = name
150 self.job_panel.set_line(worker_index, line)
151 self.main_window.refresh()
152 elif event == 'test_result':
153 status = test_event['status']
154 self.status_panel.increment_status(status)
155 if 'pid' in test_event:
156 line = 'pid: %5d ' % (test_event['pid'])
157 else:
158 line = ''
159 self.job_panel.set_line(worker_index, line)
Greg Clayton825ab582015-09-22 16:29:15 +0000160 name = test_event['test_class'] + '.' + test_event['test_name']
161 elapsed_time = test_event['event_time'] - self.job_tests[worker_index]['event_time']
Greg Claytond13c4fb2015-09-22 17:18:15 +0000162 if not status in self.hide_status_list:
163 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 +0000164 self.main_window.refresh()
165 # Append the result pairs
166 test_event['elapsed_time'] = elapsed_time
167 self.results.append([self.job_tests[worker_index], test_event])
168 self.job_tests[worker_index] = ''
169 elif event == 'job_begin':
170 self.jobs[worker_index] = test_event
171 if 'pid' in test_event:
172 line = 'pid: %5d ' % (test_event['pid'])
173 else:
174 line = ''
175 self.job_panel.set_line(worker_index, line)
176 elif event == 'job_end':
177 self.jobs[worker_index] = ''
178 self.job_panel.set_line(worker_index, '')
Greg Clayton414dba52015-09-24 00:19:42 +0000179 elif event == 'initialize':
Greg Clayton825ab582015-09-22 16:29:15 +0000180 self.initialize_event = test_event
181 num_jobs = test_event['worker_count']
182 job_frame = self.main_window.get_contained_rect(height=num_jobs+2)
183 results_frame = self.main_window.get_contained_rect(top_inset=num_jobs+2, bottom_inset=1)
184 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 +0000185 self.job_panel = lldbcurses.BoxedPanel(frame=job_frame, title="Jobs")
186 self.results_panel = lldbcurses.BoxedPanel(frame=results_frame, title="Results")
187
188 self.results_panel.add_key_action(curses.KEY_UP, self.results_panel.select_prev , "Select the previous list entry")
189 self.results_panel.add_key_action(curses.KEY_DOWN, self.results_panel.select_next , "Select the next list entry")
190 self.results_panel.add_key_action(curses.KEY_HOME, self.results_panel.scroll_begin , "Scroll to the start of the list")
191 self.results_panel.add_key_action(curses.KEY_END, self.results_panel.scroll_end , "Scroll to the end of the list")
192 self.results_panel.add_key_action(curses.KEY_ENTER, self.show_info_panel , "Display info for the selected result item")
193 self.results_panel.add_key_action('.', lambda : self.toggle_status('success') , "Toggle showing/hiding tests whose status is 'success'")
194 self.results_panel.add_key_action('e', lambda : self.toggle_status('error') , "Toggle showing/hiding tests whose status is 'error'")
195 self.results_panel.add_key_action('f', lambda : self.toggle_status('failure') , "Toggle showing/hiding tests whose status is 'failure'")
196 self.results_panel.add_key_action('s', lambda : self.toggle_status('skip') , "Toggle showing/hiding tests whose status is 'skip'")
197 self.results_panel.add_key_action('x', lambda : self.toggle_status('expected_failure') , "Toggle showing/hiding tests whose status is 'expected_failure'")
198 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 +0000199 self.status_panel = lldbcurses.StatusPanel(frame=status_frame)
200
201 self.main_window.add_child(self.job_panel)
202 self.main_window.add_child(self.results_panel)
203 self.main_window.add_child(self.status_panel)
204 self.main_window.set_first_responder(self.results_panel)
205
Greg Clayton414dba52015-09-24 00:19:42 +0000206 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 +0000207 self.status_panel.add_status_item(name="success", title="Success", format="%u", width=20, value=0, update=False)
208 self.status_panel.add_status_item(name="failure", title="Failure", format="%u", width=20, value=0, update=False)
209 self.status_panel.add_status_item(name="error", title="Error", format="%u", width=20, value=0, update=False)
210 self.status_panel.add_status_item(name="skip", title="Skipped", format="%u", width=20, value=0, update=True)
211 self.status_panel.add_status_item(name="expected_failure", title="Expected Failure", format="%u", width=30, value=0, update=False)
212 self.status_panel.add_status_item(name="unexpected_success", title="Unexpected Success", format="%u", width=30, value=0, update=False)
213 self.main_window.refresh()
214 elif event == 'terminate':
Greg Claytonb877a202015-09-24 16:37:41 +0000215 #self.main_window.key_event_loop()
Greg Clayton825ab582015-09-22 16:29:15 +0000216 lldbcurses.terminate_curses()
217 check_for_one_key = False
218 self.using_terminal = False
219 # Check for 1 keypress with no delay
220
221 # Check for 1 keypress with no delay
222 if check_for_one_key:
223 self.main_window.key_event_loop(0, 1)
224