-
Notifications
You must be signed in to change notification settings - Fork 107
Expand file tree
/
Copy pathsyscall_test.go
More file actions
56 lines (46 loc) · 1.29 KB
/
syscall_test.go
File metadata and controls
56 lines (46 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2023 The Ebitengine Authors
package purego_test
import (
"os"
"runtime"
"testing"
"unsafe"
"github.com/ebitengine/purego"
"github.com/ebitengine/purego/internal/load"
)
func TestOS(t *testing.T) {
// set and unset an environment variable since this calls into fakecgo.
err := os.Setenv("TESTING", "SOMETHING")
if err != nil {
t.Errorf("failed to Setenv: %s", err)
}
err = os.Unsetenv("TESTING")
if err != nil {
t.Errorf("failed to Unsetenv: %s", err)
}
}
func TestErrno(t *testing.T) {
if runtime.GOOS != "darwin" {
t.Skip("platform does not support returning errno from syscall")
}
libc, err := load.OpenLibrary("/usr/lib/libSystem.B.dylib")
if err != nil {
t.Fatal(err)
}
openSym, err := load.OpenSymbol(libc, "open")
if err != nil {
t.Fatal(err)
}
r1, _, errno := purego.SyscallN(openSym, uintptr(unsafe.Pointer(&[]byte("_file_that_does_not_exist_\x00")[0])), uintptr(os.O_RDWR))
if int32(r1) != -1 {
t.Errorf("open returned %d, wanted -1", r1)
}
var strerror func(int32) string
purego.RegisterLibFunc(&strerror, libc, "strerror")
const expected = "No such file or directory"
got := strerror(int32(errno))
if got != expected {
t.Errorf("strerror returned %q, wanted \"%s\"", got, expected)
}
}