first commit
This commit is contained in:
commit
5893b00dd2
1669 changed files with 1982740 additions and 0 deletions
60
libraries/M5UnitUnified/pio_project/test/common_main.cpp
Normal file
60
libraries/M5UnitUnified/pio_project/test/common_main.cpp
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
/*
|
||||
main for UnitTest on native
|
||||
*/
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
// C++ version
|
||||
#if __cplusplus >= 202002L
|
||||
#pragma message "C++20 or later"
|
||||
#elif __cplusplus >= 201703L
|
||||
#pragma message "C++17 or later"
|
||||
#elif __cplusplus >= 201402L
|
||||
#pragma message "C++14 or later"
|
||||
#elif __cplusplus >= 201103L
|
||||
#pragma message "C++11 or later"
|
||||
#else
|
||||
#error "Need C++11 or later"
|
||||
#endif
|
||||
// Compiler
|
||||
#if defined(__clang__)
|
||||
#pragma message "Clang"
|
||||
#elif defined(_MSC_VER)
|
||||
#pragma message "MSVC"
|
||||
#elif defined(__BORLANDC__)
|
||||
#pragma message "BORLANDC"
|
||||
#elif defined(__MINGW32__) || defined(__MINGW64__)
|
||||
#pragma message "MINGW"
|
||||
#elif defined(__INTEL_COMPILER)
|
||||
#pragma message "ICC"
|
||||
#elif defined(__GNUG__)
|
||||
#pragma message "GCC"
|
||||
#else
|
||||
#pragma message "Unknown compiler"
|
||||
#endif
|
||||
|
||||
/*
|
||||
For native test, this main() is used.
|
||||
If the Arduino framework is used, the framework library main is used.
|
||||
*/
|
||||
#if !defined(ARDUINO)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
|
||||
#ifdef GTEST_FILTER
|
||||
::testing::GTEST_FLAG(filter) = GTEST_FILTER;
|
||||
#endif
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wunused-result"
|
||||
RUN_ALL_TESTS();
|
||||
#pragma GCC diagnostic pop
|
||||
// Always return zero-code and allow PlatformIO to parse results
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
/*
|
||||
main for UnitTest on embedded
|
||||
*/
|
||||
#include <gtest/gtest.h>
|
||||
#include <M5Unified.h>
|
||||
#include <esp_system.h>
|
||||
|
||||
#pragma message "Embedded setup/loop"
|
||||
|
||||
#if __has_include(<esp_idf_version.h>)
|
||||
#include <esp_idf_version.h>
|
||||
#else // esp_idf_version.h has been introduced in Arduino 1.0.5 (ESP-IDF3.3)
|
||||
#define ESP_IDF_VERSION_VAL(major, minor, patch) ((major << 16) | (minor << 8) | (patch))
|
||||
#define ESP_IDF_VERSION ESP_IDF_VERSION_VAL(3, 2, 0)
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
auto& lcd = M5.Display;
|
||||
} // namespace
|
||||
|
||||
void test()
|
||||
{
|
||||
lcd.fillRect(0, 0, lcd.width() >> 1, lcd.height(), RUN_ALL_TESTS() ? TFT_RED : TFT_GREEN);
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
delay(1500);
|
||||
|
||||
M5.begin();
|
||||
|
||||
M5_LOGI("CPP %ld", __cplusplus);
|
||||
M5_LOGI("ESP-IDF Version %d.%d.%d", (ESP_IDF_VERSION >> 16) & 0xFF, (ESP_IDF_VERSION >> 8) & 0xFF,
|
||||
ESP_IDF_VERSION & 0xFF);
|
||||
M5_LOGI("BOARD:%X", M5.getBoard());
|
||||
M5_LOGI("Heap: %u", esp_get_free_heap_size());
|
||||
|
||||
lcd.clear(TFT_DARKGRAY);
|
||||
::testing::InitGoogleTest();
|
||||
|
||||
#ifdef GTEST_FILTER
|
||||
::testing::GTEST_FLAG(filter) = GTEST_FILTER;
|
||||
#endif
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
test();
|
||||
#if 0
|
||||
delay(1000);
|
||||
esp_restart();
|
||||
#endif
|
||||
while (true) {
|
||||
delay(10000);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
/*
|
||||
UnitTest for M5UnitComponet
|
||||
*/
|
||||
#include <gtest/gtest.h>
|
||||
#include <M5UnitComponent.hpp>
|
||||
#include <M5UnitUnified.hpp>
|
||||
#include "unit_dummy.hpp"
|
||||
#include <Wire.h>
|
||||
|
||||
using namespace m5::unit;
|
||||
|
||||
TEST(Component, Update)
|
||||
{
|
||||
UnitUnified units;
|
||||
UnitDummy u;
|
||||
EXPECT_FALSE(u.isRegistered());
|
||||
|
||||
{
|
||||
auto cfg = u.component_config();
|
||||
EXPECT_FALSE(cfg.self_update); // false as default
|
||||
|
||||
EXPECT_EQ(u.count, 0U);
|
||||
EXPECT_TRUE(units.add(u, Wire));
|
||||
|
||||
units.update(); // Dont call u.update() because unit was not begun.
|
||||
EXPECT_EQ(u.count, 0U);
|
||||
|
||||
EXPECT_TRUE(units.begin());
|
||||
units.update(); // Call u.update()
|
||||
EXPECT_EQ(u.count, 1U);
|
||||
|
||||
cfg.self_update = true;
|
||||
u.component_config(cfg);
|
||||
cfg = u.component_config();
|
||||
EXPECT_TRUE(cfg.self_update);
|
||||
|
||||
units.update(); // Don't call u.update()
|
||||
EXPECT_EQ(u.count, 1U);
|
||||
|
||||
u.update(); // If component_config.self_update is true, you have to call it yourself
|
||||
EXPECT_EQ(u.count, 2U);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
/*
|
||||
UnitTest for M5UnitComponet
|
||||
*/
|
||||
#include <gtest/gtest.h>
|
||||
#include <M5UnitComponent.hpp>
|
||||
#include "unit_dummy.hpp"
|
||||
|
||||
TEST(Component, Children)
|
||||
{
|
||||
m5::unit::UnitDummy u0, u1, u2, u3;
|
||||
|
||||
//
|
||||
EXPECT_FALSE(u0.hasParent());
|
||||
EXPECT_FALSE(u0.hasSiblings());
|
||||
EXPECT_FALSE(u0.hasChildren());
|
||||
|
||||
EXPECT_EQ(0U, u0.childrenSize());
|
||||
EXPECT_FALSE(u0.add(u1, 0));
|
||||
|
||||
// add 1
|
||||
auto cfg = u0.component_config();
|
||||
cfg.max_children = 1;
|
||||
u0.component_config(cfg);
|
||||
EXPECT_LT(u1.channel(), 0);
|
||||
EXPECT_TRUE(u0.add(u1, 0));
|
||||
EXPECT_FALSE(u0.add(u1, 1));
|
||||
EXPECT_FALSE(u0.add(u2, 1));
|
||||
|
||||
EXPECT_FALSE(u0.hasParent());
|
||||
EXPECT_FALSE(u0.hasSiblings());
|
||||
EXPECT_TRUE(u0.hasChildren());
|
||||
EXPECT_EQ(1U, u0.childrenSize());
|
||||
|
||||
EXPECT_EQ(0, u1.channel());
|
||||
EXPECT_TRUE(u1.hasParent());
|
||||
EXPECT_FALSE(u1.hasSiblings());
|
||||
EXPECT_FALSE(u1.hasChildren());
|
||||
|
||||
// add 2
|
||||
cfg = u0.component_config();
|
||||
cfg.max_children = 2;
|
||||
u0.component_config(cfg);
|
||||
|
||||
EXPECT_LT(u2.channel(), 0);
|
||||
EXPECT_FALSE(u0.add(u2, 0)); // same channel (failed)
|
||||
EXPECT_LT(u2.channel(), 0);
|
||||
EXPECT_TRUE(u0.add(u2, 3));
|
||||
|
||||
EXPECT_FALSE(u0.hasParent());
|
||||
EXPECT_FALSE(u0.hasSiblings());
|
||||
EXPECT_TRUE(u0.hasChildren());
|
||||
EXPECT_EQ(2U, u0.childrenSize());
|
||||
|
||||
EXPECT_TRUE(u1.hasParent());
|
||||
EXPECT_TRUE(u1.hasSiblings());
|
||||
EXPECT_FALSE(u1.hasChildren());
|
||||
|
||||
EXPECT_TRUE(u2.hasParent());
|
||||
EXPECT_TRUE(u2.hasSiblings());
|
||||
EXPECT_FALSE(u2.hasChildren());
|
||||
EXPECT_EQ(3, u2.channel());
|
||||
|
||||
EXPECT_LT(u3.channel(), 0);
|
||||
EXPECT_FALSE(u0.add(u3, 2)); // max = 2 (failed)
|
||||
EXPECT_LT(u3.channel(), 0);
|
||||
|
||||
// iteration
|
||||
m5::unit::UnitDummy* ptr[] = {&u1, &u2};
|
||||
size_t i = 0;
|
||||
for (auto it = u0.childBegin(); it != u0.childEnd(); ++it) {
|
||||
EXPECT_EQ(&(*it), ptr[i++]);
|
||||
// printf("[%u]:%s\n", it->port(), (*it).deviceName());
|
||||
}
|
||||
EXPECT_EQ(i, u0.childrenSize());
|
||||
}
|
||||
22
libraries/M5UnitUnified/pio_project/test/unit_dummy.cpp
Normal file
22
libraries/M5UnitUnified/pio_project/test/unit_dummy.cpp
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
/*
|
||||
UnitTest for M5UnitComponent
|
||||
*/
|
||||
#include "unit_dummy.hpp"
|
||||
#include <M5Utility.hpp>
|
||||
|
||||
using namespace m5::utility::mmh3;
|
||||
|
||||
namespace m5 {
|
||||
namespace unit {
|
||||
|
||||
const char UnitDummy::name[] = "UnitDummy";
|
||||
const m5::unit::types::uid_t UnitDummy::uid{"UnitDummy"_mmh3};
|
||||
const m5::unit::types::attr_t UnitDummy::attr{0};
|
||||
|
||||
} // namespace unit
|
||||
} // namespace m5
|
||||
40
libraries/M5UnitUnified/pio_project/test/unit_dummy.hpp
Normal file
40
libraries/M5UnitUnified/pio_project/test/unit_dummy.hpp
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
/*
|
||||
UnitTest for M5UnitComponent
|
||||
*/
|
||||
#ifndef M5_UNIT_COMPONENT_TEST_UNIT_DUMMY_HPP
|
||||
#define M5_UNIT_COMPONENT_TEST_UNIT_DUMMY_HPP
|
||||
|
||||
#include <M5UnitComponent.hpp>
|
||||
|
||||
namespace m5 {
|
||||
namespace unit {
|
||||
// DummyComponent for UnitTest
|
||||
class UnitDummy : public m5::unit::Component {
|
||||
M5_UNIT_COMPONENT_HPP_BUILDER(UnitDummy, 0x00);
|
||||
|
||||
public:
|
||||
UnitDummy() : Component(0x01)
|
||||
{
|
||||
}
|
||||
virtual ~UnitDummy()
|
||||
{
|
||||
}
|
||||
|
||||
virtual bool begin() override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
virtual void update(const bool force = false) override
|
||||
{
|
||||
++count;
|
||||
}
|
||||
uint32_t count{};
|
||||
};
|
||||
} // namespace unit
|
||||
} // namespace m5
|
||||
#endif
|
||||
169
libraries/M5UnitUnified/pio_project/test/unit_unified_test.cpp
Normal file
169
libraries/M5UnitUnified/pio_project/test/unit_unified_test.cpp
Normal file
|
|
@ -0,0 +1,169 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
/*
|
||||
UnitTest for M5UnitUnified
|
||||
*/
|
||||
#include <gtest/gtest.h>
|
||||
#include <M5Unified.h>
|
||||
|
||||
#include <M5UnitComponent.hpp>
|
||||
#include <M5UnitUnified.hpp>
|
||||
|
||||
#include <M5UnitUnifiedENV.h>
|
||||
#include <M5UnitUnifiedMETER.h>
|
||||
#include <M5UnitUnifiedHUB.h>
|
||||
#include <M5UnitUnifiedGESTURE.h>
|
||||
#include <M5UnitUnifiedHEART.h>
|
||||
#include <M5UnitUnifiedTOF.h>
|
||||
#include <M5UnitUnifiedWEIGHT.h>
|
||||
#include <M5UnitUnifiedANADIG.h>
|
||||
#include <M5UnitUnifiedCOLOR.h>
|
||||
#include <M5UnitUnifiedTHERMO.h>
|
||||
#include <M5UnitUnifiedDISTANCE.h>
|
||||
#include <M5UnitUnifiedEXTIO.h>
|
||||
#include <M5UnitUnifiedINFRARED.h>
|
||||
#include <M5UnitUnifiedCRYPTO.h>
|
||||
|
||||
#include <M5UnitUnifiedRFID.h>
|
||||
#include <M5UnitUnifiedKEYBOARD.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
|
||||
namespace {
|
||||
|
||||
#if 0
|
||||
// Get the equivalent of a unique type name without RTTI
|
||||
template <typename U>
|
||||
const char* TypeName() {
|
||||
return __PRETTY_FUNCTION__;
|
||||
}
|
||||
#endif
|
||||
|
||||
std::vector<m5::unit::Component*> vec;
|
||||
|
||||
template <class U>
|
||||
void each_unit_test()
|
||||
{
|
||||
SCOPED_TRACE(U::name);
|
||||
|
||||
U* unit = new U();
|
||||
EXPECT_TRUE((bool)unit);
|
||||
|
||||
M5_LOGI(">>%02XH %08X [%s]", U::DEFAULT_ADDRESS, U::uid, U::name);
|
||||
|
||||
// Are the values the same via class and via instance?
|
||||
EXPECT_EQ(+U::DEFAULT_ADDRESS, unit->address());
|
||||
EXPECT_STREQ(U::name, unit->deviceName());
|
||||
EXPECT_EQ(U::uid, unit->identifier());
|
||||
EXPECT_EQ(U::attr, unit->attribute());
|
||||
|
||||
// Identical IDs exist?
|
||||
for (auto&& e : vec) {
|
||||
EXPECT_NE(unit->identifier(), e->identifier()) << unit->deviceName() << " / " << e->deviceName();
|
||||
}
|
||||
|
||||
// Move
|
||||
{
|
||||
U tmp;
|
||||
// Move constructor
|
||||
U mc(std::move(tmp));
|
||||
// assign by move
|
||||
U mc2;
|
||||
mc2 = std::move(mc);
|
||||
}
|
||||
|
||||
vec.push_back(unit);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// Check each value and check duplicate uid
|
||||
TEST(UnitUnified, EachUnit)
|
||||
{
|
||||
// ENV
|
||||
each_unit_test<m5::unit::UnitSCD40>();
|
||||
each_unit_test<m5::unit::UnitSCD41>();
|
||||
each_unit_test<m5::unit::UnitSHT30>();
|
||||
each_unit_test<m5::unit::UnitQMP6988>();
|
||||
each_unit_test<m5::unit::UnitENV3>();
|
||||
each_unit_test<m5::unit::UnitBME688>();
|
||||
each_unit_test<m5::unit::UnitSGP30>();
|
||||
each_unit_test<m5::unit::UnitSHT40>();
|
||||
each_unit_test<m5::unit::UnitBMP280>();
|
||||
each_unit_test<m5::unit::UnitENV4>();
|
||||
|
||||
// METER
|
||||
each_unit_test<m5::unit::UnitADS1113>();
|
||||
each_unit_test<m5::unit::UnitADS1114>();
|
||||
each_unit_test<m5::unit::UnitADS1115>();
|
||||
each_unit_test<m5::unit::meter::UnitEEPROM>();
|
||||
each_unit_test<m5::unit::UnitAmeter>();
|
||||
each_unit_test<m5::unit::UnitVmeter>();
|
||||
each_unit_test<m5::unit::UnitKmeterISO>();
|
||||
each_unit_test<m5::unit::UnitDualKmeter>();
|
||||
|
||||
// HUB
|
||||
each_unit_test<m5::unit::UnitPCA9548AP>();
|
||||
|
||||
// GESTURE
|
||||
each_unit_test<m5::unit::UnitPAJ7620U2>();
|
||||
|
||||
// HEART
|
||||
each_unit_test<m5::unit::UnitMAX30100>();
|
||||
each_unit_test<m5::unit::UnitMAX30102>();
|
||||
|
||||
// TOF
|
||||
each_unit_test<m5::unit::UnitVL53L0X>();
|
||||
each_unit_test<m5::unit::UnitVL53L1X>();
|
||||
|
||||
// WEIGHT
|
||||
each_unit_test<m5::unit::UnitWeightI2C>();
|
||||
each_unit_test<m5::unit::UnitMiniScales>();
|
||||
|
||||
// ANADIG
|
||||
each_unit_test<m5::unit::UnitMCP4725>();
|
||||
each_unit_test<m5::unit::UnitGP8413>();
|
||||
each_unit_test<m5::unit::UnitADS11XX>();
|
||||
each_unit_test<m5::unit::UnitADS1110>();
|
||||
each_unit_test<m5::unit::UnitADS1100>();
|
||||
|
||||
// COLOR
|
||||
each_unit_test<m5::unit::UnitTCS34725>();
|
||||
|
||||
// THERMO
|
||||
each_unit_test<m5::unit::UnitMLX90614>();
|
||||
each_unit_test<m5::unit::UnitMLX90614BAA>();
|
||||
each_unit_test<m5::unit::UnitNCIR2>();
|
||||
|
||||
// DISTANCE
|
||||
each_unit_test<m5::unit::UnitRCWL9620>();
|
||||
|
||||
// EXTIO
|
||||
each_unit_test<m5::unit::UnitExtIO2>();
|
||||
|
||||
// INFRARED
|
||||
each_unit_test<m5::unit::UnitSTHS34PF80>();
|
||||
|
||||
// CRYPTO
|
||||
each_unit_test<m5::unit::UnitATECC608B>();
|
||||
each_unit_test<m5::unit::UnitATECC608B_TNGTLS>();
|
||||
|
||||
// RFID
|
||||
each_unit_test<m5::unit::UnitMFRC522>();
|
||||
each_unit_test<m5::unit::UnitWS1850S>();
|
||||
|
||||
// KEYBOARD
|
||||
each_unit_test<m5::unit::UnitKeyboard>();
|
||||
each_unit_test<m5::unit::UnitKeyboardBitwise>();
|
||||
each_unit_test<m5::unit::UnitCardKB>();
|
||||
each_unit_test<m5::unit::UnitFacesQWERTY>();
|
||||
|
||||
for (auto&& e : vec) {
|
||||
delete e;
|
||||
}
|
||||
vec.clear();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue