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

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

Issue 3038034: add shift key (Shift_L) LED to factory_Leds test (Closed) Base URL: ssh://git@chromiumos-git/autotest.git
Patch Set: tammo's feedback; fix orig png had oval cut-out Created 10 years, 4 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
« no previous file with comments | « no previous file | client/site_tests/factory_Leds/src/shf.png » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # -*- coding: utf-8 -*- 1 # -*- coding: utf-8 -*-
2 # 2 #
3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 7
8 # DESCRIPTION : 8 # DESCRIPTION :
9 # 9 #
10 # This is a factory test to test the LEDs (wifi, battery, etc). 10 # This is a factory test to test the LEDs (wifi, battery, etc).
(...skipping 25 matching lines...) Expand all
36 _ORANGE = gtk.gdk.color_parse('orange') 36 _ORANGE = gtk.gdk.color_parse('orange')
37 37
38 _LED_NAMES = 'sleepled battchgled wlan battfulled powerled 3g'.split() 38 _LED_NAMES = 'sleepled battchgled wlan battfulled powerled 3g'.split()
39 _ORANGE_LED_NAMES = _LED_NAMES[0:3] 39 _ORANGE_LED_NAMES = _LED_NAMES[0:3]
40 _BLUE_LED_NAMES = _LED_NAMES[3:] 40 _BLUE_LED_NAMES = _LED_NAMES[3:]
41 41
42 _LED_COUNT = 3 42 _LED_COUNT = 3
43 _LED_Y_OFFSET = 10 43 _LED_Y_OFFSET = 10
44 _LED_X_OFFSETS = [10, 80, 150] 44 _LED_X_OFFSETS = [10, 80, 150]
45 _LED_RADIUS = 18 45 _LED_RADIUS = 18
46 _SHFL_XYR = {'x':166,'y':20, 'r':9}
46 47
47 48
48 def run_led_ctl(led_ctl_path, args): 49 def run_led_ctl(led_ctl_path, args):
49 rc = subprocess.call([led_ctl_path] + args.split()) 50 rc = subprocess.call([led_ctl_path] + args.split())
50 if rc != 1: 51 if rc != 1:
51 factory.log('%s(%s) failed with rc %s' % (led_ctl_path, args, rc)) 52 factory.log('%s(%s) failed with rc %s' % (led_ctl_path, args, rc))
52 53
53 54
54 def pattern_all_off(led_ctl_fn): 55 def pattern_all_off(led_ctl_fn):
55 for n in _LED_NAMES: 56 for n in _LED_NAMES:
56 led_ctl_fn('-%s -off' % n) 57 led_ctl_fn('-%s -off' % n)
57 return [ful.BLACK, ful.BLACK, ful.BLACK] 58 return [ful.BLACK, ful.BLACK, ful.BLACK]
58 59
59 def pattern_blue_on(led_ctl_fn): 60 def pattern_blue_on(led_ctl_fn):
60 pattern_all_off(led_ctl_fn) 61 pattern_all_off(led_ctl_fn)
61 for n in _BLUE_LED_NAMES: 62 for n in _BLUE_LED_NAMES:
62 led_ctl_fn('-%s -on' % n) 63 led_ctl_fn('-%s -on' % n)
63 return [ful.BLUE, ful.BLUE, ful.BLUE] 64 return [ful.BLUE, ful.BLUE, ful.BLUE]
64 65
65 def pattern_orange_on(led_ctl_fn): 66 def pattern_orange_on(led_ctl_fn):
66 pattern_all_off(led_ctl_fn) 67 pattern_all_off(led_ctl_fn)
67 for n in _ORANGE_LED_NAMES: 68 for n in _ORANGE_LED_NAMES:
68 led_ctl_fn('-%s -on' % n) 69 led_ctl_fn('-%s -on' % n)
69 return [_ORANGE, _ORANGE, _ORANGE] 70 return [_ORANGE, _ORANGE, _ORANGE]
70 71
71 _PATTERN_LIST = [ 72 _PATTERN_LIST = [
72 ('all off', pattern_all_off), 73 ('all off', pattern_all_off),
73 ('blue on', pattern_blue_on), 74 ('blue on', pattern_blue_on),
74 ('orange on', pattern_orange_on)] 75 ('orange on', pattern_orange_on),
76 ('shift led', False)]
75 77
76 78
77 class factory_Leds(test.test): 79 class factory_Leds(test.test):
78 version = 1 80 version = 1
79 preserve_srcdir = True 81 preserve_srcdir = True
80 82
81 def goto_next_pattern(self): 83 def goto_next_pattern(self):
82 if not self._pattern_queue: 84 if not self._pattern_queue:
83 gtk.main_quit() 85 gtk.main_quit()
84 return 86 return
85 self._current_pattern, cb_fn = self._pattern_queue.pop() 87 self._current_pattern, cb_fn = self._pattern_queue.pop()
86 self._status_map[self._current_pattern] = ful.ACTIVE 88 self._status_map[self._current_pattern] = ful.ACTIVE
87 led_ctl_fn = lambda args: run_led_ctl(self._led_ctl_path, args) 89 if cb_fn:
88 self._led_colors = cb_fn(led_ctl_fn) 90 led_ctl_fn = lambda args: run_led_ctl(self._led_ctl_path, args)
91 self._led_colors = cb_fn(led_ctl_fn)
92 else:
93 self._pattern_da.connect('expose_event', self.shift_led_expose)
89 self._pattern_da.queue_draw() 94 self._pattern_da.queue_draw()
90 95
96 def shift_led_expose(self, widget, event):
97 context = widget.window.cairo_create()
98 context.set_source_surface(self._shf_image, 0, 0)
99 context.paint()
100
101 if self._shift_cnt is 2:
102 if self._shift_color is ful.BLACK:
103 self._shift_color = ful.BLUE
104 else:
105 self._shift_color = ful.BLACK
106 self._shift_cnt = 0
107 context.set_source_color(self._shift_color)
108 context.arc(_SHFL_XYR['x'], _SHFL_XYR['y'], _SHFL_XYR['r'],
109 0.0, 2.0 * pi)
110 context.fill()
111
91 def pattern_expose(self, widget, event): 112 def pattern_expose(self, widget, event):
92 context = widget.window.cairo_create() 113 context = widget.window.cairo_create()
93 context.set_source_surface(self._leds_image, 0, 0) 114 context.set_source_surface(self._leds_image, 0, 0)
94 context.paint() 115 context.paint()
95 for led_index in range(_LED_COUNT): 116 for led_index in range(_LED_COUNT):
96 color = self._led_colors[led_index] 117 color = self._led_colors[led_index]
97 x_offset = _LED_X_OFFSETS[led_index] + _LED_RADIUS + 3 118 x_offset = _LED_X_OFFSETS[led_index] + _LED_RADIUS + 3
98 y_offset = _LED_Y_OFFSET + _LED_RADIUS + 3 119 y_offset = _LED_Y_OFFSET + _LED_RADIUS + 3
99 context.set_source_color(color) 120 context.set_source_color(color)
100 context.arc(x_offset, y_offset, _LED_RADIUS, 0.0, 2.0 * pi) 121 context.arc(x_offset, y_offset, _LED_RADIUS, 0.0, 2.0 * pi)
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 eb.add(hbox) 155 eb.add(hbox)
135 return eb 156 return eb
136 157
137 def key_release_callback(self, widget, event): 158 def key_release_callback(self, widget, event):
138 if event.keyval == gtk.keysyms.Tab: 159 if event.keyval == gtk.keysyms.Tab:
139 self._status_map[self._current_pattern] = ful.FAILED 160 self._status_map[self._current_pattern] = ful.FAILED
140 self.goto_next_pattern() 161 self.goto_next_pattern()
141 elif event.keyval == gtk.keysyms.Return: 162 elif event.keyval == gtk.keysyms.Return:
142 self._status_map[self._current_pattern] = ful.PASSED 163 self._status_map[self._current_pattern] = ful.PASSED
143 self.goto_next_pattern() 164 self.goto_next_pattern()
165 elif self._current_pattern.startswith("shift") and \
166 event.keyval == gtk.keysyms.Shift_L:
167 self._shift_cnt += 1
168 self._pattern_da.queue_draw()
144 else: 169 else:
145 self._ft_state.exit_on_trigger(event) 170 self._ft_state.exit_on_trigger(event)
146 return True 171 return True
147 172
148 def register_callbacks(self, window): 173 def register_callbacks(self, window):
149 window.connect('key-release-event', self.key_release_callback) 174 window.connect('key-release-event', self.key_release_callback)
150 window.add_events(gdk.KEY_RELEASE_MASK) 175 window.add_events(gdk.KEY_RELEASE_MASK)
151 176
152 def run_once(self, 177 def run_once(self,
153 test_widget_size=None, 178 test_widget_size=None,
154 trigger_set=None, 179 trigger_set=None,
155 led_ctl_path=None): 180 led_ctl_path=None):
156 181
157 factory.log('%s run_once' % self.__class__) 182 factory.log('%s run_once' % self.__class__)
158 183
159 self._ft_state = ful.State(trigger_set) 184 self._ft_state = ful.State(trigger_set)
160 185
161 self._led_ctl_path = led_ctl_path 186 self._led_ctl_path = led_ctl_path
162 187
188 self._shift_color = ful.BLACK
189 self._shift_cnt = 0
190
163 os.chdir(self.srcdir) 191 os.chdir(self.srcdir)
164 image = cairo.ImageSurface.create_from_png('leds.png') 192 image = cairo.ImageSurface.create_from_png('leds.png')
165 image_size = (image.get_width(), image.get_height()) 193 image_size = (image.get_width(), image.get_height())
166 self._leds_image = image 194 self._leds_image = image
167 195
196 image = cairo.ImageSurface.create_from_png('shf.png')
197 self._shf_image = image
198
168 self._pattern_queue = [x for x in reversed(_PATTERN_LIST)] 199 self._pattern_queue = [x for x in reversed(_PATTERN_LIST)]
169 self._status_map = dict((n, ful.UNTESTED) for n, f in _PATTERN_LIST) 200 self._status_map = dict((n, ful.UNTESTED) for n, f in _PATTERN_LIST)
170 201
171 pattern_da = gtk.DrawingArea() 202 pattern_da = gtk.DrawingArea()
172 pattern_da.set_size_request(*image_size) 203 pattern_da.set_size_request(*image_size)
173 pattern_da.connect('expose_event', self.pattern_expose) 204 pattern_da.connect('expose_event', self.pattern_expose)
174 self._pattern_da = pattern_da 205 self._pattern_da = pattern_da
175 206
176 pattern_label = ful.make_label(_PATTERN_LABEL_STR) 207 pattern_label = ful.make_label(_PATTERN_LABEL_STR)
177 208
(...skipping 27 matching lines...) Expand all
205 window_registration_callback=self.register_callbacks, 236 window_registration_callback=self.register_callbacks,
206 cleanup_callback=self.quit) 237 cleanup_callback=self.quit)
207 238
208 failed_set = set(name for name, status in self._status_map.items() 239 failed_set = set(name for name, status in self._status_map.items()
209 if status is not ful.PASSED) 240 if status is not ful.PASSED)
210 if failed_set: 241 if failed_set:
211 raise error.TestFail('some patterns failed (%s)' % 242 raise error.TestFail('some patterns failed (%s)' %
212 ', '.join(failed_set)) 243 ', '.join(failed_set))
213 244
214 factory.log('%s run_once finished' % self.__class__) 245 factory.log('%s run_once finished' % self.__class__)
OLDNEW
« no previous file with comments | « no previous file | client/site_tests/factory_Leds/src/shf.png » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698