github.com/m10x/go/src@v0.0.0-20220112094212-ba61592315da/syscall/syscall_test.go (about) 1 // Copyright 2013 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 syscall_test 6 7 import ( 8 "internal/testenv" 9 "os" 10 "runtime" 11 "syscall" 12 "testing" 13 ) 14 15 func testSetGetenv(t *testing.T, key, value string) { 16 err := syscall.Setenv(key, value) 17 if err != nil { 18 t.Fatalf("Setenv failed to set %q: %v", value, err) 19 } 20 newvalue, found := syscall.Getenv(key) 21 if !found { 22 t.Fatalf("Getenv failed to find %v variable (want value %q)", key, value) 23 } 24 if newvalue != value { 25 t.Fatalf("Getenv(%v) = %q; want %q", key, newvalue, value) 26 } 27 } 28 29 func TestEnv(t *testing.T) { 30 testSetGetenv(t, "TESTENV", "AVALUE") 31 // make sure TESTENV gets set to "", not deleted 32 testSetGetenv(t, "TESTENV", "") 33 } 34 35 // Check that permuting child process fds doesn't interfere with 36 // reporting of fork/exec status. See Issue 14979. 37 func TestExecErrPermutedFds(t *testing.T) { 38 testenv.MustHaveExec(t) 39 40 attr := &os.ProcAttr{Files: []*os.File{os.Stdin, os.Stderr, os.Stdout}} 41 _, err := os.StartProcess("/", []string{"/"}, attr) 42 if err == nil { 43 t.Fatalf("StartProcess of invalid program returned err = nil") 44 } 45 } 46 47 func TestGettimeofday(t *testing.T) { 48 if runtime.GOOS == "js" { 49 t.Skip("not implemented on " + runtime.GOOS) 50 } 51 tv := &syscall.Timeval{} 52 if err := syscall.Gettimeofday(tv); err != nil { 53 t.Fatal(err) 54 } 55 if tv.Sec == 0 && tv.Usec == 0 { 56 t.Fatal("Sec and Usec both zero") 57 } 58 }