...
Source file
src/os/exec/exec_posix_test.go
Documentation: os/exec
1
2
3
4
5
6
7
8 package exec_test
9
10 import (
11 "os/user"
12 "runtime"
13 "strconv"
14 "syscall"
15 "testing"
16 "time"
17 )
18
19 func TestCredentialNoSetGroups(t *testing.T) {
20 if runtime.GOOS == "android" {
21 t.Skip("unsupported on Android")
22 }
23
24 u, err := user.Current()
25 if err != nil {
26 t.Fatalf("error getting current user: %v", err)
27 }
28
29 uid, err := strconv.Atoi(u.Uid)
30 if err != nil {
31 t.Fatalf("error converting Uid=%s to integer: %v", u.Uid, err)
32 }
33
34 gid, err := strconv.Atoi(u.Gid)
35 if err != nil {
36 t.Fatalf("error converting Gid=%s to integer: %v", u.Gid, err)
37 }
38
39
40 cmd := helperCommand(t, "echo", "foo")
41 cmd.SysProcAttr = &syscall.SysProcAttr{
42 Credential: &syscall.Credential{
43 Uid: uint32(uid),
44 Gid: uint32(gid),
45 NoSetGroups: true,
46 },
47 }
48
49 if err = cmd.Run(); err != nil {
50 t.Errorf("Failed to run command: %v", err)
51 }
52 }
53
54
55
56 func TestWaitid(t *testing.T) {
57 t.Parallel()
58
59 cmd := helperCommand(t, "sleep")
60 if err := cmd.Start(); err != nil {
61 t.Fatal(err)
62 }
63
64
65
66
67 time.Sleep(100 * time.Millisecond)
68
69 if err := cmd.Process.Signal(syscall.SIGSTOP); err != nil {
70 cmd.Process.Kill()
71 t.Fatal(err)
72 }
73
74 ch := make(chan error)
75 go func() {
76 ch <- cmd.Wait()
77 }()
78
79 time.Sleep(100 * time.Millisecond)
80
81 if err := cmd.Process.Signal(syscall.SIGCONT); err != nil {
82 t.Error(err)
83 syscall.Kill(cmd.Process.Pid, syscall.SIGCONT)
84 }
85
86 cmd.Process.Kill()
87
88 <-ch
89 }
90
View as plain text