-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsimulation.go
84 lines (72 loc) · 2.43 KB
/
simulation.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
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 gosim
import (
"time"
"github.com/jellevandenhooff/gosim/gosimruntime"
"github.com/jellevandenhooff/gosim/internal/simulation"
)
// IsSim returns if the program is running inside of a gosim simulation.
//
// To include or exclude code or tests only if running inside of a gosim the
// gosim tool also supports a build tag. Use the `//go:build sim` build
// constraint at the top of a go file to only include it in simulated builds or
// `//go:build !sim` to exclude it from simulated from builds.
func IsSim() bool {
return gosimruntime.IsSim()
}
// Yield yields the processor, allowing other goroutines to run. Similar to
// [runtime.Gosched] but for gosim's scheduler.
//
// TODO: Replace with runtime.Gosched() instead?
func Yield() {
gosimruntime.Yield()
}
/*
type Simulation struct{}
func CurrentSimulation() Simulation {
return Simulation{}
}
// SetConnected configures the network connectivity between addresses a and b.
//
// TODO: How will this fail? Unrouteable or rejected
// TODO: Support asymmetry
func (s Simulation) SetConnected(a, b string, connected bool) error {
return simulation.SyscallSetConnected(a, b, connected)
}
// SetDelay configures the network latency between addresses a and b.
//
// TODO: Support asymmetry
func (s Simulation) SetDelay(a, b string, delay time.Duration) error {
return simulation.SyscallSetDelay(a, b, delay)
}
// SetSimulationTimeout resets the simulation timeout to the given duration.
// After the simulated duration the simululation will fail with a test timeout
// error.
func (s Simulation) SetSimulationTimeout(timeout time.Duration) {
err := simulation.SyscallSetSimulationTimeout(timeout)
if err != nil {
panic(err)
}
}
*/
// SetConnected configures the network connectivity between addresses a and b.
//
// TODO: How will this fail? Unrouteable or rejected
// TODO: Support asymmetry
func SetConnected(a, b string, connected bool) error {
return simulation.SyscallSetConnected(a, b, connected)
}
// SetDelay configures the network latency between addresses a and b.
//
// TODO: Support asymmetry
func SetDelay(a, b string, delay time.Duration) error {
return simulation.SyscallSetDelay(a, b, delay)
}
// SetSimulationTimeout resets the simulation timeout to the given duration.
// After the simulated duration the simululation will fail with a test timeout
// error.
func SetSimulationTimeout(d time.Duration) {
err := simulation.SyscallSetSimulationTimeout(d)
if err != nil {
panic(err)
}
}