1
0
mirror of https://github.com/golang/go synced 2024-11-23 03:30:02 -07:00

syscall: move TestForegroundSignal create call out of goroutine

That way the skip takes effect.

Also ignore the result of calling TIOCSPGRP when cleaing up TestForeground.
It has started to fail for some reason, and the result doesn't matter.

Also call TIOCSPGRP to clean up in TestForegroundSignal.

For #37217

Change-Id: I2e4282d7d91ad9a198eeb12cef01c2214c2a98c2
Reviewed-on: https://go-review.googlesource.com/c/go/+/314271
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
This commit is contained in:
Ian Lance Taylor 2021-04-27 11:28:40 -07:00
parent 291eb0178f
commit 0c3557e6ad

View File

@ -214,10 +214,9 @@ func TestForeground(t *testing.T) {
cmd.Stop()
errno = syscall.Ioctl(tty.Fd(), syscall.TIOCSPGRP, uintptr(unsafe.Pointer(&fpgrp)))
if errno != 0 {
t.Fatalf("TIOCSPGRP failed with error code: %s", errno)
}
// This call fails on darwin/arm64. The failure doesn't matter, though.
// This is just best effort.
syscall.Ioctl(tty.Fd(), syscall.TIOCSPGRP, uintptr(unsafe.Pointer(&fpgrp)))
}
func TestForegroundSignal(t *testing.T) {
@ -227,14 +226,34 @@ func TestForegroundSignal(t *testing.T) {
}
defer tty.Close()
// This should really be pid_t, however _C_int (aka int32) is generally
// equivalent.
fpgrp := int32(0)
errno := syscall.Ioctl(tty.Fd(), syscall.TIOCGPGRP, uintptr(unsafe.Pointer(&fpgrp)))
if errno != 0 {
t.Fatalf("TIOCGPGRP failed with error code: %s", errno)
}
if fpgrp == 0 {
t.Fatalf("Foreground process group is zero")
}
defer func() {
signal.Ignore(syscall.SIGTTIN, syscall.SIGTTOU)
syscall.Ioctl(tty.Fd(), syscall.TIOCSPGRP, uintptr(unsafe.Pointer(&fpgrp)))
signal.Reset()
}()
ch1 := make(chan os.Signal, 1)
ch2 := make(chan bool)
signal.Notify(ch1, syscall.SIGTTIN, syscall.SIGTTOU)
defer signal.Stop(ch1)
cmd := create(t)
go func() {
cmd := create(t)
cmd.proc.SysProcAttr = &syscall.SysProcAttr{
Ctty: int(tty.Fd()),
Foreground: true,