Skip to content

Commit

Permalink
unittest skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
vroland committed Feb 6, 2024
1 parent 54a63ca commit 60168a6
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 6 deletions.
11 changes: 11 additions & 0 deletions examples/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This is the project CMakeLists.txt file for the test subproject
cmake_minimum_required(VERSION 3.16)

# Add newly added components to one of these lines:
# 1. Add here if the component is compatible with IDF >= v4.3
set(EXTRA_COMPONENT_DIRS "../../")

set(TEST_COMPONENTS "epdiy")

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(epdiy_testrunner)
1 change: 1 addition & 0 deletions examples/test/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
idf_component_register(SRCS "main.c" INCLUDE_DIRS ".")
17 changes: 17 additions & 0 deletions examples/test/main/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <stdio.h>
#include <unity.h>

static void print_banner(const char* text)
{
printf("\n#### %s #####\n\n", text);
}


void app_main(void)
{
print_banner("Running all the registered tests");
UNITY_BEGIN();
unity_run_all_tests();
UNITY_END();
}

11 changes: 5 additions & 6 deletions src/board/epd_board_v7.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,20 +162,21 @@ static void epd_board_deinit() {

int tries = 0;
while (!((pca9555_read_input(config_reg.port, 1) & 0xC0) == 0x80)) {
if (tries >= 500) {
if (tries >= 50) {
ESP_LOGE("epdiy", "failed to shut down TPS65185!");
break;
}
tries++;
vTaskDelay(1);
printf("%X\n", pca9555_read_input(config_reg.port, 1));
}

// Not sure why we need this delay, but the TPS65185 seems to generate an interrupt after some time that needs to be cleared.
vTaskDelay(500);
vTaskDelay(50);
pca9555_read_input(config_reg.port, 0);
pca9555_read_input(config_reg.port, 1);
ESP_LOGI("epdiy", "going to sleep.");
i2c_driver_delete(EPDIY_I2C_PORT);

gpio_uninstall_isr_service();
}

static void epd_board_set_ctrl(epd_ctrl_state_t *state, const epd_ctrl_state_t * const mask) {
Expand Down Expand Up @@ -214,8 +215,6 @@ static void epd_board_poweron(epd_ctrl_state_t *state) {
while (!(pca9555_read_input(config_reg.port, 1) & CFG_PIN_PWRGOOD)) {
}

printf("PG is up\n");

ESP_ERROR_CHECK(tps_write_register(config_reg.port, TPS_REG_ENABLE, 0x3F));

tps_set_vcom(config_reg.port, vcom);
Expand Down
3 changes: 3 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
idf_component_register(SRC_DIRS "."
INCLUDE_DIRS "."
REQUIRES unity epdiy)
43 changes: 43 additions & 0 deletions test/test_initialization.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <unity.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

#include "epd_board.h"
#include "epdiy.h"
#include "epd_display.h"

TEST_CASE("Mean of an empty array is zero", "[mean]")
{
const int values[] = { 0 };
TEST_ASSERT_EQUAL(1, 1);
}

TEST_CASE("V7 initialization and deinitialization works", "[epdiy]")
{
epd_init(&epd_board_v7, &ED097TC2, EPD_OPTIONS_DEFAULT);

epd_poweron();
vTaskDelay(2);
epd_poweroff();

epd_deinit();
}

TEST_CASE("V7 re-initialization works", "[epdiy]")
{
epd_init(&epd_board_v7, &ED097TC2, EPD_OPTIONS_DEFAULT);

epd_poweron();
vTaskDelay(2);
epd_poweroff();

epd_deinit();

epd_init(&epd_board_v7, &ED097TC2, EPD_OPTIONS_DEFAULT);

epd_poweron();
vTaskDelay(2);
epd_poweroff();

epd_deinit();
}

0 comments on commit 60168a6

Please sign in to comment.