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

Side by Side Diff: client/site_tests/factory_Camera/factory_Camera.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 test looks in "/dev/video0" for a v4l2 video capture device, 8 # This test looks in "/dev/video0" for a v4l2 video capture device,
9 # and starts streaming captured frames on the monitor. 9 # and starts streaming captured frames on the monitor.
10 # The observer then decides if the captured image looks good or defective, 10 # The observer then decides if the captured image looks good or defective,
11 # pressing enter key to let it pass or tab key to fail. 11 # pressing enter key to let it pass or tab key to fail.
12 12
13 from autotest_lib.client.bin import test
14 from autotest_lib.client.common_lib import error
15 from autotest_lib.client.common_lib import factory_test
16 13
17 import gtk 14 import gtk
18 from gtk import gdk 15 from gtk import gdk
19 import glib 16 import glib
20 import pango 17 import pango
21 import numpy 18 import numpy
22 19
20 from autotest_lib.client.bin import factory
21 from autotest_lib.client.bin import factory_ui_lib as ful
22 from autotest_lib.client.bin import test
23 from autotest_lib.client.common_lib import error
24
23 import v4l2 25 import v4l2
24 26
27
25 DEVICE_NAME = "/dev/video0" 28 DEVICE_NAME = "/dev/video0"
26 PREFERRED_WIDTH = 320 29 PREFERRED_WIDTH = 320
27 PREFERRED_HEIGHT = 240 30 PREFERRED_HEIGHT = 240
28 PREFERRED_BUFFER_COUNT = 4 31 PREFERRED_BUFFER_COUNT = 4
29 32
33
30 class factory_Camera(test.test): 34 class factory_Camera(test.test):
31 version = 1 35 version = 1
32 key_good = gdk.keyval_from_name('Return') 36 key_good = gdk.keyval_from_name('Return')
33 key_bad = gdk.keyval_from_name('Tab') 37 key_bad = gdk.keyval_from_name('Tab')
34 38
35 @staticmethod 39 @staticmethod
36 def get_best_frame_size(dev, pixel_format, width, height): 40 def get_best_frame_size(dev, pixel_format, width, height):
37 """Given the preferred frame size, find a reasonable frame size the 41 """Given the preferred frame size, find a reasonable frame size the
38 capture device is capable of. 42 capture device is capable of.
39 43
(...skipping 14 matching lines...) Expand all
54 return min(good_sizes, key=lambda x: x[0] * x[1]) 58 return min(good_sizes, key=lambda x: x[0] * x[1])
55 return max(sizes, key=lambda x: x[0] * x[1]) 59 return max(sizes, key=lambda x: x[0] * x[1])
56 60
57 def render(self, pixels): 61 def render(self, pixels):
58 numpy.maximum(pixels, 0, pixels) 62 numpy.maximum(pixels, 0, pixels)
59 numpy.minimum(pixels, 255, pixels) 63 numpy.minimum(pixels, 255, pixels)
60 self.pixels[:] = pixels 64 self.pixels[:] = pixels
61 self.img.queue_draw() 65 self.img.queue_draw()
62 66
63 def key_release_callback(self, widget, event): 67 def key_release_callback(self, widget, event):
64 factory_test.XXX_log('key_release_callback %s(%s)' % 68 factory.log('key_release_callback %s(%s)' %
65 (event.keyval, gdk.keyval_name(event.keyval))) 69 (event.keyval, gdk.keyval_name(event.keyval)))
66 if event.keyval == self.key_good: 70 if event.keyval == self.key_good:
67 self.fail = False 71 self.fail = False
68 gtk.main_quit() 72 gtk.main_quit()
69 if event.keyval == self.key_bad: 73 if event.keyval == self.key_bad:
70 gtk.main_quit() 74 gtk.main_quit()
71 return factory_test.test_switch_on_trigger(event) 75 self.ft_state.exit_on_trigger(event)
76 return
72 77
73 def register_callbacks(self, w): 78 def register_callbacks(self, w):
74 w.connect('key-release-event', self.key_release_callback) 79 w.connect('key-release-event', self.key_release_callback)
75 w.add_events(gdk.KEY_RELEASE_MASK) 80 w.add_events(gdk.KEY_RELEASE_MASK)
76 81
77 def run_once(self, test_widget_size=None, trigger_set=None, 82 def run_once(self, test_widget_size=None, trigger_set=None,
78 result_file_path=None): 83 result_file_path=None):
79 84
85 factory.log('%s run_once' % self.__class__)
86
80 self.fail = True 87 self.fail = True
81 88
82 factory_test.XXX_log('factory_Camera') 89 self.ft_state = ful.State(
83 90 trigger_set=trigger_set,
84 factory_test.init(trigger_set=trigger_set, 91 result_file_path=result_file_path)
85 result_file_path=result_file_path)
86 92
87 label = gtk.Label( 93 label = gtk.Label(
88 "Press %s key if the image looks good\nPress %s otherwise" 94 "Press %s key if the image looks good\nPress %s otherwise"
89 % (gdk.keyval_name(self.key_good),gdk.keyval_name(self.key_bad))) 95 % (gdk.keyval_name(self.key_good),gdk.keyval_name(self.key_bad)))
90 96
91 label.modify_font(pango.FontDescription('courier new condensed 12')) 97 label.modify_font(pango.FontDescription('courier new condensed 12'))
92 label.modify_fg(gtk.STATE_NORMAL, gdk.color_parse('light green')) 98 label.modify_fg(gtk.STATE_NORMAL, gdk.color_parse('light green'))
93 99
94 test_widget = gtk.VBox() 100 test_widget = gtk.VBox()
95 test_widget.modify_bg(gtk.STATE_NORMAL, gdk.color_parse('black')) 101 test_widget.modify_bg(gtk.STATE_NORMAL, gdk.color_parse('black'))
(...skipping 23 matching lines...) Expand all
119 self.pixbuf = gdk.Pixbuf(gdk.COLORSPACE_RGB, False, 8, 125 self.pixbuf = gdk.Pixbuf(gdk.COLORSPACE_RGB, False, 8,
120 width, height) 126 width, height)
121 self.pixels = self.pixbuf.get_pixels_array() 127 self.pixels = self.pixbuf.get_pixels_array()
122 self.img = gtk.image_new_from_pixbuf(self.pixbuf) 128 self.img = gtk.image_new_from_pixbuf(self.pixbuf)
123 self.test_widget.add(self.img) 129 self.test_widget.add(self.img)
124 self.img.show() 130 self.img.show()
125 131
126 dev.capture_mmap_prepare(PREFERRED_BUFFER_COUNT, 2) 132 dev.capture_mmap_prepare(PREFERRED_BUFFER_COUNT, 2)
127 dev.capture_mmap_start() 133 dev.capture_mmap_start()
128 134
129 factory_test.run_test_widget( 135 self.ft_state.run_test_widget(
130 test_widget=test_widget, 136 test_widget=test_widget,
131 test_widget_size=test_widget_size, 137 test_widget_size=test_widget_size,
132 window_registration_callback=self.register_callbacks) 138 window_registration_callback=self.register_callbacks)
133 139
134 dev.capture_mmap_stop() 140 dev.capture_mmap_stop()
135 dev.capture_mmap_finish() 141 dev.capture_mmap_finish()
136 142
137 if self.fail: 143 if self.fail:
138 raise error.TestFail('camera test failed by user indication') 144 raise error.TestFail('camera test failed by user indication')
139 145
140 factory_test.XXX_log('exiting factory_Camera') 146 factory.log('%s run_once finished' % self.__class__)
OLDNEW
« no previous file with comments | « client/common_lib/factory_test.py ('k') | client/site_tests/factory_DeveloperRecovery/DevRecTest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698