OLD | NEW |
(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 factory test allows execution of a test-based script, with the |
| 9 # stdout of the script displayed in a the testing widget via gtk |
| 10 # label. Keyboard input will be passed to the script via its stdin. |
| 11 |
| 12 from autotest_lib.client.bin import test |
| 13 from autotest_lib.client.common_lib import error |
| 14 from autotest_lib.client.common_lib import factory_test |
| 15 |
| 16 import gobject |
| 17 import gtk |
| 18 import pango |
| 19 import sys |
| 20 import subprocess |
| 21 |
| 22 |
| 23 class Script: |
| 24 |
| 25 def __init__(self, cmdline, label): |
| 26 self._cmdline |
| 27 self._label = label |
| 28 self._proc = subprocess.Popen(cmdline.split(), |
| 29 stdin=subprocess.PIPE, |
| 30 stdout=subprocess.PIPE) |
| 31 gobject.io_add_watch(self._proc.stdout, gobject.IO_IN, self.recv) |
| 32 |
| 33 def recv(self, src, cond): |
| 34 msg = self._proc.stdout.read() |
| 35 self._label.set_text(msg) |
| 36 self._label.queue_draw() |
| 37 returncode = self._proc.poll() |
| 38 if returncode is not None: |
| 39 gtk.main_quit() |
| 40 if returncode is not 0: |
| 41 error.TestFail('%s script returned %d' % |
| 42 (self._cmdline, returncode)) |
| 43 return True |
| 44 |
| 45 def send(self, msg): |
| 46 print >> self._proc.stdin, msg |
| 47 self._proc.stdin.flush() |
| 48 |
| 49 def quit(self): |
| 50 if self._proc.poll() is None: |
| 51 return |
| 52 factory_test.XXX('killing Script') |
| 53 self._proc.kill() |
| 54 |
| 55 |
| 56 class factory_ScriptWrapper(test.test): |
| 57 version = 1 |
| 58 |
| 59 def key_release_callback(self, widget, event): |
| 60 char = event.keyval in range(32,127) and chr(event.keyval) or None |
| 61 factory_test.XXX_log('key_release_callback %s(%s)' % |
| 62 (event.keyval, char)) |
| 63 if not factory_test.test_switch_on_trigger(event): |
| 64 self._script.send(char) |
| 65 return True |
| 66 |
| 67 def register_callbacks(self, window): |
| 68 window.connect('key-release-event', self.key_release_callback) |
| 69 window.add_events(gtk.gdk.KEY_RELEASE_MASK) |
| 70 |
| 71 def run_once(self, test_widget_size=None, trigger_set=None, |
| 72 result_file_path=None, cmdline=None): |
| 73 |
| 74 factory_test.XXX_log('factory_ScriptWrapper') |
| 75 |
| 76 factory_test.init(trigger_set=trigger_set, |
| 77 result_file_path=result_file_path) |
| 78 |
| 79 label = gtk.Label('') |
| 80 label.modify_font(pango.FontDescription('courier new condensed 16')) |
| 81 label.set_alignment(0.5, 0.5) |
| 82 label.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse('light green')) |
| 83 |
| 84 test_widget = gtk.EventBox() |
| 85 test_widget.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse('black')) |
| 86 test_widget.add(label) |
| 87 |
| 88 self._script = Script(cmdline, label) |
| 89 |
| 90 factory_test.run_test_widget( |
| 91 test_widget=test_widget, |
| 92 test_widget_size=test_widget_size, |
| 93 window_registration_callback=self.register_callbacks, |
| 94 cleanup_callback=self._script.quit) |
| 95 |
| 96 factory_test.XXX_log('exiting factory_ScriptWrapper') |
OLD | NEW |