| 1 |
// +build cgo |
| 2 |
|
| 3 |
package psx |
| 4 |
|
| 5 |
import ( |
| 6 |
"runtime" |
| 7 |
"syscall" |
| 8 |
"testing" |
| 9 |
) |
| 10 |
|
| 11 |
// The man page for errno indicates that it is never set to zero, so |
| 12 |
// validate that it retains its value over a successful Syscall[36]() |
| 13 |
// and is overwritten on a failing syscall. |
| 14 |
func TestErrno(t *testing.T) { |
| 15 |
// This testing is much easier if we don't have to guess which |
| 16 |
// thread is running this Go code. |
| 17 |
runtime.LockOSThread() |
| 18 |
defer runtime.UnlockOSThread() |
| 19 |
|
| 20 |
// Start from a known bad state and clean up afterwards. |
| 21 |
setErrno(int(syscall.EPERM)) |
| 22 |
defer setErrno(0) |
| 23 |
|
| 24 |
v3, _, errno := Syscall3(syscall.SYS_GETUID, 0, 0, 0) |
| 25 |
if errno != 0 { |
| 26 |
t.Fatalf("psx getuid failed: %v", errno) |
| 27 |
} |
| 28 |
v6, _, errno := Syscall6(syscall.SYS_GETUID, 0, 0, 0, 0, 0, 0) |
| 29 |
if errno != 0 { |
| 30 |
t.Fatalf("psx getuid failed: %v", errno) |
| 31 |
} |
| 32 |
|
| 33 |
if v3 != v6 { |
| 34 |
t.Errorf("psx getuid failed to match v3=%d, v6=%d", v3, v6) |
| 35 |
} |
| 36 |
|
| 37 |
if v := setErrno(-1); v != int(syscall.EPERM) { |
| 38 |
t.Errorf("psx changes prevailing errno got=%v(%d) want=%v", syscall.Errno(v), v, syscall.EPERM) |
| 39 |
} |
| 40 |
} |