| peusterm | 94f53ae | 2016-01-15 12:32:53 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | """ |
| 4 | Run all tests |
| 5 | -v : verbose output |
| 6 | -e : emulator test only (no API tests) |
| 7 | -a : API tests only |
| 8 | """ |
| 9 | |
| 10 | from unittest import defaultTestLoader, TextTestRunner, TestSuite |
| 11 | import os |
| 12 | import sys |
| 13 | from mininet.util import ensureRoot |
| 14 | from mininet.clean import cleanup |
| 15 | from mininet.log import setLogLevel |
| 16 | |
| 17 | |
| 18 | def runTests( testDir, verbosity=1, emuonly=False, apionly=False ): |
| 19 | "discover and run all tests in testDir" |
| peusterm | 0344cc6 | 2016-02-03 09:50:26 +0100 | [diff] [blame] | 20 | # ensure inport paths work |
| 21 | sys.path.append("%s/.." % testDir) |
| peusterm | 94f53ae | 2016-01-15 12:32:53 +0100 | [diff] [blame] | 22 | # ensure root and cleanup before starting tests |
| 23 | ensureRoot() |
| 24 | cleanup() |
| 25 | # discover all tests in testDir |
| 26 | testSuite = defaultTestLoader.discover( testDir ) |
| 27 | if emuonly: |
| 28 | testSuiteFiltered = [s for s in testSuite if "Emulator" in str(s)] |
| 29 | testSuite = TestSuite() |
| 30 | testSuite.addTests(testSuiteFiltered) |
| 31 | if apionly: |
| 32 | testSuiteFiltered = [s for s in testSuite if "Api" in str(s)] |
| 33 | testSuite = TestSuite() |
| 34 | testSuite.addTests(testSuiteFiltered) |
| 35 | |
| 36 | # run tests |
| 37 | TextTestRunner( verbosity=verbosity ).run( testSuite ) |
| 38 | |
| 39 | |
| 40 | def main(thisdir): |
| 41 | setLogLevel( 'warning' ) |
| 42 | # get the directory containing example tests |
| 43 | vlevel = 2 if '-v' in sys.argv else 1 |
| 44 | emuonly = ('-e' in sys.argv) |
| 45 | apionly = ('-a' in sys.argv) |
| 46 | runTests( |
| 47 | testDir=thisdir, verbosity=vlevel, emuonly=emuonly, apionly=apionly) |
| 48 | |
| 49 | |
| 50 | if __name__ == '__main__': |
| 51 | thisdir = os.path.dirname( os.path.realpath( __file__ ) ) |
| 52 | main(thisdir) |