From 0232b48868f75c590602874156171559e3645f2a Mon Sep 17 00:00:00 2001 From: Michael Schmid Date: Thu, 11 Jul 2019 15:31:26 +0200 Subject: [PATCH] terminated refactoring, looks good now --- src/main/java/mvd/jester/App.java | 4 ++-- src/main/java/mvd/jester/model/SystemSetup.java | 31 +++++++++++++++++-------------- src/main/java/mvd/jester/tests/MaiaBertogna.java | 8 ++++---- src/main/java/mvd/jester/tests/SchmidMottok.java | 16 +++++++++------- src/main/java/mvd/jester/tests/TestEnvironment.java | 37 +++++++++++++++++++++---------------- src/main/java/mvd/jester/tests/TestInterface.java | 4 +--- src/test/java/mvd/jester/model/TaskSetTest.java | 2 +- 7 files changed, 55 insertions(+), 47 deletions(-) diff --git a/src/main/java/mvd/jester/App.java b/src/main/java/mvd/jester/App.java index 0c8d099..2edd6d3 100644 --- a/src/main/java/mvd/jester/App.java +++ b/src/main/java/mvd/jester/App.java @@ -1,6 +1,5 @@ package mvd.jester; -import mvd.jester.model.Task; import mvd.jester.model.SystemSetup; import mvd.jester.tests.MaiaBertogna; import mvd.jester.tests.SchmidMottok; @@ -12,8 +11,9 @@ import mvd.jester.tests.TestEnvironment; */ public class App { public static void main(String[] args) { + SystemSetup.Builder generator = new SystemSetup.Builder().setNumberOfProcessors(4); - TestEnvironment te = new TestEnvironment(4000, 4); + TestEnvironment te = new TestEnvironment(generator, 10000); te.registerTestInterface(SchmidMottok.class); te.registerTestInterface(MaiaBertogna.class); diff --git a/src/main/java/mvd/jester/model/SystemSetup.java b/src/main/java/mvd/jester/model/SystemSetup.java index 55572e9..fb72d65 100644 --- a/src/main/java/mvd/jester/model/SystemSetup.java +++ b/src/main/java/mvd/jester/model/SystemSetup.java @@ -25,7 +25,7 @@ public class SystemSetup { return tasks; } - public void setSortedTaskSet(SortedTaskSet tasks) { + public void setTasks(SortedTaskSet tasks) { this.tasks = tasks; } @@ -45,7 +45,7 @@ public class SystemSetup { return utilization; } - public static class Generator { + public static class Builder { private long numberOfProcessors = 4; private long minPeriod = 100; private long maxPeriod = 1000; @@ -57,7 +57,7 @@ public class SystemSetup { private long ratio = randomTaskRatio(); private PriorityManager priorityManager = new RateMonotonic(); - public Generator() { + public Builder() { } @@ -119,33 +119,36 @@ public class SystemSetup { return new SystemSetup(taskSet, numberOfProcessors); } - public void addTask(SystemSetup taskSet) { - taskSet.tasks.add(generateTask()); + public void rebuild(SystemSetup systemSetup) { + this.ratio = randomTaskRatio(); + systemSetup.tasks = generateTaskSet(); } - /** - * @param numberOfProcessors the numberOfProcessors to set - */ - public void setNumberOfProcessors(long numberOfProcessors) { - this.numberOfProcessors = numberOfProcessors; + public void addTask(SystemSetup systemSetup) { + systemSetup.tasks.add(generateTask()); } + public Builder setNumberOfProcessors(long numberOfProcessors) { + this.numberOfProcessors = numberOfProcessors; + + return this; + } - public Generator setNumberOfSegments(long minNumberOfSegments, long maxNumberOfSegments) { + public Builder setNumberOfSegments(long minNumberOfSegments, long maxNumberOfSegments) { this.minNumberOfSegments = minNumberOfSegments; this.maxNumberOfSegments = maxNumberOfSegments; return this; } - public Generator setPeriods(long minPeriod, long maxPeriod) { + public Builder setPeriods(long minPeriod, long maxPeriod) { this.minPeriod = minPeriod; this.maxPeriod = maxPeriod; return this; } - public Generator setPriorityManager(PriorityManager priorityManager) { + public Builder setPriorityManager(PriorityManager priorityManager) { this.priorityManager = priorityManager; return this; } @@ -153,7 +156,7 @@ public class SystemSetup { /** * @param maxNumberOfJobs the maxNumberOfJobs to set */ - public Generator setNumberOfJobs(long minNumberOfJobs, long maxNumberOfJobs) { + public Builder setNumberOfJobs(long minNumberOfJobs, long maxNumberOfJobs) { this.minNumberOfJobs = minNumberOfJobs; this.maxNumberOfJobs = maxNumberOfJobs; return this; diff --git a/src/main/java/mvd/jester/tests/MaiaBertogna.java b/src/main/java/mvd/jester/tests/MaiaBertogna.java index a738e96..edffae3 100644 --- a/src/main/java/mvd/jester/tests/MaiaBertogna.java +++ b/src/main/java/mvd/jester/tests/MaiaBertogna.java @@ -12,15 +12,15 @@ import mvd.jester.model.SystemSetup; */ public class MaiaBertogna extends AbstractTest { - private SystemSetup systemSetup; + private final SystemSetup systemSetup; - public MaiaBertogna() { + public MaiaBertogna(SystemSetup systemSetup) { + this.systemSetup = systemSetup; } @Override - public boolean runSchedulabilityCheck(SystemSetup systemSetup) { + public boolean runSchedulabilityCheck() { responseTimes.clear(); - this.systemSetup = systemSetup; for (Task t : systemSetup.getTasks()) { responseTimes.put(t, calculateResponseTime(t)); } diff --git a/src/main/java/mvd/jester/tests/SchmidMottok.java b/src/main/java/mvd/jester/tests/SchmidMottok.java index 44fc48f..1aedfe5 100644 --- a/src/main/java/mvd/jester/tests/SchmidMottok.java +++ b/src/main/java/mvd/jester/tests/SchmidMottok.java @@ -12,15 +12,15 @@ import mvd.jester.model.SystemSetup; */ public class SchmidMottok extends AbstractTest { - private SystemSetup systemSetup; + private final SystemSetup systemSetup; - public SchmidMottok() { + public SchmidMottok(SystemSetup systemSetup) { + this.systemSetup = systemSetup; } @Override - public boolean runSchedulabilityCheck(SystemSetup systemSetup) { + public boolean runSchedulabilityCheck() { responseTimes.clear(); - this.systemSetup = systemSetup; for (Task t : systemSetup.getTasks()) { responseTimes.put(t, calculateResponseTime(t)); } @@ -56,7 +56,7 @@ public class SchmidMottok extends AbstractTest { } } - double taskInterference = (double) interference / 4; + double taskInterference = (double) interference / systemSetup.getNumberOfProcessors(); double selfInterference = getSelfInterference(task); long totalInterference = (long) Math.floor(taskInterference + selfInterference); @@ -71,11 +71,13 @@ public class SchmidMottok extends AbstractTest { private double getSelfInterference(Task task) { double interference = 0; + long numberOfProcessors = systemSetup.getNumberOfProcessors(); for (Segment s : task.getSegments()) { - long processingUnits = s.getNumberOfJobs() > 4 ? 4 : s.getNumberOfJobs(); + long numberOfJobs = s.getNumberOfJobs() > numberOfProcessors ? numberOfProcessors + : s.getNumberOfJobs(); interference += - (double) (s.getNumberOfTasklets() - 1) * s.getTaskletWcet() / processingUnits; + (double) (s.getNumberOfTasklets() - 1) * s.getTaskletWcet() / numberOfJobs; } return interference; diff --git a/src/main/java/mvd/jester/tests/TestEnvironment.java b/src/main/java/mvd/jester/tests/TestEnvironment.java index 8354b01..fc60f2a 100644 --- a/src/main/java/mvd/jester/tests/TestEnvironment.java +++ b/src/main/java/mvd/jester/tests/TestEnvironment.java @@ -5,7 +5,6 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; -import mvd.jester.model.SortedTaskSet; import mvd.jester.model.SystemSetup; /** @@ -14,17 +13,24 @@ import mvd.jester.model.SystemSetup; public class TestEnvironment { private final long numberOfTaskSets; - private final long numberOfProcessors; - private final Set> abstractTests; + private final SystemSetup systemSetup; + private final SystemSetup.Builder builder; + private final Set> abstractTests; - public TestEnvironment(long numberOfTaskSets, long numberOfProcessors) { + public TestEnvironment(SystemSetup.Builder builder, long numberOfTaskSets) { this.numberOfTaskSets = numberOfTaskSets; - this.numberOfProcessors = numberOfProcessors; abstractTests = new HashSet<>(); + + this.builder = builder; + this.systemSetup = builder.build(); } public TestEnvironment registerTestInterface(Class abstractTest) { - abstractTests.add(abstractTest); + try { + abstractTests.add(abstractTest.getConstructor(SystemSetup.class)); + } catch (Exception e) { + System.out.println("Missing constructor!"); + } return this; } @@ -32,9 +38,9 @@ public class TestEnvironment { public void runTests() { Map testCases = new HashMap<>(); - for (Class t : abstractTests) { + for (Constructor t : abstractTests) { try { - testCases.put(t.newInstance(), (long) 0); + testCases.put(t.newInstance(this.systemSetup), (long) 0); } catch (Exception e) { System.out.println("Ahhh SHIT!"); } @@ -43,24 +49,23 @@ public class TestEnvironment { long checkedTasksets = 0; - while (checkedTasksets < 4000) { - SystemSetup.Generator generator = new SystemSetup.Generator(); - SystemSetup systemSetup = generator.build(); + while (checkedTasksets < numberOfTaskSets) { + builder.rebuild(this.systemSetup); - double utilization = systemSetup.getUtilization(); + double utilization = this.systemSetup.getUtilization(); - while (utilization <= systemSetup.getNumberOfProcessors() + while (utilization <= this.systemSetup.getNumberOfProcessors() && checkedTasksets < numberOfTaskSets) { checkedTasksets++; for (AbstractTest t : testCases.keySet()) { - if (t.runSchedulabilityCheck(systemSetup)) { + if (t.runSchedulabilityCheck()) { testCases.computeIfPresent(t, (k, v) -> v + 1); } } - generator.addTask(systemSetup); + builder.addTask(systemSetup); - utilization = systemSetup.getUtilization(); + utilization = this.systemSetup.getUtilization(); } } diff --git a/src/main/java/mvd/jester/tests/TestInterface.java b/src/main/java/mvd/jester/tests/TestInterface.java index b92f13d..8b2b4fa 100644 --- a/src/main/java/mvd/jester/tests/TestInterface.java +++ b/src/main/java/mvd/jester/tests/TestInterface.java @@ -1,13 +1,11 @@ package mvd.jester.tests; -import mvd.jester.model.SystemSetup; - /** * TestInterface */ public interface TestInterface { - public boolean runSchedulabilityCheck(SystemSetup systemSetup); + public boolean runSchedulabilityCheck(); public String getName(); diff --git a/src/test/java/mvd/jester/model/TaskSetTest.java b/src/test/java/mvd/jester/model/TaskSetTest.java index 4f23b0c..7245c94 100644 --- a/src/test/java/mvd/jester/model/TaskSetTest.java +++ b/src/test/java/mvd/jester/model/TaskSetTest.java @@ -14,7 +14,7 @@ public class TaskSetTest { public void testRandomTaskSetGeneration() { for (int i = 0; i < NUMBER_OF_SETS; ++i) { - SystemSetup taskSet = new SystemSetup.Generator().build(); + SystemSetup taskSet = new SystemSetup.Builder().build(); for (Task t : taskSet.getTasks()) { assertTrue(t.getPeriod() >= 100); -- libgit2 0.26.0