1 # Copyright (C) 2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
25 def __configureTests(args=[], exe=None):
27 usage = "Usage: %s [options]"%exe
29 usage = "Usage: %prog [options]"
31 Run tests of SALOME components provided with application.\n
32 Principal options are:
34 Show this help message and exit.
37 Enable verbose output from tests.
39 Enable more verbose output from tests.
44 Show available tests (without running them).
46 -R <regex>, --tests-regex <regex>
47 Run tests matching regular expression.
48 -E <regex>, --exclude-regex <regex>
49 Exclude tests matching regular expression.
51 -L <regex>, --label-regex <regex>
52 Run tests with labels matching regular expression.
53 -LE <regex>, --label-exclude <regex>
54 Exclude tests with labels matching regular expression.
56 For complete description of available options, pleaser refer to ctest documentation.\n
61 if args[0] in ["-h", "--help"]:
68 # tests must be in ${ABSOLUTE_APPLI_PATH}/${__testSubDir}/
69 __testSubDir = "bin/salome/test"
71 # Both display process stdout&stderr to console and capture them to variables
72 def __runTest(command, workdir):
73 p = subprocess.Popen(command, cwd=workdir, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=0)
78 reads = [p.stdout.fileno(), p.stderr.fileno()]
79 ret = select.select(reads, [], [])
82 if fd == p.stdout.fileno():
83 read = p.stdout.readline()
84 sys.stdout.write(read)
87 if fd == p.stderr.fileno():
88 read = p.stderr.readline()
89 sys.stderr.write(read)
98 return p.returncode, "".join(stdout), "".join(stderr)
101 def runTests(args, exe=None):
102 args = __configureTests(args, exe)
104 appliPath = os.getenv("ABSOLUTE_APPLI_PATH")
106 raise SalomeContextException("Unable to find application path. Please check that the variable ABSOLUTE_APPLI_PATH is set.")
108 testPath = os.path.join(appliPath, __testSubDir)
110 command = ["ctest"] + args
111 res, out, err = __runTest(command, testPath)