@@ -237,51 +237,6 @@ static void test_recv_fail(int sock, void *buf, size_t max_len, int flags)
237
237
zassert_equal (errno , EAGAIN , "recvfrom() returned unexpected errno (%d)" , errno );
238
238
}
239
239
240
- static void calc_net_context (struct net_context * context , void * user_data )
241
- {
242
- int * count = user_data ;
243
-
244
- (* count )++ ;
245
- }
246
-
247
- /* Wait until the number of TCP contexts reaches a certain level
248
- * exp_num_contexts : The number of contexts to wait for
249
- * timeout : The time to wait for
250
- */
251
- int wait_for_n_tcp_contexts (int exp_num_contexts , k_timeout_t timeout )
252
- {
253
- uint32_t start_time = k_uptime_get_32 ();
254
- uint32_t time_diff ;
255
- int context_count = 0 ;
256
-
257
- /* After the client socket closing, the context count should be 1 less */
258
- net_context_foreach (calc_net_context , & context_count );
259
-
260
- time_diff = k_uptime_get_32 () - start_time ;
261
-
262
- /* Eventually the client socket should be cleaned up */
263
- while (context_count != exp_num_contexts ) {
264
- context_count = 0 ;
265
- net_context_foreach (calc_net_context , & context_count );
266
- k_sleep (K_MSEC (50 ));
267
- time_diff = k_uptime_get_32 () - start_time ;
268
-
269
- if (K_MSEC (time_diff ).ticks > timeout .ticks ) {
270
- return - ETIMEDOUT ;
271
- }
272
- }
273
-
274
- return 0 ;
275
- }
276
-
277
- static void test_context_cleanup (void )
278
- {
279
- zassert_equal (wait_for_n_tcp_contexts (0 , TCP_TEARDOWN_TIMEOUT ),
280
- 0 ,
281
- "Not all TCP contexts properly cleaned up" );
282
- }
283
-
284
-
285
240
ZTEST_USER (socket_reuseaddr_test_suite , test_enable_disable )
286
241
{
287
242
int server_sock = -1 ;
@@ -321,8 +276,6 @@ ZTEST_USER(socket_reuseaddr_test_suite, test_enable_disable)
321
276
zassert_equal (value , (int ) true, "SO_REUSEADDR not correctly set, returned %d" , value );
322
277
323
278
close (server_sock );
324
-
325
- test_context_cleanup ();
326
279
}
327
280
328
281
@@ -359,8 +312,6 @@ static void test_reuseaddr_unspecified_specified_common(sa_family_t family,
359
312
360
313
close (server_sock1 );
361
314
close (server_sock2 );
362
-
363
- test_context_cleanup ();
364
315
}
365
316
366
317
ZTEST_USER (socket_reuseaddr_test_suite , test_ipv4_first_unspecified )
@@ -440,8 +391,6 @@ static void test_reuseaddr_tcp_listening_common(sa_family_t family,
440
391
441
392
close (server_sock1 );
442
393
close (server_sock2 );
443
-
444
- test_context_cleanup ();
445
394
}
446
395
447
396
ZTEST_USER (socket_reuseaddr_test_suite , test_ipv4_tcp_unspecified_listening )
@@ -526,7 +475,10 @@ static void test_reuseaddr_tcp_tcp_time_wait_common(sa_family_t family,
526
475
close (client_sock );
527
476
close (server_sock );
528
477
529
- test_context_cleanup ();
478
+ /* Connection is in TIME_WAIT state, context will be released
479
+ * after K_MSEC(CONFIG_NET_TCP_TIME_WAIT_DELAY), so wait for it.
480
+ */
481
+ k_sleep (K_MSEC (CONFIG_NET_TCP_TIME_WAIT_DELAY ));
530
482
}
531
483
532
484
ZTEST_USER (socket_reuseaddr_test_suite , test_ipv4_tcp_time_wait_unspecified )
@@ -601,8 +553,6 @@ ZTEST_USER(socket_reuseport_test_suite, test_enable_disable)
601
553
zassert_equal (value , (int ) true, "SO_REUSEPORT not correctly set, returned %d" , value );
602
554
603
555
close (server_sock );
604
-
605
- test_context_cleanup ();
606
556
}
607
557
608
558
@@ -644,8 +594,6 @@ static void test_reuseport_unspecified_specified_common(sa_family_t family,
644
594
645
595
close (server_sock1 );
646
596
close (server_sock2 );
647
-
648
- test_context_cleanup ();
649
597
}
650
598
651
599
ZTEST_USER (socket_reuseport_test_suite , test_ipv4_both_unspecified_bad )
@@ -879,8 +827,6 @@ static void test_reuseport_udp_server_client_common(sa_family_t family,
879
827
close (accept_sock );
880
828
close (client_sock );
881
829
close (server_sock );
882
-
883
- test_context_cleanup ();
884
830
}
885
831
886
832
ZTEST_USER (socket_reuseport_test_suite , test_ipv4_udp_bad_both_not_set )
@@ -990,7 +936,10 @@ static void test_reuseport_tcp_identical_clients_common(sa_family_t family,
990
936
close (client_sock2 );
991
937
close (server_sock );
992
938
993
- test_context_cleanup ();
939
+ /* Connection is in TIME_WAIT state, context will be released
940
+ * after K_MSEC(CONFIG_NET_TCP_TIME_WAIT_DELAY), so wait for it.
941
+ */
942
+ k_sleep (K_MSEC (CONFIG_NET_TCP_TIME_WAIT_DELAY ));
994
943
}
995
944
996
945
ZTEST_USER (socket_reuseport_test_suite , test_ipv4_tcp_identical_clients )
0 commit comments