-
Notifications
You must be signed in to change notification settings - Fork 1
/
async_unix_notbsd_aio_test.go
101 lines (86 loc) · 2.29 KB
/
async_unix_notbsd_aio_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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// +build linux android
package asyncfs
import (
"github.com/stretchr/testify/assert"
"os"
"runtime"
"syscall"
"testing"
"time"
"unsafe"
)
func Test_asyncRWAio(t *testing.T) {
if runtime.GOOS != "linux" && runtime.GOOS != "android" {
t.Skip("skipping; linux-only test")
}
const sz = 8
var c1 ctx
err := c1.initAio(sz)
assert.NoError(t, err)
c1.sz = sz
c1.align = 512
c1.operationsFd = make(map[unsafe.Pointer]*File, sz)
c1.alignedBuffers = make(map[unsafe.Pointer]slice)
c = &c1
f, err := Open("/tmp/aio", syscall.O_RDWR|syscall.O_CREAT, 0644, ModeAsync)
assert.NoError(t, err)
defer os.Remove(f.path)
buf := make([]uint8, 4095)
n, err := f.asyncRWAio(iocbCmdPwrite, buf)
assert.Equal(t, 0, n)
assert.EqualError(t, err, ErrUnalignedData.Error())
c.align = 11
buf = make([]uint8, 4096)
n, err = f.asyncRWAio(iocbCmdPwrite, buf)
assert.Equal(t, 0, n)
assert.EqualError(t, err, ErrUnalignedData.Error())
c.align = 512
buf = AllocBuf(4096)
n, err = f.asyncRWAio(iocbCmdPwrite, buf)
assert.Equal(t, 0, n)
assert.NoError(t, err)
assert.Equal(t, 1, len(c.operationsFd))
}
func Test_fillStatesAio(t *testing.T) {
if runtime.GOOS != "linux" && runtime.GOOS != "android" {
t.Skip("skipping; linux-only test")
}
const sz = 8
var c1 ctx
err := c1.initAio(sz)
assert.NoError(t, err)
c = &c1
c.sz = sz
c.align = 512
c.operationsFd = make(map[unsafe.Pointer]*File, sz)
c.alignedBuffers = make(map[unsafe.Pointer]slice)
f, err := Open("/tmp/aio", syscall.O_RDWR|syscall.O_CREAT, 0644, ModeAsync)
assert.NoError(t, err)
defer os.Remove(f.path)
buf := make([]uint8, 4096)
n, err := f.writeAsync(buf)
assert.Equal(t, 0, n)
assert.NoError(t, err)
assert.False(t, f.lastAsyncOpState.complete)
time.Sleep(time.Millisecond * 10)
err = fillStatesAio(c)
assert.NoError(t, err)
assert.True(t, f.lastAsyncOpState.complete)
assert.Equal(t, int64(4096), f.pos)
for i := 0; i < sz+1; i++ {
n, err = f.writeAsync(buf)
assert.Equal(t, 0, n)
assert.NoError(t, err)
f.pos += int64(len(buf))
}
f.pos = 0
time.Sleep(time.Millisecond * 10)
err = fillStatesAio(c)
assert.NoError(t, err)
assert.True(t, f.lastAsyncOpState.complete)
assert.Equal(t, int64(4096*(sz+1)+4096), f.pos)
c.aio = 0
err = fillStatesAio(c)
assert.Error(t, err)
assert.EqualError(t, syscall.EINVAL, err.Error())
}