A Discrete-Event Network Simulator
API
test-waf.py
Go to the documentation of this file.
1 #! /usr/bin/env python3
2 
19 
20 # NOTE: Run this script with the Python3 interpreter if the python3 compatibility
21 # of the ns-3 unit test runner needs to be tested.
22 
23 # The following options of waf are being tested for poratability by this script.
24 # To see the options supported by this script, run with the -h option on the command line
25 #
26 # build : executes the build (pre: configure, post: clean)
27 # check : run the equivalent of the old ns-3 unit tests using test.py
28 # clean : cleans the project
29 # configure: configures the project (pore: None, post: distclean)
30 # dist : makes a tarball for redistributing the sources (pre:none )
31 # distcheck: checks if the project compiles (tarball from 'dist') (pre: dist, post: rm -rf ns-3*.tar.bz2)
32 # docs : build all the documentation: doxygen, manual, tutorial, models (pre: configure; post: distclean)
33 # doxygen : do a full build, generate the introspected doxygen and then the doxygen
34 # install : installs the targets on the system (pre: configure, post: uninstall )
35 # list : lists the targets to execute (pre: configure)
36 # shell : run a shell with an environment suitably modified to run locally built programs (pre:configure)
37 # sphinx : build the Sphinx documentation: manual, tutorial, models
38 # step : executes tasks in a step-by-step fashion, for debugging (pre: configure)
39 # uninstall: removes the targets installed (pre: install, post uninstall)
40 # *update : updates the plugins from the *waflib/extras* directory
41 
42 
43 
44 
45 from __future__ import print_function
46 from TestBase import TestBaseClass
47 import sys
48 
49 def replace(pre, post, main_cmd_list):
50  if pre:
51  pre = pre + ' && '
52  else:
53  pre = ''
54  if post:
55  post = ' && ' + post
56  else:
57  post = ''
58  return [ pre + main_cmd + post for main_cmd in main_cmd_list ]
59 
60 def main(argv):
61  """
62  Prepares test cases and executes
63  """
64  runner = TestBaseClass(argv[1:], "Test suite for the ns-3 Waf build system", 'waf')
65  in_cmds = runner.override_cmds()
66  if in_cmds:
67  cmds = in_cmds.split(',')
68  else:
69  cmds = ['basic', 'build', 'configure', 'step', 'clean', 'dist', 'list']
70 
71  config_test_cases = [
72  "--enable-gcov",
73  "--enable-sudo",
74  "--enable-sudo",
75  "--enable-tests",
76  "--disable-tests",
77  "--enable-examples",
78  "--disable-examples",
79  "--doxygen-no-build",
80  "--enable-static",
81  "--enable-mpi",
82  "--enable-rpath",
83  "--enable-modules=build/utils/test-runner.cc.1.o",
84  "--boost-static",
85  "--boost-mt",
86  "--boost-linkage_autodetect",
87  "--boost-python=33",
88  "--disable-gtk",
89  "--int64x64=cairo",
90  "--disable-pthread",
91  "--force-planetlab",
92  "--nopyc",
93  "--nopyo",
94  "--disable-python",
95  "--apiscan=all",
96  "--with-python=/usr/bin/python2.7",
97  "-o test_out && rm -rf test_out",
98  "--out=test_out && rm -rf test_out",
99  "-t test_top && rm -rf test_top",
100  "--top=test_top && rm -rf test_top",
101  "--download",
102  "--check-c-compiler=gc",
103  "--check-cxx-compiler=g++",
104  ]
105 
106  basic_test_cases = [
107  "--version",
108  "-h",
109  "--help",
110  ]
111 
112  build_test_cases = [
113  "-j10",
114  "--jobs=10",
115  "-d optimized",
116  "-d debug",
117  "-d release",
118  "--build-profile optimized",
119  "--build-profile debug",
120  "--build-profile release",
121  "-p",
122  "--progress",
123  ]
124 
125  step_test_cases = [
126  "--files=\"*/main.c,*/test/main.o\"",
127  ]
128 
129  install_test_cases = [
130  "-f",
131  "--force",
132  "--prefix=./test-prefix && rm -rf ./test-prefix",
133  "--exec-prefix=.",
134  "--bindir=./test-prefix/bin --sbindir=./test-prefix/sbin --libexecdir=./test-prefix/libexec --sysconfdir=./test-prefix/etc --sharedstatedir=./test-prefix/com --localstatedir=./test-prefix/var --libdir=./test-prefix/lib --includedir=./test-prefix/include --oldincludedir=./test-prefix/usr/include --datarootdir=./test-prefix/share --datadir=./test-prefix/share_root --infodir=./test-prefix/info --localedir=./test-prefix/locale --mandir=./test-prefix/man --docdir=./test-prefix/doc/package --htmldir=./test-prefix/doc --dvidir=./test-prefix/doc --pdfdir=./test-prefix/doc --psdir=./test-prefix/doc && rm -rf ./test-prefix",
135  ]
136 
137  common_test_cases = [
138  "",
139  "-k",
140  "--keep",
141  "-v",
142  "--verbose",
143  "--nocache",
144  "--zones=task_gen",
145  "--zones=deps",
146  "--zones=tasks",
147  "--no-task-lines",
148  ]
149 
150  test_case_mappings = {
151  'basic' : basic_test_cases,
152  'configure' : config_test_cases,
153  'build' : build_test_cases,
154  'step' : step_test_cases,
155  'install' : install_test_cases,
156  }
157 
158  waf_string = sys.executable + ' waf'
159  cmd_execute_list = []
160  for cmd in cmds:
161  if cmd == 'basic':
162  cmd_list = []
163  else:
164  cmd_list = ['%s %s %s' % (waf_string, cmd, option) for option in common_test_cases ]
165  if cmd in test_case_mappings:
166  cmd_list += ['%s %s %s' % (waf_string, cmd, option) for option in test_case_mappings[cmd] ]
167  if cmd == 'basic':
168  cmd_list.append('%s configure && %s build && %s --run scratch/myfirst' % tuple([waf_string]*3))
169  cmd_list.append('%s configure && %s build && %s --pyrun scratch/myfirst.py' % tuple([waf_string]*3))
170  if cmd == 'build':
171  cmd_list = replace(waf_string+' configure', waf_string+' clean', cmd_list)
172  cmd_list.append('%s configure --enable-gcov && %s build --lcov-report && %s clean' % tuple([waf_string]*3))
173  elif cmd == 'configure':
174  cmd_list = replace(None, waf_string+' distclean', cmd_list)
175  elif cmd == 'distcheck':
176  cmd_list = replace(waf_string+' dist', 'rm -rf ns-3*.tar.bz2', cmd_list)
177  elif cmd == 'docs':
178  cmd_list = replace(waf_string+' configure', waf_string+' distclean', cmd_list)
179  elif cmd == 'install':
180  cmd_list = replace(waf_string+' configure', waf_string+' uninstall', cmd_list)
181  elif cmd == 'list':
182  cmd_list = replace(waf_string+' configure', waf_string +' distclean', cmd_list)
183  elif cmd == 'shell':
184  cmd_list = replace(waf_string+' configure', waf_string+' distclean', cmd_list)
185  elif cmd == 'step':
186  cmd_list = replace(waf_string+' configure', waf_string+' distclean', cmd_list)
187  elif cmd == 'uninstall':
188  cmd_list = replace(waf_string+' install', None, cmd_list)
189  cmd_execute_list += cmd_list
190 
191  return runner.runtests(cmd_execute_list)
192 
193 if __name__ == '__main__':
194  sys.exit(main(sys.argv))
def replace(pre, post, main_cmd_list)
Definition: test-waf.py:49
TestBaseClass class.
Definition: TestBase.py:53