-
Notifications
You must be signed in to change notification settings - Fork 13
/
uring_test.go
64 lines (54 loc) · 1.41 KB
/
uring_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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package gouring
import (
"bytes"
"os"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
type genericTestingT interface {
assert.TestingT
require.TestingT
}
func testNewIoUring(t genericTestingT, entries uint32, flags uint32) *IoUring {
h, err := New(entries, flags)
require.NoError(t, err)
require.NotNil(t, h)
return h
}
func testNewIoUringWithParams(t genericTestingT, entries uint32, p *IoUringParams) *IoUring {
h, err := NewWithParams(entries, p)
require.NoError(t, err)
require.NotNil(t, h)
return h
}
func TestRingWrapper(t *testing.T) {
h := testNewIoUring(t, 256, 0)
defer h.Close()
// O_RDWR|O_CREATE|O_EXCL
ftmp, err := os.CreateTemp(os.TempDir(), "test_iouring_ring_wrapper_*")
require.NoError(t, err)
fd := ftmp.Fd()
var whatToWrite = [][]byte{
[]byte("hello\n"),
[]byte("\tworld\n\n"),
[]byte("io_uring\t\t\n"),
[]byte("nice!\n!!!\n\x00"),
}
var off uint64 = 0
for _, bs := range whatToWrite {
sqe := h.GetSqe()
PrepWrite(sqe, int(fd), &bs[0], len(bs), off)
sqe.Flags = IOSQE_IO_LINK
off = off + uint64(len(bs))
}
submitted, err := h.SubmitAndWait(uint32(len(whatToWrite)))
require.NoError(t, err)
require.Equal(t, len(whatToWrite), int(submitted))
var readed = make([]byte, 1024)
nb, err := ftmp.Read(readed)
assert.NoError(t, err)
readed = readed[:nb]
joined := bytes.Join(whatToWrite, []byte{})
assert.Equal(t, joined, readed)
}