19from __future__
import print_function
29 print(
"-", end=
"", file=out)
31 print(
"running test case " + case_string, end=
"\n\n", file=out)
36 print(
"\nFailed Cases:")
37 for case
in failed_cases:
42 print(
"Commands to be executed:")
44 print(cmd.replace(sys.executable,
""))
48 dir_files = [f
for f
in os.listdir(
".")
if os.path.exists(f)]
49 if not "VERSION" in dir_files
and not "ns3" in dir_files:
51 os.path.split(os.path.abspath(
"."))[1] ==
"tests"
52 and os.path.split(os.path.abspath(os.pardir))[1] ==
"utils"
56 print(
"Error: Invalid working directory")
63 Generic class for testing tools based on provided commands and
test cases.
77 Provide input argument list, description and mode of the suite being executed.
78 @param self this object
79 @param argv argument list
80 @param desc description
85 self.my_env["LD_LIBRARY_PATH"] = os.getcwd() +
"/build"
92 Parses the commandline arguments
93 @param self this object
94 @param argv argument list
95 @param desc description
96 @return command line arguments
98 parser = argparse.ArgumentParser(description=desc)
106 help=
"File to be used for storing the command specific output (Default: "
115 help=
"List out all the commands being tested",
122 help=
"Sends only stderr output to FILE",
130 help=
"Enter a comma-separated list of commands to override the existing ones. NOT APPLICABLE FOR TEST-PY SUITE.",
132 return parser.parse_args(argv)
136 Can be used by importing suite to handle custom commands
137 @param self this object
138 @return custom commands
145 @param self this object
146 @param cmds test commands
152 base_dir = os.sep.join(
153 os.path.abspath(__file__).replace(os.path.pathsep,
"/").split(
"/")[:-3]
156 total_tests = len(cmds)
160 with open(self.
options.out_file,
"w", encoding=
"utf-8")
as out:
162 with open(os.devnull,
"w", encoding=
"utf-8")
as sink:
166 case_string = cmd.replace(sys.executable,
"")
167 print(
"running test case: " + case_string)
170 ret = subprocess.call(
171 cmd, shell=
True, env=self.
my_env, stdout=outstream, stderr=out, cwd=base_dir
177 failed_cases.append(case_string)
179 "[ %s out of %s ] test cases passed; Progress = %.2f%% \n"
180 % (passed, total_tests, progress * 100 / total_tests)
182 if final_return != 0:
185 print(
"\nAll cases passed")
186 print(
"Detailed output available in " + self.
options.out_file, end=
"\n\n")
def __init__(self, argv, desc, mode)
Provide input argument list, description and mode of the suite being executed.
def parseargs(self, argv, desc)
Parses the commandline arguments.
def override_cmds(self)
Can be used by importing suite to handle custom commands.
def runtests(self, cmds)
Execute the tests.
def print_case_in_file(case_string, out)
def print_failed_cases(failed_cases)
-ns3 Test suite for the ns3 wrapper script