-
Notifications
You must be signed in to change notification settings - Fork 10
/
register_test.go
42 lines (35 loc) · 964 Bytes
/
register_test.go
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
// +build linux
package iouring
import (
"io/ioutil"
"os"
"syscall"
"testing"
"github.com/stretchr/testify/require"
)
func TestRegisterBuffers(t *testing.T) {
r, err := New(2048, nil)
require.NoError(t, err)
require.NotNil(t, r)
vecs := make([]*syscall.Iovec, 10)
require.NoError(t, RegisterBuffers(r.Fd(), vecs))
require.NoError(t, UnregisterBuffers(r.Fd(), vecs))
}
func TestFileRegistry(t *testing.T) {
r, err := New(2048, nil)
require.NoError(t, err)
require.NotNil(t, r)
reg := NewFileRegistry(r.Fd())
f, err := ioutil.TempFile("", "test-file-registry")
require.NoError(t, err)
defer os.Remove(f.Name())
f2, err := ioutil.TempFile("", "test-file-registry")
require.NoError(t, err)
defer os.Remove(f2.Name())
require.NoError(t, reg.Register(int(f.Fd())))
require.NoError(t, reg.Register(int(f2.Fd())))
id, ok := reg.ID(int(f2.Fd()))
require.NotZero(t, id)
require.True(t, ok)
require.NoError(t, reg.Unregister(int(f.Fd())))
}