@@ -175,10 +175,88 @@ void test_poll(void)
175175 zassert_equal (res , 0 , "close failed" );
176176}
177177
178+ #define TEST_SNDBUF_SIZE CONFIG_NET_TCP_MAX_RECV_WINDOW_SIZE
179+
180+ static void test_pollout_tcp (void )
181+ {
182+ int res ;
183+ int c_sock ;
184+ int s_sock ;
185+ int new_sock ;
186+ struct sockaddr_in6 c_addr ;
187+ struct sockaddr_in6 s_addr ;
188+ struct pollfd pollout [1 ];
189+ char buf [TEST_SNDBUF_SIZE ] = { };
190+
191+ prepare_sock_tcp_v6 (CONFIG_NET_CONFIG_MY_IPV6_ADDR , CLIENT_PORT ,
192+ & c_sock , & c_addr );
193+ prepare_sock_tcp_v6 (CONFIG_NET_CONFIG_MY_IPV6_ADDR , SERVER_PORT ,
194+ & s_sock , & s_addr );
195+
196+ res = bind (s_sock , (struct sockaddr * )& s_addr , sizeof (s_addr ));
197+ zassert_equal (res , 0 , "" );
198+ res = listen (s_sock , 0 );
199+ zassert_equal (res , 0 , "" );
200+ res = connect (c_sock , (const struct sockaddr * )& s_addr ,
201+ sizeof (s_addr ));
202+ zassert_equal (res , 0 , "" );
203+ new_sock = accept (s_sock , NULL , NULL );
204+ zassert_true (new_sock >= 0 , "" );
205+
206+ k_msleep (10 );
207+
208+ /* POLLOUT should be reported after connecting */
209+ memset (pollout , 0 , sizeof (pollout ));
210+ pollout [0 ].fd = c_sock ;
211+ pollout [0 ].events = POLLOUT ;
212+
213+ res = poll (pollout , ARRAY_SIZE (pollout ), 10 );
214+ zassert_equal (res , 1 , "" );
215+ zassert_equal (pollout [0 ].revents , POLLOUT , "" );
216+
217+ /* POLLOUT should not be reported after filling the window */
218+ res = send (c_sock , buf , sizeof (buf ), 0 );
219+ zassert_equal (res , sizeof (buf ), "" );
220+
221+ memset (pollout , 0 , sizeof (pollout ));
222+ pollout [0 ].fd = c_sock ;
223+ pollout [0 ].events = POLLOUT ;
224+
225+ res = poll (pollout , ARRAY_SIZE (pollout ), 10 );
226+ zassert_equal (res , 0 , "%d" , pollout [0 ].revents );
227+ zassert_equal (pollout [0 ].revents , 0 , "" );
228+
229+ /* POLLOUT should be reported again after consuming the data server
230+ * side.
231+ */
232+ res = recv (new_sock , buf , sizeof (buf ), 0 );
233+ zassert_equal (res , sizeof (buf ), "" );
234+
235+ memset (pollout , 0 , sizeof (pollout ));
236+ pollout [0 ].fd = c_sock ;
237+ pollout [0 ].events = POLLOUT ;
238+
239+ /* Wait longer this time to give TCP stack a chance to send ZWP. */
240+ res = poll (pollout , ARRAY_SIZE (pollout ), 500 );
241+ zassert_equal (res , 1 , "" );
242+ zassert_equal (pollout [0 ].revents , POLLOUT , "" );
243+
244+ k_msleep (10 );
245+
246+ /* Finalize the test */
247+ res = close (c_sock );
248+ zassert_equal (res , 0 , "close failed" );
249+ res = close (s_sock );
250+ zassert_equal (res , 0 , "close failed" );
251+ res = close (new_sock );
252+ zassert_equal (res , 0 , "close failed" );
253+ }
254+
178255void test_main (void )
179256{
180257 ztest_test_suite (socket_poll ,
181- ztest_unit_test (test_poll ));
258+ ztest_unit_test (test_poll ),
259+ ztest_unit_test (test_pollout_tcp ));
182260
183261 ztest_run_test_suite (socket_poll );
184262}
0 commit comments