syscall_test.go 1.4 KB

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