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

Side by Side Diff: client/site_tests/factory_ScriptWrapper/factory_ScriptWrapper.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 factory test allows execution of a test-based script, with the 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 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. 10 # label. Keyboard input will be passed to the script via its stdin.
11 11
12 from autotest_lib.client.bin import test 12 import imp
13 from autotest_lib.client.common_lib import error
14 from autotest_lib.client.common_lib import factory_test
15
16 import gobject 13 import gobject
17 import gtk 14 import gtk
18 import pango 15 import pango
19 import sys 16 import sys
20 import subprocess 17 import subprocess
21 18
19 from gtk import gdk
20
21 from autotest_lib.client.bin import factory
22 from autotest_lib.client.bin import factory_ui_lib as ful
23 from autotest_lib.client.bin import test
24 from autotest_lib.client.common_lib import error
25 from autotest_lib.client.common_lib import pexpect
26
27
28 _MAX_LABEL_CHARS=256
29
22 30
23 class Script: 31 class Script:
24 32
25 def __init__(self, cmdline, label): 33 def __init__(self, cmdline, pexpect, label):
26 self._cmdline 34 self._cmdline = cmdline
27 self._label = label 35 self._label = label
28 self._proc = subprocess.Popen(cmdline.split(), 36 self._ibuf = ''
29 stdin=subprocess.PIPE, 37 self._proc = pexpect.spawn(cmdline)
30 stdout=subprocess.PIPE) 38 gobject.io_add_watch(self._proc.fileno(), gobject.IO_IN, self.recv)
31 gobject.io_add_watch(self._proc.stdout, gobject.IO_IN, self.recv)
32 39
33 def recv(self, src, cond): 40 def recv(self, src, cond):
34 msg = self._proc.stdout.read() 41 msg = self._proc.read_nonblocking(_MAX_LABEL_CHARS)
42 factory.log('recv script msg %s' % repr(msg))
35 self._label.set_text(msg) 43 self._label.set_text(msg)
36 self._label.queue_draw() 44 self._label.queue_draw()
37 returncode = self._proc.poll() 45 if not self._proc.isalive():
38 if returncode is not None: 46 self._proc.close()
39 gtk.main_quit() 47 gtk.main_quit()
40 if returncode is not 0: 48 if self._proc.exitstatus is not 0:
41 error.TestFail('%s script returned %d' % 49 error.TestFail('%s script return code was %d' %
42 (self._cmdline, returncode)) 50 (self._cmdline, self._proc.exitstatus))
43 return True 51 return True
44 52
45 def send(self, msg): 53 def send(self, char):
46 print >> self._proc.stdin, msg 54 if char != '\n':
47 self._proc.stdin.flush() 55 self._ibuf += char
48
49 def quit(self):
50 if self._proc.poll() is None:
51 return 56 return
52 factory_test.XXX('killing Script') 57 factory.log('sending script %s' % repr(self._ibuf))
53 self._proc.kill() 58 self._proc.sendline(self._ibuf)
59 self._ibuf = ''
54 60
55 61
56 class factory_ScriptWrapper(test.test): 62 class factory_ScriptWrapper(test.test):
57 version = 1 63 version = 1
58 64
59 def key_release_callback(self, widget, event): 65 def key_release_callback(self, widget, event):
60 char = event.keyval in range(32,127) and chr(event.keyval) or None 66 char = event.keyval in range(32,127) and chr(event.keyval) or None
61 factory_test.XXX_log('key_release_callback %s(%s)' % 67 char = event.keyval == gdk.keyval_from_name('Return') and '\n' or char
62 (event.keyval, char)) 68 if not self._ft_state.exit_on_trigger(event) and char is not None:
63 if not factory_test.test_switch_on_trigger(event):
64 self._script.send(char) 69 self._script.send(char)
65 return True 70 return True
66 71
67 def register_callbacks(self, window): 72 def register_callbacks(self, window):
68 window.connect('key-release-event', self.key_release_callback) 73 window.connect('key-release-event', self.key_release_callback)
69 window.add_events(gtk.gdk.KEY_RELEASE_MASK) 74 window.add_events(gtk.gdk.KEY_RELEASE_MASK)
70 75
71 def run_once(self, test_widget_size=None, trigger_set=None, 76 def run_once(self,
72 result_file_path=None, cmdline=None): 77 test_widget_size=None,
78 trigger_set=None,
79 result_file_path=None,
80 cmdline=None):
73 81
74 factory_test.XXX_log('factory_ScriptWrapper') 82 factory.log('%s run_once' % self.__class__)
75 83
76 factory_test.init(trigger_set=trigger_set, 84 self._ft_state = ful.State(
77 result_file_path=result_file_path) 85 trigger_set=trigger_set,
86 result_file_path=result_file_path)
78 87
79 label = gtk.Label('') 88 label = gtk.Label('')
80 label.modify_font(pango.FontDescription('courier new condensed 16')) 89 label.modify_font(pango.FontDescription('courier new condensed 16'))
81 label.set_alignment(0.5, 0.5) 90 label.set_alignment(0.5, 0.5)
82 label.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse('light green')) 91 label.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse('light green'))
83 92
84 test_widget = gtk.EventBox() 93 test_widget = gtk.EventBox()
85 test_widget.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse('black')) 94 test_widget.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse('black'))
86 test_widget.add(label) 95 test_widget.add(label)
87 96
88 self._script = Script(cmdline, label) 97 self._script = Script(cmdline, pexpect, label)
89 98
90 factory_test.run_test_widget( 99 self._ft_state.run_test_widget(
91 test_widget=test_widget, 100 test_widget=test_widget,
92 test_widget_size=test_widget_size, 101 test_widget_size=test_widget_size,
93 window_registration_callback=self.register_callbacks, 102 window_registration_callback=self.register_callbacks)
94 cleanup_callback=self._script.quit)
95 103
96 factory_test.XXX_log('exiting factory_ScriptWrapper') 104 factory.log('%s run_once finished' % self.__class__)
OLDNEW
« no previous file with comments | « client/site_tests/factory_ScriptWrapper/dummy.sh ('k') | client/site_tests/factory_Touchpad/factory_Touchpad.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698