summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2022-11-07 16:38:58 +1100
committerjacqueline <me@jacqueline.id.au>2022-11-07 16:38:58 +1100
commit6584060296042d8af440b21024ee7996e5034ec1 (patch)
treec4bd79361894a669a1f2f2778f5dff01416f779a
parentc29c218b85a4fe7cff037ead66ef45966c1c6542 (diff)
downloadtangara-fw-6584060296042d8af440b21024ee7996e5034ec1.tar.gz
Add a unit test app + example tests
-rw-r--r--.env1
-rw-r--r--.gitignore5
-rw-r--r--CMakeLists.txt34
-rw-r--r--common.cmake33
-rw-r--r--src/drivers/test/CMakeLists.txt1
-rw-r--r--src/drivers/test/test_example.cpp9
-rw-r--r--test/CMakeLists.txt10
-rw-r--r--test/main/CMakeLists.txt1
-rw-r--r--test/main/main.c22
-rw-r--r--test/sdkconfig.defaults2
10 files changed, 86 insertions, 32 deletions
diff --git a/.env b/.env
index 37afa5da..d6f9345a 100644
--- a/.env
+++ b/.env
@@ -1,4 +1,5 @@
repo_dir=$(cd "$(dirname "$_")" && pwd)
+export PROJ_PATH=$repo_dir
export ADF_PATH=$repo_dir/lib/esp-adf
export IDF_PATH=$ADF_PATH/esp-idf
. $IDF_PATH/export.sh
diff --git a/.gitignore b/.gitignore
index 12657b40..95ed8bd6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,3 +5,8 @@ build.clang/
sdkconfig.old
.vscode
compile_commands.json
+warnings.txt
+
+test/build/
+test/dependencies.lock
+test/sdkconfig
diff --git a/CMakeLists.txt b/CMakeLists.txt
index eaf575af..a3c93d09 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,34 +1,4 @@
-# For more information about build system see
-# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html
-cmake_minimum_required(VERSION 3.8)
-set(CMAKE_CXX_STANDARD 17)
-set(CMAKE_CXX_STANDARD_REQUIRED ON)
+cmake_minimum_required(VERSION 3.16)
+include(common.cmake)
-# ESP-ADF clobbers EXTRA_COMPONENT_DIRS, so include it first.
-include($ENV{ADF_PATH}/CMakeLists.txt)
-
-# Build only the subset of components that we actually depend on.
-set(COMPONENTS "")
-
-# External dependencies
-list(APPEND EXTRA_COMPONENT_DIRS "lib/result")
-list(APPEND EXTRA_COMPONENT_DIRS "lib/lvgl")
-
-# Project components
-list(APPEND EXTRA_COMPONENT_DIRS "src")
-
-# Additional warnings used when compiling our components.
-# Unable to be used due to issues in ESP-IDF includes are: -Wpedantic
-# -Wuseless-cast -Wconversion -Wold-style-cast -Wsign-conversion -Wcast-align
-set(EXTRA_WARNINGS "-Wshadow" "-Wnon-virtual-dtor" "-Wunused"
- "-Woverloaded-virtual" "-Wmisleading-indentation" "-Wduplicated-cond"
- "-Wduplicated-branches" "-Wlogical-op" "-Wnull-dereference"
- "-Wdouble-promotion" "-Wformat=2" "-Wimplicit-fallthrough")
-
-include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(gay-ipod-fw)
-
-# Extra build flags that should apply to the entire build. This should mostly
-# just be used to setting flags that our external dependencies requires.
-# Otherwise, prefer adding per-component build flags to keep things neat.
-idf_build_set_property(COMPILE_OPTIONS "-DRESULT_DISABLE_EXCEPTIONS -DLV_CONF_INCLUDE_SIMPLE" APPEND)
diff --git a/common.cmake b/common.cmake
new file mode 100644
index 00000000..22bdd63f
--- /dev/null
+++ b/common.cmake
@@ -0,0 +1,33 @@
+# For more information about build system see
+# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html
+set(CMAKE_CXX_STANDARD 17)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+
+# ESP-ADF clobbers EXTRA_COMPONENT_DIRS, so include it first.
+include($ENV{ADF_PATH}/CMakeLists.txt)
+
+# Build only the subset of components that we actually depend on.
+set(COMPONENTS "")
+
+# External dependencies
+list(APPEND EXTRA_COMPONENT_DIRS "$ENV{PROJ_PATH}/lib/result")
+list(APPEND EXTRA_COMPONENT_DIRS "$ENV{PROJ_PATH}/lib/lvgl")
+
+# Project components
+list(APPEND EXTRA_COMPONENT_DIRS "$ENV{PROJ_PATH}/src")
+
+include($ENV{IDF_PATH}/tools/cmake/project.cmake)
+
+# Additional warnings used when compiling our components.
+# Unable to be used due to issues in ESP-IDF includes are: -Wpedantic
+# -Wuseless-cast -Wconversion -Wold-style-cast -Wsign-conversion -Wcast-align
+set(EXTRA_WARNINGS "-Wshadow" "-Wnon-virtual-dtor" "-Wunused"
+ "-Woverloaded-virtual" "-Wmisleading-indentation" "-Wduplicated-cond"
+ "-Wduplicated-branches" "-Wlogical-op" "-Wnull-dereference"
+ "-Wdouble-promotion" "-Wformat=2" "-Wimplicit-fallthrough")
+
+# Extra build flags that should apply to the entire build. This should mostly
+# just be used to setting flags that our external dependencies requires.
+# Otherwise, prefer adding per-component build flags to keep things neat.
+idf_build_set_property(
+ COMPILE_OPTIONS "-DRESULT_DISABLE_EXCEPTIONS -DLV_CONF_INCLUDE_SIMPLE" APPEND)
diff --git a/src/drivers/test/CMakeLists.txt b/src/drivers/test/CMakeLists.txt
new file mode 100644
index 00000000..52e981fc
--- /dev/null
+++ b/src/drivers/test/CMakeLists.txt
@@ -0,0 +1 @@
+idf_component_register(SRC_DIRS "." INCLUDE_DIRS "." REQUIRES cmock drivers)
diff --git a/src/drivers/test/test_example.cpp b/src/drivers/test/test_example.cpp
new file mode 100644
index 00000000..2a43341a
--- /dev/null
+++ b/src/drivers/test/test_example.cpp
@@ -0,0 +1,9 @@
+#include "unity.h"
+
+TEST_CASE("Example test case", "[cooltag]") {
+ TEST_ASSERT_EQUAL(0, 0);
+}
+
+TEST_CASE("test that doesn't run", "[cooltag][ignore]") {
+ TEST_ASSERT_EQUAL(0, 1);
+}
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
new file mode 100644
index 00000000..ddcc063a
--- /dev/null
+++ b/test/CMakeLists.txt
@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 3.16)
+include(../common.cmake)
+
+# Treat warnings as errors for test purposes.
+list(APPEND EXTRA_WARNINGS "-Werror")
+
+# List all components that include tests here.
+set(TEST_COMPONENTS "drivers")
+
+project(device_tests)
diff --git a/test/main/CMakeLists.txt b/test/main/CMakeLists.txt
new file mode 100644
index 00000000..52a3b94c
--- /dev/null
+++ b/test/main/CMakeLists.txt
@@ -0,0 +1 @@
+idf_component_register(SRCS "main.c" INCLUDE_DIRS ".")
diff --git a/test/main/main.c b/test/main/main.c
new file mode 100644
index 00000000..6806aa2e
--- /dev/null
+++ b/test/main/main.c
@@ -0,0 +1,22 @@
+#include <stdio.h>
+#include <string.h>
+#include "unity.h"
+
+static void print_banner(const char* text);
+
+void app_main(void)
+{
+ print_banner("Running tests without [ignore] tag");
+ UNITY_BEGIN();
+ unity_run_tests_by_tag("[ignore]", true);
+ UNITY_END();
+
+ print_banner("Starting interactive test menu");
+ unity_run_menu();
+}
+
+static void print_banner(const char* text)
+{
+ printf("\n#### %s #####\n\n", text);
+}
+
diff --git a/test/sdkconfig.defaults b/test/sdkconfig.defaults
new file mode 100644
index 00000000..80ff5eb3
--- /dev/null
+++ b/test/sdkconfig.defaults
@@ -0,0 +1,2 @@
+CONFIG_ESP_TASK_WDT=n
+