-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterpreter_test.go
50 lines (40 loc) · 1.11 KB
/
interpreter_test.go
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
package main
import "testing"
func benchmarkProgram(path string, b *testing.B) {
for i := 0; i < b.N; i++ {
interpretTree(path)
}
}
func BenchmarkParallel(b *testing.B) {
benchmarkProgram("parallel.csp", b)
}
func BenchmarkPhilosophers(b *testing.B) {
benchmarkProgram("philosophers.csp", b)
}
func BenchmarkClientServer(b *testing.B) {
benchmarkProgram("clientserver.csp", b)
}
func testAllConsumed(path string, shouldDeadlock bool, t *testing.T) {
remaining := interpretTree(path)
if remaining != nil {
errorFmt := "All events should be executed in %s. " +
"The events %v were not."
t.Errorf(errorFmt, path, remaining)
} else if hasDeadlocked != shouldDeadlock {
if shouldDeadlock {
t.Error("Process did not deadlock when it was expected to.")
} else {
t.Error("Process unexpectedly deadlocked.")
}
}
}
func TestParallel(t *testing.T) {
testAllConsumed("parallel.csp", true, t)
}
func TestChannels(t *testing.T) {
testAllConsumed("channels.csp", false, t)
}
func TestPhilosophers(t *testing.T) {
testAllConsumed("philosophers.csp", false, t)
testAllConsumed("philosophers2.csp", true, t)
}