v0.11.1 15800b5

syscall_test.go RawHistoryFolder

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: 2023 The Ebitengine Authors
3
4package purego_test
5
6import (
7	"os"
8	"path/filepath"
9	"runtime"
10	"testing"
11
12	"github.com/ebitengine/purego"
13	"github.com/ebitengine/purego/internal/load"
14)
15
16func TestOS(t *testing.T) {
17	// set and unset an environment variable since this calls into fakecgo.
18	err := os.Setenv("TESTING", "SOMETHING")
19	if err != nil {
20		t.Errorf("failed to Setenv: %s", err)
21	}
22	err = os.Unsetenv("TESTING")
23	if err != nil {
24		t.Errorf("failed to Unsetenv: %s", err)
25	}
26}
27
28// errnoIsCaptured reports whether SyscallN returns the libc errno as its third
29// value on this platform.
30func errnoIsCaptured() bool {
31	switch runtime.GOOS {
32	case "darwin":
33		return true
34	case "linux":
35		switch runtime.GOARCH {
36		case "mips", "mipsle", "mips64", "mips64le", "ppc64":
37			return true
38		}
39	}
40	return false
41}
42
43func TestErrno(t *testing.T) {
44	if !errnoIsCaptured() {
45		t.Skip("platform does not support returning errno from syscall")
46	}
47
48	libFileName := filepath.Join(t.TempDir(), "liberrnotest.so")
49	if err := buildSharedLib(t, "CC", libFileName, filepath.Join("testdata", "liberrnotest", "errno_test.c")); err != nil {
50		t.Fatal(err)
51	}
52	defer os.Remove(libFileName)
53
54	lib, err := load.OpenLibrary(libFileName)
55	if err != nil {
56		t.Fatal(err)
57	}
58
59	setErrno, err := load.OpenSymbol(lib, "setErrno")
60	if err != nil {
61		t.Fatal(err)
62	}
63
64	r1, _, errno := purego.SyscallN(setErrno)
65	if int32(r1) != -1 {
66		t.Errorf("setErrno returned %d, wanted -1", r1)
67	}
68
69	libcName, err := getSystemLibrary()
70	if err != nil {
71		t.Fatal(err)
72	}
73	libc, err := load.OpenLibrary(libcName)
74	if err != nil {
75		t.Fatal(err)
76	}
77
78	var strerror func(int32) string
79	purego.RegisterLibFunc(&strerror, libc, "strerror")
80
81	const expected = "No such file or directory"
82	got := strerror(int32(errno))
83	if got != expected {
84		t.Errorf("strerror returned %q, wanted \"%s\"", got, expected)
85	}
86}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 102

↑↓ moveenter openesc close