Step 2: Move test folder to root
[integration/test.git] / tools / CSIT_Test / base / run.py
1 #!/usr/bin/env python
2 """
3 CSIT test tools.
4 Authors: Baohua Yang@IBM, Denghui Huang@IBM
5 Updated: 2013-11-07
6
7 Usage: Before running the test tool, should
8  1. Start 2-layer tree topology network. e.g., in Mininet, run
9     'sudo mn --controller=remote,ip=127.0.0.1 --mac --topo tree,2'.
10  2. Configure gateway in the controller web GUI, name = 'gateway', subnet = '10.0.0.254/24'.
11  3. In Mininet, run 'h1 ping h2' to make sure the network is connected.
12 """
13 import doctest
14 import os
15 from restlib import *  # noqa
16
17
18 def test_module(module_name):
19     '''
20     Run single test on given module.
21     '''
22     print "#Test case: " + module_name.replace('_', ' ')
23     cmd = 'python -m doctest ' + module_name + '.py'
24     os.system(cmd)
25
26
27 def run(modules=None):
28     '''
29     Run test cases according to the given modules.
30     If no parameter is given, then will scan the case directory,
31      and try to run all cases.
32     '''
33     backup_dir = os.getcwd()
34     if not modules:
35         modules = [e[:-3] for e in os.listdir(MODULES_DIR) if e.endswith('.py')]
36     os.chdir(backup_dir + '/' + MODULES_DIR)
37     for name in modules:
38         test_module(name)
39     os.chdir(backup_dir)
40
41
42 if __name__ == '__main__':
43     doctest.testmod()
44     test_modules = ['switch_manager', 'topology_manager', 'forwarding_rule_manager', 'statistics_manager',
45                     'host_tracker', 'arp_handler', 'forwarding_manager', 'container_manager']
46     # test_modules = ['topology_manager']
47     run(test_modules)
48     # run()