mirror of https://github.com/yandex/odyssey.git
machinarium: add test_read_pool0 test
This commit is contained in:
parent
4baaaabb86
commit
b4489d32e5
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -0,0 +1,106 @@
|
|||
|
||||
/*
|
||||
* machinarium.
|
||||
*
|
||||
* Cooperative multitasking engine.
|
||||
*/
|
||||
|
||||
#include <machinarium.h>
|
||||
#include <machinarium_test.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
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();
|
||||
}
|
Loading…
Reference in New Issue