@@ -26,6 +26,7 @@ use iceoryx2_bb_system_types::file_name::FileName;
2626use iceoryx2_bb_system_types:: file_path:: FilePath ;
2727use iceoryx2_bb_testing:: assert_that;
2828use iceoryx2_bb_testing:: test_requires;
29+ use iceoryx2_bb_testing:: watchdog:: Watchdog ;
2930use iceoryx2_pal_posix:: posix:: POSIX_SUPPORT_UNIX_DATAGRAM_SOCKETS_ANCILLARY_DATA ;
3031use std:: thread;
3132use std:: time:: Instant ;
@@ -158,7 +159,9 @@ fn unix_datagram_socket_non_blocking_mode_returns_zero_when_nothing_was_received
158159}
159160
160161#[ test]
161- fn unix_datagram_socket_blocking_mode_blocks ( ) {
162+ fn unix_datagram_socket_blocking_receive_blocks ( ) {
163+ let _watchdog = Watchdog :: new ( ) ;
164+
162165 create_test_directory ( ) ;
163166 let socket_name = generate_socket_name ( ) ;
164167 let received_message = AtomicBool :: new ( false ) ;
@@ -190,15 +193,95 @@ fn unix_datagram_socket_blocking_mode_blocks() {
190193 thread:: sleep ( TIMEOUT ) ;
191194 let received_message_old = received_message. load ( Ordering :: Relaxed ) ;
192195 sut_sender. blocking_send ( send_data. as_slice ( ) ) . unwrap ( ) ;
193- t. join ( ) . ok ( ) ;
196+ t. join ( ) . unwrap ( ) ;
194197
195198 assert_that ! ( received_message_old, eq false ) ;
196199 assert_that ! ( received_message. load( Ordering :: Relaxed ) , eq true ) ;
197200 } ) ;
198201}
199202
200203#[ test]
201- fn unix_datagram_socket_timeout_blocks_at_least ( ) {
204+ fn unix_datagram_socket_blocking_send_blocks ( ) {
205+ let _watchdog = Watchdog :: new ( ) ;
206+
207+ create_test_directory ( ) ;
208+ let socket_name = generate_socket_name ( ) ;
209+ let handle = BarrierHandle :: new ( ) ;
210+ let handle_2 = BarrierHandle :: new ( ) ;
211+ let barrier = BarrierBuilder :: new ( 2 ) . create ( & handle) . unwrap ( ) ;
212+ let barrier_2 = BarrierBuilder :: new ( 2 ) . create ( & handle_2) . unwrap ( ) ;
213+ let send_data: Vec < u8 > = vec ! [ 1u8 , 3u8 , 3u8 , 7u8 , 13u8 , 73u8 ] ;
214+
215+ thread:: scope ( |s| {
216+ let t = s. spawn ( || {
217+ barrier. wait ( ) ;
218+ let sut_sender = UnixDatagramSenderBuilder :: new ( & socket_name)
219+ . create ( )
220+ . unwrap ( ) ;
221+
222+ while let Ok ( true ) = sut_sender. try_send ( send_data. as_slice ( ) ) { }
223+
224+ let start = Instant :: now ( ) ;
225+ barrier_2. wait ( ) ;
226+
227+ let result = sut_sender. blocking_send ( send_data. as_slice ( ) ) ;
228+
229+ assert_that ! ( result, is_ok) ;
230+ assert_that ! ( start. elapsed( ) , time_at_least TIMEOUT ) ;
231+ } ) ;
232+
233+ let sut_receiver = UnixDatagramReceiverBuilder :: new ( & socket_name)
234+ . permission ( Permission :: OWNER_ALL )
235+ . creation_mode ( CreationMode :: PurgeAndCreate )
236+ . create ( )
237+ . unwrap ( ) ;
238+ barrier. wait ( ) ;
239+ barrier_2. wait ( ) ;
240+
241+ thread:: sleep ( TIMEOUT ) ;
242+
243+ let mut receive_data: Vec < u8 > = vec ! [ 0 , 0 , 0 , 0 , 0 , 0 ] ;
244+ while let Ok ( count) = sut_receiver. try_receive ( receive_data. as_mut_slice ( ) ) {
245+ if count == 0 {
246+ break ;
247+ }
248+ }
249+
250+ t. join ( ) . unwrap ( ) ;
251+ } ) ;
252+ }
253+
254+ #[ test]
255+ fn unix_datagram_socket_timed_send_blocks_at_least_for_timeout ( ) {
256+ let _watchdog = Watchdog :: new ( ) ;
257+
258+ create_test_directory ( ) ;
259+ let socket_name = generate_socket_name ( ) ;
260+ let send_data: Vec < u8 > = vec ! [ 1u8 , 3u8 , 3u8 , 7u8 , 13u8 , 173u8 ] ;
261+
262+ let _sut_receiver = UnixDatagramReceiverBuilder :: new ( & socket_name)
263+ . permission ( Permission :: OWNER_ALL )
264+ . creation_mode ( CreationMode :: PurgeAndCreate )
265+ . create ( )
266+ . unwrap ( ) ;
267+ let sut_sender = UnixDatagramSenderBuilder :: new ( & socket_name)
268+ . create ( )
269+ . unwrap ( ) ;
270+
271+ while let Ok ( true ) = sut_sender. try_send ( send_data. as_slice ( ) ) { }
272+
273+ let start = Instant :: now ( ) ;
274+
275+ let result = sut_sender. timed_send ( send_data. as_slice ( ) , TIMEOUT ) ;
276+
277+ assert_that ! ( result, is_ok) ;
278+ assert_that ! ( start. elapsed( ) , time_at_least TIMEOUT ) ;
279+ }
280+
281+ #[ test]
282+ fn unix_datagram_socket_timeout_receive_blocks_at_least_for_timeout ( ) {
283+ let _watchdog = Watchdog :: new ( ) ;
284+
202285 create_test_directory ( ) ;
203286 let socket_name = generate_socket_name ( ) ;
204287 let handle = BarrierHandle :: new ( ) ;
@@ -226,7 +309,7 @@ fn unix_datagram_socket_timeout_blocks_at_least() {
226309 let start = Instant :: now ( ) ;
227310 barrier_2. wait ( ) ;
228311
229- t. join ( ) . ok ( ) ;
312+ t. join ( ) . unwrap ( ) ;
230313
231314 assert_that ! ( start. elapsed( ) , time_at_least TIMEOUT ) ;
232315 } ) ;
0 commit comments