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

Unified Diff: client/site_tests/factory_ExternalStorage/factory_ExternalStorage.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 side-by-side diff with in-line comments
Download patch
Index: client/site_tests/factory_ExternalStorage/factory_ExternalStorage.py
diff --git a/client/site_tests/factory_ExternalStorage/factory_ExternalStorage.py b/client/site_tests/factory_ExternalStorage/factory_ExternalStorage.py
new file mode 100644
index 0000000000000000000000000000000000000000..51d1cf365b35e927990f0b4db4d7db401df23d6f
--- /dev/null
+++ b/client/site_tests/factory_ExternalStorage/factory_ExternalStorage.py
@@ -0,0 +1,113 @@
+# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+
+# DESCRIPTION :
+#
+# This is an example factory test that does not really do anything --
+# it displays a message in the center of the testing area, as
+# communicated by arguments to run_once(). This test makes use of the
+# factory_test library to display its UI, and to monitor keyboard
+# events for test-switching triggers. This test can be terminated by
+# typing SHIFT-Q.
+
+from autotest_lib.client.bin import test
+from autotest_lib.client.bin import utils
+from autotest_lib.client.common_lib import error
+from autotest_lib.client.common_lib import factory_test
+
+import gobject
+import gtk
+import pango
+import os
+import sys
+
+
+_STATE_WAIT_INSERT = 1
+_STATE_WAIT_REMOVE = 2
+
+
+def find_root_dev():
+ rootdev = utils.system_output('rootdev')
+ return os.path.basename(rootdev[:-1])
+
+
+def find_all_storage_dev():
+ lssys = utils.run('ls -d /sys/block/sd*')
+ devices = lssys.stdout.rsplit('\n')
+ new_devices = set(os.path.basename(d.rstrip()) for d in devices if d)
+ return new_devices
+
+
+class factory_ExternalStorage(test.test):
+ version = 1
+
+ def key_release_callback(self, widget, event):
+ char = event.keyval in range(32,127) and chr(event.keyval) or None
+ factory_test.XXX_log('key_release_callback %s(%s)' %
+ (event.keyval, char))
+ factory_test.test_switch_on_trigger(event)
+ return True
+
+ def register_callbacks(self, window):
+ window.connect('key-release-event', self.key_release_callback)
+ window.add_events(gtk.gdk.KEY_RELEASE_MASK)
+
+ def rescan_storage(self, test_tag):
+ if self._state == _STATE_WAIT_INSERT:
+ new_devices = find_all_storage_dev()
+ diff = new_devices - self._devices
+ if diff:
+ self._devices = new_devices
+ factory_test.XXX_log('found new devs : %s' % diff)
+ self._target_device = diff.pop()
+ devpath = '/dev/%s' % self._target_device
+ self._prompt.set_test('testing drive %s...', devpath)
+ gtk.main_iteration()
+ test._result = self.job.run_test('hardware_StorageFio',
+ dev=devpath, tag=test_tag)
+ self._prompt.set_test('remove USB drive...')
+ self._state = _STATE_WAIT_REMOVE
+ else:
+ diff = self._devices - find_all_storage_dev()
+ if diff:
+ if diff != set(self._target_device):
+ raise error.TestFail('too many devs removed (%s vs %s)' %
+ (diff, self._target_device))
+ gtk.main_quit()
+ return True
+
+ def run_once(self, test_widget_size=None, trigger_set=None,
+ result_file_path=None, test_tag_prefix=None, test_count=None):
+
+ factory_test.XXX_log('factory_ExternalStorage %s %s' %
+ (test_tag_prefix, test_count))
+
+ test_tag = '%s_%s' % (test_tag_prefix, test_count)
+
+ factory_test.init(trigger_set=trigger_set,
+ result_file_path=result_file_path)
+
+ label = gtk.Label('')
+ label.modify_font(pango.FontDescription('courier new condensed 20'))
+ label.set_alignment(0.5, 0.5)
+ label.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse('light green'))
+ self._prompt = label
+
+ test_widget = gtk.EventBox()
+ test_widget.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse('black'))
+ test_widget.add(label)
+
+ self._prompt.set_text('insert USB drive...')
+ self._state = _STATE_WAIT_INSERT
+ self._result = False
+ self._devices = find_all_storage_dev()
+ gobject.timeout_add(250, self.rescan_storage, test_tag)
+
+ factory_test.run_test_widget(
+ test_widget=test_widget,
+ test_widget_size=test_widget_size,
+ window_registration_callback=self.register_callbacks)
+
+ factory_test.XXX_log('exiting factory_ExternalStorage')
« no previous file with comments | « client/site_tests/factory_Display/factory_Display.py ('k') | client/site_tests/factory_RebootStub/factory_RebootStub.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698