END_TEST START_TEST(test_http_close_on_replace) { const gchar *connect = "POST /?sid=16a0dd9a4e554a9f94520c8bfa59e1b9&connect=true HTTP/1.1\n" "Content-Length: 0\n\n"; const gchar *poll = "POST /?sid=16a0dd9a4e554a9f94520c8bfa59e1b9 HTTP/1.1\n" "Content-Length: 18\n\n" "/test/close:0=null"; gint err; qev_fd_t s1 = test_socket(); struct client *client = test_get_client_raw(); qev_fd_t s2 = test_socket(); err = send(s1, connect, strlen(connect), 0); ck_assert_int_eq(err, strlen(connect)); QEV_WAIT_FOR(client->http.client != NULL); err = send(s2, poll, strlen(poll), 0); ck_assert_int_eq(err, strlen(poll)); _assert_status_code(s1, 403); _assert_status_code(s2, 403); close(s1); close(s2); }
static struct httpc* _httpc_new() { gint err; gchar sid[33]; GString *buff = qev_buffer_get(); struct httpc *hc = g_slice_alloc0(sizeof(*hc)); _uuid(sid); hc->polling = test_socket(); hc->waiting = test_socket(); hc->aq = g_async_queue_new(); hc->sid = g_strdup(sid); hc->th_run = TRUE; g_mutex_init(&hc->lock); hc->th = g_thread_new("httpc", _httpc_thread, hc); g_string_printf(buff, INIT_HEADERS, hc->sid); err = send(hc->polling, buff->str, buff->len, 0); ck_assert_int_eq(err, buff->len); qev_buffer_put(buff); _next(hc, "/qio/callback/1:0={\"code\":200,\"data\":\"localhost\"}"); return hc; }
void device1(NN_UNUSED void *arg) { int rc; /* Intialise the device sockets. */ deva = test_socket(AF_SP_RAW, NN_PAIR); test_bind(deva, SOCKET_ADDRESS_A); devb = test_socket(AF_SP_RAW, NN_PAIR); test_bind(devb, SOCKET_ADDRESS_B); /* Run the device. */ rc = nn_device(deva, devb); nn_assert(rc < 0 && (nn_errno() == EBADF)); }
void device2(NN_UNUSED void *arg) { int rc; /* Intialise the device sockets. */ devc = test_socket(AF_SP_RAW, NN_PULL); test_bind(devc, SOCKET_ADDRESS_C); devd = test_socket(AF_SP_RAW, NN_PUSH); test_bind(devd, SOCKET_ADDRESS_D); /* Run the device. */ rc = nn_device(devc, devd); nn_assert(rc < 0 && nn_errno() == EBADF); }
int testdomain() { int rc; int s; int op; size_t opsz; printf("test domain\n"); s = test_socket (AF_SP, NN_PAIR); opsz = sizeof (op); rc = nn_getsockopt (s, NN_SOL_SOCKET, NN_DOMAIN, &op, &opsz); errno_assert (rc == 0); nn_assert (opsz == sizeof (op)); nn_assert (op == AF_SP); opsz = sizeof (op); rc = nn_getsockopt (s, NN_SOL_SOCKET, NN_PROTOCOL, &op, &opsz); errno_assert (rc == 0); nn_assert (opsz == sizeof (op)); nn_assert (op == NN_PAIR); test_close (s); return 0; }
int register_device(void) { int result; result = test_socket(); if(result < 0) { printk( KERN_ALERT "led-driver: Server socket is not created." ); } printk( KERN_ALERT "led-driver: register_device() is called." ); result = register_chrdev( 0, device_name, &simple_driver_fops ); if( result < 0 ) { printk( KERN_ALERT "Simple-driver: can\'t register character device with errorcode = %i", result ); return result; } device_file_major_number = result; printk( KERN_ALERT "Simple-driver: registered character device with major number = %i and minor numbers 0...255" , device_file_major_number ); return 0; }
END_TEST START_TEST(test_http_error_invalid_events) { const gchar *headers = "POST /?sid=16a0dd9a4e554a9f94520c8bfa59e1b9&connect=true HTTP/1.1\n" \ "Content-Length: 19\n\n" \ "im an event\n" \ "/test:0"; const gchar *headers_after = "POST /?sid=16a0dd9a4e554a9f94520c8bfa59e1b9 HTTP/1.1\n" "Content-Length: 0\n\n"; gint err; qev_fd_t s = test_socket(); err = send(s, headers, strlen(headers), 0); ck_assert_int_eq(err, strlen(headers)); _assert_status_code(s, 400); err = send(s, headers_after, strlen(headers_after), 0); ck_assert_int_eq(err, strlen(headers_after)); _assert_status_code(s, 403); close(s); }
END_TEST START_TEST(test_http_disabled) { const gchar *header = "GET /iframe HTTP/1.1\n\n"; ck_assert(g_file_set_contents("test_http_disabled.ini", "[quick.io]\n" "public-address =", -1, NULL)); test_setup_with_config("test_http_disabled.ini"); unlink("test_http_disabled.ini"); gint err; gchar buff[0xffff]; qev_fd_t s = test_socket(); err = send(s, header, strlen(header), 0); ck_assert_int_eq(strlen(header), err); err = recv(s, buff, sizeof(buff), 0); ck_assert_int_gt(err, 0); buff[err] = '\0'; ck_assert(strstr(buff, "501 Not Implemented") != NULL); ck_assert(strstr(buff, "window.parent.postMessage") != NULL); close(s); }
END_TEST START_TEST(test_http_close_with_surrogate) { const gchar *headers = "POST /?sid=16a0dd9a4e554a9f94520c8bfa59e1b9&connect=true HTTP/1.1\n" "Content-Length: 0\n\n"; gint err; qev_fd_t s = test_socket(); struct client *client = test_get_client_raw(); ck_assert(!qev_is_surrogate(client)); err = send(s, headers, strlen(headers), 0); ck_assert_int_eq(err, strlen(headers)); QEV_WAIT_FOR(client->http.client != NULL); QEV_WAIT_FOR(client->http.client->http.client != NULL); qev_close(client, HTTP_DONE); _assert_status_code(s, 403); close(s); }
END_TEST START_TEST(test_http_partial_body) { const gchar *headers = "POST / HTTP/1.1\n" "Content-Length: 16\n\n"; const gchar *body = "/qio/ping:0=null"; gint err; qev_fd_t s = test_socket(); struct client *client = test_get_client_raw(); err = send(s, headers, strlen(headers), 0); ck_assert_int_eq(err, strlen(headers)); QEV_WAIT_FOR(client->timeout != NULL); err = send(s, body, strlen(body), 0); ck_assert_int_eq(err, strlen(body)); _assert_status_code(s, 403); ck_assert(!client->qev_client._flags.closed); close(s); }
int testterm() { int rc; int s; struct nn_thread thread; printf("test term\n"); /* Close the socket with no associated endpoints. */ s = test_socket (AF_SP, NN_PAIR); test_close (s); /* Test nn_term() before nn_close(). */ nn_thread_init (&thread, worker, NULL); nn_sleep (100); nn_term(); /* Check that it's not possible to create new sockets after nn_term(). */ rc = nn_socket (AF_SP, NN_PAIR); nn_assert (rc == -1); errno_assert (nn_errno () == ETERM); /* Wait till worker thread terminates. */ nn_thread_term(&thread); printf("nn_thread_term finished\n"); return 0; }
int main () { #if !defined NN_HAVE_WINDOWS int sb; int i; int j; struct nn_thread threads [THREAD_COUNT]; /* Stress the shutdown algorithm. */ sb = test_socket (AF_SP, NN_PUB); test_bind (sb, SOCKET_ADDRESS); for (j = 0; j != 10; ++j) { for (i = 0; i != THREAD_COUNT; ++i) nn_thread_init (&threads [i], routine, NULL); for (i = 0; i != THREAD_COUNT; ++i) nn_thread_term (&threads [i]); } test_close (sb); #endif return 0; }
int main (int argc, const char *argv[]) { int end0; int end1; struct nn_thread thread5; struct nn_thread thread6; int port = get_test_port(argc, argv); test_addr_from(socket_address_h, "tcp", "127.0.0.1", port); test_addr_from(socket_address_i, "tcp", "127.0.0.1", port + 1); test_addr_from(socket_address_j, "tcp", "127.0.0.1", port + 2); /* Test the bi-directional device with REQ/REP (headers). */ /* Start the devices. */ nn_thread_init (&thread5, device5, NULL); nn_thread_init (&thread6, device6, NULL); /* Create two sockets to connect to the device. */ end0 = test_socket (AF_SP, NN_REQ); test_connect (end0, socket_address_h); end1 = test_socket (AF_SP, NN_REP); test_connect (end1, socket_address_j); /* Wait for TCP to establish. */ nn_sleep (100); /* Pass a message between endpoints. */ test_send (end0, "XYZ"); test_recv (end1, "XYZ"); /* Now send a reply. */ test_send (end1, "REPLYXYZ"); test_recv (end0, "REPLYXYZ"); /* Clean up. */ test_close (end0); test_close (end1); /* Shut down the devices. */ nn_term (); nn_thread_term (&thread5); nn_thread_term (&thread6); return 0; }
int testipc_shutdown() { int sb; int i; int j; struct nn_thread threads [THREAD_COUNT]; printf("test ipc shutdown\n"); /* Stress the shutdown algorithm. */ #if defined(SIGPIPE) && defined(SIG_IGN) signal (SIGPIPE, SIG_IGN); #endif sb = test_socket (AF_SP, NN_PUB); test_bind (sb, SOCKET_ADDRESS); for (j = 0; j != TEST_LOOPS; ++j) { for (i = 0; i != THREAD_COUNT; ++i) nn_thread_init (&threads [i], routine, NULL); for (i = 0; i != THREAD_COUNT; ++i) nn_thread_term (&threads [i]); } test_close (sb); /* Test race condition of sending message while socket shutting down */ sb = test_socket (AF_SP, NN_PUSH); test_bind (sb, SOCKET_ADDRESS); for (j = 0; j != TEST_LOOPS; ++j) { for (i = 0; i != TEST2_THREAD_COUNT; ++i) nn_thread_init (&threads [i], routine2, NULL); active = TEST2_THREAD_COUNT; while ( active ) { (void) nn_send (sb, "hello", 5, NN_DONTWAIT); } for (i = 0; i != TEST2_THREAD_COUNT; ++i) nn_thread_term(&threads [i]); } test_close (sb); return 0; }
int main(int argc, char **argv) { if (!test_socket()) return 1; printf("OK\n"); return 0; }
int main () { int sb; int i; int j; struct nn_thread threads [THREAD_COUNT]; /* Stress the shutdown algorithm. */ sb = test_socket (AF_SP, NN_PUB); test_bind (sb, SOCKET_ADDRESS); for (j = 0; j != TEST_LOOPS; ++j) { for (i = 0; i != THREAD_COUNT; ++i) nn_thread_init (&threads [i], routine, NULL); for (i = 0; i != THREAD_COUNT; ++i) nn_thread_term (&threads [i]); } test_close (sb); /* Test race condition of sending message while socket shutting down */ sb = test_socket (AF_SP, NN_PUSH); test_bind (sb, SOCKET_ADDRESS); for (j = 0; j != TEST_LOOPS; ++j) { for (i = 0; i != TEST2_THREAD_COUNT; ++i) nn_thread_init (&threads [i], routine2, NULL); nn_atomic_init(&active, TEST2_THREAD_COUNT); while (active.n) { (void) nn_send (sb, "hello", 5, NN_DONTWAIT); } for (i = 0; i != TEST2_THREAD_COUNT; ++i) nn_thread_term (&threads [i]); nn_atomic_term(&active); } test_close (sb); return 0; }
int main(int argc, char *argv[]) { test_socket(); test_socketpair(); test_listen_unbound(); test_bind(); test_listen_bound(); }
void device6 (NN_UNUSED void *arg) { int rc; int dev2; int dev3; dev2 = test_socket (AF_SP_RAW, NN_REP); test_connect (dev2, socket_address_i); dev3 = test_socket (AF_SP_RAW, NN_REQ); test_bind (dev3, socket_address_j); /* Run the device. */ rc = nn_device (dev2, dev3); nn_assert (rc < 0 && nn_errno () == ETERM); /* Clean up. */ test_close (dev2); test_close (dev3); }
int main(void) { int sd, ret; socklen_t len; struct sctp_rtoinfo srtoinfo; /*setting the variables*/ struct sctp_rtoinfo grtoinfo; /*Getting the variables*/ sd = test_socket (PF_INET, SOCK_STREAM, IPPROTO_SCTP); len = sizeof(struct sctp_rtoinfo); /*TEST1 Getting the default values using getsockopt()*/ ret = getsockopt(sd, IPPROTO_SCTP, SCTP_RTOINFO, &grtoinfo, &len); if (ret < 0) tst_brkm(TBROK, tst_exit, "getsockopt SCTP_RTOINFO " "ret:%d, errno:%d", ret, errno); tst_resm(TPASS, "getsockopt() SCTP_RTOINFO - SUCCESS"); /*Assigning the values to RTO initial and max and min bounds*/ srtoinfo.srto_initial=60; srtoinfo.srto_max=100; srtoinfo.srto_min=40; /*TEST2 Setting the values using setsockopt()*/ ret = setsockopt(sd, IPPROTO_SCTP, SCTP_RTOINFO, &srtoinfo, sizeof(struct sctp_rtoinfo)); if (ret < 0) tst_brkm(TBROK, tst_exit, "setsockopt SCTP_RTOINFO " "ret:%d, errno:%d", ret, errno); tst_resm(TPASS, "setsockopt() SCTP_RTOINFO - SUCCESS"); /*Getting the values which are set using setsockopt()*/ ret = getsockopt(sd, IPPROTO_SCTP, SCTP_RTOINFO, &grtoinfo, &len); if (ret < 0) tst_brkm(TBROK, tst_exit, "getsockopt SCTP_RTOINFO " "ret:%d, errno:%d", ret, errno); /* TEST3 Compare the get values with the set values. */ if (srtoinfo.srto_initial != grtoinfo.srto_initial && srtoinfo.srto_max != grtoinfo.srto_max && srtoinfo.srto_min != grtoinfo.srto_min) tst_brkm(TBROK, tst_exit, "setsockopt/getsockopt SCTP_RTOINFO " "compare failed"); tst_resm(TPASS, "setsockopt()/getsockopt SCTP_RTOINFO compare - " "SUCCESS"); close(sd); return 0; }
int main () { int rc; int sb; int sc; struct nn_iovec iov [2]; struct nn_msghdr hdr; char buf [6]; sb = test_socket (AF_SP, NN_PAIR); test_bind (sb, SOCKET_ADDRESS); sc = test_socket (AF_SP, NN_PAIR); test_connect (sc, SOCKET_ADDRESS); iov [0].iov_base = "AB"; iov [0].iov_len = 2; iov [1].iov_base = "CDEF"; iov [1].iov_len = 4; memset (&hdr, 0, sizeof (hdr)); hdr.msg_iov = iov; hdr.msg_iovlen = 2; rc = nn_sendmsg (sc, &hdr, 0); errno_assert (rc >= 0); nn_assert (rc == 6); iov [0].iov_base = buf; iov [0].iov_len = 4; iov [1].iov_base = buf + 4; iov [1].iov_len = 2; memset (&hdr, 0, sizeof (hdr)); hdr.msg_iov = iov; hdr.msg_iovlen = 2; rc = nn_recvmsg (sb, &hdr, 0); errno_assert (rc >= 0); nn_assert (rc == 6); nn_assert (memcmp (buf, "ABCDEF", 6) == 0); test_close (sc); test_close (sb); return 0; }
void device5 (NN_UNUSED void *arg) { int rc; int dev0; int dev1; /* Intialise the device sockets. */ dev0 = test_socket (AF_SP_RAW, NN_REP); test_bind (dev0, socket_address_h); dev1 = test_socket (AF_SP_RAW, NN_REQ); test_bind (dev1, socket_address_i); /* Run the device. */ rc = nn_device (dev0, dev1); nn_assert (rc < 0 && nn_errno () == ETERM); /* Clean up. */ test_close (dev0); test_close (dev1); }
void device1 (NN_UNUSED void *arg) { int rc; int deva; int devb; /* Intialise the device sockets. */ deva = test_socket (AF_SP_RAW, NN_PAIR); test_bind (deva, SOCKET_ADDRESS_A); devb = test_socket (AF_SP_RAW, NN_PAIR); test_bind (devb, SOCKET_ADDRESS_B); /* Run the device. */ rc = nn_device (deva, devb); nn_assert (rc < 0 && nn_errno () == ETERM); /* Clean up. */ test_close (devb); test_close (deva); }
void* tcp_server_handler(void* arg) { tcp_server_thread_info* pinfo = (tcp_server_thread_info *)arg; int printer_socket = tcp_connect_to_printer(pinfo->printer, pinfo->printer_port); fd_set sockets; timeval tv; int maxfd = pinfo->accepted_socket > printer_socket ? pinfo->accepted_socket : printer_socket; maxfd += 1; int running = 1; int total_bytes = 0; while (running) { FD_ZERO(&sockets); FD_SET(pinfo->accepted_socket, &sockets); FD_SET(printer_socket, &sockets); tv.tv_sec = 3; tv.tv_usec = 0; switch(select(maxfd, &sockets, NULL, NULL, &tv)) { case -1: printf("error in select.\n"); exit(1); case 0: printf("no data.\n"); break; default: int from = pinfo->accepted_socket; int to = printer_socket; if (FD_ISSET(printer_socket, &sockets)) { from = printer_socket; to = pinfo->accepted_socket; } int err = test_socket(from); if (err <= 0 and errno != EAGAIN) { printf("client socket closed.\n"); running = 0; break; } total_bytes += pass_data(from, to); } } printf("thread exit. passed %d bytes in this session.\n", total_bytes); close(printer_socket); delete pinfo; }
int main(int argc, char **argv) { test_file(); test_fork(); test_time(); test_socket(); // test_clone(); test_signal(); test_shm(); return 0; }
int main (NN_UNUSED int argc, const NN_UNUSED char *argv[]) { int sb; int sc1; int sc2; sb = test_socket (AF_SP, NN_PAIR); test_bind (sb, "inproc://pair"); sc1 = test_socket (AF_SP, NN_PAIR); test_connect (sc1, "inproc://pair"); sc2 = test_socket (AF_SP, NN_PAIR); test_connect (sc2, "inproc://pair"); test_send (sb, "HELLO"); test_recv (sc1, "HELLO"); test_send (sc1, "THERE"); test_recv (sb, "THERE"); return 0; }
int main () { int end0; int end1; struct nn_thread thread5; struct nn_thread thread6; /* Test the bi-directional device with REQ/REP (headers). */ /* Start the devices. */ nn_thread_init (&thread5, device5, NULL); nn_thread_init (&thread6, device6, NULL); /* Create two sockets to connect to the device. */ end0 = test_socket (AF_SP, NN_REQ); test_connect (end0, SOCKET_ADDRESS_H); end1 = test_socket (AF_SP, NN_REP); test_connect (end1, SOCKET_ADDRESS_J); /* Wait for TCP to establish. */ nn_sleep (1000); /* Pass a message between endpoints. */ test_send (end0, "XYZ"); test_recv (end1, "XYZ"); /* Now send a reply. */ test_send (end1, "REPLYXYZ"); test_recv (end0, "REPLYXYZ"); /* Clean up. */ test_close (end0); test_close (end1); /* Shut down the devices. */ nn_term (); nn_thread_term (&thread5); nn_thread_term (&thread6); return 0; }
int main () { struct nn_thread thread; sb = test_socket (AF_SP, NN_PAIR); test_bind (sb, SOCKET_ADDRESS); sc = test_socket (AF_SP, NN_PAIR); test_connect (sc, SOCKET_ADDRESS); nn_thread_init (&thread, worker, NULL); test_recv (sb, "ABC"); test_recv (sb, "ABC"); nn_thread_term (&thread); test_close (sc); test_close (sb); return 0; }
void device3(NN_UNUSED void *arg) { int rc; /* Intialise the device socket. */ deve = test_socket(AF_SP_RAW, NN_BUS); test_bind(deve, SOCKET_ADDRESS_E); /* Run the device. */ rc = nn_device(deve, -1); nn_assert(rc < 0 && nn_errno() == EBADF); }
END_TEST START_TEST(test_http_requests_on_same_socket) { guint i; gint err; gchar sid[32]; GString *buff = qev_buffer_get(); GString *msg = qev_buffer_get(); qev_fd_t s = test_socket(); _uuid(sid); // Opening handshake g_string_printf(buff, INIT_HEADERS, sid); err = send(s, buff->str, buff->len, 0); ck_assert_int_eq(err, buff->len); err = recv(s, buff->str, buff->allocated_len, 0); ck_assert(err > 0); g_string_set_size(buff, err); ck_assert(strstr(buff->str, "/qio/callback/1") != NULL); // First poll, sending nothing g_string_printf(buff, MSG_HEADERS, sid, msg->len, msg->str); err = send(s, buff->str, buff->len, 0); ck_assert_int_eq(err, buff->len); // Send a ping with an expected callback: the first request should bring // back the ping's callback g_string_assign(msg, "/qio/ping:2=null"); g_string_printf(buff, MSG_HEADERS, sid, msg->len, msg->str); err = send(s, buff->str, buff->len, 0); ck_assert_int_eq(err, buff->len); for (i = 0; i < 2; i++) { err = recv(s, buff->str, buff->allocated_len, 0); ck_assert(err > 0); g_string_set_size(buff, err); if (strstr(buff->str, "/qio/callback/2") != NULL) { break; } } ck_assert(strstr(buff->str, "/qio/callback/2") != NULL); qev_buffer_put(msg); qev_buffer_put(buff); close(s); }
int main () { int rc; int push; int pull1; int pull2; int sndprio; pull1 = test_socket (AF_SP, NN_PULL); test_bind (pull1, SOCKET_ADDRESS_A); pull2 = test_socket (AF_SP, NN_PULL); test_bind (pull2, SOCKET_ADDRESS_B); push = test_socket (AF_SP, NN_PUSH); sndprio = 1; rc = nn_setsockopt (push, NN_SOL_SOCKET, NN_SNDPRIO, &sndprio, sizeof (sndprio)); errno_assert (rc == 0); test_connect (push, SOCKET_ADDRESS_A); sndprio = 2; rc = nn_setsockopt (push, NN_SOL_SOCKET, NN_SNDPRIO, &sndprio, sizeof (sndprio)); errno_assert (rc == 0); test_connect (push, SOCKET_ADDRESS_B); test_send (push, "ABC"); test_send (push, "DEF"); test_recv (pull1, "ABC"); test_recv (pull1, "DEF"); test_close (pull1); test_close (push); test_close (pull2); /* Test removing a pipe from the list. */ push = test_socket (AF_SP, NN_PUSH); test_bind (push, SOCKET_ADDRESS_A); pull1 = test_socket (AF_SP, NN_PULL); test_connect (pull1, SOCKET_ADDRESS_A); test_send (push, "ABC"); test_recv (pull1, "ABC"); test_close (pull1); rc = nn_send (push, "ABC", 3, NN_DONTWAIT); nn_assert (rc == -1 && nn_errno() == EAGAIN); pull1 = test_socket (AF_SP, NN_PULL); test_connect (pull1, SOCKET_ADDRESS_A); test_send (push, "ABC"); test_recv (pull1, "ABC"); test_close (pull1); test_close (push); return 0; }