Skip to content

Commit

Permalink
Integration test (#114)
Browse files Browse the repository at this point in the history
* Add integration test

* Change provisioning stop timeout to 5 seconds

The frontend polls with a 1 second period, and the deafult 1 second
timeout would sometimes cause the provisioning to stop before the
frontend receives a response.

* Add test for midi mapping, fix bugs in proto conversion

* Test all midi mapping types

* Add console component

* Integrate UART logging with test

* Skip firmware flashing if already done

* Add wifi config console command to firmware

* Update API test setup
  • Loading branch information
Barabas5532 authored Jun 26, 2024
1 parent d0204b5 commit 3b568bb
Show file tree
Hide file tree
Showing 36 changed files with 1,350 additions and 227 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ env:
CMAKE_C_COMPILER_LAUNCHER: ccache
CMAKE_CXX_COMPILER_LAUNCHER: ccache
CCACHE_DIR: /ccache
FLUTTER_VERSION: '3.16.0'
FLUTTER_VERSION: '3.16.9'
FLUTTER_CHANNEL: 'stable'

jobs:
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@
[submodule "thirdparty/esp-idf-components/esp32-fft/esp32-fft"]
path = thirdparty/esp-idf-components/esp32-fft/esp32-fft
url = https://github.com/Barabas5532/esp32-fft.git
[submodule "thirdparty/esp-idf-components/embedded_cli/EmbeddedCLI"]
path = thirdparty/esp-idf-components/embedded_cli/EmbeddedCLI
url = https://github.com/AndreRenaud/EmbeddedCLI.git
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,26 @@
[![Firmware docs](https://img.shields.io/badge/docs-firmware-blue)](https://shrapneldsp.github.io/ShrapnelMonorepo/firmware-docs/)
[![Frontend docs](https://img.shields.io/badge/docs-frontend-blue)](https://shrapneldsp.github.io/ShrapnelMonorepo/frontend-docs/)
[![Requirements](https://img.shields.io/badge/docs-requirements-blue)](https://shrapneldsp.github.io/ShrapnelMonorepo/requirements/)

# Running integration tests

Prerequisites:

1. Set up Wi-Fi network for testing:
* Must use 2.4 GHz band, ShrapnelDSP device has no 5 GHz support.
* Ethernet connection to PC running the test so it stays online while connecting to the
ShrapnelDSP access point for provisioning.
* Static IP address set up for the ShrapnelDSP device.
2. Set up the development machine for running integration tests:
* [NetworkManager](https://wiki.archlinux.org/title/NetworkManager) and the nmcli tool is is
required to connect to the ShrapnelDSP device for provisioning.
* Create a NetworkManager connection profile for the ShrapnelDSP device's access point. The name
of the profile must be exactly the same as the access point's SSID. This can be done easily by
connecting to the access point using nmtui. It creates a profile with the correct settings by
default.
* Create a test_config.json file at the root of the repository. This must be a JSON file
containing a single object with keys DUT_IP_ADDRESS, NETWORK_SSID, NETWORK_PASSPHRASE,
FIRMWARE_BINARY_PATH. The network credentials are used during Wi-Fi provisioning. The firmware
binary path should contain bootloader.bin, partition-table.bin and esp32-dsp.bin files.

To execute tests, `cd frontend`, then use `run_api_test.sh` or `run_integration_test.sh`.
1 change: 1 addition & 0 deletions firmware/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions firmware/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ if(ESP_PLATFORM)
add_subdirectory(../effects/gate gate)
add_subdirectory(../effects/valvestate valvestate)
add_subdirectory(../effects/wah wah)
add_subdirectory(../thirdparty/esp-idf-components/etl etl)
add_subdirectory(../thirdparty/esp-idf-components/cppcodec cppcodec)
add_subdirectory(../thirdparty/esp-idf-components/nanopb nanopb)
add_subdirectory(../thirdparty/esp-idf-components/embedded_cli embedded_cli)
add_subdirectory(../thirdparty/esp-idf-components/esp32-fft esp32-fft)
add_subdirectory(../thirdparty/esp-idf-components/etl etl)
add_subdirectory(../thirdparty/esp-idf-components/nanopb nanopb)
add_subdirectory(components/api)
add_subdirectory(components/audio)
add_subdirectory(components/audio_events)
Expand All @@ -47,6 +48,7 @@ if(ESP_PLATFORM)
add_subdirectory(components/persistence)
add_subdirectory(components/presets)
add_subdirectory(components/server)
add_subdirectory(components/shrapnel_console)
add_subdirectory(components/wifi)

return()
Expand Down
13 changes: 0 additions & 13 deletions firmware/README.md

This file was deleted.

3 changes: 2 additions & 1 deletion firmware/components/messages/include/messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ using ApiMessage =
shrapnel::midi::MappingApiMessage,
shrapnel::events::ApiMessage,
shrapnel::selected_preset::SelectedPresetApiMessage,
shrapnel::presets::PresetsApiMessage>;
shrapnel::presets::PresetsApiMessage,
shrapnel::midi::Message>;
using FileDescriptor = std::optional<int>;
using AppMessage = std::pair<ApiMessage, FileDescriptor>;

Expand Down
7 changes: 7 additions & 0 deletions firmware/components/midi_mapping/include/midi_mapping_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,12 @@ template <>
int from_proto(const shrapnel_midi_mapping_Message &message,
midi::MappingApiMessage &out);

template <>
std::optional<midi::Message> from_bytes(std::span<const uint8_t> buffer);

template <>
int from_proto(const shrapnel_midi_mapping_MidiMessage &message,
midi::Message &out);

} // namespace api
} // namespace shrapnel
35 changes: 35 additions & 0 deletions firmware/components/midi_mapping/src/midi_mapping_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,41 @@ std::optional<midi::Mapping> from_bytes(std::span<const uint8_t> buffer)
return out;
}

template <>
std::optional<shrapnel_midi_mapping_MidiMessage>
from_bytes(std::span<const uint8_t> buffer)
{
auto stream = pb_istream_from_buffer(buffer.data(), buffer.size());
shrapnel_midi_mapping_MidiMessage message =
shrapnel_midi_mapping_MidiMessage_init_zero;
bool success =
pb_decode(&stream, &shrapnel_midi_mapping_MidiMessage_msg, &message);
if(!success)
{
return std::nullopt;
}

return message;
}

template <>
std::optional<midi::Message> from_bytes(std::span<const uint8_t> buffer)
{
auto proto = from_bytes<shrapnel_midi_mapping_MidiMessage>(buffer);
if(!proto.has_value())
{
return std::nullopt;
}

midi::Message out{};
int rc = from_proto(*proto, out);
if(rc != 0)
{
return std::nullopt;
}
return out;
}

} // namespace api

} // namespace shrapnel
22 changes: 22 additions & 0 deletions firmware/components/shrapnel_console/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
add_library(shrapnel_console STATIC)
add_library(shrapnel::console ALIAS shrapnel_console)

target_sources(shrapnel_console
PRIVATE
src/shrapnel_console.cpp)

target_include_directories(shrapnel_console
PUBLIC
include)

target_link_libraries(shrapnel_console
PUBLIC
idf::esp_common
idf::log
shrapnel::embedded_cli
shrapnel::etl
shrapnel::midi_mapping
PRIVATE
idf::console
cppcodec
shrapnel::compiler_warning_flags)
55 changes: 55 additions & 0 deletions firmware/components/shrapnel_console/include/shrapnel_console.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright 2022 Barabas Raffai
*
* This file is part of ShrapnelDSP.
*
* ShrapnelDSP is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* ShrapnelDSP is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* ShrapnelDSP. If not, see <https://www.gnu.org/licenses/>.
*/

#pragma once

extern "C" {
#include "embedded_cli.h"
}

#include "midi_protocol.h"
#include <cstddef>
#include <etl/delegate.h>

namespace shrapnel {

using MidiMessageSendCallback = etl::delegate<void(const midi::Message &)>;
using WifiSetupCallback =
etl::delegate<void(const char *ssid, const char *password)>;

class Console
{
public:
Console(MidiMessageSendCallback a_midi_message_callback,
WifiSetupCallback a_wifi_setup_callback);

void handle_character(char c);

private:
friend int handle_midi(int argc, char *argv[]);
friend int handle_wifi(int argc, char *argv[]);

static void putch(void *, char c, bool);

MidiMessageSendCallback midi_message_callback;
WifiSetupCallback wifi_setup_callback;

struct embedded_cli cli;
};
} // namespace shrapnel
Loading

0 comments on commit 3b568bb

Please sign in to comment.