| 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 import common, fnmatch, logging, os, re, string, threading, time | 5 import common, fnmatch, logging, os, re, string, threading, time |
| 6 | 6 |
| 7 from autotest_lib.server import autotest, hosts, subcommand | 7 from autotest_lib.server import autotest, hosts, subcommand |
| 8 from autotest_lib.server import site_bsd_router | 8 from autotest_lib.server import site_bsd_router |
| 9 from autotest_lib.server import site_linux_router | 9 from autotest_lib.server import site_linux_router |
| 10 from autotest_lib.server import site_host_attributes | 10 from autotest_lib.server import site_host_attributes |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 # Calculate ssid based on test name; this lets us track progress | 179 # Calculate ssid based on test name; this lets us track progress |
| 180 # by watching beacon frames. | 180 # by watching beacon frames. |
| 181 # | 181 # |
| 182 return re.sub('[^a-zA-Z0-9_]', '_', "%s_%s" % (self.name, ipaddr)) | 182 return re.sub('[^a-zA-Z0-9_]', '_', "%s_%s" % (self.name, ipaddr)) |
| 183 | 183 |
| 184 | 184 |
| 185 def run(self): | 185 def run(self): |
| 186 """ | 186 """ |
| 187 Run a WiFi test. Each step is interpreted as a method either | 187 Run a WiFi test. Each step is interpreted as a method either |
| 188 in this class or the ancillary router class and invoked with | 188 in this class or the ancillary router class and invoked with |
| 189 the supplied parameter dictionary. | 189 the supplied parameter dictionary. If the method is prefixed |
| 190 with '!' then we expect the operation to fail; this is useful, |
| 191 for example, for testing parameter checking in flimflam. |
| 190 """ | 192 """ |
| 191 for s in self.steps: | 193 for s in self.steps: |
| 192 method = s[0] | 194 method = s[0] |
| 195 if method[0] == '!': |
| 196 expect_failure = True |
| 197 method = method[1:] |
| 198 else: |
| 199 expect_failure = False |
| 193 if len(s) > 1: | 200 if len(s) > 1: |
| 194 params = s[1] | 201 params = s[1] |
| 195 else: | 202 else: |
| 196 params = {} | 203 params = {} |
| 197 | 204 |
| 198 # What should perf data be prefixed with? | 205 # What should perf data be prefixed with? |
| 199 if 'perf_prefix' in params: | 206 if 'perf_prefix' in params: |
| 200 self.prefix = '%s_%s' % (method, params.pop('perf_prefix')) | 207 self.prefix = '%s_%s' % (method, params.pop('perf_prefix')) |
| 201 elif method in self.iterated_steps: | 208 elif method in self.iterated_steps: |
| 202 self.prefix = '%s_%d' % (method, self.iterated_steps[method]) | 209 self.prefix = '%s_%d' % (method, self.iterated_steps[method]) |
| 203 self.iterated_steps[method] += 1 | 210 self.iterated_steps[method] += 1 |
| 204 else: | 211 else: |
| 205 self.prefix = method | 212 self.prefix = method |
| 206 | 213 |
| 207 logging.info("%s: step '%s' params %s", self.name, method, params) | 214 if expect_failure is True: |
| 215 logging.info("%s: step '%s' (expect failure) params %s", |
| 216 self.name, method, params) |
| 217 else: |
| 218 logging.info("%s: step '%s' params %s", self.name, method, |
| 219 params) |
| 208 | 220 |
| 209 func = getattr(self, method, None) | 221 func = getattr(self, method, None) |
| 210 if func is None: | 222 if func is None: |
| 211 func = getattr(self.wifi, method, None) | 223 func = getattr(self.wifi, method, None) |
| 212 if func is not None: | 224 if func is not None: |
| 213 try: | 225 try: |
| 214 func(params) | 226 func(params) |
| 227 if expect_failure is True: |
| 228 raise error.TestFail("Expected failure") |
| 215 except Exception, e: | 229 except Exception, e: |
| 230 if expect_failure is True: |
| 231 continue |
| 216 logging.error("%s: Step '%s' failed: %s; abort test", | 232 logging.error("%s: Step '%s' failed: %s; abort test", |
| 217 self.name, method, str(e)) | 233 self.name, method, str(e)) |
| 218 self.cleanup(params) | 234 self.cleanup(params) |
| 219 raise e | 235 raise e |
| 220 break | |
| 221 else: | 236 else: |
| 222 logging.error("%s: Step '%s' unknown; abort test", | 237 logging.error("%s: Step '%s' unknown; abort test", |
| 223 self.name, method) | 238 self.name, method) |
| 224 self.cleanup(params) | 239 self.cleanup(params) |
| 225 break | 240 break |
| 226 | 241 |
| 227 # Other cleanup steps might be optional, but this is mandatory | 242 # Other cleanup steps might be optional, but this is mandatory |
| 228 self.client_netdump_stop({}) | 243 self.client_netdump_stop({}) |
| 229 | 244 |
| 230 | 245 |
| (...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 864 except error.TestFail: | 879 except error.TestFail: |
| 865 if 'expect_failure' in testcase: | 880 if 'expect_failure' in testcase: |
| 866 self.expect_failure(name, testcase['expect_failure']) | 881 self.expect_failure(name, testcase['expect_failure']) |
| 867 else: | 882 else: |
| 868 raise | 883 raise |
| 869 except Exception, e: | 884 except Exception, e: |
| 870 if 'expect_failure' in testcase: | 885 if 'expect_failure' in testcase: |
| 871 self.expect_failure(name, testcase['expect_failure']) | 886 self.expect_failure(name, testcase['expect_failure']) |
| 872 else: | 887 else: |
| 873 raise error.TestFail(e) | 888 raise error.TestFail(e) |
| OLD | NEW |