Rename cases to modules and minor bug fix
[integration/test.git] / test / 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  'sudo mn --controller=remote,ip=127.0.0.1 --mac --topo tree,2'.
9  2. Configure gateway in the controller web GUI, name = 'gateway', subnet = '10.0.0.254/24'.
10  3. In Mininet, run 'h1 ping h2' to make sure the network is connected.
11 """
12 import doctest
13 import os
14 from restlib import *
15
16
17 def test_module(module_name):
18     '''
19     Run single test on given module.
20     '''
21     print "#Test case: " + module_name.replace('_', ' ')
22     cmd = 'python -m doctest ' + module_name + '.py'
23     os.system(cmd)
24
25 def run(modules=None):
26     '''
27     Run test cases according to the given modules.
28     If no parameter is given, then will scan the case directory,
29      and try to run all cases.
30     '''
31     backup_dir = os.getcwd()
32     if not modules:
33         modules = [e[:-3] for e in os.listdir(MODULES_DIR) if e.endswith('.py')]
34     os.chdir(backup_dir + '/' + MODULES_DIR)
35     for name in modules:
36         test_module(name)
37     os.chdir(backup_dir)
38
39
40 if __name__ == '__main__':
41     doctest.testmod()
42     test_modules = ['switch_manager', 'topology_manager', 'forwarding_rule_manager', 'statistics_manager',
43                     'host_tracker', 'arp_handler', 'forwarding_manager', 'container_manager']
44     #test_modules = ['topology_manager']
45     run(test_modules)
46     #run()