diff --git a/tests/machinarium_test.c b/tests/machinarium_test.c index 5b9e31c3..49266d09 100644 --- a/tests/machinarium_test.c +++ b/tests/machinarium_test.c @@ -55,16 +55,21 @@ extern void test_getaddrinfo2(void); extern void test_client_server0(void); extern void test_client_server1(void); + extern void test_read_10mb0(void); extern void test_read_10mb1(void); extern void test_read_10mb2(void); extern void test_read_timeout(void); extern void test_read_cancel(void); +extern void test_read_poll0(void); +extern void test_read_poll1(void); + extern void test_tls0(void); extern void test_tls_read_10mb0(void); extern void test_tls_read_10mb1(void); extern void test_tls_read_10mb2(void); +extern void test_tls_read_10mb_poll(void); int main(int argc, char *argv[]) @@ -113,9 +118,12 @@ main(int argc, char *argv[]) machinarium_test(test_read_10mb2); machinarium_test(test_read_timeout); machinarium_test(test_read_cancel); + machinarium_test(test_read_poll0); + machinarium_test(test_read_poll1); machinarium_test(test_tls0); machinarium_test(test_tls_read_10mb0); machinarium_test(test_tls_read_10mb1); machinarium_test(test_tls_read_10mb2); + machinarium_test(test_tls_read_10mb_poll); return 0; } diff --git a/tests/makefile b/tests/makefile index 73f4cf16..488e309d 100644 --- a/tests/makefile +++ b/tests/makefile @@ -49,10 +49,13 @@ OBJECTS = machinarium_test.o \ test_read_10mb2.o \ test_read_timeout.o \ test_read_cancel.o \ + test_read_poll0.o \ + test_read_poll1.o \ test_tls0.o \ test_tls_read_10mb0.o \ test_tls_read_10mb1.o \ - test_tls_read_10mb2.o + test_tls_read_10mb2.o \ + test_tls_read_10mb_poll.o all: clean $(OBJECTS) machinarium_test machinarium_test: $(CC) $(OBJECTS) $(LFLAGS) -o machinarium_test diff --git a/tests/test_read_poll0.c b/tests/test_read_poll0.c new file mode 100644 index 00000000..be4babb4 --- /dev/null +++ b/tests/test_read_poll0.c @@ -0,0 +1,106 @@ + +/* + * machinarium. + * + * Cooperative multitasking engine. +*/ + +#include +#include + +#include +#include + +static void +server(void *arg) +{ + machine_io_t *server = machine_io_create(); + test(server != NULL); + + struct sockaddr_in sa; + sa.sin_family = AF_INET; + sa.sin_addr.s_addr = inet_addr("127.0.0.1"); + sa.sin_port = htons(7778); + int rc; + rc = machine_bind(server, (struct sockaddr*)&sa); + test(rc == 0); + + machine_io_t *client; + rc = machine_accept(server, &client, 16, UINT32_MAX); + test(rc == 0); + + machine_io_t *io_set[] = {client}; + machine_io_t *io; + io = machine_read_poll(io_set, 1, UINT32_MAX); + test(io == client); + + char buf[1024]; + rc = machine_read(client, buf, sizeof(buf), UINT32_MAX); + test(rc == 0); + + /* test eof */ + io = machine_read_poll(io_set, 1, UINT32_MAX); + test(io == client); + rc = machine_read(client, buf, sizeof(buf), UINT32_MAX); + test(rc == -1); + + rc = machine_close(client); + test(rc == 0); + machine_io_free(client); + + rc = machine_close(server); + test(rc == 0); + machine_io_free(server); +} + +static void +client(void *arg) +{ + machine_io_t *client = machine_io_create(); + test(client != NULL); + + struct sockaddr_in sa; + sa.sin_family = AF_INET; + sa.sin_addr.s_addr = inet_addr("127.0.0.1"); + sa.sin_port = htons(7778); + int rc; + rc = machine_connect(client, (struct sockaddr*)&sa, UINT32_MAX); + test(rc == 0); + + char buf[1024]; + memset(buf, 'x', sizeof(buf)); + + rc = machine_write(client, buf, 1024, UINT32_MAX); + test(rc == 0); + + rc = machine_close(client); + test(rc == 0); + machine_io_free(client); +} + +static void +test_cs(void *arg) +{ + int rc; + rc = machine_coroutine_create(server, NULL); + test(rc != -1); + + rc = machine_coroutine_create(client, NULL); + test(rc != -1); +} + +void +test_read_poll0(void) +{ + machinarium_init(); + + int id; + id = machine_create("test", test_cs, NULL); + test(id != -1); + + int rc; + rc = machine_wait(id); + test(rc != -1); + + machinarium_free(); +}