@@ -2063,7 +2063,7 @@ void test_full_zwave_tx_queue()
2063
2063
(void * )& my_user_pointer ,
2064
2064
& test_tx_session_id_2 ));
2065
2065
contiki_test_helper_run (0 );
2066
-
2066
+ // Fill the queue
2067
2067
for (int i = 1 ; i < ZWAVE_TX_QUEUE_BUFFER_SIZE ; ++ i ) {
2068
2068
TEST_ASSERT_EQUAL (SL_STATUS_OK ,
2069
2069
zwave_tx_send_data (& test_connection_1 ,
@@ -2074,9 +2074,14 @@ void test_full_zwave_tx_queue()
2074
2074
(void * )& my_user_pointer ,
2075
2075
& test_tx_session_id ));
2076
2076
}
2077
+ zwave_tx_session_id_t second_message_id = test_tx_session_id ;
2077
2078
2078
2079
TEST_ASSERT_EQUAL (ZWAVE_TX_QUEUE_BUFFER_SIZE , zwave_tx_get_queue_size ());
2079
2080
2081
+ zwave_controller_transport_abort_send_data_ExpectAndReturn (
2082
+ test_tx_session_id_2 ,
2083
+ SL_STATUS_FAIL );
2084
+
2080
2085
// Now there is no more queue space:
2081
2086
TEST_ASSERT_EQUAL (SL_STATUS_FAIL ,
2082
2087
zwave_tx_send_data (& test_connection_1 ,
@@ -2087,16 +2092,13 @@ void test_full_zwave_tx_queue()
2087
2092
(void * )& my_user_pointer ,
2088
2093
& test_tx_session_id ));
2089
2094
2090
- // Get one free slot
2091
- on_zwave_transport_send_data_complete (TRANSMIT_COMPLETE_OK ,
2092
- NULL ,
2093
- test_tx_session_id_2 );
2094
-
2095
+ // Process events
2095
2096
contiki_test_helper_run (0 );
2096
2097
TEST_ASSERT_EQUAL (1 , send_done_count );
2097
- TEST_ASSERT_EQUAL (TRANSMIT_COMPLETE_OK , send_done_status );
2098
+ TEST_ASSERT_EQUAL (TRANSMIT_COMPLETE_FAIL , send_done_status );
2098
2099
2099
- // Now queueing should work again:
2100
+
2101
+ // The first frame should be discarded no matter it's timestamp since the queue is full
2100
2102
TEST_ASSERT_EQUAL (SL_STATUS_OK ,
2101
2103
zwave_tx_send_data (& test_connection_1 ,
2102
2104
sizeof (test_expected_frame_data_1 ),
@@ -2106,7 +2108,56 @@ void test_full_zwave_tx_queue()
2106
2108
(void * )& my_user_pointer ,
2107
2109
& test_tx_session_id ));
2108
2110
2109
- // And now we are full again:
2111
+ zwave_controller_transport_abort_send_data_ExpectAndReturn (
2112
+ second_message_id ,
2113
+ SL_STATUS_FAIL );
2114
+
2115
+ // Check that we only discarded one frame and that the other frames are still here
2116
+ TEST_ASSERT_EQUAL (SL_STATUS_FAIL ,
2117
+ zwave_tx_send_data (& test_connection_1 ,
2118
+ sizeof (test_expected_frame_data_1 ),
2119
+ test_expected_frame_data_1 ,
2120
+ & test_tx_options_1 ,
2121
+ send_data_callback ,
2122
+ (void * )& my_user_pointer ,
2123
+ & test_tx_session_id ));
2124
+ }
2125
+
2126
+ void test_full_zwave_tx_queue_with_timeouts ()
2127
+ {
2128
+ // We do not care about interactions with the transports for this test.
2129
+ zwave_controller_transport_send_data_IgnoreAndReturn (SL_STATUS_OK );
2130
+
2131
+ // Queue a first element:
2132
+ TEST_ASSERT_EQUAL (SL_STATUS_OK ,
2133
+ zwave_tx_send_data (& test_connection_2 ,
2134
+ sizeof (test_expected_frame_data_2 ),
2135
+ test_expected_frame_data_2 ,
2136
+ & test_tx_options_2 ,
2137
+ send_data_callback ,
2138
+ (void * )& my_user_pointer ,
2139
+ & test_tx_session_id_2 ));
2140
+ contiki_test_helper_run (0 );
2141
+
2142
+ // Fill the queue with elements that will time out after 400 ms
2143
+ for (int i = 1 ; i < ZWAVE_TX_QUEUE_BUFFER_SIZE ; ++ i ) {
2144
+ TEST_ASSERT_EQUAL (SL_STATUS_OK ,
2145
+ zwave_tx_send_data (& test_connection_2 ,
2146
+ sizeof (test_expected_frame_data_2 ),
2147
+ test_expected_frame_data_2 ,
2148
+ & test_tx_options_2 ,
2149
+ send_data_callback ,
2150
+ (void * )& my_user_pointer ,
2151
+ & test_tx_session_id ));
2152
+ }
2153
+
2154
+ TEST_ASSERT_EQUAL (ZWAVE_TX_QUEUE_BUFFER_SIZE , zwave_tx_get_queue_size ());
2155
+
2156
+ zwave_controller_transport_abort_send_data_ExpectAndReturn (
2157
+ test_tx_session_id_2 ,
2158
+ SL_STATUS_FAIL );
2159
+
2160
+ // Now there is no more queue space:
2110
2161
TEST_ASSERT_EQUAL (SL_STATUS_FAIL ,
2111
2162
zwave_tx_send_data (& test_connection_1 ,
2112
2163
sizeof (test_expected_frame_data_1 ),
@@ -2115,8 +2166,29 @@ void test_full_zwave_tx_queue()
2115
2166
send_data_callback ,
2116
2167
(void * )& my_user_pointer ,
2117
2168
& test_tx_session_id ));
2169
+
2170
+ // We advance the internal contiki clock by 1000 ms so that the Tx Queue
2171
+ // discard the frames that should have timed out by now.
2172
+ contiki_test_helper_run (1000 );
2173
+ TEST_ASSERT_EQUAL (ZWAVE_TX_QUEUE_BUFFER_SIZE , send_done_count );
2174
+ TEST_ASSERT_EQUAL (TRANSMIT_COMPLETE_FAIL , send_done_status );
2175
+
2176
+
2177
+ // We filling the queue again and check if everything works as expected
2178
+ // By now the queue should be empty since all the frames should have timed out
2179
+ for (int i = 1 ; i < ZWAVE_TX_QUEUE_BUFFER_SIZE ; ++ i ) {
2180
+ TEST_ASSERT_EQUAL (SL_STATUS_OK ,
2181
+ zwave_tx_send_data (& test_connection_2 ,
2182
+ sizeof (test_expected_frame_data_2 ),
2183
+ test_expected_frame_data_2 ,
2184
+ & test_tx_options_2 ,
2185
+ send_data_callback ,
2186
+ (void * )& my_user_pointer ,
2187
+ & test_tx_session_id ));
2188
+ }
2118
2189
}
2119
2190
2191
+
2120
2192
void test_additional_back_off ()
2121
2193
{
2122
2194
zwave_node_id_t chatty_node_id = 23 ;
0 commit comments