Fixed tests
This commit is contained in:
parent
61c91120e5
commit
6accf285db
@ -36,12 +36,19 @@ static void close_cb(oio_handle* handle, int status) {
|
||||
}
|
||||
|
||||
|
||||
static oio_buf alloc_cb(oio_handle* handle, size_t size) {
|
||||
oio_buf buf = {0, 0};
|
||||
FATAL("alloc should not be called");
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
TEST_IMPL(bind_error_access) {
|
||||
struct sockaddr_in addr = oio_ip4_addr("255.255.255.255", TEST_PORT);
|
||||
oio_handle server;
|
||||
int r;
|
||||
|
||||
oio_init();
|
||||
oio_init(alloc_cb);
|
||||
|
||||
r = oio_tcp_init(&server, close_cb, NULL);
|
||||
ASSERT(r == 0);
|
||||
@ -65,7 +72,7 @@ TEST_IMPL(bind_error_addrinuse) {
|
||||
oio_handle server1, server2;
|
||||
int r;
|
||||
|
||||
oio_init();
|
||||
oio_init(alloc_cb);
|
||||
|
||||
r = oio_tcp_init(&server1, close_cb, NULL);
|
||||
ASSERT(r == 0);
|
||||
@ -100,7 +107,7 @@ TEST_IMPL(bind_error_addrnotavail) {
|
||||
oio_handle server;
|
||||
int r;
|
||||
|
||||
oio_init();
|
||||
oio_init(alloc_cb);
|
||||
|
||||
r = oio_tcp_init(&server, close_cb, NULL);
|
||||
ASSERT(r == 0);
|
||||
@ -123,7 +130,7 @@ TEST_IMPL(bind_error_fault_1) {
|
||||
oio_handle server;
|
||||
int r;
|
||||
|
||||
oio_init();
|
||||
oio_init(alloc_cb);
|
||||
|
||||
r = oio_tcp_init(&server, close_cb, NULL);
|
||||
ASSERT(r == 0);
|
||||
@ -149,7 +156,7 @@ TEST_IMPL(bind_error_inval) {
|
||||
oio_handle server;
|
||||
int r;
|
||||
|
||||
oio_init();
|
||||
oio_init(alloc_cb);
|
||||
|
||||
r = oio_tcp_init(&server, close_cb, NULL);
|
||||
ASSERT(r == 0);
|
||||
|
||||
@ -39,10 +39,17 @@ void close_cb(oio_handle *handle, int status) {
|
||||
}
|
||||
|
||||
|
||||
static oio_buf alloc_cb(oio_handle* handle, size_t size) {
|
||||
oio_buf buf = {0, 0};
|
||||
FATAL("alloc should not be called");
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
TEST_IMPL(close_cb_stack) {
|
||||
oio_handle handle;
|
||||
|
||||
oio_init();
|
||||
oio_init(alloc_cb);
|
||||
|
||||
if (oio_tcp_init(&handle, &close_cb, NULL)) {
|
||||
FATAL("oio_tcp_init failed");
|
||||
|
||||
@ -46,11 +46,18 @@ static void on_connect(oio_req *req, int status) {
|
||||
}
|
||||
|
||||
|
||||
static oio_buf alloc_cb(oio_handle* handle, size_t size) {
|
||||
oio_buf buf = {0, 0};
|
||||
FATAL("alloc should not be called");
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
TEST_IMPL(connection_fail) {
|
||||
struct sockaddr_in client_addr, server_addr;
|
||||
int r;
|
||||
|
||||
oio_init();
|
||||
oio_init(alloc_cb);
|
||||
|
||||
client_addr = oio_ip4_addr("0.0.0.0", 0);
|
||||
|
||||
|
||||
@ -102,32 +102,32 @@ static void start_server() {
|
||||
}
|
||||
|
||||
|
||||
static void read_cb(oio_req* req, size_t nread, int status) {
|
||||
static void read_cb(oio_handle* handle, int nread, oio_buf buf) {
|
||||
/* The server will not send anything, it should close gracefully. */
|
||||
ASSERT(req != NULL);
|
||||
ASSERT(status == 0);
|
||||
ASSERT(nread == 0);
|
||||
ASSERT(handle != NULL);
|
||||
ASSERT(nread == -1);
|
||||
ASSERT(oio_last_error().code == OIO_EOF);
|
||||
|
||||
oio_close(req->handle);
|
||||
|
||||
free(req);
|
||||
if (buf.base) {
|
||||
free(buf.base);
|
||||
}
|
||||
|
||||
oio_close(handle);
|
||||
}
|
||||
|
||||
|
||||
static void connect_cb(oio_req* req, int status) {
|
||||
oio_buf buf;
|
||||
int r;
|
||||
|
||||
ASSERT(req != NULL);
|
||||
ASSERT(status == 0);
|
||||
|
||||
free(req);
|
||||
|
||||
/* Reuse the req to do a read. */
|
||||
/* Not that the server will send anything, but otherwise we'll never know */
|
||||
/* when te server closes the connection. */
|
||||
oio_req_init(req, req->handle, read_cb);
|
||||
buf.base = (char*)&BUFFER;
|
||||
buf.len = sizeof BUFFER;
|
||||
r = oio_read(req, &buf, 1);
|
||||
r = oio_read_start(req->handle, read_cb);
|
||||
ASSERT(r == 0);
|
||||
|
||||
connect_cb_called++;
|
||||
@ -152,8 +152,17 @@ static void client_connect() {
|
||||
}
|
||||
|
||||
|
||||
static oio_buf alloc_cb(oio_handle* handle, size_t size) {
|
||||
oio_buf buf;
|
||||
buf.base = (char*)malloc(size);
|
||||
buf.len = size;
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEST_IMPL(delayed_accept) {
|
||||
oio_init();
|
||||
oio_init(alloc_cb);
|
||||
|
||||
start_server();
|
||||
|
||||
|
||||
@ -86,17 +86,23 @@ static void pinger_write_ping(pinger_t* pinger) {
|
||||
}
|
||||
|
||||
|
||||
static void pinger_after_read(oio_req* req, size_t nread, int status) {
|
||||
static void pinger_read_cb(oio_handle* handle, int nread, oio_buf buf) {
|
||||
unsigned int i;
|
||||
pinger_t* pinger;
|
||||
|
||||
ASSERT(status == 0);
|
||||
pinger = (pinger_t*)handle->data;
|
||||
|
||||
pinger = (pinger_t*)req->handle->data;
|
||||
if (nread < 0) {
|
||||
ASSERT(oio_last_error().code == OIO_EOF);
|
||||
|
||||
if (nread == 0) {
|
||||
puts("got EOF");
|
||||
|
||||
if (buf.base) {
|
||||
free(buf.base);
|
||||
}
|
||||
|
||||
oio_close(&pinger->handle);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -115,14 +121,6 @@ static void pinger_after_read(oio_req* req, size_t nread, int status) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pinger_try_read(pinger);
|
||||
}
|
||||
|
||||
|
||||
void pinger_try_read(pinger_t* pinger) {
|
||||
oio_req_init(&pinger->read_req, &pinger->handle, pinger_after_read);
|
||||
oio_read(&pinger->read_req, &pinger->buf, 1);
|
||||
}
|
||||
|
||||
|
||||
@ -131,8 +129,9 @@ void pinger_on_connect(oio_req *req, int status) {
|
||||
|
||||
ASSERT(status == 0);
|
||||
|
||||
pinger_try_read(pinger);
|
||||
pinger_write_ping(pinger);
|
||||
|
||||
oio_read_start(req->handle, pinger_read_cb);
|
||||
}
|
||||
|
||||
|
||||
@ -160,8 +159,16 @@ void pinger_new() {
|
||||
}
|
||||
|
||||
|
||||
static oio_buf alloc_cb(oio_handle* handle, size_t size) {
|
||||
oio_buf buf;
|
||||
buf.base = (char*)malloc(size);
|
||||
buf.len = size;
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
TEST_IMPL(ping_pong) {
|
||||
oio_init();
|
||||
oio_init(alloc_cb);
|
||||
|
||||
pinger_new();
|
||||
oio_run();
|
||||
|
||||
@ -55,34 +55,24 @@ static void close_cb(oio_handle* handle, int status) {
|
||||
}
|
||||
|
||||
|
||||
static void read_cb(oio_req* req, size_t nread, int status) {
|
||||
oio_buf receive_buf;
|
||||
int r;
|
||||
static void read_cb(oio_handle* handle, int nread, oio_buf buf) {
|
||||
ASSERT(handle != NULL);
|
||||
|
||||
if (nread < 0) {
|
||||
ASSERT(oio_last_error().code == OIO_EOF);
|
||||
|
||||
/* The server will not send anything, it should close gracefully. */
|
||||
ASSERT(req != NULL);
|
||||
ASSERT(status == 0);
|
||||
if (buf.base) {
|
||||
free(buf.base);
|
||||
}
|
||||
|
||||
if (nread > 0) {
|
||||
bytes_received_done += nread;
|
||||
|
||||
receive_buf.len = CHUNK_SIZE;
|
||||
receive_buf.base = receive_buffer + bytes_received_done;
|
||||
receive_buf.len = (CHUNK_SIZE > TOTAL_BYTES - bytes_received_done)
|
||||
? TOTAL_BYTES - bytes_received_done
|
||||
: CHUNK_SIZE;
|
||||
oio_close(handle);
|
||||
return;
|
||||
}
|
||||
|
||||
/* As long as we don't have graceful disconnect, I'll have to be this... */
|
||||
/* Todo: FIXME */
|
||||
if (bytes_received_done < TOTAL_BYTES) {
|
||||
oio_req_init(req, req->handle, read_cb);
|
||||
r = oio_read(req, &receive_buf, 1);
|
||||
ASSERT(r == 0);
|
||||
} else {
|
||||
oio_close(req->handle);
|
||||
free(req);
|
||||
}
|
||||
|
||||
bytes_received_done += nread;
|
||||
|
||||
free(buf.base);
|
||||
}
|
||||
|
||||
|
||||
@ -135,11 +125,18 @@ static void connect_cb(oio_req* req, int status) {
|
||||
receive_buf.base = receive_buffer;
|
||||
|
||||
oio_req_init(req, handle, read_cb);
|
||||
r = oio_read(req, &receive_buf, 1);
|
||||
r = oio_read_start(handle, read_cb);
|
||||
ASSERT(r == 0);
|
||||
}
|
||||
|
||||
|
||||
static oio_buf alloc_cb(oio_handle* handle, size_t size) {
|
||||
oio_buf buf;
|
||||
buf.base = (char*)malloc(size);
|
||||
buf.len = size;
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
TEST_IMPL(tcp_writealot) {
|
||||
struct sockaddr_in addr = oio_ip4_addr("127.0.0.1", TEST_PORT);
|
||||
@ -156,7 +153,7 @@ TEST_IMPL(tcp_writealot) {
|
||||
ASSERT(send_buffer != NULL);
|
||||
ASSERT(receive_buffer != NULL);
|
||||
|
||||
oio_init();
|
||||
oio_init(alloc_cb);
|
||||
|
||||
r = oio_tcp_init(client, close_cb, NULL);
|
||||
ASSERT(r == 0);
|
||||
|
||||
@ -54,13 +54,18 @@ static void dummy_timeout_cb(oio_req *req, int64_t skew, int status) {
|
||||
}
|
||||
|
||||
|
||||
static oio_buf alloc_cb(oio_handle* handle, size_t size) {
|
||||
FATAL("alloc should not be called");
|
||||
}
|
||||
|
||||
|
||||
TEST_IMPL(timeout) {
|
||||
oio_req *req;
|
||||
oio_req exit_req;
|
||||
oio_req dummy_req;
|
||||
int i;
|
||||
|
||||
oio_init();
|
||||
oio_init(alloc_cb);
|
||||
|
||||
start_time = oio_now();
|
||||
ASSERT(0 < start_time);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user