syscall_test.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. // +build aix darwin dragonfly freebsd linux netbsd openbsd solaris
  5. package unix_test
  6. import (
  7. "fmt"
  8. "testing"
  9. "golang.org/x/sys/unix"
  10. )
  11. func testSetGetenv(t *testing.T, key, value string) {
  12. err := unix.Setenv(key, value)
  13. if err != nil {
  14. t.Fatalf("Setenv failed to set %q: %v", value, err)
  15. }
  16. newvalue, found := unix.Getenv(key)
  17. if !found {
  18. t.Fatalf("Getenv failed to find %v variable (want value %q)", key, value)
  19. }
  20. if newvalue != value {
  21. t.Fatalf("Getenv(%v) = %q; want %q", key, newvalue, value)
  22. }
  23. }
  24. func TestEnv(t *testing.T) {
  25. testSetGetenv(t, "TESTENV", "AVALUE")
  26. // make sure TESTENV gets set to "", not deleted
  27. testSetGetenv(t, "TESTENV", "")
  28. }
  29. func TestItoa(t *testing.T) {
  30. // Make most negative integer: 0x8000...
  31. i := 1
  32. for i<<1 != 0 {
  33. i <<= 1
  34. }
  35. if i >= 0 {
  36. t.Fatal("bad math")
  37. }
  38. s := unix.Itoa(i)
  39. f := fmt.Sprint(i)
  40. if s != f {
  41. t.Fatalf("itoa(%d) = %s, want %s", i, s, f)
  42. }
  43. }
  44. func TestUname(t *testing.T) {
  45. var utsname unix.Utsname
  46. err := unix.Uname(&utsname)
  47. if err != nil {
  48. t.Fatalf("Uname: %v", err)
  49. }
  50. t.Logf("OS: %s/%s %s", utsname.Sysname[:], utsname.Machine[:], utsname.Release[:])
  51. }
  52. // Test that this compiles. (Issue #31735)
  53. func TestStatFieldNames(t *testing.T) {
  54. var st unix.Stat_t
  55. var _ *unix.Timespec
  56. _ = &st.Atim
  57. _ = &st.Mtim
  58. _ = &st.Ctim
  59. _ = int64(st.Mtim.Sec)
  60. _ = int64(st.Mtim.Nsec)
  61. }