Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: client/site_tests/factory_Display/factory_Display.py

Issue 2836043: Relocate library files for wider access and re-use; also associated cleanup. (Closed) Base URL: ssh://gitrw.chromium.org/autotest.git
Patch Set: patch typo Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 5
6 # DESCRIPTION : 6 # DESCRIPTION :
7 # 7 #
8 # This is an example factory test that does not really do anything -- 8 # This is a factory test to test the LCD display.
9 # it displays a message in the center of the testing area, as
10 # communicated by arguments to run_once(). This test makes use of the
11 # factory_test library to display its UI, and to monitor keyboard
12 # events for test-switching triggers. This test can be terminated by
13 # typing SHIFT-Q.
14 9
15 from autotest_lib.client.bin import test
16 from autotest_lib.client.common_lib import error
17 from autotest_lib.client.common_lib import factory_test
18 10
19 import gtk 11 import gtk
20 import pango 12 import pango
21 import os 13 import os
22 import sys 14 import sys
23 15
16 from autotest_lib.client.bin import factory
17 from autotest_lib.client.bin import factory_ui_lib as ful
18 from autotest_lib.client.bin import test
19 from autotest_lib.client.common_lib import error
24 20
25 def XXX_log(s):
26 print >> sys.stderr, 'FACTORY: ' + s
27
28
29 _BLACK = gtk.gdk.Color()
30 _RED = gtk.gdk.Color(0xFFFF, 0, 0)
31 _GREEN = gtk.gdk.Color(0, 0xFFFF, 0)
32 _BLUE = gtk.gdk.Color(0, 0, 0xFFFF)
33 _WHITE = gtk.gdk.Color(0xFFFF, 0xFFFF, 0xFFFF)
34
35 _ACTIVE = 'ACTIVE'
36 _PASSED = 'PASS'
37 _FAILED = 'FAIL'
38 _UNTESTED = 'UNTESTED'
39
40 _LABEL_COLORS = {
41 _ACTIVE: gtk.gdk.color_parse('light goldenrod'),
42 _PASSED: gtk.gdk.color_parse('pale green'),
43 _FAILED: gtk.gdk.color_parse('tomato'),
44 _UNTESTED: gtk.gdk.color_parse('dark slate grey')}
45 21
46 _LABEL_STATUS_SIZE = (140, 30) 22 _LABEL_STATUS_SIZE = (140, 30)
47 _LABEL_STATUS_FONT = pango.FontDescription('courier new condensed 16') 23 _LABEL_STATUS_FONT = pango.FontDescription('courier new condensed 16')
48 _LABEL_FONT = pango.FontDescription('courier new condensed 20') 24 _LABEL_FONT = pango.FontDescription('courier new condensed 20')
49 _LABEL_FG = gtk.gdk.color_parse('light green') 25 _LABEL_FG = gtk.gdk.color_parse('light green')
50 _LABEL_UNTESTED_FG = gtk.gdk.color_parse('grey40') 26 _LABEL_UNTESTED_FG = gtk.gdk.color_parse('grey40')
51 27
52 28
53 def pattern_cb_solid(widget, event, color=None): 29 def pattern_cb_solid(widget, event, color=None):
54 dr = widget.window 30 dr = widget.window
55 xmax, ymax = dr.get_size() 31 xmax, ymax = dr.get_size()
56 gc = gtk.gdk.GC(dr) 32 gc = gtk.gdk.GC(dr)
57 gc.set_rgb_fg_color(color) 33 gc.set_rgb_fg_color(color)
58 dr.draw_rectangle(gc, True, 0, 0, xmax, ymax) 34 dr.draw_rectangle(gc, True, 0, 0, xmax, ymax)
59 return False 35 return False
60 36
61 37
62 def pattern_cb_grid(widget, event, color=None): 38 def pattern_cb_grid(widget, event, color=None):
63 dr = widget.window 39 dr = widget.window
64 xmax, ymax = dr.get_size() 40 xmax, ymax = dr.get_size()
65 gc = gtk.gdk.GC(dr) 41 gc = gtk.gdk.GC(dr)
66 gc.set_rgb_fg_color(_BLACK) 42 gc.set_rgb_fg_color(ful.BLACK)
67 dr.draw_rectangle(gc, True, 0, 0, xmax, ymax) 43 dr.draw_rectangle(gc, True, 0, 0, xmax, ymax)
68 gc.set_rgb_fg_color(color) 44 gc.set_rgb_fg_color(color)
69 gc.set_line_attributes(1, 45 gc.set_line_attributes(1,
70 gtk.gdk.LINE_SOLID, 46 gtk.gdk.LINE_SOLID,
71 gtk.gdk.CAP_BUTT, 47 gtk.gdk.CAP_BUTT,
72 gtk.gdk.JOIN_MITER) 48 gtk.gdk.JOIN_MITER)
73 for x in range(0, xmax, 20): 49 for x in range(0, xmax, 20):
74 dr.draw_line(gc, x, 0, x, ymax) 50 dr.draw_line(gc, x, 0, x, ymax)
75 for y in range(0, ymax, 20): 51 for y in range(0, ymax, 20):
76 dr.draw_line(gc, 0, y, xmax, y) 52 dr.draw_line(gc, 0, y, xmax, y)
77 return False 53 return False
78 54
79 55
80 _PATTERN_LIST = [ 56 _PATTERN_LIST = [
81 ('solid red', lambda *x: pattern_cb_solid(*x, **{'color':_RED})), 57 ('solid red', lambda *x: pattern_cb_solid(*x, **{'color':ful.RED})),
82 ('solid green', lambda *x: pattern_cb_solid(*x, **{'color':_GREEN})), 58 ('solid green', lambda *x: pattern_cb_solid(*x, **{'color':ful.GREEN})),
83 ('solid blue', lambda *x: pattern_cb_solid(*x, **{'color':_BLUE})), 59 ('solid blue', lambda *x: pattern_cb_solid(*x, **{'color':ful.BLUE})),
84 ('solid white', lambda *x: pattern_cb_solid(*x, **{'color':_WHITE})), 60 ('solid white', lambda *x: pattern_cb_solid(*x, **{'color':ful.WHITE})),
85 ('grid', lambda *x: pattern_cb_grid(*x, **{'color':_GREEN}))] 61 ('grid', lambda *x: pattern_cb_grid(*x, **{'color':ful.GREEN}))]
86 62
87 63
88 class factory_Display(test.test): 64 class factory_Display(test.test):
89 version = 1 65 version = 1
90 66
91 def display_full_screen(self, pattern_callback): 67 def display_full_screen(self, pattern_callback):
92 window = gtk.Window(gtk.WINDOW_TOPLEVEL) 68 window = gtk.Window(gtk.WINDOW_TOPLEVEL)
93 screen = window.get_screen() 69 screen = window.get_screen()
94 screen_size = (screen.get_width(), screen.get_height()) 70 screen_size = (screen.get_width(), screen.get_height())
95 window.set_size_request(*screen_size) 71 window.set_size_request(*screen_size)
96 drawing_area = gtk.DrawingArea() 72 drawing_area = gtk.DrawingArea()
97 window.add(drawing_area) 73 window.add(drawing_area)
98 window.show_all() 74 window.show_all()
99 self._fs_window = window 75 self._fs_window = window
100 drawing_area.connect('expose_event', pattern_callback) 76 drawing_area.connect('expose_event', pattern_callback)
101 77
102 def goto_next_pattern(self): 78 def goto_next_pattern(self):
103 if not self._pattern_queue: 79 if not self._pattern_queue:
104 gtk.main_quit() 80 gtk.main_quit()
105 return 81 return
106 self._current_pattern = self._pattern_queue.pop() 82 self._current_pattern = self._pattern_queue.pop()
107 name, cb_fn = self._current_pattern 83 name, cb_fn = self._current_pattern
108 self._status_map[name] = _ACTIVE 84 self._status_map[name] = ful.ACTIVE
109 self._current_pattern_shown = False 85 self._current_pattern_shown = False
110 86
111 def key_press_callback(self, widget, event): 87 def key_press_callback(self, widget, event):
112 pattern_name, pattern_cb = self._current_pattern 88 pattern_name, pattern_cb = self._current_pattern
113 if event.keyval == gtk.keysyms.space and not self._fs_window: 89 if event.keyval == gtk.keysyms.space and not self._fs_window:
114 self.display_full_screen(pattern_cb) 90 self.display_full_screen(pattern_cb)
115 return True 91 return True
116 92
117 def key_release_callback(self, widget, event): 93 def key_release_callback(self, widget, event):
118 pattern_name, pattern_cb = self._current_pattern 94 pattern_name, pattern_cb = self._current_pattern
119 if event.keyval == gtk.keysyms.space and self._fs_window is not None: 95 if event.keyval == gtk.keysyms.space and self._fs_window is not None:
120 self._fs_window.destroy() 96 self._fs_window.destroy()
121 self._fs_window = None 97 self._fs_window = None
122 self._current_pattern_shown = True 98 self._current_pattern_shown = True
123 elif event.keyval == gtk.keysyms.Tab and self._current_pattern_shown: 99 elif event.keyval == gtk.keysyms.Tab and self._current_pattern_shown:
124 self._status_map[pattern_name] = _FAILED 100 self._status_map[pattern_name] = ful.FAILED
125 self.goto_next_pattern() 101 self.goto_next_pattern()
126 elif event.keyval == gtk.keysyms.Return and self._current_pattern_shown: 102 elif event.keyval == gtk.keysyms.Return and self._current_pattern_shown:
127 self._status_map[pattern_name] = _PASSED 103 self._status_map[pattern_name] = ful.PASSED
128 self.goto_next_pattern() 104 self.goto_next_pattern()
129 elif event.keyval == ord('Q'): 105 elif event.keyval == ord('Q'):
130 factory_test.XXX_log('factory_Display exiting...')
131 gtk.main_quit() 106 gtk.main_quit()
132 else: 107 else:
133 factory_test.test_switch_on_trigger(event) 108 self._ft_state.exit_on_trigger(event)
134 self._test_widget.queue_draw() 109 self._test_widget.queue_draw()
135 return True 110 return True
136 111
137 def label_status_expose(self, widget, event, name=None): 112 def label_status_expose(self, widget, event, name=None):
138 status = self._status_map[name] 113 status = self._status_map[name]
139 widget.set_text(status) 114 widget.set_text(status)
140 widget.modify_fg(gtk.STATE_NORMAL, _LABEL_COLORS[status]) 115 widget.modify_fg(gtk.STATE_NORMAL, ful.LABEL_COLORS[status])
141 116
142 def make_pattern_label_box(self, name): 117 def make_pattern_label_box(self, name):
143 eb = gtk.EventBox() 118 eb = gtk.EventBox()
144 eb.modify_bg(gtk.STATE_NORMAL, _BLACK) 119 eb.modify_bg(gtk.STATE_NORMAL, ful.BLACK)
145 label_status = gtk.Label(_UNTESTED) 120 label_status = gtk.Label(ful.UNTESTED)
146 label_status.set_size_request(*_LABEL_STATUS_SIZE) 121 label_status.set_size_request(*_LABEL_STATUS_SIZE)
147 label_status.set_alignment(0, 0.5) 122 label_status.set_alignment(0, 0.5)
148 label_status.modify_font(_LABEL_STATUS_FONT) 123 label_status.modify_font(_LABEL_STATUS_FONT)
149 label_status.modify_fg(gtk.STATE_NORMAL, _LABEL_UNTESTED_FG) 124 label_status.modify_fg(gtk.STATE_NORMAL, _LABEL_UNTESTED_FG)
150 expose_cb = lambda *x: self.label_status_expose(*x, **{'name':name}) 125 expose_cb = lambda *x: self.label_status_expose(*x, **{'name':name})
151 label_status.connect('expose_event', expose_cb) 126 label_status.connect('expose_event', expose_cb)
152 label_en = gtk.Label(name) 127 label_en = gtk.Label(name)
153 label_en.set_alignment(1, 0.5) 128 label_en.set_alignment(1, 0.5)
154 label_en.modify_font(_LABEL_STATUS_FONT) 129 label_en.modify_font(_LABEL_STATUS_FONT)
155 label_en.modify_fg(gtk.STATE_NORMAL, _LABEL_FG) 130 label_en.modify_fg(gtk.STATE_NORMAL, _LABEL_FG)
156 label_sep = gtk.Label(' : ') 131 label_sep = gtk.Label(' : ')
157 label_sep.set_alignment(0.5, 0.5) 132 label_sep.set_alignment(0.5, 0.5)
158 label_sep.modify_font(_LABEL_FONT) 133 label_sep.modify_font(_LABEL_FONT)
159 label_sep.modify_fg(gtk.STATE_NORMAL, _LABEL_FG) 134 label_sep.modify_fg(gtk.STATE_NORMAL, _LABEL_FG)
160 hbox = gtk.HBox() 135 hbox = gtk.HBox()
161 hbox.pack_end(label_status, False, False) 136 hbox.pack_end(label_status, False, False)
162 hbox.pack_end(label_sep, False, False) 137 hbox.pack_end(label_sep, False, False)
163 hbox.pack_end(label_en, False, False) 138 hbox.pack_end(label_en, False, False)
164 eb.add(hbox) 139 eb.add(hbox)
165 return eb 140 return eb
166 141
167 def register_callbacks(self, window): 142 def register_callbacks(self, window):
168 window.connect('key-press-event', self.key_press_callback) 143 window.connect('key-press-event', self.key_press_callback)
169 window.add_events(gtk.gdk.KEY_PRESS_MASK) 144 window.add_events(gtk.gdk.KEY_PRESS_MASK)
170 window.connect('key-release-event', self.key_release_callback) 145 window.connect('key-release-event', self.key_release_callback)
171 window.add_events(gtk.gdk.KEY_RELEASE_MASK) 146 window.add_events(gtk.gdk.KEY_RELEASE_MASK)
172 147
173 def run_once(self, test_widget_size=None, trigger_set=None, 148 def run_once(self,
149 test_widget_size=None,
150 trigger_set=None,
174 result_file_path=None): 151 result_file_path=None):
175 152
176 factory_test.XXX_log('factory_Display') 153 factory.log('%s run_once' % self.__class__)
177 154
178 xset_status = os.system('xset r off') 155 xset_status = os.system('xset r off')
179 xmm_status = os.system('xmodmap -e "clear Lock"') 156 if xset_status:
180 if xset_status or xmm_status: 157 raise TestFail('ERROR: disabling key repeat')
181 raise TestFail('ERROR: disabling key repeat or caps lock')
182 158
183 factory_test.init(trigger_set=trigger_set, 159 self._ft_state = ful.State(
184 result_file_path=result_file_path) 160 trigger_set=trigger_set,
161 result_file_path=result_file_path)
185 162
186 self._pattern_queue = [x for x in reversed(_PATTERN_LIST)] 163 self._pattern_queue = [x for x in reversed(_PATTERN_LIST)]
187 self._status_map = dict((n, _UNTESTED) for n, f in _PATTERN_LIST) 164 self._status_map = dict((n, ful.UNTESTED) for n, f in _PATTERN_LIST)
188 165
189 prompt_label = gtk.Label('hold SPACE to display pattern,\n' 166 prompt_label = gtk.Label('hold SPACE to display pattern,\n'
190 'TAB to fail and RETURN to pass\n') 167 'TAB to fail and RETURN to pass\n')
191 prompt_label.modify_font(_LABEL_FONT) 168 prompt_label.modify_font(_LABEL_FONT)
192 prompt_label.set_alignment(0.5, 0.5) 169 prompt_label.set_alignment(0.5, 0.5)
193 prompt_label.modify_fg(gtk.STATE_NORMAL, _LABEL_FG) 170 prompt_label.modify_fg(gtk.STATE_NORMAL, _LABEL_FG)
194 self._prompt_label = prompt_label 171 self._prompt_label = prompt_label
195 172
196 vbox = gtk.VBox() 173 vbox = gtk.VBox()
197 vbox.pack_start(prompt_label, False, False) 174 vbox.pack_start(prompt_label, False, False)
198 175
199 for name, cb_fun in _PATTERN_LIST: 176 for name, cb_fun in _PATTERN_LIST:
200 label_box = self.make_pattern_label_box(name) 177 label_box = self.make_pattern_label_box(name)
201 vbox.pack_start(label_box, False, False) 178 vbox.pack_start(label_box, False, False)
202 179
203 test_widget = gtk.EventBox() 180 test_widget = gtk.EventBox()
204 test_widget.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse('black')) 181 test_widget.modify_bg(gtk.STATE_NORMAL, ful.BLACK)
205 test_widget.add(vbox) 182 test_widget.add(vbox)
206 self._test_widget = test_widget 183 self._test_widget = test_widget
207 184
208 self.goto_next_pattern() 185 self.goto_next_pattern()
209 186
210 self._fs_window = None 187 self._fs_window = None
211 188
212 factory_test.run_test_widget( 189 self._ft_state.run_test_widget(
213 test_widget=test_widget, 190 test_widget=test_widget,
214 test_widget_size=test_widget_size, 191 test_widget_size=test_widget_size,
215 window_registration_callback=self.register_callbacks) 192 window_registration_callback=self.register_callbacks)
216 193
217 failed_set = set(name for name, status in self._status_map.items() 194 failed_set = set(name for name, status in self._status_map.items()
218 if status is not _PASSED) 195 if status is not ful.PASSED)
219 if failed_set: 196 if failed_set:
220 raise error.TestFail('some patterns failed (%s)' % 197 raise error.TestFail('some patterns failed (%s)' %
221 ', '.join(failed_set)) 198 ', '.join(failed_set))
222 199
223 factory_test.XXX_log('exiting factory_Display') 200 factory.log('%s run_once finished' % self.__class__)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698