From 8db57d6dc5cf5c83cffd393a37ca37bc1a67f1af Mon Sep 17 00:00:00 2001 From: jacqueline Date: Tue, 25 Jun 2024 15:23:51 +1000 Subject: [PATCH] Unbreak the tests build --- src/drivers/test/CMakeLists.txt | 2 +- .../test/{test_battery.cpp => test_adc.cpp} | 8 ++--- src/drivers/test/test_dac.cpp | 16 +++++----- src/drivers/test/test_gpio_expander.cpp | 31 ------------------- src/drivers/test/test_storage.cpp | 16 +++++----- src/drivers/wm8523.cpp | 2 +- src/memory/memory_resource.cpp | 3 +- test/CMakeLists.txt | 18 +++++------ test/fixtures/CMakeLists.txt | 8 ++--- test/fixtures/i2c_fixture.hpp | 2 +- test/fixtures/spi_fixture.hpp | 2 +- test/main/CMakeLists.txt | 10 +++--- test/main/main.cpp | 4 +-- test/sdkconfig.test | 1 + 14 files changed, 44 insertions(+), 79 deletions(-) rename src/drivers/test/{test_battery.cpp => test_adc.cpp} (65%) delete mode 100644 src/drivers/test/test_gpio_expander.cpp diff --git a/src/drivers/test/CMakeLists.txt b/src/drivers/test/CMakeLists.txt index 90e7b3a1..ff1dab0b 100644 --- a/src/drivers/test/CMakeLists.txt +++ b/src/drivers/test/CMakeLists.txt @@ -3,5 +3,5 @@ # SPDX-License-Identifier: GPL-3.0-only idf_component_register( - SRCS "test_storage.cpp" "test_gpio_expander.cpp" "test_battery.cpp" "test_dac.cpp" + SRCS "test_adc.cpp" "test_storage.cpp" "test_dac.cpp" INCLUDE_DIRS "." REQUIRES catch2 cmock drivers fixtures) diff --git a/src/drivers/test/test_battery.cpp b/src/drivers/test/test_adc.cpp similarity index 65% rename from src/drivers/test/test_battery.cpp rename to src/drivers/test/test_adc.cpp index 690eb2b7..df103af3 100644 --- a/src/drivers/test/test_battery.cpp +++ b/src/drivers/test/test_adc.cpp @@ -4,7 +4,7 @@ * SPDX-License-Identifier: GPL-3.0-only */ -#include "battery.hpp" +#include "drivers/adc.hpp" #include @@ -13,12 +13,12 @@ namespace drivers { TEST_CASE("battery measurement", "[integration]") { - Battery battery; + AdcBattery battery; SECTION("voltage is within range") { uint32_t mv = battery.Millivolts(); - REQUIRE(mv <= 2200); // Plugged in, no battery. - REQUIRE(mv >= 1000); + REQUIRE(mv <= 4210); // Should never be charged above this. + REQUIRE(mv >= 3000); // Should never be discharged below this. } } diff --git a/src/drivers/test/test_dac.cpp b/src/drivers/test/test_dac.cpp index 2269f280..11c69c14 100644 --- a/src/drivers/test/test_dac.cpp +++ b/src/drivers/test/test_dac.cpp @@ -4,7 +4,8 @@ * SPDX-License-Identifier: GPL-3.0-only */ -#include "dac.hpp" +#include +#include "drivers/wm8523.hpp" #include @@ -16,16 +17,15 @@ namespace drivers { -TEST_CASE("dac configuration", "[integration]") { +TEST_CASE("dac is present", "[integration]") { I2CFixture i2c; - IGpios expander; - cpp::result dac_res = AudioDac::create(&expander); - REQUIRE(dac_res.has_value()); - std::unique_ptr dac(dac_res.value()); - auto power_state = dac->ReadPowerState(); + SECTION("device id is correct") { + auto res = wm8523::ReadRegister(wm8523::Register::kReset); - REQUIRE(power_state.first == true); // booted + REQUIRE(res.has_value()); + REQUIRE(res.value() == 0x8523); + } } } // namespace drivers diff --git a/src/drivers/test/test_gpio_expander.cpp b/src/drivers/test/test_gpio_expander.cpp deleted file mode 100644 index 7c323313..00000000 --- a/src/drivers/test/test_gpio_expander.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2023 jacqueline - * - * SPDX-License-Identifier: GPL-3.0-only - */ - -#include "drivers/gpios.hpp" - -#include "catch2/catch.hpp" - -#include "drivers/i2c.hpp" -#include "i2c_fixture.hpp" - -namespace drivers { - -TEST_CASE("gpio expander", "[integration]") { - I2CFixture i2c; - IGpios expander; - SECTION("with() writes when ") { - // Initial value. - expander.Read(); - REQUIRE(expander.get_input(IGpios::KEY_DOWN) == true); - - expander.with([&](auto& gpio) { gpio.set_pin(IGpios::KEY_DOWN, false); }); - - expander.Read(); - REQUIRE(expander.get_input(IGpios::KEY_DOWN) == false); - } -} - -} // namespace drivers diff --git a/src/drivers/test/test_storage.cpp b/src/drivers/test/test_storage.cpp index f97a0a85..5af40052 100644 --- a/src/drivers/test/test_storage.cpp +++ b/src/drivers/test/test_storage.cpp @@ -22,31 +22,31 @@ namespace drivers { -static const std::pmr::string kTestFilename = "test"; -static const std::pmr::string kTestFilePath = - std::pmr::string(kStoragePath) + "/" + kTestFilename; +static const std::string kTestFilename = "test"; +static const std::string kTestFilePath = + std::string(kStoragePath) + "/" + kTestFilename; TEST_CASE("sd card storage", "[integration]") { I2CFixture i2c; SpiFixture spi; - IGpios expander; + std::unique_ptr gpios{Gpios::Create(false)}; { - std::unique_ptr result(SdStorage::create(&expander).value()); + std::unique_ptr result(SdStorage::Create(*gpios).value()); SECTION("write to a file") { { std::ofstream test_file; - test_file.open(kTestFilePath.c_str()); + test_file.open(kTestFilePath); test_file << "hello here is some test"; test_file.close(); } SECTION("read from a file") { std::ifstream test_file; - test_file.open(kTestFilePath.c_str()); + test_file.open(kTestFilePath); - std::pmr::string line; + std::string line; REQUIRE(std::getline(test_file, line)); REQUIRE(line == "hello here is some test"); diff --git a/src/drivers/wm8523.cpp b/src/drivers/wm8523.cpp index 26316387..177679f1 100644 --- a/src/drivers/wm8523.cpp +++ b/src/drivers/wm8523.cpp @@ -50,7 +50,7 @@ auto ReadRegister(Register reg) -> std::optional { if (transaction.Execute() != ESP_OK) { return {}; } - return (msb << 8) & lsb; + return (msb << 8) | lsb; } auto WriteRegister(Register reg, uint16_t data) -> bool { diff --git a/src/memory/memory_resource.cpp b/src/memory/memory_resource.cpp index 74c0bc48..3351a1b9 100644 --- a/src/memory/memory_resource.cpp +++ b/src/memory/memory_resource.cpp @@ -27,7 +27,8 @@ void Resource::do_deallocate(void* p, heap_caps_free(p); } -bool Resource::do_is_equal(const std::pmr::memory_resource& other) const { +bool Resource::do_is_equal( + const std::pmr::memory_resource& other) const noexcept { return this == &other; } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 1b90a614..072a350f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,8 +1,6 @@ -/* - * Copyright 2023 jacqueline - * - * SPDX-License-Identifier: GPL-3.0-only - */ +# Copyright 2024 jacqueline +# +# SPDX-License-Identifier: GPL-3.0-only cmake_minimum_required(VERSION 3.16) include($ENV{PROJ_PATH}/tools/cmake/common.cmake) @@ -17,18 +15,18 @@ idf_build_set_property( #list(APPEND EXTRA_WARNINGS "-Werror") list(APPEND EXTRA_COMPONENT_DIRS - "$ENV{PROJ_PATH}/src/audio" "$ENV{PROJ_PATH}/src/codecs" - "$ENV{PROJ_PATH}/src/database" "$ENV{PROJ_PATH}/src/drivers" + "$ENV{PROJ_PATH}/src/graphics" + "$ENV{PROJ_PATH}/src/locale" "$ENV{PROJ_PATH}/src/memory" + "$ENV{PROJ_PATH}/src/tangara" "$ENV{PROJ_PATH}/src/tasks" - "$ENV{PROJ_PATH}/src/ui" - "$ENV{PROJ_PATH}/src/dev_console" + "$ENV{PROJ_PATH}/src/util" "fixtures" ) # List all components that include tests here. -set(TEST_COMPONENTS "codecs" "database" "drivers") +set(TEST_COMPONENTS "drivers") project(device_tests) diff --git a/test/fixtures/CMakeLists.txt b/test/fixtures/CMakeLists.txt index 9895cf8d..44deefcd 100644 --- a/test/fixtures/CMakeLists.txt +++ b/test/fixtures/CMakeLists.txt @@ -1,7 +1,5 @@ -/* - * Copyright 2023 jacqueline - * - * SPDX-License-Identifier: GPL-3.0-only - */ +# Copyright 2023 jacqueline +# +# SPDX-License-Identifier: GPL-3.0-only idf_component_register(INCLUDE_DIRS "." REQUIRES drivers) diff --git a/test/fixtures/i2c_fixture.hpp b/test/fixtures/i2c_fixture.hpp index e7e5d42d..dd33fe9e 100644 --- a/test/fixtures/i2c_fixture.hpp +++ b/test/fixtures/i2c_fixture.hpp @@ -7,7 +7,7 @@ #pragma once #include "catch2/catch.hpp" -#include "i2c.hpp" +#include "drivers/i2c.hpp" class I2CFixture { public: diff --git a/test/fixtures/spi_fixture.hpp b/test/fixtures/spi_fixture.hpp index a5e9cac3..d29977eb 100644 --- a/test/fixtures/spi_fixture.hpp +++ b/test/fixtures/spi_fixture.hpp @@ -7,7 +7,7 @@ #pragma once #include "catch2/catch.hpp" -#include "spi.hpp" +#include "drivers/spi.hpp" class SpiFixture { public: diff --git a/test/main/CMakeLists.txt b/test/main/CMakeLists.txt index d629441d..2cbd90fd 100644 --- a/test/main/CMakeLists.txt +++ b/test/main/CMakeLists.txt @@ -1,10 +1,8 @@ -/* - * Copyright 2023 jacqueline - * - * SPDX-License-Identifier: GPL-3.0-only - */ +# Copyright 2023 jacqueline +# +# SPDX-License-Identifier: GPL-3.0-only idf_component_register( SRCS "main.cpp" INCLUDE_DIRS "." - REQUIRES "catch2 dev_console") + REQUIRES "catch2 tangara") diff --git a/test/main/main.cpp b/test/main/main.cpp index 2a935397..57be6b24 100644 --- a/test/main/main.cpp +++ b/test/main/main.cpp @@ -8,11 +8,11 @@ #include +#include "catch_runner.hpp" #include "esp_console.h" #include "esp_log.h" -#include "catch_runner.hpp" -#include "console.hpp" +#include "dev_console/console.hpp" void RegisterCatch2() { esp_console_cmd_t cmd{ diff --git a/test/sdkconfig.test b/test/sdkconfig.test index 42c5d0d0..c0fbf922 100644 --- a/test/sdkconfig.test +++ b/test/sdkconfig.test @@ -10,3 +10,4 @@ CONFIG_COMPILER_CXX_RTTI=y CONFIG_COMPILER_STACK_CHECK_MODE_STRONG=y CONFIG_COMPILER_STACK_CHECK=y CONFIG_ESP_TASK_WDT=y +CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="../partitions.csv"