Salome HOME
updated copyright message
[modules/kernel.git] / bin / runTests.py
1 # Copyright (C) 2015-2023  CEA, EDF, 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     --print-labels
39         Print the list of all labels associated with the test set.
40         This option will not run any tests.
41
42     -V,--verbose
43         Enable verbose output from tests.
44     -VV,--extra-verbose
45         Enable more verbose output from tests.
46     -Q,--quiet
47         Suppress all output.
48
49     -N,--show-only
50         Show available tests (without running them).
51
52     -R <regex>, --tests-regex <regex>
53         Run tests matching regular expression.
54     -E <regex>, --exclude-regex <regex>
55         Exclude tests matching regular expression.
56
57     -L <regex>, --label-regex <regex>
58         Run tests with labels matching regular expression.
59     -LE <regex>, --label-exclude <regex>
60         Exclude tests with labels matching regular expression.
61
62 For complete description of available options, pleaser refer to ctest documentation.\n
63 """
64   if not args:
65     return []
66
67   if args[0] in ["-h", "--help"]:
68     print(usage + epilog)
69     sys.exit(0)
70
71   return args
72 #
73
74 # tests must be in ${ABSOLUTE_APPLI_PATH}/${__testSubDir}/
75 __testSubDir = "bin/salome/test"
76
77 def runTests(args, exe=None):
78   args = __configureTests(args, exe)
79
80   appliPath = os.getenv("ABSOLUTE_APPLI_PATH")
81   if not appliPath:
82       raise SalomeContextException("Unable to find application path. Please check that the variable ABSOLUTE_APPLI_PATH is set.")
83
84   testPath = os.path.join(appliPath, __testSubDir)
85
86   command = ["ctest"] + args
87   p = subprocess.Popen(command, cwd=testPath)
88   p.communicate()
89   return p.returncode
90 #