Linux GNU 11.4.0 Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 13 / 0 / 13
Functions: -% 0 / 1 / 1
Branches: 81.2% 13 / 0 / 16

OMCompiler/Compiler/Util/Testsuite.mo
Line Branch Exec Source
1 /*
2 * This file is part of OpenModelica.
3 *
4 * Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC),
5 * c/o Linköpings universitet, Department of Computer and Information Science,
6 * SE-58183 Linköping, Sweden.
7 *
8 * All rights reserved.
9 *
10 * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF AGPL VERSION 3 LICENSE OR
11 * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.8.
12 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
13 * RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GNU AGPL
14 * VERSION 3, ACCORDING TO RECIPIENTS CHOICE.
15 *
16 * The OpenModelica software and the OSMC (Open Source Modelica Consortium)
17 * Public License (OSMC-PL) are obtained from OSMC, either from the above
18 * address, from the URLs:
19 * http://www.openmodelica.org or
20 * https://github.com/OpenModelica/ or
21 * http://www.ida.liu.se/projects/OpenModelica,
22 * and in the OpenModelica distribution.
23 *
24 * GNU AGPL version 3 is obtained from:
25 * https://www.gnu.org/licenses/licenses.html#GPL
26 *
27 * This program is distributed WITHOUT ANY WARRANTY; without
28 * even the implied warranty of MERCHANTABILITY or FITNESS
29 * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
30 * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
31 *
32 * See the full OSMC Public License conditions for more details.
33 *
34 */
35
36 encapsulated package Testsuite
37 " file: Testsuite.mo
38 package: Testsuite
39 description: Functions used when running the testsuite."
40
41 protected
42
43 import Autoconf;
44 import Flags;
45 import System;
46
47 public
48
49 function isRunning
50 output Boolean runningTestsuite;
51 algorithm
52
3/4
✓ Branch 1 taken 110 times.
✓ Branch 2 taken 2748101 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 110 times.
2748211 runningTestsuite := not stringEq(Flags.getConfigString(Flags.RUNNING_TESTSUITE),"");
53 end isRunning;
54
55 public function getTempFilesFile
56 output String tempFile "File containing a list of files created by running this test so rtest can remove them after";
57 algorithm
58 42729 tempFile := Flags.getConfigString(Flags.RUNNING_TESTSUITE);
59 end getTempFilesFile;
60
61 public function friendly "Testsuite friendly name (start after testsuite/ or build/)"
62 input String name;
63 output String friendly;
64 algorithm
65 1400249 friendly := friendly2(isRunning(),name);
66 end friendly;
67
68 protected function friendly2
69 "Testsuite friendly name (start after testsuite/ or build/)"
70 input Boolean cond;
71 input String name;
72 output String friendly;
73 algorithm
74 friendly := match cond
75 local
76 Integer i;
77 list<String> strs;
78 String newName;
79
80 case true
81 algorithm
82 newName := if Autoconf.os == "Windows_NT" then System.stringReplace(name, "\\", "/") else name;
83 // build_cmake/install_cmake is what a CMake build out of the source tree
84 // produces; build/install_cmake is what the testsuite scripts and the CI
85 // jobs use. Strip either, or the paths a test prints are the ones on the
86 // machine that ran it.
87 1400235 (i,strs) := System.regex(newName, "^(.*/Compiler/)?(.*/testsuite/)?(.*/.openmodelica/libraries/)?(.*/lib/omlibrary/)?(.*/build(_cmake)?/(install_cmake/)?)?(.*)$", 9, true, false);
88 1400235 friendly := listGet(strs,i);
89
90 // Remove the name of any temporary folders used to sandbox a test case,
91 // since they contain the process id which changes each time the test is run.
92 1400235 (i,strs) := System.regex(friendly, "^(.*)(/[_[:alnum:]]*\\.mos?_temp[0-9]*)(.*)$", 4, true, false);
93
2/2
✓ Branch 0 taken 133 times.
✓ Branch 1 taken 1400102 times.
1400235 if i == 4 then
94 133 friendly := listGet(strs, 2) + listGet(strs, 4);
95 end if;
96 then
97 friendly;
98
99 else name;
100 end match;
101 end friendly2;
102
103 public function friendlyPath
104 "Adds ../ in front of a relative file path if we're running
105 the testsuite, to compensate for tests being sandboxed.
106 adrpo: only when running with partest the tests are sandboxed!"
107 input String inPath;
108 output String outPath;
109 algorithm
110 outPath := matchcontinue()
111 local
112 String path;
113
114 case ()
115 algorithm
116 // we're running the testsuite
117
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2221 times.
2221 true := isRunning();
118 // directory or file does not exist in this directory
119
2/2
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 2220 times.
2221 false := System.directoryExists(inPath);
120
2/2
✓ Branch 1 taken 2083 times.
✓ Branch 2 taken 137 times.
2220 false := System.regularFileExists(inPath);
121 // prefix the path
122 137 path := "../" + inPath;
123
3/4
✓ Branch 1 taken 137 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 136 times.
✓ Branch 5 taken 1 time.
137 true := System.directoryExists(path) or System.regularFileExists(path);
124 then
125 path;
126
127 else inPath;
128 end matchcontinue;
129 end friendlyPath;
130
131 annotation(__OpenModelica_Interface="util");
132 end Testsuite;
133