void test_tcp () { // send 1000 msg on hwm 1000, receive 1000, on TCP transport TEST_ASSERT_EQUAL_INT (1000, test_defaults (1000, 1000, "tcp://127.0.0.1:*")); // send 100 msg on hwm 100, receive 100 TEST_ASSERT_EQUAL_INT (100, test_defaults (100, 100, "tcp://127.0.0.1:*")); // send 6000 msg on hwm 2000, drops above hwm, only receive hwm: TEST_ASSERT_EQUAL_INT (6000, test_blocking (2000, 6000, "tcp://127.0.0.1:*")); }
int main (void) { setup_test_environment(); int count; // send 1000 msg on hwm 1000, receive 1000 count = test_defaults (1000,1000); assert (count == 1000); // send 6000 msg on hwm 2000, drops above hwm, only receive hwm count = test_blocking (2000,6000); assert (count == 6000); return 0; }
int main (void) { setup_test_environment(); int count; // send 1000 msg on hwm 1000, receive 1000 count = test_defaults (1000,1000); assert (count == 1000); // send 6000 msg on hwm 2000, drops above hwm, only receive hwm count = test_blocking (2000,6000); assert (count == 6000); // hwm should apply to the messages that have already been received test_reset_hwm (); return 0; }
void test_blocking_2000 () { // send 6000 msg on hwm 2000, drops above hwm, only receive hwm TEST_ASSERT_EQUAL_INT (6000, test_blocking (2000, 6000)); }
void test_ipc () { TEST_ASSERT_EQUAL_INT (1000, test_defaults (1000, 1000, "ipc://*")); TEST_ASSERT_EQUAL_INT (100, test_defaults (100, 100, "ipc://*")); TEST_ASSERT_EQUAL_INT (6000, test_blocking (2000, 6000, "ipc://*")); }
void test_inproc () { TEST_ASSERT_EQUAL_INT (1000, test_defaults (1000, 1000, "inproc://a")); TEST_ASSERT_EQUAL_INT (100, test_defaults (100, 100, "inproc://b")); TEST_ASSERT_EQUAL_INT (6000, test_blocking (2000, 6000, "inproc://c")); }
int main(int argc, char **argv) { int mfd,sfd; int status; struct termios t; char buffer[80]; char *tomaster = "2MASTER\n"; char *toslave = "2SLAVE\n"; char name[16]; char *ttynam; struct stat sb; if (openpty(&mfd,&sfd,name,0,0) < 0) { printf("out of ptys\n"); return -1; } printf("opened: %s\n",name); master = mfd; slave = sfd; printf("testing ttyname\n"); if (ttynam = ttyname(master)) { name[5] = 'p'; printf("opened pty: %s, ttyname returned on master %s\n", name,ttynam); if (!strcmp(name,ttynam)) printf("Ok\n"); else printf("Failed ttyname for master\n"); if (!stat(name,&sb)) { print_statbuf(name,&sb); } else { printf("could not do stat on %s errno: %d\n",name,errno); } } else { printf("could not do ttyname on master fd\n"); } if (ttynam = ttyname(slave)) { name[5] = 't'; printf("opened pty: %s, ttyname returned on slave %s\n", name,ttynam); if (!strcmp(name,ttynam)) printf("Ok\n"); else printf("Failed ttyname for slave\n"); if (!stat(name,&sb)) { print_statbuf(name,&sb); } else { printf("could not do stat on %s errno: %d\n",name,errno); } } else { printf("could not do ttyname on slave fd\n"); } probefd(); if (test_select() == 0) {printf("test_select ok\n");} #if 0 return 0; test_nonblocking(); test_blocking(); test_raw(); #endif if (fork() != 0) { printf("going to read slave\n"); if ((status = read(sfd,buffer,76)) > 0) { buffer[status] = 0; printf("0read slave: \"%s\"\n",buffer); } else { printf("0read slave returned: %d, errno: %d\n",status,errno); } } else { printf("parent should be blocking for 3 seconds\n"); sleep (3); printf("writing data...\n"); write(mfd,"wakeup\n",7); printf("wrote data\n"); exit(0); } #if 1 printf("setting master and slave nonblocking\n"); fcntl(mfd,F_SETFL,O_NONBLOCK); fcntl(sfd,F_SETFL,O_NONBLOCK); #endif #if 0 assert(tcgetattr(sfd,&t) == 0); t.c_lflag &= ~(ICANON); /* make it raw */ t.c_cc[VMIN] = 10; t.c_cc[VTIME] = 2; (void) tcsetattr(sfd, TCSAFLUSH, &t); #endif assert(tcgetattr(mfd,&t) == 0); assert(tcgetattr(sfd,&t) == 0); printf("echo: %d echonl: %d\n", t.c_lflag & ECHO,t.c_lflag & ECHONL); #if 0 return (doshell(mfd,sfd)); #endif probefd(); if ((status = read(mfd,buffer,80)) > 0) { buffer[status] = 0; printf("1read master (echo on): \"%s\"\n",buffer); } else { printf("1read master returned: %d, errno: %d\n",status,errno); } if ((status = read(sfd,buffer,80)) > 0) { buffer[status] = 0; printf("2read slave (echo on): \"%s\"\n",buffer); } else { printf("2read slave returned: %d, errno: %d\n",status,errno); } if (fork() == 0) { /* child */ write(mfd,tomaster,strlen(tomaster)); exit(0); } sleep(2); write(sfd,toslave,strlen(toslave)); if ((status = read(mfd,buffer,80)) > 0) { buffer[status] = 0; printf("3read master (echo on): \"%s\"\n",buffer); } else { printf("3read master returned: %d, errno: %d\n",status,errno); } if ((status = read(sfd,buffer,80)) > 0) { buffer[status] = 0; printf("4read slave (echo on): \"%s\"\n",buffer); } else { printf("4read slave returned: %d, errno: %d\n",status,errno); } assert(tcgetattr(mfd,&t) == 0); assert(tcgetattr(sfd,&t) == 0); t.c_lflag &= ~(ECHO); t.c_lflag |= ECHONL; (void) tcsetattr(sfd, TCSANOW, &t); printf("echo: %d echonl: %d\n", t.c_lflag & ECHO,t.c_lflag & ECHONL); write(mfd,tomaster,strlen(tomaster)); write(sfd,toslave,strlen(toslave)); probefd(); if ((status = read(mfd,buffer,80)) > 0) { buffer[status] = 0; printf("5read master (echo off): \"%s\"\n",buffer); } else { printf("5read master returned: %d\n",status); } probefd(); if ((status = read(sfd,buffer,80)) > 0) { buffer[status] = 0; printf("6read slave: \"%s\"\n",buffer); } else { printf("6read slave returned: %d\n",status); } probefd(); (void) close(sfd); (void) close(mfd); return 0; }