| OLD | NEW | 
|---|
| 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 an example factory test that does not really do anything -- | 
| 9 # it displays a message in the center of the testing area, as | 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 | 10 # communicated by arguments to run_once().  This test makes use of the | 
| 11 # factory_ui_lib library to display its UI, and to monitor keyboard | 11 # factory_ui_lib library to display its UI, and to monitor keyboard | 
| 12 # events for test-switching triggers.  This test can be terminated by | 12 # events for test-switching triggers.  This test can be terminated by | 
| 13 # typing SHIFT-Q. | 13 # typing SHIFT-Q. | 
| 14 | 14 | 
| 15 | 15 | 
| 16 import gtk | 16 import gtk | 
| 17 import pango | 17 import pango | 
| 18 import sys | 18 import sys | 
| 19 | 19 | 
| 20 from gtk import gdk | 20 from gtk import gdk | 
|  | 21 from itertools import count, izip, product | 
| 21 | 22 | 
| 22 from autotest_lib.client.bin import factory | 23 from autotest_lib.client.bin import factory | 
| 23 from autotest_lib.client.bin import factory_ui_lib as ful | 24 from autotest_lib.client.bin import factory_ui_lib as ful | 
| 24 from autotest_lib.client.bin import test | 25 from autotest_lib.client.bin import test | 
| 25 from autotest_lib.client.common_lib import error | 26 from autotest_lib.client.common_lib import error | 
| 26 | 27 | 
|  | 28 from factory import AutomatedSequence | 
|  | 29 | 
|  | 30 N_ROW = 15 | 
|  | 31 LABEL_EN_SIZE = (170, 35) | 
|  | 32 LABEL_EN_SIZE_2 = (450, 25) | 
|  | 33 LABEL_EN_FONT = pango.FontDescription('courier new extra-condensed 16') | 
|  | 34 TAB_BORDER = 20 | 
|  | 35 | 
|  | 36 def trim(text, length): | 
|  | 37     if len(text) > length: | 
|  | 38         text = text[:length-3] + '...' | 
|  | 39     return text | 
| 27 | 40 | 
| 28 class factory_Review(test.test): | 41 class factory_Review(test.test): | 
| 29     version = 1 | 42     version = 1 | 
| 30 | 43 | 
| 31     def run_once(self, | 44     def make_summary_tab(self, status_map, tests): | 
| 32                  status_file_path=None, | 45         n_test = len(tests) | 
| 33                  test_list=None): | 46         N_COL = n_test / N_ROW + (n_test % N_ROW != 0) | 
|  | 47 | 
|  | 48         info_box = gtk.HBox() | 
|  | 49         info_box.set_spacing(20) | 
|  | 50         for status in (ful.ACTIVE, ful.PASSED, ful.FAILED, ful.UNTESTED): | 
|  | 51             label = ful.make_label(status, | 
|  | 52                                    size=LABEL_EN_SIZE, | 
|  | 53                                    font=LABEL_EN_FONT, | 
|  | 54                                    alignment=(0.5, 0.5), | 
|  | 55                                    fg=ful.LABEL_COLORS[status]) | 
|  | 56             info_box.pack_start(label, False, False) | 
|  | 57 | 
|  | 58         status_table = gtk.Table(N_ROW, N_COL, True) | 
|  | 59         for (j, i), (t, p) in izip(product(xrange(N_COL), xrange(N_ROW)), | 
|  | 60                                    tests): | 
|  | 61             msg_en = t.label_en | 
|  | 62             if p is not None: | 
|  | 63                 msg_en = '  ' + msg_en | 
|  | 64             msg_en = trim(msg_en, 12) | 
|  | 65             if t.label_zw: | 
|  | 66                 msg = '{0:<12} ({1})'.format(msg_en, t.label_zw) | 
|  | 67             else: | 
|  | 68                 msg = msg_en | 
|  | 69             status = status_map.lookup_status(t) | 
|  | 70             status_label = ful.make_label(msg, | 
|  | 71                                           size=LABEL_EN_SIZE_2, | 
|  | 72                                           font=LABEL_EN_FONT, | 
|  | 73                                           alignment=(0.0, 0.5), | 
|  | 74                                           fg=ful.LABEL_COLORS[status]) | 
|  | 75             status_table.attach(status_label, j, j+1, i, i+1) | 
|  | 76 | 
|  | 77         vbox = gtk.VBox() | 
|  | 78         vbox.set_spacing(20) | 
|  | 79         vbox.pack_start(info_box, False, False) | 
|  | 80         vbox.pack_start(status_table, False, False) | 
|  | 81         return vbox | 
|  | 82 | 
|  | 83     def make_error_tab(self, status_map, t): | 
|  | 84         msg = '%s (%s)\n%s' % (t.label_en, t.label_zw, | 
|  | 85                                status_map.lookup_error_msg(t)) | 
|  | 86         label = ful.make_label(msg, | 
|  | 87                                font=LABEL_EN_FONT, | 
|  | 88                                alignment=(0.0, 0.0)) | 
|  | 89         label.set_line_wrap(True) | 
|  | 90         frame = gtk.Frame() | 
|  | 91         frame.add(label) | 
|  | 92         return frame | 
|  | 93 | 
|  | 94     def key_release_callback(self, widget, event): | 
|  | 95         factory.log('key_release_callback %s(%s)' % | 
|  | 96                     (event.keyval, gdk.keyval_name(event.keyval))) | 
|  | 97         if event.keyval == ord('k'): | 
|  | 98             self.notebook.prev_page() | 
|  | 99         elif event.keyval == ord('j'): | 
|  | 100             self.notebook.next_page() | 
|  | 101         return True | 
|  | 102 | 
|  | 103     def register_callback(self, window): | 
|  | 104         window.connect('key-release-event', self.key_release_callback) | 
|  | 105         window.add_events(gdk.KEY_RELEASE_MASK) | 
|  | 106 | 
|  | 107     def run_once(self, status_file_path=None, test_list=None): | 
| 34 | 108 | 
| 35         factory.log('%s run_once' % self.__class__) | 109         factory.log('%s run_once' % self.__class__) | 
| 36 | 110 | 
| 37         status_map = factory.StatusMap(test_list, status_file_path) | 111         status_map = factory.StatusMap(test_list, status_file_path) | 
| 38         untested = status_map.filter(ful.UNTESTED) | 112         tests = sum(([(t, None)] + | 
| 39         passed = status_map.filter(ful.PASSED) | 113                      list(product(getattr(t, 'subtest_list', []), [t])) | 
| 40         failed = status_map.filter(ful.FAILED) | 114                      for t in test_list), []) | 
| 41 | 115 | 
| 42         top_label = ful.make_label('UNTESTED=%d\t' % len(untested) + | 116         self.notebook = gtk.Notebook() | 
| 43                                'PASSED=%d\t' % len(passed) + | 117         self.notebook.modify_bg(gtk.STATE_NORMAL, ful.BLACK) | 
| 44                                'FAILED=%d' % len(failed)) |  | 
| 45 | 118 | 
| 46         # decompose automated sequence tests | 119         tab = self.make_summary_tab(status_map, tests) | 
| 47         failure_report_list =[] | 120         tab.set_border_width(TAB_BORDER) | 
| 48         for t in failed: | 121         self.notebook.append_page(tab, ful.make_label('Summary')) | 
| 49             t_name = t.label_en | 122 | 
| 50             if not isinstance(t, factory.AutomatedSequence): | 123         ts = (t for t, _ in tests | 
| 51                 # Simple Test | 124                 if not isinstance(t, AutomatedSequence) and \ | 
| 52                 err_msg = status_map.lookup_error_msg(t) | 125                    status_map.lookup_status(t) == ful.FAILED) | 
| 53                 failure_report_list.append('%s: %s' % (t_name, err_msg)) | 126         for i, t in izip(count(1), ts): | 
| 54                 continue | 127             if not isinstance(t, AutomatedSequence) and \ | 
| 55             # Complex Test | 128                status_map.lookup_status(t) == ful.FAILED: | 
| 56             for subtest in t.subtest_list: | 129                 tab = self.make_error_tab(status_map, t) | 
| 57                 if status_map.lookup_status(subtest) != ful.FAILED: | 130                 tab.set_border_width(TAB_BORDER) | 
| 58                     continue | 131                 self.notebook.append_page(tab, ful.make_label('#%02d' % i)) | 
| 59                 err_msg = status_map.lookup_error_msg(subtest) | 132 | 
| 60                 failure_report_list.append( | 133         control_label = ful.make_label('Press j/k to change tabs', | 
| 61                         '%s: (%s) %s' % (t_name, subtest.label_en, err_msg)) | 134                                        font=LABEL_EN_FONT, | 
| 62         failure_report = ful.make_label('\n'.join(failure_report_list)) | 135                                        alignment=(0.5, 0.5)) | 
| 63 | 136 | 
| 64         vbox = gtk.VBox() | 137         vbox = gtk.VBox() | 
| 65         vbox.set_spacing(20) | 138         vbox.set_spacing(20) | 
| 66         vbox.pack_start(top_label, False, False) | 139         vbox.pack_start(control_label, False, False) | 
| 67         vbox.pack_start(failure_report, False, False) | 140         vbox.pack_start(self.notebook, False, False) | 
| 68 | 141 | 
| 69         test_widget = gtk.EventBox() | 142         test_widget = gtk.EventBox() | 
| 70         test_widget.modify_bg(gtk.STATE_NORMAL, ful.BLACK) | 143         test_widget.modify_bg(gtk.STATE_NORMAL, ful.BLACK) | 
| 71         test_widget.add(vbox) | 144         test_widget.add(vbox) | 
| 72 | 145 | 
| 73         ful.run_test_widget(self.job, test_widget) | 146         ful.run_test_widget(self.job, test_widget, | 
|  | 147                             window_registration_callback=self.register_callback) | 
| 74 | 148 | 
| 75         factory.log('%s run_once finished' % self.__class__) | 149         factory.log('%s run_once finished' % self.__class__) | 
| OLD | NEW | 
|---|