@@ -12670,18 +12670,30 @@ END_TEST
1267012670
1267112671START_TEST (test_queue_pop_wraparound ) {
1267212672 struct queue q ;
12673+ struct {
12674+ uint8_t buf [8 ];
12675+ uint8_t guard [4 ];
12676+ } storage ;
1267312677 uint8_t data [] = {9 , 10 , 11 , 12 };
12678+ uint8_t expected_guard [] = {0xEE , 0xEE , 0xEE , 0xEE };
1267412679 uint8_t out [4 ];
1267512680 int len ;
12676- queue_init (& q , mem , memsz , 0x12345678 );
12677-
12678- q .head = memsz - 1 ;
12679- q .tail = memsz - 1 ;
12680- queue_insert (& q , data , 0 , sizeof (data ));
12681+ memset (& storage , 0 , sizeof (storage ));
12682+ memset (storage .guard , 0xEE , sizeof (storage .guard ));
12683+ queue_init (& q , storage .buf , sizeof (storage .buf ), 0x12345678 );
12684+
12685+ /* Manually set a wrapped queue state: tail near end, head near start. */
12686+ q .tail = 6 ;
12687+ q .head = 2 ;
12688+ storage .buf [6 ] = data [0 ];
12689+ storage .buf [7 ] = data [1 ];
12690+ storage .buf [0 ] = data [2 ];
12691+ storage .buf [1 ] = data [3 ];
1268112692 len = queue_pop (& q , out , sizeof (out ));
1268212693 ck_assert_int_eq (len , sizeof (out ));
1268312694 ck_assert_mem_eq (out , data , sizeof (data ));
1268412695 ck_assert_int_eq (queue_len (& q ), 0 );
12696+ ck_assert_mem_eq (storage .guard , expected_guard , sizeof (expected_guard ));
1268512697}
1268612698END_TEST
1268712699
0 commit comments