@@ -37,6 +37,9 @@ namespace
37
37
1100 ,1200 };
38
38
TCPSocket sock;
39
39
Semaphore tx_sem (0 , 1 );
40
+
41
+ Timer tc_exec_time;
42
+ int time_allotted;
40
43
}
41
44
42
45
static void _sigio_handler (osThreadId id) {
@@ -45,7 +48,10 @@ static void _sigio_handler(osThreadId id) {
45
48
46
49
void TCPSOCKET_ECHOTEST ()
47
50
{
48
- tcpsocket_connect_to_echo_srv (sock);
51
+ if (tcpsocket_connect_to_echo_srv (sock) != NSAPI_ERROR_OK) {
52
+ TEST_FAIL ();
53
+ return ;
54
+ }
49
55
50
56
int recvd;
51
57
int sent;
@@ -57,6 +63,8 @@ void TCPSOCKET_ECHOTEST()
57
63
if (sent < 0 ) {
58
64
printf (" [Round#%02d] network error %d\n " , x, sent);
59
65
TEST_FAIL ();
66
+ TEST_ASSERT_EQUAL (NSAPI_ERROR_OK, sock.close ());
67
+ return ;
60
68
}
61
69
62
70
int bytes2recv = sent;
@@ -65,6 +73,8 @@ void TCPSOCKET_ECHOTEST()
65
73
if (recvd < 0 ) {
66
74
printf (" [Round#%02d] network error %d\n " , x, recvd);
67
75
TEST_FAIL ();
76
+ TEST_ASSERT_EQUAL (NSAPI_ERROR_OK, sock.close ());
77
+ return ;
68
78
}
69
79
bytes2recv -= recvd;
70
80
}
@@ -80,10 +90,15 @@ void tcpsocket_echotest_nonblock_receiver(void *receive_bytes)
80
90
while (bytes2recv) {
81
91
recvd = sock.recv (&(tcp_global::rx_buffer[*(int *)receive_bytes-bytes2recv]), bytes2recv);
82
92
if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
93
+ if (tc_exec_time.read () >= time_allotted) {
94
+ TEST_FAIL ();
95
+ break ;
96
+ }
83
97
wait (1 );
84
98
continue ;
85
99
} else if (recvd < 0 ) {
86
100
TEST_FAIL ();
101
+ break ;
87
102
}
88
103
bytes2recv -= recvd;
89
104
}
@@ -99,6 +114,9 @@ void tcpsocket_echotest_nonblock_receiver(void *receive_bytes)
99
114
100
115
void TCPSOCKET_ECHOTEST_NONBLOCK ()
101
116
{
117
+ tc_exec_time.start ();
118
+ time_allotted = split2half_rmng_tcp_test_time (); // [s]
119
+
102
120
tcpsocket_connect_to_echo_srv (sock);
103
121
sock.set_blocking (false );
104
122
sock.sigio (callback (_sigio_handler, Thread::gettid ()));
@@ -124,19 +142,30 @@ void TCPSOCKET_ECHOTEST_NONBLOCK()
124
142
while (bytes2send > 0 ) {
125
143
sent = sock.send (&(tcp_global::tx_buffer[pkt_s-bytes2send]), bytes2send);
126
144
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
+ }
128
152
continue ;
129
153
} else if (sent <= 0 ) {
130
154
printf (" [Sender#%02d] network error %d\n " , s_idx, sent);
155
+ thread->terminate ();
156
+ delete thread;
131
157
TEST_FAIL ();
158
+ goto END;
132
159
}
133
160
bytes2send -= sent;
134
161
}
135
162
printf (" [Sender#%02d] bytes sent: %d\n " , s_idx, pkt_s);
136
- tx_sem.wait ();
163
+ tx_sem.wait (split2half_rmng_tcp_test_time () );
137
164
thread->join ();
138
165
delete thread;
139
166
}
167
+ END:
168
+ tc_exec_time.stop ();
140
169
free (stack_mem);
141
170
TEST_ASSERT_EQUAL (NSAPI_ERROR_OK, sock.close ());
142
171
}
0 commit comments