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
6b1ef83a
authored
5 years ago
by
Michael Schmid
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added new unit tests
parent
5e54ea41
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
373 additions
and
83 deletions
+373
-83
src/main/java/mvd/jester/TestEnvironment.java
+103
-67
src/main/java/mvd/jester/simulator/internals/maiabertogna/JobContext.java
+2
-0
src/main/java/mvd/jester/simulator/internals/schmidmottok/TaskletContext.java
+2
-0
src/test/java/mvd/jester/simulator/TestProcessorContext.java
+107
-0
src/test/java/mvd/jester/simulator/maiabertogna/TestJobContext.java
+10
-5
src/test/java/mvd/jester/simulator/schmidmottok/TestJobContext.java
+82
-1
src/test/java/mvd/jester/simulator/schmidmottok/TestSegmentContext.java
+2
-3
src/test/java/mvd/jester/simulator/schmidmottok/TestTaskContext.java
+12
-7
src/test/java/mvd/jester/simulator/schmidmottok/TestTaskletContext.java
+53
-0
No files found.
src/main/java/mvd/jester/TestEnvironment.java
View file @
6b1ef83a
...
...
@@ -79,18 +79,18 @@ public class TestEnvironment {
}
public
void
runTests
()
{
Set
<
AbstractTest
>
abstractTestInstances
=
new
HashSet
<>();
Set
<
AbstractSimulato
r
>
abstractSimulatorInstances
=
new
HashSet
<>();
Set
<
TestPair
>
abstractTestInstances
=
new
HashSet
<>();
Set
<
SimulatorPai
r
>
abstractSimulatorInstances
=
new
HashSet
<>();
Map
<
Long
,
Long
>
totalNumberOfTasks
=
new
HashMap
<>();
Map
<
Long
,
Table
<
PriorityManager
,
AbstractTest
,
Long
>>
testResults
=
new
HashMap
<>();
Map
<
Long
,
Table
<
PriorityManager
,
AbstractSimulator
,
Long
>>
simulatorResults
=
new
HashMap
<>();
Table
<
Long
,
TestPair
,
Long
>
testResults
=
HashBasedTable
.
create
();
Table
<
Long
,
SimulatorPair
,
Long
>
simulatorResults
=
HashBasedTable
.
create
();
for
(
PriorityManager
pm
:
schedulingAlgorithms
)
{
for
(
Constructor
<?
extends
AbstractTest
>
c
:
abstractTests
)
{
try
{
abstractTestInstances
.
add
(
c
.
newInstance
(
this
.
systemSetup
));
abstractTestInstances
.
add
(
new
TestPair
(
pm
,
c
.
newInstance
(
this
.
systemSetup
)
));
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"Could not instantiate object of AbstractTest!"
);
}
...
...
@@ -98,11 +98,13 @@ public class TestEnvironment {
for
(
Constructor
<?
extends
AbstractSimulator
>
c
:
abstractSimulators
)
{
try
{
abstractSimulatorInstances
.
add
(
c
.
newInstance
(
this
.
systemSetup
));
abstractSimulatorInstances
.
add
(
new
SimulatorPair
(
pm
,
c
.
newInstance
(
this
.
systemSetup
)));
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"Could not instantiate object of AbstractSimulator!"
);
}
}
}
long
checkedTasksets
=
0
;
...
...
@@ -123,36 +125,34 @@ public class TestEnvironment {
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
))
{
Long
val
=
table
.
get
(
priorityManager
,
test
);
if
(
val
==
null
)
{
table
.
put
(
priorityManager
,
test
,
(
long
)
1
);
}
else
{
table
.
put
(
priorityManager
,
test
,
val
+
1
);
for
(
TestPair
testInstance
:
abstractTestInstances
)
{
PriorityManager
priorityManager
=
testInstance
.
getPriorityManager
();
AbstractTest
abstractTest
=
testInstance
.
getAbstractTest
();
if
(!
testResults
.
contains
(
roundedUtilization
,
testInstance
))
{
testResults
.
put
(
roundedUtilization
,
testInstance
,
(
long
)
0
);
}
if
(
priorityManager
.
hasTest
(
abstractTest
)
&&
abstractTest
.
runSchedulabilityCheck
(
priorityManager
))
{
Long
val
=
testResults
.
get
(
roundedUtilization
,
testInstance
);
testResults
.
put
(
roundedUtilization
,
testInstance
,
val
+
1
);
}
}
for
(
AbstractSimulator
simulator
:
abstractSimulatorInstances
)
{
Table
<
PriorityManager
,
AbstractSimulator
,
Long
>
table
=
simulatorResults
.
computeIfAbsent
(
roundedUtilization
,
k
->
HashBasedTable
.
create
());
if
(
priorityManager
.
hasSimulator
(
simulator
)
&&
simulator
.
runSimulation
(
priorityManager
))
{
Long
val
=
table
.
get
(
priorityManager
,
simulator
);
if
(
val
==
null
)
{
table
.
put
(
priorityManager
,
simulator
,
(
long
)
1
);
}
else
{
table
.
put
(
priorityManager
,
simulator
,
val
+
1
);
for
(
SimulatorPair
simulatorInstance
:
abstractSimulatorInstances
)
{
PriorityManager
priorityManager
=
simulatorInstance
.
getPriorityManager
();
AbstractSimulator
abstractSimulator
=
simulatorInstance
.
getAbstractSimulator
();
if
(!
simulatorResults
.
contains
(
roundedUtilization
,
simulatorInstance
))
{
simulatorResults
.
put
(
roundedUtilization
,
simulatorInstance
,
(
long
)
0
);
}
if
(
priorityManager
.
hasSimulator
(
abstractSimulator
)
&&
abstractSimulator
.
runSimulation
(
priorityManager
))
{
Long
val
=
simulatorResults
.
get
(
roundedUtilization
,
simulatorInstance
);
simulatorResults
.
put
(
roundedUtilization
,
simulatorInstance
,
val
+
1
);
}
}
}
builder
.
addTask
(
systemSetup
);
utilization
=
this
.
systemSetup
.
getUtilization
();
...
...
@@ -163,7 +163,7 @@ public class TestEnvironment {
logSimulationResults
(
simulatorResults
,
totalNumberOfTasks
);
}
private
void
logTestResults
(
Map
<
Long
,
Table
<
PriorityManager
,
AbstractTest
,
Long
>
>
results
,
private
void
logTestResults
(
Table
<
Long
,
TestPair
,
Long
>
results
,
Map
<
Long
,
Long
>
totalNumberOfTasks
)
{
LocalTime
date
=
LocalTime
.
now
();
Logger
log
=
new
Logger
(
"./results/results_"
+
systemSetup
.
getNumberOfProcessors
()
+
"_"
...
...
@@ -171,28 +171,17 @@ public class TestEnvironment {
String
firstLine
=
new
String
(
"Utilization"
);
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
();
}
for
(
TestPair
testPair
:
results
.
columnKeySet
())
{
firstLine
=
firstLine
+
"\t"
+
testPair
.
getName
();
}
log
.
log
(
firstLine
);
for
(
Long
util
:
results
.
keySet
())
{
String
line
=
String
.
valueOf
((
double
)
util
/
10
);
Table
<
PriorityManager
,
AbstractTest
,
Long
>
tests
=
results
.
get
(
util
);
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"
;
}
}
for
(
Long
util
:
totalNumberOfTasks
.
keySet
())
{
String
line
=
String
.
valueOf
((
double
)
util
/
10
)
+
"\t"
+
totalNumberOfTasks
.
get
(
util
);
for
(
TestPair
simulatorPair
:
results
.
columnKeySet
())
{
line
+=
"\t"
+
results
.
get
(
util
,
simulatorPair
);
}
log
.
log
(
line
);
}
...
...
@@ -201,8 +190,7 @@ public class TestEnvironment {
log
.
finalize
();
}
private
void
logSimulationResults
(
Map
<
Long
,
Table
<
PriorityManager
,
AbstractSimulator
,
Long
>>
results
,
private
void
logSimulationResults
(
Table
<
Long
,
SimulatorPair
,
Long
>
results
,
Map
<
Long
,
Long
>
totalNumberOfTasks
)
{
LocalTime
date
=
LocalTime
.
now
();
Logger
log
=
new
Logger
(
"./results/results_sim_"
+
systemSetup
.
getNumberOfProcessors
()
+
"_"
...
...
@@ -210,34 +198,82 @@ public class TestEnvironment {
String
firstLine
=
new
String
(
"Utilization\tTotal"
);
if
(!
results
.
isEmpty
())
{
Long
first
=
results
.
keySet
().
iterator
().
next
();
for
(
SimulatorPair
simulatorPair
:
results
.
columnKeySet
())
{
firstLine
=
firstLine
+
"\t"
+
simulatorPair
.
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
kv
:
totalNumberOfTasks
.
keySet
())
{
String
line
=
String
.
valueOf
((
double
)
kv
/
10
)
+
"\t"
+
totalNumberOfTasks
.
get
(
kv
);
for
(
SimulatorPair
simulatorPair
:
results
.
columnKeySet
())
{
line
+=
"\t"
+
results
.
get
(
kv
,
simulatorPair
);
}
log
.
log
(
line
);
}
}
log
.
log
(
firstLine
);
log
.
finalize
();
}
private
class
SimulatorPair
{
private
final
PriorityManager
priorityManager
;
private
final
AbstractSimulator
abstractSimulator
;
for
(
Long
util
:
totalNumberOfTasks
.
keySet
())
{
String
line
=
String
.
valueOf
((
double
)
util
/
10
);
line
+=
"\t"
+
totalNumberOfTasks
.
get
(
util
);
Table
<
PriorityManager
,
AbstractSimulator
,
Long
>
tests
=
results
.
get
(
util
);
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"
;
public
SimulatorPair
(
PriorityManager
priorityManager
,
AbstractSimulator
abstractSimulator
)
{
this
.
abstractSimulator
=
abstractSimulator
;
this
.
priorityManager
=
priorityManager
;
}
/**
* @return the priorityManager
*/
public
PriorityManager
getPriorityManager
()
{
return
priorityManager
;
}
/**
* @return the abstractSimulator
*/
public
AbstractSimulator
getAbstractSimulator
()
{
return
abstractSimulator
;
}
log
.
log
(
line
);
public
String
getName
()
{
return
abstractSimulator
.
getName
()
+
"_"
+
priorityManager
.
getName
();
}
}
log
.
finalize
();
private
class
TestPair
{
private
final
PriorityManager
priorityManager
;
private
final
AbstractTest
abstractTest
;
public
TestPair
(
PriorityManager
priorityManager
,
AbstractTest
abstractTest
)
{
this
.
abstractTest
=
abstractTest
;
this
.
priorityManager
=
priorityManager
;
}
/**
* @return the priorityManager
*/
public
PriorityManager
getPriorityManager
()
{
return
priorityManager
;
}
/**
* @return the abstractTest
*/
public
AbstractTest
getAbstractTest
()
{
return
abstractTest
;
}
public
String
getName
()
{
return
abstractTest
.
getName
()
+
"_"
+
priorityManager
.
getName
();
}
}
}
This diff is collapsed.
Click to expand it.
src/main/java/mvd/jester/simulator/internals/maiabertogna/JobContext.java
View file @
6b1ef83a
...
...
@@ -37,6 +37,8 @@ public class JobContext implements JobContextInterface {
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
();
...
...
This diff is collapsed.
Click to expand it.
src/main/java/mvd/jester/simulator/internals/schmidmottok/TaskletContext.java
View file @
6b1ef83a
...
...
@@ -44,6 +44,8 @@ public class TaskletContext {
}
currentJob
=
Optional
.
empty
();
return
true
;
}
else
if
(
executionTime
<
0
)
{
throw
new
RuntimeException
(
"Tasklet was executed for longer than its WCET!"
);
}
return
false
;
}
...
...
This diff is collapsed.
Click to expand it.
src/test/java/mvd/jester/simulator/TestProcessorContext.java
0 → 100644
View file @
6b1ef83a
package
mvd
.
jester
.
simulator
;
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
static
org
.
mockito
.
AdditionalMatchers
.
gt
;
import
static
org
.
mockito
.
AdditionalMatchers
.
lt
;
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.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
;
/**
* TestProcessorContext
*/
public
class
TestProcessorContext
{
@Test
@DisplayName
(
"Check if the job execution is updated correctly."
)
void
testUpdateExecution
()
{
for
(
int
run
=
0
;
run
<
100
;
++
run
)
{
long
jobWcet
=
ThreadLocalRandom
.
current
().
nextLong
(
1
,
10
);
TaskContext
task
=
mock
(
TaskContext
.
class
);
JobContext
job
=
mock
(
JobContext
.
class
);
when
(
job
.
updateExecution
(
lt
(
jobWcet
))).
thenReturn
(
Optional
.
empty
());
when
(
job
.
updateExecution
(
jobWcet
)).
thenReturn
(
Optional
.
of
(
task
));
when
(
job
.
updateExecution
(
gt
(
jobWcet
))).
thenThrow
(
RuntimeException
.
class
);
ProcessorContext
processor
=
new
ProcessorContext
(
1
);
assertFalse
(
processor
.
updateExecution
(
0
).
isPresent
());
processor
.
setJob
(
job
);
for
(
int
i
=
0
;
i
<
jobWcet
;
++
i
)
{
assertFalse
(
processor
.
updateExecution
(
i
).
isPresent
());
}
Optional
<
TaskContextInterface
>
tci
=
processor
.
updateExecution
(
jobWcet
);
assertTrue
(
tci
.
isPresent
());
assertTrue
(
tci
.
get
().
equals
(
task
));
assertThrows
(
RuntimeException
.
class
,
()
->
processor
.
updateExecution
(
jobWcet
+
1
));
verify
(
job
,
times
((
int
)
jobWcet
+
2
)).
updateExecution
(
anyLong
());
}
}
@Test
@DisplayName
(
"Check if the processor correctly accepts jobs"
)
void
testAcceptTask
()
{
for
(
int
run
=
0
;
run
<
100
;
++
run
)
{
long
firstPeriod
=
ThreadLocalRandom
.
current
().
nextLong
(
100
,
1000
);
long
secondPeriod
=
ThreadLocalRandom
.
current
().
nextLong
(
100
,
1000
);
JobContext
firstJob
=
mock
(
JobContext
.
class
);
TaskContext
firstTaskContext
=
mock
(
TaskContext
.
class
);
Task
firstTask
=
mock
(
Task
.
class
);
when
(
firstJob
.
getTaskContext
()).
thenReturn
(
firstTaskContext
);
when
(
firstJob
.
prepareJob
(
anyLong
())).
thenReturn
(
true
);
when
(
firstTaskContext
.
getTask
()).
thenReturn
(
firstTask
);
when
(
firstTaskContext
.
getNextJob
()).
thenReturn
(
Optional
.
of
(
firstJob
));
when
(
firstTask
.
getPeriod
()).
thenReturn
((
long
)
firstPeriod
);
JobContext
secondJob
=
mock
(
JobContext
.
class
);
TaskContext
secondTaskContext
=
mock
(
TaskContext
.
class
);
Task
secondTask
=
mock
(
Task
.
class
);
when
(
secondJob
.
getTaskContext
()).
thenReturn
(
secondTaskContext
);
when
(
secondJob
.
prepareJob
(
anyLong
())).
thenReturn
(
true
);
when
(
secondTaskContext
.
getTask
()).
thenReturn
(
secondTask
);
when
(
secondTaskContext
.
getNextJob
()).
thenReturn
(
Optional
.
of
(
secondJob
));
when
(
secondTask
.
getPeriod
()).
thenReturn
((
long
)
secondPeriod
);
ProcessorContext
processor
=
new
ProcessorContext
(
1
);
assertTrue
(
processor
.
acceptTask
(
secondTaskContext
,
run
));
if
(
firstPeriod
<
secondPeriod
)
{
assertTrue
(
processor
.
acceptTask
(
firstTaskContext
,
run
));
}
else
{
assertFalse
(
processor
.
acceptTask
(
firstTaskContext
,
run
));
}
assertFalse
(
processor
.
acceptTask
(
secondTaskContext
,
run
));
int
time
=
firstPeriod
<
secondPeriod
?
1
:
0
;
verify
(
firstJob
,
times
(
time
)).
prepareJob
(
anyLong
());
verify
(
firstJob
,
times
(
time
)).
setCurrentProcessor
(
processor
);
verify
(
firstTaskContext
,
times
(
time
)).
getNextJob
();
verify
(
secondJob
,
times
(
1
)).
prepareJob
(
anyLong
());
verify
(
secondJob
,
times
(
1
)).
setCurrentProcessor
(
processor
);
verify
(
secondJob
,
times
(
time
)).
setCurrentProcessor
(
null
);
verify
(
secondTaskContext
,
times
(
1
)).
getNextJob
();
}
}
}
This diff is collapsed.
Click to expand it.
src/test/java/mvd/jester/simulator/maiabertogna/TestJobContext.java
View file @
6b1ef83a
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
;
...
...
@@ -25,19 +28,18 @@ public class TestJobContext {
@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
);
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
=
new
ProcessorContext
(
0
);
ProcessorContext
p
=
mock
(
ProcessorContext
.
class
);
job
.
setCurrentProcessor
(
p
);
p
.
setJob
(
job
);
assertTrue
(
job
.
checkExecutionTime
());
...
...
@@ -51,6 +53,9 @@ public class TestJobContext {
assertFalse
(
p
.
getJob
().
isPresent
());
assertFalse
(
job
.
getCurrentProcessor
().
isPresent
());
assertFalse
(
job
.
checkExecutionTime
());
verify
(
p
,
times
(
1
)).
setJob
(
null
);
assertThrows
(
RuntimeException
.
class
,
()
->
job
.
updateExecution
(
1
));
}
}
}
This diff is collapsed.
Click to expand it.
src/test/java/mvd/jester/simulator/schmidmottok/TestJobContext.java
View file @
6b1ef83a
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
.
AdditionalMatchers
.
gt
;
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
...
...
@@ -12,7 +28,72 @@ public class TestJobContext {
@Test
@DisplayName
(
"Check if the job is prepared correctly."
)
public
void
testPrepareJob
()
{
assertTrue
(
true
);
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
();
}
}
This diff is collapsed.
Click to expand it.
src/test/java/mvd/jester/simulator/schmidmottok/TestSegmentContext.java
View file @
6b1ef83a
...
...
@@ -80,10 +80,9 @@ public class TestSegmentContext {
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
));
tci
.
get
().
setCurrentJob
(
mock
(
JobContext
.
class
));
}
assertFalse
(
sc
.
getNextTasklet
().
isPresent
());
...
...
@@ -93,7 +92,7 @@ public class TestSegmentContext {
for
(
int
i
=
0
;
i
<
jobWcet
;
++
i
)
{
Optional
<
TaskletContext
>
tasklet
=
sc
.
getNextTasklet
();
assertTrue
(
tasklet
.
isPresent
());
tasklet
.
get
().
setCurrentJob
(
new
JobContext
(
tc
,
sc
));
tasklet
.
get
().
setCurrentJob
(
mock
(
JobContext
.
class
));
for
(
int
j
=
0
;
j
<
numberOfJobs
;
++
j
)
{
tasklet
.
get
().
updateExecution
(
j
);
}
...
...
This diff is collapsed.
Click to expand it.
src/test/java/mvd/jester/simulator/schmidmottok/TestTaskContext.java
View file @
6b1ef83a
...
...
@@ -58,8 +58,7 @@ public class TestTaskContext {
@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);
long
numberOfProcessors
=
ThreadLocalRandom
.
current
().
nextLong
(
2
,
10
);
Set
<
Segment
>
segments
=
new
LinkedHashSet
<>();
segments
.
add
(
new
Segment
(
5
,
1
));
...
...
@@ -67,7 +66,7 @@ public class TestTaskContext {
segments
.
add
(
new
Segment
(
15
,
1
));
Task
t
=
new
Task
(
100
,
segments
);
TaskContext
tc
=
new
TaskContext
(
t
,
1
,
0
);
TaskContext
tc
=
new
TaskContext
(
t
,
numberOfProcessors
,
0
);
Optional
<
JobContextInterface
>
job
=
tc
.
getNextJob
();
assertTrue
(
job
.
isPresent
());
...
...
@@ -76,19 +75,25 @@ public class TestTaskContext {
tc
.
acceptNotification
(
0
);
for
(
int
i
=
0
;
i
<
9
;
++
i
)
{
for
(
int
i
=
0
;
i
<
numberOfProcessors
-
1
;
++
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
));
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
());
}
}
...
...
This diff is collapsed.
Click to expand it.
src/test/java/mvd/jester/simulator/schmidmottok/TestTaskletContext.java
0 → 100644
View file @
6b1ef83a
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
));
}
}
}
This diff is collapsed.
Click to expand it.
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