8 import os, sys, optparse
9 import time, subprocess
10 from testcase_class
import *
13 parse = optparse.OptionParser()
15 ./run_tests.py [--keep|-k] [--help|-h] t1 [t2 [...]]
17 - unpack and launch test[s] in the test/ directory.
20 t1 [t2 [..]]: tests to run """)
23 parse.add_option(
"-k",
"--keep",action=
"store_false", \
24 dest=
"cleanup_after_test", default=
True, \
25 help=
"do not erase test directory after it succeeded")
27 (options, args) = parse.parse_args()
30 print(
"ERROR: Wrong argument string")
36 program = maindir+
"/bin/winnet"
37 testdir = maindir+
"/test"
38 bindir = maindir+
"/bin"
39 if not os.path.isdir(testdir):
40 print(
"ERROR: test directory does not exist. Perhaps you are not running")
41 print(
" this script from the WINNET root directory with the ")
42 print(
" `make tests` command.")
46 print(
"Running tests:")
49 for i
in range(len(args)):
53 if not (tc==
"-k" or tc==
"--keep"):
54 print (
"ERROR: unknown option.")
59 nd = 3
if len(args)>99
else 2
if len(args)>9
else 1
60 wt_format =
"%" + str(nd) +
"d/%" + str(nd) +
"d"
61 t.whichtest = wt_format % (i+1,len(args))
62 t.len_spaces = 45 - len(tc)
63 if not os.path.exists(testdir +
"/" + tc +
".py"):
64 print(
"ERROR: testcase "+tc+
" does not exist!")
67 exec(compile(open(testdir +
"/" + tc +
".py",
"rb").read(), testdir +
"/" + tc +
".py",
'exec'))
71 print(
"ERROR: while unpacking test "+tc)
79 except AttributeError:
85 print(
"ERROR: when launching test "+tc)
92 print(
"\r [" + t.whichtest +
"] " + tc \
93 +
": .."+
"."*t.len_spaces +
"... [FAIL] ")
96 print(
"\r [" + t.whichtest +
"] " + tc \
97 +
": .."+
"."*t.len_spaces +
"... [ OK ] ")
98 if options.cleanup_after_test:
102 print(
" - %d out of %d tests have failed." % (n_failed, n_tests))
104 print(
" - all tests have passed successfully!")