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
Oct 10, 2019
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 {
...
@@ -79,18 +79,18 @@ public class TestEnvironment {
}
}
public
void
runTests
()
{
public
void
runTests
()
{
Set
<
AbstractTest
>
abstractTestInstances
=
new
HashSet
<>();
Set
<
TestPair
>
abstractTestInstances
=
new
HashSet
<>();
Set
<
AbstractSimulato
r
>
abstractSimulatorInstances
=
new
HashSet
<>();
Set
<
SimulatorPai
r
>
abstractSimulatorInstances
=
new
HashSet
<>();
Map
<
Long
,
Long
>
totalNumberOfTasks
=
new
HashMap
<>();
Map
<
Long
,
Long
>
totalNumberOfTasks
=
new
HashMap
<>();
Map
<
Long
,
Table
<
PriorityManager
,
AbstractTest
,
Long
>>
testResults
=
new
HashMap
<>();
Table
<
Long
,
TestPair
,
Long
>
testResults
=
HashBasedTable
.
create
();
Map
<
Long
,
Table
<
PriorityManager
,
AbstractSimulator
,
Long
>>
simulatorResults
=
Table
<
Long
,
SimulatorPair
,
Long
>
simulatorResults
=
HashBasedTable
.
create
();
new
HashMap
<>();
for
(
PriorityManager
pm
:
schedulingAlgorithms
)
{
for
(
Constructor
<?
extends
AbstractTest
>
c
:
abstractTests
)
{
for
(
Constructor
<?
extends
AbstractTest
>
c
:
abstractTests
)
{
try
{
try
{
abstractTestInstances
.
add
(
c
.
newInstance
(
this
.
systemSetup
));
abstractTestInstances
.
add
(
new
TestPair
(
pm
,
c
.
newInstance
(
this
.
systemSetup
)
));
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"Could not instantiate object of AbstractTest!"
);
System
.
out
.
println
(
"Could not instantiate object of AbstractTest!"
);
}
}
...
@@ -98,11 +98,13 @@ public class TestEnvironment {
...
@@ -98,11 +98,13 @@ public class TestEnvironment {
for
(
Constructor
<?
extends
AbstractSimulator
>
c
:
abstractSimulators
)
{
for
(
Constructor
<?
extends
AbstractSimulator
>
c
:
abstractSimulators
)
{
try
{
try
{
abstractSimulatorInstances
.
add
(
c
.
newInstance
(
this
.
systemSetup
));
abstractSimulatorInstances
.
add
(
new
SimulatorPair
(
pm
,
c
.
newInstance
(
this
.
systemSetup
)));
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"Could not instantiate object of AbstractSimulator!"
);
System
.
out
.
println
(
"Could not instantiate object of AbstractSimulator!"
);
}
}
}
}
}
long
checkedTasksets
=
0
;
long
checkedTasksets
=
0
;
...
@@ -123,36 +125,34 @@ public class TestEnvironment {
...
@@ -123,36 +125,34 @@ public class TestEnvironment {
totalNumberOfTasks
.
compute
(
roundedUtilization
,
(
k
,
v
)
->
v
==
null
?
1
:
v
+
1
);
totalNumberOfTasks
.
compute
(
roundedUtilization
,
(
k
,
v
)
->
v
==
null
?
1
:
v
+
1
);
for
(
PriorityManager
priorityManager
:
schedulingAlgorithms
)
{
for
(
TestPair
testInstance
:
abstractTestInstances
)
{
for
(
AbstractTest
test
:
abstractTestInstances
)
{
PriorityManager
priorityManager
=
testInstance
.
getPriorityManager
();
Table
<
PriorityManager
,
AbstractTest
,
Long
>
table
=
testResults
AbstractTest
abstractTest
=
testInstance
.
getAbstractTest
();
.
computeIfAbsent
(
roundedUtilization
,
k
->
HashBasedTable
.
create
());
if
(!
testResults
.
contains
(
roundedUtilization
,
testInstance
))
{
if
(
priorityManager
.
hasTest
(
test
)
testResults
.
put
(
roundedUtilization
,
testInstance
,
(
long
)
0
);
&&
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
);
}
}
if
(
priorityManager
.
hasTest
(
abstractTest
)
&&
abstractTest
.
runSchedulabilityCheck
(
priorityManager
))
{
Long
val
=
testResults
.
get
(
roundedUtilization
,
testInstance
);
testResults
.
put
(
roundedUtilization
,
testInstance
,
val
+
1
);
}
}
}
}
for
(
AbstractSimulator
simulator
:
abstractSimulatorInstances
)
{
for
(
SimulatorPair
simulatorInstance
:
abstractSimulatorInstances
)
{
Table
<
PriorityManager
,
AbstractSimulator
,
Long
>
table
=
simulatorResults
PriorityManager
priorityManager
=
simulatorInstance
.
getPriorityManager
();
.
computeIfAbsent
(
roundedUtilization
,
k
->
HashBasedTable
.
create
());
AbstractSimulator
abstractSimulator
=
simulatorInstance
.
getAbstractSimulator
();
if
(
priorityManager
.
hasSimulator
(
simulator
)
if
(!
simulatorResults
.
contains
(
roundedUtilization
,
simulatorInstance
))
{
&&
simulator
.
runSimulation
(
priorityManager
))
{
simulatorResults
.
put
(
roundedUtilization
,
simulatorInstance
,
(
long
)
0
);
Long
val
=
table
.
get
(
priorityManager
,
simulator
);
if
(
val
==
null
)
{
table
.
put
(
priorityManager
,
simulator
,
(
long
)
1
);
}
else
{
table
.
put
(
priorityManager
,
simulator
,
val
+
1
);
}
}
if
(
priorityManager
.
hasSimulator
(
abstractSimulator
)
&&
abstractSimulator
.
runSimulation
(
priorityManager
))
{
Long
val
=
simulatorResults
.
get
(
roundedUtilization
,
simulatorInstance
);
simulatorResults
.
put
(
roundedUtilization
,
simulatorInstance
,
val
+
1
);
}
}
}
}
}
builder
.
addTask
(
systemSetup
);
builder
.
addTask
(
systemSetup
);
utilization
=
this
.
systemSetup
.
getUtilization
();
utilization
=
this
.
systemSetup
.
getUtilization
();
...
@@ -163,7 +163,7 @@ public class TestEnvironment {
...
@@ -163,7 +163,7 @@ public class TestEnvironment {
logSimulationResults
(
simulatorResults
,
totalNumberOfTasks
);
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
)
{
Map
<
Long
,
Long
>
totalNumberOfTasks
)
{
LocalTime
date
=
LocalTime
.
now
();
LocalTime
date
=
LocalTime
.
now
();
Logger
log
=
new
Logger
(
"./results/results_"
+
systemSetup
.
getNumberOfProcessors
()
+
"_"
Logger
log
=
new
Logger
(
"./results/results_"
+
systemSetup
.
getNumberOfProcessors
()
+
"_"
...
@@ -171,28 +171,17 @@ public class TestEnvironment {
...
@@ -171,28 +171,17 @@ public class TestEnvironment {
String
firstLine
=
new
String
(
"Utilization"
);
String
firstLine
=
new
String
(
"Utilization"
);
if
(!
results
.
isEmpty
())
{
if
(!
results
.
isEmpty
())
{
Long
first
=
results
.
keySet
().
iterator
().
next
();
for
(
TestPair
testPair
:
results
.
columnKeySet
())
{
firstLine
=
firstLine
+
"\t"
+
testPair
.
getName
();
for
(
PriorityManager
p
:
results
.
get
(
first
).
rowKeySet
())
{
for
(
AbstractTest
t
:
results
.
get
(
first
).
columnKeySet
())
{
firstLine
=
firstLine
+
"\t"
+
t
.
getName
()
+
"_"
+
p
.
getName
();
}
}
}
log
.
log
(
firstLine
);
log
.
log
(
firstLine
);
for
(
Long
util
:
results
.
keySet
())
{
for
(
Long
util
:
totalNumberOfTasks
.
keySet
())
{
String
line
=
String
.
valueOf
((
double
)
util
/
10
);
String
line
=
Table
<
PriorityManager
,
AbstractTest
,
Long
>
tests
=
results
.
get
(
util
);
String
.
valueOf
((
double
)
util
/
10
)
+
"\t"
+
totalNumberOfTasks
.
get
(
util
);
for
(
TestPair
simulatorPair
:
results
.
columnKeySet
())
{
for
(
PriorityManager
p
:
tests
.
rowKeySet
())
{
line
+=
"\t"
+
results
.
get
(
util
,
simulatorPair
);
for
(
AbstractTest
t
:
tests
.
columnKeySet
())
{
if
(
tests
.
contains
(
p
,
t
))
{
line
+=
"\t"
+
tests
.
get
(
p
,
t
);
}
else
{
line
+=
"\t"
+
"0"
;
}
}
}
}
log
.
log
(
line
);
log
.
log
(
line
);
}
}
...
@@ -201,8 +190,7 @@ public class TestEnvironment {
...
@@ -201,8 +190,7 @@ public class TestEnvironment {
log
.
finalize
();
log
.
finalize
();
}
}
private
void
logSimulationResults
(
private
void
logSimulationResults
(
Table
<
Long
,
SimulatorPair
,
Long
>
results
,
Map
<
Long
,
Table
<
PriorityManager
,
AbstractSimulator
,
Long
>>
results
,
Map
<
Long
,
Long
>
totalNumberOfTasks
)
{
Map
<
Long
,
Long
>
totalNumberOfTasks
)
{
LocalTime
date
=
LocalTime
.
now
();
LocalTime
date
=
LocalTime
.
now
();
Logger
log
=
new
Logger
(
"./results/results_sim_"
+
systemSetup
.
getNumberOfProcessors
()
+
"_"
Logger
log
=
new
Logger
(
"./results/results_sim_"
+
systemSetup
.
getNumberOfProcessors
()
+
"_"
...
@@ -210,34 +198,82 @@ public class TestEnvironment {
...
@@ -210,34 +198,82 @@ public class TestEnvironment {
String
firstLine
=
new
String
(
"Utilization\tTotal"
);
String
firstLine
=
new
String
(
"Utilization\tTotal"
);
if
(!
results
.
isEmpty
())
{
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
())
{
log
.
log
(
firstLine
);
for
(
AbstractSimulator
s
:
results
.
get
(
first
).
columnKeySet
())
{
firstLine
=
firstLine
+
"\t"
+
s
.
getName
()
+
"_"
+
p
.
getName
();
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
())
{
public
SimulatorPair
(
PriorityManager
priorityManager
,
AbstractSimulator
abstractSimulator
)
{
for
(
AbstractSimulator
s
:
tests
.
columnKeySet
())
{
this
.
abstractSimulator
=
abstractSimulator
;
if
(
tests
.
contains
(
p
,
s
))
{
this
.
priorityManager
=
priorityManager
;
line
+=
"\t"
+
tests
.
get
(
p
,
s
);
}
else
{
line
+=
"\t"
+
"0"
;
}
}
/**
* @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
();
}
}
}
}
}
src/main/java/mvd/jester/simulator/internals/maiabertogna/JobContext.java
View file @
6b1ef83a
...
@@ -37,6 +37,8 @@ public class JobContext implements JobContextInterface {
...
@@ -37,6 +37,8 @@ public class JobContext implements JobContextInterface {
currentProcessor
.
get
().
setJob
(
null
);
currentProcessor
.
get
().
setJob
(
null
);
currentProcessor
=
Optional
.
empty
();
currentProcessor
=
Optional
.
empty
();
return
taskContext
.
acceptNotification
(
time
);
return
taskContext
.
acceptNotification
(
time
);
}
else
if
(
executionTime
<
0
)
{
throw
new
RuntimeException
(
"Job was executed for longer than its WCET!"
);
}
}
return
Optional
.
empty
();
return
Optional
.
empty
();
...
...
src/main/java/mvd/jester/simulator/internals/schmidmottok/TaskletContext.java
View file @
6b1ef83a
...
@@ -44,6 +44,8 @@ public class TaskletContext {
...
@@ -44,6 +44,8 @@ public class TaskletContext {
}
}
currentJob
=
Optional
.
empty
();
currentJob
=
Optional
.
empty
();
return
true
;
return
true
;
}
else
if
(
executionTime
<
0
)
{
throw
new
RuntimeException
(
"Tasklet was executed for longer than its WCET!"
);
}
}
return
false
;
return
false
;
}
}
...
...
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
();
}
}
}
src/test/java/mvd/jester/simulator/maiabertogna/TestJobContext.java
View file @
6b1ef83a
package
mvd
.
jester
.
simulator
.
maiabertogna
;
package
mvd
.
jester
.
simulator
.
maiabertogna
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertFalse
;
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
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
import
static
org
.
mockito
.
ArgumentMatchers
.
anyLong
;
import
static
org
.
mockito
.
ArgumentMatchers
.
anyLong
;
import
static
org
.
mockito
.
Mockito
.
mock
;
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
.
Mockito
.
when
;
import
java.util.Optional
;
import
java.util.Optional
;
import
java.util.concurrent.ThreadLocalRandom
;
import
java.util.concurrent.ThreadLocalRandom
;
...
@@ -25,19 +28,18 @@ public class TestJobContext {
...
@@ -25,19 +28,18 @@ public class TestJobContext {
@DisplayName
(
"Check if execution of Job is updated correctly."
)
@DisplayName
(
"Check if execution of Job is updated correctly."
)
public
void
testUpdateExecution
()
{
public
void
testUpdateExecution
()
{
for
(
int
run
=
0
;
run
<
100
;
++
run
)
{
for
(
int
run
=
0
;
run
<
100
;
++
run
)
{
long
numberOfJobs
=
ThreadLocalRandom
.
current
().
nextLong
(
1
,
10
);
long
jobWcet
=
ThreadLocalRandom
.
current
().
nextLong
(
20
,
50
);
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
);
SegmentContext
sc
=
mock
(
SegmentContext
.
class
);
when
(
sc
.
getSegment
()).
thenReturn
(
s
);
when
(
sc
.
getSegment
()).
thenReturn
(
s
);
TaskContext
tc
=
mock
(
TaskContext
.
class
);
TaskContext
tc
=
mock
(
TaskContext
.
class
);
when
(
tc
.
acceptNotification
(
anyLong
())).
thenReturn
(
Optional
.
of
(
tc
));
when
(
tc
.
acceptNotification
(
anyLong
())).
thenReturn
(
Optional
.
of
(
tc
));
JobContext
job
=
new
JobContext
(
tc
,
sc
);
JobContext
job
=
new
JobContext
(
tc
,
sc
);
ProcessorContext
p
=
new
ProcessorContext
(
0
);
ProcessorContext
p
=
mock
(
ProcessorContext
.
class
);
job
.
setCurrentProcessor
(
p
);
job
.
setCurrentProcessor
(
p
);
p
.
setJob
(
job
);
assertTrue
(
job
.
checkExecutionTime
());
assertTrue
(
job
.
checkExecutionTime
());
...
@@ -51,6 +53,9 @@ public class TestJobContext {
...
@@ -51,6 +53,9 @@ public class TestJobContext {
assertFalse
(
p
.
getJob
().
isPresent
());
assertFalse
(
p
.
getJob
().
isPresent
());
assertFalse
(
job
.
getCurrentProcessor
().
isPresent
());
assertFalse
(
job
.
getCurrentProcessor
().
isPresent
());
assertFalse
(
job
.
checkExecutionTime
());
assertFalse
(
job
.
checkExecutionTime
());
verify
(
p
,
times
(
1
)).
setJob
(
null
);
assertThrows
(
RuntimeException
.
class
,
()
->
job
.
updateExecution
(
1
));
}
}
}
}
}
}
src/test/java/mvd/jester/simulator/schmidmottok/TestJobContext.java
View file @
6b1ef83a
package
mvd
.
jester
.
simulator
.
schmidmottok
;
package
mvd
.
jester
.
simulator
.
schmidmottok
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertFalse
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
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.DisplayName
;
import
org.junit.jupiter.api.Test
;
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
* TestJobContext
...
@@ -12,7 +28,72 @@ public class TestJobContext {
...
@@ -12,7 +28,72 @@ public class TestJobContext {
@Test
@Test
@DisplayName
(
"Check if the job is prepared correctly."
)
@DisplayName
(
"Check if the job is prepared correctly."
)
public
void
testPrepareJob
()
{
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
();
}
}
}
src/test/java/mvd/jester/simulator/schmidmottok/TestSegmentContext.java
View file @
6b1ef83a
...
@@ -80,10 +80,9 @@ public class TestSegmentContext {
...
@@ -80,10 +80,9 @@ public class TestSegmentContext {
SegmentContext
sc
=
new
SegmentContext
(
tc
,
s
,
4
);
SegmentContext
sc
=
new
SegmentContext
(
tc
,
s
,
4
);
for
(
int
i
=
0
;
i
<
jobWcet
;
++
i
)
{
for
(
int
i
=
0
;
i
<
jobWcet
;
++
i
)
{
Optional
<
TaskletContext
>
tci
=
sc
.
getNextTasklet
();
Optional
<
TaskletContext
>
tci
=
sc
.
getNextTasklet
();
assertTrue
(
tci
.
isPresent
());
assertTrue
(
tci
.
isPresent
());
tci
.
get
().
setCurrentJob
(
new
JobContext
(
tc
,
sc
));
tci
.
get
().
setCurrentJob
(
mock
(
JobContext
.
class
));
}
}
assertFalse
(
sc
.
getNextTasklet
().
isPresent
());
assertFalse
(
sc
.
getNextTasklet
().
isPresent
());
...
@@ -93,7 +92,7 @@ public class TestSegmentContext {
...
@@ -93,7 +92,7 @@ public class TestSegmentContext {
for
(
int
i
=
0
;
i
<
jobWcet
;
++
i
)
{
for
(
int
i
=
0
;
i
<
jobWcet
;
++
i
)
{
Optional
<
TaskletContext
>
tasklet
=
sc
.
getNextTasklet
();
Optional
<
TaskletContext
>
tasklet
=
sc
.
getNextTasklet
();
assertTrue
(
tasklet
.
isPresent
());
assertTrue
(
tasklet
.
isPresent
());
tasklet
.
get
().
setCurrentJob
(
new
JobContext
(
tc
,
sc
));
tasklet
.
get
().
setCurrentJob
(
mock
(
JobContext
.
class
));
for
(
int
j
=
0
;
j
<
numberOfJobs
;
++
j
)
{
for
(
int
j
=
0
;
j
<
numberOfJobs
;
++
j
)
{
tasklet
.
get
().
updateExecution
(
j
);
tasklet
.
get
().
updateExecution
(
j
);
}
}
...
...
src/test/java/mvd/jester/simulator/schmidmottok/TestTaskContext.java
View file @
6b1ef83a
...
@@ -58,8 +58,7 @@ public class TestTaskContext {
...
@@ -58,8 +58,7 @@ public class TestTaskContext {
@DisplayName
(
"Check if the next job is returned correctly."
)
@DisplayName
(
"Check if the next job is returned correctly."
)
public
void
testGetNextJob
()
{
public
void
testGetNextJob
()
{
for
(
int
run
=
0
;
run
<
100
;
++
run
)
{
for
(
int
run
=
0
;
run
<
100
;
++
run
)
{
// long numberOfJobs = ThreadLocalRandom.current().nextLong(1, 10);
long
numberOfProcessors
=
ThreadLocalRandom
.
current
().
nextLong
(
2
,
10
);
// long numberOfSegments = ThreadLocalRandom.current().nextLong(3, 10);
Set
<
Segment
>
segments
=
new
LinkedHashSet
<>();
Set
<
Segment
>
segments
=
new
LinkedHashSet
<>();
segments
.
add
(
new
Segment
(
5
,
1
));
segments
.
add
(
new
Segment
(
5
,
1
));
...
@@ -67,7 +66,7 @@ public class TestTaskContext {
...
@@ -67,7 +66,7 @@ public class TestTaskContext {
segments
.
add
(
new
Segment
(
15
,
1
));
segments
.
add
(
new
Segment
(
15
,
1
));
Task
t
=
new
Task
(
100
,
segments
);
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
();
Optional
<
JobContextInterface
>
job
=
tc
.
getNextJob
();
assertTrue
(
job
.
isPresent
());
assertTrue
(
job
.
isPresent
());
...
@@ -76,19 +75,25 @@ public class TestTaskContext {
...
@@ -76,19 +75,25 @@ public class TestTaskContext {
tc
.
acceptNotification
(
0
);
tc
.
acceptNotification
(
0
);
for
(
int
i
=
0
;
i
<
9
;
++
i
)
{
for
(
int
i
=
0
;
i
<
numberOfProcessors
-
1
;
++
i
)
{
job
=
tc
.
getNextJob
();
job
=
tc
.
getNextJob
();
assertTrue
(
job
.
isPresent
());
assertTrue
(
job
.
isPresent
());
job
.
get
().
setCurrentProcessor
(
new
ProcessorContext
(
i
));
job
.
get
().
setCurrentProcessor
(
new
ProcessorContext
(
i
));
tc
.
acceptNotification
(
0
);
}
}
job
=
tc
.
getNextJob
();
job
=
tc
.
getNextJob
();
assertTrue
(
job
.
isPresent
());
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
());
assertFalse
(
tc
.
getNextJob
().
isPresent
());
for
(
int
i
=
0
;
i
<
10
;
++
i
)
{
tc
.
acceptNotification
(
0
);
tc
.
acceptNotification
(
0
);
}
assertTrue
(
tc
.
getNextJob
().
isPresent
());
assertTrue
(
tc
.
getNextJob
().
isPresent
());
}
}
}
}
...
...
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
));
}
}
}
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