-
Notifications
You must be signed in to change notification settings - Fork 3
/
Main.scala
87 lines (66 loc) · 2.02 KB
/
Main.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package daut41_mexec
import daut.{DautOptions, Monitor}
// System Under Test
trait SUTEvent
case class Stop(taskId: Int) extends SUTEvent
case class Swap(taskId: Int) extends SUTEvent
class SUT {
def submit(event: SUTEvent): Unit = {
println(s"submitting $event to SUT")
}
}
// Abstract events:
sealed trait AbstractEvent
case class Command(taskId: Int, cmdNum: Int) extends AbstractEvent
// Concrete events:
sealed trait ConcreteEvent
case class DispatchRequest(taskId: Int, cmdNum: Int) extends ConcreteEvent
case class DispatchReply(taskId: Int, cmdNum: Int) extends ConcreteEvent
case class CommandComplete(taskId: Int, cmdNum: Int) extends ConcreteEvent
// Monitors:
class AbstractMonitor extends Monitor[AbstractEvent] {
val sut = SUT()
always {
case Command(taskId1, cmdNum1) => always {
case Command(taskId2, cmdNum2) =>
println(s"two commands: $taskId1 $cmdNum1 -> $taskId2 $cmdNum2")
if (taskId1 == taskId2 && cmdNum1 == cmdNum2) {
sut.submit(Stop(taskId1))
}
ensure (taskId1 != taskId2 || cmdNum1 != cmdNum2)
}
}
}
class ConcreteMonitor extends Monitor[ConcreteEvent] {
val abstractMonitor = monitorAbstraction(AbstractMonitor())
always {
case DispatchRequest(taskId, cmdNum) =>
hot {
case DispatchRequest(`taskId`, `cmdNum`) => error
case DispatchReply(`taskId`, `cmdNum`) =>
hot {
case CommandComplete(`taskId`, `cmdNum`) =>
abstractMonitor(Command(taskId, cmdNum))
println(s"$taskId $cmdNum")
}
}
}
}
object Main {
def main(args: Array[String]): Unit = {
DautOptions.SHOW_TRANSITIONS = true
val trace: List[ConcreteEvent] = List(
DispatchRequest(1, 1),
DispatchReply(1, 1),
CommandComplete(1, 1),
DispatchRequest(1, 2),
DispatchReply(1, 2),
CommandComplete(1, 2),
DispatchRequest(1, 2),
DispatchReply(1, 2),
CommandComplete(1, 2)
)
val monitor = new ConcreteMonitor
monitor(trace)
}
}