github.com/ii64/gouring@v0.4.1/uring_test.go (about) 1 package gouring 2 3 import ( 4 "bytes" 5 "os" 6 "testing" 7 8 "github.com/stretchr/testify/assert" 9 "github.com/stretchr/testify/require" 10 ) 11 12 type genericTestingT interface { 13 assert.TestingT 14 require.TestingT 15 } 16 17 func testNewIoUring(t genericTestingT, entries uint32, flags uint32) *IoUring { 18 h, err := New(entries, flags) 19 require.NoError(t, err) 20 require.NotNil(t, h) 21 return h 22 } 23 24 func testNewIoUringWithParams(t genericTestingT, entries uint32, p *IoUringParams) *IoUring { 25 h, err := NewWithParams(entries, p) 26 require.NoError(t, err) 27 require.NotNil(t, h) 28 return h 29 } 30 31 func TestRingWrapper(t *testing.T) { 32 h := testNewIoUring(t, 256, 0) 33 defer h.Close() 34 35 // O_RDWR|O_CREATE|O_EXCL 36 ftmp, err := os.CreateTemp(os.TempDir(), "test_iouring_ring_wrapper_*") 37 require.NoError(t, err) 38 fd := ftmp.Fd() 39 40 var whatToWrite = [][]byte{ 41 []byte("hello\n"), 42 []byte("\tworld\n\n"), 43 []byte("io_uring\t\t\n"), 44 []byte("nice!\n!!!\n\x00"), 45 } 46 var off uint64 = 0 47 for _, bs := range whatToWrite { 48 sqe := h.GetSqe() 49 PrepWrite(sqe, int(fd), &bs[0], len(bs), off) 50 sqe.Flags = IOSQE_IO_LINK 51 off = off + uint64(len(bs)) 52 } 53 submitted, err := h.SubmitAndWait(uint32(len(whatToWrite))) 54 require.NoError(t, err) 55 require.Equal(t, len(whatToWrite), int(submitted)) 56 57 var readed = make([]byte, 1024) 58 nb, err := ftmp.Read(readed) 59 assert.NoError(t, err) 60 readed = readed[:nb] 61 62 joined := bytes.Join(whatToWrite, []byte{}) 63 assert.Equal(t, joined, readed) 64 }