-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_readv.nim
More file actions
34 lines (31 loc) · 978 Bytes
/
test_readv.nim
File metadata and controls
34 lines (31 loc) · 978 Bytes
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
import unittest2
import nimuring
import posix
template withReadvQueue(body: untyped) =
var q {.inject.} = newQueue(1, {})
let fd {.inject.} = open("/dev/zero").getFileHandle
var buffer {.inject.}: array[128, uint8]
for i in 0..high(buffer):
buffer[i] = 42
let iovecs {.inject.}: seq[IoVec] = @[IoVec(iov_base: buffer[0].unsafeAddr, iov_len: 128)]
try:
body
finally:
discard close(fd)
suite "readv operation":
test "readv fills buffer with zeros":
withReadvQueue:
q.readv(cast[pointer](0xcccccccc), fd, iovecs)
q.submit()
let cqes = q.copyCqes(1)
check cqes[0].userData == 0xcccccccc.uint64
check cqes[0].res == 128
for i in 0..high(buffer):
check buffer[i] == 0
test "readv userData and result":
withReadvQueue:
q.readv(cast[pointer](0xcccccccc), fd, iovecs)
q.submit()
let cqes = q.copyCqes(1)
check cqes[0].userData == 0xcccccccc.uint64
check cqes[0].res == 128