char test_reset_countdowns(void) { char result = 0; float secs[] = {0, 0}; T_CALLBACK callbacks[] = {set_value_to_1, set_value_to_2}; reset_all_countdowns(); print_test_beauty(__FUNCTION__); value = 0; if (!(prepare_countdowns(2, secs, callbacks, NULL))) { printf("Setting the countdowns failed!\n"); failure_message(__FUNCTION__); return 1; } run_countdown(); result |= compare_dec(value, 0, "PRE Callback execution"); CONCAT_EXP(TIMER, _COMPA_vect)(); result |= compare_dec(value, 1, "Callback execution 1"); reset_all_countdowns(); CONCAT_EXP(TIMER, _COMPA_vect)(); result |= compare_dec(value, 1, "Callback execution 2"); if (result != 0) { failure_message(__FUNCTION__); } else { success_message(__FUNCTION__); } return result; }
char test_countdown_preparation(void) { int i; char buf[1000]; char result = 0; float seconds[4]; int expected[4][2]; float fail_zeros[11] = {0}; for (i = 0; i < 4; i++) { seconds[i] = (MAX_SECONDS - 1) / 3 * i; expected[i][0] = (int)(seconds[i] / SECONDS_PER_OVERFLOW); expected[i][1] = (int)(seconds[i] - (expected[i][0] * SECONDS_PER_OVERFLOW)) / SECONDS_PER_TICK; } T_CALLBACK cb[] = {sei, sei}; T_CALLBACK cb_zeros[11] = {NULL}; print_test_beauty(__FUNCTION__); if ((prepare_countdowns(11, fail_zeros, cb_zeros, NULL))) { printf("Countdown preparation did not abort on too many countdowns!\n"); failure_message(__FUNCTION__); return 1; } if (!(prepare_countdowns(4, seconds, cb, NULL))) { printf("Setting the countdowns failed!\n"); failure_message(__FUNCTION__); return 1; } for (i = 0; i < 4; i++) { sprintf(buf, "Overflow calc for %f", seconds[i]); result |= compare_dec(_CT_O._cd_ovfs[i], expected[i][0], buf); sprintf(buf, "Tick calc for %f", seconds[i]); result |= compare_dec(_CT_O._cd_ticks[i], expected[i][1], buf); ; } if (result != 0) { failure_message(__FUNCTION__); } else { success_message(__FUNCTION__); } return result; }
void run_test( int test_return_value, char* test_name, int test_count ) { test_return_value == 1 ? failure_message(test_name, test_count) : success_message(test_name, test_count); }
char test_non_isr_callback_combination(void) { char result = 0; T_CALLBACK cur_cb; float secs[] = {0, 0, 0}; T_CALLBACK callbacks[] = {set_value_to_1, set_value_to_2, set_value_to_3}; uint8_t in_isr[] = {1, 0, 1}; reset_all_countdowns(); print_test_beauty(__FUNCTION__); value = 0; if (!(prepare_countdowns(3, secs, callbacks, in_isr))) { printf("Setting the countdowns failed!\n"); failure_message(__FUNCTION__); return 1; } run_countdown(); result |= compare_dec(value, 0, "PRE Callback execution"); CONCAT_EXP(TIMER, _COMPA_vect)(); compare_cb(get_current_callback(), NULL, "Available callback 1"); result |= compare_dec(value, 1, "Callback execution 1"); CONCAT_EXP(TIMER, _COMPA_vect)(); result |= compare_dec(value, 1, "Callback execution 2"); cur_cb = get_current_callback(); result |= compare_cb(cur_cb, set_value_to_2, "Available callback 2"); (*cur_cb)(); result |= compare_dec(value, 2, "NON-ISR Callback execution 2"); CONCAT_EXP(TIMER, _COMPA_vect)(); compare_cb(get_current_callback(), NULL, "Available callback 3"); result |= compare_dec(value, 3, "Callback execution 3"); if (result != 0) { failure_message(__FUNCTION__); } else { success_message(__FUNCTION__); } return result; }
char test_failure_on_exceeding(void) { char result = 0; float seconds = MAX_SECONDS + 1; print_test_beauty(__FUNCTION__); if ((prepare_single_countdown(seconds, sei, 0))) { printf( "Countdown preparation did not abort while exceeding " "MAX_SECONDS!\n"); failure_message(__FUNCTION__); return 1; } if (result != 0) { failure_message(__FUNCTION__); } else { success_message(__FUNCTION__); } return result; }