-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathasynctest-clobberstream.c
47 lines (42 loc) · 1.31 KB
/
asynctest-clobberstream.c
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
#include "asynctest-clobberstream.h"
#include <errno.h>
#include <string.h>
#include <async/async.h>
#include <async/clobberstream.h>
#include <async/substream.h>
#include <async/zerostream.h>
enum {
OFFSET = 10,
MASK = -1,
TOTAL_BYTE_COUNT = 50,
};
VERDICT test_clobberstream(void)
{
async_t *async = make_async();
substream_t *substr =
make_substream(async, zerostream, SUBSTREAM_CLOSE_AT_END, 0,
TOTAL_BYTE_COUNT);
clobberstream_t *clstr =
clobber(async, substream_as_bytestream_1(substr), OFFSET, MASK);
uint8_t buffer[TOTAL_BYTE_COUNT];
ssize_t count = clobberstream_read(clstr, buffer, OFFSET + 2);
if (count != OFFSET + 2) {
tlog("Unexpected error %d (errno %d)", (int) count, (int) errno);
return FAIL;
}
count = clobberstream_read(clstr, buffer + OFFSET + 2,
sizeof buffer - (OFFSET + 2));
if (count != TOTAL_BYTE_COUNT - (OFFSET + 2)) {
tlog("Unexpected error %d (errno %d)", (int) count, (int) errno);
return FAIL;
}
uint64_t value;
memcpy(&value, buffer + OFFSET, sizeof value);
if (value != MASK) {
tlog("Unexpected clobber value");
return FAIL;
}
clobberstream_close(clstr);
destroy_async(async);
return posttest_check(PASS);
}