Skip to content

Commit 9e43409

Browse files
committed
Only link to existing files.
- Make runtest.pl only create symlinks to existing files, to avoid that files generated by test cases escape their sandboxes. - Remove the name of the sandbox folder in paths when running tests with runtest.pl, since they contain the process id which changes each time.
1 parent 1af2088 commit 9e43409

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

OMCompiler/Compiler/Util/Testsuite.mo

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ algorithm
7878
newName := if Autoconf.os == "Windows_NT" then System.stringReplace(name, "\\", "/") else name;
7979
(i,strs) := System.regex(newName, "^(.*/Compiler/)?(.*/testsuite/(libraries-for-testing/.openmodelica/libraries/)?)?(.*/lib/omlibrary/)?(.*/build/)?(.*)$", 7, true, false);
8080
friendly := listGet(strs,i);
81+
82+
// Remove the name of any temporary folders used to sandbox a test case,
83+
// since they contain the process id which changes each time the test is run.
84+
(i,strs) := System.regex(friendly, "^(.*)(/[_[:alnum:]]*\\.mos?_temp[0-9]*)(.*)$", 4, true, false);
85+
if i == 4 then
86+
friendly := listGet(strs, 2) + listGet(strs, 4);
87+
end if;
8188
then
8289
friendly;
8390

testsuite/partest/runtest.pl

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,22 @@ sub make_link {
5555
# Depending on how the path is given we need to use different rules for how
5656
# the symlink should be created.
5757
for ($file) {
58-
if (/\.\.\/(\w*)\/package.mo/) { symlink("../" . $1, "../" . $1); }
59-
elsif (/\.\/(\w*)\/package.mo/) { symlink("../" . $1, $1); }
60-
elsif (/\.\.\/([\w-]*)\//) { symlink("../" . $1, "../" . $1); }
61-
elsif (/^(\w*)\/(.*)/) { symlink("../" . $1, $1); }
62-
elsif (/(.*)/) { symlink("../" . $1, $1); }
63-
else { symlink("../" . $file, $file); }
58+
if (/\.\.\/(\w*)\/package.mo/) { symlink_if_exists("../" . $1, "../" . $1); }
59+
elsif (/\.\/(\w*)\/package.mo/) { symlink_if_exists("../" . $1, $1); }
60+
elsif (/\.\.\/([\w-]*)\//) { symlink_if_exists("../" . $1, "../" . $1); }
61+
elsif (/^(\w*)\/(.*)/) { symlink_if_exists("../" . $1, $1); }
62+
elsif (/(.*)/) { symlink_if_exists("../" . $1, $1); }
63+
else { symlink_if_exists("../" . $file, $file); }
64+
}
65+
}
66+
67+
# Creates a symbolic link to a file, but only if the file exists.
68+
sub symlink_if_exists {
69+
my $src = shift;
70+
my $dst = shift;
71+
72+
if (-e $src) {
73+
symlink($src, $dst)
6474
}
6575
}
6676

@@ -146,7 +156,6 @@ sub enter_sandbox {
146156
if (/$stop_expr/) { last; }
147157
elsif (/setup_command.*\s(.*\.c)/) { make_link($1); }
148158
elsif (/depends: *([A-Za-z0-9_.-]*)/) { make_link($1); }
149-
elsif (/loadFile.*\(\"linearized_model\.mo\"\)/) {}
150159
elsif (/loadFile.*\(\"(.*)\"\)/) { make_link($1); }
151160
elsif (/runScript.*\(\"(.*)\"\)/) { make_link($1); }
152161
elsif (/importFMU.*\(\"(.*)\"\)/) { make_link($1); }

0 commit comments

Comments
 (0)