9 #include "../../firmware.h"
10 #include "../../test.h"
12 bool test_buffer_add_remove_element(
void);
13 bool test_buffer_retrieve_element(
void);
14 bool test_buffer_roll(
void);
15 bool test_buffer_fill_elements(
void);
17 bool buffer_tests(
void)
19 bool test_state =
true;
21 assert_run_print(test_buffer_add_remove_element(),
"Buffer Add & Remove Element", test_state);
23 assert_run_print(test_buffer_retrieve_element(),
"Buffer Retrieve Element", test_state);
25 assert_run_print(test_buffer_roll(),
"Buffer Roll", test_state);
27 assert_run_print(test_buffer_fill_elements(),
"Buffer Fill & Overflow", test_state);
33 bool test_buffer_add_remove_element(
void)
35 uint8_t test_buffer_packet[BUFFER_SLOT_SIZE] = { 0 };
41 if(Buffer_count_occupied() != 0)
46 Buffer_store_new_data(test_buffer_packet);
47 if(Buffer_count_occupied() != 1)
53 Buffer_remove_index(0x34);
54 if(Buffer_count_occupied() != 1)
60 Buffer_remove_index(0x01);
61 if(Buffer_count_occupied() != 0)
69 bool test_buffer_retrieve_element(
void)
72 uint8_t reference_buffer_packet[BUFFER_SLOT_SIZE];
73 uint8_t test_buffer_packet[BUFFER_SLOT_SIZE] = {0};
76 for(i=0; i<BUFFER_SLOT_SIZE; i++)
78 reference_buffer_packet[i] = (uint8_t)(
Random(255));
85 if(Buffer_get_occupancy(0x00))
91 if(Buffer_get_next_data(test_buffer_packet))
97 Buffer_store_new_data(reference_buffer_packet);
100 if(!Buffer_get_occupancy(0x00))
106 if(!Buffer_get_next_data(test_buffer_packet))
111 if(memcmp(test_buffer_packet, reference_buffer_packet, BUFFER_SLOT_SIZE) != 0)
119 bool test_buffer_roll(
void)
122 uint8_t reference1_buffer_packet[BUFFER_SLOT_SIZE];
123 uint8_t reference2_buffer_packet[BUFFER_SLOT_SIZE];
124 uint8_t test_buffer_packet[BUFFER_SLOT_SIZE] = {0};
127 for(i=0; i<BUFFER_SLOT_SIZE; i++)
129 reference1_buffer_packet[i] = (uint8_t)(
Random(255));
130 reference2_buffer_packet[i] = (uint8_t)(
Random(255));
137 if(Buffer_count_occupied() != 0)
141 Debug_print(
"Buffer count should be empty, is: %d\r\n", Buffer_count_occupied());
147 if(Buffer_get_next_data(test_buffer_packet))
151 Debug_print(
"Succeeded in retrieving non-existent packet.\r\n");
157 Buffer_store_new_data(reference1_buffer_packet);
160 if(Buffer_count_occupied() != 1)
164 Debug_print(
"Buffer count should be 1, is: %d\r\n", Buffer_count_occupied());
170 if(!Buffer_get_next_data(test_buffer_packet))
174 Debug_print(
"Failed to retrieve packet (attempt 1).\r\n");
178 if(memcmp(test_buffer_packet, reference1_buffer_packet, BUFFER_SLOT_SIZE) != 0)
182 Debug_print(
"Failed to match retrieved packet (attempt 1).\r\n");
188 if(!Buffer_get_next_data(test_buffer_packet))
192 Debug_print(
"Failed to retrieve packet (attempt 2).\r\n");
196 if(memcmp(test_buffer_packet, reference1_buffer_packet, BUFFER_SLOT_SIZE) != 0)
200 Debug_print(
"Failed to match retrieved packet (attempt 2).\r\n");
206 if(Buffer_count_occupied() != 1)
212 Buffer_store_new_data(reference2_buffer_packet);
215 if(Buffer_count_occupied() != 2)
221 if(!Buffer_get_next_data(test_buffer_packet))
225 Debug_print(
"Failed to retrieve packet2 (attempt 1).\r\n");
229 if(memcmp(test_buffer_packet, reference2_buffer_packet, BUFFER_SLOT_SIZE) != 0)
233 Debug_print(
"Failed to match retrieved packet2 (attempt 1).\r\n");
239 if(!Buffer_get_next_data(test_buffer_packet))
243 Debug_print(
"Failed to retrieve packet1 (attempt 3).\r\n");
247 if(memcmp(test_buffer_packet, reference1_buffer_packet, BUFFER_SLOT_SIZE) != 0)
251 Debug_print(
"Failed to match retrieved packet1 (attempt 3).\r\n");
257 if(!Buffer_get_next_data(test_buffer_packet))
261 Debug_print(
"Failed to retrieve packet2 (attempt 2).\r\n");
265 if(memcmp(test_buffer_packet, reference2_buffer_packet, BUFFER_SLOT_SIZE) != 0)
269 Debug_print(
"Failed to match retrieved packet2 (attempt 2).\r\n");
275 Buffer_remove_index(0x01);
276 if(Buffer_count_occupied() != 1)
282 if(!Buffer_get_next_data(test_buffer_packet))
286 Debug_print(
"Failed to retrieve packet2 (attempt 3).\r\n");
290 if(memcmp(test_buffer_packet, reference2_buffer_packet, BUFFER_SLOT_SIZE) != 0)
294 Debug_print(
"Failed to match retrieved packet2 (attempt 3).\r\n");
302 bool test_buffer_fill_elements(
void)
304 uint8_t test_buffer_packet[BUFFER_SLOT_SIZE] = { 0 };
310 for(uint16_t i=0; i<BUFFER_SLOTS; i++)
312 Buffer_store_new_data(test_buffer_packet);
314 if(Buffer_count_occupied() != i+1)
318 Debug_print(
"i: %d Occupied: %d\r\n", i, Buffer_count_occupied());
325 for(uint16_t i=0; i<BUFFER_SLOTS; i++)
327 Buffer_store_new_data(test_buffer_packet);
329 if(Buffer_count_occupied() != BUFFER_SLOTS)
333 Debug_print(
"i: %d Occupied: %d\r\n", i, Buffer_count_occupied());
uint32_t Random(uint32_t max)
void Debug_print(char *fmt,...)