Commit 0232b488 by Michael Schmid

terminated refactoring, looks good now

parent 59c46e2a
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);
......
......@@ -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;
......
......@@ -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));
}
......
......@@ -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;
......
......@@ -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<Class<? extends AbstractTest>> abstractTests;
private final SystemSetup systemSetup;
private final SystemSetup.Builder builder;
private final Set<Constructor<? extends AbstractTest>> 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<? extends AbstractTest> 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<AbstractTest, Long> testCases = new HashMap<>();
for (Class<? extends AbstractTest> t : abstractTests) {
for (Constructor<? extends AbstractTest> 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();
}
}
......
package mvd.jester.tests;
import mvd.jester.model.SystemSetup;
/**
* TestInterface
*/
public interface TestInterface {
public boolean runSchedulabilityCheck(SystemSetup systemSetup);
public boolean runSchedulabilityCheck();
public String getName();
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment