Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding system tests #399

Merged
merged 39 commits into from
Feb 11, 2025
Merged
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
122d4da
Refactor existing tests
Vahila Dec 24, 2024
95fabb5
Add system tests for Run MATLAB Command step
Vahila Dec 31, 2024
db9eb7c
Set up main.yml to run system tests
Vahila Dec 31, 2024
42a5d44
Update maven goal
Vahila Jan 2, 2025
60e88f8
Update version
Vahila Jan 2, 2025
9e9f57c
Update test set up
Vahila Jan 6, 2025
309b23d
Add tests for Matrix project
Vahila Jan 6, 2025
42730cc
Add tests for Run MATLAB Tests build step
Vahila Jan 6, 2025
b8921ad
Add tests for Artifacts generation
Vahila Jan 6, 2025
2ce87ae
Add tests for Customize Test Run
Vahila Jan 6, 2025
dc4aab5
Add tests for MATLAB Global Tool
Vahila Jan 6, 2025
21763ac
Add tests for Start Up options
Vahila Jan 6, 2025
62dcd17
Add test data
Vahila Jan 6, 2025
71a7d4c
Update main.yml
Vahila Jan 6, 2025
e96379a
Add tests for MPMinstall feature
Vahila Jan 8, 2025
1e85a8f
Update FilterTestData.zip
Vahila Jan 20, 2025
14276c4
Use Java 11 in set up
Vahila Jan 20, 2025
0140125
Add tests for Run MATLAB Build step
Vahila Jan 20, 2025
eba0e3f
Refactor tests
Vahila Jan 20, 2025
a52b697
Use mvn verify
Vahila Jan 20, 2025
53be112
Update failing test
Vahila Jan 20, 2025
e0d7182
Merge branch 'integ_tests' of https://github.com/mathworks/jenkins-ma…
Vahila Jan 20, 2025
bcb085d
Delete MPMInstallIT.java
Vahila Jan 20, 2025
de3da63
Refactor tests
Vahila Jan 20, 2025
c50d60a
Merge branch '2.16.0-SNAPSHOT-Qualification' into integ_tests
Vahila Jan 23, 2025
3df9592
Address review comments
Vahila Jan 30, 2025
7f26d59
Remove scratch file related tests
Vahila Feb 4, 2025
30e5eb0
Update indentation
Vahila Feb 4, 2025
0abb319
Remove sleep statements
Vahila Feb 4, 2025
191def8
Add verify goal for failsafe plugin
Vahila Feb 5, 2025
1dbb9b1
Update package
Vahila Feb 5, 2025
d69e644
Use teat data
Vahila Feb 5, 2025
87dd4e6
Update package name
Vahila Feb 5, 2025
004d7c9
Use maven in batch mode
Vahila Feb 5, 2025
b6fdbf7
Update failing test
Vahila Feb 5, 2025
35e5f1d
Remove unused function
Vahila Feb 5, 2025
5a6ab02
Delete azure-pipelines.yml
Vahila Feb 5, 2025
c73c73a
Remove timeout
Vahila Feb 11, 2025
b19294f
Merge remote-tracking branch 'origin/dev_main' into integ_tests
Vahila Feb 11, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add system tests for Run MATLAB Command step
Vahila committed Dec 31, 2024
commit 95fabb5c46fbc372e0e821c15ed21a58ccccb914
66 changes: 66 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -125,6 +125,36 @@
<version>11.0.24</version>
<scope>test</scope>
</dependency>

<!-- Dependencies for system tests -->
<!-- https://mvnrepository.com/artifact/com.jcabi/jcabi-xml -->
<dependency>
<groupId>com.jcabi</groupId>
<artifactId>jcabi-xml</artifactId>
<version>0.23.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jenkinsci.plugins/pipeline-model-definition -->
<dependency>
<groupId>org.jenkinsci.plugins</groupId>
<artifactId>pipeline-model-definition</artifactId>
<version>2.2218.v56d0cda_37c72</version>
</dependency>
<!-- Need unzip to add the files in pipeline workspace -->
<!-- https://mvnrepository.com/artifact/org.jenkins-ci.plugins/pipeline-utility-steps -->
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>pipeline-utility-steps</artifactId>
<version>2.7.1</version>
<scope>test</scope>
</dependency>
<!-- TODO: see if this is necessary Using for verifyCodeCoverage -->
<!-- https://mvnrepository.com/artifact/org.jenkins-ci.plugins/cobertura -->
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>cobertura</artifactId>
<version>1.16</version>
</dependency>

</dependencies>
<build>
<plugins>
@@ -215,6 +245,42 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19.1</version>
<executions>
<execution>
<id>integration-tests</id>
<goals>
<goal>integration-test</goal>
</goals>
<configuration>
<includes>
<include>**/*IT.java</include>
</includes>
<excludes>
<exclude>**/*Test.java</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<includes>
<include>**/*Test.java</include>
<include>**/*Tester.java</include>
</includes>
<excludes>
<exclude>**/*IT.java</exclude>>
</excludes>
</configuration>
</plugin>

</plugins>
<pluginManagement>
<plugins>
106 changes: 106 additions & 0 deletions src/test/java/com/mathworks/ci/systemTests/MatlabRootSetup.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package com.mathworks.ci.systemTests;

import com.mathworks.ci.MatlabInstallation;
import org.jvnet.hudson.test.JenkinsRule;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;

import static org.jvnet.hudson.test.JenkinsRule.NO_PROPERTIES;

public class MatlabRootSetup {
static String installedPath = "", binPath = "", MATLAB_ROOT="";
public static MatlabInstallation.DescriptorImpl matlabInstDescriptor;

public MatlabRootSetup(){
getBinPath();
}

/*
* This method returns the environment path needed to be set for DSL pipeline scripts
*/
public static String getEnvironmentDSL() {
getBinPath();
String environment = "environment { \n" +
"PATH = " + "\""+ binPath + "${PATH}"+ "\"" + "\n" +
"}";
return environment;
}

/*
* This method returns the environment path needed to be set for Scripted pipeline
*/
public static String getEnvironmentScriptedPipeline() {
getBinPath();
String environment = "";
environment = "env.PATH =" + '"' + binPath + "${env.PATH}" + '"';
return environment;
}

/*
* This method returns the MATLAB Root needed for Free Style or Multi Config projects
*/
public static String getMatlabRoot() {
getBinPath();
MATLAB_ROOT = installedPath;

System.out.println(MATLAB_ROOT);
return MATLAB_ROOT;
}

/*
* This method returns the bin path needed for scripted pipelines based on the testing platform -- Windows or Linux
* or Mac
*/
public static void getBinPath() {
installedPath = System.getenv("MATLAB_ROOT");
if (installedPath == null || installedPath.isEmpty()) {
installedPath = System.getProperty("MATLAB_ROOT");
if (installedPath == null || installedPath.isEmpty()) {
throw new IllegalStateException("MATLAB_ROOT is not set as an environment variable or system property.");
}
}

if (System.getProperty("os.name").startsWith("Win")) {
binPath = installedPath.replace("\\", "\\\\")+ "\\\\bin;";
} else {
binPath = installedPath + "/bin:";
}

// You may want to store or return binPath as needed
// System.out.println("Binary Path: " + binPath);
}

public static MatlabInstallation setMatlabInstallation(String name, String home, JenkinsRule jenkins) {
if(matlabInstDescriptor == null){
MatlabRootSetup.matlabInstDescriptor = jenkins.getInstance().getDescriptorByType(MatlabInstallation.DescriptorImpl.class);
}
MatlabInstallation[] prevInst = getMatlabInstallation();
ArrayList<MatlabInstallation> newInst = new ArrayList<>(Arrays.asList(prevInst));
MatlabInstallation newMatlabInstallation = new MatlabInstallation(name, home, NO_PROPERTIES);
newInst.add(newMatlabInstallation);
MatlabInstallation[] setInst = new MatlabInstallation[newInst.size()];
matlabInstDescriptor.setInstallations(newInst.toArray(setInst));
return newMatlabInstallation;
}

public static MatlabInstallation[] getMatlabInstallation(){
// static method to return all installations
return MatlabInstallation.getAll();
}

public static URL getRunMATLABTestsData() throws MalformedURLException {
File file = new File(System.getProperty("user.dir") + File.separator +"src" + File.separator + "test" + File.separator + "resources" + File.separator + "TestData" + File.separator + "FilterTestData.zip");
URL zipfile = file.toURI().toURL();
return zipfile;
}

public static URL getTestOnWarningData() throws MalformedURLException {
File file = new File(System.getProperty("user.dir") + File.separator +"src" + File.separator + "test" + File.separator + "resources" + File.separator + "TestData" + File.separator + "TestWithWarning.zip");
URL zipfile = file.toURI().toURL();
return zipfile;
}
}
78 changes: 78 additions & 0 deletions src/test/java/com/mathworks/ci/systemTests/RunMATLABCommandIT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.mathworks.ci.systemTests;

import com.mathworks.ci.*;
import com.mathworks.ci.freestyle.RunMatlabCommandBuilder;
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.model.Result;
import org.junit.*;
import org.junit.rules.Timeout;
import org.jvnet.hudson.test.JenkinsRule;
import java.io.IOException;


public class RunMATLABCommandIT {

private FreeStyleProject project;
private UseMatlabVersionBuildWrapper buildWrapper;
private RunMatlabCommandBuilder scriptBuilder;

@Rule
public Timeout timeout = Timeout.seconds(0);

@Rule
public JenkinsRule jenkins = new JenkinsRule();

@BeforeClass
public static void checkMatlabRoot() {
// Check if the MATLAB_ROOT environment variable is defined
String matlabRoot = System.getenv("MATLAB_ROOT");
Assume.assumeTrue("Not running tests as MATLAB_ROOT environment variable is not defined", matlabRoot != null && !matlabRoot.isEmpty());
}

@Before
public void testSetup() throws IOException {
this.project = jenkins.createFreeStyleProject();
this.scriptBuilder = new RunMatlabCommandBuilder();
this.buildWrapper = new UseMatlabVersionBuildWrapper();
}

@After
public void testTearDown() {
this.project = null;
this.scriptBuilder = null;
}

/*
* Test to verify if Build FAILS when matlab command fails
*/

@Test
public void verifyBuildFailureWhenMatlabCommandFails() throws Exception {
this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), MatlabRootSetup.getMatlabRoot()));
project.getBuildWrappersList().add(this.buildWrapper);
RunMatlabCommandBuilder tester =
new RunMatlabCommandBuilder();
tester.setMatlabCommand("apple");
project.getBuildersList().add(tester);
FreeStyleBuild build = project.scheduleBuild2(0).get();
jenkins.assertLogContains("apple", build);
jenkins.assertBuildStatus(Result.FAILURE, build);
}


/* Test To Verify if Build passes when matlab command passes
*/
@Test
public void verifyBuildPassesWhenMatlabCommandPasses() throws Exception {
this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), MatlabRootSetup.getMatlabRoot()));
project.getBuildWrappersList().add(this.buildWrapper);
RunMatlabCommandBuilder tester =
new RunMatlabCommandBuilder();
tester.setMatlabCommand("disp 'apple'");
project.getBuildersList().add(tester);
FreeStyleBuild build = project.scheduleBuild2(0).get();
jenkins.assertBuildStatus(Result.SUCCESS, build);
jenkins.assertLogContains("apple", build);
}
}
30 changes: 30 additions & 0 deletions src/test/java/com/mathworks/ci/systemTests/TestData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.mathworks.ci.systemTests;

import java.io.InputStream;
import java.util.Properties;

public class TestData {

static String value="";
static InputStream inputStream;

public static String getPropValues(String key){
try{
Properties prop=new Properties();

inputStream=TestData.class.getClassLoader().getResourceAsStream("testdataconfig.properties");
if(inputStream!=null){
prop.load(inputStream);
} else {
System.out.println("NOT ABLE TO FIND testdataconfig.properties FILE");
}
value=prop.getProperty(key);
}
catch(Exception e){
System.out.println(e);
}

return value;
}

}
16 changes: 16 additions & 0 deletions src/test/resources/testdataconfig.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
matlab.command=pwd
matlab.invalid.command=apple
matlab.invalid.root.path = fake/matlab/root/path

pdftestreport.file.path=matlabTestArtifacts/testreport.pdf
taptestresult.file.path=matlabTestArtifacts/taptestresults.tap
junit.file.path=matlabTestArtifacts/junittestresults.xml
stmresults.file.path=matlabTestArtifacts/simulinktestresults.mldatx
cobertura.file.path=matlabTestArtifacts/cobertura.xml
modelcoverage.file.path=matlabTestArtifacts/coberturamodelcoverage.xml

matlab.windows.installed.path = C:\\Program Files\\MATLAB\\R2023b
matlab.linux.installed.path = /usr/local/MATLAB/R2023b
matlab.mac.installed.path = /mathworks/devel/relarchive/R2021b/executables/GR/maci64/MATLAB_R2021b.app
matlab.version = R2023b
matlab.matrix.version = R2023a