Skip to content

Commit

Permalink
Merge pull request #112 from adamfowleruk/feature-89
Browse files Browse the repository at this point in the history
v2.1.0-beta2 Beta of the Exposure and Risk API
  • Loading branch information
adamfowleruk authored Dec 19, 2021
2 parents 6268834 + a682f1f commit 571e92f
Show file tree
Hide file tree
Showing 60 changed files with 5,443 additions and 2,130 deletions.
45 changes: 32 additions & 13 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -1,38 +1,57 @@
{
"configurations": [
{
"name": "Win32",
"name": "Win64",
"includePath": [
"${default}"
"${workspaceFolder}"
// "${workspaceFolder}/herald/include",
// "${workspaceFolder}/herald-tests"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.19041.0",
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.27.29110/bin/Hostx64/x64/cl.exe",
// "defines": [
// "_DEBUG",
// "UNICODE",
// "_UNICODE"
// ],
// "windowsSdkVersion": "10.0.19041.0",
// "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.27.29110/bin/Hostx64/x64/cl.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "msvc-x64",
// "intelliSenseMode": "msvc-x64",
"compileCommands": "${workspaceFolder}/build/compile_commands.json",
"configurationProvider": "ms-vscode.cmake-tools"
},
{
"name": "zephyr",
"includePath": [
"${default}",
"${ZEPHYR_BASE}/include"
"${workspaceFolder}/herald/include",
"${workspaceFolder}/herald-tests",
"${ZEPHYR_BASE}/include",
"${ZEPHYR_BASE}/../nrf/include"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
"_UNICODE",
"__ZEPHYR__",
"CONFIG_BT_NUS"
],
"compilerPath": "c:/gnuarmemb/bin/arm-none-eabi-gcc.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-arm",
"configurationProvider": "ms-vscode.cmake-tools"
"configurationProvider": "ms-vscode.cmake-tools",
"browse": {
"path": [
"${workspaceFolder}",
"${workspaceFolder}/herald/include",
"${workspaceFolder}/herald/src",
"${workspaceFolder}/herald-tests",
"${ZEPHYR_BASE}/include",
"${ZEPHYR_BASE}/../nrf/include"
],
"limitSymbolsToIncludedHeaders": true
}
}
],
"version": 4
Expand Down
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/build/herald-tests/herald-tests.exe",
"args": ["[k-matchingkeyseed]"],
"args": ["[exposure]"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/build/herald-tests",
"environment": [],
Expand Down
10 changes: 9 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@
"backoff"
],
"cmake.configureSettings": {
// "CODE_COVERAGE": "ON"
"CODE_COVERAGE": "ON",
"OPENSSL_ROOT_DIR": "/opt/openssl",
"OPENSSL_CRYPTO_LIBRARY": "/opt/openssl/lib64/libcrypto.a",
"OPENSSL_INCLUDE_DIR": "/opt/openssl/include",
"OPENSSL_USE_STATIC_LIBS": true
},
"kconfig.zephyr.west": "west",
"kconfig.zephyr.base": "${ZEPHYR_BASE}",
Expand All @@ -105,5 +109,9 @@
"board": "nrf52840dk_nrf52840",
"arch": "arm",
"dir": "${ZEPHYR_BASE}/boards/arm/nrf52840dk_nrf52840"
},
"C_Cpp.intelliSenseMemoryLimit": 16384,
"editor.quickSuggestions": {
"other": true
}
}
25 changes: 19 additions & 6 deletions herald-tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ cmake_minimum_required(VERSION 3.12)
add_executable(herald-tests
# Test templates
test-templates.h
test-templates.cpp
test-util.h

# Catch all to ensure all files in Herald are included in code coverage reports
codecoverage-tests.cpp

# base data types
allocatablearray-tests.cpp
bytearrayprinter-tests.cpp
Expand Down Expand Up @@ -53,6 +57,10 @@ add_executable(herald-tests
# App level
nordicuart-tests.cpp

# Usage level
exposure-risk-tests.cpp
exposure-manager-tests-new.cpp

# main test file
main.cpp
)
Expand All @@ -63,11 +71,16 @@ include_directories(${herald_SOURCE_DIR})
# find_package(Threads REQUIRED)

target_link_libraries(herald-tests PRIVATE herald) # Threads::Threads
target_code_coverage(herald-tests AUTO EXTERNAL EXCLUDE herald-tests/*) # EXCLUDE DOES NOT WORK YET!!!
target_code_coverage(herald-tests AUTO EXTERNAL EXCLUDE *-tests.cpp test-*.h *ain.cpp *est-util.cpp *est-templates.h *atch.hpp /usr/include/**/*) # EXCLUDE ONLY WORKS WITH PATTERNS

#add_compile_options(-Wl,--stack,100000000)
#set_target_properties(herald-tests PROPERTIES LINK_FLAGS -Wl,--stack,10000000)
#set_target_properties(herald-tests PROPERTIES LINK_FLAGS /STACK:10000000)
add_compile_options(/STACK:1000000000000)
set_target_properties(herald-tests PROPERTIES LINK_FLAGS /STACK:1000000000000)
if (WIN32)
#add_compile_options(-Wl,--stack,100000000)
#set_target_properties(herald-tests PROPERTIES LINK_FLAGS -Wl,--stack,10000000)
#set_target_properties(herald-tests PROPERTIES LINK_FLAGS /STACK:10000000)
add_compile_options(/STACK:1000000000000)
set_target_properties(herald-tests PROPERTIES LINK_FLAGS /STACK:1000000000000)
else()
# GCov flags for template classes
add_compile_options(--coverage -fno-inline -fno-inline-small-functions -fno-default-inline)
endif ()
target_compile_features(herald-tests PRIVATE cxx_std_17)
5 changes: 3 additions & 2 deletions herald-tests/allocatablearray-tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ TEST_CASE("allocatablearray-empty", "[allocatablearray][ctor][empty]") {

const herald::datatype::AllocatableArray<herald::datatype::Data> cda;
REQUIRE(0 == cda.size());
REQUIRE(cda.begin() == cda.end());
// The following methods dont exist if const
// REQUIRE(cda.begin() == cda.end());
REQUIRE(cda.cbegin() == cda.cend());
}
}
Expand All @@ -29,7 +30,7 @@ TEST_CASE("referencearray-empty", "[referencearray][ctor][empty]") {

const herald::datatype::ReferenceArray<herald::datatype::Data> cda;
REQUIRE(0 == cda.size());
REQUIRE(cda.begin() == cda.end());
// REQUIRE(cda.begin() == cda.end());
REQUIRE(cda.cbegin() == cda.cend());
}
}
Expand Down
141 changes: 99 additions & 42 deletions herald-tests/analysisrunner-tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,14 @@

#include "herald/herald.h"

#include "test-templates.h"

#include <utility>
#include <iostream>

using namespace herald::analysis::sampling;
using namespace herald::datatype;

template <std::size_t Sz>
struct DummyRSSISource {
using value_type = Sample<RSSI>; // allows AnalysisRunner to introspect this class at compile time

DummyRSSISource(const std::size_t srcDeviceKey, SampleList<Sample<RSSI>,Sz>&& data)
: key(srcDeviceKey), data(std::move(data)), lastAddedAt(0), lastRunAdded(0), hasRan(false) {};
~DummyRSSISource() = default;

template <typename RunnerT>
void run(std::uint64_t timeTo, RunnerT& runner) {
// push through data at default rate
lastRunAdded = 0;
for (auto& v: data) {
// devList.push(v.taken,v.value); // copy data over (It's unusual taking a SampleList and sending to a SampleList)
auto sampleTime = v.taken.secondsSinceUnixEpoch();
// Only push data that hasn't been pushed yet, otherwise we get an ever increasing sample list
if ((!hasRan || sampleTime > lastAddedAt) && (sampleTime <= timeTo)) {
lastRunAdded++;
runner.template newSample<RSSI>(key,v);
}
}
runner.run(Date(timeTo));
lastAddedAt = timeTo;
hasRan = true;
}

std::uint64_t getLastRunAdded() {
return lastRunAdded;
}

private:
std::size_t key;
SampleList<Sample<RSSI>,Sz> data;
std::uint64_t lastAddedAt;
std::uint64_t lastRunAdded;
bool hasRan;
};

struct DummyDistanceDelegate /* : herald::analysis::AnalysisDelegate */ {
using value_type = Distance;

Expand Down Expand Up @@ -90,6 +54,45 @@ struct DummyDistanceDelegate /* : herald::analysis::AnalysisDelegate */ {
};


struct DummyBrightnessDelegate {
using value_type = RunningMean<Luminosity>;

DummyBrightnessDelegate() : lastSampledID(0), brightness() {};
DummyBrightnessDelegate(const DummyBrightnessDelegate&) = delete; // copy ctor deleted
DummyBrightnessDelegate(DummyBrightnessDelegate&& other) noexcept : lastSampledID(other.lastSampledID), brightness(std::move(other.brightness)) {} // move ctor
~DummyBrightnessDelegate() {};

DummyBrightnessDelegate& operator=(DummyBrightnessDelegate&& other) noexcept {
lastSampledID = other.lastSampledID;
std::swap(brightness,other.brightness);
return *this;
}

// specific override of template
void newSample(SampledID sampled, Sample<RunningMean<Luminosity>> sample) {
lastSampledID = sampled;
brightness.push(sample);
}

void reset() {
brightness.clear();
lastSampledID = 0;
}

// Test only methods
SampledID lastSampled() {
return lastSampledID;
}

const SampleList<Sample<RunningMean<Luminosity>>,25>& samples() {
return brightness;
}

private:
SampledID lastSampledID;
SampleList<Sample<RunningMean<Luminosity>>,25> brightness;
};

TEST_CASE("variantset-basic", "[variantset][basic]") {
SECTION("variantset-basic") {
herald::analysis::VariantSet<int,double> vs;
Expand Down Expand Up @@ -158,7 +161,7 @@ TEST_CASE("variantset-listmanager", "[variantset][listmanager]") {
TEST_CASE("analysisrunner-nodata", "[analysisrunner][nodata]") {
SECTION("analysisrunner-nodata") {
SampleList<Sample<RSSI>,25> srcData;
DummyRSSISource src(1234,std::move(srcData));
DummySampleSource src(1234,std::move(srcData));

herald::analysis::algorithms::distance::FowlerBasicAnalyser distanceAnalyser(30, -50, -24);

Expand Down Expand Up @@ -188,7 +191,7 @@ TEST_CASE("analysisrunner-singledataitem", "[analysisrunner][singledataitem]") {
SECTION("analysisrunner-singledataitem") {
SampleList<Sample<RSSI>,25> srcData;
srcData.push(50,-55);
DummyRSSISource src(1234,std::move(srcData));
DummySampleSource src(1234,std::move(srcData));

herald::analysis::algorithms::distance::FowlerBasicAnalyser distanceAnalyser(30, -50, -24);

Expand All @@ -213,6 +216,60 @@ TEST_CASE("analysisrunner-singledataitem", "[analysisrunner][singledataitem]") {
}
}


/// Single data item use case with 1 data item, no failures, correct summary output
TEST_CASE("analysisrunner-singledataitem-twoanalyses", "[analysisrunner][singledataitem][twoanalyses][multivariate]") {
SECTION("analysisrunner-singledataitem-twoanalyses") {
SampleList<Sample<RSSI>,25> srcData;
srcData.push(50,-55);
DummySampleSource src(1234,std::move(srcData));

SampleList<Sample<Luminosity>,15> srcLightData;
srcLightData.push(40,12);
srcLightData.push(50,12);
srcLightData.push(60,12);
DummySampleSource srcLight(5678,std::move(srcLightData));

herald::analysis::algorithms::distance::FowlerBasicAnalyser distanceAnalyser(30, -50, -24);
herald::analysis::algorithms::RunningMeanAnalyser<herald::datatype::Luminosity,2> meanLight{60};

DummyDistanceDelegate myDelegate;
DummyBrightnessDelegate myBrightnessDelegate;
herald::analysis::AnalysisDelegateManager adm(std::move(myDelegate),std::move(myBrightnessDelegate)); // NOTE: myDelegate MOVED FROM and no longer accessible
herald::analysis::AnalysisProviderManager apm(std::move(distanceAnalyser), std::move(meanLight)); // NOTE: distanceAnalyser MOVED FROM and no longer accessible

herald::analysis::AnalysisRunner<
herald::analysis::AnalysisDelegateManager<
DummyDistanceDelegate,
DummyBrightnessDelegate
>,
herald::analysis::AnalysisProviderManager<
herald::analysis::algorithms::distance::FowlerBasicAnalyser,
herald::analysis::algorithms::RunningMeanAnalyser<herald::datatype::Luminosity,2>
>,
RSSI,Distance,Luminosity,RunningMean<Luminosity>
> runner(adm, apm); // just for Sample<RSSI> types, and their produced output (Sample<Distance>)

src.run(140,runner);
srcLight.run(160,runner);
REQUIRE(src.getLastRunAdded() == 1); // Single data item
REQUIRE(srcLight.getLastRunAdded() == 3); // Three data items

auto& delegateRef = adm.get<DummyDistanceDelegate>();
REQUIRE(delegateRef.lastSampled() == 1234); // ran once, past 50, for SampleID=1234

auto& samples = delegateRef.samples();
REQUIRE(samples.size() == 1); // 1 as single data item (for THIS delegate)


auto& delegateBRef = adm.get<DummyBrightnessDelegate>();
REQUIRE(delegateBRef.lastSampled() == 5678); // ran once, past 50, for SampleID=1234

auto& samplesB = delegateBRef.samples();
REQUIRE(samplesB.size() == 2); // 2 as we now correctly separate by time interval (0-60, 60-120)
}
}

/// [Who] As a DCT app developer
/// [What] I want to link my live application data to an analysis runner easily
/// [Value] So I don't have to write plumbing code for Herald itself
Expand All @@ -233,7 +290,7 @@ TEST_CASE("analysisrunner-basic", "[analysisrunner][basic]") {
srcData.push(80,-55);
srcData.push(90,-55);
srcData.push(100,-55);
DummyRSSISource src(1234,std::move(srcData));
DummySampleSource src(1234,std::move(srcData));

herald::analysis::algorithms::distance::FowlerBasicAnalyser distanceAnalyser(30, -50, -24);

Expand Down Expand Up @@ -295,7 +352,7 @@ TEST_CASE("analysisrunner-nonewdata", "[analysisrunner][nonewdata]") {
srcData.push(80,-55);
srcData.push(90,-55);
srcData.push(100,-55);
DummyRSSISource src(1234,std::move(srcData));
DummySampleSource src(1234,std::move(srcData));

herald::analysis::algorithms::distance::FowlerBasicAnalyser distanceAnalyser(30, -50, -24);

Expand Down
21 changes: 21 additions & 0 deletions herald-tests/codecoverage-tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2021 Herald Project Contributors
// SPDX-License-Identifier: Apache-2.0
//

#include "catch.hpp"

#include "herald/herald.h"


TEST_CASE("coverage-catch-all", "[coverage][catch-all]") {
SECTION("coverage-catch-all") {
using namespace herald::datatype;

// TODO Instantiate all templates to ensure GCov picks them up


Base64String myString;

REQUIRE("wibble" != myString.encoded());
}
}
Loading

0 comments on commit 571e92f

Please sign in to comment.