Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
las3_pub
/
jester
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
5e54ea41
authored
Oct 07, 2019
by
Michael Schmid
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Last changes and unit tests
parent
6bc244f2
Show whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
593 additions
and
90 deletions
+593
-90
src/main/java/mvd/jester/App.java
+1
-40
src/main/java/mvd/jester/TestEnvironment.java
+62
-33
src/main/java/mvd/jester/priority/EarliestDeadlineFirst.java
+2
-1
src/main/java/mvd/jester/simulator/AbstractSimulator.java
+1
-1
src/main/java/mvd/jester/simulator/internals/maiabertogna/SegmentContext.java
+1
-1
src/main/java/mvd/jester/simulator/internals/maiabertogna/TaskContext.java
+1
-4
src/main/java/mvd/jester/simulator/internals/schmidmottok/SegmentContext.java
+2
-2
src/main/java/mvd/jester/simulator/internals/schmidmottok/TaskContext.java
+1
-4
src/test/java/mvd/jester/model/TestSegment.java
+30
-0
src/test/java/mvd/jester/model/TestSystemSetup.java
+5
-4
src/test/java/mvd/jester/priority/TestEarliestDeadlineFirst.java
+29
-0
src/test/java/mvd/jester/priority/TestRateMonotonic.java
+29
-0
src/test/java/mvd/jester/simulator/maiabertogna/TestJobContext.java
+56
-0
src/test/java/mvd/jester/simulator/maiabertogna/TestSegmentContext.java
+57
-0
src/test/java/mvd/jester/simulator/maiabertogna/TestTaskContext.java
+96
-0
src/test/java/mvd/jester/simulator/schmidmottok/TestJobContext.java
+18
-0
src/test/java/mvd/jester/simulator/schmidmottok/TestSegmentContext.java
+106
-0
src/test/java/mvd/jester/simulator/schmidmottok/TestTaskContext.java
+96
-0
No files found.
src/main/java/mvd/jester/App.java
View file @
5e54ea41
...
...
@@ -12,7 +12,7 @@ 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
,
4000
);
TestEnvironment
te
=
new
TestEnvironment
(
builder
,
4000
0
);
te
.
registerSchedulingAlgorithm
(
new
RateMonotonic
());
te
.
registerSchedulingAlgorithm
(
new
EarliestDeadlineFirst
());
...
...
@@ -24,44 +24,5 @@ public class App {
mvd
.
jester
.
simulator
.
SchmidMottok
.
class
);
te
.
runTests
();
// boolean mbWorked = false;
// boolean smWorked = false;
// SystemSetup thisOne = null;
// EventPrinter.enablePrinter();
// do {
// SystemSetup.Builder builder = new SystemSetup.Builder().setNumberOfProcessors(8);
// SystemSetup systemSetup = builder.build();
// SchmidMottok sm = new SchmidMottok(systemSetup);
// MaiaBertogna mb = new MaiaBertogna(systemSetup);
// smWorked = sm.runSimulation();
// mbWorked = mb.runSimulation();
// thisOne = systemSetup;
// } while (smWorked == mbWorked);
// try (PrintWriter out = new PrintWriter("./results/manCheck.txt")) {
// out.println(thisOne);
// } catch (Exception e) {
// System.out.println("Ähm something went horribly wrong!");
// }
// SchmidMottok sm = new SchmidMottok(thisOne);
// MaiaBertogna mb = new MaiaBertogna(thisOne);
// mb.runSimulation();
// sm.runSimulation();
// SystemSetup systemSetup = SystemSetup.fromFile("results/manCheck.txt");
// EventPrinter.enablePrinter();
// SchmidMottok sm = new SchmidMottok(systemSetup);
// sm.runSimulation();
}
}
src/main/java/mvd/jester/TestEnvironment.java
View file @
5e54ea41
...
...
@@ -6,6 +6,7 @@ import java.util.HashMap;
import
java.util.HashSet
;
import
java.util.Map
;
import
java.util.Set
;
import
com.google.common.collect.HashBasedTable
;
import
com.google.common.collect.Table
;
import
mvd.jester.model.SystemSetup
;
import
mvd.jester.priority.PriorityManager
;
...
...
@@ -81,11 +82,11 @@ public class TestEnvironment {
Set
<
AbstractTest
>
abstractTestInstances
=
new
HashSet
<>();
Set
<
AbstractSimulator
>
abstractSimulatorInstances
=
new
HashSet
<>();
Map
<
Long
,
Map
<
AbstractTest
,
Long
>>
testResult
s
=
new
HashMap
<>();
Map
<
Long
,
Map
<
AbstractSimulator
,
Long
>>
simulatorResults
=
new
HashMap
<>();
//
Map<Long, Table<PriorityManager, AbstractTest, Long>> testResults = new HashMap<>();
//
Map<Long, Table<PriorityManager, AbstractSimulator, Long>> simulatorResults =
//
new HashMap<>();
Map
<
Long
,
Long
>
totalNumberOfTask
s
=
new
HashMap
<>();
Map
<
Long
,
Table
<
PriorityManager
,
AbstractTest
,
Long
>>
testResults
=
new
HashMap
<>();
Map
<
Long
,
Table
<
PriorityManager
,
AbstractSimulator
,
Long
>>
simulatorResults
=
new
HashMap
<>();
for
(
Constructor
<?
extends
AbstractTest
>
c
:
abstractTests
)
{
try
{
...
...
@@ -120,24 +121,34 @@ public class TestEnvironment {
long
roundedUtilization
=
(
long
)
(
utilization
*
10
);
totalNumberOfTasks
.
compute
(
roundedUtilization
,
(
k
,
v
)
->
v
==
null
?
1
:
v
+
1
);
for
(
PriorityManager
priorityManager
:
schedulingAlgorithms
)
{
for
(
AbstractTest
test
:
abstractTestInstances
)
{
Table
<
PriorityManager
,
AbstractTest
,
Long
>
table
=
testResults
.
computeIfAbsent
(
roundedUtilization
,
k
->
HashBasedTable
.
create
());
if
(
priorityManager
.
hasTest
(
test
)
&&
test
.
runSchedulabilityCheck
(
priorityManager
))
{
testResults
.
computeIfAbsent
(
roundedUtilization
,
k
->
new
HashMap
<
AbstractTest
,
Long
>())
.
compute
(
test
,
(
k
,
v
)
->
(
v
==
null
)
?
1
:
v
+
1
);
Long
val
=
table
.
get
(
priorityManager
,
test
);
if
(
val
==
null
)
{
table
.
put
(
priorityManager
,
test
,
(
long
)
1
);
}
else
{
table
.
put
(
priorityManager
,
test
,
val
+
1
);
}
}
}
for
(
AbstractSimulator
simulator
:
abstractSimulatorInstances
)
{
Table
<
PriorityManager
,
AbstractSimulator
,
Long
>
table
=
simulatorResults
.
computeIfAbsent
(
roundedUtilization
,
k
->
HashBasedTable
.
create
());
if
(
priorityManager
.
hasSimulator
(
simulator
)
&&
simulator
.
runSimulation
(
priorityManager
))
{
simulatorResults
.
computeIfAbsent
(
roundedUtilization
,
k
->
new
HashMap
<
AbstractSimulator
,
Long
>())
.
compute
(
simulator
,
(
k
,
v
)
->
(
v
==
null
)
?
1
:
v
+
1
);
Long
val
=
table
.
get
(
priorityManager
,
simulator
);
if
(
val
==
null
)
{
table
.
put
(
priorityManager
,
simulator
,
(
long
)
1
);
}
else
{
table
.
put
(
priorityManager
,
simulator
,
val
+
1
);
}
}
}
...
...
@@ -148,66 +159,84 @@ public class TestEnvironment {
}
}
logTestResults
(
abstractTestInstances
,
testResult
s
);
logSimulationResults
(
abstractSimulatorInstances
,
simulatorResult
s
);
logTestResults
(
testResults
,
totalNumberOfTask
s
);
logSimulationResults
(
simulatorResults
,
totalNumberOfTask
s
);
}
private
void
logTestResults
(
Set
<
AbstractTest
>
testCase
s
,
Map
<
Long
,
Map
<
AbstractTest
,
Long
>>
result
s
)
{
private
void
logTestResults
(
Map
<
Long
,
Table
<
PriorityManager
,
AbstractTest
,
Long
>>
result
s
,
Map
<
Long
,
Long
>
totalNumberOfTask
s
)
{
LocalTime
date
=
LocalTime
.
now
();
Logger
log
=
new
Logger
(
"./results/results_"
+
systemSetup
.
getNumberOfProcessors
()
+
"_"
+
date
.
getHour
()
+
":"
+
date
.
getMinute
()
+
".txt"
);
String
firstLine
=
new
String
(
"Utilization"
);
for
(
AbstractTest
t
:
testCases
)
{
firstLine
=
firstLine
+
"\t"
+
t
.
getName
();
if
(!
results
.
isEmpty
())
{
Long
first
=
results
.
keySet
().
iterator
().
next
();
for
(
PriorityManager
p
:
results
.
get
(
first
).
rowKeySet
())
{
for
(
AbstractTest
t
:
results
.
get
(
first
).
columnKeySet
())
{
firstLine
=
firstLine
+
"\t"
+
t
.
getName
()
+
"_"
+
p
.
getName
();
}
}
log
.
log
(
firstLine
);
for
(
Long
util
:
results
.
keySet
())
{
String
line
=
String
.
valueOf
((
double
)
util
/
10
);
Map
<
AbstractTest
,
Long
>
tests
=
results
.
get
(
util
);
Table
<
PriorityManager
,
AbstractTest
,
Long
>
tests
=
results
.
get
(
util
);
for
(
AbstractTest
t
:
testCases
)
{
if
(
tests
.
containsKey
(
t
))
{
line
+=
"\t"
+
tests
.
get
(
t
);
for
(
PriorityManager
p
:
tests
.
rowKeySet
())
{
for
(
AbstractTest
t
:
tests
.
columnKeySet
())
{
if
(
tests
.
contains
(
p
,
t
))
{
line
+=
"\t"
+
tests
.
get
(
p
,
t
);
}
else
{
line
+=
"\t"
+
"0"
;
}
}
}
log
.
log
(
line
);
}
}
log
.
finalize
();
}
private
void
logSimulationResults
(
Set
<
AbstractSimulator
>
testCases
,
Map
<
Long
,
Map
<
AbstractSimulator
,
Long
>>
results
)
{
private
void
logSimulationResults
(
Map
<
Long
,
Table
<
PriorityManager
,
AbstractSimulator
,
Long
>>
results
,
Map
<
Long
,
Long
>
totalNumberOfTasks
)
{
LocalTime
date
=
LocalTime
.
now
();
Logger
log
=
new
Logger
(
"./results/results_sim_"
+
systemSetup
.
getNumberOfProcessors
()
+
"_"
+
date
.
getHour
()
+
":"
+
date
.
getMinute
()
+
".txt"
);
String
firstLine
=
new
String
(
"Utilization"
);
String
firstLine
=
new
String
(
"Utilization\tTotal"
);
if
(!
results
.
isEmpty
())
{
Long
first
=
results
.
keySet
().
iterator
().
next
();
for
(
AbstractSimulator
t
:
testCases
)
{
firstLine
=
firstLine
+
"\t"
+
t
.
getName
();
for
(
PriorityManager
p
:
results
.
get
(
first
).
rowKeySet
())
{
for
(
AbstractSimulator
s
:
results
.
get
(
first
).
columnKeySet
())
{
firstLine
=
firstLine
+
"\t"
+
s
.
getName
()
+
"_"
+
p
.
getName
();
}
}
log
.
log
(
firstLine
);
for
(
Long
util
:
result
s
.
keySet
())
{
for
(
Long
util
:
totalNumberOfTask
s
.
keySet
())
{
String
line
=
String
.
valueOf
((
double
)
util
/
10
);
Map
<
AbstractSimulator
,
Long
>
tests
=
results
.
get
(
util
);
line
+=
"\t"
+
totalNumberOfTasks
.
get
(
util
);
Table
<
PriorityManager
,
AbstractSimulator
,
Long
>
tests
=
results
.
get
(
util
);
for
(
AbstractSimulator
t
:
testCases
)
{
if
(
tests
.
containsKey
(
t
))
{
line
+=
"\t"
+
tests
.
get
(
t
);
for
(
PriorityManager
p
:
tests
.
rowKeySet
())
{
for
(
AbstractSimulator
s
:
tests
.
columnKeySet
())
{
if
(
tests
.
contains
(
p
,
s
))
{
line
+=
"\t"
+
tests
.
get
(
p
,
s
);
}
else
{
line
+=
"\t"
+
"0"
;
}
}
}
log
.
log
(
line
);
}
}
log
.
finalize
();
}
...
...
src/main/java/mvd/jester/priority/EarliestDeadlineFirst.java
View file @
5e54ea41
...
...
@@ -6,6 +6,7 @@ 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.internals.TaskContextInterface
;
import
mvd.jester.tests.AbstractTest
;
...
...
@@ -16,7 +17,7 @@ public class EarliestDeadlineFirst implements PriorityManager {
final
static
Set
<
Class
<?
extends
AbstractTest
>>
abstractTests
=
new
HashSet
<>();
final
static
Set
<
Class
<?
extends
AbstractSimulator
>>
abstractSimulators
=
new
HashSet
<>(
Arrays
.
asList
(
MaiaBertogna
.
class
));
new
HashSet
<>(
Arrays
.
asList
(
MaiaBertogna
.
class
,
SchmidMottok
.
class
));
/**
* Compare the priority of two tasks according to the Rate Monotonic policy
...
...
src/main/java/mvd/jester/simulator/AbstractSimulator.java
View file @
5e54ea41
...
...
@@ -91,7 +91,7 @@ public abstract class AbstractSimulator implements SimulatorInterface {
private
long
getHyperPeriod
()
{
return
systemSetup
.
getTasks
().
stream
().
max
(
Comparator
.
comparing
(
Task:
:
getPeriod
)).
get
()
.
getPeriod
()
*
2
;
/* * 10 */
.
getPeriod
()
*
10
;
}
private
class
ProcessorComparator
implements
Comparator
<
ProcessorContext
>
{
...
...
src/main/java/mvd/jester/simulator/internals/maiabertogna/SegmentContext.java
View file @
5e54ea41
...
...
@@ -30,7 +30,7 @@ public class SegmentContext {
return
segment
;
}
Optional
<
JobContextInterface
>
getNextJob
()
{
public
Optional
<
JobContextInterface
>
getNextJob
()
{
return
jobs
.
stream
()
.
filter
(
j
->
!
j
.
getCurrentProcessor
().
isPresent
()
&&
j
.
checkExecutionTime
())
.
findFirst
();
...
...
src/main/java/mvd/jester/simulator/internals/maiabertogna/TaskContext.java
View file @
5e54ea41
...
...
@@ -64,10 +64,7 @@ public class TaskContext implements TaskContextInterface {
public
Optional
<
JobContextInterface
>
getNextJob
()
{
if
(
currentSegment
<
segments
.
size
())
{
Optional
<
JobContextInterface
>
optionalJob
=
segments
.
get
(
currentSegment
).
getNextJob
();
if
(
optionalJob
.
isPresent
())
{
return
optionalJob
;
}
return
segments
.
get
(
currentSegment
).
getNextJob
();
}
return
Optional
.
empty
();
...
...
src/main/java/mvd/jester/simulator/internals/schmidmottok/SegmentContext.java
View file @
5e54ea41
...
...
@@ -43,7 +43,7 @@ public class SegmentContext {
return
jobs
.
size
();
}
Optional
<
JobContextInterface
>
getNextJob
()
{
public
Optional
<
JobContextInterface
>
getNextJob
()
{
boolean
taskletAvailable
=
tasklets
.
stream
()
.
anyMatch
(
t
->
!
t
.
getCurrentJob
().
isPresent
()
&&
t
.
checkExecutionTime
());
...
...
@@ -63,7 +63,7 @@ public class SegmentContext {
}
}
Optional
<
TaskletContext
>
getNextTasklet
()
{
public
Optional
<
TaskletContext
>
getNextTasklet
()
{
return
tasklets
.
stream
()
.
filter
(
t
->
!
t
.
getCurrentJob
().
isPresent
()
&&
t
.
checkExecutionTime
()).
findFirst
();
}
...
...
src/main/java/mvd/jester/simulator/internals/schmidmottok/TaskContext.java
View file @
5e54ea41
...
...
@@ -64,10 +64,7 @@ public class TaskContext implements TaskContextInterface {
public
Optional
<
JobContextInterface
>
getNextJob
()
{
if
(
currentSegment
<
segments
.
size
())
{
Optional
<
JobContextInterface
>
optionalJob
=
segments
.
get
(
currentSegment
).
getNextJob
();
if
(
optionalJob
.
isPresent
())
{
return
optionalJob
;
}
return
segments
.
get
(
currentSegment
).
getNextJob
();
}
return
Optional
.
empty
();
...
...
src/test/java/mvd/jester/model/TestSegment.java
0 → 100644
View file @
5e54ea41
package
mvd
.
jester
.
model
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
import
com.google.common.math.LongMath
;
import
org.junit.jupiter.api.DisplayName
;
import
org.junit.jupiter.api.Test
;
/**
* SegmentTest
*/
public
class
TestSegment
{
@Test
@DisplayName
(
"Test if dynamic segments are constructed correctly."
)
public
void
testSegmentConstruction
()
{
Segment
s1
=
new
Segment
(
100
,
10
);
Segment
s2
=
new
Segment
(
9
,
10
);
assertTrue
(
s1
.
getJobWcet
()
==
100
);
assertTrue
(
s1
.
getNumberOfJobs
()
==
10
);
assertTrue
(
s1
.
getNumberOfTasklets
()
==
100
);
assertTrue
(
s1
.
getTaskletWcet
()
==
10
);
assertTrue
(
s2
.
getJobWcet
()
==
9
);
assertTrue
(
s2
.
getNumberOfJobs
()
==
10
);
assertTrue
(
s2
.
getNumberOfTasklets
()
==
9
*
10
/
LongMath
.
gcd
(
9
,
10
));
assertTrue
(
s2
.
getTaskletWcet
()
==
LongMath
.
gcd
(
9
,
10
));
}
}
src/test/java/mvd/jester/model/T
askSetTest
.java
→
src/test/java/mvd/jester/model/T
estSystemSetup
.java
View file @
5e54ea41
...
...
@@ -5,7 +5,7 @@ import org.junit.jupiter.api.DisplayName;
import
org.junit.jupiter.api.Test
;
public
class
T
askSetTest
{
public
class
T
estSystemSetup
{
private
static
final
int
NUMBER_OF_SETS
=
1000
;
...
...
@@ -14,7 +14,8 @@ public class TaskSetTest {
public
void
testRandomTaskSetGeneration
()
{
for
(
int
i
=
0
;
i
<
NUMBER_OF_SETS
;
++
i
)
{
SystemSetup
taskSet
=
new
SystemSetup
.
Builder
().
build
();
SystemSetup
taskSet
=
new
SystemSetup
.
Builder
().
setNumberOfSegments
(
1
,
7
)
.
setNumberOfJobs
(
2
,
10
).
setPeriods
(
100
,
1000
).
build
();
for
(
Task
t
:
taskSet
.
getTasks
())
{
assertTrue
(
t
.
getPeriod
()
>=
100
);
...
...
@@ -29,11 +30,11 @@ public class TaskSetTest {
assertTrue
(
s
.
getJobWcet
()
>=
1
);
assertTrue
(
s
.
getJobWcet
()
<=
maxJobWcet
);
assertTrue
(
s
.
getNumberOfJobs
()
>=
1
);
assertTrue
(
s
.
getNumberOfJobs
()
<=
6
);
assertTrue
(
s
.
getNumberOfJobs
()
<=
10
);
}
assertTrue
(
t
.
getSegments
().
size
()
>=
1
);
assertTrue
(
t
.
getSegments
().
size
()
<=
5
);
assertTrue
(
t
.
getSegments
().
size
()
<=
7
);
}
}
...
...
src/test/java/mvd/jester/priority/TestEarliestDeadlineFirst.java
0 → 100644
View file @
5e54ea41
package
mvd
.
jester
.
priority
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertThrows
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
import
java.util.HashSet
;
import
org.junit.jupiter.api.DisplayName
;
import
org.junit.jupiter.api.Test
;
import
mvd.jester.model.Task
;
import
mvd.jester.simulator.internals.maiabertogna.TaskContext
;
/**
* TestEarliestDeadlineFirst
*/
public
class
TestEarliestDeadlineFirst
{
@Test
@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
);
assertThrows
(
RuntimeException
.
class
,
()
->
edf
.
compare
(
t1
,
t2
));
assertTrue
(
edf
.
compare
(
tc1
,
tc2
)
<
0
);
}
}
src/test/java/mvd/jester/priority/TestRateMonotonic.java
0 → 100644
View file @
5e54ea41
package
mvd
.
jester
.
priority
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
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.Task
;
import
mvd.jester.simulator.internals.maiabertogna.TaskContext
;
/**
* TestRateMonotonic
*/
public
class
TestRateMonotonic
{
@Test
@DisplayName
(
"Test if priority manager returns the correct priority."
)
public
void
testPriority
()
{
RateMonotonic
rm
=
new
RateMonotonic
();
Task
t1
=
new
Task
(
100
,
new
HashSet
<
Segment
>());
Task
t2
=
new
Task
(
200
,
new
HashSet
<
Segment
>());
TaskContext
tc1
=
new
TaskContext
(
t1
,
0
);
TaskContext
tc2
=
new
TaskContext
(
t2
,
0
);
assertTrue
(
rm
.
compare
(
t1
,
t2
)
<
0
);
assertTrue
(
rm
.
compare
(
tc1
,
tc2
)
<
0
);
}
}
src/test/java/mvd/jester/simulator/maiabertogna/TestJobContext.java
0 → 100644
View file @
5e54ea41
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
.
ArgumentMatchers
.
anyLong
;
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.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
numberOfJobs
=
ThreadLocalRandom
.
current
().
nextLong
(
1
,
10
);
long
jobWcet
=
ThreadLocalRandom
.
current
().
nextLong
(
20
,
50
);
Segment
s
=
new
Segment
(
jobWcet
,
numberOfJobs
);
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
=
new
ProcessorContext
(
0
);
job
.
setCurrentProcessor
(
p
);
p
.
setJob
(
job
);
assertTrue
(
job
.
checkExecutionTime
());
for
(
int
i
=
0
;
i
<
jobWcet
-
1
;
++
i
)
{
assertFalse
(
job
.
updateExecution
(
i
).
isPresent
());
}
Optional
<
TaskContextInterface
>
otc
=
job
.
updateExecution
(
0
);
assertTrue
(
otc
.
isPresent
());
assertTrue
(
tc
.
equals
(
otc
.
get
()));
assertFalse
(
p
.
getJob
().
isPresent
());
assertFalse
(
job
.
getCurrentProcessor
().
isPresent
());
assertFalse
(
job
.
checkExecutionTime
());
}
}
}
src/test/java/mvd/jester/simulator/maiabertogna/TestSegmentContext.java
0 → 100644
View file @
5e54ea41
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
<
JobContextInterface
>
job
=
Optional
.
empty
();
for
(
int
i
=
0
;
i
<
numberOfJobs
;
++
i
)
{
job
=
sc
.
getNextJob
();
assertTrue
(
job
.
isPresent
());
job
.
get
().
setCurrentProcessor
(
new
ProcessorContext
(
i
));
}
assertFalse
(
sc
.
getNextJob
().
isPresent
());
sc
=
new
SegmentContext
(
tc
,
s
);
for
(
int
i
=
0
;
i
<
numberOfJobs
;
++
i
)
{
job
=
sc
.
getNextJob
();
assertTrue
(
job
.
isPresent
());
job
.
get
().
setCurrentProcessor
(
new
ProcessorContext
(
i
));
for
(
int
j
=
0
;
j
<
jobWcet
;
++
j
)
{
job
.
get
().
updateExecution
(
i
);
}
}
assertFalse
(
sc
.
getNextJob
().
isPresent
());
}
}
}
src/test/java/mvd/jester/simulator/maiabertogna/TestTaskContext.java
0 → 100644
View file @
5e54ea41
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
<
Segment
>
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
<
TaskContextInterface
>
tci
=
tc
.
acceptNotification
(
0
);
assertTrue
(
tci
.
isPresent
());
assertTrue
(
tci
.
get
().
equals
(
tc
));
}
}
@Test
@DisplayName
(
"Check if the next job is returned correctly."
)
public
void
testGetNextJob
()
{
for
(
int
run
=
0
;
run
<
100
;
++
run
)
{
// long numberOfJobs = ThreadLocalRandom.current().nextLong(1, 10);
// long numberOfSegments = ThreadLocalRandom.current().nextLong(3, 10);
Set
<
Segment
>
segments
=
new
LinkedHashSet
<>();
segments
.
add
(
new
Segment
(
5
,
1
));
segments
.
add
(
new
Segment
(
10
,
10
));
segments
.
add
(
new
Segment
(
15
,
1
));
Task
t
=
new
Task
(
100
,
segments
);
TaskContext
tc
=
new
TaskContext
(
t
,
0
);
Optional
<
JobContextInterface
>
job
=
tc
.
getNextJob
();
assertTrue
(
job
.
isPresent
());
job
.
get
().
setCurrentProcessor
(
new
ProcessorContext
(
0
));
assertFalse
(
tc
.
getNextJob
().
isPresent
());
tc
.
acceptNotification
(
0
);
for
(
int
i
=
0
;
i
<
9
;
++
i
)
{
job
=
tc
.
getNextJob
();
assertTrue
(
job
.
isPresent
());
job
.
get
().
setCurrentProcessor
(
new
ProcessorContext
(
i
));
tc
.
acceptNotification
(
0
);
}
job
=
tc
.
getNextJob
();
assertTrue
(
job
.
isPresent
());
job
.
get
().
setCurrentProcessor
(
new
ProcessorContext
(
20
));
assertFalse
(
tc
.
getNextJob
().
isPresent
());
tc
.
acceptNotification
(
0
);
assertTrue
(
tc
.
getNextJob
().
isPresent
());
}
}
}
src/test/java/mvd/jester/simulator/schmidmottok/TestJobContext.java
0 → 100644
View file @
5e54ea41
package
mvd
.
jester
.
simulator
.
schmidmottok
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
import
org.junit.jupiter.api.DisplayName
;
import
org.junit.jupiter.api.Test
;
/**
* TestJobContext
*/
public
class
TestJobContext
{
@Test
@DisplayName
(
"Check if the job is prepared correctly."
)
public
void
testPrepareJob
()
{
assertTrue
(
true
);
}
}
src/test/java/mvd/jester/simulator/schmidmottok/TestSegmentContext.java
0 → 100644
View file @
5e54ea41
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
<
JobContextInterface
>
job
=
Optional
.
empty
();
when
(
tc
.
acceptNotification
(
jobWcet
-
1
)).
thenReturn
(
Optional
.
empty
());
long
numJobs
=
numberOfJobs
>
4
?
4
:
numberOfJobs
;
for
(
int
i
=
0
;
i
<
numJobs
;
++
i
)
{
job
=
sc
.
getNextJob
();
assertTrue
(
job
.
isPresent
());
job
.
get
().
setCurrentProcessor
(
new
ProcessorContext
(
i
));
}
assertFalse
(
sc
.
getNextJob
().
isPresent
());
sc
=
new
SegmentContext
(
tc
,
s
,
4
);
job
=
sc
.
getNextJob
();
assertTrue
(
job
.
isPresent
());
job
.
get
().
setCurrentProcessor
(
new
ProcessorContext
(
0
));
for
(
int
i
=
0
;
i
<
jobWcet
*
numberOfJobs
;
++
i
)
{
job
.
get
().
updateExecution
(
i
);
}
assertFalse
(
sc
.
getNextJob
().
isPresent
());
}
}
@Test
@DisplayName
(
"Check if SegmentContext returns the correct amount of tasklets."
)
void
testGetNextTasklet
()
{
for
(
int
run
=
0
;
run
<
100
;
++
run
)
{
long
numberOfJobs
=
ThreadLocalRandom
.
current
().
nextLong
(
1
,
10
);
long
jobWcet
=
ThreadLocalRandom
.
current
().
nextLong
(
20
,
50
);
Segment
s
=
mock
(
Segment
.
class
);
when
(
s
.
getNumberOfJobs
()).
thenReturn
(
numberOfJobs
);
when
(
s
.
getJobWcet
()).
thenReturn
(
jobWcet
);
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
<
TaskletContext
>
tci
=
sc
.
getNextTasklet
();
assertTrue
(
tci
.
isPresent
());
tci
.
get
().
setCurrentJob
(
new
JobContext
(
tc
,
sc
));
}
assertFalse
(
sc
.
getNextTasklet
().
isPresent
());
sc
=
new
SegmentContext
(
tc
,
s
,
4
);
for
(
int
i
=
0
;
i
<
jobWcet
;
++
i
)
{
Optional
<
TaskletContext
>
tasklet
=
sc
.
getNextTasklet
();
assertTrue
(
tasklet
.
isPresent
());
tasklet
.
get
().
setCurrentJob
(
new
JobContext
(
tc
,
sc
));
for
(
int
j
=
0
;
j
<
numberOfJobs
;
++
j
)
{
tasklet
.
get
().
updateExecution
(
j
);
}
}
assertFalse
(
sc
.
getNextTasklet
().
isPresent
());
}
}
}
src/test/java/mvd/jester/simulator/schmidmottok/TestTaskContext.java
0 → 100644
View file @
5e54ea41
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
<
Segment
>
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
<
TaskContextInterface
>
tci
=
tc
.
acceptNotification
(
0
);
assertTrue
(
tci
.
isPresent
());
assertTrue
(
tci
.
get
().
equals
(
tc
));
}
}
@Test
@DisplayName
(
"Check if the next job is returned correctly."
)
public
void
testGetNextJob
()
{
for
(
int
run
=
0
;
run
<
100
;
++
run
)
{
// long numberOfJobs = ThreadLocalRandom.current().nextLong(1, 10);
// long numberOfSegments = ThreadLocalRandom.current().nextLong(3, 10);
Set
<
Segment
>
segments
=
new
LinkedHashSet
<>();
segments
.
add
(
new
Segment
(
5
,
1
));
segments
.
add
(
new
Segment
(
10
,
10
));
segments
.
add
(
new
Segment
(
15
,
1
));
Task
t
=
new
Task
(
100
,
segments
);
TaskContext
tc
=
new
TaskContext
(
t
,
1
,
0
);
Optional
<
JobContextInterface
>
job
=
tc
.
getNextJob
();
assertTrue
(
job
.
isPresent
());
job
.
get
().
setCurrentProcessor
(
new
ProcessorContext
(
0
));
assertFalse
(
tc
.
getNextJob
().
isPresent
());
tc
.
acceptNotification
(
0
);
for
(
int
i
=
0
;
i
<
9
;
++
i
)
{
job
=
tc
.
getNextJob
();
assertTrue
(
job
.
isPresent
());
job
.
get
().
setCurrentProcessor
(
new
ProcessorContext
(
i
));
tc
.
acceptNotification
(
0
);
}
job
=
tc
.
getNextJob
();
assertTrue
(
job
.
isPresent
());
job
.
get
().
setCurrentProcessor
(
new
ProcessorContext
(
20
));
assertFalse
(
tc
.
getNextJob
().
isPresent
());
tc
.
acceptNotification
(
0
);
assertTrue
(
tc
.
getNextJob
().
isPresent
());
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment