void *pthread_entry2( void *arg) { #ifdef TEST_NET int fd; int netstate = 0; #endif #ifdef TEST_DEV int ser1; int serstate = 0; #endif #if defined(TEST_DEV) || defined(TEST_NET) int i; ssize_t done; #endif int netdone = 0; int serdone = 0; int err; fd_set rd, wr; CYG_TEST_INFO( "Thread 2 running" ); FD_ZERO( &rd ); FD_ZERO( &wr ); #ifdef TEST_NET CYG_TEST_INFO( "Thread2: calling socket()"); fd = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); if( fd < 0 ) SHOW_RESULT( socket, fd ); CYG_TEST_CHECK( fd >= 0, "socket() returned error"); CYG_TEST_INFO( "Thread2: calling connect()"); err = connect( fd, (struct sockaddr *)&sa, sizeof(sa)); if( err < 0 ) SHOW_RESULT( connect, err ); CYG_TEST_CHECK( err == 0, "connect() returned error"); FD_SET( fd, &rd ); #else netdone = 1; #endif #ifdef TEST_DEV for( i = 0; i < TEST_BUFSIZE; i++ ) sbuf1[i] = i; CYG_TEST_INFO( "Thread2: calling open(/dev/ser1)"); ser1 = open("/dev/ser1", O_RDWR ); if( ser1 < 0 ) SHOW_RESULT( open, ser1 ); CYG_TEST_CHECK( ser1 >= 0, "open(/dev/ser1) returned error"); CYG_TEST_INFO( "Thread2: calling write(ser1)"); done = write( ser1, sbuf1, TEST_BUFSIZE); if( done != TEST_BUFSIZE ) SHOW_RESULT( write, done ); CYG_TEST_CHECK( done == TEST_BUFSIZE, "write() returned bad size"); FD_SET( ser1, &wr ); #else serdone = 1; #endif while(!(netdone && serdone)) { fd_set rd_res = rd; fd_set wr_res = wr; CYG_TEST_INFO( "Thread2: calling select()"); show_fdsets( "Thread2 request: ", 8, &rd_res, &wr_res, NULL ); err = select( 8, &rd_res, &wr_res, NULL, NULL ); if( err < 0 ) SHOW_RESULT( select, err ); CYG_TEST_CHECK( err >= 0, "select() returned error"); show_fdsets( "Thread2 result: ", 8, &rd_res, &wr_res, NULL ); #ifdef TEST_NET switch( netstate ) { case 0: CYG_TEST_INFO( "Thread2: netstate 0"); if( FD_ISSET( fd, &rd_res ) ) { CYG_TEST_INFO( "Thread2: calling read()"); done = read( fd, buf2, TEST_BUFSIZE); if( done != TEST_BUFSIZE ) SHOW_RESULT( read, done ); CYG_TEST_CHECK( done == TEST_BUFSIZE, "read() returned bad size"); for( i = 0; i < TEST_BUFSIZE; i++ ) if( buf1[i] != buf2[i] ) diag_printf("buf1[%d](%02x) != buf2[%d](%02x)\n",i,buf1[i],i,buf2[i]); netstate++; FD_CLR( fd, &rd ); FD_SET( fd, &wr ); } break; case 1: CYG_TEST_INFO( "Thread2: netstate 1"); if( FD_ISSET( fd, &wr_res ) ) { CYG_TEST_INFO( "Thread2: calling write()"); done = write( fd, buf2, TEST_BUFSIZE); if( done != TEST_BUFSIZE ) SHOW_RESULT( write, done ); CYG_TEST_CHECK( done == TEST_BUFSIZE, "write() returned bad size"); FD_CLR( fd, &wr ); netstate++; netdone = 1; CYG_TEST_INFO( "Thread2: netdone"); } break; } #endif #ifdef TEST_DEV switch( serstate ) { case 0: CYG_TEST_INFO( "Thread2: serstate 0"); if( FD_ISSET( ser1, &wr_res ) ) { FD_CLR( ser1, &wr ); FD_SET( ser1, &rd ); serstate++; } break; case 1: CYG_TEST_INFO( "Thread2: serstate 1"); if( FD_ISSET( ser1, &rd_res ) ) { CYG_TEST_INFO( "Thread2: calling read(ser1)"); done = read( ser1, sbuf3, TEST_BUFSIZE); if( done != TEST_BUFSIZE ) SHOW_RESULT( read, done ); CYG_TEST_CHECK( done == TEST_BUFSIZE, "read() returned bad size"); for( i = 0; i < TEST_BUFSIZE; i++ ) if( sbuf1[i] != sbuf3[i] ) diag_printf("sbuf1[%d](%02x) != sbuf3[%d](%02x)\n",i,sbuf1[i],i,sbuf3[i]); FD_CLR( ser1, &rd ); serstate++; serdone = 1; CYG_TEST_INFO( "Thread2: serdone"); } break; } #endif } #ifdef TEST_NET CYG_TEST_INFO( "Thread2: calling close(fd)"); err = close(fd); if( err < 0 ) SHOW_RESULT( close, err ); CYG_TEST_CHECK( err == 0, "close() returned error"); #endif #ifdef TEST_DEV CYG_TEST_INFO( "Thread2: calling close(ser1)"); err = close(ser1); if( err < 0 ) SHOW_RESULT( close, err ); CYG_TEST_CHECK( err == 0, "close(ser1) returned error"); #endif CYG_TEST_INFO( "Thread2: calling pthread_exit()"); pthread_exit( arg ); }
void *pthread_entry1( void *arg) { int fd = 0; int err; fd_set rd, wr; sigset_t mask, oldmask; struct sigaction sigact; struct timespec ts; CYG_TEST_INFO( "Thread 1 running" ); FD_ZERO( &rd ); FD_ZERO( &wr ); sigfillset( &mask ); pthread_sigmask( SIG_SETMASK, &mask, &oldmask ); sigdelset( &mask, SIGUSR1 ); sigact.sa_mask = mask; sigact.sa_flags = SA_SIGINFO; sigact.sa_sigaction = sigusr1; err = sigaction( SIGUSR1, &sigact, NULL ); if( err < 0 ) SHOW_RESULT( sigact, err ); CYG_TEST_INFO( "Thread1: calling socket()"); fd = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); if( fd < 0 ) SHOW_RESULT( socket, fd ); CYG_TEST_CHECK( fd >= 0, "socket() returned error"); CYG_TEST_INFO( "Thread1: calling bind()"); err = bind( fd, (struct sockaddr *)&sa, sizeof(sa)); if( err < 0 ) SHOW_RESULT( bind, err ); CYG_TEST_CHECK( err == 0, "bind() returned error"); CYG_TEST_INFO( "Thread1: calling listen()"); err = listen( fd, 3); if( err < 0 ) SHOW_RESULT( listen, err ); CYG_TEST_CHECK( err == 0, "listen() returned error"); FD_SET( fd, &rd ); ts.tv_sec = 0; ts.tv_nsec = 0; while( running ) { fd_set rd_res = rd; fd_set wr_res = wr; // ts.tv_nsec = 1000000 * (pselect_wakeups % 10); err = pselect( 8, &rd_res, &wr_res, NULL, &ts, &mask ); if( err < 0 ) { if( errno == EINTR ) pselect_eintr++; else SHOW_RESULT( pselect, err ); } if( err > 0 ) show_fdsets( "Thread1 result: ", 8, &rd_res, &wr_res, NULL ); pselect_wakeups++; } // If we were interrupted at just the wrong point above we may still // have a SIGUSR1 signal pending that we didn't handle, and so won't // have accounted for. So let's look... CYG_TEST_CHECK( 0 == sigpending( &mask ), "sigpending() returned error"); if (1 == sigismember(&mask, SIGUSR1) ) pselect_eintr++; pthread_sigmask( SIG_SETMASK, &oldmask, NULL ); pthread_exit(arg); }
void *pthread_entry1( void *arg) { #ifdef TEST_NET int fd = 0, fd2 = -1; struct sockaddr_in accsa; socklen_t accsa_len = sizeof(accsa); int netstate = 0; #endif #ifdef TEST_DEV int ser0; int serstate = 0; #endif #if defined(TEST_DEV) || defined(TEST_NET) int i; ssize_t done; #endif int netdone = 0; int serdone = 0; int err; fd_set rd, wr; CYG_TEST_INFO( "Thread 1 running" ); FD_ZERO( &rd ); FD_ZERO( &wr ); #ifdef TEST_DEV CYG_TEST_INFO( "Thread1: calling open()"); ser0 = open("/dev/ser0", O_RDWR ); if( ser0 < 0 ) SHOW_RESULT( open, ser0 ); CYG_TEST_CHECK( ser0 >= 0, "open(/dev/ser0) returned error"); FD_SET( ser0, &rd ); #else serdone = 1; #endif #ifdef TEST_NET for( i = 0; i < TEST_BUFSIZE; i++ ) buf1[i] = i; CYG_TEST_INFO( "Thread1: calling socket()"); fd = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); if( fd < 0 ) SHOW_RESULT( socket, fd ); CYG_TEST_CHECK( fd >= 0, "socket() returned error"); CYG_TEST_INFO( "Thread1: calling bind()"); err = bind( fd, (struct sockaddr *)&sa, sizeof(sa)); if( err < 0 ) SHOW_RESULT( bind, err ); CYG_TEST_CHECK( err == 0, "bind() returned error"); CYG_TEST_INFO( "Thread1: calling listen()"); err = listen( fd, 3); if( err < 0 ) SHOW_RESULT( listen, err ); CYG_TEST_CHECK( err == 0, "listen() returned error"); FD_SET( fd, &rd ); #else netdone = 1; #endif while(!(netdone && serdone)) { fd_set rd_res = rd; fd_set wr_res = wr; CYG_TEST_INFO( "Thread1: calling select()"); show_fdsets( "Thread1 request: ", 8, &rd_res, &wr_res, NULL ); err = select( 8, &rd_res, &wr_res, NULL, NULL ); if( err < 0 ) SHOW_RESULT( select, err ); CYG_TEST_CHECK( err >= 0, "select() returned error"); show_fdsets( "Thread1 result: ", 8, &rd_res, &wr_res, NULL ); #ifdef TEST_NET switch( netstate ) { case 0: CYG_TEST_INFO( "Thread1: netstate 0"); if( FD_ISSET( fd, &rd_res ) ) { CYG_TEST_INFO( "Thread1: calling accept(fd)"); fd2 = accept( fd, (struct sockaddr *)&accsa, &accsa_len ); if( fd2 < 0 ) SHOW_RESULT( accept, fd2 ); CYG_TEST_CHECK( fd2 >= 0, "accept() returned error"); FD_CLR( fd, &rd ); FD_SET( fd2, &wr ); netstate++; } break; case 1: CYG_TEST_INFO( "Thread1: netstate 1"); if( FD_ISSET( fd2, &wr_res ) ) { CYG_TEST_INFO( "Thread1: calling write(fd2)"); done = write( fd2, buf1, TEST_BUFSIZE); if( done != TEST_BUFSIZE ) SHOW_RESULT( write, done ); CYG_TEST_CHECK( done == TEST_BUFSIZE, "write() returned bad size"); FD_CLR( fd2, &wr ); FD_SET( fd2, &rd ); netstate++; } break; case 2: CYG_TEST_INFO( "Thread1: netstate 2"); if( FD_ISSET( fd2, &rd_res ) ) { CYG_TEST_INFO( "Thread1: calling read(fd2)"); done = read( fd2, buf3, TEST_BUFSIZE); if( done != TEST_BUFSIZE ) SHOW_RESULT( read, done ); CYG_TEST_CHECK( done == TEST_BUFSIZE, "read() returned bad size"); for( i = 0; i < TEST_BUFSIZE; i++ ) if( buf1[i] != buf3[i] ) diag_printf("buf1[%d](%02x) != buf3[%d](%02x)\n",i,buf1[i],i,buf3[i]); FD_CLR( fd2, &rd ); netstate++; netdone = 1; CYG_TEST_INFO( "Thread1: netdone"); } break; } #endif #ifdef TEST_DEV switch( serstate ) { case 0: CYG_TEST_INFO( "Thread1: serstate 0"); if( FD_ISSET( ser0, &rd_res ) ) { CYG_TEST_INFO( "Thread1: calling read(ser0)"); done = read( ser0, sbuf2, TEST_BUFSIZE); if( done != TEST_BUFSIZE ) SHOW_RESULT( read, done ); CYG_TEST_CHECK( done == TEST_BUFSIZE, "read() returned bad size"); for( i = 0; i < TEST_BUFSIZE; i++ ) if( sbuf1[i] != sbuf2[i] ) diag_printf("buf1[%d](%02x) != buf2[%d](%02x)\n",i,sbuf1[i],i,sbuf2[i]); FD_CLR( ser0, &rd ); FD_SET( ser0, &wr ); serstate++; } break; case 1: CYG_TEST_INFO( "Thread1: serstate 1"); if( FD_ISSET( ser0, &wr_res ) ) { CYG_TEST_INFO( "Thread1: calling write(ser0)"); done = write( ser0, sbuf2, TEST_BUFSIZE); if( done != TEST_BUFSIZE ) SHOW_RESULT( write, done ); CYG_TEST_CHECK( done == TEST_BUFSIZE, "write() returned bad size"); FD_CLR( ser0, &wr ); serstate++; serdone = 1; CYG_TEST_INFO( "Thread1: serdone"); } else FD_SET( ser0, &wr ); break; } #endif } #ifdef TEST_NET CYG_TEST_INFO( "Thread1: calling close(fd)"); err = close(fd); if( err < 0 ) SHOW_RESULT( close, err ); CYG_TEST_CHECK( err == 0, "close() returned error"); if( fd2 >= 0 ) { CYG_TEST_INFO( "Thread1: calling close(fd2)"); err = close(fd2); if( err < 0 ) SHOW_RESULT( close, err ); CYG_TEST_CHECK( err == 0, "close() returned error"); } #endif #ifdef TEST_DEV CYG_TEST_INFO( "Thread1: calling close(ser0)"); err = close(ser0); if( err < 0 ) SHOW_RESULT( close, err ); CYG_TEST_CHECK( err == 0, "close() returned error"); #endif CYG_TEST_INFO( "Thread1: calling pthread_exit()"); pthread_exit( arg ); }