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 | |
| 7 | This script is the entry point for running OpenFlow tests |
| 8 | using the OFT framework. |
| 9 | |
| 10 | The global configuration is passed around in a dictionary |
Brandon Heller | 88f709d | 2010-04-01 12:29:56 -0700 | [diff] [blame] | 11 | generally called config. The keys have the following |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 12 | significance. |
| 13 | |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 14 | <pre> |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 15 | platform : String identifying the target platform |
| 16 | controller_host : Host on which test controller is running (for sockets) |
| 17 | controller_port : Port on which test controller listens for switch cxn |
| 18 | port_count : (Optional) Number of ports in dataplane |
| 19 | base_of_port : (Optional) Base OpenFlow port number in dataplane |
| 20 | base_if_index : (Optional) Base OS network interface for dataplane |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 21 | test_dir : (TBD) Directory to search for test files (default .) |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 22 | test_spec : (TBD) Specification of test(s) to run |
| 23 | log_file : Filename for test logging |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 24 | list : Boolean: List all tests and exit |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 25 | debug : String giving debug level (info, warning, error...) |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 26 | </pre> |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 27 | |
| 28 | See config_defaults below for the default values. |
| 29 | |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 30 | The following are stored in the config dictionary, but are not currently |
| 31 | configurable through the command line. |
| 32 | |
| 33 | <pre> |
| 34 | dbg_level : logging module value of debug level |
| 35 | port_map : Map of dataplane OpenFlow port to OS interface names |
| 36 | test_mod_map : Dictionary indexed by module names and whose value |
| 37 | is the module reference |
| 38 | all_tests : Dictionary indexed by module reference and whose |
| 39 | value is a list of functions in that module |
| 40 | </pre> |
| 41 | |
| 42 | To add a test to the system, either: edit an existing test case file (like |
| 43 | basic.py) to add a test class which inherits from unittest.TestCase (directly |
| 44 | or indirectly); or add a new file which includes a function definition |
| 45 | test_set_init(config). Preferably the file is in the same directory as existing |
| 46 | tests, though you can specify the directory on the command line. The file |
| 47 | should not be called "all" as that's reserved for the test-spec. |
| 48 | |
| 49 | If you add a new file, the test_set_init function should record the port |
| 50 | map object from the configuration along with whatever other configuration |
| 51 | information it may need. |
| 52 | |
| 53 | TBD: To add configuration to the system, first add an entry to config_default |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 54 | below. If you want this to be a command line parameter, edit config_setup |
| 55 | to add the option and default value to the parser. Then edit config_get |
| 56 | to make sure the option value gets copied into the configuration |
| 57 | structure (which then gets passed to everyone else). |
| 58 | |
| 59 | By convention, oft attempts to import the contents of a file by the |
| 60 | name of $platform.py into the local namespace. |
| 61 | |
| 62 | IMPORTANT: That file should define a function platform_config_update which |
| 63 | takes a configuration dictionary as an argument and updates it for the |
| 64 | current run. In particular, it should set up config["port_map"] with |
| 65 | the proper map from OF port numbers to OF interface names. |
| 66 | |
| 67 | You can add your own platform, say gp104, by adding a file gp104.py |
| 68 | that defines the function platform_config_update and then use the |
| 69 | parameter --platform=gp104 on the command line. |
| 70 | |
| 71 | If platform_config_update does not set config["port_map"], an attempt |
| 72 | is made to generate a default map via the function default_port_map_setup. |
| 73 | This will use "local" and "remote" for platform names if available |
| 74 | and generate a sequential map based on the values of base_of_port and |
| 75 | base_if_index in the configuration structure. |
| 76 | |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 77 | The current model for test sets is basic.py. The current convention is |
| 78 | that the test set should implement a function test_set_init which takes |
| 79 | an oft configuration dictionary and returns a unittest.TestSuite object. |
| 80 | Future test sets should do the same thing. |
| 81 | |
Dan Talayco | 52f6444 | 2010-03-03 15:32:41 -0800 | [diff] [blame] | 82 | Default setup: |
| 83 | |
| 84 | The default setup runs locally using veth pairs. To exercise this, |
| 85 | checkout and build an openflow userspace datapath. Then start it on |
| 86 | the local host: |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 87 | <pre> |
Dan Talayco | 52f6444 | 2010-03-03 15:32:41 -0800 | [diff] [blame] | 88 | sudo ~/openflow/regress/bin/veth_setup.pl |
| 89 | sudo ofdatapath -i veth0,veth2,veth4,veth6 punix:/tmp/ofd & |
| 90 | sudo ofprotocol unix:/tmp/ofd tcp:127.0.0.1 --fail=closed --max-backoff=1 & |
| 91 | |
| 92 | Next, run oft: |
| 93 | sudo ./oft --debug=info |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 94 | </pre> |
Dan Talayco | 52f6444 | 2010-03-03 15:32:41 -0800 | [diff] [blame] | 95 | |
| 96 | Examine oft.log if things don't work. |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 97 | |
Dan Talayco | 1a88c12 | 2010-03-07 22:00:20 -0800 | [diff] [blame] | 98 | @todo Support per-component debug levels (esp controller vs dataplane) |
| 99 | @todo Consider moving oft up a level |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 100 | |
Dan Talayco | 1a88c12 | 2010-03-07 22:00:20 -0800 | [diff] [blame] | 101 | Current test case setup: |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 102 | Files in this or sub directories (or later, directory specified on |
| 103 | command line) that contain a function test_set_init are considered test |
| 104 | files. |
| 105 | The function test_set_init examines the test_spec config variable |
| 106 | and generates a suite of tests. |
| 107 | Support a command line option --test_mod so that all tests in that |
| 108 | module will be run. |
| 109 | Support all to specify all tests from the module. |
| 110 | |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 111 | """ |
| 112 | |
| 113 | import sys |
| 114 | from optparse import OptionParser |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 115 | from subprocess import Popen,PIPE |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 116 | import logging |
| 117 | import unittest |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 118 | import time |
Brandon Heller | 446c143 | 2010-04-01 12:43:27 -0700 | [diff] [blame^] | 119 | import os |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 120 | |
| 121 | ##@var DEBUG_LEVELS |
| 122 | # Map from strings to debugging levels |
| 123 | DEBUG_LEVELS = { |
| 124 | 'debug' : logging.DEBUG, |
| 125 | 'verbose' : logging.DEBUG, |
| 126 | 'info' : logging.INFO, |
| 127 | 'warning' : logging.WARNING, |
| 128 | 'warn' : logging.WARNING, |
| 129 | 'error' : logging.ERROR, |
| 130 | 'critical' : logging.CRITICAL |
| 131 | } |
| 132 | |
| 133 | _debug_default = "warning" |
| 134 | _debug_level_default = DEBUG_LEVELS[_debug_default] |
| 135 | |
| 136 | ##@var config_default |
| 137 | # The default configuration dictionary for OFT |
| 138 | config_default = { |
| 139 | "platform" : "local", |
| 140 | "controller_host" : "127.0.0.1", |
| 141 | "controller_port" : 6633, |
| 142 | "port_count" : 4, |
| 143 | "base_of_port" : 1, |
| 144 | "base_if_index" : 1, |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 145 | "test_spec" : "all", |
| 146 | "test_dir" : ".", |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 147 | "log_file" : "oft.log", |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 148 | "list" : False, |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 149 | "debug" : _debug_default, |
| 150 | "dbg_level" : _debug_level_default, |
| 151 | "port_map" : {} |
| 152 | } |
| 153 | |
Dan Talayco | 1a88c12 | 2010-03-07 22:00:20 -0800 | [diff] [blame] | 154 | #@todo Set up a dict of config params so easier to manage: |
| 155 | # <param> <cmdline flags> <default value> <help> <optional parser> |
| 156 | |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 157 | # Map options to config structure |
| 158 | def config_get(opts): |
| 159 | "Convert options class to OFT configuration dictionary" |
| 160 | cfg = config_default.copy() |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 161 | for key in cfg.keys(): |
| 162 | cfg[key] = eval("opts." + key) |
| 163 | |
| 164 | # Special case checks |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 165 | if opts.debug not in DEBUG_LEVELS.keys(): |
| 166 | print "Warning: Bad value specified for debug level; using default" |
| 167 | opts.debug = _debug_default |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 168 | cfg["dbg_level"] = DEBUG_LEVELS[cfg["debug"]] |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 169 | |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 170 | return cfg |
| 171 | |
| 172 | def config_setup(cfg_dflt): |
| 173 | """ |
| 174 | Set up the configuration including parsing the arguments |
| 175 | |
| 176 | @param cfg_dflt The default configuration dictionary |
| 177 | @return A pair (config, args) where config is an config |
| 178 | object and args is any additional arguments from the command line |
| 179 | """ |
| 180 | |
| 181 | parser = OptionParser(version="%prog 0.1") |
| 182 | |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 183 | #@todo parse port map as option? |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 184 | # Set up default values |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 185 | for key in cfg_dflt.keys(): |
| 186 | eval("parser.set_defaults("+key+"=cfg_dflt['"+key+"'])") |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 187 | |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 188 | #@todo Add options via dictionary |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 189 | plat_help = """Set the platform type. Valid values include: |
| 190 | local: User space virtual ethernet pair setup |
| 191 | remote: Remote embedded Broadcom based switch |
Dan Talayco | 673e085 | 2010-03-06 23:09:23 -0800 | [diff] [blame] | 192 | Create a new_plat.py file and use --platform=new_plat on the command line |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 193 | """ |
| 194 | parser.add_option("-P", "--platform", help=plat_help) |
| 195 | parser.add_option("-H", "--host", dest="controller_host", |
| 196 | help="The IP/name of the test controller host") |
| 197 | parser.add_option("-p", "--port", dest="controller_port", |
| 198 | type="int", help="Port number of the test controller") |
Dan Talayco | 673e085 | 2010-03-06 23:09:23 -0800 | [diff] [blame] | 199 | test_list_help = """Indicate tests to run. Valid entries are "all" (the |
| 200 | default) or a comma separated list of: |
| 201 | module Run all tests in the named module |
| 202 | testcase Run tests in all modules with the name testcase |
| 203 | module.testcase Run the specific test case |
| 204 | """ |
| 205 | parser.add_option("--test-spec", "--test-list", help=test_list_help) |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 206 | parser.add_option("--log-file", |
| 207 | help="Name of log file, empty string to log to console") |
| 208 | parser.add_option("--debug", |
| 209 | help="Debug lvl: debug, info, warning, error, critical") |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 210 | parser.add_option("--port-count", |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 211 | help="Number of ports to use (optional)") |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 212 | parser.add_option("--base-of-port", |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 213 | help="Base OpenFlow port number (optional)") |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 214 | parser.add_option("--base-if-index", |
| 215 | help="Base interface index number (optional)") |
| 216 | parser.add_option("--list", action="store_true", |
Brandon Heller | 824504e | 2010-04-01 12:21:37 -0700 | [diff] [blame] | 217 | help="List all tests and exit") |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 218 | # Might need this if other parsers want command line |
| 219 | # parser.allow_interspersed_args = False |
| 220 | (options, args) = parser.parse_args() |
| 221 | |
| 222 | config = config_get(options) |
| 223 | |
| 224 | return (config, args) |
| 225 | |
| 226 | def logging_setup(config): |
| 227 | """ |
| 228 | Set up logging based on config |
| 229 | """ |
| 230 | _format = "%(asctime)s %(name)-10s: %(levelname)-8s: %(message)s" |
| 231 | _datefmt = "%H:%M:%S" |
Dan Talayco | 88fc880 | 2010-03-07 11:37:52 -0800 | [diff] [blame] | 232 | logging.basicConfig(filename=config["log_file"], |
| 233 | level=config["dbg_level"], |
| 234 | format=_format, datefmt=_datefmt) |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 235 | |
| 236 | def default_port_map_setup(config): |
| 237 | """ |
| 238 | Setup the OF port mapping based on config |
| 239 | @param config The OFT configuration structure |
| 240 | @return Port map dictionary |
| 241 | """ |
| 242 | if (config["base_of_port"] is None) or not config["port_count"]: |
| 243 | return None |
| 244 | port_map = {} |
| 245 | if config["platform"] == "local": |
| 246 | # For local, use every other veth port |
| 247 | for idx in range(config["port_count"]): |
| 248 | port_map[config["base_of_port"] + idx] = "veth" + \ |
| 249 | str(config["base_if_index"] + (2 * idx)) |
| 250 | elif config["platform"] == "remote": |
| 251 | # For remote, use eth ports |
| 252 | for idx in range(config["port_count"]): |
| 253 | port_map[config["base_of_port"] + idx] = "eth" + \ |
| 254 | str(config["base_if_index"] + idx) |
| 255 | else: |
| 256 | return None |
| 257 | |
| 258 | logging.info("Built default port map") |
| 259 | return port_map |
| 260 | |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 261 | def test_list_generate(config): |
| 262 | """Generate the list of all known tests indexed by module name |
| 263 | |
| 264 | Conventions: Test files must implement the function test_set_init |
| 265 | |
Dan Talayco | 1a88c12 | 2010-03-07 22:00:20 -0800 | [diff] [blame] | 266 | Test cases are classes that implement runTest |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 267 | |
| 268 | @param config The oft configuration dictionary |
| 269 | @returns An array of triples (mod-name, module, [tests]) where |
| 270 | mod-name is the string (filename) of the module, module is the |
| 271 | value returned from __import__'ing the module and [tests] is an |
| 272 | array of strings giving the test cases from the module. |
| 273 | """ |
| 274 | |
| 275 | # Find and import test files |
| 276 | p1 = Popen(["find", config["test_dir"], "-type","f"], stdout = PIPE) |
| 277 | p2 = Popen(["xargs", "grep", "-l", "-e", "^def test_set_init"], |
| 278 | stdin=p1.stdout, stdout=PIPE) |
| 279 | |
| 280 | all_tests = {} |
| 281 | mod_name_map = {} |
| 282 | # There's an extra empty entry at the end of the list |
| 283 | filelist = p2.communicate()[0].split("\n")[:-1] |
| 284 | for file in filelist: |
Dan Talayco | de2a639 | 2010-03-10 13:56:51 -0800 | [diff] [blame] | 285 | if file[-1:] == '~': |
| 286 | continue |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 287 | modfile = file.lstrip('./')[:-3] |
| 288 | |
| 289 | try: |
| 290 | mod = __import__(modfile) |
| 291 | except: |
| 292 | logging.warning("Could not import file " + file) |
| 293 | continue |
| 294 | mod_name_map[modfile] = mod |
| 295 | added_fn = False |
| 296 | for fn in dir(mod): |
| 297 | if 'runTest' in dir(eval("mod." + fn)): |
| 298 | if not added_fn: |
| 299 | mod_name_map[modfile] = mod |
| 300 | all_tests[mod] = [] |
| 301 | added_fn = True |
| 302 | all_tests[mod].append(fn) |
| 303 | config["all_tests"] = all_tests |
| 304 | config["mod_name_map"] = mod_name_map |
| 305 | |
| 306 | def die(msg, exit_val=1): |
| 307 | print msg |
| 308 | logging.critical(msg) |
| 309 | sys.exit(exit_val) |
| 310 | |
| 311 | def add_test(suite, mod, name): |
| 312 | logging.info("Adding test " + mod.__name__ + "." + name) |
| 313 | suite.addTest(eval("mod." + name)()) |
| 314 | |
Dan Talayco | 79f3608 | 2010-03-11 16:53:53 -0800 | [diff] [blame] | 315 | def _space_to(n, str): |
| 316 | """ |
| 317 | Generate a string of spaces to achieve width n given string str |
| 318 | If length of str >= n, return one space |
| 319 | """ |
| 320 | spaces = n - len(str) |
| 321 | if spaces > 0: |
| 322 | return " " * spaces |
| 323 | return " " |
| 324 | |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 325 | # |
| 326 | # Main script |
| 327 | # |
| 328 | |
| 329 | # Get configuration, set up logging, import platform from file |
| 330 | (config, args) = config_setup(config_default) |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 331 | |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 332 | test_list_generate(config) |
| 333 | |
| 334 | # Check if test list is requested; display and exit if so |
| 335 | if config["list"]: |
Dan Talayco | 79f3608 | 2010-03-11 16:53:53 -0800 | [diff] [blame] | 336 | did_print = False |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 337 | print "\nTest List:" |
| 338 | for mod in config["all_tests"].keys(): |
Dan Talayco | 79f3608 | 2010-03-11 16:53:53 -0800 | [diff] [blame] | 339 | if config["test_spec"] != "all" and \ |
| 340 | config["test_spec"] != mod.__name__: |
| 341 | continue |
| 342 | did_print = True |
| 343 | desc = mod.__doc__.strip() |
| 344 | desc = desc.split('\n')[0] |
| 345 | start_str = " Module " + mod.__name__ + ": " |
| 346 | print start_str + _space_to(22, start_str) + desc |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 347 | for test in config["all_tests"][mod]: |
Dan Talayco | 79f3608 | 2010-03-11 16:53:53 -0800 | [diff] [blame] | 348 | desc = eval('mod.' + test + '.__doc__.strip()') |
| 349 | desc = desc.split('\n')[0] |
| 350 | start_str = " " + test + ":" |
| 351 | print start_str + _space_to(22, start_str) + desc |
| 352 | print |
| 353 | if not did_print: |
| 354 | print "No tests found for " + config["test_spec"] |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 355 | sys.exit(0) |
| 356 | |
| 357 | logging_setup(config) |
| 358 | logging.info("++++++++ " + time.asctime() + " ++++++++") |
| 359 | |
| 360 | # Generate the test suite |
| 361 | #@todo Decide if multiple suites are ever needed |
| 362 | suite = unittest.TestSuite() |
| 363 | |
| 364 | if config["test_spec"] == "all": |
| 365 | for mod in config["all_tests"].keys(): |
| 366 | for test in config["all_tests"][mod]: |
| 367 | add_test(suite, mod, test) |
| 368 | |
| 369 | else: |
| 370 | for ts_entry in config["test_spec"].split(","): |
| 371 | parts = ts_entry.split(".") |
| 372 | |
| 373 | if len(parts) == 1: # Either a module or test name |
| 374 | if ts_entry in config["mod_name_map"].keys(): |
| 375 | mod = config["mod_name_map"][ts_entry] |
| 376 | for test in config["all_tests"][mod]: |
| 377 | add_test(suite, mod, test) |
| 378 | else: # Search for matching tests |
| 379 | test_found = False |
| 380 | for mod in config["all_tests"].keys(): |
| 381 | if ts_entry in config["all_tests"][mod]: |
| 382 | add_test(suite, mod, ts_entry) |
| 383 | test_found = True |
| 384 | if not test_found: |
| 385 | die("Could not find module or test: " + ts_entry) |
| 386 | |
| 387 | elif len(parts) == 2: # module.test |
| 388 | if parts[0] not in config["mod_name_map"]: |
| 389 | die("Unknown module in test spec: " + ts_entry) |
| 390 | mod = config["mod_name_map"][parts[0]] |
| 391 | if parts[1] in config["all_tests"][mod]: |
| 392 | add_test(suite, mod, parts[1]) |
| 393 | else: |
| 394 | die("No known test matches: " + ts_entry) |
| 395 | |
| 396 | else: |
| 397 | die("Bad test spec: " + ts_entry) |
| 398 | |
| 399 | # Check if platform specified |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 400 | if config["platform"]: |
| 401 | _imp_string = "from " + config["platform"] + " import *" |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 402 | logging.info("Importing platform: " + _imp_string) |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 403 | try: |
| 404 | exec(_imp_string) |
| 405 | except: |
| 406 | logging.warn("Failed to import " + config["platform"] + " file") |
| 407 | |
| 408 | try: |
| 409 | platform_config_update(config) |
| 410 | except: |
| 411 | logging.warn("Could not run platform host configuration") |
| 412 | |
| 413 | if not config["port_map"]: |
| 414 | # Try to set up default port mapping if not done by platform |
| 415 | config["port_map"] = default_port_map_setup(config) |
| 416 | |
| 417 | if not config["port_map"]: |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 418 | die("Interface port map is not defined. Exiting") |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 419 | |
| 420 | logging.debug("Configuration: " + str(config)) |
| 421 | logging.info("OF port map: " + str(config["port_map"])) |
| 422 | |
| 423 | # Init the test sets |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 424 | for (modname,mod) in config["mod_name_map"].items(): |
| 425 | try: |
| 426 | mod.test_set_init(config) |
| 427 | except: |
| 428 | logging.warning("Could not run test_set_init for " + modname) |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 429 | |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 430 | if config["dbg_level"] == logging.CRITICAL: |
| 431 | _verb = 0 |
| 432 | elif config["dbg_level"] >= logging.WARNING: |
| 433 | _verb = 1 |
| 434 | else: |
| 435 | _verb = 2 |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 436 | |
Brandon Heller | 446c143 | 2010-04-01 12:43:27 -0700 | [diff] [blame^] | 437 | if os.getuid() != 0: |
| 438 | print "ERROR: Super-user privileges required. Please re-run with " \ |
| 439 | "sudo or as root." |
| 440 | exit(1) |
| 441 | |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 442 | logging.info("*** TEST RUN START: " + time.asctime()) |
| 443 | unittest.TextTestRunner(verbosity=_verb).run(suite) |
| 444 | logging.info("*** TEST RUN END : " + time.asctime()) |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 445 | |