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

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

Issue 2857012: Batched update of factory tests. (Closed) Base URL: ssh://gitrw.chromium.org/autotest.git
Patch Set: finished comment Created 10 years, 6 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
(Empty)
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
3 # found in the LICENSE file.
4
5
6 # DESCRIPTION :
7 #
8 # This is an example factory test that does not really do anything --
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
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
19 import gtk
20 import pango
21 import os
22 import sys
23
24
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
46 _LABEL_STATUS_SIZE = (140, 30)
47 _LABEL_STATUS_FONT = pango.FontDescription('courier new condensed 16')
48 _LABEL_FONT = pango.FontDescription('courier new condensed 20')
49 _LABEL_FG = gtk.gdk.color_parse('light green')
50 _LABEL_UNTESTED_FG = gtk.gdk.color_parse('grey40')
51
52
53 def pattern_cb_solid(widget, event, color=None):
54 dr = widget.window
55 xmax, ymax = dr.get_size()
56 gc = gtk.gdk.GC(dr)
57 gc.set_rgb_fg_color(color)
58 dr.draw_rectangle(gc, True, 0, 0, xmax, ymax)
59 return False
60
61
62 def pattern_cb_grid(widget, event, color=None):
63 dr = widget.window
64 xmax, ymax = dr.get_size()
65 gc = gtk.gdk.GC(dr)
66 gc.set_rgb_fg_color(_BLACK)
67 dr.draw_rectangle(gc, True, 0, 0, xmax, ymax)
68 gc.set_rgb_fg_color(color)
69 gc.set_line_attributes(1,
70 gtk.gdk.LINE_SOLID,
71 gtk.gdk.CAP_BUTT,
72 gtk.gdk.JOIN_MITER)
73 for x in range(0, xmax, 20):
74 dr.draw_line(gc, x, 0, x, ymax)
75 for y in range(0, ymax, 20):
76 dr.draw_line(gc, 0, y, xmax, y)
77 return False
78
79
80 _PATTERN_LIST = [
81 ('solid red', lambda *x: pattern_cb_solid(*x, **{'color':_RED})),
82 ('solid green', lambda *x: pattern_cb_solid(*x, **{'color':_GREEN})),
83 ('solid blue', lambda *x: pattern_cb_solid(*x, **{'color':_BLUE})),
84 ('solid white', lambda *x: pattern_cb_solid(*x, **{'color':_WHITE})),
85 ('grid', lambda *x: pattern_cb_grid(*x, **{'color':_GREEN}))]
86
87
88 class factory_Display(test.test):
89 version = 1
90
91 def display_full_screen(self, pattern_callback):
92 window = gtk.Window(gtk.WINDOW_TOPLEVEL)
93 screen = window.get_screen()
94 screen_size = (screen.get_width(), screen.get_height())
95 window.set_size_request(*screen_size)
96 drawing_area = gtk.DrawingArea()
97 window.add(drawing_area)
98 window.show_all()
99 self._fs_window = window
100 drawing_area.connect('expose_event', pattern_callback)
101
102 def goto_next_pattern(self):
103 if not self._pattern_queue:
104 gtk.main_quit()
105 return
106 self._current_pattern = self._pattern_queue.pop()
107 name, cb_fn = self._current_pattern
108 self._status_map[name] = _ACTIVE
109 self._current_pattern_shown = False
110
111 def key_press_callback(self, widget, event):
112 pattern_name, pattern_cb = self._current_pattern
113 if event.keyval == gtk.keysyms.space and not self._fs_window:
114 self.display_full_screen(pattern_cb)
115 return True
116
117 def key_release_callback(self, widget, event):
118 pattern_name, pattern_cb = self._current_pattern
119 if event.keyval == gtk.keysyms.space and self._fs_window is not None:
120 self._fs_window.destroy()
121 self._fs_window = None
122 self._current_pattern_shown = True
123 elif event.keyval == gtk.keysyms.Tab and self._current_pattern_shown:
124 self._status_map[pattern_name] = _FAILED
125 self.goto_next_pattern()
126 elif event.keyval == gtk.keysyms.Return and self._current_pattern_shown:
127 self._status_map[pattern_name] = _PASSED
128 self.goto_next_pattern()
129 elif event.keyval == ord('Q'):
130 factory_test.XXX_log('factory_Display exiting...')
131 gtk.main_quit()
132 else:
133 factory_test.test_switch_on_trigger(event)
134 self._test_widget.queue_draw()
135 return True
136
137 def label_status_expose(self, widget, event, name=None):
138 status = self._status_map[name]
139 widget.set_text(status)
140 widget.modify_fg(gtk.STATE_NORMAL, _LABEL_COLORS[status])
141
142 def make_pattern_label_box(self, name):
143 eb = gtk.EventBox()
144 eb.modify_bg(gtk.STATE_NORMAL, _BLACK)
145 label_status = gtk.Label(_UNTESTED)
146 label_status.set_size_request(*_LABEL_STATUS_SIZE)
147 label_status.set_alignment(0, 0.5)
148 label_status.modify_font(_LABEL_STATUS_FONT)
149 label_status.modify_fg(gtk.STATE_NORMAL, _LABEL_UNTESTED_FG)
150 expose_cb = lambda *x: self.label_status_expose(*x, **{'name':name})
151 label_status.connect('expose_event', expose_cb)
152 label_en = gtk.Label(name)
153 label_en.set_alignment(1, 0.5)
154 label_en.modify_font(_LABEL_STATUS_FONT)
155 label_en.modify_fg(gtk.STATE_NORMAL, _LABEL_FG)
156 label_sep = gtk.Label(' : ')
157 label_sep.set_alignment(0.5, 0.5)
158 label_sep.modify_font(_LABEL_FONT)
159 label_sep.modify_fg(gtk.STATE_NORMAL, _LABEL_FG)
160 hbox = gtk.HBox()
161 hbox.pack_end(label_status, False, False)
162 hbox.pack_end(label_sep, False, False)
163 hbox.pack_end(label_en, False, False)
164 eb.add(hbox)
165 return eb
166
167 def register_callbacks(self, window):
168 window.connect('key-press-event', self.key_press_callback)
169 window.add_events(gtk.gdk.KEY_PRESS_MASK)
170 window.connect('key-release-event', self.key_release_callback)
171 window.add_events(gtk.gdk.KEY_RELEASE_MASK)
172
173 def run_once(self, test_widget_size=None, trigger_set=None,
174 result_file_path=None):
175
176 factory_test.XXX_log('factory_Display')
177
178 xset_status = os.system('xset r off')
179 xmm_status = os.system('xmodmap -e "clear Lock"')
180 if xset_status or xmm_status:
181 raise TestFail('ERROR: disabling key repeat or caps lock')
182
183 factory_test.init(trigger_set=trigger_set,
184 result_file_path=result_file_path)
185
186 self._pattern_queue = [x for x in reversed(_PATTERN_LIST)]
187 self._status_map = dict((n, _UNTESTED) for n, f in _PATTERN_LIST)
188
189 prompt_label = gtk.Label('hold SPACE to display pattern,\n'
190 'TAB to fail and RETURN to pass\n')
191 prompt_label.modify_font(_LABEL_FONT)
192 prompt_label.set_alignment(0.5, 0.5)
193 prompt_label.modify_fg(gtk.STATE_NORMAL, _LABEL_FG)
194 self._prompt_label = prompt_label
195
196 vbox = gtk.VBox()
197 vbox.pack_start(prompt_label, False, False)
198
199 for name, cb_fun in _PATTERN_LIST:
200 label_box = self.make_pattern_label_box(name)
201 vbox.pack_start(label_box, False, False)
202
203 test_widget = gtk.EventBox()
204 test_widget.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse('black'))
205 test_widget.add(vbox)
206 self._test_widget = test_widget
207
208 self.goto_next_pattern()
209
210 self._fs_window = None
211
212 factory_test.run_test_widget(
213 test_widget=test_widget,
214 test_widget_size=test_widget_size,
215 window_registration_callback=self.register_callbacks)
216
217 failed_set = set(name for name, status in self._status_map.items()
218 if status is not _PASSED)
219 if failed_set:
220 raise error.TestFail('some patterns failed (%s)' %
221 ', '.join(failed_set))
222
223 factory_test.XXX_log('exiting factory_Display')
OLDNEW
« no previous file with comments | « client/deps/factory/ui ('k') | client/site_tests/factory_ExternalStorage/factory_ExternalStorage.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698