2018-05-07 Edward Smith-Rowland <3dw4rd@verizon.net>
[official-gcc.git] / libgo / go / os / exec / exec_posix_test.go
blob865b6c3ced28915da50af7cfa89e62d3ab91ec6d
1 // Copyright 2017 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // +build darwin dragonfly freebsd linux netbsd openbsd solaris
7 package exec_test
9 import (
10 "os/user"
11 "strconv"
12 "syscall"
13 "testing"
14 "time"
17 func TestCredentialNoSetGroups(t *testing.T) {
18 u, err := user.Current()
19 if err != nil {
20 t.Fatalf("error getting current user: %v", err)
23 uid, err := strconv.Atoi(u.Uid)
24 if err != nil {
25 t.Fatalf("error converting Uid=%s to integer: %v", u.Uid, err)
28 gid, err := strconv.Atoi(u.Gid)
29 if err != nil {
30 t.Fatalf("error converting Gid=%s to integer: %v", u.Gid, err)
33 // If NoSetGroups is true, setgroups isn't called and cmd.Run should succeed
34 cmd := helperCommand(t, "echo", "foo")
35 cmd.SysProcAttr = &syscall.SysProcAttr{
36 Credential: &syscall.Credential{
37 Uid: uint32(uid),
38 Gid: uint32(gid),
39 NoSetGroups: true,
43 if err = cmd.Run(); err != nil {
44 t.Errorf("Failed to run command: %v", err)
48 // For issue #19314: make sure that SIGSTOP does not cause the process
49 // to appear done.
50 func TestWaitid(t *testing.T) {
51 t.Parallel()
53 cmd := helperCommand(t, "sleep")
54 if err := cmd.Start(); err != nil {
55 t.Fatal(err)
58 // The sleeps here are unnecessary in the sense that the test
59 // should still pass, but they are useful to make it more
60 // likely that we are testing the expected state of the child.
61 time.Sleep(100 * time.Millisecond)
63 if err := cmd.Process.Signal(syscall.SIGSTOP); err != nil {
64 cmd.Process.Kill()
65 t.Fatal(err)
68 ch := make(chan error)
69 go func() {
70 ch <- cmd.Wait()
71 }()
73 time.Sleep(100 * time.Millisecond)
75 if err := cmd.Process.Signal(syscall.SIGCONT); err != nil {
76 t.Error(err)
77 syscall.Kill(cmd.Process.Pid, syscall.SIGCONT)
80 cmd.Process.Kill()
82 <-ch