Unbreak the tests build

custom
jacqueline 10 months ago
parent 2d04e13cc6
commit 8db57d6dc5
  1. 2
      src/drivers/test/CMakeLists.txt
  2. 8
      src/drivers/test/test_adc.cpp
  3. 16
      src/drivers/test/test_dac.cpp
  4. 31
      src/drivers/test/test_gpio_expander.cpp
  5. 16
      src/drivers/test/test_storage.cpp
  6. 2
      src/drivers/wm8523.cpp
  7. 3
      src/memory/memory_resource.cpp
  8. 18
      test/CMakeLists.txt
  9. 8
      test/fixtures/CMakeLists.txt
  10. 2
      test/fixtures/i2c_fixture.hpp
  11. 2
      test/fixtures/spi_fixture.hpp
  12. 10
      test/main/CMakeLists.txt
  13. 4
      test/main/main.cpp
  14. 1
      test/sdkconfig.test

@ -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)

@ -4,7 +4,7 @@
* SPDX-License-Identifier: GPL-3.0-only
*/
#include "battery.hpp"
#include "drivers/adc.hpp"
#include <cstdint>
@ -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.
}
}

@ -4,7 +4,8 @@
* SPDX-License-Identifier: GPL-3.0-only
*/
#include "dac.hpp"
#include <stdint.h>
#include "drivers/wm8523.hpp"
#include <cstdint>
@ -16,16 +17,15 @@
namespace drivers {
TEST_CASE("dac configuration", "[integration]") {
TEST_CASE("dac is present", "[integration]") {
I2CFixture i2c;
IGpios expander;
cpp::result<AudioDac*, AudioDac::Error> dac_res = AudioDac::create(&expander);
REQUIRE(dac_res.has_value());
std::unique_ptr<AudioDac> 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

@ -1,31 +0,0 @@
/*
* Copyright 2023 jacqueline <me@jacqueline.id.au>
*
* 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

@ -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<IGpios> gpios{Gpios::Create(false)};
{
std::unique_ptr<SdStorage> result(SdStorage::create(&expander).value());
std::unique_ptr<SdStorage> 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");

@ -50,7 +50,7 @@ auto ReadRegister(Register reg) -> std::optional<uint16_t> {
if (transaction.Execute() != ESP_OK) {
return {};
}
return (msb << 8) & lsb;
return (msb << 8) | lsb;
}
auto WriteRegister(Register reg, uint16_t data) -> bool {

@ -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;
}

@ -1,8 +1,6 @@
/*
* Copyright 2023 jacqueline <me@jacqueline.id.au>
*
* SPDX-License-Identifier: GPL-3.0-only
*/
# Copyright 2024 jacqueline <me@jacqueline.id.au>
#
# 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)

@ -1,7 +1,5 @@
/*
* Copyright 2023 jacqueline <me@jacqueline.id.au>
*
* SPDX-License-Identifier: GPL-3.0-only
*/
# Copyright 2023 jacqueline <me@jacqueline.id.au>
#
# SPDX-License-Identifier: GPL-3.0-only
idf_component_register(INCLUDE_DIRS "." REQUIRES drivers)

@ -7,7 +7,7 @@
#pragma once
#include "catch2/catch.hpp"
#include "i2c.hpp"
#include "drivers/i2c.hpp"
class I2CFixture {
public:

@ -7,7 +7,7 @@
#pragma once
#include "catch2/catch.hpp"
#include "spi.hpp"
#include "drivers/spi.hpp"
class SpiFixture {
public:

@ -1,10 +1,8 @@
/*
* Copyright 2023 jacqueline <me@jacqueline.id.au>
*
* SPDX-License-Identifier: GPL-3.0-only
*/
# Copyright 2023 jacqueline <me@jacqueline.id.au>
#
# SPDX-License-Identifier: GPL-3.0-only
idf_component_register(
SRCS "main.cpp"
INCLUDE_DIRS "."
REQUIRES "catch2 dev_console")
REQUIRES "catch2 tangara")

@ -8,11 +8,11 @@
#include <cstdint>
#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{

@ -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"

Loading…
Cancel
Save