Commit a52ab93d by Michael Schmid

switched to java 11 and jacoco, small changes

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