Repo unification
This commit is contained in:
73
firmware/tests/ut_hw/ut_analog.c
Normal file
73
firmware/tests/ut_hw/ut_analog.c
Normal file
@@ -0,0 +1,73 @@
|
||||
#include "ut_analog.h"
|
||||
|
||||
#include "..\mock_board\mock_board_ain.h"
|
||||
|
||||
#include "..\..\src\hw\analog.h"
|
||||
|
||||
static const uint8_t NOT_ACCESED_AIN_CH = 255;
|
||||
|
||||
static int ut_analog_ch_get(uint8_t analog_ch, uint16_t ain_value, uint16_t exp_out, uint8_t exp_ain_ch)
|
||||
{
|
||||
printf(" Input: Analog-Ch:%d AIN-Value:%d \n", analog_ch, ain_value);
|
||||
|
||||
mock_board_ain_write_ch(NOT_ACCESED_AIN_CH);
|
||||
mock_board_ain_write_data(exp_ain_ch, ain_value);
|
||||
|
||||
uint16_t out = analog_ch_get(analog_ch);
|
||||
|
||||
uint8_t ain_ch = mock_board_ain_read_ch();
|
||||
|
||||
printf(" Output: ANALOG:%d AIN-Ch:%d \n", out, ain_ch);
|
||||
printf("Expected: ANALOG:%d AIN-Ch:%d \n", exp_out, exp_ain_ch);
|
||||
|
||||
if((out==exp_out)&&(ain_ch==exp_ain_ch))
|
||||
{
|
||||
printf("PASS\n\n");
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("FAIL\n\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int ut_analog_ch_get_test(void)
|
||||
{
|
||||
printf("******************************************************\n");
|
||||
printf("uint16_t analog_ch_get(uint8_t analog_ch) \n");
|
||||
|
||||
int test_res;
|
||||
int pass = 1;
|
||||
|
||||
uint8_t analog_ch;
|
||||
uint16_t ain_value;
|
||||
uint16_t exp_out;
|
||||
uint8_t exp_ain_ch;
|
||||
|
||||
// Normal 1
|
||||
analog_ch = ANALOG_1;
|
||||
ain_value = 2500;
|
||||
exp_out = 2500;
|
||||
exp_ain_ch = BSP_AIN2;
|
||||
test_res = ut_analog_ch_get(analog_ch, ain_value, exp_out, exp_ain_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Normal 2
|
||||
analog_ch = ANALOG_2;
|
||||
ain_value = 3000;
|
||||
exp_out = 3000;
|
||||
exp_ain_ch = BSP_AIN1;
|
||||
test_res = ut_analog_ch_get(analog_ch, ain_value, exp_out, exp_ain_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Wrong channel
|
||||
analog_ch = 0;
|
||||
ain_value = 1200;
|
||||
exp_out = 0;
|
||||
exp_ain_ch = NOT_ACCESED_AIN_CH;
|
||||
test_res = ut_analog_ch_get(analog_ch, ain_value, exp_out, exp_ain_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
return pass;
|
||||
}
|
||||
9
firmware/tests/ut_hw/ut_analog.h
Normal file
9
firmware/tests/ut_hw/ut_analog.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef UT_HW_ANALOG_H_
|
||||
#define UT_HW_ANALOG_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int ut_analog_ch_get_test(void);
|
||||
|
||||
#endif /* UT_HW_ANALOG_H_ */
|
||||
854
firmware/tests/ut_hw/ut_buttons.c
Normal file
854
firmware/tests/ut_hw/ut_buttons.c
Normal file
@@ -0,0 +1,854 @@
|
||||
#include "ut_buttons.h"
|
||||
|
||||
#include "..\mock_board\mock_board_din.h"
|
||||
#include "..\mock_board\mock_board_dout.h"
|
||||
|
||||
#include "..\..\src\hw\buttons.h"
|
||||
|
||||
static const uint8_t NOT_ACCESED_DIN_CH = 255;
|
||||
static const uint8_t NOT_ACCESED_DIN_LVL = BSP_DIN_LOW;
|
||||
|
||||
static const uint8_t NOT_ACCESED_DOUT_CH = 255;
|
||||
static const int8_t NOT_ACCESED_DOUT_LVL = BSP_DOUT_HIZ;
|
||||
|
||||
static int ut_btn_reset(btn_t* btn, btn_t* exp_btn)
|
||||
{
|
||||
printf(" Input: State:%d New-State:%d State-time:%d Transition-cntr:%d Debounce-act:%d \n", btn->state, btn->new_state, btn->state_time, btn->transition_cntr, btn->dbnc_active);
|
||||
|
||||
btn_reset(btn);
|
||||
|
||||
printf(" Output: State:%d New-State:%d State-time:%d Transition-cntr:%d Debounce-act:%d \n", btn->state, btn->new_state, btn->state_time, btn->transition_cntr, btn->dbnc_active);
|
||||
printf("Expected: State:%d New-State:%d State-time:%d Transition-cntr:%d Debounce-act:%d \n", exp_btn->state, exp_btn->new_state, exp_btn->state_time, exp_btn->transition_cntr, exp_btn->dbnc_active);
|
||||
|
||||
int equal = 1;
|
||||
if(btn->state != exp_btn->state) equal = 0;
|
||||
if(btn->new_state != exp_btn->new_state) equal = 0;
|
||||
if(btn->state_time != exp_btn->state_time) equal = 0;
|
||||
if(btn->transition_cntr != exp_btn->transition_cntr) equal = 0;
|
||||
if(btn->dbnc_active != exp_btn->dbnc_active) equal = 0;
|
||||
|
||||
if(equal)
|
||||
{
|
||||
printf("PASS\n\n");
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("FAIL\n\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int ut_btn_reset_test(void)
|
||||
{
|
||||
printf("******************************************************\n");
|
||||
printf("void btn_reset(btn_t* btn) \n");
|
||||
|
||||
int test_res;
|
||||
int pass = 1;
|
||||
|
||||
btn_t btn;
|
||||
btn_t exp_btn;
|
||||
|
||||
// Normal 1
|
||||
btn.state = 0;
|
||||
btn.new_state = 0;
|
||||
btn.state_time = 0;
|
||||
btn.transition_cntr = 0;
|
||||
btn.dbnc_active = 0;
|
||||
exp_btn.state = 0;
|
||||
exp_btn.new_state = 0;
|
||||
exp_btn.state_time = 0;
|
||||
exp_btn.transition_cntr = 0;
|
||||
exp_btn.dbnc_active = 1;
|
||||
test_res = ut_btn_reset(&btn, &exp_btn);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Normal 1
|
||||
btn.state = 1;
|
||||
btn.new_state = 1;
|
||||
btn.state_time = 1000;
|
||||
btn.transition_cntr = 20;
|
||||
btn.dbnc_active = 0;
|
||||
exp_btn.state = BTN_INACTIVE;
|
||||
exp_btn.new_state = 0;
|
||||
exp_btn.state_time = 0;
|
||||
exp_btn.transition_cntr = 0;
|
||||
exp_btn.dbnc_active = 1;
|
||||
test_res = ut_btn_reset(&btn, &exp_btn);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
return pass;
|
||||
}
|
||||
|
||||
static int ut_btn_process(uint8_t lvl, btn_t* btn, btn_cfg_t* cfg, uint8_t exp_out, btn_t* exp_btn, btn_cfg_t* exp_cfg)
|
||||
{
|
||||
printf(" Input: Level:%d \n", lvl);
|
||||
printf(" Input: State:%d New-State:%d State-time:%d Transition-cntr:%d Debounce-act:%d \n", btn->state, btn->new_state, btn->state_time, btn->transition_cntr, btn->dbnc_active);
|
||||
printf(" Input: Act-Lvl:%d Debounce-lim:%d Repeat-Time:%d \n", cfg->act_lvl, cfg->dbnc_lim, cfg->repeat_time);
|
||||
|
||||
uint8_t out = btn_process(lvl, btn, cfg);
|
||||
|
||||
printf(" Output: %d \n", out);
|
||||
printf(" Output: State:%d New-State:%d State-time:%d Transition-cntr:%d Debounce-act:%d \n", btn->state, btn->new_state, btn->state_time, btn->transition_cntr, btn->dbnc_active);
|
||||
printf(" Output: Act-Lvl:%d Debounce-lim:%d Repeat-Time:%d \n", cfg->act_lvl, cfg->dbnc_lim, cfg->repeat_time);
|
||||
|
||||
printf("Expected: %d \n", exp_out);
|
||||
printf("Expected: State:%d New-State:%d State-time:%d Transition-cntr:%d Debounce-act:%d \n", exp_btn->state, exp_btn->new_state, exp_btn->state_time, exp_btn->transition_cntr, exp_btn->dbnc_active);
|
||||
printf("Expected: Act-Lvl:%d Debounce-lim:%d Repeat-Time:%d \n", exp_cfg->act_lvl, exp_cfg->dbnc_lim, exp_cfg->repeat_time);
|
||||
|
||||
int equal = 1;
|
||||
if(btn->state != exp_btn->state) equal = 0;
|
||||
if(btn->new_state != exp_btn->new_state) equal = 0;
|
||||
if(btn->state_time != exp_btn->state_time) equal = 0;
|
||||
if(btn->transition_cntr != exp_btn->transition_cntr) equal = 0;
|
||||
if(btn->dbnc_active != exp_btn->dbnc_active) equal = 0;
|
||||
if(cfg->act_lvl != exp_cfg->act_lvl) equal = 0;
|
||||
if(cfg->dbnc_lim != exp_cfg->dbnc_lim) equal = 0;
|
||||
if(cfg->repeat_time != exp_cfg->repeat_time) equal = 0;
|
||||
|
||||
if((out==exp_out)&&(equal))
|
||||
{
|
||||
printf("PASS\n\n");
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("FAIL\n\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int ut_btn_process_test(void)
|
||||
{
|
||||
printf("******************************************************\n");
|
||||
printf("uint8_t btn_process(uint8_t lvl, btn_t* btn, btn_cfg_t* cfg) \n");
|
||||
|
||||
int test_res;
|
||||
int pass = 1;
|
||||
|
||||
uint8_t lvl;
|
||||
btn_t btn;
|
||||
btn_cfg_t cfg;
|
||||
uint8_t exp_out;
|
||||
btn_t exp_btn;
|
||||
btn_cfg_t exp_cfg;
|
||||
|
||||
// No changes
|
||||
lvl = 0;
|
||||
btn.state = 0;
|
||||
btn.new_state = 0;
|
||||
btn.state_time = 0;
|
||||
btn.transition_cntr = 0;
|
||||
btn.dbnc_active = 0;
|
||||
cfg.act_lvl = 1;
|
||||
cfg.dbnc_lim = 0;
|
||||
cfg.repeat_time = 0;
|
||||
|
||||
exp_out = 0;
|
||||
exp_btn.state = 0;
|
||||
exp_btn.new_state = 0;
|
||||
exp_btn.state_time = 1;
|
||||
exp_btn.transition_cntr = 0;
|
||||
exp_btn.dbnc_active = 0;
|
||||
exp_cfg.act_lvl = cfg.act_lvl;
|
||||
exp_cfg.dbnc_lim = cfg.dbnc_lim;
|
||||
exp_cfg.repeat_time = cfg.repeat_time;
|
||||
|
||||
test_res = ut_btn_process(lvl, &btn, &cfg, exp_out, &exp_btn, &exp_cfg);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// State time increase
|
||||
lvl = 1;
|
||||
btn.state = 0;
|
||||
btn.new_state = 0;
|
||||
btn.state_time = 12345;
|
||||
btn.transition_cntr = 0;
|
||||
btn.dbnc_active = 0;
|
||||
cfg.act_lvl = 0;
|
||||
cfg.dbnc_lim = 0;
|
||||
cfg.repeat_time = 0;
|
||||
|
||||
exp_out = 0;
|
||||
exp_btn.state = 0;
|
||||
exp_btn.new_state = 0;
|
||||
exp_btn.state_time = 12346;
|
||||
exp_btn.transition_cntr = 0;
|
||||
exp_btn.dbnc_active = 0;
|
||||
exp_cfg.act_lvl = cfg.act_lvl;
|
||||
exp_cfg.dbnc_lim = cfg.dbnc_lim;
|
||||
exp_cfg.repeat_time = cfg.repeat_time;
|
||||
|
||||
test_res = ut_btn_process(lvl, &btn, &cfg, exp_out, &exp_btn, &exp_cfg);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Activation, first time, act high
|
||||
lvl = 1;
|
||||
btn.state = 0;
|
||||
btn.new_state = 0;
|
||||
btn.state_time = 38455;
|
||||
btn.transition_cntr = 0;
|
||||
btn.dbnc_active = 0;
|
||||
cfg.act_lvl = 1;
|
||||
cfg.dbnc_lim = 0;
|
||||
cfg.repeat_time = 0;
|
||||
|
||||
exp_out = 1;
|
||||
exp_btn.state = 1;
|
||||
exp_btn.new_state = 1;
|
||||
exp_btn.state_time = 0;
|
||||
exp_btn.transition_cntr = 0;
|
||||
exp_btn.dbnc_active = 0;
|
||||
exp_cfg.act_lvl = cfg.act_lvl;
|
||||
exp_cfg.dbnc_lim = cfg.dbnc_lim;
|
||||
exp_cfg.repeat_time = cfg.repeat_time;
|
||||
|
||||
test_res = ut_btn_process(lvl, &btn, &cfg, exp_out, &exp_btn, &exp_cfg);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Activation, first time, act low
|
||||
lvl = 0;
|
||||
btn.state = 0;
|
||||
btn.new_state = 0;
|
||||
btn.state_time = 38455;
|
||||
btn.transition_cntr = 0;
|
||||
btn.dbnc_active = 0;
|
||||
cfg.act_lvl = 0;
|
||||
cfg.dbnc_lim = 0;
|
||||
cfg.repeat_time = 0;
|
||||
|
||||
exp_out = 1;
|
||||
exp_btn.state = 1;
|
||||
exp_btn.new_state = 1;
|
||||
exp_btn.state_time = 0;
|
||||
exp_btn.transition_cntr = 0;
|
||||
exp_btn.dbnc_active = 0;
|
||||
exp_cfg.act_lvl = cfg.act_lvl;
|
||||
exp_cfg.dbnc_lim = cfg.dbnc_lim;
|
||||
exp_cfg.repeat_time = cfg.repeat_time;
|
||||
|
||||
test_res = ut_btn_process(lvl, &btn, &cfg, exp_out, &exp_btn, &exp_cfg);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Active second time, not cleared new flag
|
||||
lvl = 1;
|
||||
btn.state = 1;
|
||||
btn.new_state = 1;
|
||||
btn.state_time = 0;
|
||||
btn.transition_cntr = 0;
|
||||
btn.dbnc_active = 0;
|
||||
cfg.act_lvl = 1;
|
||||
cfg.dbnc_lim = 0;
|
||||
cfg.repeat_time = 0;
|
||||
|
||||
exp_out = 1;
|
||||
exp_btn.state = 1;
|
||||
exp_btn.new_state = 1;
|
||||
exp_btn.state_time = 1;
|
||||
exp_btn.transition_cntr = 0;
|
||||
exp_btn.dbnc_active = 0;
|
||||
exp_cfg.act_lvl = cfg.act_lvl;
|
||||
exp_cfg.dbnc_lim = cfg.dbnc_lim;
|
||||
exp_cfg.repeat_time = cfg.repeat_time;
|
||||
|
||||
test_res = ut_btn_process(lvl, &btn, &cfg, exp_out, &exp_btn, &exp_cfg);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Active second time, cleared new flag
|
||||
lvl = 1;
|
||||
btn.state = 1;
|
||||
btn.new_state = 0;
|
||||
btn.state_time = 0;
|
||||
btn.transition_cntr = 0;
|
||||
btn.dbnc_active = 0;
|
||||
cfg.act_lvl = 1;
|
||||
cfg.dbnc_lim = 0;
|
||||
cfg.repeat_time = 0;
|
||||
|
||||
exp_out = 1;
|
||||
exp_btn.state = 1;
|
||||
exp_btn.new_state = 0;
|
||||
exp_btn.state_time = 1;
|
||||
exp_btn.transition_cntr = 0;
|
||||
exp_btn.dbnc_active = 0;
|
||||
exp_cfg.act_lvl = cfg.act_lvl;
|
||||
exp_cfg.dbnc_lim = cfg.dbnc_lim;
|
||||
exp_cfg.repeat_time = cfg.repeat_time;
|
||||
|
||||
test_res = ut_btn_process(lvl, &btn, &cfg, exp_out, &exp_btn, &exp_cfg);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Deactive, act high
|
||||
lvl = 0;
|
||||
btn.state = 1;
|
||||
btn.new_state = 0;
|
||||
btn.state_time = 60584;
|
||||
btn.transition_cntr = 0;
|
||||
btn.dbnc_active = 0;
|
||||
cfg.act_lvl = 1;
|
||||
cfg.dbnc_lim = 0;
|
||||
cfg.repeat_time = 0;
|
||||
|
||||
exp_out = 0;
|
||||
exp_btn.state = 0;
|
||||
exp_btn.new_state = 1;
|
||||
exp_btn.state_time = 0;
|
||||
exp_btn.transition_cntr = 0;
|
||||
exp_btn.dbnc_active = 0;
|
||||
exp_cfg.act_lvl = cfg.act_lvl;
|
||||
exp_cfg.dbnc_lim = cfg.dbnc_lim;
|
||||
exp_cfg.repeat_time = cfg.repeat_time;
|
||||
|
||||
test_res = ut_btn_process(lvl, &btn, &cfg, exp_out, &exp_btn, &exp_cfg);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Deactive, act low
|
||||
lvl = 1;
|
||||
btn.state = 1;
|
||||
btn.new_state = 0;
|
||||
btn.state_time = 558;
|
||||
btn.transition_cntr = 0;
|
||||
btn.dbnc_active = 0;
|
||||
cfg.act_lvl = 0;
|
||||
cfg.dbnc_lim = 0;
|
||||
cfg.repeat_time = 0;
|
||||
|
||||
exp_out = 0;
|
||||
exp_btn.state = 0;
|
||||
exp_btn.new_state = 1;
|
||||
exp_btn.state_time = 0;
|
||||
exp_btn.transition_cntr = 0;
|
||||
exp_btn.dbnc_active = 0;
|
||||
exp_cfg.act_lvl = cfg.act_lvl;
|
||||
exp_cfg.dbnc_lim = cfg.dbnc_lim;
|
||||
exp_cfg.repeat_time = cfg.repeat_time;
|
||||
|
||||
test_res = ut_btn_process(lvl, &btn, &cfg, exp_out, &exp_btn, &exp_cfg);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Debounce, first
|
||||
lvl = 1;
|
||||
btn.state = 0;
|
||||
btn.new_state = 0;
|
||||
btn.state_time = 24789;
|
||||
btn.transition_cntr = 0;
|
||||
btn.dbnc_active = 0;
|
||||
cfg.act_lvl = 1;
|
||||
cfg.dbnc_lim = 10;
|
||||
cfg.repeat_time = 0;
|
||||
|
||||
exp_out = 0;
|
||||
exp_btn.state = 0;
|
||||
exp_btn.new_state = 0;
|
||||
exp_btn.state_time = 24790;
|
||||
exp_btn.transition_cntr = 0;
|
||||
exp_btn.dbnc_active = 1;
|
||||
exp_cfg.act_lvl = cfg.act_lvl;
|
||||
exp_cfg.dbnc_lim = cfg.dbnc_lim;
|
||||
exp_cfg.repeat_time = cfg.repeat_time;
|
||||
|
||||
test_res = ut_btn_process(lvl, &btn, &cfg, exp_out, &exp_btn, &exp_cfg);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Debounce at end
|
||||
lvl = 1;
|
||||
btn.state = 0;
|
||||
btn.new_state = 0;
|
||||
btn.state_time = 142;
|
||||
btn.transition_cntr = 9;
|
||||
btn.dbnc_active = 1;
|
||||
cfg.act_lvl = 1;
|
||||
cfg.dbnc_lim = 10;
|
||||
cfg.repeat_time = 0;
|
||||
|
||||
exp_out = 1;
|
||||
exp_btn.state = 1;
|
||||
exp_btn.new_state = 1;
|
||||
exp_btn.state_time = 0;
|
||||
exp_btn.transition_cntr = 0;
|
||||
exp_btn.dbnc_active = 0;
|
||||
exp_cfg.act_lvl = cfg.act_lvl;
|
||||
exp_cfg.dbnc_lim = cfg.dbnc_lim;
|
||||
exp_cfg.repeat_time = cfg.repeat_time;
|
||||
|
||||
test_res = ut_btn_process(lvl, &btn, &cfg, exp_out, &exp_btn, &exp_cfg);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Debounce fail, act high, fail to active state
|
||||
lvl = 0;
|
||||
btn.state = 0;
|
||||
btn.new_state = 0;
|
||||
btn.state_time = 142;
|
||||
btn.transition_cntr = 5;
|
||||
btn.dbnc_active = 1;
|
||||
cfg.act_lvl = 1;
|
||||
cfg.dbnc_lim = 10;
|
||||
cfg.repeat_time = 0;
|
||||
|
||||
exp_out = 0;
|
||||
exp_btn.state = 0;
|
||||
exp_btn.new_state = 0;
|
||||
exp_btn.state_time = 143;
|
||||
exp_btn.transition_cntr = 0;
|
||||
exp_btn.dbnc_active = 0;
|
||||
exp_cfg.act_lvl = cfg.act_lvl;
|
||||
exp_cfg.dbnc_lim = cfg.dbnc_lim;
|
||||
exp_cfg.repeat_time = cfg.repeat_time;
|
||||
|
||||
test_res = ut_btn_process(lvl, &btn, &cfg, exp_out, &exp_btn, &exp_cfg);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Debounce fail, act low, fail to active state
|
||||
lvl = 1;
|
||||
btn.state = 0;
|
||||
btn.new_state = 0;
|
||||
btn.state_time = 257;
|
||||
btn.transition_cntr = 4;
|
||||
btn.dbnc_active = 1;
|
||||
cfg.act_lvl = 0;
|
||||
cfg.dbnc_lim = 10;
|
||||
cfg.repeat_time = 0;
|
||||
|
||||
exp_out = 0;
|
||||
exp_btn.state = 0;
|
||||
exp_btn.new_state = 0;
|
||||
exp_btn.state_time = 258;
|
||||
exp_btn.transition_cntr = 0;
|
||||
exp_btn.dbnc_active = 0;
|
||||
exp_cfg.act_lvl = cfg.act_lvl;
|
||||
exp_cfg.dbnc_lim = cfg.dbnc_lim;
|
||||
exp_cfg.repeat_time = cfg.repeat_time;
|
||||
|
||||
test_res = ut_btn_process(lvl, &btn, &cfg, exp_out, &exp_btn, &exp_cfg);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Before New state repeat
|
||||
lvl = 1;
|
||||
btn.state = 1;
|
||||
btn.new_state = 0;
|
||||
btn.state_time = 4998;
|
||||
btn.transition_cntr = 0;
|
||||
btn.dbnc_active = 0;
|
||||
cfg.act_lvl = 1;
|
||||
cfg.dbnc_lim = 10;
|
||||
cfg.repeat_time = 5000;
|
||||
|
||||
exp_out = 1;
|
||||
exp_btn.state = 1;
|
||||
exp_btn.new_state = 0;
|
||||
exp_btn.state_time = 4999;
|
||||
exp_btn.transition_cntr = 0;
|
||||
exp_btn.dbnc_active = 0;
|
||||
exp_cfg.act_lvl = cfg.act_lvl;
|
||||
exp_cfg.dbnc_lim = cfg.dbnc_lim;
|
||||
exp_cfg.repeat_time = cfg.repeat_time;
|
||||
|
||||
test_res = ut_btn_process(lvl, &btn, &cfg, exp_out, &exp_btn, &exp_cfg);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Before New state repeat
|
||||
lvl = 1;
|
||||
btn.state = 1;
|
||||
btn.new_state = 0;
|
||||
btn.state_time = 4999;
|
||||
btn.transition_cntr = 0;
|
||||
btn.dbnc_active = 0;
|
||||
cfg.act_lvl = 1;
|
||||
cfg.dbnc_lim = 10;
|
||||
cfg.repeat_time = 5000;
|
||||
|
||||
exp_out = 1;
|
||||
exp_btn.state = 1;
|
||||
exp_btn.new_state = 1;
|
||||
exp_btn.state_time = 5000;
|
||||
exp_btn.transition_cntr = 0;
|
||||
exp_btn.dbnc_active = 0;
|
||||
exp_cfg.act_lvl = cfg.act_lvl;
|
||||
exp_cfg.dbnc_lim = cfg.dbnc_lim;
|
||||
exp_cfg.repeat_time = cfg.repeat_time;
|
||||
|
||||
test_res = ut_btn_process(lvl, &btn, &cfg, exp_out, &exp_btn, &exp_cfg);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Before New state repeat
|
||||
lvl = 1;
|
||||
btn.state = 1;
|
||||
btn.new_state = 0;
|
||||
btn.state_time = 5000;
|
||||
btn.transition_cntr = 0;
|
||||
btn.dbnc_active = 0;
|
||||
cfg.act_lvl = 1;
|
||||
cfg.dbnc_lim = 10;
|
||||
cfg.repeat_time = 5000;
|
||||
|
||||
exp_out = 1;
|
||||
exp_btn.state = 1;
|
||||
exp_btn.new_state = 0;
|
||||
exp_btn.state_time = 5001;
|
||||
exp_btn.transition_cntr = 0;
|
||||
exp_btn.dbnc_active = 0;
|
||||
exp_cfg.act_lvl = cfg.act_lvl;
|
||||
exp_cfg.dbnc_lim = cfg.dbnc_lim;
|
||||
exp_cfg.repeat_time = cfg.repeat_time;
|
||||
|
||||
test_res = ut_btn_process(lvl, &btn, &cfg, exp_out, &exp_btn, &exp_cfg);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Before New state repeat
|
||||
lvl = 1;
|
||||
btn.state = 1;
|
||||
btn.new_state = 0;
|
||||
btn.state_time = 19999;
|
||||
btn.transition_cntr = 0;
|
||||
btn.dbnc_active = 0;
|
||||
cfg.act_lvl = 1;
|
||||
cfg.dbnc_lim = 10;
|
||||
cfg.repeat_time = 5000;
|
||||
|
||||
exp_out = 1;
|
||||
exp_btn.state = 1;
|
||||
exp_btn.new_state = 1;
|
||||
exp_btn.state_time = 20000;
|
||||
exp_btn.transition_cntr = 0;
|
||||
exp_btn.dbnc_active = 0;
|
||||
exp_cfg.act_lvl = cfg.act_lvl;
|
||||
exp_cfg.dbnc_lim = cfg.dbnc_lim;
|
||||
exp_cfg.repeat_time = cfg.repeat_time;
|
||||
|
||||
test_res = ut_btn_process(lvl, &btn, &cfg, exp_out, &exp_btn, &exp_cfg);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Before New state repeat
|
||||
lvl = 1;
|
||||
btn.state = 1;
|
||||
btn.new_state = 0;
|
||||
btn.state_time = 0xFFFE;
|
||||
btn.transition_cntr = 0;
|
||||
btn.dbnc_active = 0;
|
||||
cfg.act_lvl = 1;
|
||||
cfg.dbnc_lim = 10;
|
||||
cfg.repeat_time = 255;
|
||||
|
||||
exp_out = 1;
|
||||
exp_btn.state = 1;
|
||||
exp_btn.new_state = 0;
|
||||
exp_btn.state_time = 0xFFFF;
|
||||
exp_btn.transition_cntr = 0;
|
||||
exp_btn.dbnc_active = 0;
|
||||
exp_cfg.act_lvl = cfg.act_lvl;
|
||||
exp_cfg.dbnc_lim = cfg.dbnc_lim;
|
||||
exp_cfg.repeat_time = cfg.repeat_time;
|
||||
|
||||
test_res = ut_btn_process(lvl, &btn, &cfg, exp_out, &exp_btn, &exp_cfg);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
return pass;
|
||||
}
|
||||
|
||||
static int ut_btn_ch_process(uint8_t btn_ch, btn_t* btn, uint8_t din_lvl, uint8_t exp_out, btn_t* exp_btn, uint8_t exp_din_ch)
|
||||
{
|
||||
printf(" Input: Btn-Ch:%d Din-Lvl:%d\n", btn_ch, din_lvl);
|
||||
printf(" Input: State:%d New-State:%d State-time:%d Transition-cntr:%d Debounce-act:%d \n", btn->state, btn->new_state, btn->state_time, btn->transition_cntr, btn->dbnc_active);
|
||||
|
||||
mock_board_din_write_ch(NOT_ACCESED_DIN_CH);
|
||||
mock_board_din_write_data(exp_din_ch, din_lvl);
|
||||
|
||||
uint8_t out = btn_ch_process(btn_ch, btn);
|
||||
|
||||
uint8_t din_ch = mock_board_din_read_ch();
|
||||
|
||||
printf(" Output: %d \n", out);
|
||||
printf(" Output: State:%d New-State:%d State-time:%d Transition-cntr:%d Debounce-act:%d \n", btn->state, btn->new_state, btn->state_time, btn->transition_cntr, btn->dbnc_active);
|
||||
printf(" Output: Din-Ch:%d \n", din_ch);
|
||||
|
||||
printf("Expected: %d \n", exp_out);
|
||||
printf("Expected: State:%d New-State:%d State-time:%d Transition-cntr:%d Debounce-act:%d \n", exp_btn->state, exp_btn->new_state, exp_btn->state_time, exp_btn->transition_cntr, exp_btn->dbnc_active);
|
||||
printf("Expected: Din-Ch:%d \n", exp_din_ch);
|
||||
|
||||
int equal = 1;
|
||||
if(btn->state != exp_btn->state) equal = 0;
|
||||
if(btn->new_state != exp_btn->new_state) equal = 0;
|
||||
if(btn->state_time != exp_btn->state_time) equal = 0;
|
||||
if(btn->transition_cntr != exp_btn->transition_cntr) equal = 0;
|
||||
if(btn->dbnc_active != exp_btn->dbnc_active) equal = 0;
|
||||
|
||||
if((out==exp_out)&&(equal)&&(din_ch==exp_din_ch))
|
||||
{
|
||||
printf("PASS\n\n");
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("FAIL\n\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int ut_btn_ch_process_test(void)
|
||||
{
|
||||
printf("******************************************************\n");
|
||||
printf("uint8_t btn_ch_process(uint8_t btn_ch, btn_t* btn) \n");
|
||||
|
||||
int test_res;
|
||||
int pass = 1;
|
||||
|
||||
uint8_t btn_ch;
|
||||
btn_t btn;
|
||||
uint8_t din_lvl;
|
||||
uint8_t exp_out;
|
||||
btn_t exp_btn;
|
||||
uint8_t exp_din_ch;
|
||||
|
||||
// Mapping check 1
|
||||
btn_ch = BTN_1;
|
||||
btn.state = 0;
|
||||
btn.new_state = 0;
|
||||
btn.state_time = 150;
|
||||
btn.transition_cntr = 9;
|
||||
btn.dbnc_active = 1;
|
||||
din_lvl = BSP_DIN_LOW;
|
||||
|
||||
exp_out = 1;
|
||||
exp_btn.state = 1;
|
||||
exp_btn.new_state = 1;
|
||||
exp_btn.state_time = 0;
|
||||
exp_btn.transition_cntr = 0;
|
||||
exp_btn.dbnc_active = 0;
|
||||
exp_din_ch = BSP_DIN1;
|
||||
|
||||
test_res = ut_btn_ch_process(btn_ch, &btn, din_lvl, exp_out, &exp_btn, exp_din_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Mapping check 2
|
||||
btn_ch = BTN_2;
|
||||
btn.state = 0;
|
||||
btn.new_state = 0;
|
||||
btn.state_time = 150;
|
||||
btn.transition_cntr = 9;
|
||||
btn.dbnc_active = 1;
|
||||
din_lvl = BSP_DIN_LOW;
|
||||
|
||||
exp_out = 1;
|
||||
exp_btn.state = 1;
|
||||
exp_btn.new_state = 1;
|
||||
exp_btn.state_time = 0;
|
||||
exp_btn.transition_cntr = 0;
|
||||
exp_btn.dbnc_active = 0;
|
||||
exp_din_ch = BSP_DIN3;
|
||||
|
||||
test_res = ut_btn_ch_process(btn_ch, &btn, din_lvl, exp_out, &exp_btn, exp_din_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Mapping check 3
|
||||
btn_ch = BTN_3;
|
||||
btn.state = 0;
|
||||
btn.new_state = 0;
|
||||
btn.state_time = 150;
|
||||
btn.transition_cntr = 9;
|
||||
btn.dbnc_active = 1;
|
||||
din_lvl = BSP_DIN_LOW;
|
||||
|
||||
exp_out = 1;
|
||||
exp_btn.state = 1;
|
||||
exp_btn.new_state = 1;
|
||||
exp_btn.state_time = 0;
|
||||
exp_btn.transition_cntr = 0;
|
||||
exp_btn.dbnc_active = 0;
|
||||
exp_din_ch = BSP_DIN4;
|
||||
|
||||
test_res = ut_btn_ch_process(btn_ch, &btn, din_lvl, exp_out, &exp_btn, exp_din_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Mapping check 4
|
||||
btn_ch = BTN_4;
|
||||
btn.state = 0;
|
||||
btn.new_state = 0;
|
||||
btn.state_time = 150;
|
||||
btn.transition_cntr = 9;
|
||||
btn.dbnc_active = 1;
|
||||
din_lvl = BSP_DIN_HIGH;
|
||||
|
||||
exp_out = 1;
|
||||
exp_btn.state = 1;
|
||||
exp_btn.new_state = 1;
|
||||
exp_btn.state_time = 0;
|
||||
exp_btn.transition_cntr = 0;
|
||||
exp_btn.dbnc_active = 0;
|
||||
exp_din_ch = BSP_DIN5;
|
||||
|
||||
test_res = ut_btn_ch_process(btn_ch, &btn, din_lvl, exp_out, &exp_btn, exp_din_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Mapping check 5
|
||||
btn_ch = BTN_5;
|
||||
btn.state = 0;
|
||||
btn.new_state = 0;
|
||||
btn.state_time = 150;
|
||||
btn.transition_cntr = 9;
|
||||
btn.dbnc_active = 1;
|
||||
din_lvl = BSP_DIN_HIGH;
|
||||
|
||||
exp_out = 1;
|
||||
exp_btn.state = 1;
|
||||
exp_btn.new_state = 1;
|
||||
exp_btn.state_time = 0;
|
||||
exp_btn.transition_cntr = 0;
|
||||
exp_btn.dbnc_active = 0;
|
||||
exp_din_ch = BSP_DIN6;
|
||||
|
||||
test_res = ut_btn_ch_process(btn_ch, &btn, din_lvl, exp_out, &exp_btn, exp_din_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Mapping check 6
|
||||
btn_ch = BTN_6;
|
||||
btn.state = 0;
|
||||
btn.new_state = 0;
|
||||
btn.state_time = 150;
|
||||
btn.transition_cntr = 9;
|
||||
btn.dbnc_active = 1;
|
||||
din_lvl = BSP_DIN_LOW;
|
||||
|
||||
exp_out = 1;
|
||||
exp_btn.state = 1;
|
||||
exp_btn.new_state = 1;
|
||||
exp_btn.state_time = 0;
|
||||
exp_btn.transition_cntr = 0;
|
||||
exp_btn.dbnc_active = 0;
|
||||
exp_din_ch = BSP_DIN7;
|
||||
|
||||
test_res = ut_btn_ch_process(btn_ch, &btn, din_lvl, exp_out, &exp_btn, exp_din_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Mapping check 6N
|
||||
btn_ch = BTN_6N;
|
||||
btn.state = 0;
|
||||
btn.new_state = 0;
|
||||
btn.state_time = 150;
|
||||
btn.transition_cntr = 9;
|
||||
btn.dbnc_active = 1;
|
||||
din_lvl = BSP_DIN_LOW;
|
||||
|
||||
exp_out = 1;
|
||||
exp_btn.state = 1;
|
||||
exp_btn.new_state = 1;
|
||||
exp_btn.state_time = 0;
|
||||
exp_btn.transition_cntr = 0;
|
||||
exp_btn.dbnc_active = 0;
|
||||
exp_din_ch = BSP_DIN7N;
|
||||
|
||||
test_res = ut_btn_ch_process(btn_ch, &btn, din_lvl, exp_out, &exp_btn, exp_din_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Wrong channel
|
||||
btn_ch = 0;
|
||||
btn.state = 1;
|
||||
btn.new_state = 0;
|
||||
btn.state_time = 150;
|
||||
btn.transition_cntr = 9;
|
||||
btn.dbnc_active = 1;
|
||||
din_lvl = BSP_DIN_LOW;
|
||||
|
||||
exp_out = 0;
|
||||
exp_btn.state = 1;
|
||||
exp_btn.new_state = 0;
|
||||
exp_btn.state_time = 150;
|
||||
exp_btn.transition_cntr = 9;
|
||||
exp_btn.dbnc_active = 1;
|
||||
exp_din_ch = NOT_ACCESED_DIN_CH;
|
||||
|
||||
test_res = ut_btn_ch_process(btn_ch, &btn, din_lvl, exp_out, &exp_btn, exp_din_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
return pass;
|
||||
}
|
||||
|
||||
static int ut_btn_ch_set_pull(uint8_t btn_ch, int8_t lvl, int8_t exp_dout_lvl, uint8_t exp_dout_ch)
|
||||
{
|
||||
printf(" Input: Btn-Ch:%d Din-Lvl:%d\n", btn_ch, lvl);
|
||||
|
||||
mock_board_dout_write_ch(NOT_ACCESED_DOUT_CH);
|
||||
mock_board_dout_write_data(exp_dout_ch, NOT_ACCESED_DOUT_LVL);
|
||||
|
||||
btn_ch_set_pull(btn_ch, lvl);
|
||||
|
||||
uint8_t dout_ch = mock_board_dout_read_ch();
|
||||
int8_t dout = mock_board_dout_read_data(exp_dout_ch);
|
||||
|
||||
printf(" Output: Dout-Ch:%d Dout-Lvl:%d \n", dout_ch, dout);
|
||||
printf("Expected: Dout-Ch:%d Dout-Lvl:%d \n", exp_dout_ch, exp_dout_lvl);
|
||||
|
||||
if((dout==exp_dout_lvl)&&(dout_ch==exp_dout_ch))
|
||||
{
|
||||
printf("PASS\n\n");
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("FAIL\n\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int ut_btn_ch_set_pull_test(void)
|
||||
{
|
||||
printf("******************************************************\n");
|
||||
printf("void btn_ch_set_pull(uint8_t btn_ch, int8_t lvl) \n");
|
||||
|
||||
int test_res;
|
||||
int pass = 1;
|
||||
|
||||
uint8_t btn_ch;
|
||||
int8_t lvl;
|
||||
int8_t exp_dout_lvl;
|
||||
uint8_t exp_dout_ch;
|
||||
|
||||
// Mapping check 1
|
||||
btn_ch = BTN_6;
|
||||
lvl = 0;
|
||||
exp_dout_lvl = BSP_DOUT_LOW;
|
||||
exp_dout_ch = BSP_DOUT5;
|
||||
test_res = ut_btn_ch_set_pull(btn_ch, lvl, exp_dout_lvl, exp_dout_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Mapping check 2
|
||||
btn_ch = BTN_6N;
|
||||
lvl = 1;
|
||||
exp_dout_lvl = BSP_DOUT_HIGH;
|
||||
exp_dout_ch = BSP_DOUT5;
|
||||
test_res = ut_btn_ch_set_pull(btn_ch, lvl, exp_dout_lvl, exp_dout_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Define check 1
|
||||
btn_ch = BTN_6N;
|
||||
lvl = BTN_PULL_LOW;
|
||||
exp_dout_lvl = BSP_DOUT_LOW;
|
||||
exp_dout_ch = BSP_DOUT5;
|
||||
test_res = ut_btn_ch_set_pull(btn_ch, lvl, exp_dout_lvl, exp_dout_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Define check 2
|
||||
btn_ch = BTN_6N;
|
||||
lvl = BTN_PULL_HIGH;
|
||||
exp_dout_lvl = BSP_DOUT_HIGH;
|
||||
exp_dout_ch = BSP_DOUT5;
|
||||
test_res = ut_btn_ch_set_pull(btn_ch, lvl, exp_dout_lvl, exp_dout_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Define check 3
|
||||
btn_ch = BTN_6N;
|
||||
lvl = BTN_PULL_NONE;
|
||||
exp_dout_lvl = BSP_DOUT_HIZ;
|
||||
exp_dout_ch = BSP_DOUT5;
|
||||
test_res = ut_btn_ch_set_pull(btn_ch, lvl, exp_dout_lvl, exp_dout_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Wrong channel
|
||||
btn_ch = 0;
|
||||
lvl = 0;
|
||||
exp_dout_lvl = NOT_ACCESED_DOUT_LVL;
|
||||
exp_dout_ch = NOT_ACCESED_DOUT_CH;
|
||||
test_res = ut_btn_ch_set_pull(btn_ch, lvl, exp_dout_lvl, exp_dout_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
return pass;
|
||||
}
|
||||
12
firmware/tests/ut_hw/ut_buttons.h
Normal file
12
firmware/tests/ut_hw/ut_buttons.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef UT_HW_BUTTONS_H_
|
||||
#define UT_HW_BUTTONS_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int ut_btn_reset_test(void);
|
||||
int ut_btn_process_test(void);
|
||||
int ut_btn_ch_process_test(void);
|
||||
int ut_btn_ch_set_pull_test(void);
|
||||
|
||||
#endif /* UT_HW_BUTTONS_H_ */
|
||||
2638
firmware/tests/ut_hw/ut_hb_control.c
Normal file
2638
firmware/tests/ut_hw/ut_hb_control.c
Normal file
File diff suppressed because it is too large
Load Diff
15
firmware/tests/ut_hw/ut_hb_control.h
Normal file
15
firmware/tests/ut_hw/ut_hb_control.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef UT_HW_HB_CONTROL_H_
|
||||
#define UT_HW_HB_CONTROL_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int ut_hb_is_equal_fb_struct_test(void);
|
||||
int ut_hb_is_equal_ctrl_struct_test(void);
|
||||
|
||||
int ut_hb_init_test(void);
|
||||
int ut_hb_enable_test(void);
|
||||
int ut_hb_disable_test(void);
|
||||
int ut_hb_process_test(void);
|
||||
|
||||
#endif /* UT_HW_HB_CONTROL_H_ */
|
||||
170
firmware/tests/ut_hw/ut_led_display.c
Normal file
170
firmware/tests/ut_hw/ut_led_display.c
Normal file
@@ -0,0 +1,170 @@
|
||||
#include "ut_led_display.h"
|
||||
|
||||
#include "..\mock_board\mock_board_odout.h"
|
||||
|
||||
#include "..\..\src\hw\led_display.h"
|
||||
|
||||
static uint8_t NOT_ACCESD_OD_CHANNEL = 255;
|
||||
static uint8_t NOT_ACCESD_OD_LEVEL = BSP_ODOUT_HIGH;
|
||||
static uint8_t NOT_ACCESD_PERCENT = 255;
|
||||
|
||||
static int ut_led_dsp_set_image(uint8_t image, uint8_t exp_image)
|
||||
{
|
||||
printf(" Input:%x \n", image);
|
||||
|
||||
// Reset image
|
||||
mock_board_odout_write_ch(NOT_ACCESD_OD_CHANNEL);
|
||||
mock_board_odout_write_data(BSP_OD1,NOT_ACCESD_OD_LEVEL);
|
||||
mock_board_odout_write_data(BSP_OD2,NOT_ACCESD_OD_LEVEL);
|
||||
mock_board_odout_write_data(BSP_OD3,NOT_ACCESD_OD_LEVEL);
|
||||
mock_board_odout_write_data(BSP_OD4,NOT_ACCESD_OD_LEVEL);
|
||||
mock_board_odout_write_data(BSP_OD5,NOT_ACCESD_OD_LEVEL);
|
||||
mock_board_odout_write_data(BSP_OD6,NOT_ACCESD_OD_LEVEL);
|
||||
|
||||
led_dsp_set_image(image);
|
||||
|
||||
// Read set OD output image
|
||||
uint8_t i1 = mock_board_odout_read_data(BSP_OD1);
|
||||
uint8_t i2 = mock_board_odout_read_data(BSP_OD2);
|
||||
uint8_t i3 = mock_board_odout_read_data(BSP_OD3);
|
||||
uint8_t i4 = mock_board_odout_read_data(BSP_OD4);
|
||||
uint8_t i5 = mock_board_odout_read_data(BSP_OD5);
|
||||
uint8_t i6 = mock_board_odout_read_data(BSP_OD6);
|
||||
|
||||
uint8_t out_image = 0x00;
|
||||
if(i1==BSP_ODOUT_LOW) out_image |= 0x01;
|
||||
if(i2==BSP_ODOUT_LOW) out_image |= 0x02;
|
||||
if(i3==BSP_ODOUT_LOW) out_image |= 0x04;
|
||||
if(i4==BSP_ODOUT_LOW) out_image |= 0x08;
|
||||
if(i5==BSP_ODOUT_LOW) out_image |= 0x10;
|
||||
if(i6==BSP_ODOUT_LOW) out_image |= 0x20;
|
||||
|
||||
printf(" Output:%x \n", out_image);
|
||||
printf("Expected:%x \n", exp_image);
|
||||
|
||||
if(out_image==exp_image)
|
||||
{
|
||||
printf("PASS\n\n");
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("FAIL\n\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int ut_led_dsp_set_image_test(void)
|
||||
{
|
||||
printf("******************************************************\n");
|
||||
printf("void led_dsp_set_image(uint8_t image) \n");
|
||||
|
||||
int test_res;
|
||||
int pass = 1;
|
||||
|
||||
uint8_t image;
|
||||
uint8_t exp_image;
|
||||
|
||||
// Normal 1
|
||||
image = 0x00;
|
||||
exp_image = 0x00;
|
||||
test_res = ut_led_dsp_set_image(image, exp_image);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Normal 1
|
||||
image = 0x3F;
|
||||
exp_image = 0x3F;
|
||||
test_res = ut_led_dsp_set_image(image, exp_image);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Normal 1
|
||||
image = 0xAA;
|
||||
exp_image = 0x2A;
|
||||
test_res = ut_led_dsp_set_image(image, exp_image);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Normal 1
|
||||
image = 0x55;
|
||||
exp_image = 0x15;
|
||||
test_res = ut_led_dsp_set_image(image, exp_image);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
return pass;
|
||||
}
|
||||
|
||||
static int ut_led_dsp_backligth_set(uint8_t percent, uint8_t exp_percent)
|
||||
{
|
||||
printf(" Input:%d \n", percent);
|
||||
|
||||
// Reset image
|
||||
mock_board_odout_write_pwm(NOT_ACCESD_PERCENT);
|
||||
|
||||
led_dsp_backligth_set(percent);
|
||||
|
||||
// Read set OD output image
|
||||
uint8_t pwm = mock_board_odout_read_pwm();
|
||||
|
||||
printf(" Output:%d \n", pwm);
|
||||
printf("Expected:%d \n", exp_percent);
|
||||
|
||||
if(pwm==exp_percent)
|
||||
{
|
||||
printf("PASS\n\n");
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("FAIL\n\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int ut_led_dsp_backligth_set_test(void)
|
||||
{
|
||||
printf("******************************************************\n");
|
||||
printf("void led_dsp_backligth_set(uint8_t percent) \n");
|
||||
|
||||
int test_res;
|
||||
int pass = 1;
|
||||
|
||||
uint8_t percent;
|
||||
uint8_t exp_percent;
|
||||
|
||||
// Normal 1
|
||||
percent = 0;
|
||||
exp_percent = 0;
|
||||
test_res = ut_led_dsp_backligth_set(percent, exp_percent);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Normal 1
|
||||
percent = 25;
|
||||
exp_percent = 25;
|
||||
test_res = ut_led_dsp_backligth_set(percent, exp_percent);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Normal 1
|
||||
percent = 50;
|
||||
exp_percent = 50;
|
||||
test_res = ut_led_dsp_backligth_set(percent, exp_percent);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Normal 1
|
||||
percent = 75;
|
||||
exp_percent = 75;
|
||||
test_res = ut_led_dsp_backligth_set(percent, exp_percent);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Normal 1
|
||||
percent = 100;
|
||||
exp_percent = 100;
|
||||
test_res = ut_led_dsp_backligth_set(percent, exp_percent);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Normal 1
|
||||
percent = 200;
|
||||
exp_percent = 200;
|
||||
test_res = ut_led_dsp_backligth_set(percent, exp_percent);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
return pass;
|
||||
}
|
||||
10
firmware/tests/ut_hw/ut_led_display.h
Normal file
10
firmware/tests/ut_hw/ut_led_display.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef UT_HW_LED_DISPLAY_H_
|
||||
#define UT_HW_LED_DISPLAY_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int ut_led_dsp_set_image_test(void);
|
||||
int ut_led_dsp_backligth_set_test(void);
|
||||
|
||||
#endif /* UT_HW_LED_DISPLAY_H_ */
|
||||
48
firmware/tests/ut_hw/ut_startup.c
Normal file
48
firmware/tests/ut_hw/ut_startup.c
Normal file
@@ -0,0 +1,48 @@
|
||||
#include "ut_startup.h"
|
||||
|
||||
#include "..\mock_board\mock_board_setup.h"
|
||||
|
||||
#include "..\..\src\hw\startup.h"
|
||||
|
||||
static int ut_hw_startup(uint8_t exp_called)
|
||||
{
|
||||
printf(" Input: \n");
|
||||
|
||||
mock_board_setup_reset_called();
|
||||
|
||||
hw_startup();
|
||||
|
||||
uint8_t called = mock_board_setup_read_called();
|
||||
|
||||
printf(" Output: Called:%d \n", called);
|
||||
printf("Expected: Called:%d \n", exp_called);
|
||||
|
||||
if(called==exp_called)
|
||||
{
|
||||
printf("PASS\n\n");
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("FAIL\n\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int ut_hw_startup_test(void)
|
||||
{
|
||||
printf("******************************************************\n");
|
||||
printf("void hw_startup(void) \n");
|
||||
|
||||
int test_res;
|
||||
int pass = 1;
|
||||
|
||||
uint8_t exp_called;
|
||||
|
||||
// Normal 1
|
||||
exp_called = 1;
|
||||
test_res = ut_hw_startup(exp_called);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
return pass;
|
||||
}
|
||||
9
firmware/tests/ut_hw/ut_startup.h
Normal file
9
firmware/tests/ut_hw/ut_startup.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef UT_HW_STARTUP_H_
|
||||
#define UT_HW_STARTUP_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int ut_hw_startup_test(void);
|
||||
|
||||
#endif /* UT_HW_STARTUP_H_ */
|
||||
Reference in New Issue
Block a user