| 1 |
// Copyright 2018 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 |
"syscall" |
| 9 |
"testing" |
| 10 |
) |
| 11 |
|
| 12 |
// testalias checks for aliasing of error strings returned by sys1 and sys2, |
| 13 |
// which both call the function named fn in package syscall |
| 14 |
func testalias(t *testing.T, fn string, sys1, sys2 func() error) { |
| 15 |
err := sys1().Error() |
| 16 |
errcopy := string([]byte(err)) |
| 17 |
sys2() |
| 18 |
if err != errcopy { |
| 19 |
t.Errorf("syscall.%s error string changed from %q to %q\n", fn, errcopy, err) |
| 20 |
} |
| 21 |
} |
| 22 |
|
| 23 |
// issue 13770: errors cannot be nested in Plan 9 |
| 24 |
|
| 25 |
func TestPlan9Syserr(t *testing.T) { |
| 26 |
testalias(t, |
| 27 |
"Syscall", |
| 28 |
func() error { |
| 29 |
return syscall.Mkdir("/", 0) |
| 30 |
}, |
| 31 |
func() error { |
| 32 |
return syscall.Mkdir("#", 0) |
| 33 |
}) |
| 34 |
testalias(t, |
| 35 |
"Syscall6", |
| 36 |
func() error { |
| 37 |
return syscall.Mount(0, 0, "", 0, "") |
| 38 |
}, |
| 39 |
func() error { |
| 40 |
return syscall.Mount(-1, 0, "", 0, "") |
| 41 |
}) |
| 42 |
// originally failed only on plan9_arm |
| 43 |
testalias(t, |
| 44 |
"seek", |
| 45 |
func() error { |
| 46 |
_, err := syscall.Seek(0, 0, -1) |
| 47 |
return err |
| 48 |
}, |
| 49 |
func() error { |
| 50 |
_, err := syscall.Seek(-1, 0, 0) |
| 51 |
return err |
| 52 |
}) |
| 53 |
} |