-
Notifications
You must be signed in to change notification settings - Fork 125
/
Copy pathsignals_test.go
58 lines (49 loc) · 1.04 KB
/
signals_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
51
52
53
54
55
56
57
58
// +build !windows
package memguard
import (
"fmt"
"net"
"os"
"testing"
)
func TestCatchSignal(t *testing.T) {
testingMode = true
// Start a listener object
listener, err := net.Listen("tcp", "127.0.0.1:")
if err != nil {
SafePanic(err)
}
defer listener.Close()
// Spawn a handler to catch interrupts
CatchSignal(func(s os.Signal) {
fmt.Println("Received signal:", s.String())
listener.Close()
}, os.Interrupt)
// Grab a handle on the running process
process, err := os.FindProcess(os.Getpid())
if err != nil {
t.Error(nil)
}
// Send it an interrupt signal
if err := process.Signal(os.Interrupt); err != nil {
t.Error(err)
}
// Todo: catch this violation
//
// b, err := NewBuffer(32)
// if err != nil {
// t.Error(err)
// }
// bA := (*[64]byte)(unsafe.Pointer(&b.Buffer.Data[0]))
// bA[42] = 0x69
}
func TestCatchInterrupt(t *testing.T) {
CatchInterrupt()
process, err := os.FindProcess(os.Getpid())
if err != nil {
t.Error(nil)
}
if err := process.Signal(os.Interrupt); err != nil {
t.Error(err)
}
}