3 from xml.dom import minidom
4 from vsm_test_parser import Logger, Parser
10 _defLaunchArgs = ["--report_format=XML",
11 "--catch_system_errors=no",
12 "--log_level=test_suite",
13 "--report_level=detailed",
18 def _checkIfBinExists(binary):
19 # Check if binary is accessible through PATH env and with no additional paths
20 paths = [s + "/" for s in os.environ["PATH"].split(os.pathsep)]
22 existsInPaths = any([os.path.isfile(path + binary) and os.access(path + binary, os.X_OK)
26 log.error(binary + " NOT FOUND.")
32 def launchTest(cmd=[], externalToolCmd=[], parsing=True):
33 """Default function used to launch test binary.
35 Creates a new subprocess and parses it's output
37 if not _checkIfBinExists(cmd[0]):
39 if externalToolCmd and not _checkIfBinExists(externalToolCmd[0]):
42 log.info("Starting " + cmd[0] + " ...")
46 commandString = " ".join(externalToolCmd + cmd + _defLaunchArgs)
47 log.info("Invoking `" + commandString + "`")
48 p = subprocess.Popen(externalToolCmd + cmd + _defLaunchArgs,
49 stdout=subprocess.PIPE,
50 stderr=subprocess.STDOUT)
51 testResult = parser.parseOutputFromProcess(p)
53 domResult = minidom.parseString(testResult)
54 log.XMLSummary(domResult)
55 log.failedTestSummary(cmd[0])
57 log.terminatedBySignal(" ".join(cmd), -p.returncode)
59 # Launching process without coloring does not require report in XML form
60 # Avoid providing --report_format=XML, redirect std* by default to system's std*
61 commandString = " ".join(externalToolCmd + cmd + _defLaunchArgs[1:])
62 log.info("Invoking `" + commandString + "`")
63 p = subprocess.Popen(externalToolCmd + cmd + _defLaunchArgs[1:])
66 log.info(cmd[0] + " finished.")
70 _valgrindCmd = ["valgrind"]
71 _gdbCmd = ["gdb", "--args"]
74 argparser = argparse.ArgumentParser(description="Test binary launcher for vasum.")
75 group = argparser.add_mutually_exclusive_group()
76 group.add_argument('--valgrind', action='store_true',
77 help='Launch test binary inside Valgrind (assuming it is installed).')
78 group.add_argument('--gdb', action='store_true',
79 help='Launch test binary with a tool specified by $VSM_DEBUGGER variable. '
81 argparser.add_argument('binary', nargs=argparse.REMAINDER,
82 help='Binary to be launched using script.')
84 args = argparser.parse_known_args()
88 debuggerVar = os.getenv("VSM_DEBUGGER")
90 _customDebuggerCmd = debuggerVar.split()
92 _customDebuggerCmd = _gdbCmd
93 launchTest(args[0].binary, externalToolCmd=_customDebuggerCmd + args[1], parsing=False)
94 elif args[0].valgrind:
95 launchTest(args[0].binary, externalToolCmd=_valgrindCmd + args[1])
97 launchTest(args[0].binary, parsing=True)
99 log.info("Test binary not provided! Exiting.")
103 if __name__ == "__main__":