@@ -37,6 +37,9 @@ namespace
3737 1100 ,1200 };
3838 TCPSocket sock;
3939 Semaphore tx_sem (0 , 1 );
40+
41+ Timer tc_exec_time;
42+ int time_allotted;
4043}
4144
4245static void _sigio_handler (osThreadId id) {
@@ -45,7 +48,10 @@ static void _sigio_handler(osThreadId id) {
4548
4649void TCPSOCKET_ECHOTEST ()
4750{
48- tcpsocket_connect_to_echo_srv (sock);
51+ if (tcpsocket_connect_to_echo_srv (sock) != NSAPI_ERROR_OK) {
52+ TEST_FAIL ();
53+ return ;
54+ }
4955
5056 int recvd;
5157 int sent;
@@ -57,6 +63,8 @@ void TCPSOCKET_ECHOTEST()
5763 if (sent < 0 ) {
5864 printf (" [Round#%02d] network error %d\n " , x, sent);
5965 TEST_FAIL ();
66+ TEST_ASSERT_EQUAL (NSAPI_ERROR_OK, sock.close ());
67+ return ;
6068 }
6169
6270 int bytes2recv = sent;
@@ -65,6 +73,8 @@ void TCPSOCKET_ECHOTEST()
6573 if (recvd < 0 ) {
6674 printf (" [Round#%02d] network error %d\n " , x, recvd);
6775 TEST_FAIL ();
76+ TEST_ASSERT_EQUAL (NSAPI_ERROR_OK, sock.close ());
77+ return ;
6878 }
6979 bytes2recv -= recvd;
7080 }
@@ -80,10 +90,15 @@ void tcpsocket_echotest_nonblock_receiver(void *receive_bytes)
8090 while (bytes2recv) {
8191 recvd = sock.recv (&(tcp_global::rx_buffer[*(int *)receive_bytes-bytes2recv]), bytes2recv);
8292 if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
93+ if (tc_exec_time.read () >= time_allotted) {
94+ TEST_FAIL ();
95+ break ;
96+ }
8397 wait (1 );
8498 continue ;
8599 } else if (recvd < 0 ) {
86100 TEST_FAIL ();
101+ break ;
87102 }
88103 bytes2recv -= recvd;
89104 }
@@ -99,6 +114,9 @@ void tcpsocket_echotest_nonblock_receiver(void *receive_bytes)
99114
100115void TCPSOCKET_ECHOTEST_NONBLOCK ()
101116{
117+ tc_exec_time.start ();
118+ time_allotted = split2half_rmng_tcp_test_time (); // [s]
119+
102120 tcpsocket_connect_to_echo_srv (sock);
103121 sock.set_blocking (false );
104122 sock.sigio (callback (_sigio_handler, Thread::gettid ()));
@@ -124,19 +142,30 @@ void TCPSOCKET_ECHOTEST_NONBLOCK()
124142 while (bytes2send > 0 ) {
125143 sent = sock.send (&(tcp_global::tx_buffer[pkt_s-bytes2send]), bytes2send);
126144 if (sent == NSAPI_ERROR_WOULD_BLOCK) {
127- TEST_ASSERT_NOT_EQUAL (osEventTimeout, osSignalWait (SIGNAL_SIGIO, SIGIO_TIMEOUT).status );
145+ if (tc_exec_time.read () >= time_allotted ||
146+ osSignalWait (SIGNAL_SIGIO, SIGIO_TIMEOUT).status == osEventTimeout) {
147+ thread->terminate ();
148+ delete thread;
149+ TEST_FAIL ();
150+ goto END;
151+ }
128152 continue ;
129153 } else if (sent <= 0 ) {
130154 printf (" [Sender#%02d] network error %d\n " , s_idx, sent);
155+ thread->terminate ();
156+ delete thread;
131157 TEST_FAIL ();
158+ goto END;
132159 }
133160 bytes2send -= sent;
134161 }
135162 printf (" [Sender#%02d] bytes sent: %d\n " , s_idx, pkt_s);
136- tx_sem.wait ();
163+ tx_sem.wait (split2half_rmng_tcp_test_time () );
137164 thread->join ();
138165 delete thread;
139166 }
167+ END:
168+ tc_exec_time.stop ();
140169 free (stack_mem);
141170 TEST_ASSERT_EQUAL (NSAPI_ERROR_OK, sock.close ());
142171}
0 commit comments