Hi I am working on C project for ESP32 using the platformio enviroment. I am using the unity test framework provided from the platformio env. I would like to unit test the following function
float reading_board_temp(void)
{
uint32_t adc_reading = 0;
float board_temp = 0;
for (int i = 0; i < NO_OF_SAMPLES; i++)
{
adc_reading += adc1_get_raw((adc1_channel_t)adc_1_ch_board_temp);
vTaskDelay(TEN_TICKS_DELAY);
}
adc_reading /= NO_OF_SAMPLES;
uint32_t voltage = esp_adc_cal_raw_to_voltage(adc_reading, adc_chars_board_temp);
board_temp = (voltage - MCP9700AT_OFFSET)/TEMP_DIVIDER;
return board_temp;
}
This is the test file I have created always in platformio
#include <Arduino.h>
#include <unity.h>
#include <gpioa_module.h>
void test_board_temp()
{
float expected_temp = 35;
float risult_reading = 0;
risult_reading = reading_board_temp ();
TEST_ASSERT_EQUAL(expected_temp, risult_reading);
}
void setUp(void)
{
}
void tearDown(void)
{
}
void setup()
{
// NOTE!!! Wait for >2 secs
// if board doesn't support software reset via Serial.DTR/RTS
delay(2000);
UNITY_BEGIN();
RUN_TEST(test_board_temp);
RUN_TEST(test_example2);
UNITY_END();
}
void loop()
{
}
When I try to test in the esp32 it seems to freeze.
How can I test the function removing or faking the hw dependancies ?
Thanks a lot for your kind reply.