]> SALOME platform Git repositories - modules/kernel.git/blob - bin/runTests.py
Salome HOME
Fix Salome launch when there are config files named SalomeApprc.DEV.7 for instance
[modules/kernel.git] / bin / runTests.py
1 # Copyright (C) 2015 CEA/DEN, EDF R&D, OPEN CASCADE
2 #
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.
7 #
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.
12 #
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
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 import os
21 import sys
22 import select
23 import subprocess
24
25 def __configureTests(args=[], exe=None):
26   if exe:
27       usage = "Usage: %s [options]"%exe
28   else:
29       usage = "Usage: %prog [options]"
30   epilog  = """\n
31 Run tests of SALOME components provided with application.\n
32 Principal options are:
33     -h,--help
34         Show this help message and exit.
35
36     -V,--verbose
37         Enable verbose output from tests.
38     -VV,--extra-verbose
39         Enable more verbose output from tests.
40     -Q,--quiet
41         Suppress all output.
42
43     -N,--show-only
44         Show available tests (without running them).
45
46     -R <regex>, --tests-regex <regex>
47         Run tests matching regular expression.
48     -E <regex>, --exclude-regex <regex>
49         Exclude tests matching regular expression.
50
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.
55
56 For complete description of available options, pleaser refer to ctest documentation.\n
57 """
58   if not args:
59     return []
60
61   if args[0] in ["-h", "--help"]:
62     print usage + epilog
63     sys.exit(0)
64
65   return args
66 #
67
68 # tests must be in ${ABSOLUTE_APPLI_PATH}/${__testSubDir}/
69 __testSubDir = "bin/salome/test"
70
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)
74   stdout = []
75   stderr = []
76
77   while True:
78     reads = [p.stdout.fileno(), p.stderr.fileno()]
79     ret = select.select(reads, [], [])
80
81     for fd in ret[0]:
82       if fd == p.stdout.fileno():
83         read = p.stdout.readline()
84         sys.stdout.write(read)
85         stdout.append(read)
86         pass
87       if fd == p.stderr.fileno():
88         read = p.stderr.readline()
89         sys.stderr.write(read)
90         stderr.append(read)
91         pass
92       pass
93
94     if p.poll() != None:
95       break
96     pass
97
98   return p.returncode, "".join(stdout), "".join(stderr)
99 #
100
101 def runTests(args, exe=None):
102   args = __configureTests(args, exe)
103
104   appliPath = os.getenv("ABSOLUTE_APPLI_PATH")
105   if not appliPath:
106       raise SalomeContextException("Unable to find application path. Please check that the variable ABSOLUTE_APPLI_PATH is set.")
107
108   testPath = os.path.join(appliPath, __testSubDir)
109
110   command = ["ctest"] + args
111   res, out, err = __runTest(command, testPath)
112
113   sys.exit(res)
114 #