From a9eacf1059705dbd672dde44add6c57c994df35d Mon Sep 17 00:00:00 2001 From: Michael Schmid Date: Mon, 23 Mar 2020 13:23:06 +0100 Subject: [PATCH] renamed namespace and added a few tests --- pom.xml | 17 +++++++++++++++++ src/main/java/mvd/jester/App.java | 32 ++++++++++---------------------- src/main/java/mvd/jester/ResultCollector.java | 4 ++-- src/main/java/mvd/jester/ResultLogger.java | 213 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------------------------------------------------------------- src/main/java/mvd/jester/info/SchedulingInfo.java | 12 +++++++++--- src/main/java/mvd/jester/info/TerminationInfo.java | 28 ++++++++++++++++++++++++++++ src/main/java/mvd/jester/model/SystemSetup.java | 4 ++-- src/main/java/mvd/jester/priority/EarliestDeadlineFirst.java | 6 +++--- src/main/java/mvd/jester/priority/RateMonotonic.java | 8 ++++---- src/main/java/mvd/jester/simulator/AbstractSimulator.java | 17 ++++++++--------- src/main/java/mvd/jester/simulator/DynamicForkJoin.java | 39 +++++++++++++++++++++++++++++++++++++++ src/main/java/mvd/jester/simulator/MaiaBertogna.java | 38 -------------------------------------- src/main/java/mvd/jester/simulator/ParallelSynchronous.java | 38 ++++++++++++++++++++++++++++++++++++++ src/main/java/mvd/jester/simulator/SchmidMottok.java | 39 --------------------------------------- src/main/java/mvd/jester/simulator/internals/dynamicforkjoin/JobContext.java | 129 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main/java/mvd/jester/simulator/internals/dynamicforkjoin/SegmentContext.java | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main/java/mvd/jester/simulator/internals/dynamicforkjoin/TaskContext.java | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main/java/mvd/jester/simulator/internals/dynamicforkjoin/TaskletContext.java | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main/java/mvd/jester/simulator/internals/maiabertogna/JobContext.java | 97 ------------------------------------------------------------------------------------------------- src/main/java/mvd/jester/simulator/internals/maiabertogna/SegmentContext.java | 43 ------------------------------------------- src/main/java/mvd/jester/simulator/internals/maiabertogna/TaskContext.java | 87 --------------------------------------------------------------------------------------- src/main/java/mvd/jester/simulator/internals/parallelsynchronous/JobContext.java | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main/java/mvd/jester/simulator/internals/parallelsynchronous/SegmentContext.java | 43 +++++++++++++++++++++++++++++++++++++++++++ src/main/java/mvd/jester/simulator/internals/parallelsynchronous/TaskContext.java | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main/java/mvd/jester/simulator/internals/schmidmottok/JobContext.java | 129 --------------------------------------------------------------------------------------------------------------------------------- src/main/java/mvd/jester/simulator/internals/schmidmottok/SegmentContext.java | 78 ------------------------------------------------------------------------------ src/main/java/mvd/jester/simulator/internals/schmidmottok/TaskContext.java | 88 ---------------------------------------------------------------------------------------- src/main/java/mvd/jester/simulator/internals/schmidmottok/TaskletContext.java | 61 ------------------------------------------------------------- src/main/java/mvd/jester/tests/AbstractTest.java | 3 --- src/main/java/mvd/jester/tests/ChwaLee.java | 11 +++++++---- src/main/java/mvd/jester/tests/MaiaBertogna.java | 11 +++++++---- src/main/java/mvd/jester/tests/SchmidMottok.java | 11 +++++++---- src/main/java/mvd/jester/utils/Logger.java | 4 ++-- src/test/java/mvd/jester/TestResultCollector.java | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/test/java/mvd/jester/info/TestSchedulingInfo.java | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/test/java/mvd/jester/info/TestTerminationInfo.java | 40 ++++++++++++++++++++++++++++++++++++++++ src/test/java/mvd/jester/model/TestSystemSetup.java | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++----- src/test/java/mvd/jester/priority/TestEarliestDeadlineFirst.java | 50 ++++++++++++++++++++++++++++++++++++++++++++------ src/test/java/mvd/jester/priority/TestRateMonotonic.java | 47 ++++++++++++++++++++++++++++++++++++++++++----- src/test/java/mvd/jester/simulator/TestProcessorContext.java | 4 ++-- src/test/java/mvd/jester/simulator/dynamicforkjoin/TestJobContext.java | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/test/java/mvd/jester/simulator/dynamicforkjoin/TestSegmentContext.java | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/test/java/mvd/jester/simulator/dynamicforkjoin/TestTaskContext.java | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/test/java/mvd/jester/simulator/dynamicforkjoin/TestTaskletContext.java | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/test/java/mvd/jester/simulator/maiabertogna/TestJobContext.java | 61 ------------------------------------------------------------- src/test/java/mvd/jester/simulator/maiabertogna/TestSegmentContext.java | 57 --------------------------------------------------------- src/test/java/mvd/jester/simulator/maiabertogna/TestTaskContext.java | 96 ------------------------------------------------------------------------------------------------ src/test/java/mvd/jester/simulator/parallelsynchronous/TestJobContext.java | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/test/java/mvd/jester/simulator/parallelsynchronous/TestSegmentContext.java | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/test/java/mvd/jester/simulator/parallelsynchronous/TestTaskContext.java | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/test/java/mvd/jester/simulator/schmidmottok/TestJobContext.java | 98 -------------------------------------------------------------------------------------------------- src/test/java/mvd/jester/simulator/schmidmottok/TestSegmentContext.java | 105 --------------------------------------------------------------------------------------------------------- src/test/java/mvd/jester/simulator/schmidmottok/TestTaskContext.java | 101 ----------------------------------------------------------------------------------------------------- src/test/java/mvd/jester/simulator/schmidmottok/TestTaskletContext.java | 53 ----------------------------------------------------- src/test/java/mvd/jester/tests/TestMaiaBertogna.java | 42 ++++++++++++++++++++++++++++++++++++++++-- src/test/java/mvd/jester/tests/TestSchmidMottok.java | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 56 files changed, 1844 insertions(+), 1437 deletions(-) create mode 100644 src/main/java/mvd/jester/simulator/DynamicForkJoin.java delete mode 100644 src/main/java/mvd/jester/simulator/MaiaBertogna.java create mode 100644 src/main/java/mvd/jester/simulator/ParallelSynchronous.java delete mode 100644 src/main/java/mvd/jester/simulator/SchmidMottok.java create mode 100644 src/main/java/mvd/jester/simulator/internals/dynamicforkjoin/JobContext.java create mode 100644 src/main/java/mvd/jester/simulator/internals/dynamicforkjoin/SegmentContext.java create mode 100644 src/main/java/mvd/jester/simulator/internals/dynamicforkjoin/TaskContext.java create mode 100644 src/main/java/mvd/jester/simulator/internals/dynamicforkjoin/TaskletContext.java delete mode 100644 src/main/java/mvd/jester/simulator/internals/maiabertogna/JobContext.java delete mode 100644 src/main/java/mvd/jester/simulator/internals/maiabertogna/SegmentContext.java delete mode 100644 src/main/java/mvd/jester/simulator/internals/maiabertogna/TaskContext.java create mode 100644 src/main/java/mvd/jester/simulator/internals/parallelsynchronous/JobContext.java create mode 100644 src/main/java/mvd/jester/simulator/internals/parallelsynchronous/SegmentContext.java create mode 100644 src/main/java/mvd/jester/simulator/internals/parallelsynchronous/TaskContext.java delete mode 100644 src/main/java/mvd/jester/simulator/internals/schmidmottok/JobContext.java delete mode 100644 src/main/java/mvd/jester/simulator/internals/schmidmottok/SegmentContext.java delete mode 100644 src/main/java/mvd/jester/simulator/internals/schmidmottok/TaskContext.java delete mode 100644 src/main/java/mvd/jester/simulator/internals/schmidmottok/TaskletContext.java create mode 100644 src/test/java/mvd/jester/TestResultCollector.java create mode 100644 src/test/java/mvd/jester/info/TestSchedulingInfo.java create mode 100644 src/test/java/mvd/jester/info/TestTerminationInfo.java create mode 100644 src/test/java/mvd/jester/simulator/dynamicforkjoin/TestJobContext.java create mode 100644 src/test/java/mvd/jester/simulator/dynamicforkjoin/TestSegmentContext.java create mode 100644 src/test/java/mvd/jester/simulator/dynamicforkjoin/TestTaskContext.java create mode 100644 src/test/java/mvd/jester/simulator/dynamicforkjoin/TestTaskletContext.java delete mode 100644 src/test/java/mvd/jester/simulator/maiabertogna/TestJobContext.java delete mode 100644 src/test/java/mvd/jester/simulator/maiabertogna/TestSegmentContext.java delete mode 100644 src/test/java/mvd/jester/simulator/maiabertogna/TestTaskContext.java create mode 100644 src/test/java/mvd/jester/simulator/parallelsynchronous/TestJobContext.java create mode 100644 src/test/java/mvd/jester/simulator/parallelsynchronous/TestSegmentContext.java create mode 100644 src/test/java/mvd/jester/simulator/parallelsynchronous/TestTaskContext.java delete mode 100644 src/test/java/mvd/jester/simulator/schmidmottok/TestJobContext.java delete mode 100644 src/test/java/mvd/jester/simulator/schmidmottok/TestSegmentContext.java delete mode 100644 src/test/java/mvd/jester/simulator/schmidmottok/TestTaskContext.java delete mode 100644 src/test/java/mvd/jester/simulator/schmidmottok/TestTaskletContext.java create mode 100644 src/test/java/mvd/jester/tests/TestSchmidMottok.java diff --git a/pom.xml b/pom.xml index 5160f5d..28afa01 100644 --- a/pom.xml +++ b/pom.xml @@ -15,6 +15,12 @@ + + net.sourceforge.cobertura + cobertura + 2.1.1 + test + org.apache.commons commons-math3 @@ -56,6 +62,17 @@ + + + + + org.codehaus.mojo + cobertura-maven-plugin + 2.7 + + + + diff --git a/src/main/java/mvd/jester/App.java b/src/main/java/mvd/jester/App.java index 0663b05..7a86f97 100644 --- a/src/main/java/mvd/jester/App.java +++ b/src/main/java/mvd/jester/App.java @@ -11,30 +11,18 @@ import mvd.jester.priority.RateMonotonic; */ public class App { public static void main(String[] args) { - SystemSetup.Builder builder = new SystemSetup.Builder().setNumberOfProcessors(8); - TestEnvironment te = new TestEnvironment(builder, 40000); + for (int p = 4; p <= 16; p *= 2) { + SystemSetup.Builder builder = new SystemSetup.Builder().setNumberOfProcessors(p); + TestEnvironment te = new TestEnvironment(builder, 40000); - te.registerSchedulingAlgorithm(new RateMonotonic()); - te.registerSchedulingAlgorithm(new EarliestDeadlineFirst()); + te.registerSchedulingAlgorithm(new RateMonotonic()); + te.registerSchedulingAlgorithm(new EarliestDeadlineFirst()); - te.registerTest(mvd.jester.tests.SchmidMottok.class); - te.registerTest(mvd.jester.tests.MaiaBertogna.class); - te.registerTest(mvd.jester.tests.ChwaLee.class); + te.registerTest(mvd.jester.tests.SchmidMottok.class); + te.registerTest(mvd.jester.tests.MaiaBertogna.class); + te.registerTest(mvd.jester.tests.ChwaLee.class); - te.registerSimulator(mvd.jester.simulator.MaiaBertogna.class); - te.registerSimulator(mvd.jester.simulator.SchmidMottok.class); - - - te.runExperiments(); - - // SystemSetup setup = SystemSetup.readFromFile( - // "/home/mike/Promotion/projects/eclipse/jester/results/test_this.txt", 16); - - // SchmidMottok sm = new SchmidMottok(setup); - // MaiaBertogna mb = new MaiaBertogna(setup); - // RateMonotonic rm = new RateMonotonic(); - - // sm.runSchedulabilityCheck(rm); - // mb.runSchedulabilityCheck(rm); + te.runExperiments(); + } } } diff --git a/src/main/java/mvd/jester/ResultCollector.java b/src/main/java/mvd/jester/ResultCollector.java index 658b41c..404145d 100644 --- a/src/main/java/mvd/jester/ResultCollector.java +++ b/src/main/java/mvd/jester/ResultCollector.java @@ -39,8 +39,8 @@ public class ResultCollector } - public void addResult(SchedulingInfo schedulingInfo) { - this.schedulingInfos.add(schedulingInfo); + public boolean addResult(SchedulingInfo schedulingInfo) { + return this.schedulingInfos.add(schedulingInfo); } public Set getResults() { diff --git a/src/main/java/mvd/jester/ResultLogger.java b/src/main/java/mvd/jester/ResultLogger.java index a533b59..44db254 100644 --- a/src/main/java/mvd/jester/ResultLogger.java +++ b/src/main/java/mvd/jester/ResultLogger.java @@ -4,13 +4,17 @@ import java.io.IOException; import java.time.LocalTime; import java.util.Set; import java.util.TreeSet; +import java.util.function.Supplier; import java.util.stream.Collectors; +import java.util.stream.Stream; import com.google.common.collect.ImmutableList; import com.google.common.collect.ObjectArrays; import com.google.common.collect.Table; import com.google.common.collect.TreeBasedTable; import org.apache.commons.csv.CSVFormat; import org.apache.commons.csv.CSVPrinter; +import mvd.jester.info.SchedulingInfo; +import mvd.jester.info.TerminationInfo.Level; import mvd.jester.simulator.AbstractSimulator; import mvd.jester.tests.AbstractTest; import mvd.jester.utils.Logger; @@ -33,15 +37,56 @@ public class ResultLogger { } public void logTests(Set> results) { - logFeasibility(results, "test"); - logTaskRatio(results, "test"); + if (!results.isEmpty()) { + logFeasibility(results, "test"); + logFeasibilityRatio(results, "test"); + logTaskRatio(results, "test"); + logFeasibilityLevel(results, "test"); + } } public void logSimulations(Set> results) { - logFeasibility(results, "sim"); - logTaskRatio(results, "sim"); + if (!results.isEmpty()) { + logFeasibility(results, "sim"); + logTaskRatio(results, "sim"); + } } + + public void logFeasibilityLevel(Set> results, + String type) { + LocalTime date = LocalTime.now(); + Logger log = new Logger("./results/feasibility_level_" + type + "_" + numberOfProcessors + + "_" + date.getHour() + ":" + date.getMinute() + ".txt"); + + Table, Double> resultTable = TreeBasedTable.create(); + Set> resultCollectors = new TreeSet<>(); + + for (long util = 0; util <= numberOfProcessors * 10; util += numberOfProcessors / 4) { + for (ResultCollector rc : results) { + resultCollectors.add(rc); + final long local_util = util; + + Supplier> schedulingResults = () -> rc.getResults().stream() + .filter(r -> Math.round(r.getUtilization() * 10 / (numberOfProcessors / 4)) + * (numberOfProcessors / 4) == local_util); + if (schedulingResults.get().filter(r -> !r.checkTasksetFeasible()).count() > 0) { + double feasibleTasksets = (double) schedulingResults.get() + .filter(r -> r.checkLevelFail(Level.HIGH)).count() + / schedulingResults.get().filter(r -> !r.checkTasksetFeasible()) + .count(); + resultTable.put(util, rc, feasibleTasksets); + } else { + resultTable.put(util, rc, 0.); + } + } + } + + logData(log, resultTable, resultCollectors, "Utilization"); + } + + + public void logFeasibility(Set> results, String type) { LocalTime date = LocalTime.now(); @@ -51,23 +96,49 @@ public class ResultLogger { Table, Long> resultTable = TreeBasedTable.create(); Set> resultCollectors = new TreeSet<>(); - for (ResultCollector r : results) { - System.out.println(r.getName() + ": " - + r.getResults().stream().filter(p -> p.checkTasksetFeasible()).count()); - } - - for (long util = 0; util < numberOfProcessors * 10; util++) { + for (long util = 0; util <= numberOfProcessors * 10; util += numberOfProcessors / 4) { for (ResultCollector rc : results) { resultCollectors.add(rc); final long local_util = util; long feasibleTasksets = rc.getResults().stream() - .filter(r -> Math.round(r.getUtilization() * 10) == local_util) + .filter(r -> Math.round(r.getUtilization() * 10 / (numberOfProcessors / 4)) + * (numberOfProcessors / 4) == local_util) .filter(r -> r.checkTasksetFeasible()).count(); resultTable.put(util, rc, feasibleTasksets); } } - logData(log, resultTable, resultCollectors); + logData(log, resultTable, resultCollectors, "Utilization"); + } + + public void logFeasibilityRatio(Set> results, + String type) { + LocalTime date = LocalTime.now(); + Logger log = new Logger("./results/feasibility_ratio_" + type + "_" + numberOfProcessors + + "_" + date.getHour() + ":" + date.getMinute() + ".txt"); + + Table, Double> resultTable = TreeBasedTable.create(); + Set> resultCollectors = new TreeSet<>(); + + for (long util = 0; util <= numberOfProcessors * 10; util += numberOfProcessors / 4) { + for (ResultCollector rc : results) { + resultCollectors.add(rc); + final long local_util = util; + Supplier> schedulingResults = () -> rc.getResults().stream() + .filter(r -> Math.round(r.getUtilization() * 10 / (numberOfProcessors / 4)) + * (numberOfProcessors / 4) == local_util); + if (schedulingResults.get().count() > 0) { + double feasibleTasksets = + (double) schedulingResults.get().filter(r -> r.checkTasksetFeasible()) + .count() / schedulingResults.get().count(); + resultTable.put(util, rc, feasibleTasksets); + } else { + resultTable.put(util, rc, 1.); + } + } + } + + logData(log, resultTable, resultCollectors, "Utilization"); } public void logTaskRatio(Set> results, @@ -79,28 +150,28 @@ public class ResultLogger { Table, Long> resultTable = TreeBasedTable.create(); Set> resultCollectors = new TreeSet<>(); - for (long ratio = 0; ratio < 10; ratio += 1) { + for (long ratio = 0; ratio <= 10; ratio += 1) { for (ResultCollector rc : results) { resultCollectors.add(rc); final long local_ratio = ratio; long feasibleTasksets = rc.getResults().stream() - .filter(r -> Math.round(r.getParallelTaskRatio() * 10) == local_ratio) + .filter(r -> Math.ceil(r.getParallelTaskRatio() * 10) == local_ratio) .filter(r -> r.checkTasksetFeasible()).count(); resultTable.put(ratio, rc, feasibleTasksets); } } - logData(log, resultTable, resultCollectors); + logData(log, resultTable, resultCollectors, "TaskRatio"); } private void logData(Logger log, - Table, Long> resultTable, - Set> resultCollectors) { + Table, ? extends Number> resultTable, + Set> resultCollectors, String xDataName) { final Appendable out = new StringBuilder(); try { String[] resultCollectorNames = resultCollectors.stream() .map(ResultCollector::getName).toArray(String[]::new); - String[] header = ObjectArrays.concat("Utilization", resultCollectorNames); + String[] header = ObjectArrays.concat(xDataName, resultCollectorNames); final CSVPrinter printer = CSVFormat.DEFAULT.withHeader(header).print(out); printer.printRecords(resultTable.rowMap().entrySet().stream() @@ -114,110 +185,4 @@ public class ResultLogger { log.log(out); log.finalize(); } - - - // public void logFeasibility( - // Table, Set> results, String type) { - // LocalTime date = LocalTime.now(); - // Logger log = new Logger("./results/feasibility_" + type + "_" + numberOfProcessors + "_" - // + date.getHour() + ":" + date.getMinute() + ".txt"); - // String firstLine = new String("Utilization"); - - // if (!results.isEmpty()) { - // for (ResultCollector pair : results.columnKeySet()) { - // firstLine = firstLine + "\t" + pair.getName(); - // } - - // log.log(firstLine); - - // for (Long util : totalNumberOfTasksets.keySet()) { - // String line = String.valueOf((double) util / 10); - // for (ResultCollector pair : results.columnKeySet()) { - // long feasibleTasksets = results.get(util, pair).stream() - // .filter(s -> s.checkTasksetFeasible()).count(); - // line += "\t" + feasibleTasksets; - // } - // log.log(line); - // } - // } - - // log.finalize(); - // } - - - // public void logFailedTardiness( - // Table, Set> results, String type) { - // LocalTime date = LocalTime.now(); - // Logger log = new Logger("./results/failed_tardiness_" + type + "_" + numberOfProcessors - // + "_" + date.getHour() + ":" + date.getMinute() + ".txt"); - // String firstLine = new String("Utilization"); - - // if (!results.isEmpty()) { - // for (ResultCollector pair : results.columnKeySet()) { - // firstLine = firstLine + "\t" + pair.getName(); - // } - - // log.log(firstLine); - - // for (Long kv : totalNumberOfTasksets.keySet()) { - // String line = String.valueOf((double) kv / 10); - // for (ResultCollector pair : results.columnKeySet()) { - // Set simulationInfos = results.get(kv, pair); - // List values = new ArrayList<>(); - - // for (SchedulingInfo s : simulationInfos) { - // Optional failedTerminationInfo = - // s.getFailedTerminationInfo(); - // if (failedTerminationInfo.isPresent()) { - // values.add(failedTerminationInfo.get().getLateness()); - // } - // } - // double meanTardiness = 0; - // if (!values.isEmpty()) { - // meanTardiness = Stats.meanOf(values.iterator()); - // } - // line += "\t" + meanTardiness; - // } - // log.log(line); - // } - // } - - // log.finalize(); - // } - - // public void logTardinessStatistics( - // Table, Set> results, String type) { - // LocalTime date = LocalTime.now(); - // Logger log = new Logger("./results/statistics_tardiness_" + type + "_" + numberOfProcessors - // + "_" + date.getHour() + ":" + date.getMinute() + ".txt"); - // String firstLine = new String("Utilization"); - - // if (!results.isEmpty()) { - // for (ResultCollector pair : results.columnKeySet()) { - // firstLine = firstLine + "\t" + pair.getName(); - // } - - // log.log(firstLine); - - // for (Long kv : totalNumberOfTasksets.keySet()) { - // String line = String.valueOf((double) kv / 10); - // for (ResultCollector pair : results.columnKeySet()) { - // Set simulationInfos = results.get(kv, pair); - // DescriptiveStatistics stats = new DescriptiveStatistics(); - - // for (SchedulingInfo s : simulationInfos) { - // for (TerminationInfo t : s.getTerminationInfos()) { - // stats.addValue(t.getLateness()); - // } - // } - - // line += "\t" + stats.getMean(); - // } - // log.log(line); - // } - // } - - // log.finalize(); - // } - } diff --git a/src/main/java/mvd/jester/info/SchedulingInfo.java b/src/main/java/mvd/jester/info/SchedulingInfo.java index adf6259..425de6f 100644 --- a/src/main/java/mvd/jester/info/SchedulingInfo.java +++ b/src/main/java/mvd/jester/info/SchedulingInfo.java @@ -3,9 +3,10 @@ package mvd.jester.info; import java.util.HashSet; import java.util.Optional; import java.util.Set; +import mvd.jester.info.TerminationInfo.Level; /** - * DeadlineMissInfo + * SchedulingInfo */ public class SchedulingInfo { @@ -44,13 +45,18 @@ public class SchedulingInfo { terminationInfos.stream().filter(t -> t.getLateness() > 0).findFirst(); } + public boolean checkLevelFail(Level level) { + return terminationInfos.stream() + .anyMatch(t -> t.getLateness() > 0 && t.getTaskLevel() == level); + } + public boolean checkTasksetFeasible() { // return terminationInfos.isEmpty(); return !terminationInfos.stream().anyMatch(t -> t.getLateness() > 0); } - public void addTerminationInfo(TerminationInfo terminationInfo) { - terminationInfos.add(terminationInfo); + public boolean addTerminationInfo(TerminationInfo terminationInfo) { + return terminationInfos.add(terminationInfo); } /** diff --git a/src/main/java/mvd/jester/info/TerminationInfo.java b/src/main/java/mvd/jester/info/TerminationInfo.java index b75a906..5fbb277 100644 --- a/src/main/java/mvd/jester/info/TerminationInfo.java +++ b/src/main/java/mvd/jester/info/TerminationInfo.java @@ -9,14 +9,31 @@ public class TerminationInfo { private final long deadline; private final long responseTime; private final long lateness; + private final Level taskLevel; public TerminationInfo(long releaseTime, long deadline, long responseTime) { this.releaseTime = releaseTime; this.deadline = deadline; this.responseTime = responseTime; this.lateness = responseTime - deadline; + this.taskLevel = Level.LOW; } + public TerminationInfo(long releaseTime, long deadline, long responseTime, Level taskLevel) { + this.releaseTime = releaseTime; + this.deadline = deadline; + this.responseTime = responseTime; + this.lateness = responseTime - deadline; + this.taskLevel = taskLevel; + } + + public TerminationInfo(long deadline, long responseTime, Level taskLevel) { + this.releaseTime = 0; + this.deadline = deadline; + this.responseTime = responseTime; + this.lateness = responseTime - deadline; + this.taskLevel = taskLevel; + } /** * @return the deadline @@ -45,4 +62,15 @@ public class TerminationInfo { public long getResponseTime() { return responseTime; } + + /** + * @return the taskLevel + */ + public Level getTaskLevel() { + return taskLevel; + } + + public enum Level { + HIGH, LOW + } } diff --git a/src/main/java/mvd/jester/model/SystemSetup.java b/src/main/java/mvd/jester/model/SystemSetup.java index ea8b6c9..d33d987 100644 --- a/src/main/java/mvd/jester/model/SystemSetup.java +++ b/src/main/java/mvd/jester/model/SystemSetup.java @@ -180,8 +180,8 @@ public class SystemSetup { systemSetup.tasks = generateTaskSet(); } - public void addTask(SystemSetup systemSetup) { - systemSetup.tasks.add(generateTask()); + public boolean addTask(SystemSetup systemSetup) { + return systemSetup.tasks.add(generateTask()); } public Builder setNumberOfProcessors(long numberOfProcessors) { diff --git a/src/main/java/mvd/jester/priority/EarliestDeadlineFirst.java b/src/main/java/mvd/jester/priority/EarliestDeadlineFirst.java index 4af7fa2..fd7b1bb 100644 --- a/src/main/java/mvd/jester/priority/EarliestDeadlineFirst.java +++ b/src/main/java/mvd/jester/priority/EarliestDeadlineFirst.java @@ -5,8 +5,8 @@ import java.util.HashSet; import java.util.Set; import mvd.jester.model.Task; import mvd.jester.simulator.AbstractSimulator; -import mvd.jester.simulator.MaiaBertogna; -import mvd.jester.simulator.SchmidMottok; +import mvd.jester.simulator.ParallelSynchronous; +import mvd.jester.simulator.DynamicForkJoin; import mvd.jester.simulator.internals.TaskContextInterface; import mvd.jester.tests.AbstractTest; import mvd.jester.tests.ChwaLee; @@ -19,7 +19,7 @@ public class EarliestDeadlineFirst implements PriorityManager { final static Set> abstractTests = new HashSet<>(Arrays.asList(ChwaLee.class)); final static Set> abstractSimulators = - new HashSet<>(Arrays.asList(MaiaBertogna.class, SchmidMottok.class)); + new HashSet<>(Arrays.asList(ParallelSynchronous.class, DynamicForkJoin.class)); /** * Compare the priority of two tasks according to the Rate Monotonic policy diff --git a/src/main/java/mvd/jester/priority/RateMonotonic.java b/src/main/java/mvd/jester/priority/RateMonotonic.java index b76a947..3c46ff4 100644 --- a/src/main/java/mvd/jester/priority/RateMonotonic.java +++ b/src/main/java/mvd/jester/priority/RateMonotonic.java @@ -13,16 +13,16 @@ public class RateMonotonic implements PriorityManager { final static Set> abstractTests = new HashSet<>(Arrays .asList(mvd.jester.tests.MaiaBertogna.class, mvd.jester.tests.SchmidMottok.class)); final static Set> abstractSimulators = - new HashSet<>(Arrays.asList(mvd.jester.simulator.MaiaBertogna.class, - mvd.jester.simulator.SchmidMottok.class)); + new HashSet<>(Arrays.asList(mvd.jester.simulator.ParallelSynchronous.class, + mvd.jester.simulator.DynamicForkJoin.class)); /** * Compare the priority of two tasks according to the Rate Monotonic policy * * @param t1 The first task * @param t2 The second task - * @return 0 if both tasks have the same priority, positive number if the first task has a - * higher priority, negative number if the second task has a higher priority + * @return 0 if both tasks have the same priority, negative number if the first task has a + * higher priority, positive number if the second task has a higher priority */ @Override public int compare(Task t1, Task t2) { diff --git a/src/main/java/mvd/jester/simulator/AbstractSimulator.java b/src/main/java/mvd/jester/simulator/AbstractSimulator.java index a019dae..83d1088 100644 --- a/src/main/java/mvd/jester/simulator/AbstractSimulator.java +++ b/src/main/java/mvd/jester/simulator/AbstractSimulator.java @@ -25,7 +25,6 @@ public abstract class AbstractSimulator implements SimulatorInterface, TypeInter protected final SystemSetup systemSetup; protected final Set processors; protected TreeMultiset readyTasks; - protected long hyperPeriod; AbstractSimulator(SystemSetup systemSetup) { this.systemSetup = systemSetup; @@ -34,8 +33,6 @@ public abstract class AbstractSimulator implements SimulatorInterface, TypeInter for (int i = 0; i < systemSetup.getNumberOfProcessors(); ++i) { processors.add(new ProcessorContext(i)); } - this.hyperPeriod = getHyperPeriod(); - } @@ -45,7 +42,7 @@ public abstract class AbstractSimulator implements SimulatorInterface, TypeInter public SchedulingInfo runSimulation(PriorityManager priorityManager) { SchedulingInfo schedulingInfo = new SchedulingInfo(systemSetup.getParallelTaskRatio(), systemSetup.getUtilization()); - init(priorityManager); + long hyperPeriod = init(priorityManager); for (int t = 0; t < hyperPeriod; ++t) { if (!releaseTasks(t)) { throw new RuntimeException("Could not release a task. This should not happen!"); @@ -66,10 +63,12 @@ public abstract class AbstractSimulator implements SimulatorInterface, TypeInter Optional optionalTc = p.updateExecution(t); if (optionalTc.isPresent()) { TaskContextInterface tc = optionalTc.get(); - TerminationInfo terminationInfo = - new TerminationInfo(tc.getReleaseTime(), tc.getDeadline(), t); - schedulingInfo.addTerminationInfo(terminationInfo); if (t >= tc.getDeadline()) { + TerminationInfo terminationInfo = + new TerminationInfo(tc.getReleaseTime(), tc.getDeadline(), t); + schedulingInfo.addTerminationInfo(terminationInfo); + + EventPrinter.print("Time " + t + ": Task " + tc + " failed its deadline!"); schedulingInfo.setFailedTerminationInfo(terminationInfo); return schedulingInfo; @@ -83,12 +82,12 @@ public abstract class AbstractSimulator implements SimulatorInterface, TypeInter return schedulingInfo; } - private void init(PriorityManager priorityManager) { + private long init(PriorityManager priorityManager) { this.readyTasks = TreeMultiset.create((t1, t2) -> priorityManager.compare(t1, t2)); for (ProcessorContext p : processors) { p.setJob(null); } - this.hyperPeriod = getHyperPeriod(); + return getHyperPeriod(); } private Set sortProcessors(Set processors) { diff --git a/src/main/java/mvd/jester/simulator/DynamicForkJoin.java b/src/main/java/mvd/jester/simulator/DynamicForkJoin.java new file mode 100644 index 0000000..5a96941 --- /dev/null +++ b/src/main/java/mvd/jester/simulator/DynamicForkJoin.java @@ -0,0 +1,39 @@ +package mvd.jester.simulator; + + +import mvd.jester.model.SystemSetup; +import mvd.jester.model.Task; +import mvd.jester.simulator.internals.dynamicforkjoin.TaskContext; + +/** + * SchmidMottok + */ +public class DynamicForkJoin extends AbstractSimulator { + + public DynamicForkJoin(SystemSetup systemSetup) { + super(systemSetup); + } + + + @Override + protected boolean releaseTasks(long timeStep) { + for (Task t : systemSetup.getTasks()) { + if (timeStep % t.getPeriod() == 0) { + TaskContext tc = new TaskContext(t, systemSetup.getNumberOfProcessors(), timeStep); + if (!readyTasks.add(tc)) { + EventPrinter + .print("Time " + timeStep + ": Task " + tc + " could not be released!"); + return false; + } + EventPrinter.print("Time " + timeStep + ": Task " + tc + " released!"); + } + } + return true; + } + + + @Override + public String getName() { + return "SchmidMottok"; + } +} diff --git a/src/main/java/mvd/jester/simulator/MaiaBertogna.java b/src/main/java/mvd/jester/simulator/MaiaBertogna.java deleted file mode 100644 index f21fa4a..0000000 --- a/src/main/java/mvd/jester/simulator/MaiaBertogna.java +++ /dev/null @@ -1,38 +0,0 @@ -package mvd.jester.simulator; - -import mvd.jester.model.SystemSetup; -import mvd.jester.model.Task; -import mvd.jester.simulator.internals.maiabertogna.TaskContext; - -/** - * MaiaBertogna - */ -public class MaiaBertogna extends AbstractSimulator { - - public MaiaBertogna(SystemSetup systemSetup) { - super(systemSetup); - } - - @Override - protected boolean releaseTasks(long timeStep) { - for (Task t : systemSetup.getTasks()) { - if (timeStep % t.getPeriod() == 0) { - TaskContext tc = new TaskContext(t, timeStep); - if (!readyTasks.add(tc)) { - EventPrinter - .print("Time " + timeStep + ": Task " + tc + " could not be released!"); - return false; - } - EventPrinter.print("Time " + timeStep + ": Task " + tc + " released!"); - } - } - return true; - } - - @Override - public String getName() { - return "MaiaBertogna"; - } - - -} diff --git a/src/main/java/mvd/jester/simulator/ParallelSynchronous.java b/src/main/java/mvd/jester/simulator/ParallelSynchronous.java new file mode 100644 index 0000000..f3dcb35 --- /dev/null +++ b/src/main/java/mvd/jester/simulator/ParallelSynchronous.java @@ -0,0 +1,38 @@ +package mvd.jester.simulator; + +import mvd.jester.model.SystemSetup; +import mvd.jester.model.Task; +import mvd.jester.simulator.internals.parallelsynchronous.TaskContext; + +/** + * MaiaBertogna + */ +public class ParallelSynchronous extends AbstractSimulator { + + public ParallelSynchronous(SystemSetup systemSetup) { + super(systemSetup); + } + + @Override + protected boolean releaseTasks(long timeStep) { + for (Task t : systemSetup.getTasks()) { + if (timeStep % t.getPeriod() == 0) { + TaskContext tc = new TaskContext(t, timeStep); + if (!readyTasks.add(tc)) { + EventPrinter + .print("Time " + timeStep + ": Task " + tc + " could not be released!"); + return false; + } + EventPrinter.print("Time " + timeStep + ": Task " + tc + " released!"); + } + } + return true; + } + + @Override + public String getName() { + return "MaiaBertogna"; + } + + +} diff --git a/src/main/java/mvd/jester/simulator/SchmidMottok.java b/src/main/java/mvd/jester/simulator/SchmidMottok.java deleted file mode 100644 index f82f047..0000000 --- a/src/main/java/mvd/jester/simulator/SchmidMottok.java +++ /dev/null @@ -1,39 +0,0 @@ -package mvd.jester.simulator; - - -import mvd.jester.model.SystemSetup; -import mvd.jester.model.Task; -import mvd.jester.simulator.internals.schmidmottok.TaskContext; - -/** - * SchmidMottok - */ -public class SchmidMottok extends AbstractSimulator { - - public SchmidMottok(SystemSetup systemSetup) { - super(systemSetup); - } - - - @Override - protected boolean releaseTasks(long timeStep) { - for (Task t : systemSetup.getTasks()) { - if (timeStep % t.getPeriod() == 0) { - TaskContext tc = new TaskContext(t, systemSetup.getNumberOfProcessors(), timeStep); - if (!readyTasks.add(tc)) { - EventPrinter - .print("Time " + timeStep + ": Task " + tc + " could not be released!"); - return false; - } - EventPrinter.print("Time " + timeStep + ": Task " + tc + " released!"); - } - } - return true; - } - - - @Override - public String getName() { - return "SchmidMottok"; - } -} diff --git a/src/main/java/mvd/jester/simulator/internals/dynamicforkjoin/JobContext.java b/src/main/java/mvd/jester/simulator/internals/dynamicforkjoin/JobContext.java new file mode 100644 index 0000000..5b16ced --- /dev/null +++ b/src/main/java/mvd/jester/simulator/internals/dynamicforkjoin/JobContext.java @@ -0,0 +1,129 @@ +package mvd.jester.simulator.internals.dynamicforkjoin; + +import java.util.Optional; +import mvd.jester.simulator.EventPrinter; +import mvd.jester.simulator.internals.JobContextInterface; +import mvd.jester.simulator.internals.ProcessorContext; +import mvd.jester.simulator.internals.TaskContextInterface; + +/** + * Job + * + * @param + */ +public class JobContext implements JobContextInterface { + + private final TaskContext taskContext; + private final SegmentContext segmentContext; + private final long wcet; + private Optional currentProcessor; + private Optional currentTasklet; + + + public JobContext(TaskContext taskContext, SegmentContext segmentContext) { + this.currentProcessor = Optional.empty(); + this.currentTasklet = Optional.empty(); + this.taskContext = taskContext; + this.segmentContext = segmentContext; + this.wcet = segmentContext.getSegment().getJobWcet(); + } + + public Optional updateExecution(long time) { + boolean jobIsIdle = true; + if (currentTasklet.isPresent()) { + jobIsIdle = currentTasklet.get().updateExecution(time); + } + + if (jobIsIdle) { + currentTasklet = segmentContext.getNextTasklet(); + Optional tc = taskContext.acceptNotification(time); + + if (currentTasklet.isPresent()) { + EventPrinter.print("Time " + time + ": Job " + this + " started executing tasklet " + + currentTasklet.get() + " on Processor " + currentProcessor.get()); + currentTasklet.get().setCurrentJob(this); + } else { + if (currentProcessor.isPresent()) { + currentProcessor.get().setJob(null); + } + currentProcessor = Optional.empty(); + return tc; + } + } + + return Optional.empty(); + } + + public boolean checkExecutionTime() { + if (currentTasklet.isPresent()) { + return currentTasklet.get().checkExecutionTime(); + } + return false; + } + + /** + * @return the wcet + */ + public long getWcet() { + return wcet; + } + + /** + * @param processor the currentProcessor to set + */ + public void setCurrentProcessor(ProcessorContext processor) { + this.currentProcessor = Optional.ofNullable(processor); + } + + /** + * @return the currentProcessor + */ + public Optional getCurrentProcessor() { + return currentProcessor; + } + + /** + * @param currentTasklet the currentTasklet to set + */ + public void setCurrentTasklet(TaskletContext currentTasklet) { + this.currentTasklet = Optional.ofNullable(currentTasklet); + } + + /** + * @return the segmentContext + */ + public SegmentContext getSegmentContext() { + return segmentContext; + } + + + /** + * @return the taskContext + */ + public TaskContext getTaskContext() { + return taskContext; + } + + @Override + public String toString() { + return "(of task=" + taskContext + ")"; + } + + @Override + public boolean prepareJob(long time) { + if (!currentTasklet.isPresent()) { + currentTasklet = segmentContext.getNextTasklet(); + if (currentTasklet.isPresent()) { + currentTasklet.get().setCurrentJob(this); + // EventPrinter.print("Time " + time + ": Job " + this + " started executing + // tasklet" + // + currentTasklet.get()); + return true; + } else { + return false; + } + } + return true; + } + +} diff --git a/src/main/java/mvd/jester/simulator/internals/dynamicforkjoin/SegmentContext.java b/src/main/java/mvd/jester/simulator/internals/dynamicforkjoin/SegmentContext.java new file mode 100644 index 0000000..b5da48e --- /dev/null +++ b/src/main/java/mvd/jester/simulator/internals/dynamicforkjoin/SegmentContext.java @@ -0,0 +1,78 @@ +package mvd.jester.simulator.internals.dynamicforkjoin; + +import java.util.HashSet; +import java.util.Optional; +import java.util.Set; +import mvd.jester.model.Segment; +import mvd.jester.simulator.internals.JobContextInterface; + +/** + * Segment + */ +public class SegmentContext { + private final Segment segment; + private final Set jobs; + private final Set tasklets; + + public SegmentContext(TaskContext taskContext, Segment segment, long numberOfProcessors) { + this.segment = segment; + jobs = new HashSet<>(); + tasklets = new HashSet<>(); + + long numberOfJobs = segment.getNumberOfJobs() > numberOfProcessors ? numberOfProcessors + : segment.getNumberOfJobs(); + + for (int j = 0; j < numberOfJobs; ++j) { + jobs.add(new JobContext(taskContext, this)); + } + + for (int j = 0; j < segment.getNumberOfTasklets(); ++j) { + tasklets.add(new TaskletContext(taskContext, this)); + } + } + + + /** + * @return the segment + */ + public Segment getSegment() { + return segment; + } + + public long getNumberOfJobs() { + return jobs.size(); + } + + public Optional getNextJob() { + boolean taskletAvailable = tasklets.stream() + .anyMatch(t -> !t.getCurrentJob().isPresent() && t.checkExecutionTime()); + + boolean jobNotFinished = jobs.stream() + .anyMatch(j -> !j.getCurrentProcessor().isPresent() && j.checkExecutionTime()); + + if (jobNotFinished) { + return jobs.stream() + .filter(j -> !j.getCurrentProcessor().isPresent() && j.checkExecutionTime()) + .findFirst(); + } else if (taskletAvailable) { + return jobs.stream() + .filter(j -> !j.getCurrentProcessor().isPresent() && !j.checkExecutionTime()) + .findFirst(); + } else { + return Optional.empty(); + } + } + + public Optional getNextTasklet() { + return tasklets.stream() + .filter(t -> !t.getCurrentJob().isPresent() && t.checkExecutionTime()).findFirst(); + } + + + + @Override + public String toString() { + return "(nJobs=" + segment.getNumberOfJobs() + ", nTasklets=" + + segment.getNumberOfTasklets() + ", taskletWcet=" + segment.getTaskletWcet() + ")"; + } +} diff --git a/src/main/java/mvd/jester/simulator/internals/dynamicforkjoin/TaskContext.java b/src/main/java/mvd/jester/simulator/internals/dynamicforkjoin/TaskContext.java new file mode 100644 index 0000000..458f621 --- /dev/null +++ b/src/main/java/mvd/jester/simulator/internals/dynamicforkjoin/TaskContext.java @@ -0,0 +1,88 @@ +package mvd.jester.simulator.internals.dynamicforkjoin; + +import java.util.ArrayList; +import java.util.Optional; +import mvd.jester.model.Segment; +import mvd.jester.model.Task; +import mvd.jester.simulator.EventPrinter; +import mvd.jester.simulator.internals.JobContextInterface; +import mvd.jester.simulator.internals.TaskContextInterface; + +/** + * TaskContext + */ +public class TaskContext implements TaskContextInterface { + + private final Task task; + private final ArrayList segments; + private final long releaseTime; + private final long deadline; + private int currentSegment; + private int segmentCounter; + + + public TaskContext(Task task, long numberOfProcessors, long releaseTime) { + this.task = task; + this.segments = new ArrayList<>(); + this.currentSegment = 0; + this.segmentCounter = 0; + this.deadline = releaseTime + task.getDeadline(); + this.releaseTime = releaseTime; + + for (Segment s : task.getSegments()) { + segments.add(new SegmentContext(this, s, numberOfProcessors)); + } + } + + /** + * @return the task + */ + public Task getTask() { + return task; + } + + /** + * @return the deadline + */ + @Override + public long getDeadline() { + return deadline; + } + + @Override + public long getReleaseTime() { + return releaseTime; + } + + public Optional acceptNotification(long time) { + segmentCounter++; + + if (segmentCounter >= segments.get(currentSegment).getSegment().getNumberOfTasklets()) { + currentSegment++; + segmentCounter = 0; + if (currentSegment >= segments.size()) { + EventPrinter.print("Time " + time + ": Task " + this + "finished!"); + return Optional.of(this); + } + } + + + return Optional.empty(); + } + + public Optional getNextJob() { + if (currentSegment < segments.size()) { + return segments.get(currentSegment).getNextJob(); + } + + return Optional.empty(); + } + + + @Override + public String toString() { + return "(period=" + task.getPeriod() + ", deadline=" + deadline + ", segments=" + + segments.size() + ")"; + } + +} diff --git a/src/main/java/mvd/jester/simulator/internals/dynamicforkjoin/TaskletContext.java b/src/main/java/mvd/jester/simulator/internals/dynamicforkjoin/TaskletContext.java new file mode 100644 index 0000000..1c686a4 --- /dev/null +++ b/src/main/java/mvd/jester/simulator/internals/dynamicforkjoin/TaskletContext.java @@ -0,0 +1,61 @@ +package mvd.jester.simulator.internals.dynamicforkjoin; + +import java.util.Optional; + +/** + * Tasklet + */ +public class TaskletContext { + + private final TaskContext taskContext; + private Optional currentJob; + private final long wcet; + private long executionTime; + + + public TaskletContext(TaskContext taskContext, SegmentContext segment) { + this.taskContext = taskContext; + this.wcet = segment.getSegment().getTaskletWcet(); + this.executionTime = wcet; + currentJob = Optional.empty(); + } + + + /** + * @return the currentJob + */ + public Optional getCurrentJob() { + return currentJob; + } + + public void setCurrentJob(JobContext jobContext) { + currentJob = Optional.ofNullable(jobContext); + } + + /** + * @return true if tasklet finished, false otherwise + */ + public boolean updateExecution(long time) { + executionTime--; + + if (executionTime == 0) { + if (currentJob.isPresent()) { + currentJob.get().setCurrentTasklet(null); + } + currentJob = Optional.empty(); + return true; + } else if (executionTime < 0) { + throw new RuntimeException("Tasklet was executed for longer than its WCET!"); + } + return false; + } + + public boolean checkExecutionTime() { + return executionTime > 0; + } + + @Override + public String toString() { + return "(wcet=" + wcet + ", task=" + taskContext + ")"; + } +} diff --git a/src/main/java/mvd/jester/simulator/internals/maiabertogna/JobContext.java b/src/main/java/mvd/jester/simulator/internals/maiabertogna/JobContext.java deleted file mode 100644 index 05c7d54..0000000 --- a/src/main/java/mvd/jester/simulator/internals/maiabertogna/JobContext.java +++ /dev/null @@ -1,97 +0,0 @@ -package mvd.jester.simulator.internals.maiabertogna; - -import java.util.Optional; -import mvd.jester.simulator.EventPrinter; -import mvd.jester.simulator.internals.JobContextInterface; -import mvd.jester.simulator.internals.ProcessorContext; -import mvd.jester.simulator.internals.TaskContextInterface; - -/** - * Job - * - * @param - */ -public class JobContext implements JobContextInterface { - - private final TaskContext taskContext; - private final SegmentContext segmentContext; - private final long wcet; - private Optional currentProcessor; - private long executionTime; - - - public JobContext(TaskContext taskContext, SegmentContext segmentContext) { - this.currentProcessor = Optional.empty(); - this.taskContext = taskContext; - this.segmentContext = segmentContext; - this.wcet = segmentContext.getSegment().getJobWcet(); - this.executionTime = wcet; - } - - public Optional updateExecution(long time) { - executionTime--; - - if (executionTime == 0) { - EventPrinter.print("Time " + time + ": " + currentProcessor.get() - + " finished execution of job " + this + "!"); - currentProcessor.get().setJob(null); - currentProcessor = Optional.empty(); - return taskContext.acceptNotification(time); - } else if (executionTime < 0) { - throw new RuntimeException("Job was executed for longer than its WCET!"); - } - - return Optional.empty(); - } - - public boolean checkExecutionTime() { - return executionTime > 0; - } - - /** - * @return the wcet - */ - public long getWcet() { - return wcet; - } - - /** - * @param processor the currentProcessor to set - */ - public void setCurrentProcessor(ProcessorContext processor) { - this.currentProcessor = Optional.ofNullable(processor); - } - - /** - * @return the currentProcessor - */ - public Optional getCurrentProcessor() { - return currentProcessor; - } - - /** - * @return the segmentContext - */ - public SegmentContext getSegmentContext() { - return segmentContext; - } - - - /** - * @return the taskContext - */ - public TaskContext getTaskContext() { - return taskContext; - } - - @Override - public String toString() { - return "(jobWcet=" + wcet + ", of task=" + taskContext + ")"; - } - - @Override - public boolean prepareJob(long time) { - return true; - } - -} diff --git a/src/main/java/mvd/jester/simulator/internals/maiabertogna/SegmentContext.java b/src/main/java/mvd/jester/simulator/internals/maiabertogna/SegmentContext.java deleted file mode 100644 index d35deda..0000000 --- a/src/main/java/mvd/jester/simulator/internals/maiabertogna/SegmentContext.java +++ /dev/null @@ -1,43 +0,0 @@ -package mvd.jester.simulator.internals.maiabertogna; - -import java.util.HashSet; -import java.util.Optional; -import java.util.Set; -import mvd.jester.model.Segment; -import mvd.jester.simulator.internals.JobContextInterface; - -/** - * Segment - */ -public class SegmentContext { - private final Segment segment; - private final Set jobs; - - public SegmentContext(TaskContext taskContext, Segment segment) { - this.segment = segment; - jobs = new HashSet<>(); - - for (int j = 0; j < segment.getNumberOfJobs(); ++j) { - jobs.add(new JobContext(taskContext, this)); - } - } - - - /** - * @return the segment - */ - public Segment getSegment() { - return segment; - } - - public Optional getNextJob() { - return jobs.stream() - .filter(j -> !j.getCurrentProcessor().isPresent() && j.checkExecutionTime()) - .findFirst(); - } - - @Override - public String toString() { - return "(nJobs=" + segment.getNumberOfJobs() + ", jobWcet=" + segment.getJobWcet() + ")"; - } -} diff --git a/src/main/java/mvd/jester/simulator/internals/maiabertogna/TaskContext.java b/src/main/java/mvd/jester/simulator/internals/maiabertogna/TaskContext.java deleted file mode 100644 index adfab81..0000000 --- a/src/main/java/mvd/jester/simulator/internals/maiabertogna/TaskContext.java +++ /dev/null @@ -1,87 +0,0 @@ -package mvd.jester.simulator.internals.maiabertogna; - -import java.util.ArrayList; -import java.util.Optional; -import mvd.jester.model.Segment; -import mvd.jester.model.Task; -import mvd.jester.simulator.EventPrinter; -import mvd.jester.simulator.internals.JobContextInterface; -import mvd.jester.simulator.internals.TaskContextInterface; - -/** - * TaskContext - */ -public class TaskContext implements TaskContextInterface { - - private final Task task; - private final ArrayList segments; - private final long deadline; - private final long releaseTime; - private int currentSegment; - private int segmentCounter; - - - public TaskContext(Task task, long releaseTime) { - this.task = task; - this.segments = new ArrayList<>(); - this.currentSegment = 0; - this.segmentCounter = 0; - this.releaseTime = releaseTime; - this.deadline = releaseTime + task.getDeadline(); - - for (Segment s : task.getSegments()) { - segments.add(new SegmentContext(this, s)); - } - } - - /** - * @return the task - */ - public Task getTask() { - return task; - } - - /** - * @return the deadline - */ - @Override - public long getDeadline() { - return deadline; - } - - @Override - public long getReleaseTime() { - return releaseTime; - } - - public Optional acceptNotification(long time) { - segmentCounter++; - - if (segmentCounter >= segments.get(currentSegment).getSegment().getNumberOfJobs()) { - currentSegment++; - segmentCounter = 0; - if (currentSegment >= segments.size()) { - EventPrinter.print("Time " + time + ": Task " + this + "finished!"); - return Optional.of(this); - } - } - - - return Optional.empty(); - } - - public Optional getNextJob() { - if (currentSegment < segments.size()) { - return segments.get(currentSegment).getNextJob(); - } - - return Optional.empty(); - } - - - @Override - public String toString() { - return "(period=" + task.getPeriod() + ", deadline=" + deadline + ", segments=" - + segments.size() + ")"; - } -} diff --git a/src/main/java/mvd/jester/simulator/internals/parallelsynchronous/JobContext.java b/src/main/java/mvd/jester/simulator/internals/parallelsynchronous/JobContext.java new file mode 100644 index 0000000..da92104 --- /dev/null +++ b/src/main/java/mvd/jester/simulator/internals/parallelsynchronous/JobContext.java @@ -0,0 +1,97 @@ +package mvd.jester.simulator.internals.parallelsynchronous; + +import java.util.Optional; +import mvd.jester.simulator.EventPrinter; +import mvd.jester.simulator.internals.JobContextInterface; +import mvd.jester.simulator.internals.ProcessorContext; +import mvd.jester.simulator.internals.TaskContextInterface; + +/** + * Job + * + * @param + */ +public class JobContext implements JobContextInterface { + + private final TaskContext taskContext; + private final SegmentContext segmentContext; + private final long wcet; + private Optional currentProcessor; + private long executionTime; + + + public JobContext(TaskContext taskContext, SegmentContext segmentContext) { + this.currentProcessor = Optional.empty(); + this.taskContext = taskContext; + this.segmentContext = segmentContext; + this.wcet = segmentContext.getSegment().getJobWcet(); + this.executionTime = wcet; + } + + public Optional updateExecution(long time) { + executionTime--; + + if (executionTime == 0) { + EventPrinter.print("Time " + time + ": " + currentProcessor.get() + + " finished execution of job " + this + "!"); + currentProcessor.get().setJob(null); + currentProcessor = Optional.empty(); + return taskContext.acceptNotification(time); + } else if (executionTime < 0) { + throw new RuntimeException("Job was executed for longer than its WCET!"); + } + + return Optional.empty(); + } + + public boolean checkExecutionTime() { + return executionTime > 0; + } + + /** + * @return the wcet + */ + public long getWcet() { + return wcet; + } + + /** + * @param processor the currentProcessor to set + */ + public void setCurrentProcessor(ProcessorContext processor) { + this.currentProcessor = Optional.ofNullable(processor); + } + + /** + * @return the currentProcessor + */ + public Optional getCurrentProcessor() { + return currentProcessor; + } + + /** + * @return the segmentContext + */ + public SegmentContext getSegmentContext() { + return segmentContext; + } + + + /** + * @return the taskContext + */ + public TaskContext getTaskContext() { + return taskContext; + } + + @Override + public String toString() { + return "(jobWcet=" + wcet + ", of task=" + taskContext + ")"; + } + + @Override + public boolean prepareJob(long time) { + return true; + } + +} diff --git a/src/main/java/mvd/jester/simulator/internals/parallelsynchronous/SegmentContext.java b/src/main/java/mvd/jester/simulator/internals/parallelsynchronous/SegmentContext.java new file mode 100644 index 0000000..b03d8f1 --- /dev/null +++ b/src/main/java/mvd/jester/simulator/internals/parallelsynchronous/SegmentContext.java @@ -0,0 +1,43 @@ +package mvd.jester.simulator.internals.parallelsynchronous; + +import java.util.HashSet; +import java.util.Optional; +import java.util.Set; +import mvd.jester.model.Segment; +import mvd.jester.simulator.internals.JobContextInterface; + +/** + * Segment + */ +public class SegmentContext { + private final Segment segment; + private final Set jobs; + + public SegmentContext(TaskContext taskContext, Segment segment) { + this.segment = segment; + jobs = new HashSet<>(); + + for (int j = 0; j < segment.getNumberOfJobs(); ++j) { + jobs.add(new JobContext(taskContext, this)); + } + } + + + /** + * @return the segment + */ + public Segment getSegment() { + return segment; + } + + public Optional getNextJob() { + return jobs.stream() + .filter(j -> !j.getCurrentProcessor().isPresent() && j.checkExecutionTime()) + .findFirst(); + } + + @Override + public String toString() { + return "(nJobs=" + segment.getNumberOfJobs() + ", jobWcet=" + segment.getJobWcet() + ")"; + } +} diff --git a/src/main/java/mvd/jester/simulator/internals/parallelsynchronous/TaskContext.java b/src/main/java/mvd/jester/simulator/internals/parallelsynchronous/TaskContext.java new file mode 100644 index 0000000..a25ffb4 --- /dev/null +++ b/src/main/java/mvd/jester/simulator/internals/parallelsynchronous/TaskContext.java @@ -0,0 +1,86 @@ +package mvd.jester.simulator.internals.parallelsynchronous; + +import java.util.ArrayList; +import java.util.Optional; +import mvd.jester.model.Segment; +import mvd.jester.model.Task; +import mvd.jester.simulator.EventPrinter; +import mvd.jester.simulator.internals.JobContextInterface; +import mvd.jester.simulator.internals.TaskContextInterface; + +/** + * TaskContext + */ +public class TaskContext implements TaskContextInterface { + + private final Task task; + private final ArrayList segments; + private final long deadline; + private final long releaseTime; + private int currentSegment; + private int segmentCounter; + + public TaskContext(Task task, long releaseTime) { + this.task = task; + this.segments = new ArrayList<>(); + this.currentSegment = 0; + this.segmentCounter = 0; + this.releaseTime = releaseTime; + this.deadline = releaseTime + task.getDeadline(); + + for (Segment s : task.getSegments()) { + segments.add(new SegmentContext(this, s)); + } + } + + /** + * @return the task + */ + public Task getTask() { + return task; + } + + /** + * @return the deadline + */ + @Override + public long getDeadline() { + return deadline; + } + + @Override + public long getReleaseTime() { + return releaseTime; + } + + public Optional acceptNotification(long time) { + segmentCounter++; + + if (segmentCounter >= segments.get(currentSegment).getSegment().getNumberOfJobs()) { + currentSegment++; + segmentCounter = 0; + if (currentSegment >= segments.size()) { + EventPrinter.print("Time " + time + ": Task " + this + "finished!"); + return Optional.of(this); + } + } + + + return Optional.empty(); + } + + public Optional getNextJob() { + if (currentSegment < segments.size()) { + return segments.get(currentSegment).getNextJob(); + } + + return Optional.empty(); + } + + + @Override + public String toString() { + return "(period=" + task.getPeriod() + ", deadline=" + deadline + ", segments=" + + segments.size() + ")"; + } +} diff --git a/src/main/java/mvd/jester/simulator/internals/schmidmottok/JobContext.java b/src/main/java/mvd/jester/simulator/internals/schmidmottok/JobContext.java deleted file mode 100644 index 4a71c5e..0000000 --- a/src/main/java/mvd/jester/simulator/internals/schmidmottok/JobContext.java +++ /dev/null @@ -1,129 +0,0 @@ -package mvd.jester.simulator.internals.schmidmottok; - -import java.util.Optional; -import mvd.jester.simulator.EventPrinter; -import mvd.jester.simulator.internals.JobContextInterface; -import mvd.jester.simulator.internals.ProcessorContext; -import mvd.jester.simulator.internals.TaskContextInterface; - -/** - * Job - * - * @param - */ -public class JobContext implements JobContextInterface { - - private final TaskContext taskContext; - private final SegmentContext segmentContext; - private final long wcet; - private Optional currentProcessor; - private Optional currentTasklet; - - - public JobContext(TaskContext taskContext, SegmentContext segmentContext) { - this.currentProcessor = Optional.empty(); - this.currentTasklet = Optional.empty(); - this.taskContext = taskContext; - this.segmentContext = segmentContext; - this.wcet = segmentContext.getSegment().getJobWcet(); - } - - public Optional updateExecution(long time) { - boolean jobIsIdle = true; - if (currentTasklet.isPresent()) { - jobIsIdle = currentTasklet.get().updateExecution(time); - } - - if (jobIsIdle) { - currentTasklet = segmentContext.getNextTasklet(); - Optional tc = taskContext.acceptNotification(time); - - if (currentTasklet.isPresent()) { - EventPrinter.print("Time " + time + ": Job " + this + " started executing tasklet " - + currentTasklet.get() + " on Processor " + currentProcessor.get()); - currentTasklet.get().setCurrentJob(this); - } else { - if (currentProcessor.isPresent()) { - currentProcessor.get().setJob(null); - } - currentProcessor = Optional.empty(); - return tc; - } - } - - return Optional.empty(); - } - - public boolean checkExecutionTime() { - if (currentTasklet.isPresent()) { - return currentTasklet.get().checkExecutionTime(); - } - return false; - } - - /** - * @return the wcet - */ - public long getWcet() { - return wcet; - } - - /** - * @param processor the currentProcessor to set - */ - public void setCurrentProcessor(ProcessorContext processor) { - this.currentProcessor = Optional.ofNullable(processor); - } - - /** - * @return the currentProcessor - */ - public Optional getCurrentProcessor() { - return currentProcessor; - } - - /** - * @param currentTasklet the currentTasklet to set - */ - public void setCurrentTasklet(TaskletContext currentTasklet) { - this.currentTasklet = Optional.ofNullable(currentTasklet); - } - - /** - * @return the segmentContext - */ - public SegmentContext getSegmentContext() { - return segmentContext; - } - - - /** - * @return the taskContext - */ - public TaskContext getTaskContext() { - return taskContext; - } - - @Override - public String toString() { - return "(of task=" + taskContext + ")"; - } - - @Override - public boolean prepareJob(long time) { - if (!currentTasklet.isPresent()) { - currentTasklet = segmentContext.getNextTasklet(); - if (currentTasklet.isPresent()) { - currentTasklet.get().setCurrentJob(this); - // EventPrinter.print("Time " + time + ": Job " + this + " started executing - // tasklet" - // + currentTasklet.get()); - return true; - } else { - return false; - } - } - return true; - } - -} diff --git a/src/main/java/mvd/jester/simulator/internals/schmidmottok/SegmentContext.java b/src/main/java/mvd/jester/simulator/internals/schmidmottok/SegmentContext.java deleted file mode 100644 index 884de1e..0000000 --- a/src/main/java/mvd/jester/simulator/internals/schmidmottok/SegmentContext.java +++ /dev/null @@ -1,78 +0,0 @@ -package mvd.jester.simulator.internals.schmidmottok; - -import java.util.HashSet; -import java.util.Optional; -import java.util.Set; -import mvd.jester.model.Segment; -import mvd.jester.simulator.internals.JobContextInterface; - -/** - * Segment - */ -public class SegmentContext { - private final Segment segment; - private final Set jobs; - private final Set tasklets; - - public SegmentContext(TaskContext taskContext, Segment segment, long numberOfProcessors) { - this.segment = segment; - jobs = new HashSet<>(); - tasklets = new HashSet<>(); - - long numberOfJobs = segment.getNumberOfJobs() > numberOfProcessors ? numberOfProcessors - : segment.getNumberOfJobs(); - - for (int j = 0; j < numberOfJobs; ++j) { - jobs.add(new JobContext(taskContext, this)); - } - - for (int j = 0; j < segment.getNumberOfTasklets(); ++j) { - tasklets.add(new TaskletContext(taskContext, this)); - } - } - - - /** - * @return the segment - */ - public Segment getSegment() { - return segment; - } - - public long getNumberOfJobs() { - return jobs.size(); - } - - public Optional getNextJob() { - boolean taskletAvailable = tasklets.stream() - .anyMatch(t -> !t.getCurrentJob().isPresent() && t.checkExecutionTime()); - - boolean jobNotFinished = jobs.stream() - .anyMatch(j -> !j.getCurrentProcessor().isPresent() && j.checkExecutionTime()); - - if (jobNotFinished) { - return jobs.stream() - .filter(j -> !j.getCurrentProcessor().isPresent() && j.checkExecutionTime()) - .findFirst(); - } else if (taskletAvailable) { - return jobs.stream() - .filter(j -> !j.getCurrentProcessor().isPresent() && !j.checkExecutionTime()) - .findFirst(); - } else { - return Optional.empty(); - } - } - - public Optional getNextTasklet() { - return tasklets.stream() - .filter(t -> !t.getCurrentJob().isPresent() && t.checkExecutionTime()).findFirst(); - } - - - - @Override - public String toString() { - return "(nJobs=" + segment.getNumberOfJobs() + ", nTasklets=" - + segment.getNumberOfTasklets() + ", taskletWcet=" + segment.getTaskletWcet() + ")"; - } -} diff --git a/src/main/java/mvd/jester/simulator/internals/schmidmottok/TaskContext.java b/src/main/java/mvd/jester/simulator/internals/schmidmottok/TaskContext.java deleted file mode 100644 index 587c0cb..0000000 --- a/src/main/java/mvd/jester/simulator/internals/schmidmottok/TaskContext.java +++ /dev/null @@ -1,88 +0,0 @@ -package mvd.jester.simulator.internals.schmidmottok; - -import java.util.ArrayList; -import java.util.Optional; -import mvd.jester.model.Segment; -import mvd.jester.model.Task; -import mvd.jester.simulator.EventPrinter; -import mvd.jester.simulator.internals.JobContextInterface; -import mvd.jester.simulator.internals.TaskContextInterface; - -/** - * TaskContext - */ -public class TaskContext implements TaskContextInterface { - - private final Task task; - private final ArrayList segments; - private final long releaseTime; - private final long deadline; - private int currentSegment; - private int segmentCounter; - - - public TaskContext(Task task, long numberOfProcessors, long releaseTime) { - this.task = task; - this.segments = new ArrayList<>(); - this.currentSegment = 0; - this.segmentCounter = 0; - this.deadline = releaseTime + task.getDeadline(); - this.releaseTime = releaseTime; - - for (Segment s : task.getSegments()) { - segments.add(new SegmentContext(this, s, numberOfProcessors)); - } - } - - /** - * @return the task - */ - public Task getTask() { - return task; - } - - /** - * @return the deadline - */ - @Override - public long getDeadline() { - return deadline; - } - - @Override - public long getReleaseTime() { - return releaseTime; - } - - public Optional acceptNotification(long time) { - segmentCounter++; - - if (segmentCounter >= segments.get(currentSegment).getSegment().getNumberOfTasklets()) { - currentSegment++; - segmentCounter = 0; - if (currentSegment >= segments.size()) { - EventPrinter.print("Time " + time + ": Task " + this + "finished!"); - return Optional.of(this); - } - } - - - return Optional.empty(); - } - - public Optional getNextJob() { - if (currentSegment < segments.size()) { - return segments.get(currentSegment).getNextJob(); - } - - return Optional.empty(); - } - - - @Override - public String toString() { - return "(period=" + task.getPeriod() + ", deadline=" + deadline + ", segments=" - + segments.size() + ")"; - } - -} diff --git a/src/main/java/mvd/jester/simulator/internals/schmidmottok/TaskletContext.java b/src/main/java/mvd/jester/simulator/internals/schmidmottok/TaskletContext.java deleted file mode 100644 index d3c43e9..0000000 --- a/src/main/java/mvd/jester/simulator/internals/schmidmottok/TaskletContext.java +++ /dev/null @@ -1,61 +0,0 @@ -package mvd.jester.simulator.internals.schmidmottok; - -import java.util.Optional; - -/** - * Tasklet - */ -public class TaskletContext { - - private final TaskContext taskContext; - private Optional currentJob; - private final long wcet; - private long executionTime; - - - public TaskletContext(TaskContext taskContext, SegmentContext segment) { - this.taskContext = taskContext; - this.wcet = segment.getSegment().getTaskletWcet(); - this.executionTime = wcet; - currentJob = Optional.empty(); - } - - - /** - * @return the currentJob - */ - public Optional getCurrentJob() { - return currentJob; - } - - public void setCurrentJob(JobContext jobContext) { - currentJob = Optional.ofNullable(jobContext); - } - - /** - * @return true if tasklet finished, false otherwise - */ - public boolean updateExecution(long time) { - executionTime--; - - if (executionTime == 0) { - if (currentJob.isPresent()) { - currentJob.get().setCurrentTasklet(null); - } - currentJob = Optional.empty(); - return true; - } else if (executionTime < 0) { - throw new RuntimeException("Tasklet was executed for longer than its WCET!"); - } - return false; - } - - public boolean checkExecutionTime() { - return executionTime > 0; - } - - @Override - public String toString() { - return "(wcet=" + wcet + ", task=" + taskContext + ")"; - } -} diff --git a/src/main/java/mvd/jester/tests/AbstractTest.java b/src/main/java/mvd/jester/tests/AbstractTest.java index d8cd647..640453a 100644 --- a/src/main/java/mvd/jester/tests/AbstractTest.java +++ b/src/main/java/mvd/jester/tests/AbstractTest.java @@ -2,7 +2,6 @@ package mvd.jester.tests; import java.util.HashMap; import java.util.Map; -import java.util.Set; import mvd.jester.TypeInterface; import mvd.jester.info.TerminationInfo; import mvd.jester.model.SystemSetup; @@ -15,12 +14,10 @@ public abstract class AbstractTest implements TestInterface, TypeInterface { protected final Map responseTimes; protected final SystemSetup systemSetup; - protected Set tasks; public AbstractTest(SystemSetup systemSetup) { this.systemSetup = systemSetup; this.responseTimes = new HashMap<>(); - this.tasks = systemSetup.getTasks(); } } diff --git a/src/main/java/mvd/jester/tests/ChwaLee.java b/src/main/java/mvd/jester/tests/ChwaLee.java index e3bb107..5f04895 100644 --- a/src/main/java/mvd/jester/tests/ChwaLee.java +++ b/src/main/java/mvd/jester/tests/ChwaLee.java @@ -5,9 +5,11 @@ import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; import java.util.List; +import java.util.Set; import com.google.common.math.LongMath; import mvd.jester.info.SchedulingInfo; import mvd.jester.info.TerminationInfo; +import mvd.jester.info.TerminationInfo.Level; import mvd.jester.model.Segment; import mvd.jester.model.SortedTaskSet; import mvd.jester.model.SystemSetup; @@ -25,19 +27,20 @@ public class ChwaLee extends AbstractTest { @Override public SchedulingInfo runSchedulabilityCheck(PriorityManager priorityManager) { - tasks = new SortedTaskSet(priorityManager); + SortedTaskSet tasks = new SortedTaskSet(priorityManager); tasks.addAll(systemSetup.getTasks()); responseTimes.clear(); for (Task t : tasks) { - long responseTime = calculateResponseTime(t); - responseTimes.put(t, new TerminationInfo(0, t.getDeadline(), responseTime)); + Level taskLevel = tasks.headSet(t).size() <= tasks.size() / 2 ? Level.HIGH : Level.LOW; + long responseTime = calculateResponseTime(tasks, t); + responseTimes.put(t, new TerminationInfo(t.getDeadline(), responseTime, taskLevel)); } return new SchedulingInfo(new HashSet<>(responseTimes.values()), systemSetup.getParallelTaskRatio(), systemSetup.getUtilization()); } - private long calculateResponseTime(Task task) { + private long calculateResponseTime(Set tasks, Task task) { long minimumWcet = getMinimumWcet(task); long deadline = task.getDeadline(); long numberOfProcessors = systemSetup.getNumberOfProcessors(); diff --git a/src/main/java/mvd/jester/tests/MaiaBertogna.java b/src/main/java/mvd/jester/tests/MaiaBertogna.java index 0b29619..d57be1a 100644 --- a/src/main/java/mvd/jester/tests/MaiaBertogna.java +++ b/src/main/java/mvd/jester/tests/MaiaBertogna.java @@ -2,9 +2,11 @@ package mvd.jester.tests; import java.math.RoundingMode; import java.util.HashSet; +import java.util.Set; import com.google.common.math.LongMath; import mvd.jester.info.SchedulingInfo; import mvd.jester.info.TerminationInfo; +import mvd.jester.info.TerminationInfo.Level; import mvd.jester.model.Segment; import mvd.jester.model.SortedTaskSet; import mvd.jester.model.Task; @@ -22,12 +24,13 @@ public class MaiaBertogna extends AbstractTest { @Override public SchedulingInfo runSchedulabilityCheck(PriorityManager priorityManager) { - tasks = new SortedTaskSet(priorityManager); + SortedTaskSet tasks = new SortedTaskSet(priorityManager); tasks.addAll(systemSetup.getTasks()); responseTimes.clear(); for (Task t : tasks) { - long responseTime = calculateResponseTime(t); - responseTimes.put(t, new TerminationInfo(0, t.getDeadline(), responseTime)); + Level taskLevel = tasks.headSet(t).size() <= tasks.size() / 2 ? Level.HIGH : Level.LOW; + long responseTime = calculateResponseTime(tasks, t); + responseTimes.put(t, new TerminationInfo(t.getDeadline(), responseTime, taskLevel)); } return new SchedulingInfo(new HashSet<>(responseTimes.values()), @@ -39,7 +42,7 @@ public class MaiaBertogna extends AbstractTest { return "MaiaBertogna"; } - private long calculateResponseTime(Task task) { + private long calculateResponseTime(Set tasks, Task task) { long minimumWcet = getMinimumWcet(task); long responseTime = minimumWcet; long previousResponseTime = 0; diff --git a/src/main/java/mvd/jester/tests/SchmidMottok.java b/src/main/java/mvd/jester/tests/SchmidMottok.java index edc0a1a..c4f5a86 100644 --- a/src/main/java/mvd/jester/tests/SchmidMottok.java +++ b/src/main/java/mvd/jester/tests/SchmidMottok.java @@ -2,9 +2,11 @@ package mvd.jester.tests; import java.math.RoundingMode; import java.util.HashSet; +import java.util.Set; import com.google.common.math.LongMath; import mvd.jester.info.SchedulingInfo; import mvd.jester.info.TerminationInfo; +import mvd.jester.info.TerminationInfo.Level; import mvd.jester.model.Segment; import mvd.jester.model.SortedTaskSet; import mvd.jester.model.Task; @@ -22,12 +24,13 @@ public class SchmidMottok extends AbstractTest { @Override public SchedulingInfo runSchedulabilityCheck(PriorityManager priorityManager) { - tasks = new SortedTaskSet(priorityManager); + SortedTaskSet tasks = new SortedTaskSet(priorityManager); tasks.addAll(systemSetup.getTasks()); responseTimes.clear(); for (Task t : tasks) { - long responseTime = calculateResponseTime(t); - responseTimes.put(t, new TerminationInfo(0, t.getDeadline(), responseTime)); + Level taskLevel = tasks.headSet(t).size() <= tasks.size() / 2 ? Level.HIGH : Level.LOW; + long responseTime = calculateResponseTime(tasks, t); + responseTimes.put(t, new TerminationInfo(t.getDeadline(), responseTime, taskLevel)); } return new SchedulingInfo(new HashSet<>(responseTimes.values()), @@ -39,7 +42,7 @@ public class SchmidMottok extends AbstractTest { return "SchmidMottok"; } - private long calculateResponseTime(Task task) { + private long calculateResponseTime(Set tasks, Task task) { long minimumWcet = getMinimumWcet(task); long responseTime = minimumWcet; long previousResponseTime = 0; diff --git a/src/main/java/mvd/jester/utils/Logger.java b/src/main/java/mvd/jester/utils/Logger.java index f82b9e2..03b1672 100644 --- a/src/main/java/mvd/jester/utils/Logger.java +++ b/src/main/java/mvd/jester/utils/Logger.java @@ -31,10 +31,10 @@ public class Logger { public void finalize() { try { if (printWriter != null) { - printWriter.close(); // Will close bw and fw too + printWriter.close(); } if (bufferedWriter != null) { - bufferedWriter.close(); // Will close fw too + bufferedWriter.close(); } if (fileWriter != null) { fileWriter.close(); diff --git a/src/test/java/mvd/jester/TestResultCollector.java b/src/test/java/mvd/jester/TestResultCollector.java new file mode 100644 index 0000000..5a91c76 --- /dev/null +++ b/src/test/java/mvd/jester/TestResultCollector.java @@ -0,0 +1,62 @@ +package mvd.jester; + +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.HashSet; +import java.util.Set; +import java.util.concurrent.ThreadLocalRandom; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import mvd.jester.info.SchedulingInfo; +import mvd.jester.priority.PriorityManager; + +/** + * TestResultCollector + */ +public class TestResultCollector { + + @Test + @DisplayName("Test if getters and setters work correctly.") + void testGettersAndSetters() { + final PriorityManager pm = mock(PriorityManager.class); + final String pmName = "PriorityManagerName"; + when(pm.getName()).thenReturn(pmName); + + final TypeInterface ti = mock(TypeInterface.class); + final String tiName = "TypeInterfaceName"; + when(ti.getName()).thenReturn(tiName); + + final ResultCollector rc1 = new ResultCollector<>(pm, ti); + final ResultCollector rc2 = new ResultCollector<>(pm, ti); + + assertTrue(rc1.getPriorityManager() == pm); + assertTrue(rc1.getAbstractValue() == ti); + assertTrue(rc1.getName().equals(tiName + "_" + pmName)); + assertTrue(rc1.compareTo(rc2) == 0); + } + + @Test + @DisplayName("Check if adding SchedulingInfos works correctly.") + void testSchedulingInfos() { + final TypeInterface ti = mock(TypeInterface.class); + final PriorityManager pm = mock(PriorityManager.class); + + final ResultCollector rc = new ResultCollector<>(pm, ti); + + final Set schedulingInfos = new HashSet<>(); + + long numberOfSchedulingInfos = ThreadLocalRandom.current().nextLong(5, 10); + for (int i = 0; i < numberOfSchedulingInfos; ++i) { + SchedulingInfo si = mock(SchedulingInfo.class); + schedulingInfos.add(si); + assertTrue(rc.addResult(si)); + assertFalse(rc.addResult(si)); + } + + assertTrue(rc.getResults().size() == numberOfSchedulingInfos); + assertTrue(rc.getResults().equals(schedulingInfos)); + assertTrue(rc.addResult(null)); + } +} diff --git a/src/test/java/mvd/jester/info/TestSchedulingInfo.java b/src/test/java/mvd/jester/info/TestSchedulingInfo.java new file mode 100644 index 0000000..f46045f --- /dev/null +++ b/src/test/java/mvd/jester/info/TestSchedulingInfo.java @@ -0,0 +1,79 @@ +package mvd.jester.info; + +import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.mock; +import java.util.HashSet; +import java.util.Set; +import java.util.concurrent.ThreadLocalRandom; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import mvd.jester.info.TerminationInfo.Level; + +/** + * TestTerminationInfo + */ +public class TestSchedulingInfo { + + @Test + @DisplayName("Check if SchedulingInfos parameters are calculated correctly.") + public void testSchedulingInfo() { + for (int run = 0; run < 1000; ++run) { + Set terminationInfos = new HashSet<>(); + int numberOfTerminationInfos = ThreadLocalRandom.current().nextInt(5, 10); + boolean feasibile = true; + boolean levelFailed = false; + for (int i = 0; i < numberOfTerminationInfos; ++i) { + long deadline = ThreadLocalRandom.current().nextLong(50, 100); + long responseTime = ThreadLocalRandom.current().nextLong(50, 100); + Level taskLevel = + ThreadLocalRandom.current().nextLong(0, 100) < 50 ? Level.LOW : Level.HIGH; + terminationInfos.add(new TerminationInfo(deadline, responseTime, taskLevel)); + + if (deadline < responseTime) { + feasibile = false; + if (taskLevel == Level.HIGH) { + levelFailed = true; + } + } + + } + + SchedulingInfo schedulingInfo = + new SchedulingInfo(terminationInfos, 2, numberOfTerminationInfos); + + assertTrue(schedulingInfo.checkLevelFail(Level.HIGH) == levelFailed); + assertTrue(schedulingInfo.checkTasksetFeasible() == feasibile); + } + } + + @Test + @DisplayName("Check Getters and Setters.") + public void testGettersAndSetters() { + double taskRatio = 0.23; + double utilization = 0.49; + SchedulingInfo si = new SchedulingInfo(taskRatio, utilization); + + Set terminationInfos = new HashSet<>(); + long numberOfTerminationInfos = ThreadLocalRandom.current().nextLong(5, 10); + for (int i = 0; i < numberOfTerminationInfos; ++i) { + TerminationInfo ti = mock(TerminationInfo.class); + terminationInfos.add(ti); + assertTrue(si.addTerminationInfo(ti)); + assertFalse(si.addTerminationInfo(ti)); + } + + assertTrue(si.getParallelTaskRatio() == taskRatio); + assertTrue(si.getUtilization() == utilization); + assertTrue(si.getTerminationInfos().size() == numberOfTerminationInfos); + assertTrue(si.getTerminationInfos().equals(terminationInfos)); + assertTrue(si.addTerminationInfo(null)); + assertFalse(si.getFailedTerminationInfo().isPresent()); + + TerminationInfo ti = mock(TerminationInfo.class); + si.setFailedTerminationInfo(ti); + assertTrue(si.getFailedTerminationInfo().isPresent()); + assertTrue(si.getFailedTerminationInfo().get().equals(ti)); + } + +} diff --git a/src/test/java/mvd/jester/info/TestTerminationInfo.java b/src/test/java/mvd/jester/info/TestTerminationInfo.java new file mode 100644 index 0000000..1150dc6 --- /dev/null +++ b/src/test/java/mvd/jester/info/TestTerminationInfo.java @@ -0,0 +1,40 @@ +package mvd.jester.info; + +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import mvd.jester.info.TerminationInfo.Level; + +/** + * TestTerminationInfo + */ +public class TestTerminationInfo { + + @Test + @DisplayName("Check Getters and Setters") + public void testGettersAndSetters() { + long releaseTime = 20; + long deadline = 40; + long responseTime = 30; + Level taskLevel = Level.LOW; + + TerminationInfo ti = new TerminationInfo(releaseTime, deadline, responseTime); + TerminationInfo til = new TerminationInfo(deadline, responseTime, taskLevel); + TerminationInfo tirl = new TerminationInfo(releaseTime, deadline, responseTime, taskLevel); + + + assertTrue(ti.getDeadline() == deadline); + assertTrue(til.getDeadline() == deadline); + assertTrue(tirl.getDeadline() == deadline); + assertTrue(ti.getResponseTime() == responseTime); + assertTrue(til.getResponseTime() == responseTime); + assertTrue(tirl.getResponseTime() == responseTime); + assertTrue(ti.getReleaseTime() == releaseTime); + assertTrue(tirl.getReleaseTime() == releaseTime); + assertTrue(til.getTaskLevel() == taskLevel); + assertTrue(tirl.getTaskLevel() == taskLevel); + assertTrue(ti.getLateness() == responseTime - deadline); + assertTrue(til.getLateness() == responseTime - deadline); + assertTrue(tirl.getLateness() == responseTime - deadline); + } +} diff --git a/src/test/java/mvd/jester/model/TestSystemSetup.java b/src/test/java/mvd/jester/model/TestSystemSetup.java index c39c803..711e90b 100644 --- a/src/test/java/mvd/jester/model/TestSystemSetup.java +++ b/src/test/java/mvd/jester/model/TestSystemSetup.java @@ -1,23 +1,40 @@ package mvd.jester.model; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.mock; +import java.io.IOException; +import java.util.Set; +import java.util.concurrent.ThreadLocalRandom; +import org.junit.Rule; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import org.junit.rules.TemporaryFolder; public class TestSystemSetup { + @Rule + public TemporaryFolder tf = new TemporaryFolder(); - private static final int NUMBER_OF_SETS = 1000; + 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_SETS; ++i) { - SystemSetup taskSet = new SystemSetup.Builder().setNumberOfSegments(1, 7) - .setNumberOfJobs(2, 10).setPeriods(100, 1000, 1000).build(); + for (int i = 0; i < NUMBER_OF_RUNS; ++i) { + long numberOfProcessors = ThreadLocalRandom.current().nextLong(2, 8); + SystemSetup.Builder systemSetupBuilder = new SystemSetup.Builder()// + .setNumberOfSegments(1, 7)// + .setNumberOfJobs(2, 10)// + .setPeriods(100, 1000, 1000)// + .setNumberOfProcessors(numberOfProcessors); - for (Task t : taskSet.getTasks()) { + SystemSetup systemSetup = systemSetupBuilder.build(); + + assertTrue(systemSetup.getNumberOfProcessors() == numberOfProcessors); + + for (Task t : systemSetup.getTasks()) { assertTrue(t.getPeriod() >= 100); assertTrue(t.getPeriod() <= 1000); assertTrue(t.getDeadline() == t.getPeriod()); @@ -35,8 +52,39 @@ public class TestSystemSetup { assertTrue(t.getSegments().size() >= 1); assertTrue(t.getSegments().size() <= 7); + } + + assertTrue(systemSetupBuilder.addTask(systemSetup)); + + Set tasks = systemSetup.getTasks(); + systemSetupBuilder.rebuild(systemSetup); + assertFalse(tasks == systemSetup.getTasks()); } + } + @Test + @DisplayName("Check Getters and Setters.") + void testGettersAndSetters() { + @SuppressWarnings("unchecked") + Set t1 = mock(Set.class); + + @SuppressWarnings("unchecked") + Set t2 = mock(Set.class); + + SystemSetup systemSetup = new SystemSetup(t1, 2); + + systemSetup.setTasks(t2); + assertTrue(systemSetup.getTasks() == t2); } + + // @Test + // @DisplayName("Check if parser works correclty.") + // void testParser() throws IOException { + // SystemSetup systemSetup = new SystemSetup.Builder().setNumberOfSegments(1, 7) + // .setNumberOfJobs(2, 10).setPeriods(100, 1000, 1000).build(); + + // systemSetup.writeToFile(null); + // systemSetup.writeToFile(tf.getRoot().getAbsolutePath()); + // } } diff --git a/src/test/java/mvd/jester/priority/TestEarliestDeadlineFirst.java b/src/test/java/mvd/jester/priority/TestEarliestDeadlineFirst.java index dee0483..6a79a6c 100644 --- a/src/test/java/mvd/jester/priority/TestEarliestDeadlineFirst.java +++ b/src/test/java/mvd/jester/priority/TestEarliestDeadlineFirst.java @@ -1,11 +1,19 @@ package mvd.jester.priority; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -import java.util.HashSet; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import mvd.jester.model.SystemSetup; import mvd.jester.model.Task; -import mvd.jester.simulator.internals.maiabertogna.TaskContext; +import mvd.jester.simulator.DynamicForkJoin; +import mvd.jester.simulator.ParallelSynchronous; +import mvd.jester.simulator.internals.parallelsynchronous.TaskContext; +import mvd.jester.tests.ChwaLee; +import mvd.jester.tests.MaiaBertogna; +import mvd.jester.tests.SchmidMottok; /** * TestEarliestDeadlineFirst @@ -16,13 +24,43 @@ public class TestEarliestDeadlineFirst { @DisplayName("Test if priority manager returns the correct priority.") public void testPriority() { EarliestDeadlineFirst edf = new EarliestDeadlineFirst(); - Task t1 = new Task(100, new HashSet<>()); - Task t2 = new Task(200, new HashSet<>()); - TaskContext tc1 = new TaskContext(t1, 0); - TaskContext tc2 = new TaskContext(t2, 0); + Task t1 = mock(Task.class); + Task t2 = mock(Task.class); + when(t1.getDeadline()).thenReturn((long) 100); + when(t2.getDeadline()).thenReturn((long) 200); + + TaskContext tc1 = mock(TaskContext.class); + TaskContext tc2 = mock(TaskContext.class); + when(tc1.getDeadline()).thenReturn((long) 100); + when(tc2.getDeadline()).thenReturn((long) 200); assertTrue(edf.compare(t1, t2) < 0); assertTrue(edf.compare(tc1, tc2) < 0); + assertTrue(edf.compare(t1, t1) == 0); + assertTrue(edf.compare(tc1, tc1) == 0); + assertTrue(edf.compare(t2, t1) > 0); + assertTrue(edf.compare(tc2, tc1) > 0); } + + + @Test + @DisplayName("Check Getters, Tests and Simulators.") + void testGettersTestsAndSimulators() { + EarliestDeadlineFirst edf = new EarliestDeadlineFirst(); + assertTrue(edf.hasTest(ChwaLee.class)); + assertFalse(edf.hasTest(MaiaBertogna.class)); + assertFalse(edf.hasTest(SchmidMottok.class)); + assertTrue(edf.hasSimulator(ParallelSynchronous.class)); + assertTrue(edf.hasSimulator(DynamicForkJoin.class)); + + assertTrue(edf.hasTest(new ChwaLee(mock(SystemSetup.class)))); + assertFalse(edf.hasTest(new SchmidMottok(mock(SystemSetup.class)))); + assertFalse(edf.hasTest(new MaiaBertogna(mock(SystemSetup.class)))); + assertTrue(edf.hasSimulator(new ParallelSynchronous(mock(SystemSetup.class)))); + assertTrue(edf.hasSimulator(new DynamicForkJoin(mock(SystemSetup.class)))); + + assertTrue(edf.getName().equals("EDF")); + } + } diff --git a/src/test/java/mvd/jester/priority/TestRateMonotonic.java b/src/test/java/mvd/jester/priority/TestRateMonotonic.java index 685039f..b445146 100644 --- a/src/test/java/mvd/jester/priority/TestRateMonotonic.java +++ b/src/test/java/mvd/jester/priority/TestRateMonotonic.java @@ -1,12 +1,21 @@ package mvd.jester.priority; +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.HashSet; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import mvd.jester.model.Segment; +import mvd.jester.model.SystemSetup; import mvd.jester.model.Task; -import mvd.jester.simulator.internals.maiabertogna.TaskContext; +import mvd.jester.simulator.DynamicForkJoin; +import mvd.jester.simulator.ParallelSynchronous; +import mvd.jester.simulator.internals.parallelsynchronous.TaskContext; +import mvd.jester.tests.ChwaLee; +import mvd.jester.tests.MaiaBertogna; +import mvd.jester.tests.SchmidMottok; /** * TestRateMonotonic @@ -17,13 +26,41 @@ public class TestRateMonotonic { @DisplayName("Test if priority manager returns the correct priority.") public void testPriority() { RateMonotonic rm = new RateMonotonic(); - Task t1 = new Task(100, new HashSet()); - Task t2 = new Task(200, new HashSet()); + Task t1 = mock(Task.class); + Task t2 = mock(Task.class); + when(t1.getPeriod()).thenReturn((long) 100); + when(t2.getPeriod()).thenReturn((long) 200); - TaskContext tc1 = new TaskContext(t1, 0); - TaskContext tc2 = new TaskContext(t2, 0); + TaskContext tc1 = mock(TaskContext.class); + TaskContext tc2 = mock(TaskContext.class); + when(tc1.getTask()).thenReturn(t1); + when(tc2.getTask()).thenReturn(t2); assertTrue(rm.compare(t1, t2) < 0); assertTrue(rm.compare(tc1, tc2) < 0); + assertTrue(rm.compare(t1, t1) == 0); + assertTrue(rm.compare(tc1, tc1) == 0); + assertTrue(rm.compare(t2, t1) > 0); + assertTrue(rm.compare(tc2, tc1) > 0); + } + + + @Test + @DisplayName("Check Tests and Simulators.") + void testTestsAndSimulators() { + RateMonotonic rm = new RateMonotonic(); + assertFalse(rm.hasTest(ChwaLee.class)); + assertTrue(rm.hasTest(MaiaBertogna.class)); + assertTrue(rm.hasTest(SchmidMottok.class)); + assertTrue(rm.hasSimulator(ParallelSynchronous.class)); + assertTrue(rm.hasSimulator(DynamicForkJoin.class)); + + assertFalse(rm.hasTest(new ChwaLee(mock(SystemSetup.class)))); + assertTrue(rm.hasTest(new SchmidMottok(mock(SystemSetup.class)))); + assertTrue(rm.hasTest(new MaiaBertogna(mock(SystemSetup.class)))); + assertTrue(rm.hasSimulator(new ParallelSynchronous(mock(SystemSetup.class)))); + assertTrue(rm.hasSimulator(new DynamicForkJoin(mock(SystemSetup.class)))); + + assertTrue(rm.getName().equals("RM")); } } diff --git a/src/test/java/mvd/jester/simulator/TestProcessorContext.java b/src/test/java/mvd/jester/simulator/TestProcessorContext.java index 0a5a00d..ae9e201 100644 --- a/src/test/java/mvd/jester/simulator/TestProcessorContext.java +++ b/src/test/java/mvd/jester/simulator/TestProcessorContext.java @@ -17,8 +17,8 @@ import org.junit.jupiter.api.Test; import mvd.jester.model.Task; import mvd.jester.simulator.internals.ProcessorContext; import mvd.jester.simulator.internals.TaskContextInterface; -import mvd.jester.simulator.internals.maiabertogna.JobContext; -import mvd.jester.simulator.internals.maiabertogna.TaskContext; +import mvd.jester.simulator.internals.parallelsynchronous.JobContext; +import mvd.jester.simulator.internals.parallelsynchronous.TaskContext; /** * TestProcessorContext diff --git a/src/test/java/mvd/jester/simulator/dynamicforkjoin/TestJobContext.java b/src/test/java/mvd/jester/simulator/dynamicforkjoin/TestJobContext.java new file mode 100644 index 0000000..8b97dc6 --- /dev/null +++ b/src/test/java/mvd/jester/simulator/dynamicforkjoin/TestJobContext.java @@ -0,0 +1,98 @@ +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.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.AdditionalMatchers.not; +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.Optional; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import mvd.jester.model.Segment; +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;; + +/** + * TestJobContext + */ +public class TestJobContext { + + @Test + @DisplayName("Check if the job is prepared correctly.") + public void testPrepareJob() { + TaskContext tc = mock(TaskContext.class); + TaskletContext tlc = mock(TaskletContext.class); + SegmentContext sc = mock(SegmentContext.class); + Segment s = mock(Segment.class); + when(sc.getSegment()).thenReturn(s); + when(s.getJobWcet()).thenReturn((long) 20); + when(sc.getNextTasklet()).thenReturn(Optional.of(tlc)) + .thenReturn(Optional.ofNullable(null)); + + + JobContext jc = new JobContext(tc, sc); + + assertTrue(jc.prepareJob(0)); + assertTrue(jc.prepareJob(1)); + jc.setCurrentTasklet(null); + assertFalse(jc.prepareJob(2)); + } + + @Test + @DisplayName("Check if the execution time is checked correctly.") + void testCheckExecutionTime() { + TaskContext tc = mock(TaskContext.class); + TaskletContext tlc = mock(TaskletContext.class); + SegmentContext sc = mock(SegmentContext.class); + Segment s = mock(Segment.class); + when(sc.getSegment()).thenReturn(s); + when(s.getJobWcet()).thenReturn((long) 20); + when(tlc.checkExecutionTime()).thenReturn(true, false); + + JobContext jc = new JobContext(tc, sc); + + assertFalse(jc.checkExecutionTime()); + jc.setCurrentTasklet(tlc); + assertTrue(jc.checkExecutionTime()); + assertFalse(jc.checkExecutionTime()); + } + + @Test + @DisplayName("Check if the execution is updated correctly.") + void checkUpdateExecution() { + TaskContext tc = mock(TaskContext.class); + TaskletContext tlc = mock(TaskletContext.class); + SegmentContext sc = mock(SegmentContext.class); + Segment s = mock(Segment.class); + ProcessorContext pc = mock(ProcessorContext.class); + when(sc.getSegment()).thenReturn(s); + when(sc.getNextTasklet()).thenReturn(Optional.ofNullable(tlc)) + .thenReturn(Optional.ofNullable(null)); + when(s.getJobWcet()).thenReturn((long) 20); + when(tlc.checkExecutionTime()).thenReturn(true, false); + when(tlc.updateExecution(not(eq(0)))).thenReturn(true); + when(tlc.updateExecution(0)).thenReturn(false); + when(tc.acceptNotification(not(eq(1)))).thenReturn(Optional.ofNullable(null)); + when(tc.acceptNotification(1)).thenReturn(Optional.ofNullable(tc)); + + JobContext jc = new JobContext(tc, sc); + jc.setCurrentProcessor(pc); + + assertFalse(jc.updateExecution(0).isPresent()); + assertFalse(jc.updateExecution(0).isPresent()); + + jc.setCurrentTasklet(tlc); + assertTrue(jc.updateExecution(1).isPresent()); + + verify(tlc, times(2)).updateExecution(anyLong()); + verify(tc, times(2)).acceptNotification(anyLong()); + verify(sc, times(2)).getNextTasklet(); + } +} diff --git a/src/test/java/mvd/jester/simulator/dynamicforkjoin/TestSegmentContext.java b/src/test/java/mvd/jester/simulator/dynamicforkjoin/TestSegmentContext.java new file mode 100644 index 0000000..dcb5c72 --- /dev/null +++ b/src/test/java/mvd/jester/simulator/dynamicforkjoin/TestSegmentContext.java @@ -0,0 +1,105 @@ +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); + when(s.getNumberOfTasklets()).thenReturn(jobWcet); + when(s.getTaskletWcet()).thenReturn(numberOfJobs); + TaskContext tc = mock(TaskContext.class); + + SegmentContext sc = new SegmentContext(tc, s, 4); + Optional 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); + when(s.getNumberOfTasklets()).thenReturn(jobWcet); + when(s.getTaskletWcet()).thenReturn(numberOfJobs); + 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 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 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()); + } + } + +} diff --git a/src/test/java/mvd/jester/simulator/dynamicforkjoin/TestTaskContext.java b/src/test/java/mvd/jester/simulator/dynamicforkjoin/TestTaskContext.java new file mode 100644 index 0000000..cffb7dc --- /dev/null +++ b/src/test/java/mvd/jester/simulator/dynamicforkjoin/TestTaskContext.java @@ -0,0 +1,101 @@ +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.Task; +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 segments = new ArrayList<>(); + + for (int i = 0; i < numberOfSegments; ++i) { + long numJobs = i % 2 == 0 ? 1 : numberOfJobs; + segments.add(new Segment(10, numJobs)); + } + + Task t = new Task(100, new LinkedHashSet<>(segments)); + TaskContext tc = new TaskContext(t, 1, 0); + + for (int i = 0; i < segments.size() - 1; ++i) { + Segment s = segments.get(i); + for (int j = 0; j < s.getNumberOfTasklets(); ++j) { + assertFalse(tc.acceptNotification(0).isPresent()); + } + } + + for (int i = 0; i < segments.get(segments.size() - 1).getNumberOfTasklets() - 1; ++i) { + assertFalse(tc.acceptNotification(0).isPresent()); + } + + Optional 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 segments = new LinkedHashSet<>(); + segments.add(new Segment(5, 1)); + segments.add(new Segment(10, 10)); + segments.add(new Segment(15, 1)); + Task t = new Task(100, segments); + + TaskContext tc = new TaskContext(t, numberOfProcessors, 0); + + Optional 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()); + } + } + +} diff --git a/src/test/java/mvd/jester/simulator/dynamicforkjoin/TestTaskletContext.java b/src/test/java/mvd/jester/simulator/dynamicforkjoin/TestTaskletContext.java new file mode 100644 index 0000000..0e34919 --- /dev/null +++ b/src/test/java/mvd/jester/simulator/dynamicforkjoin/TestTaskletContext.java @@ -0,0 +1,53 @@ +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); + when(s.getTaskletWcet()).thenReturn(taskletWcet); + 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)); + } + } +} diff --git a/src/test/java/mvd/jester/simulator/maiabertogna/TestJobContext.java b/src/test/java/mvd/jester/simulator/maiabertogna/TestJobContext.java deleted file mode 100644 index e65fc4c..0000000 --- a/src/test/java/mvd/jester/simulator/maiabertogna/TestJobContext.java +++ /dev/null @@ -1,61 +0,0 @@ -package mvd.jester.simulator.maiabertogna; - -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.ArgumentMatchers.anyLong; -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.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.ProcessorContext; -import mvd.jester.simulator.internals.TaskContextInterface; -import mvd.jester.simulator.internals.maiabertogna.JobContext; -import mvd.jester.simulator.internals.maiabertogna.SegmentContext; -import mvd.jester.simulator.internals.maiabertogna.TaskContext; - -/** - * TestJobContext - */ -public class TestJobContext { - - @Test - @DisplayName("Check if execution of Job is updated correctly.") - public void testUpdateExecution() { - for (int run = 0; run < 100; ++run) { - long jobWcet = ThreadLocalRandom.current().nextLong(20, 50); - - Segment s = mock(Segment.class); - when(s.getJobWcet()).thenReturn(jobWcet); - SegmentContext sc = mock(SegmentContext.class); - when(sc.getSegment()).thenReturn(s); - TaskContext tc = mock(TaskContext.class); - when(tc.acceptNotification(anyLong())).thenReturn(Optional.of(tc)); - - JobContext job = new JobContext(tc, sc); - ProcessorContext p = mock(ProcessorContext.class); - job.setCurrentProcessor(p); - - assertTrue(job.checkExecutionTime()); - - for (int i = 0; i < jobWcet - 1; ++i) { - assertFalse(job.updateExecution(i).isPresent()); - } - - Optional otc = job.updateExecution(0); - assertTrue(otc.isPresent()); - assertTrue(tc.equals(otc.get())); - assertFalse(p.getJob().isPresent()); - assertFalse(job.getCurrentProcessor().isPresent()); - assertFalse(job.checkExecutionTime()); - - verify(p, times(1)).setJob(null); - assertThrows(RuntimeException.class, () -> job.updateExecution(1)); - } - } -} diff --git a/src/test/java/mvd/jester/simulator/maiabertogna/TestSegmentContext.java b/src/test/java/mvd/jester/simulator/maiabertogna/TestSegmentContext.java deleted file mode 100644 index f93e707..0000000 --- a/src/test/java/mvd/jester/simulator/maiabertogna/TestSegmentContext.java +++ /dev/null @@ -1,57 +0,0 @@ -package mvd.jester.simulator.maiabertogna; - -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.maiabertogna.SegmentContext; -import mvd.jester.simulator.internals.maiabertogna.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 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()); - } - } -} diff --git a/src/test/java/mvd/jester/simulator/maiabertogna/TestTaskContext.java b/src/test/java/mvd/jester/simulator/maiabertogna/TestTaskContext.java deleted file mode 100644 index 1d04a6f..0000000 --- a/src/test/java/mvd/jester/simulator/maiabertogna/TestTaskContext.java +++ /dev/null @@ -1,96 +0,0 @@ -package mvd.jester.simulator.maiabertogna; - -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.Task; -import mvd.jester.simulator.internals.JobContextInterface; -import mvd.jester.simulator.internals.ProcessorContext; -import mvd.jester.simulator.internals.TaskContextInterface; -import mvd.jester.simulator.internals.maiabertogna.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 segments = new ArrayList<>(); - - for (int i = 0; i < numberOfSegments; ++i) { - long numJobs = i % 2 == 0 ? 1 : numberOfJobs; - segments.add(new Segment(10, numJobs)); - } - - Task t = new Task(100, new LinkedHashSet<>(segments)); - 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 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 segments = new LinkedHashSet<>(); - segments.add(new Segment(5, 1)); - segments.add(new Segment(10, 10)); - segments.add(new Segment(15, 1)); - Task t = new Task(100, segments); - - TaskContext tc = new TaskContext(t, 0); - - Optional 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()); - } - } -} diff --git a/src/test/java/mvd/jester/simulator/parallelsynchronous/TestJobContext.java b/src/test/java/mvd/jester/simulator/parallelsynchronous/TestJobContext.java new file mode 100644 index 0000000..e67e1a8 --- /dev/null +++ b/src/test/java/mvd/jester/simulator/parallelsynchronous/TestJobContext.java @@ -0,0 +1,61 @@ +package mvd.jester.simulator.parallelsynchronous; + +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.ArgumentMatchers.anyLong; +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.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.ProcessorContext; +import mvd.jester.simulator.internals.TaskContextInterface; +import mvd.jester.simulator.internals.parallelsynchronous.JobContext; +import mvd.jester.simulator.internals.parallelsynchronous.SegmentContext; +import mvd.jester.simulator.internals.parallelsynchronous.TaskContext; + +/** + * TestJobContext + */ +public class TestJobContext { + + @Test + @DisplayName("Check if execution of Job is updated correctly.") + public void testUpdateExecution() { + for (int run = 0; run < 100; ++run) { + long jobWcet = ThreadLocalRandom.current().nextLong(20, 50); + + Segment s = mock(Segment.class); + when(s.getJobWcet()).thenReturn(jobWcet); + SegmentContext sc = mock(SegmentContext.class); + when(sc.getSegment()).thenReturn(s); + TaskContext tc = mock(TaskContext.class); + when(tc.acceptNotification(anyLong())).thenReturn(Optional.of(tc)); + + JobContext job = new JobContext(tc, sc); + ProcessorContext p = mock(ProcessorContext.class); + job.setCurrentProcessor(p); + + assertTrue(job.checkExecutionTime()); + + for (int i = 0; i < jobWcet - 1; ++i) { + assertFalse(job.updateExecution(i).isPresent()); + } + + Optional otc = job.updateExecution(0); + assertTrue(otc.isPresent()); + assertTrue(tc.equals(otc.get())); + assertFalse(p.getJob().isPresent()); + assertFalse(job.getCurrentProcessor().isPresent()); + assertFalse(job.checkExecutionTime()); + + verify(p, times(1)).setJob(null); + assertThrows(RuntimeException.class, () -> job.updateExecution(1)); + } + } +} diff --git a/src/test/java/mvd/jester/simulator/parallelsynchronous/TestSegmentContext.java b/src/test/java/mvd/jester/simulator/parallelsynchronous/TestSegmentContext.java new file mode 100644 index 0000000..2cce377 --- /dev/null +++ b/src/test/java/mvd/jester/simulator/parallelsynchronous/TestSegmentContext.java @@ -0,0 +1,57 @@ +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 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()); + } + } +} diff --git a/src/test/java/mvd/jester/simulator/parallelsynchronous/TestTaskContext.java b/src/test/java/mvd/jester/simulator/parallelsynchronous/TestTaskContext.java new file mode 100644 index 0000000..e2e75f2 --- /dev/null +++ b/src/test/java/mvd/jester/simulator/parallelsynchronous/TestTaskContext.java @@ -0,0 +1,96 @@ +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.Task; +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 segments = new ArrayList<>(); + + for (int i = 0; i < numberOfSegments; ++i) { + long numJobs = i % 2 == 0 ? 1 : numberOfJobs; + segments.add(new Segment(10, numJobs)); + } + + Task t = new Task(100, new LinkedHashSet<>(segments)); + 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 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 segments = new LinkedHashSet<>(); + segments.add(new Segment(5, 1)); + segments.add(new Segment(10, 10)); + segments.add(new Segment(15, 1)); + Task t = new Task(100, segments); + + TaskContext tc = new TaskContext(t, 0); + + Optional 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()); + } + } +} diff --git a/src/test/java/mvd/jester/simulator/schmidmottok/TestJobContext.java b/src/test/java/mvd/jester/simulator/schmidmottok/TestJobContext.java deleted file mode 100644 index 1f3aa7c..0000000 --- a/src/test/java/mvd/jester/simulator/schmidmottok/TestJobContext.java +++ /dev/null @@ -1,98 +0,0 @@ -package mvd.jester.simulator.schmidmottok; - -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.ArgumentMatchers.anyLong; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.AdditionalMatchers.not; -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.Optional; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import mvd.jester.model.Segment; -import mvd.jester.simulator.internals.ProcessorContext; -import mvd.jester.simulator.internals.schmidmottok.JobContext; -import mvd.jester.simulator.internals.schmidmottok.SegmentContext; -import mvd.jester.simulator.internals.schmidmottok.TaskContext; -import mvd.jester.simulator.internals.schmidmottok.TaskletContext;; - -/** - * TestJobContext - */ -public class TestJobContext { - - @Test - @DisplayName("Check if the job is prepared correctly.") - public void testPrepareJob() { - TaskContext tc = mock(TaskContext.class); - TaskletContext tlc = mock(TaskletContext.class); - SegmentContext sc = mock(SegmentContext.class); - Segment s = mock(Segment.class); - when(sc.getSegment()).thenReturn(s); - when(s.getJobWcet()).thenReturn((long) 20); - when(sc.getNextTasklet()).thenReturn(Optional.of(tlc)) - .thenReturn(Optional.ofNullable(null)); - - - JobContext jc = new JobContext(tc, sc); - - assertTrue(jc.prepareJob(0)); - assertTrue(jc.prepareJob(1)); - jc.setCurrentTasklet(null); - assertFalse(jc.prepareJob(2)); - } - - @Test - @DisplayName("Check if the execution time is checked correctly.") - void testCheckExecutionTime() { - TaskContext tc = mock(TaskContext.class); - TaskletContext tlc = mock(TaskletContext.class); - SegmentContext sc = mock(SegmentContext.class); - Segment s = mock(Segment.class); - when(sc.getSegment()).thenReturn(s); - when(s.getJobWcet()).thenReturn((long) 20); - when(tlc.checkExecutionTime()).thenReturn(true, false); - - JobContext jc = new JobContext(tc, sc); - - assertFalse(jc.checkExecutionTime()); - jc.setCurrentTasklet(tlc); - assertTrue(jc.checkExecutionTime()); - assertFalse(jc.checkExecutionTime()); - } - - @Test - @DisplayName("Check if the execution is updated correctly.") - void checkUpdateExecution() { - TaskContext tc = mock(TaskContext.class); - TaskletContext tlc = mock(TaskletContext.class); - SegmentContext sc = mock(SegmentContext.class); - Segment s = mock(Segment.class); - ProcessorContext pc = mock(ProcessorContext.class); - when(sc.getSegment()).thenReturn(s); - when(sc.getNextTasklet()).thenReturn(Optional.ofNullable(tlc)) - .thenReturn(Optional.ofNullable(null)); - when(s.getJobWcet()).thenReturn((long) 20); - when(tlc.checkExecutionTime()).thenReturn(true, false); - when(tlc.updateExecution(not(eq(0)))).thenReturn(true); - when(tlc.updateExecution(0)).thenReturn(false); - when(tc.acceptNotification(not(eq(1)))).thenReturn(Optional.ofNullable(null)); - when(tc.acceptNotification(1)).thenReturn(Optional.ofNullable(tc)); - - JobContext jc = new JobContext(tc, sc); - jc.setCurrentProcessor(pc); - - assertFalse(jc.updateExecution(0).isPresent()); - assertFalse(jc.updateExecution(0).isPresent()); - - jc.setCurrentTasklet(tlc); - assertTrue(jc.updateExecution(1).isPresent()); - - verify(tlc, times(2)).updateExecution(anyLong()); - verify(tc, times(2)).acceptNotification(anyLong()); - verify(sc, times(2)).getNextTasklet(); - } -} diff --git a/src/test/java/mvd/jester/simulator/schmidmottok/TestSegmentContext.java b/src/test/java/mvd/jester/simulator/schmidmottok/TestSegmentContext.java deleted file mode 100644 index 3170520..0000000 --- a/src/test/java/mvd/jester/simulator/schmidmottok/TestSegmentContext.java +++ /dev/null @@ -1,105 +0,0 @@ -package mvd.jester.simulator.schmidmottok; - -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.schmidmottok.JobContext; -import mvd.jester.simulator.internals.schmidmottok.SegmentContext; -import mvd.jester.simulator.internals.schmidmottok.TaskContext; -import mvd.jester.simulator.internals.schmidmottok.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); - when(s.getNumberOfTasklets()).thenReturn(jobWcet); - when(s.getTaskletWcet()).thenReturn(numberOfJobs); - TaskContext tc = mock(TaskContext.class); - - SegmentContext sc = new SegmentContext(tc, s, 4); - Optional 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); - when(s.getNumberOfTasklets()).thenReturn(jobWcet); - when(s.getTaskletWcet()).thenReturn(numberOfJobs); - 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 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 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()); - } - } - -} diff --git a/src/test/java/mvd/jester/simulator/schmidmottok/TestTaskContext.java b/src/test/java/mvd/jester/simulator/schmidmottok/TestTaskContext.java deleted file mode 100644 index badc60c..0000000 --- a/src/test/java/mvd/jester/simulator/schmidmottok/TestTaskContext.java +++ /dev/null @@ -1,101 +0,0 @@ -package mvd.jester.simulator.schmidmottok; - -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.Task; -import mvd.jester.simulator.internals.JobContextInterface; -import mvd.jester.simulator.internals.ProcessorContext; -import mvd.jester.simulator.internals.TaskContextInterface; -import mvd.jester.simulator.internals.schmidmottok.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 segments = new ArrayList<>(); - - for (int i = 0; i < numberOfSegments; ++i) { - long numJobs = i % 2 == 0 ? 1 : numberOfJobs; - segments.add(new Segment(10, numJobs)); - } - - Task t = new Task(100, new LinkedHashSet<>(segments)); - TaskContext tc = new TaskContext(t, 1, 0); - - for (int i = 0; i < segments.size() - 1; ++i) { - Segment s = segments.get(i); - for (int j = 0; j < s.getNumberOfTasklets(); ++j) { - assertFalse(tc.acceptNotification(0).isPresent()); - } - } - - for (int i = 0; i < segments.get(segments.size() - 1).getNumberOfTasklets() - 1; ++i) { - assertFalse(tc.acceptNotification(0).isPresent()); - } - - Optional 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 segments = new LinkedHashSet<>(); - segments.add(new Segment(5, 1)); - segments.add(new Segment(10, 10)); - segments.add(new Segment(15, 1)); - Task t = new Task(100, segments); - - TaskContext tc = new TaskContext(t, numberOfProcessors, 0); - - Optional 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()); - } - } - -} diff --git a/src/test/java/mvd/jester/simulator/schmidmottok/TestTaskletContext.java b/src/test/java/mvd/jester/simulator/schmidmottok/TestTaskletContext.java deleted file mode 100644 index 41b5205..0000000 --- a/src/test/java/mvd/jester/simulator/schmidmottok/TestTaskletContext.java +++ /dev/null @@ -1,53 +0,0 @@ -package mvd.jester.simulator.schmidmottok; - -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.schmidmottok.JobContext; -import mvd.jester.simulator.internals.schmidmottok.SegmentContext; -import mvd.jester.simulator.internals.schmidmottok.TaskContext; -import mvd.jester.simulator.internals.schmidmottok.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); - when(s.getTaskletWcet()).thenReturn(taskletWcet); - 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)); - } - } -} diff --git a/src/test/java/mvd/jester/tests/TestMaiaBertogna.java b/src/test/java/mvd/jester/tests/TestMaiaBertogna.java index 50bf7b5..39fa332 100644 --- a/src/test/java/mvd/jester/tests/TestMaiaBertogna.java +++ b/src/test/java/mvd/jester/tests/TestMaiaBertogna.java @@ -1,8 +1,12 @@ package mvd.jester.tests; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import mvd.jester.info.SchedulingInfo; +import mvd.jester.info.TerminationInfo.Level; import mvd.jester.model.SystemSetup; +import mvd.jester.priority.RateMonotonic; /** * TestMaiaBertogna @@ -12,7 +16,41 @@ public class TestMaiaBertogna { @Test @DisplayName("Check if the schedulability check returns the correct values.") public void testRunSchedulabilityCheck() { - SystemSetup systemSetup = SystemSetup.readFromFile("/resources/Taskset1.txt", 0); - MaiaBertogna mb = new MaiaBertogna(systemSetup); + { + SystemSetup systemSetup = + SystemSetup.readFromFile("src/test/resources/Taskset1.txt", 4); + MaiaBertogna mb = new MaiaBertogna(systemSetup); + + SchedulingInfo schedulingInfo = mb.runSchedulabilityCheck(new RateMonotonic()); + + assertTrue(schedulingInfo.getTerminationInfos().size() == 4); + assertTrue(schedulingInfo.checkLevelFail(Level.HIGH) == true); + assertTrue(schedulingInfo.checkTasksetFeasible() == false); + assertTrue(schedulingInfo.getFailedTerminationInfo().isPresent()); + } + { + SystemSetup systemSetup = + SystemSetup.readFromFile("src/test/resources/Taskset1.txt", 8); + MaiaBertogna mb = new MaiaBertogna(systemSetup); + + SchedulingInfo schedulingInfo = mb.runSchedulabilityCheck(new RateMonotonic()); + + assertTrue(schedulingInfo.getTerminationInfos().size() == 4); + assertTrue(schedulingInfo.checkLevelFail(Level.HIGH) == true); + assertTrue(schedulingInfo.checkTasksetFeasible() == false); + assertTrue(schedulingInfo.getFailedTerminationInfo().isPresent()); + } + { + SystemSetup systemSetup = + SystemSetup.readFromFile("src/test/resources/Taskset1.txt", 16); + MaiaBertogna mb = new MaiaBertogna(systemSetup); + + SchedulingInfo schedulingInfo = mb.runSchedulabilityCheck(new RateMonotonic()); + + assertTrue(schedulingInfo.getTerminationInfos().size() == 4); + assertTrue(schedulingInfo.checkLevelFail(Level.HIGH) == false); + assertTrue(schedulingInfo.checkTasksetFeasible() == true); + assertTrue(!schedulingInfo.getFailedTerminationInfo().isPresent()); + } } } diff --git a/src/test/java/mvd/jester/tests/TestSchmidMottok.java b/src/test/java/mvd/jester/tests/TestSchmidMottok.java new file mode 100644 index 0000000..a0261a9 --- /dev/null +++ b/src/test/java/mvd/jester/tests/TestSchmidMottok.java @@ -0,0 +1,57 @@ + +package mvd.jester.tests; + +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import mvd.jester.info.SchedulingInfo; +import mvd.jester.info.TerminationInfo.Level; +import mvd.jester.model.SystemSetup; +import mvd.jester.priority.RateMonotonic; + +/** + * TestSchmidMottok + */ +public class TestSchmidMottok { + + @Test + @DisplayName("Check if the schedulability check returns the correct values.") + public void testRunSchedulabilityCheck() { + { + SystemSetup systemSetup = + SystemSetup.readFromFile("src/test/resources/Taskset1.txt", 4); + MaiaBertogna mb = new MaiaBertogna(systemSetup); + + SchedulingInfo schedulingInfo = mb.runSchedulabilityCheck(new RateMonotonic()); + + assertTrue(schedulingInfo.getTerminationInfos().size() == 4); + assertTrue(schedulingInfo.checkLevelFail(Level.HIGH) == true); + assertTrue(schedulingInfo.checkTasksetFeasible() == false); + assertTrue(schedulingInfo.getFailedTerminationInfo().isPresent()); + } + { + SystemSetup systemSetup = + SystemSetup.readFromFile("src/test/resources/Taskset1.txt", 8); + MaiaBertogna mb = new MaiaBertogna(systemSetup); + + SchedulingInfo schedulingInfo = mb.runSchedulabilityCheck(new RateMonotonic()); + + assertTrue(schedulingInfo.getTerminationInfos().size() == 4); + assertTrue(schedulingInfo.checkLevelFail(Level.HIGH) == true); + assertTrue(schedulingInfo.checkTasksetFeasible() == false); + assertTrue(schedulingInfo.getFailedTerminationInfo().isPresent()); + } + { + SystemSetup systemSetup = + SystemSetup.readFromFile("src/test/resources/Taskset1.txt", 16); + MaiaBertogna mb = new MaiaBertogna(systemSetup); + + SchedulingInfo schedulingInfo = mb.runSchedulabilityCheck(new RateMonotonic()); + + assertTrue(schedulingInfo.getTerminationInfos().size() == 4); + assertTrue(schedulingInfo.checkLevelFail(Level.HIGH) == false); + assertTrue(schedulingInfo.checkTasksetFeasible() == true); + assertTrue(!schedulingInfo.getFailedTerminationInfo().isPresent()); + } + } +} -- libgit2 0.26.0