Skip to content
This repository was archived by the owner on Mar 27, 2025. It is now read-only.

Commit 71b16bd

Browse files
authored
Merge pull request #206 from mathworks/2.7.1-SNAPSHOT-Qualification
2.7.1 snapshot qualification
2 parents c85bd64 + 79de63c commit 71b16bd

File tree

9 files changed

+76
-16
lines changed

9 files changed

+76
-16
lines changed

azure-pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
strategy:
77
matrix:
88
linux:
9-
imageName: 'ubuntu-16.04'
9+
imageName: 'ubuntu-18.04'
1010
mac:
1111
imageName: 'macOS-10.15'
1212
windows:

src/main/java/com/mathworks/ci/MatlabBuild.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,9 @@ default void prepareTmpFldr(FilePath tmpFldr, String runnerScript) throws IOExce
9999
zipFileLocation.unzip(tmpFldr);
100100
}
101101

102-
default String getRunnerScript(String script, String params) {
102+
default String getRunnerScript(String script, String params, String uniqueTmpFldrName) {
103103
script = script.replace("${PARAMS}", params);
104+
script = script.replaceAll("\\$\\{TMPDIR\\}", uniqueTmpFldrName);
104105
return script;
105106
}
106107

src/main/java/com/mathworks/ci/MatlabBuilderConstants.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ public class MatlabBuilderConstants {
4040
// MATLAB runner script
4141
static final String TEST_RUNNER_SCRIPT = "testScript = genscript(${PARAMS});\n" + "\n"
4242
+ "disp('Running MATLAB script with content:');\n"
43-
+ "disp(strtrim(testScript.writeToText()));\n"
44-
+ "fprintf('___________________________________\\n\\n');\n" + "run(testScript);\n" + "";
43+
+ "disp(strtrim(testScript.Contents));\n"
44+
+ "runnerFile = testScript.writeToFile(fullfile(tempname,'runnerScript.m'));\n"
45+
+ "[tmpDir,scriptName,ext] = fileparts(runnerFile);"
46+
+ "addpath(tmpDir);\n"
47+
+ "rmdir('.matlab/${TMPDIR}/+scriptgen', 's');\n"
48+
+ "delete('.matlab/${TMPDIR}/genscript.m');\n"
49+
+ "fprintf('___________________________________\\n\\n');\n";
4550
}

src/main/java/com/mathworks/ci/MatlabRunTestsStepExecution.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,26 +60,30 @@ public void stop(Throwable cause) throws Exception {
6060

6161
private int execMatlabCommand(FilePath workspace, Launcher launcher,
6262
TaskListener listener, EnvVars envVars) throws IOException, InterruptedException {
63-
final String uniqueTmpFldrName = getUniqueNameForRunnerFile();
63+
final String uniqueMatlabResourceFldr = getUniqueNameForRunnerFile();
6464
try {
6565
FilePath genScriptLocation =
66-
getFilePathForUniqueFolder(launcher, uniqueTmpFldrName, workspace);
66+
getFilePathForUniqueFolder(launcher, uniqueMatlabResourceFldr, workspace);
6767
final String cmdPrefix =
6868
"addpath('" + genScriptLocation.getRemote().replaceAll("'", "''") + "'); ";
6969
final String matlabScriptName = getValidMatlabFileName(genScriptLocation.getBaseName());
7070

71-
ProcStarter matlabLauncher = getProcessToRunMatlabCommand(workspace, launcher, listener,
72-
envVars, cmdPrefix + matlabScriptName, uniqueTmpFldrName);
71+
ProcStarter matlabLauncher =
72+
getProcessToRunMatlabCommand(workspace, launcher, listener, envVars,
73+
cmdPrefix + matlabScriptName + ",delete('.matlab/"
74+
+ genScriptLocation.getBaseName() + "/" + matlabScriptName
75+
+ ".m'),runnerScript,rmdir(tmpDir,'s')",
76+
uniqueMatlabResourceFldr);
7377

7478
// prepare temp folder by coping genscript package and writing runner script.
7579
prepareTmpFldr(genScriptLocation,
76-
getRunnerScript(MatlabBuilderConstants.TEST_RUNNER_SCRIPT, envVars.expand(getCommandArgs())));
80+
getRunnerScript(MatlabBuilderConstants.TEST_RUNNER_SCRIPT, envVars.expand(getCommandArgs()),uniqueMatlabResourceFldr));
7781

7882
return matlabLauncher.pwd(workspace).join();
7983
} finally {
8084
// Cleanup the runner File from tmp directory
8185
final FilePath matlabRunnerScript =
82-
getFilePathForUniqueFolder(launcher, uniqueTmpFldrName, workspace);
86+
getFilePathForUniqueFolder(launcher, uniqueMatlabResourceFldr, workspace);
8387
if (matlabRunnerScript.exists()) {
8488
matlabRunnerScript.deleteRecursive();
8589
}

src/main/java/com/mathworks/ci/RunMatlabTestsBuilder.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ private int execMatlabCommand(FilePath workspace, Launcher launcher,
282282

283283
// copy genscript package in temp folder and write a runner script.
284284
prepareTmpFldr(genScriptLocation, getRunnerScript(
285-
MatlabBuilderConstants.TEST_RUNNER_SCRIPT, envVars.expand(getInputArguments())));
285+
MatlabBuilderConstants.TEST_RUNNER_SCRIPT, envVars.expand(getInputArguments()),uniqueTmpFldrName));
286286

287287
return matlabLauncher.pwd(workspace).join();
288288
} catch (Exception e) {
@@ -301,7 +301,8 @@ private int execMatlabCommand(FilePath workspace, Launcher launcher,
301301
public String constructCommandForTest(FilePath scriptPath) {
302302
final String matlabScriptName = getValidMatlabFileName(scriptPath.getBaseName());
303303
final String runCommand = "addpath('" + scriptPath.getRemote().replaceAll("'", "''")
304-
+ "'); " + matlabScriptName;
304+
+ "'); " + matlabScriptName + ",delete('.matlab/" + scriptPath.getBaseName() + "/"
305+
+ matlabScriptName + ".m'),runnerScript,rmdir(tmpDir,'s')";
305306
return runCommand;
306307
}
307308

src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public void setUp(Context context, Run<?, ?> build, FilePath workspace, Launcher
182182
setEnv(initialEnvironment);
183183

184184
FilePath matlabExecutablePath = new FilePath(launcher.getChannel(),
185-
getNodeSpecificMatlab(Computer.currentComputer(), listener) + "/bin/" + getNodeSpecificExecutable(launcher));
185+
getNodeSpecificMatlab(Computer.currentComputer(), listener) + getNodeSpecificExecutable(launcher));
186186

187187
if (!matlabExecutablePath.exists()) {
188188
throw new MatlabNotFoundError(Message.getValue("matlab.not.found.error"));
@@ -196,6 +196,6 @@ public void setUp(Context context, Run<?, ?> build, FilePath workspace, Launcher
196196
}
197197

198198
private String getNodeSpecificExecutable(Launcher launcher) {
199-
return (launcher.isUnix()) ? "matlab" : "matlab.exe";
199+
return (launcher.isUnix()) ? "/bin/matlab" : "\\bin\\matlab.exe";
200200
}
201201
}

src/main/java/com/mathworks/ci/Utilities.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ public static void addMatlabToEnvPathFrmAxis(Computer cmp, TaskListener listener
4545
}
4646

4747
String matlabExecutablePath = getNodeSpecificHome(name,
48-
cmp.getNode(), listener, env) + "/bin";
48+
cmp.getNode(), listener, env) + ((Boolean.TRUE.equals(cmp.isUnix()))?"/bin" : "\\bin");
4949
env.put("PATH+matlabroot", matlabExecutablePath);
50+
5051
// Specify which MATLAB was added to path.
5152
listener.getLogger().println("\n" + String.format(Message.getValue("matlab.added.to.path.from"), matlabExecutablePath) + "\n");
5253
}

src/test/java/com/mathworks/ci/RunMatlabTestsBuilderTest.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ public void verifyMATLABscratchFileGenerated() throws Exception {
484484
project.getBuildWrappersList().add(this.buildWrapper);
485485
project.getBuildersList().add(testBuilder);
486486
FreeStyleBuild build = project.scheduleBuild2(0).get();
487-
File matlabRunner = new File(build.getWorkspace() + File.separator + "runMatlabTests.m");
487+
File matlabRunner = new File(build.getWorkspace() + File.separator + "runnerScript.m");
488488
Assert.assertFalse(matlabRunner.exists());
489489
}
490490

@@ -500,4 +500,28 @@ public void verifyMATLABfolderGenerated() throws Exception {
500500
File matlabRunner = new File(build.getWorkspace() + File.separator + ".matlab");
501501
Assert.assertTrue(matlabRunner.exists());
502502
}
503+
504+
/*
505+
* Test to verify if runner script is deleted from .matlab folder during MATLAB call
506+
*/
507+
@Test
508+
public void verifyRunnerScriptDeleted() throws Exception {
509+
this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b")));
510+
project.getBuildWrappersList().add(this.buildWrapper);
511+
project.getBuildersList().add(testBuilder);
512+
FreeStyleBuild build = project.scheduleBuild2(0).get();
513+
jenkins.assertLogContains("delete('.matlab/", build);
514+
}
515+
516+
/*
517+
* Test to verify if runner script is deleted from system temp directory during MATLAB call
518+
*/
519+
@Test
520+
public void verifySystemTempDirDeleted() throws Exception {
521+
this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b")));
522+
project.getBuildWrappersList().add(this.buildWrapper);
523+
project.getBuildersList().add(testBuilder);
524+
FreeStyleBuild build = project.scheduleBuild2(0).get();
525+
jenkins.assertLogContains("rmdir(tmpDir,'s')", build);
526+
}
503527
}

src/test/java/com/mathworks/ci/RunMatlabTestsStepTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,30 @@ public void verifyTestSelectByFolder () throws Exception {
163163
j.assertBuildStatusSuccess(build);
164164
}
165165

166+
/*
167+
* Verify runner script deleted from .matlab folder during MATLAB call
168+
*/
169+
170+
@Test
171+
public void verifyRunnerScriptDeletedFromWorkSpace() throws Exception {
172+
project.setDefinition(new CpsFlowDefinition(
173+
"node {runMATLABTests(testResultsPDF:'myresult/result.pdf')}", true));
174+
WorkflowRun build = project.scheduleBuild2(0).get();
175+
j.assertLogContains("delete('.matlab/", build);
176+
}
177+
178+
/*
179+
* Verify runner script deleted from system Tmp directory during MATLAB call
180+
*/
181+
182+
@Test
183+
public void verifySystemTmpDirDeleted() throws Exception {
184+
project.setDefinition(new CpsFlowDefinition(
185+
"node {runMATLABTests(testResultsPDF:'myresult/result.pdf')}", true));
186+
WorkflowRun build = project.scheduleBuild2(0).get();
187+
j.assertLogContains("rmdir(tmpDir,'s')", build);
188+
}
189+
166190
/*@Integ Test
167191
* Verify default command options for test Filter using selectByTag option
168192
*/

0 commit comments

Comments
 (0)