Commit a52ab93d by Michael Schmid

switched to java 11 and jacoco, small changes

parent 4e934ca9
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
<attribute name="test" value="true"/> <attribute name="test" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
......
...@@ -10,12 +10,17 @@ ...@@ -10,12 +10,17 @@
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.target>11</maven.compiler.target>
</properties> </properties>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.ant</artifactId>
<version>0.8.5</version>
</dependency>
<dependency>
<groupId>org.jgrapht</groupId> <groupId>org.jgrapht</groupId>
<artifactId>jgrapht-ext</artifactId> <artifactId>jgrapht-ext</artifactId>
<version>1.0.1</version> <version>1.0.1</version>
...@@ -26,12 +31,6 @@ ...@@ -26,12 +31,6 @@
<version>1.0.1</version> <version>1.0.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>net.sourceforge.cobertura</groupId>
<artifactId>cobertura</artifactId>
<version>2.1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId> <groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId> <artifactId>commons-math3</artifactId>
<version>3.2</version> <version>3.2</version>
...@@ -86,6 +85,27 @@ ...@@ -86,6 +85,27 @@
<build> <build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins> <plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.5</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<!-- attached to Maven test phase -->
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle --> <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin> <plugin>
<artifactId>maven-clean-plugin</artifactId> <artifactId>maven-clean-plugin</artifactId>
...@@ -99,10 +119,16 @@ ...@@ -99,10 +119,16 @@
<plugin> <plugin>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version> <version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin> </plugin>
<plugin> <plugin>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version> <version>2.22.1</version>
<configuration>
<argLine>${argLine}</argLine>
</configuration>
</plugin> </plugin>
<plugin> <plugin>
<artifactId>maven-jar-plugin</artifactId> <artifactId>maven-jar-plugin</artifactId>
......
...@@ -6,7 +6,6 @@ import mvd.jester.model.DagTask; ...@@ -6,7 +6,6 @@ import mvd.jester.model.DagTask;
import mvd.jester.model.SystemSetup; import mvd.jester.model.SystemSetup;
import mvd.jester.tests.AbstractTest; import mvd.jester.tests.AbstractTest;
import mvd.jester.tests.FonsecaNelis; import mvd.jester.tests.FonsecaNelis;
import mvd.jester.tests.MelaniButtazzo;
import mvd.jester.tests.SchmidMottok; import mvd.jester.tests.SchmidMottok;
...@@ -21,8 +20,8 @@ public class App { ...@@ -21,8 +20,8 @@ public class App {
new SystemSetup.DagTaskBuilder().setNumberOfProcessors(p); new SystemSetup.DagTaskBuilder().setNumberOfProcessors(p);
TestEnvironment te = new TestEnvironment(); TestEnvironment te = new TestEnvironment();
Set<ResultCollector<AbstractTest<DagTask>>> tests = te.registerTests( Set<ResultCollector<AbstractTest<DagTask>>> tests = te.registerTests(Arrays
Arrays.asList(new SchmidMottok(p), /* new MelaniButtazzo(p), */ new FonsecaNelis(p))); .asList(new SchmidMottok(p), /* new MelaniButtazzo(p), */ new FonsecaNelis(p)));
te.runExperiments(builder, tests, p, 500); te.runExperiments(builder, tests, p, 500);
} }
......
...@@ -37,9 +37,6 @@ public class ResultLogger { ...@@ -37,9 +37,6 @@ public class ResultLogger {
public <T extends Task> void logTests(Set<ResultCollector<AbstractTest<T>>> results) { public <T extends Task> void logTests(Set<ResultCollector<AbstractTest<T>>> results) {
if (!results.isEmpty()) { if (!results.isEmpty()) {
logFeasibility(results, "test"); logFeasibility(results, "test");
// logFeasibilityRatio(results, "test");
// logTaskRatio(results, "test");
// logFeasibilityLevel(results, "test");
} }
} }
......
...@@ -84,7 +84,9 @@ public class TestEnvironment { ...@@ -84,7 +84,9 @@ public class TestEnvironment {
long checkedTasksets = 0; long checkedTasksets = 0;
long numberOfTaskSets = numberOfProcessors * 4 * numberOfTaskSetsPerUtil; long numberOfTaskSets = numberOfProcessors * 4 * numberOfTaskSetsPerUtil;
// create LoggerFile here
for (double util = 1; util <= numberOfProcessors; util += 0.25) { for (double util = 1; util <= numberOfProcessors; util += 0.25) {
// new Result set here
for (int i = 0; i < numberOfTaskSetsPerUtil; ++i) { for (int i = 0; i < numberOfTaskSetsPerUtil; ++i) {
Set<DagTask> taskSet = builder.generateTaskSet(util); Set<DagTask> taskSet = builder.generateTaskSet(util);
...@@ -104,6 +106,7 @@ public class TestEnvironment { ...@@ -104,6 +106,7 @@ public class TestEnvironment {
} }
checkedTasksets++; checkedTasksets++;
} }
// write Result line to LoggerFile
} }
System.out.println(""); System.out.println("");
ResultLogger resultLogger = new ResultLogger(numberOfProcessors); ResultLogger resultLogger = new ResultLogger(numberOfProcessors);
......
package mvd.jester.model; package mvd.jester.model;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.LinkedList; import java.util.LinkedList;
...@@ -189,12 +188,6 @@ public class DagTask implements Task { ...@@ -189,12 +188,6 @@ public class DagTask implements Task {
forkNodes.add(j); forkNodes.add(j);
} }
} }
for (Job j : forkNodes) {
if (jobDag.outDegreeOf(j) <= 1) {
int test = 3;
}
}
} }
public static DirectedAcyclicGraph<Job, DefaultEdge> createNFJGraph( public static DirectedAcyclicGraph<Job, DefaultEdge> createNFJGraph(
...@@ -304,9 +297,6 @@ public class DagTask implements Task { ...@@ -304,9 +297,6 @@ public class DagTask implements Task {
Node<Job> successorParent = parContinuationNode; Node<Job> successorParent = parContinuationNode;
List<Job> successors = Graphs.successorListOf(jobDag, currentJob); List<Job> successors = Graphs.successorListOf(jobDag, currentJob);
if (successors.size() == 1) {
int test = 3;
}
// create leftSide of joinNode // create leftSide of joinNode
for (int i = 0; i < successors.size(); ++i) { for (int i = 0; i < successors.size(); ++i) {
Job succ = successors.get(i); Job succ = successors.get(i);
...@@ -441,10 +431,6 @@ public class DagTask implements Task { ...@@ -441,10 +431,6 @@ public class DagTask implements Task {
private static GraphEndPoints traverseNodes(DirectedAcyclicGraph<Job, DefaultEdge> jobDag, private static GraphEndPoints traverseNodes(DirectedAcyclicGraph<Job, DefaultEdge> jobDag,
Node<Job> node) { Node<Job> node) {
if (node.getNodeType() != NodeType.LEAF
&& (node.getLeftNode() == null || node.getRightNode() == null)) {
int test = 3;
}
switch (node.getNodeType()) { switch (node.getNodeType()) {
case LEAF: { case LEAF: {
Job j = node.getObject(); Job j = node.getObject();
...@@ -463,7 +449,6 @@ public class DagTask implements Task { ...@@ -463,7 +449,6 @@ public class DagTask implements Task {
try { try {
jobDag.addDagEdge(l, r); jobDag.addDagEdge(l, r);
} catch (Exception e) { } catch (Exception e) {
int test = 3;
} }
} }
} }
...@@ -494,10 +479,5 @@ public class DagTask implements Task { ...@@ -494,10 +479,5 @@ public class DagTask implements Task {
this.right = right; this.right = right;
} }
} }
private enum TraversalOrder {
LEFT, RIGHT
}
} }
} }
...@@ -6,12 +6,10 @@ import java.util.Collections; ...@@ -6,12 +6,10 @@ import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
import javax.print.attribute.standard.JobName;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.google.common.math.LongMath; import com.google.common.math.LongMath;
...@@ -110,10 +108,6 @@ public class FonsecaNelis extends AbstractTest<DagTask> { ...@@ -110,10 +108,6 @@ public class FonsecaNelis extends AbstractTest<DagTask> {
} }
private Node<TreeJob> transformNode(Node<TreeJob> parent, Node<Job> node) { private Node<TreeJob> transformNode(Node<TreeJob> parent, Node<Job> node) {
if (node.getNodeType() != NodeType.LEAF
&& (node.getLeftNode() == null || node.getRightNode() == null)) {
int test = 3;
}
if (node.getNodeType().equals(NodeType.LEAF)) { if (node.getNodeType().equals(NodeType.LEAF)) {
return new Node<TreeJob>(parent, new TreeJob(node.getObject())); return new Node<TreeJob>(parent, new TreeJob(node.getObject()));
} else { } else {
......
package mvd.jester.info; package mvd.jester.info;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import java.util.HashSet; import java.util.HashSet;
......
...@@ -59,8 +59,8 @@ public class TestDagUtils { ...@@ -59,8 +59,8 @@ public class TestDagUtils {
DirectedAcyclicGraph<Job, DefaultEdge> jobDagFromTree = DirectedAcyclicGraph<Job, DefaultEdge> jobDagFromTree =
DagUtils.createNFJfromDecompositionTree(tree); DagUtils.createNFJfromDecompositionTree(tree);
assertTrue(jobDag.vertexSet().equals(nfjJobDag.vertexSet())); assertTrue(jobDag.vertexSet().size() == nfjJobDag.vertexSet().size());
assertTrue(jobDag.vertexSet().equals(jobDagFromTree.vertexSet())); assertTrue(jobDag.vertexSet().size() == jobDagFromTree.vertexSet().size());
assertTrue(jobDagFromTree.edgeSet().size() == nfjJobDag.edgeSet().size()); assertTrue(jobDagFromTree.edgeSet().size() == nfjJobDag.edgeSet().size());
......
...@@ -7,23 +7,18 @@ import java.util.concurrent.ThreadLocalRandom; ...@@ -7,23 +7,18 @@ import java.util.concurrent.ThreadLocalRandom;
import com.google.common.math.DoubleMath; import com.google.common.math.DoubleMath;
import org.jgrapht.experimental.dag.DirectedAcyclicGraph; import org.jgrapht.experimental.dag.DirectedAcyclicGraph;
import org.jgrapht.graph.DefaultEdge; import org.jgrapht.graph.DefaultEdge;
import org.junit.Rule;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.rules.TemporaryFolder;
import mvd.jester.model.SystemSetup.DagTaskBuilder; import mvd.jester.model.SystemSetup.DagTaskBuilder;
public class TestSystemSetup { public class TestSystemSetup {
@Rule
public TemporaryFolder tf = new TemporaryFolder();
private static final int NUMBER_OF_RUNS = 1000; private static final int NUMBER_OF_RUNS = 1000;
@Test @Test
@DisplayName("Check if randomly generated task parameters lie within the specified ranges.") @DisplayName("Check if randomly generated task parameters lie within the specified ranges.")
public void testRandomTaskSetGeneration() { public void testRandomTaskSetGeneration() {
for (int i = 0; i < NUMBER_OF_RUNS; ++i) { for (int i = 0; i < NUMBER_OF_RUNS; ++i) {
long numberOfProcessors = ThreadLocalRandom.current().nextLong(2, 8); long numberOfProcessors = ThreadLocalRandom.current().nextLong(2, 8);
SystemSetup.SynchronousTaskBuilder systemSetupBuilder = SystemSetup.SynchronousTaskBuilder systemSetupBuilder =
......
package mvd.jester.simulator.dynamicforkjoin; // package mvd.jester.simulator.dynamicforkjoin;
import static org.junit.jupiter.api.Assertions.assertFalse; // import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue; // import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock; // import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; // import static org.mockito.Mockito.when;
import java.util.Optional; // import java.util.Optional;
import java.util.concurrent.ThreadLocalRandom; // import java.util.concurrent.ThreadLocalRandom;
import org.junit.jupiter.api.DisplayName; // import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test; // import org.junit.jupiter.api.Test;
import mvd.jester.model.Segment; // import mvd.jester.model.Segment;
import mvd.jester.simulator.internals.JobContextInterface; // import mvd.jester.simulator.internals.JobContextInterface;
import mvd.jester.simulator.internals.ProcessorContext; // import mvd.jester.simulator.internals.ProcessorContext;
import mvd.jester.simulator.internals.dynamicforkjoin.JobContext; // import mvd.jester.simulator.internals.dynamicforkjoin.JobContext;
import mvd.jester.simulator.internals.dynamicforkjoin.SegmentContext; // import mvd.jester.simulator.internals.dynamicforkjoin.SegmentContext;
import mvd.jester.simulator.internals.dynamicforkjoin.TaskContext; // import mvd.jester.simulator.internals.dynamicforkjoin.TaskContext;
import mvd.jester.simulator.internals.dynamicforkjoin.TaskletContext; // import mvd.jester.simulator.internals.dynamicforkjoin.TaskletContext;
/** // /**
* TestSegmentContext // * TestSegmentContext
*/ // */
public class TestSegmentContext { // public class TestSegmentContext {
@Test // @Test
@DisplayName("Check if segment returns the jobs correctly.") // @DisplayName("Check if segment returns the jobs correctly.")
void testGetNextJob() { // void testGetNextJob() {
for (int run = 0; run < 100; ++run) { // for (int run = 0; run < 100; ++run) {
long numberOfJobs = ThreadLocalRandom.current().nextLong(1, 10); // long numberOfJobs = ThreadLocalRandom.current().nextLong(1, 10);
long jobWcet = ThreadLocalRandom.current().nextLong(20, 50); // long jobWcet = ThreadLocalRandom.current().nextLong(20, 50);
Segment s = mock(Segment.class); // Segment s = mock(Segment.class);
when(s.getNumberOfJobs()).thenReturn(numberOfJobs); // when(s.getNumberOfJobs()).thenReturn(numberOfJobs);
when(s.getJobWcet()).thenReturn(jobWcet); // when(s.getJobWcet()).thenReturn(jobWcet);
TaskContext tc = mock(TaskContext.class); // TaskContext tc = mock(TaskContext.class);
SegmentContext sc = new SegmentContext(tc, s, 4); // SegmentContext sc = new SegmentContext(tc, s, 4);
Optional<JobContextInterface> job = Optional.empty(); // Optional<JobContextInterface> job = Optional.empty();
when(tc.acceptNotification(jobWcet - 1)).thenReturn(Optional.empty()); // when(tc.acceptNotification(jobWcet - 1)).thenReturn(Optional.empty());
long numJobs = numberOfJobs > 4 ? 4 : numberOfJobs; // long numJobs = numberOfJobs > 4 ? 4 : numberOfJobs;
for (int i = 0; i < numJobs; ++i) { // for (int i = 0; i < numJobs; ++i) {
job = sc.getNextJob(); // job = sc.getNextJob();
assertTrue(job.isPresent()); // assertTrue(job.isPresent());
job.get().setCurrentProcessor(new ProcessorContext(i)); // job.get().setCurrentProcessor(new ProcessorContext(i));
} // }
assertFalse(sc.getNextJob().isPresent()); // assertFalse(sc.getNextJob().isPresent());
sc = new SegmentContext(tc, s, 4); // sc = new SegmentContext(tc, s, 4);
job = sc.getNextJob(); // job = sc.getNextJob();
assertTrue(job.isPresent()); // assertTrue(job.isPresent());
job.get().setCurrentProcessor(new ProcessorContext(0)); // job.get().setCurrentProcessor(new ProcessorContext(0));
for (int i = 0; i < jobWcet * numberOfJobs; ++i) { // for (int i = 0; i < jobWcet * numberOfJobs; ++i) {
job.get().updateExecution(i); // job.get().updateExecution(i);
} // }
assertFalse(sc.getNextJob().isPresent()); // assertFalse(sc.getNextJob().isPresent());
} // }
} // }
@Test // @Test
@DisplayName("Check if SegmentContext returns the correct amount of tasklets.") // @DisplayName("Check if SegmentContext returns the correct amount of tasklets.")
void testGetNextTasklet() { // void testGetNextTasklet() {
for (int run = 0; run < 100; ++run) { // for (int run = 0; run < 100; ++run) {
long numberOfJobs = ThreadLocalRandom.current().nextLong(1, 10); // long numberOfJobs = ThreadLocalRandom.current().nextLong(1, 10);
long jobWcet = ThreadLocalRandom.current().nextLong(20, 50); // long jobWcet = ThreadLocalRandom.current().nextLong(20, 50);
Segment s = mock(Segment.class); // Segment s = mock(Segment.class);
when(s.getNumberOfJobs()).thenReturn(numberOfJobs); // when(s.getNumberOfJobs()).thenReturn(numberOfJobs);
when(s.getJobWcet()).thenReturn(jobWcet); // when(s.getJobWcet()).thenReturn(jobWcet);
TaskContext tc = mock(TaskContext.class); // TaskContext tc = mock(TaskContext.class);
when(tc.acceptNotification(jobWcet - 1)).thenReturn(Optional.empty()); // when(tc.acceptNotification(jobWcet - 1)).thenReturn(Optional.empty());
SegmentContext sc = new SegmentContext(tc, s, 4); // SegmentContext sc = new SegmentContext(tc, s, 4);
for (int i = 0; i < jobWcet; ++i) { // for (int i = 0; i < jobWcet; ++i) {
Optional<TaskletContext> tci = sc.getNextTasklet(); // Optional<TaskletContext> tci = sc.getNextTasklet();
assertTrue(tci.isPresent()); // assertTrue(tci.isPresent());
tci.get().setCurrentJob(mock(JobContext.class)); // tci.get().setCurrentJob(mock(JobContext.class));
} // }
assertFalse(sc.getNextTasklet().isPresent()); // assertFalse(sc.getNextTasklet().isPresent());
sc = new SegmentContext(tc, s, 4); // sc = new SegmentContext(tc, s, 4);
for (int i = 0; i < jobWcet; ++i) { // for (int i = 0; i < jobWcet; ++i) {
Optional<TaskletContext> tasklet = sc.getNextTasklet(); // Optional<TaskletContext> tasklet = sc.getNextTasklet();
assertTrue(tasklet.isPresent()); // assertTrue(tasklet.isPresent());
tasklet.get().setCurrentJob(mock(JobContext.class)); // tasklet.get().setCurrentJob(mock(JobContext.class));
for (int j = 0; j < numberOfJobs; ++j) { // for (int j = 0; j < numberOfJobs; ++j) {
tasklet.get().updateExecution(j); // tasklet.get().updateExecution(j);
} // }
} // }
assertFalse(sc.getNextTasklet().isPresent()); // assertFalse(sc.getNextTasklet().isPresent());
} // }
} // }
} // }
package mvd.jester.simulator.dynamicforkjoin; // package mvd.jester.simulator.dynamicforkjoin;
import static org.junit.jupiter.api.Assertions.assertFalse; // import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue; // import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.ArrayList; // import java.util.ArrayList;
import java.util.LinkedHashSet; // import java.util.LinkedHashSet;
import java.util.Optional; // import java.util.Optional;
import java.util.Set; // import java.util.Set;
import java.util.concurrent.ThreadLocalRandom; // import java.util.concurrent.ThreadLocalRandom;
import org.junit.jupiter.api.DisplayName; // import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test; // import org.junit.jupiter.api.Test;
import mvd.jester.model.Segment; // import mvd.jester.model.Segment;
import mvd.jester.model.SynchronousTask; // import mvd.jester.model.SynchronousTask;
import mvd.jester.simulator.internals.JobContextInterface; // import mvd.jester.simulator.internals.JobContextInterface;
import mvd.jester.simulator.internals.ProcessorContext; // import mvd.jester.simulator.internals.ProcessorContext;
import mvd.jester.simulator.internals.TaskContextInterface; // import mvd.jester.simulator.internals.TaskContextInterface;
import mvd.jester.simulator.internals.dynamicforkjoin.TaskContext; // import mvd.jester.simulator.internals.dynamicforkjoin.TaskContext;
/** // /**
* TestTaskContext // * TestTaskContext
*/ // */
public class TestTaskContext { // public class TestTaskContext {
@Test // @Test
@DisplayName("Check if TaskContext accepts its notification correctly.") // @DisplayName("Check if TaskContext accepts its notification correctly.")
public void testAcceptNotification() { // public void testAcceptNotification() {
for (int run = 0; run < 100; ++run) { // for (int run = 0; run < 100; ++run) {
long numberOfJobs = ThreadLocalRandom.current().nextLong(1, 10); // long numberOfJobs = ThreadLocalRandom.current().nextLong(1, 10);
long numberOfSegments = ThreadLocalRandom.current().nextLong(3, 10); // long numberOfSegments = ThreadLocalRandom.current().nextLong(3, 10);
ArrayList<Segment> segments = new ArrayList<>(); // ArrayList<Segment> segments = new ArrayList<>();
for (int i = 0; i < numberOfSegments; ++i) { // for (int i = 0; i < numberOfSegments; ++i) {
long numJobs = i % 2 == 0 ? 1 : numberOfJobs; // long numJobs = i % 2 == 0 ? 1 : numberOfJobs;
segments.add(new Segment(10, numJobs)); // segments.add(new Segment(10, numJobs));
} // }
SynchronousTask t = new SynchronousTask(new LinkedHashSet<>(segments), 100, 8); // SynchronousTask t = new SynchronousTask(new LinkedHashSet<>(segments), 100, 8);
TaskContext tc = new TaskContext(t, 1, 0); // TaskContext tc = new TaskContext(t, 1, 0);
for (int i = 0; i < segments.size() - 1; ++i) { // for (int i = 0; i < segments.size() - 1; ++i) {
Segment s = segments.get(i); // Segment s = segments.get(i);
} // }
Optional<TaskContextInterface> tci = tc.acceptNotification(0); // Optional<TaskContextInterface> tci = tc.acceptNotification(0);
assertTrue(tci.isPresent()); // assertTrue(tci.isPresent());
assertTrue(tci.get().equals(tc)); // assertTrue(tci.get().equals(tc));
} // }
} // }
@Test // @Test
@DisplayName("Check if the next job is returned correctly.") // @DisplayName("Check if the next job is returned correctly.")
public void testGetNextJob() { // public void testGetNextJob() {
for (int run = 0; run < 100; ++run) { // for (int run = 0; run < 100; ++run) {
long numberOfProcessors = ThreadLocalRandom.current().nextLong(2, 10); // long numberOfProcessors = ThreadLocalRandom.current().nextLong(2, 10);
Set<Segment> segments = new LinkedHashSet<>(); // Set<Segment> segments = new LinkedHashSet<>();
segments.add(new Segment(5, 1)); // segments.add(new Segment(5, 1));
segments.add(new Segment(10, 10)); // segments.add(new Segment(10, 10));
segments.add(new Segment(15, 1)); // segments.add(new Segment(15, 1));
SynchronousTask t = new SynchronousTask(segments, 100, 8); // SynchronousTask t = new SynchronousTask(segments, 100, 8);
TaskContext tc = new TaskContext(t, numberOfProcessors, 0); // TaskContext tc = new TaskContext(t, numberOfProcessors, 0);
Optional<JobContextInterface> job = tc.getNextJob(); // Optional<JobContextInterface> job = tc.getNextJob();
assertTrue(job.isPresent()); // assertTrue(job.isPresent());
job.get().setCurrentProcessor(new ProcessorContext(0)); // job.get().setCurrentProcessor(new ProcessorContext(0));
assertFalse(tc.getNextJob().isPresent()); // assertFalse(tc.getNextJob().isPresent());
tc.acceptNotification(0); // tc.acceptNotification(0);
for (int i = 0; i < numberOfProcessors - 1; ++i) { // for (int i = 0; i < numberOfProcessors - 1; ++i) {
job = tc.getNextJob(); // job = tc.getNextJob();
assertTrue(job.isPresent()); // assertTrue(job.isPresent());
job.get().setCurrentProcessor(new ProcessorContext(i)); // job.get().setCurrentProcessor(new ProcessorContext(i));
} // }
job = tc.getNextJob(); // job = tc.getNextJob();
assertTrue(job.isPresent()); // assertTrue(job.isPresent());
job.get().setCurrentProcessor(new ProcessorContext(10)); // job.get().setCurrentProcessor(new ProcessorContext(10));
assertFalse(tc.getNextJob().isPresent()); // assertFalse(tc.getNextJob().isPresent());
job.get().setCurrentProcessor(null); // job.get().setCurrentProcessor(null);
assertTrue(tc.getNextJob().isPresent()); // assertTrue(tc.getNextJob().isPresent());
job.get().setCurrentProcessor(new ProcessorContext(10)); // job.get().setCurrentProcessor(new ProcessorContext(10));
assertFalse(tc.getNextJob().isPresent()); // assertFalse(tc.getNextJob().isPresent());
for (int i = 0; i < 10; ++i) { // for (int i = 0; i < 10; ++i) {
tc.acceptNotification(0); // tc.acceptNotification(0);
} // }
assertTrue(tc.getNextJob().isPresent()); // assertTrue(tc.getNextJob().isPresent());
} // }
} // }
} // }
package mvd.jester.simulator.dynamicforkjoin; // package mvd.jester.simulator.dynamicforkjoin;
import static org.junit.jupiter.api.Assertions.assertFalse; // import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows; // import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue; // import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock; // import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times; // import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; // import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; // import static org.mockito.Mockito.when;
import java.util.concurrent.ThreadLocalRandom; // import java.util.concurrent.ThreadLocalRandom;
import org.junit.jupiter.api.DisplayName; // import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test; // import org.junit.jupiter.api.Test;
import mvd.jester.model.Segment; // import mvd.jester.model.Segment;
import mvd.jester.simulator.internals.dynamicforkjoin.JobContext; // import mvd.jester.simulator.internals.dynamicforkjoin.JobContext;
import mvd.jester.simulator.internals.dynamicforkjoin.SegmentContext; // import mvd.jester.simulator.internals.dynamicforkjoin.SegmentContext;
import mvd.jester.simulator.internals.dynamicforkjoin.TaskContext; // import mvd.jester.simulator.internals.dynamicforkjoin.TaskContext;
import mvd.jester.simulator.internals.dynamicforkjoin.TaskletContext; // import mvd.jester.simulator.internals.dynamicforkjoin.TaskletContext;
/** // /**
* TestTaskletContext // * TestTaskletContext
*/ // */
public class TestTaskletContext { // public class TestTaskletContext {
@Test // @Test
@DisplayName("Check if the execution of the tasklet is updated correctly.") // @DisplayName("Check if the execution of the tasklet is updated correctly.")
void testUpdateExecution() { // void testUpdateExecution() {
for (int run = 0; run < 100; ++run) { // for (int run = 0; run < 100; ++run) {
long taskletWcet = ThreadLocalRandom.current().nextLong(20, 50); // long taskletWcet = ThreadLocalRandom.current().nextLong(20, 50);
Segment s = mock(Segment.class); // Segment s = mock(Segment.class);
SegmentContext sc = mock(SegmentContext.class); // SegmentContext sc = mock(SegmentContext.class);
when(sc.getSegment()).thenReturn(s); // when(sc.getSegment()).thenReturn(s);
TaskContext tc = mock(TaskContext.class); // TaskContext tc = mock(TaskContext.class);
JobContext jc = mock(JobContext.class); // JobContext jc = mock(JobContext.class);
TaskletContext tasklet = new TaskletContext(tc, sc); // TaskletContext tasklet = new TaskletContext(tc, sc);
tasklet.setCurrentJob(jc); // tasklet.setCurrentJob(jc);
assertTrue(tasklet.checkExecutionTime()); // assertTrue(tasklet.checkExecutionTime());
for (int i = 0; i < taskletWcet - 1; ++i) { // for (int i = 0; i < taskletWcet - 1; ++i) {
assertFalse(tasklet.updateExecution(i)); // assertFalse(tasklet.updateExecution(i));
} // }
assertTrue(tasklet.updateExecution(taskletWcet)); // assertTrue(tasklet.updateExecution(taskletWcet));
assertFalse(tasklet.getCurrentJob().isPresent()); // assertFalse(tasklet.getCurrentJob().isPresent());
assertFalse(tasklet.checkExecutionTime()); // assertFalse(tasklet.checkExecutionTime());
verify(jc, times(1)).setCurrentTasklet(null); // verify(jc, times(1)).setCurrentTasklet(null);
assertThrows(RuntimeException.class, () -> tasklet.updateExecution(1)); // assertThrows(RuntimeException.class, () -> tasklet.updateExecution(1));
} // }
} // }
} // }
package mvd.jester.simulator.parallelsynchronous; // package mvd.jester.simulator.parallelsynchronous;
import static org.junit.jupiter.api.Assertions.assertFalse; // import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue; // import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock; // import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; // import static org.mockito.Mockito.when;
import java.util.Optional; // import java.util.Optional;
import java.util.concurrent.ThreadLocalRandom; // import java.util.concurrent.ThreadLocalRandom;
import org.junit.jupiter.api.DisplayName; // import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test; // import org.junit.jupiter.api.Test;
import mvd.jester.model.Segment; // import mvd.jester.model.Segment;
import mvd.jester.simulator.internals.JobContextInterface; // import mvd.jester.simulator.internals.JobContextInterface;
import mvd.jester.simulator.internals.parallelsynchronous.SegmentContext; // import mvd.jester.simulator.internals.parallelsynchronous.SegmentContext;
import mvd.jester.simulator.internals.parallelsynchronous.TaskContext; // import mvd.jester.simulator.internals.parallelsynchronous.TaskContext;
import mvd.jester.simulator.internals.ProcessorContext; // import mvd.jester.simulator.internals.ProcessorContext;
/** // /**
* TestSegmentContext // * TestSegmentContext
*/ // */
public class TestSegmentContext { // public class TestSegmentContext {
@Test // @Test
@DisplayName("Check if segment returns the jobs correctly.") // @DisplayName("Check if segment returns the jobs correctly.")
void testGetNextJob() { // void testGetNextJob() {
for (int run = 0; run < 100; ++run) { // for (int run = 0; run < 100; ++run) {
long numberOfJobs = ThreadLocalRandom.current().nextLong(1, 10); // long numberOfJobs = ThreadLocalRandom.current().nextLong(1, 10);
long jobWcet = ThreadLocalRandom.current().nextLong(20, 50); // long jobWcet = ThreadLocalRandom.current().nextLong(20, 50);
Segment s = new Segment(jobWcet, numberOfJobs); // Segment s = new Segment(jobWcet, numberOfJobs);
TaskContext tc = mock(TaskContext.class); // TaskContext tc = mock(TaskContext.class);
when(tc.acceptNotification(jobWcet - 1)).thenReturn(Optional.empty()); // when(tc.acceptNotification(jobWcet - 1)).thenReturn(Optional.empty());
SegmentContext sc = new SegmentContext(tc, s); // SegmentContext sc = new SegmentContext(tc, s);
Optional<JobContextInterface> job = Optional.empty(); // Optional<JobContextInterface> job = Optional.empty();
for (int i = 0; i < numberOfJobs; ++i) { // for (int i = 0; i < numberOfJobs; ++i) {
job = sc.getNextJob(); // job = sc.getNextJob();
assertTrue(job.isPresent()); // assertTrue(job.isPresent());
job.get().setCurrentProcessor(new ProcessorContext(i)); // job.get().setCurrentProcessor(new ProcessorContext(i));
} // }
assertFalse(sc.getNextJob().isPresent()); // assertFalse(sc.getNextJob().isPresent());
sc = new SegmentContext(tc, s); // sc = new SegmentContext(tc, s);
for (int i = 0; i < numberOfJobs; ++i) { // for (int i = 0; i < numberOfJobs; ++i) {
job = sc.getNextJob(); // job = sc.getNextJob();
assertTrue(job.isPresent()); // assertTrue(job.isPresent());
job.get().setCurrentProcessor(new ProcessorContext(i)); // job.get().setCurrentProcessor(new ProcessorContext(i));
for (int j = 0; j < jobWcet; ++j) { // for (int j = 0; j < jobWcet; ++j) {
job.get().updateExecution(i); // job.get().updateExecution(i);
} // }
} // }
assertFalse(sc.getNextJob().isPresent()); // assertFalse(sc.getNextJob().isPresent());
} // }
} // }
} // }
package mvd.jester.simulator.parallelsynchronous; // package mvd.jester.simulator.parallelsynchronous;
import static org.junit.jupiter.api.Assertions.assertFalse; // import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue; // import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.ArrayList; // import java.util.ArrayList;
import java.util.LinkedHashSet; // import java.util.LinkedHashSet;
import java.util.Optional; // import java.util.Optional;
import java.util.Set; // import java.util.Set;
import java.util.concurrent.ThreadLocalRandom; // import java.util.concurrent.ThreadLocalRandom;
import org.junit.jupiter.api.DisplayName; // import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test; // import org.junit.jupiter.api.Test;
import mvd.jester.model.Segment; // import mvd.jester.model.Segment;
import mvd.jester.model.SynchronousTask; // import mvd.jester.model.SynchronousTask;
import mvd.jester.simulator.internals.JobContextInterface; // import mvd.jester.simulator.internals.JobContextInterface;
import mvd.jester.simulator.internals.ProcessorContext; // import mvd.jester.simulator.internals.ProcessorContext;
import mvd.jester.simulator.internals.TaskContextInterface; // import mvd.jester.simulator.internals.TaskContextInterface;
import mvd.jester.simulator.internals.parallelsynchronous.TaskContext; // import mvd.jester.simulator.internals.parallelsynchronous.TaskContext;
/** // /**
* TestTaskContext // * TestTaskContext
*/ // */
public class TestTaskContext { // public class TestTaskContext {
@Test // @Test
@DisplayName("Check if TaskContext accepts its notification correctly.") // @DisplayName("Check if TaskContext accepts its notification correctly.")
public void testAcceptNotification() { // public void testAcceptNotification() {
for (int run = 0; run < 100; ++run) { // for (int run = 0; run < 100; ++run) {
long numberOfJobs = ThreadLocalRandom.current().nextLong(1, 10); // long numberOfJobs = ThreadLocalRandom.current().nextLong(1, 10);
long numberOfSegments = ThreadLocalRandom.current().nextLong(3, 10); // long numberOfSegments = ThreadLocalRandom.current().nextLong(3, 10);
ArrayList<Segment> segments = new ArrayList<>(); // ArrayList<Segment> segments = new ArrayList<>();
for (int i = 0; i < numberOfSegments; ++i) { // for (int i = 0; i < numberOfSegments; ++i) {
long numJobs = i % 2 == 0 ? 1 : numberOfJobs; // long numJobs = i % 2 == 0 ? 1 : numberOfJobs;
segments.add(new Segment(10, numJobs)); // segments.add(new Segment(10, numJobs));
} // }
SynchronousTask t = new SynchronousTask(new LinkedHashSet<>(segments), 100, 8); // SynchronousTask t = new SynchronousTask(new LinkedHashSet<>(segments), 100, 8);
TaskContext tc = new TaskContext(t, 0); // TaskContext tc = new TaskContext(t, 0);
for (int i = 0; i < segments.size() - 1; ++i) { // for (int i = 0; i < segments.size() - 1; ++i) {
Segment s = segments.get(i); // Segment s = segments.get(i);
for (int j = 0; j < s.getNumberOfJobs(); ++j) { // for (int j = 0; j < s.getNumberOfJobs(); ++j) {
assertFalse(tc.acceptNotification(0).isPresent()); // assertFalse(tc.acceptNotification(0).isPresent());
} // }
} // }
for (int i = 0; i < segments.get(segments.size() - 1).getNumberOfJobs() - 1; ++i) { // for (int i = 0; i < segments.get(segments.size() - 1).getNumberOfJobs() - 1; ++i) {
assertFalse(tc.acceptNotification(0).isPresent()); // assertFalse(tc.acceptNotification(0).isPresent());
} // }
Optional<TaskContextInterface> tci = tc.acceptNotification(0); // Optional<TaskContextInterface> tci = tc.acceptNotification(0);
assertTrue(tci.isPresent()); // assertTrue(tci.isPresent());
assertTrue(tci.get().equals(tc)); // assertTrue(tci.get().equals(tc));
} // }
} // }
@Test // @Test
@DisplayName("Check if the next job is returned correctly.") // @DisplayName("Check if the next job is returned correctly.")
public void testGetNextJob() { // public void testGetNextJob() {
for (int run = 0; run < 100; ++run) { // for (int run = 0; run < 100; ++run) {
// long numberOfJobs = ThreadLocalRandom.current().nextLong(1, 10); // // long numberOfJobs = ThreadLocalRandom.current().nextLong(1, 10);
// long numberOfSegments = ThreadLocalRandom.current().nextLong(3, 10); // // long numberOfSegments = ThreadLocalRandom.current().nextLong(3, 10);
Set<Segment> segments = new LinkedHashSet<>(); // Set<Segment> segments = new LinkedHashSet<>();
segments.add(new Segment(5, 1)); // segments.add(new Segment(5, 1));
segments.add(new Segment(10, 10)); // segments.add(new Segment(10, 10));
segments.add(new Segment(15, 1)); // segments.add(new Segment(15, 1));
SynchronousTask t = new SynchronousTask(segments, 100, 8); // SynchronousTask t = new SynchronousTask(segments, 100, 8);
TaskContext tc = new TaskContext(t, 0); // TaskContext tc = new TaskContext(t, 0);
Optional<JobContextInterface> job = tc.getNextJob(); // Optional<JobContextInterface> job = tc.getNextJob();
assertTrue(job.isPresent()); // assertTrue(job.isPresent());
job.get().setCurrentProcessor(new ProcessorContext(0)); // job.get().setCurrentProcessor(new ProcessorContext(0));
assertFalse(tc.getNextJob().isPresent()); // assertFalse(tc.getNextJob().isPresent());
tc.acceptNotification(0); // tc.acceptNotification(0);
for (int i = 0; i < 9; ++i) { // for (int i = 0; i < 9; ++i) {
job = tc.getNextJob(); // job = tc.getNextJob();
assertTrue(job.isPresent()); // assertTrue(job.isPresent());
job.get().setCurrentProcessor(new ProcessorContext(i)); // job.get().setCurrentProcessor(new ProcessorContext(i));
tc.acceptNotification(0); // tc.acceptNotification(0);
} // }
job = tc.getNextJob(); // job = tc.getNextJob();
assertTrue(job.isPresent()); // assertTrue(job.isPresent());
job.get().setCurrentProcessor(new ProcessorContext(20)); // job.get().setCurrentProcessor(new ProcessorContext(20));
assertFalse(tc.getNextJob().isPresent()); // assertFalse(tc.getNextJob().isPresent());
tc.acceptNotification(0); // tc.acceptNotification(0);
assertTrue(tc.getNextJob().isPresent()); // assertTrue(tc.getNextJob().isPresent());
} // }
} // }
} // }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment