detached 3a10209

dlfcn_test.go RawHistoryFolder

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: 2023 The Ebitengine Authors
3
4//go:build darwin || freebsd || linux || netbsd
5
6package purego_test
7
8import (
9	"os"
10	"path/filepath"
11	"syscall"
12	"testing"
13	"unsafe"
14
15	"github.com/bnema/purego"
16)
17
18func TestSimpleDlsym(t *testing.T) {
19	if _, err := purego.Dlsym(purego.RTLD_DEFAULT, "dlsym"); err != nil {
20		t.Errorf("Dlsym with RTLD_DEFAULT failed: %v", err)
21	}
22}
23
24func TestNestedDlopenCall(t *testing.T) {
25	libFileName := filepath.Join(t.TempDir(), "libdlnested.so")
26	t.Logf("Build %v", libFileName)
27
28	if err := buildSharedLib(t, "CXX", libFileName, filepath.Join("testdata", "libdlnested", "nested_test.cpp")); err != nil {
29		t.Fatal(err)
30	}
31	defer os.Remove(libFileName)
32
33	lib, err := purego.Dlopen(libFileName, purego.RTLD_NOW|purego.RTLD_GLOBAL)
34	if err != nil {
35		t.Fatalf("Dlopen(%q) failed: %v", libFileName, err)
36	}
37
38	purego.Dlclose(lib)
39}
40
41func TestSyscallN(t *testing.T) {
42	var dlsym uintptr
43	var err error
44	if dlsym, err = purego.Dlsym(purego.RTLD_DEFAULT, "dlsym"); err != nil {
45		t.Errorf("Dlsym with RTLD_DEFAULT failed: %v", err)
46	}
47	r1, _, err2 := purego.SyscallN(dlsym, purego.RTLD_DEFAULT, uintptr(unsafe.Pointer(&[]byte("dlsym\x00")[0])))
48	if dlsym != r1 {
49		t.Fatalf("SyscallN didn't return the same result as purego.Dlsym: %d", err2)
50	}
51}
52
53func TestSyscallNErrnoIsNotAnInputArgument(t *testing.T) {
54	if errnoIsCaptured() {
55		t.Skip("this platform saves errno; see TestErrno")
56	}
57
58	openSym, err := purego.Dlsym(purego.RTLD_DEFAULT, "open")
59	if err != nil {
60		t.Fatal(err)
61	}
62
63	path, err := syscall.BytePtrFromString("_file_that_does_not_exist_")
64	if err != nil {
65		t.Fatal(err)
66	}
67
68	// The third argument is non-zero so that echoing it back as errno is visible.
69	const third = uintptr(0o600)
70	r1, _, errno := purego.SyscallN(openSym,
71		uintptr(unsafe.Pointer(path)),
72		uintptr(os.O_RDWR),
73		third)
74	if int32(r1) != -1 {
75		t.Fatalf("open returned %d, wanted -1", r1)
76	}
77	if errno != 0 {
78		t.Errorf("SyscallN returned %d as errno where errno is not captured, wanted 0", errno)
79	}
80}

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