Salome HOME
add tests
[modules/yacs.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=None, exe=None):
26   if args is None:
27     args = []
28   if exe:
29       usage = "Usage: %s [options]"%exe
30   else:
31       usage = "Usage: %prog [options]"
32   epilog  = """\n
33 Run tests of SALOME components provided with application.\n
34 Principal options are:
35     -h,--help
36         Show this help message and exit.
37
38     -V,--verbose
39         Enable verbose output from tests.
40     -VV,--extra-verbose
41         Enable more verbose output from tests.
42     -Q,--quiet
43         Suppress all output.
44
45     -N,--show-only
46         Show available tests (without running them).
47
48     -R <regex>, --tests-regex <regex>
49         Run tests matching regular expression.
50     -E <regex>, --exclude-regex <regex>
51         Exclude tests matching regular expression.
52
53     -L <regex>, --label-regex <regex>
54         Run tests with labels matching regular expression.
55     -LE <regex>, --label-exclude <regex>
56         Exclude tests with labels matching regular expression.
57
58 For complete description of available options, pleaser refer to ctest documentation.\n
59 """
60   if not args:
61     return []
62
63   if args[0] in ["-h", "--help"]:
64     print usage + epilog
65     sys.exit(0)
66
67   return args
68 #
69
70 # tests must be in ${ABSOLUTE_APPLI_PATH}/${__testSubDir}/
71 __testSubDir = "bin/salome/test"
72
73 # Both display process stdout&stderr to console and capture them to variables
74 def __runTest(command, workdir):
75   p = subprocess.Popen(command, cwd=workdir, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=0)
76   stdout = []
77   stderr = []
78
79   while True:
80     reads = [p.stdout.fileno(), p.stderr.fileno()]
81     ret = select.select(reads, [], [])
82
83     for fd in ret[0]:
84       if fd == p.stdout.fileno():
85         read = p.stdout.readline()
86         sys.stdout.write(read)
87         stdout.append(read)
88         pass
89       if fd == p.stderr.fileno():
90         read = p.stderr.readline()
91         sys.stderr.write(read)
92         stderr.append(read)
93         pass
94       pass
95
96     if p.poll() != None:
97       break
98     pass
99
100   return p.returncode, "".join(stdout), "".join(stderr)
101 #
102
103 def runTests(args, exe=None):
104   args = __configureTests(args, exe)
105
106   appliPath = os.getenv("ABSOLUTE_APPLI_PATH")
107   if not appliPath:
108       raise SalomeContextException("Unable to find application path. Please check that the variable ABSOLUTE_APPLI_PATH is set.")
109
110   testPath = os.path.join(appliPath, __testSubDir)
111
112   command = ["ctest"] + args
113   res, out, err = __runTest(command, testPath)
114
115   sys.exit(res)
116 #