Commit ae740a45 authored by David du Colombier's avatar David du Colombier

os: add TestProgWideChdir

This test checks the working directory is
always consistent after Chdir in a Go program.

Fixes #10035.

Change-Id: I6abf0e4fcd40680ee572c6b40fc52ab17ef38d54
Reviewed-on: https://go-review.googlesource.com/6382Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: David du Colombier <0intro@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 7d3f81a9
......@@ -1040,6 +1040,57 @@ func TestChdirAndGetwd(t *testing.T) {
fd.Close()
}
// Test that Chdir+Getwd is program-wide.
func TestProgWideChdir(t *testing.T) {
const N = 10
c := make(chan bool)
cpwd := make(chan string)
for i := 0; i < N; i++ {
go func(i int) {
// Lock half the goroutines in their own operating system
// thread to exercise more scheduler possibilities.
if i%2 == 1 {
// On Plan 9, after calling LockOSThread, the goroutines
// run on different processes which don't share the working
// directory. This used to be an issue because Go expects
// the working directory to be program-wide.
// See issue 9428.
runtime.LockOSThread()
}
<-c
pwd, err := Getwd()
if err != nil {
t.Fatal("Getwd: %v", err)
}
cpwd <- pwd
}(i)
}
oldwd, err := Getwd()
if err != nil {
t.Fatal("Getwd: %v", err)
}
d, err := ioutil.TempDir("", "test")
if err != nil {
t.Fatal("TempDir: %v", err)
}
defer func() {
if err := Chdir(oldwd); err != nil {
t.Fatal("Chdir: %v", err)
}
RemoveAll(d)
}()
if err := Chdir(d); err != nil {
t.Fatal("Chdir: %v", err)
}
close(c)
for i := 0; i < N; i++ {
pwd := <-cpwd
if pwd != d {
t.Errorf("Getwd returned %q want %q", pwd, d)
}
}
}
func TestSeek(t *testing.T) {
f := newFile("TestSeek", t)
defer Remove(f.Name())
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment