Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | """ |
| 3 | @package oft |
| 4 | |
| 5 | OpenFlow test framework top level script |
| 6 | |
Rich Lane | ea5060d | 2013-01-06 13:59:00 -0800 | [diff] [blame] | 7 | This script is the entry point for running OpenFlow tests using the OFT |
| 8 | framework. For usage information, see --help or the README. |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 9 | |
Rich Lane | ea5060d | 2013-01-06 13:59:00 -0800 | [diff] [blame] | 10 | To add a new command line option, edit both the config_default dictionary and |
| 11 | the config_setup function. The option's result will end up in the global |
| 12 | oftest.config dictionary. |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 13 | """ |
| 14 | |
| 15 | import sys |
Rich Lane | 95f078b | 2013-01-06 13:24:58 -0800 | [diff] [blame] | 16 | import optparse |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 17 | from subprocess import Popen,PIPE |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 18 | import logging |
| 19 | import unittest |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 20 | import time |
Brandon Heller | 446c143 | 2010-04-01 12:43:27 -0700 | [diff] [blame] | 21 | import os |
Rich Lane | 6b452bc | 2012-07-09 16:52:21 -0700 | [diff] [blame] | 22 | import imp |
Rich Lane | 8592bec | 2012-09-03 09:06:59 -0700 | [diff] [blame] | 23 | import random |
Rich Lane | 5bd6cf9 | 2012-10-04 17:57:24 -0700 | [diff] [blame] | 24 | import signal |
Rich Lane | 943be67 | 2012-10-04 19:20:16 -0700 | [diff] [blame] | 25 | import fnmatch |
Rich Lane | 2d6d482 | 2013-01-08 10:49:16 -0800 | [diff] [blame] | 26 | import copy |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 27 | |
Rich Lane | fadf345 | 2012-10-03 16:23:37 -0700 | [diff] [blame] | 28 | root_dir = os.path.dirname(os.path.realpath(__file__)) |
| 29 | |
| 30 | pydir = os.path.join(root_dir, 'src', 'python') |
Rich Lane | 3987804 | 2012-07-09 14:45:35 -0700 | [diff] [blame] | 31 | if os.path.exists(os.path.join(pydir, 'oftest')): |
| 32 | # Running from source tree |
| 33 | sys.path.insert(0, pydir) |
| 34 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 35 | import oftest |
| 36 | from oftest import config |
Rich Lane | e55abf7 | 2012-07-26 20:11:42 -0700 | [diff] [blame] | 37 | import oftest.ofutils |
Rich Lane | 95f078b | 2013-01-06 13:24:58 -0800 | [diff] [blame] | 38 | import oftest.help_formatter |
Rich Lane | 3f7098c | 2013-03-12 10:28:32 -0700 | [diff] [blame] | 39 | import loxi |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 40 | |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 41 | ##@var DEBUG_LEVELS |
| 42 | # Map from strings to debugging levels |
| 43 | DEBUG_LEVELS = { |
| 44 | 'debug' : logging.DEBUG, |
| 45 | 'verbose' : logging.DEBUG, |
| 46 | 'info' : logging.INFO, |
| 47 | 'warning' : logging.WARNING, |
| 48 | 'warn' : logging.WARNING, |
| 49 | 'error' : logging.ERROR, |
| 50 | 'critical' : logging.CRITICAL |
| 51 | } |
| 52 | |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 53 | ##@var config_default |
| 54 | # The default configuration dictionary for OFT |
| 55 | config_default = { |
Rich Lane | 95f078b | 2013-01-06 13:24:58 -0800 | [diff] [blame] | 56 | # Miscellaneous options |
| 57 | "list" : False, |
| 58 | "list_test_names" : False, |
| 59 | "allow_user" : False, |
| 60 | |
| 61 | # Test selection options |
Rich Lane | c76b09a | 2013-01-02 16:53:22 -0800 | [diff] [blame] | 62 | "test_spec" : "", |
Rich Lane | 1a08d23 | 2013-01-04 16:03:50 -0800 | [diff] [blame] | 63 | "test_file" : None, |
Rich Lane | 74b13d1 | 2013-05-03 17:58:50 -0700 | [diff] [blame] | 64 | "test_dir" : None, |
Rich Lane | 95f078b | 2013-01-06 13:24:58 -0800 | [diff] [blame] | 65 | |
| 66 | # Switch connection options |
| 67 | "controller_host" : "0.0.0.0", # For passive bind |
Rich Lane | 4d1f3eb | 2013-10-03 13:45:57 -0700 | [diff] [blame] | 68 | "controller_port" : 6653, |
Rich Lane | 95f078b | 2013-01-06 13:24:58 -0800 | [diff] [blame] | 69 | "switch_ip" : None, # If not none, actively connect to switch |
Rich Lane | 15f2632 | 2013-01-08 11:23:24 -0800 | [diff] [blame] | 70 | "platform" : "eth", |
Rich Lane | 95f078b | 2013-01-06 13:24:58 -0800 | [diff] [blame] | 71 | "platform_args" : None, |
| 72 | "platform_dir" : os.path.join(root_dir, "platforms"), |
Rich Lane | 2d6d482 | 2013-01-08 10:49:16 -0800 | [diff] [blame] | 73 | "interfaces" : [], |
Rich Lane | 9fd0568 | 2013-01-10 15:30:38 -0800 | [diff] [blame] | 74 | "openflow_version" : "1.0", |
Rich Lane | 95f078b | 2013-01-06 13:24:58 -0800 | [diff] [blame] | 75 | |
| 76 | # Logging options |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 77 | "log_file" : "oft.log", |
Rich Lane | 69fd8e0 | 2013-08-23 16:23:42 -0700 | [diff] [blame] | 78 | "log_dir" : None, |
Rich Lane | 95f078b | 2013-01-06 13:24:58 -0800 | [diff] [blame] | 79 | "debug" : "verbose", |
Rich Lane | 9631f00 | 2014-03-21 18:05:16 -0700 | [diff] [blame] | 80 | "profile" : False, |
Stephen Finucane | 6219af7 | 2014-05-14 21:08:30 +0100 | [diff] [blame] | 81 | "profile_file" : "profile.out", |
Stephen Finucane | e016cf2 | 2014-04-16 22:04:11 +0100 | [diff] [blame] | 82 | "xunit" : False, |
| 83 | "xunit_dir" : "xunit", |
Rich Lane | 95f078b | 2013-01-06 13:24:58 -0800 | [diff] [blame] | 84 | |
| 85 | # Test behavior options |
| 86 | "relax" : False, |
Dan Talayco | d7c80d1 | 2012-04-03 15:20:57 -0700 | [diff] [blame] | 87 | "test_params" : "None", |
Rich Lane | 9a84a4f | 2012-07-17 12:27:42 -0700 | [diff] [blame] | 88 | "fail_skipped" : False, |
Rich Lane | 48f6aed | 2014-03-23 15:51:02 -0700 | [diff] [blame] | 89 | "default_timeout" : 2.0, |
| 90 | "default_negative_timeout" : 0.01, |
Jeffrey Townsend | 5cb7ed3 | 2012-08-17 18:11:01 +0000 | [diff] [blame] | 91 | "minsize" : 0, |
Rich Lane | 8592bec | 2012-09-03 09:06:59 -0700 | [diff] [blame] | 92 | "random_seed" : None, |
Stephen Finucane | 92f7cf6 | 2014-03-13 15:08:11 +0000 | [diff] [blame] | 93 | "disable_ipv6" : False, |
Rich Lane | 95f078b | 2013-01-06 13:24:58 -0800 | [diff] [blame] | 94 | |
| 95 | # Other configuration |
Rich Lane | 15f2632 | 2013-01-08 11:23:24 -0800 | [diff] [blame] | 96 | "port_map" : {}, |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 97 | } |
| 98 | |
Rich Lane | 95f078b | 2013-01-06 13:24:58 -0800 | [diff] [blame] | 99 | def config_setup(): |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 100 | """ |
| 101 | Set up the configuration including parsing the arguments |
| 102 | |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 103 | @return A pair (config, args) where config is an config |
| 104 | object and args is any additional arguments from the command line |
| 105 | """ |
| 106 | |
Rich Lane | 4113a58 | 2013-01-03 10:13:02 -0800 | [diff] [blame] | 107 | usage = "usage: %prog [options] (test|group)..." |
| 108 | |
Rich Lane | 95f078b | 2013-01-06 13:24:58 -0800 | [diff] [blame] | 109 | description = """\ |
Rich Lane | 4113a58 | 2013-01-03 10:13:02 -0800 | [diff] [blame] | 110 | OFTest is a framework and set of tests for validating OpenFlow switches. |
| 111 | |
| 112 | The default configuration assumes that an OpenFlow 1.0 switch is attempting to |
Rich Lane | 4d1f3eb | 2013-10-03 13:45:57 -0700 | [diff] [blame] | 113 | connect to a controller on the machine running OFTest, port 6653. Additionally, |
Rich Lane | 4113a58 | 2013-01-03 10:13:02 -0800 | [diff] [blame] | 114 | the interfaces veth1, veth3, veth5, and veth7 should be connected to the switch's |
| 115 | dataplane. |
| 116 | |
| 117 | If no positional arguments are given then OFTest will run all tests that |
| 118 | depend only on standard OpenFlow 1.0. Otherwise each positional argument |
| 119 | is interpreted as either a test name or a test group name. The union of |
| 120 | these will be executed. To see what groups each test belongs to use the |
Rich Lane | 948f030 | 2013-01-07 10:59:08 -0800 | [diff] [blame] | 121 | --list option. Tests and groups can be subtracted from the result by |
| 122 | prefixing them with the '^' character. |
Rich Lane | 4113a58 | 2013-01-03 10:13:02 -0800 | [diff] [blame] | 123 | """ |
| 124 | |
Rich Lane | 2d6d482 | 2013-01-08 10:49:16 -0800 | [diff] [blame] | 125 | # Parse --interface |
| 126 | def check_interface(option, opt, value): |
| 127 | try: |
| 128 | ofport, interface = value.split('@', 1) |
| 129 | ofport = int(ofport) |
| 130 | except ValueError: |
| 131 | raise optparse.OptionValueError("incorrect interface syntax (got %s, expected 'ofport@interface')" % repr(value)) |
| 132 | return (ofport, interface) |
| 133 | |
| 134 | class Option(optparse.Option): |
| 135 | TYPES = optparse.Option.TYPES + ("interface",) |
| 136 | TYPE_CHECKER = copy.copy(optparse.Option.TYPE_CHECKER) |
| 137 | TYPE_CHECKER["interface"] = check_interface |
| 138 | |
Rich Lane | 95f078b | 2013-01-06 13:24:58 -0800 | [diff] [blame] | 139 | parser = optparse.OptionParser(version="%prog 0.1", |
| 140 | usage=usage, |
| 141 | description=description, |
Rich Lane | 2d6d482 | 2013-01-08 10:49:16 -0800 | [diff] [blame] | 142 | formatter=oftest.help_formatter.HelpFormatter(), |
| 143 | option_class=Option) |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 144 | |
| 145 | # Set up default values |
Rich Lane | 95f078b | 2013-01-06 13:24:58 -0800 | [diff] [blame] | 146 | parser.set_defaults(**config_default) |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 147 | |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 148 | parser.add_option("--list", action="store_true", |
Brandon Heller | 824504e | 2010-04-01 12:21:37 -0700 | [diff] [blame] | 149 | help="List all tests and exit") |
Rich Lane | 95f078b | 2013-01-06 13:24:58 -0800 | [diff] [blame] | 150 | parser.add_option("--list-test-names", action='store_true', |
| 151 | help="List test names matching the test spec and exit") |
Rich Lane | ee57ad0 | 2012-07-13 15:40:36 -0700 | [diff] [blame] | 152 | parser.add_option("--allow-user", action="store_true", |
| 153 | help="Proceed even if oftest is not run as root") |
Rich Lane | 95f078b | 2013-01-06 13:24:58 -0800 | [diff] [blame] | 154 | |
| 155 | group = optparse.OptionGroup(parser, "Test selection options") |
| 156 | group.add_option("-T", "--test-spec", "--test-list", help="Tests to run, separated by commas") |
| 157 | group.add_option("-f", "--test-file", help="File of tests to run, one per line") |
| 158 | group.add_option("--test-dir", type="string", help="Directory containing tests") |
| 159 | parser.add_option_group(group) |
| 160 | |
| 161 | group = optparse.OptionGroup(parser, "Switch connection options") |
| 162 | group.add_option("-H", "--host", dest="controller_host", |
| 163 | help="IP address to listen on (default %default)") |
| 164 | group.add_option("-p", "--port", dest="controller_port", |
| 165 | type="int", help="Port number to listen on (default %default)") |
| 166 | group.add_option("-S", "--switch-ip", dest="switch_ip", |
| 167 | help="If set, actively connect to this switch by IP") |
| 168 | group.add_option("-P", "--platform", help="Platform module name (default %default)") |
| 169 | group.add_option("-a", "--platform-args", help="Custom arguments for the platform") |
| 170 | group.add_option("--platform-dir", type="string", help="Directory containing platform modules") |
Rich Lane | 2d6d482 | 2013-01-08 10:49:16 -0800 | [diff] [blame] | 171 | group.add_option("--interface", "-i", type="interface", dest="interfaces", metavar="INTERFACE", action="append", |
| 172 | help="Specify a OpenFlow port number and the dataplane interface to use. May be given multiple times. Example: 1@eth1") |
Rich Lane | 50cfa50 | 2013-04-25 13:45:08 -0700 | [diff] [blame] | 173 | group.add_option("--of-version", "-V", dest="openflow_version", choices=loxi.version_names.values(), |
Rich Lane | 9fd0568 | 2013-01-10 15:30:38 -0800 | [diff] [blame] | 174 | help="OpenFlow version to use") |
Rich Lane | 95f078b | 2013-01-06 13:24:58 -0800 | [diff] [blame] | 175 | parser.add_option_group(group) |
| 176 | |
| 177 | group = optparse.OptionGroup(parser, "Logging options") |
Rich Lane | 69fd8e0 | 2013-08-23 16:23:42 -0700 | [diff] [blame] | 178 | group.add_option("--log-file", help="Name of log file (default %default)") |
| 179 | group.add_option("--log-dir", help="Name of log directory") |
Rich Lane | 95f078b | 2013-01-06 13:24:58 -0800 | [diff] [blame] | 180 | dbg_lvl_names = sorted(DEBUG_LEVELS.keys(), key=lambda x: DEBUG_LEVELS[x]) |
| 181 | group.add_option("--debug", choices=dbg_lvl_names, |
| 182 | help="Debug lvl: debug, info, warning, error, critical (default %default)") |
| 183 | group.add_option("-v", "--verbose", action="store_const", dest="debug", |
| 184 | const="verbose", help="Shortcut for --debug=verbose") |
| 185 | group.add_option("-q", "--quiet", action="store_const", dest="debug", |
| 186 | const="warning", help="Shortcut for --debug=warning") |
Stephen Finucane | 6219af7 | 2014-05-14 21:08:30 +0100 | [diff] [blame] | 187 | group.add_option("--profile", action="store_true", help="Enable Python profiling") |
| 188 | group.add_option("--profile-file", help="Output file for Python profiler") |
Stephen Finucane | e016cf2 | 2014-04-16 22:04:11 +0100 | [diff] [blame] | 189 | group.add_option("--xunit", action="store_true", help="Enable xUnit-formatted results") |
| 190 | group.add_option("--xunit-dir", help="Output directory for xUnit-formatted results") |
Rich Lane | 95f078b | 2013-01-06 13:24:58 -0800 | [diff] [blame] | 191 | parser.add_option_group(group) |
| 192 | |
| 193 | group = optparse.OptionGroup(parser, "Test behavior options") |
| 194 | group.add_option("--relax", action="store_true", |
| 195 | help="Relax packet match checks allowing other packets") |
| 196 | test_params_help = """Set test parameters: key=val;... (see --list) |
| 197 | """ |
| 198 | group.add_option("-t", "--test-params", help=test_params_help) |
| 199 | group.add_option("--fail-skipped", action="store_true", |
Rich Lane | 9a84a4f | 2012-07-17 12:27:42 -0700 | [diff] [blame] | 200 | help="Return failure if any test was skipped") |
Rich Lane | 48f6aed | 2014-03-23 15:51:02 -0700 | [diff] [blame] | 201 | group.add_option("--default-timeout", type=float, |
Rich Lane | e55abf7 | 2012-07-26 20:11:42 -0700 | [diff] [blame] | 202 | help="Timeout in seconds for most operations") |
Rich Lane | 48f6aed | 2014-03-23 15:51:02 -0700 | [diff] [blame] | 203 | group.add_option("--default-negative-timeout", type=float, |
| 204 | help="Timeout in seconds for negative checks") |
Rich Lane | 95f078b | 2013-01-06 13:24:58 -0800 | [diff] [blame] | 205 | group.add_option("--minsize", type="int", |
| 206 | help="Minimum allowable packet size on the dataplane.") |
| 207 | group.add_option("--random-seed", type="int", |
| 208 | help="Random number generator seed") |
Stephen Finucane | 92f7cf6 | 2014-03-13 15:08:11 +0000 | [diff] [blame] | 209 | group.add_option("--disable-ipv6", action="store_true", |
| 210 | help="Disable IPv6 tests") |
Rich Lane | 95f078b | 2013-01-06 13:24:58 -0800 | [diff] [blame] | 211 | parser.add_option_group(group) |
Jeffrey Townsend | 5cb7ed3 | 2012-08-17 18:11:01 +0000 | [diff] [blame] | 212 | |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 213 | # Might need this if other parsers want command line |
| 214 | # parser.allow_interspersed_args = False |
| 215 | (options, args) = parser.parse_args() |
| 216 | |
Rich Lane | 74b13d1 | 2013-05-03 17:58:50 -0700 | [diff] [blame] | 217 | # If --test-dir wasn't given, pick one based on the OpenFlow version |
| 218 | if options.test_dir == None: |
| 219 | if options.openflow_version == "1.0": |
| 220 | options.test_dir = os.path.join(root_dir, "tests") |
| 221 | else: |
| 222 | options.test_dir = os.path.join(root_dir, "tests-" + options.openflow_version) |
| 223 | |
Rich Lane | 95f078b | 2013-01-06 13:24:58 -0800 | [diff] [blame] | 224 | # Convert options from a Namespace to a plain dictionary |
| 225 | config = config_default.copy() |
| 226 | for key in config.keys(): |
| 227 | config[key] = getattr(options, key) |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 228 | |
| 229 | return (config, args) |
| 230 | |
| 231 | def logging_setup(config): |
| 232 | """ |
| 233 | Set up logging based on config |
| 234 | """ |
Rich Lane | 69fd8e0 | 2013-08-23 16:23:42 -0700 | [diff] [blame] | 235 | |
| 236 | logging.getLogger().setLevel(DEBUG_LEVELS[config["debug"]]) |
| 237 | |
| 238 | if config["log_dir"] != None: |
| 239 | if os.path.exists(config["log_dir"]): |
| 240 | import shutil |
| 241 | shutil.rmtree(config["log_dir"]) |
| 242 | os.makedirs(config["log_dir"]) |
| 243 | else: |
| 244 | if os.path.exists(config["log_file"]): |
| 245 | os.remove(config["log_file"]) |
| 246 | |
| 247 | oftest.open_logfile('main') |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 248 | |
Stephen Finucane | e016cf2 | 2014-04-16 22:04:11 +0100 | [diff] [blame] | 249 | def xunit_setup(config): |
| 250 | """ |
| 251 | Set up xUnit output based on config |
| 252 | """ |
| 253 | |
| 254 | if not config["xunit"]: |
| 255 | return |
| 256 | |
Stephen Finucane | 6219af7 | 2014-05-14 21:08:30 +0100 | [diff] [blame] | 257 | if os.path.exists(config["xunit_dir"]): |
| 258 | import shutil |
| 259 | shutil.rmtree(config["xunit_dir"]) |
| 260 | os.makedirs(config["xunit_dir"]) |
Stephen Finucane | e016cf2 | 2014-04-16 22:04:11 +0100 | [diff] [blame] | 261 | |
Rich Lane | 472aaea | 2013-08-27 09:27:38 -0700 | [diff] [blame] | 262 | def pcap_setup(config): |
| 263 | """ |
| 264 | Set up dataplane packet capturing based on config |
| 265 | """ |
| 266 | |
| 267 | if config["log_dir"] == None: |
| 268 | filename = os.path.splitext(config["log_file"])[0] + '.pcap' |
| 269 | oftest.dataplane_instance.start_pcap(filename) |
| 270 | else: |
| 271 | # start_pcap is called per-test in base_tests |
| 272 | pass |
| 273 | |
Stephen Finucane | 6219af7 | 2014-05-14 21:08:30 +0100 | [diff] [blame] | 274 | def profiler_setup(config): |
| 275 | """ |
| 276 | Set up profiler based on config |
| 277 | """ |
| 278 | |
| 279 | if not config["profile"]: |
| 280 | return |
| 281 | |
| 282 | import cProfile |
| 283 | profiler = cProfile.Profile() |
| 284 | profiler.enable() |
| 285 | |
| 286 | return profiler |
| 287 | |
| 288 | def profiler_teardown(profiler): |
| 289 | """ |
| 290 | Tear down profiler based on config |
| 291 | """ |
| 292 | |
| 293 | if not config["profile"]: |
| 294 | return |
| 295 | |
| 296 | profiler.disable() |
| 297 | profiler.dump_stats(config["profile_file"]) |
| 298 | |
Rich Lane | 472aaea | 2013-08-27 09:27:38 -0700 | [diff] [blame] | 299 | |
Rich Lane | 943be67 | 2012-10-04 19:20:16 -0700 | [diff] [blame] | 300 | def load_test_modules(config): |
| 301 | """ |
| 302 | Load tests from the test_dir directory. |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 303 | |
Rich Lane | 943be67 | 2012-10-04 19:20:16 -0700 | [diff] [blame] | 304 | Test cases are subclasses of unittest.TestCase |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 305 | |
Rich Lane | cc45b8e | 2013-01-02 15:55:02 -0800 | [diff] [blame] | 306 | Also updates the _groups member to include "standard" and |
| 307 | module test groups if appropriate. |
| 308 | |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 309 | @param config The oft configuration dictionary |
Rich Lane | 943be67 | 2012-10-04 19:20:16 -0700 | [diff] [blame] | 310 | @returns A dictionary from test module names to tuples of |
| 311 | (module, dictionary from test names to test classes). |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 312 | """ |
| 313 | |
Rich Lane | 943be67 | 2012-10-04 19:20:16 -0700 | [diff] [blame] | 314 | result = {} |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 315 | |
Rich Lane | 943be67 | 2012-10-04 19:20:16 -0700 | [diff] [blame] | 316 | for root, dirs, filenames in os.walk(config["test_dir"]): |
| 317 | # Iterate over each python file |
| 318 | for filename in fnmatch.filter(filenames, '[!.]*.py'): |
| 319 | modname = os.path.splitext(os.path.basename(filename))[0] |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 320 | |
Rich Lane | 943be67 | 2012-10-04 19:20:16 -0700 | [diff] [blame] | 321 | try: |
| 322 | if sys.modules.has_key(modname): |
| 323 | mod = sys.modules[modname] |
| 324 | else: |
| 325 | mod = imp.load_module(modname, *imp.find_module(modname, [root])) |
| 326 | except: |
| 327 | logging.warning("Could not import file " + filename) |
| 328 | raise |
Rich Lane | 520e415 | 2012-07-09 16:18:16 -0700 | [diff] [blame] | 329 | |
Rich Lane | 943be67 | 2012-10-04 19:20:16 -0700 | [diff] [blame] | 330 | # Find all testcases defined in the module |
| 331 | tests = dict((k, v) for (k, v) in mod.__dict__.items() if type(v) == type and |
Rich Lane | 9cef274 | 2013-07-16 13:27:00 -0700 | [diff] [blame] | 332 | issubclass(v, unittest.TestCase) and |
| 333 | hasattr(v, "runTest")) |
Rich Lane | 943be67 | 2012-10-04 19:20:16 -0700 | [diff] [blame] | 334 | if tests: |
Rich Lane | cc45b8e | 2013-01-02 15:55:02 -0800 | [diff] [blame] | 335 | for (testname, test) in tests.items(): |
| 336 | # Set default annotation values |
| 337 | if not hasattr(test, "_groups"): |
| 338 | test._groups = [] |
| 339 | if not hasattr(test, "_nonstandard"): |
| 340 | test._nonstandard = False |
| 341 | if not hasattr(test, "_disabled"): |
| 342 | test._disabled = False |
| 343 | |
| 344 | # Put test in its module's test group |
| 345 | if not test._disabled: |
| 346 | test._groups.append(modname) |
| 347 | |
| 348 | # Put test in the standard test group |
| 349 | if not test._disabled and not test._nonstandard: |
| 350 | test._groups.append("standard") |
| 351 | test._groups.append("all") # backwards compatibility |
| 352 | |
Rich Lane | 943be67 | 2012-10-04 19:20:16 -0700 | [diff] [blame] | 353 | result[modname] = (mod, tests) |
Rich Lane | 520e415 | 2012-07-09 16:18:16 -0700 | [diff] [blame] | 354 | |
Rich Lane | 943be67 | 2012-10-04 19:20:16 -0700 | [diff] [blame] | 355 | return result |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 356 | |
Rich Lane | 5a9a192 | 2013-01-11 14:29:30 -0800 | [diff] [blame] | 357 | def prune_tests(test_specs, test_modules, version): |
Rich Lane | 15f64de | 2012-10-04 21:25:57 -0700 | [diff] [blame] | 358 | """ |
Rich Lane | 5a9a192 | 2013-01-11 14:29:30 -0800 | [diff] [blame] | 359 | Return tests matching the given test-specs and OpenFlow version |
Rich Lane | c76b09a | 2013-01-02 16:53:22 -0800 | [diff] [blame] | 360 | @param test_specs A list of group names or test names. |
Rich Lane | 5a9a192 | 2013-01-11 14:29:30 -0800 | [diff] [blame] | 361 | @param version An OpenFlow version (e.g. "1.0") |
Rich Lane | 15f64de | 2012-10-04 21:25:57 -0700 | [diff] [blame] | 362 | @param test_modules Same format as the output of load_test_modules. |
| 363 | @returns Same format as the output of load_test_modules. |
| 364 | """ |
| 365 | result = {} |
Rich Lane | c76b09a | 2013-01-02 16:53:22 -0800 | [diff] [blame] | 366 | for e in test_specs: |
Rich Lane | 15f64de | 2012-10-04 21:25:57 -0700 | [diff] [blame] | 367 | matched = False |
Rich Lane | 948f030 | 2013-01-07 10:59:08 -0800 | [diff] [blame] | 368 | |
| 369 | if e.startswith('^'): |
| 370 | negated = True |
| 371 | e = e[1:] |
| 372 | else: |
| 373 | negated = False |
| 374 | |
Rich Lane | 15f64de | 2012-10-04 21:25:57 -0700 | [diff] [blame] | 375 | for (modname, (mod, tests)) in test_modules.items(): |
Rich Lane | cc45b8e | 2013-01-02 15:55:02 -0800 | [diff] [blame] | 376 | for (testname, test) in tests.items(): |
| 377 | if e in test._groups or e == "%s.%s" % (modname, testname): |
| 378 | result.setdefault(modname, (mod, {})) |
Rich Lane | 948f030 | 2013-01-07 10:59:08 -0800 | [diff] [blame] | 379 | if not negated: |
Rich Lane | 5a9a192 | 2013-01-11 14:29:30 -0800 | [diff] [blame] | 380 | if not hasattr(test, "_versions") or version in test._versions: |
| 381 | result[modname][1][testname] = test |
Rich Lane | 948f030 | 2013-01-07 10:59:08 -0800 | [diff] [blame] | 382 | else: |
| 383 | if modname in result and testname in result[modname][1]: |
| 384 | del result[modname][1][testname] |
| 385 | if not result[modname][1]: |
| 386 | del result[modname] |
Rich Lane | cc45b8e | 2013-01-02 15:55:02 -0800 | [diff] [blame] | 387 | matched = True |
Rich Lane | 948f030 | 2013-01-07 10:59:08 -0800 | [diff] [blame] | 388 | |
Rich Lane | 15f64de | 2012-10-04 21:25:57 -0700 | [diff] [blame] | 389 | if not matched: |
Rich Lane | cc45b8e | 2013-01-02 15:55:02 -0800 | [diff] [blame] | 390 | die("test-spec element %s did not match any tests" % e) |
Rich Lane | 948f030 | 2013-01-07 10:59:08 -0800 | [diff] [blame] | 391 | |
Rich Lane | 15f64de | 2012-10-04 21:25:57 -0700 | [diff] [blame] | 392 | return result |
| 393 | |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 394 | def die(msg, exit_val=1): |
| 395 | print msg |
| 396 | logging.critical(msg) |
| 397 | sys.exit(exit_val) |
| 398 | |
Dan Talayco | 79f3608 | 2010-03-11 16:53:53 -0800 | [diff] [blame] | 399 | def _space_to(n, str): |
| 400 | """ |
| 401 | Generate a string of spaces to achieve width n given string str |
| 402 | If length of str >= n, return one space |
| 403 | """ |
| 404 | spaces = n - len(str) |
| 405 | if spaces > 0: |
| 406 | return " " * spaces |
| 407 | return " " |
| 408 | |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 409 | # |
| 410 | # Main script |
| 411 | # |
| 412 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 413 | # Setup global configuration |
Rich Lane | 95f078b | 2013-01-06 13:24:58 -0800 | [diff] [blame] | 414 | (new_config, args) = config_setup() |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 415 | oftest.config.update(new_config) |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 416 | |
Rich Lane | d7a85c4 | 2012-09-28 15:38:45 -0700 | [diff] [blame] | 417 | logging_setup(config) |
Stephen Finucane | e016cf2 | 2014-04-16 22:04:11 +0100 | [diff] [blame] | 418 | xunit_setup(config) |
Rich Lane | d7a85c4 | 2012-09-28 15:38:45 -0700 | [diff] [blame] | 419 | logging.info("++++++++ " + time.asctime() + " ++++++++") |
| 420 | |
Rich Lane | 9fd0568 | 2013-01-10 15:30:38 -0800 | [diff] [blame] | 421 | # Pick an OpenFlow protocol module based on the configured version |
Rich Lane | 50cfa50 | 2013-04-25 13:45:08 -0700 | [diff] [blame] | 422 | name_to_version = dict((v,k) for k, v in loxi.version_names.iteritems()) |
| 423 | sys.modules["ofp"] = loxi.protocol(name_to_version[config["openflow_version"]]) |
Rich Lane | 9fd0568 | 2013-01-10 15:30:38 -0800 | [diff] [blame] | 424 | |
| 425 | # HACK: testutils.py imports controller.py, which needs the ofp module |
| 426 | import oftest.testutils |
| 427 | |
Rich Lane | e284b6b | 2012-10-03 09:19:58 -0700 | [diff] [blame] | 428 | # Allow tests to import each other |
| 429 | sys.path.append(config["test_dir"]) |
| 430 | |
Rich Lane | c76b09a | 2013-01-02 16:53:22 -0800 | [diff] [blame] | 431 | test_specs = args |
| 432 | if config["test_spec"] != "": |
| 433 | print >> sys.stderr, "WARNING: The --test-spec option is deprecated" |
| 434 | test_specs += config["test_spec"].split(',') |
Rich Lane | 1a08d23 | 2013-01-04 16:03:50 -0800 | [diff] [blame] | 435 | if config["test_file"] != None: |
| 436 | with open(config["test_file"], 'r') as f: |
| 437 | for line in f: |
| 438 | line, _, _ = line.partition('#') # remove comments |
| 439 | line = line.strip() |
| 440 | if line: |
| 441 | test_specs.append(line) |
Rich Lane | c76b09a | 2013-01-02 16:53:22 -0800 | [diff] [blame] | 442 | if test_specs == []: |
| 443 | test_specs = ["standard"] |
| 444 | |
Rich Lane | d8e4548 | 2013-01-02 17:36:21 -0800 | [diff] [blame] | 445 | test_modules = load_test_modules(config) |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 446 | |
| 447 | # Check if test list is requested; display and exit if so |
| 448 | if config["list"]: |
Dan Talayco | 7f8dba8 | 2012-04-12 12:58:52 -0700 | [diff] [blame] | 449 | mod_count = 0 |
| 450 | test_count = 0 |
Rich Lane | 37f4211 | 2013-01-03 13:41:49 -0800 | [diff] [blame] | 451 | all_groups = set() |
Rich Lane | e811e7b | 2013-01-03 13:36:54 -0800 | [diff] [blame] | 452 | print """\ |
| 453 | Tests are shown grouped by module. If a test is in any groups beyond "standard" |
| 454 | and its module's group then they are shown in parentheses.""" |
| 455 | print |
| 456 | print """\ |
| 457 | Tests marked with '*' are non-standard and may require vendor extensions or |
| 458 | special switch configuration. These are not part of the "standard" test group.""" |
| 459 | print |
| 460 | print """\ |
| 461 | Tests marked with '!' are disabled because they are experimental, special-purpose, |
| 462 | or are too long to be run normally. These are not part of the "standard" test |
| 463 | group or their module's test group.""" |
| 464 | print |
| 465 | print "Tests marked (TP1) after name take --test-params including:" |
| 466 | print " 'vid=N;strip_vlan=bool;add_vlan=bool'" |
Rich Lane | e811e7b | 2013-01-03 13:36:54 -0800 | [diff] [blame] | 467 | print |
| 468 | print "Test List:" |
Rich Lane | 943be67 | 2012-10-04 19:20:16 -0700 | [diff] [blame] | 469 | for (modname, (mod, tests)) in test_modules.items(): |
Dan Talayco | 7f8dba8 | 2012-04-12 12:58:52 -0700 | [diff] [blame] | 470 | mod_count += 1 |
Rich Lane | 80efd65 | 2013-01-02 14:05:20 -0800 | [diff] [blame] | 471 | desc = (mod.__doc__ or "No description").strip().split('\n')[0] |
Dan Talayco | 79f3608 | 2010-03-11 16:53:53 -0800 | [diff] [blame] | 472 | start_str = " Module " + mod.__name__ + ": " |
| 473 | print start_str + _space_to(22, start_str) + desc |
Rich Lane | 943be67 | 2012-10-04 19:20:16 -0700 | [diff] [blame] | 474 | for (testname, test) in tests.items(): |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 475 | try: |
Rich Lane | 0f5b9c7 | 2013-01-02 14:05:20 -0800 | [diff] [blame] | 476 | desc = (test.__doc__ or "").strip() |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 477 | desc = desc.split('\n')[0] |
| 478 | except: |
| 479 | desc = "No description" |
Rich Lane | e811e7b | 2013-01-03 13:36:54 -0800 | [diff] [blame] | 480 | groups = set(test._groups) - set(["all", "standard", modname]) |
Rich Lane | 37f4211 | 2013-01-03 13:41:49 -0800 | [diff] [blame] | 481 | all_groups.update(test._groups) |
Rich Lane | e811e7b | 2013-01-03 13:36:54 -0800 | [diff] [blame] | 482 | if groups: |
| 483 | desc = "(%s) %s" % (",".join(groups), desc) |
Rich Lane | 5a9a192 | 2013-01-11 14:29:30 -0800 | [diff] [blame] | 484 | if hasattr(test, "_versions"): |
| 485 | desc = "(%s) %s" % (",".join(sorted(test._versions)), desc) |
Rich Lane | e811e7b | 2013-01-03 13:36:54 -0800 | [diff] [blame] | 486 | start_str = " %s%s %s:" % (test._nonstandard and "*" or " ", |
| 487 | test._disabled and "!" or " ", |
| 488 | testname) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 489 | if len(start_str) > 22: |
| 490 | desc = "\n" + _space_to(22, "") + desc |
Dan Talayco | 79f3608 | 2010-03-11 16:53:53 -0800 | [diff] [blame] | 491 | print start_str + _space_to(22, start_str) + desc |
Dan Talayco | 7f8dba8 | 2012-04-12 12:58:52 -0700 | [diff] [blame] | 492 | test_count += 1 |
Dan Talayco | 79f3608 | 2010-03-11 16:53:53 -0800 | [diff] [blame] | 493 | print |
Rich Lane | 15f64de | 2012-10-04 21:25:57 -0700 | [diff] [blame] | 494 | print "%d modules shown with a total of %d tests" % \ |
| 495 | (mod_count, test_count) |
| 496 | print |
Rich Lane | 37f4211 | 2013-01-03 13:41:49 -0800 | [diff] [blame] | 497 | print "Test groups: %s" % (', '.join(sorted(all_groups))) |
| 498 | |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 499 | sys.exit(0) |
| 500 | |
Rich Lane | 5a9a192 | 2013-01-11 14:29:30 -0800 | [diff] [blame] | 501 | test_modules = prune_tests(test_specs, test_modules, config["openflow_version"]) |
Rich Lane | d8e4548 | 2013-01-02 17:36:21 -0800 | [diff] [blame] | 502 | |
Jeffrey Townsend | 6614f97 | 2012-08-16 13:27:18 -0700 | [diff] [blame] | 503 | # Check if test list is requested; display and exit if so |
| 504 | if config["list_test_names"]: |
Rich Lane | 943be67 | 2012-10-04 19:20:16 -0700 | [diff] [blame] | 505 | for (modname, (mod, tests)) in test_modules.items(): |
Rich Lane | 943be67 | 2012-10-04 19:20:16 -0700 | [diff] [blame] | 506 | for (testname, test) in tests.items(): |
Rich Lane | cc45b8e | 2013-01-02 15:55:02 -0800 | [diff] [blame] | 507 | print "%s.%s" % (modname, testname) |
Jeffrey Townsend | 6614f97 | 2012-08-16 13:27:18 -0700 | [diff] [blame] | 508 | sys.exit(0) |
| 509 | |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 510 | # Generate the test suite |
| 511 | #@todo Decide if multiple suites are ever needed |
| 512 | suite = unittest.TestSuite() |
| 513 | |
Rich Lane | 15f64de | 2012-10-04 21:25:57 -0700 | [diff] [blame] | 514 | for (modname, (mod, tests)) in test_modules.items(): |
| 515 | for (testname, test) in tests.items(): |
Rich Lane | cc45b8e | 2013-01-02 15:55:02 -0800 | [diff] [blame] | 516 | suite.addTest(test()) |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 517 | |
Rich Lane | 51590f6 | 2012-10-09 15:06:29 -0700 | [diff] [blame] | 518 | # Allow platforms to import each other |
| 519 | sys.path.append(config["platform_dir"]) |
| 520 | |
Rich Lane | 8aebc5e | 2012-09-25 17:57:53 -0700 | [diff] [blame] | 521 | # Load the platform module |
| 522 | platform_name = config["platform"] |
| 523 | logging.info("Importing platform: " + platform_name) |
| 524 | platform_mod = None |
| 525 | try: |
Rich Lane | 483e154 | 2012-10-05 09:29:39 -0700 | [diff] [blame] | 526 | platform_mod = imp.load_module(platform_name, *imp.find_module(platform_name, [config["platform_dir"]])) |
Rich Lane | 8aebc5e | 2012-09-25 17:57:53 -0700 | [diff] [blame] | 527 | except: |
| 528 | logging.warn("Failed to import " + platform_name + " platform module") |
| 529 | raise |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 530 | |
| 531 | try: |
Rich Lane | 8aebc5e | 2012-09-25 17:57:53 -0700 | [diff] [blame] | 532 | platform_mod.platform_config_update(config) |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 533 | except: |
| 534 | logging.warn("Could not run platform host configuration") |
Rich Lane | ef403e5 | 2012-07-09 14:59:43 -0700 | [diff] [blame] | 535 | raise |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 536 | |
| 537 | if not config["port_map"]: |
Rich Lane | 8aebc5e | 2012-09-25 17:57:53 -0700 | [diff] [blame] | 538 | die("Interface port map was not defined by the platform. Exiting.") |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 539 | |
| 540 | logging.debug("Configuration: " + str(config)) |
| 541 | logging.info("OF port map: " + str(config["port_map"])) |
| 542 | |
Rich Lane | e55abf7 | 2012-07-26 20:11:42 -0700 | [diff] [blame] | 543 | oftest.ofutils.default_timeout = config["default_timeout"] |
Rich Lane | 48f6aed | 2014-03-23 15:51:02 -0700 | [diff] [blame] | 544 | oftest.ofutils.default_negative_timeout = config["default_negative_timeout"] |
Rich Lane | da3b5ad | 2012-10-03 09:05:32 -0700 | [diff] [blame] | 545 | oftest.testutils.MINSIZE = config['minsize'] |
Rich Lane | e55abf7 | 2012-07-26 20:11:42 -0700 | [diff] [blame] | 546 | |
Rich Lane | ee57ad0 | 2012-07-13 15:40:36 -0700 | [diff] [blame] | 547 | if os.getuid() != 0 and not config["allow_user"]: |
Brandon Heller | 446c143 | 2010-04-01 12:43:27 -0700 | [diff] [blame] | 548 | print "ERROR: Super-user privileges required. Please re-run with " \ |
| 549 | "sudo or as root." |
Rich Lane | d1d9c28 | 2012-10-04 22:07:10 -0700 | [diff] [blame] | 550 | sys.exit(1) |
Brandon Heller | 446c143 | 2010-04-01 12:43:27 -0700 | [diff] [blame] | 551 | |
Rich Lane | 8592bec | 2012-09-03 09:06:59 -0700 | [diff] [blame] | 552 | if config["random_seed"] is not None: |
| 553 | logging.info("Random seed: %d" % config["random_seed"]) |
| 554 | random.seed(config["random_seed"]) |
Dan Talayco | ec6084d | 2013-03-14 10:38:22 -0700 | [diff] [blame] | 555 | else: |
| 556 | # Generate random seed and report to log file |
| 557 | seed = random.randrange(100000000) |
| 558 | logging.info("Autogen random seed: %d" % seed) |
| 559 | random.seed(seed) |
Rich Lane | 8592bec | 2012-09-03 09:06:59 -0700 | [diff] [blame] | 560 | |
Rich Lane | 5bd6cf9 | 2012-10-04 17:57:24 -0700 | [diff] [blame] | 561 | # Remove python's signal handler which raises KeyboardError. Exiting from an |
| 562 | # exception waits for all threads to terminate which might not happen. |
| 563 | signal.signal(signal.SIGINT, signal.SIG_DFL) |
Dan Talayco | ac25cf3 | 2010-07-20 14:08:28 -0700 | [diff] [blame] | 564 | |
| 565 | if __name__ == "__main__": |
Stephen Finucane | 6219af7 | 2014-05-14 21:08:30 +0100 | [diff] [blame] | 566 | profiler = profiler_setup(config) |
Rich Lane | 9631f00 | 2014-03-21 18:05:16 -0700 | [diff] [blame] | 567 | |
Rich Lane | 2c7812c | 2012-12-27 17:52:23 -0800 | [diff] [blame] | 568 | # Set up the dataplane |
| 569 | oftest.dataplane_instance = oftest.dataplane.DataPlane(config) |
Rich Lane | 472aaea | 2013-08-27 09:27:38 -0700 | [diff] [blame] | 570 | pcap_setup(config) |
Rich Lane | 2c7812c | 2012-12-27 17:52:23 -0800 | [diff] [blame] | 571 | for of_port, ifname in config["port_map"].items(): |
| 572 | oftest.dataplane_instance.port_add(ifname, of_port) |
| 573 | |
Dan Talayco | ac25cf3 | 2010-07-20 14:08:28 -0700 | [diff] [blame] | 574 | logging.info("*** TEST RUN START: " + time.asctime()) |
Stephen Finucane | e016cf2 | 2014-04-16 22:04:11 +0100 | [diff] [blame] | 575 | if config["xunit"]: |
Stephen Finucane | 1278255 | 2014-05-20 21:55:04 +0100 | [diff] [blame^] | 576 | try: |
| 577 | import xmlrunner # fail-fast if module missing |
| 578 | except ImportError as ex: |
| 579 | oftest.dataplane_instance.kill() |
| 580 | profiler_teardown(profiler) |
| 581 | raise ex |
Stephen Finucane | e016cf2 | 2014-04-16 22:04:11 +0100 | [diff] [blame] | 582 | runner = xmlrunner.XMLTestRunner(output=config["xunit_dir"], |
| 583 | outsuffix="", |
| 584 | verbosity=2) |
| 585 | result = runner.run(suite) |
| 586 | else: |
| 587 | result = unittest.TextTestRunner(verbosity=2).run(suite) |
Rich Lane | 69fd8e0 | 2013-08-23 16:23:42 -0700 | [diff] [blame] | 588 | oftest.open_logfile('main') |
Rich Lane | da3b5ad | 2012-10-03 09:05:32 -0700 | [diff] [blame] | 589 | if oftest.testutils.skipped_test_count > 0: |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 590 | ts = " tests" |
Stephen Finucane | 6219af7 | 2014-05-14 21:08:30 +0100 | [diff] [blame] | 591 | if oftest.testutils.skipped_test_count == 1: |
| 592 | ts = " test" |
Rich Lane | da3b5ad | 2012-10-03 09:05:32 -0700 | [diff] [blame] | 593 | logging.info("Skipped " + str(oftest.testutils.skipped_test_count) + ts) |
| 594 | print("Skipped " + str(oftest.testutils.skipped_test_count) + ts) |
Dan Talayco | ac25cf3 | 2010-07-20 14:08:28 -0700 | [diff] [blame] | 595 | logging.info("*** TEST RUN END : " + time.asctime()) |
Rich Lane | 2c7812c | 2012-12-27 17:52:23 -0800 | [diff] [blame] | 596 | |
| 597 | # Shutdown the dataplane |
| 598 | oftest.dataplane_instance.kill() |
| 599 | oftest.dataplane_instance = None |
| 600 | |
Stephen Finucane | 6219af7 | 2014-05-14 21:08:30 +0100 | [diff] [blame] | 601 | profiler_teardown(profiler) |
Rich Lane | 9631f00 | 2014-03-21 18:05:16 -0700 | [diff] [blame] | 602 | |
Rich Lane | 50d42eb | 2012-07-16 11:57:03 -0700 | [diff] [blame] | 603 | if result.failures or result.errors: |
Shudong Zhou | d895fcb | 2012-08-01 19:09:55 -0700 | [diff] [blame] | 604 | # exit(1) hangs sometimes |
| 605 | os._exit(1) |
Rich Lane | da3b5ad | 2012-10-03 09:05:32 -0700 | [diff] [blame] | 606 | if oftest.testutils.skipped_test_count > 0 and config["fail_skipped"]: |
Shudong Zhou | d895fcb | 2012-08-01 19:09:55 -0700 | [diff] [blame] | 607 | os._exit(1) |