Use __builtin_memmove for trivially copyable types
[official-gcc.git] / libgo / go / syscall / syscall_test.go
blobc3fffda2df59ab1f59d6b2b0ccbc772f8d6f568c
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.
5 package syscall_test
7 import (
8 "fmt"
9 "internal/testenv"
10 "os"
11 "runtime"
12 "syscall"
13 "testing"
16 func testSetGetenv(t *testing.T, key, value string) {
17 err := syscall.Setenv(key, value)
18 if err != nil {
19 t.Fatalf("Setenv failed to set %q: %v", value, err)
21 newvalue, found := syscall.Getenv(key)
22 if !found {
23 t.Fatalf("Getenv failed to find %v variable (want value %q)", key, value)
25 if newvalue != value {
26 t.Fatalf("Getenv(%v) = %q; want %q", key, newvalue, value)
30 func TestEnv(t *testing.T) {
31 testSetGetenv(t, "TESTENV", "AVALUE")
32 // make sure TESTENV gets set to "", not deleted
33 testSetGetenv(t, "TESTENV", "")
36 func TestItoa(t *testing.T) {
37 // Make most negative integer: 0x8000...
38 i := 1
39 for i<<1 != 0 {
40 i <<= 1
42 if i >= 0 {
43 t.Fatal("bad math")
45 s := syscall.Itoa(i)
46 f := fmt.Sprint(i)
47 if s != f {
48 t.Fatalf("itoa(%d) = %s, want %s", i, s, f)
52 // Check that permuting child process fds doesn't interfere with
53 // reporting of fork/exec status. See Issue 14979.
54 func TestExecErrPermutedFds(t *testing.T) {
55 testenv.MustHaveExec(t)
57 attr := &os.ProcAttr{Files: []*os.File{os.Stdin, os.Stderr, os.Stdout}}
58 _, err := os.StartProcess("/", []string{"/"}, attr)
59 if err == nil {
60 t.Fatalf("StartProcess of invalid program returned err = nil")
64 func TestGettimeofday(t *testing.T) {
65 if runtime.GOOS == "nacl" {
66 t.Skip("not implemented on nacl")
68 tv := &syscall.Timeval{}
69 if err := syscall.Gettimeofday(tv); err != nil {
70 t.Fatal(err)
72 if tv.Sec == 0 && tv.Usec == 0 {
73 t.Fatal("Sec and Usec both zero")