mirror of
https://github.com/ii64/gouring.git
synced 2024-11-21 22:46:22 +01:00
Nugraha
7eedf9754b
There's other adjustment/addition: * Function name CQE/SQE renamed to Cqe/Sqe. * SQ entry union sets value withput util to reduce function complexity, so leaving function budget for another stuff. * UserData has its own type, implement for uint64, uintptr, and unsafe. * TODO: decide what to use `Syscall` or `RawSyscall`. * Exposed `SeenCqe`. * Ignore *.test file extension. * Inline cost tool. Signed-off-by: Nugraha <richiisei@gmail.com>
64 lines
1.4 KiB
Go
64 lines
1.4 KiB
Go
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)
|
|
}
|