Skip to content

Commit f7f91a0

Browse files
misc/cgo/test: only run setgid test on GNU/Linux
Fixes #3874. R=golang-dev, nj, r, minux.ma CC=golang-dev https://golang.org/cl/6446060
1 parent 601045e commit f7f91a0

File tree

4 files changed

+41
-17
lines changed

4 files changed

+41
-17
lines changed

misc/cgo/test/basic.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ package cgotest
1111
#include <stdlib.h>
1212
#include <sys/stat.h>
1313
#include <errno.h>
14-
#include <unistd.h>
1514
1615
#define SHIFT(x, y) ((x)<<(y))
1716
#define KILO SHIFT(1, 10)
@@ -58,7 +57,6 @@ import "C"
5857
import (
5958
"syscall"
6059
"testing"
61-
"time"
6260
"unsafe"
6361
)
6462

@@ -126,20 +124,6 @@ func testMultipleAssign(t *testing.T) {
126124
C.free(unsafe.Pointer(p))
127125
}
128126

129-
func testSetgid(t *testing.T) {
130-
// Issue 3871.
131-
c := make(chan bool)
132-
go func() {
133-
C.setgid(0)
134-
c <- true
135-
}()
136-
select {
137-
case <-c:
138-
case <-time.After(5 * time.Second):
139-
t.Error("setgid hung")
140-
}
141-
}
142-
143127
var (
144128
cuint = (C.uint)(0)
145129
culong C.ulong

misc/cgo/test/cgo_linux_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright 2012 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.
4+
5+
package cgotest
6+
7+
import "testing"
8+
9+
func TestSetgid(t *testing.T) { testSetgid(t) }

misc/cgo/test/cgo_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,5 @@ func Test1328(t *testing.T) { test1328(t) }
2727
func TestParallelSleep(t *testing.T) { testParallelSleep(t) }
2828
func TestSetEnv(t *testing.T) { testSetEnv(t) }
2929
func TestHelpers(t *testing.T) { testHelpers(t) }
30-
func TestSetgid(t *testing.T) { testSetgid(t) }
3130

3231
func BenchmarkCgoCall(b *testing.B) { benchCgoCall(b) }

misc/cgo/test/setgid_linux.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2012 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.
4+
5+
// Test that setgid does not hang on GNU/Linux.
6+
// See http://code.google.com/p/go/issues/detail?id=3871 for details.
7+
8+
package cgotest
9+
10+
/*
11+
#include <sys/types.h>
12+
#include <unistd.h>
13+
*/
14+
import "C"
15+
16+
import (
17+
"testing"
18+
"time"
19+
)
20+
21+
func testSetgid(t *testing.T) {
22+
c := make(chan bool)
23+
go func() {
24+
C.setgid(0)
25+
c <- true
26+
}()
27+
select {
28+
case <-c:
29+
case <-time.After(5 * time.Second):
30+
t.Error("setgid hung")
31+
}
32+
}

0 commit comments

Comments
 (0)