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

Side by Side Diff: client/site_tests/factory_ExternalStorage/factory_ExternalStorage.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 external SD and USB ports.
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.bin import utils
17 from autotest_lib.client.common_lib import error
18 from autotest_lib.client.common_lib import factory_test
19 10
20 import gobject 11 import gobject
21 import gtk 12 import gtk
22 import pango 13 import pango
23 import os 14 import os
24 import sys 15 import sys
25 16
17 from autotest_lib.client.bin import factory
18 from autotest_lib.client.bin import factory_ui_lib as ful
19 from autotest_lib.client.bin import test
20 from autotest_lib.client.bin import utils
21 from autotest_lib.client.common_lib import error
22
26 23
27 _STATE_WAIT_INSERT = 1 24 _STATE_WAIT_INSERT = 1
28 _STATE_WAIT_REMOVE = 2 25 _STATE_WAIT_REMOVE = 2
29 26
30 27
31 def find_root_dev(): 28 def find_root_dev():
32 rootdev = utils.system_output('rootdev') 29 rootdev = utils.system_output('rootdev')
33 return os.path.basename(rootdev[:-1]) 30 return os.path.basename(rootdev[:-1])
34 31
35 32
36 def find_all_storage_dev(): 33 def find_all_storage_dev():
37 lssys = utils.run('ls -d /sys/block/sd*') 34 lssys = utils.run('ls -d /sys/block/sd*')
38 devices = lssys.stdout.rsplit('\n') 35 devices = lssys.stdout.rsplit('\n')
39 new_devices = set(os.path.basename(d.rstrip()) for d in devices if d) 36 new_devices = set(os.path.basename(d.rstrip()) for d in devices if d)
40 return new_devices 37 return new_devices
41 38
42 39
43 class factory_ExternalStorage(test.test): 40 class factory_ExternalStorage(test.test):
44 version = 1 41 version = 1
45 42
46 def key_release_callback(self, widget, event): 43 def key_release_callback(self, widget, event):
47 char = event.keyval in range(32,127) and chr(event.keyval) or None 44 char = event.keyval in range(32,127) and chr(event.keyval) or None
48 factory_test.XXX_log('key_release_callback %s(%s)' % 45 factory.log('key_release_callback %s(%s)' %
49 (event.keyval, char)) 46 (event.keyval, char))
50 factory_test.test_switch_on_trigger(event) 47 self._ft_state.exit_on_trigger(event)
51 return True 48 return True
52 49
53 def register_callbacks(self, window): 50 def register_callbacks(self, window):
54 window.connect('key-release-event', self.key_release_callback) 51 window.connect('key-release-event', self.key_release_callback)
55 window.add_events(gtk.gdk.KEY_RELEASE_MASK) 52 window.add_events(gtk.gdk.KEY_RELEASE_MASK)
56 53
57 def rescan_storage(self, test_tag): 54 def rescan_storage(self, test_tag):
58 if self._state == _STATE_WAIT_INSERT: 55 if self._state == _STATE_WAIT_INSERT:
59 new_devices = find_all_storage_dev() 56 new_devices = find_all_storage_dev()
60 diff = new_devices - self._devices 57 diff = new_devices - self._devices
61 if diff: 58 if diff:
62 self._devices = new_devices 59 self._devices = new_devices
63 factory_test.XXX_log('found new devs : %s' % diff) 60 factory.log('found new devs : %s' % diff)
64 self._target_device = diff.pop() 61 self._target_device = diff.pop()
65 devpath = '/dev/%s' % self._target_device 62 devpath = '/dev/%s' % self._target_device
66 self._prompt.set_test('testing drive %s...', devpath) 63 self._prompt.set_test('testing drive %s...', devpath)
67 gtk.main_iteration() 64 gtk.main_iteration()
68 test._result = self.job.run_test('hardware_StorageFio', 65 test._result = self.job.run_test('hardware_StorageFio',
69 dev=devpath, tag=test_tag) 66 dev=devpath, tag=test_tag)
70 self._prompt.set_test('remove USB drive...') 67 self._prompt.set_test('remove USB drive...')
71 self._state = _STATE_WAIT_REMOVE 68 self._state = _STATE_WAIT_REMOVE
72 else: 69 else:
73 diff = self._devices - find_all_storage_dev() 70 diff = self._devices - find_all_storage_dev()
74 if diff: 71 if diff:
75 if diff != set(self._target_device): 72 if diff != set(self._target_device):
76 raise error.TestFail('too many devs removed (%s vs %s)' % 73 raise error.TestFail('too many devs removed (%s vs %s)' %
77 (diff, self._target_device)) 74 (diff, self._target_device))
78 gtk.main_quit() 75 gtk.main_quit()
79 return True 76 return True
80 77
81 def run_once(self, test_widget_size=None, trigger_set=None, 78 def run_once(self, test_widget_size=None, trigger_set=None,
82 result_file_path=None, test_tag_prefix=None, test_count=None): 79 result_file_path=None, test_tag_prefix=None, test_count=None):
83 80
84 factory_test.XXX_log('factory_ExternalStorage %s %s' % 81 factory.log('%s run_once' % self.__class__)
85 (test_tag_prefix, test_count))
86 82
87 test_tag = '%s_%s' % (test_tag_prefix, test_count) 83 test_tag = '%s_%s' % (test_tag_prefix, test_count)
84 factory.log('test_tag = %s' % test_tag)
88 85
89 factory_test.init(trigger_set=trigger_set, 86 self._ft_state = ful.State(
90 result_file_path=result_file_path) 87 trigger_set=trigger_set,
88 result_file_path=result_file_path)
91 89
92 label = gtk.Label('') 90 label = gtk.Label('')
93 label.modify_font(pango.FontDescription('courier new condensed 20')) 91 label.modify_font(pango.FontDescription('courier new condensed 20'))
94 label.set_alignment(0.5, 0.5) 92 label.set_alignment(0.5, 0.5)
95 label.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse('light green')) 93 label.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse('light green'))
96 self._prompt = label 94 self._prompt = label
97 95
98 test_widget = gtk.EventBox() 96 test_widget = gtk.EventBox()
99 test_widget.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse('black')) 97 test_widget.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse('black'))
100 test_widget.add(label) 98 test_widget.add(label)
101 99
102 self._prompt.set_text('insert USB drive...') 100 self._prompt.set_text('insert USB drive...')
103 self._state = _STATE_WAIT_INSERT 101 self._state = _STATE_WAIT_INSERT
104 self._result = False 102 self._result = False
105 self._devices = find_all_storage_dev() 103 self._devices = find_all_storage_dev()
106 gobject.timeout_add(250, self.rescan_storage, test_tag) 104 gobject.timeout_add(250, self.rescan_storage, test_tag)
107 105
108 factory_test.run_test_widget( 106 self._ft_state.run_test_widget(
109 test_widget=test_widget, 107 test_widget=test_widget,
110 test_widget_size=test_widget_size, 108 test_widget_size=test_widget_size,
111 window_registration_callback=self.register_callbacks) 109 window_registration_callback=self.register_callbacks)
112 110
113 factory_test.XXX_log('exiting factory_ExternalStorage') 111 factory.log('%s run_once finished' % self.__class__)
OLDNEW
« no previous file with comments | « client/site_tests/factory_Dummy/factory_Dummy.py ('k') | client/site_tests/factory_Keyboard/KeyboardTest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698