From 064c7dc16b6c7946e770eb0d43603e078ddbc2d3 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 24 Dec 2021 09:25:24 +0000 Subject: [PATCH] GCC fixes for unit tests --- include/etl/experimental/singleton.h | 87 ++++++++++++++++++++++++++++ test/test_callback_timer_locked.cpp | 35 ++++++----- test/test_message_timer_locked.cpp | 33 ++++++----- 3 files changed, 128 insertions(+), 27 deletions(-) create mode 100644 include/etl/experimental/singleton.h diff --git a/include/etl/experimental/singleton.h b/include/etl/experimental/singleton.h new file mode 100644 index 00000000..9291d85b --- /dev/null +++ b/include/etl/experimental/singleton.h @@ -0,0 +1,87 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_SINGLETON_INCLUDED +#define ETL_SINGLETON_INCLUDED + +#include "platform.h" + +namespace etl +{ + //*************************************************************************** + /// Creates . + //*************************************************************************** + template + class singleton + { + public: + + static TObject& get_instance() + { + return p_instance.get(); + } + + protected: + + static TObject* p_instance; + + private: + + singleton() ETL_DELETE; + singleton(const singleton&) ETL_DELETE; + singleton& operator =(const singleton&) ETL_DELETE; + }; + + + template + class singleton_factory + { + virtual ~singleton_factory() {} + + template + TSingleton* create(TArgs args...) + { + if (is_created) + { + return TSingleton::mp_Instance.get(); + } + + + is_created = true; + static Singleton Tmp; + _TSingleton::mp_Instance.reset(pTmp); + + return _TSingleton::mp_Instance.get(); + } + + }; +} + +#endif diff --git a/test/test_callback_timer_locked.cpp b/test/test_callback_timer_locked.cpp index 2b18706f..80f6dec0 100644 --- a/test/test_callback_timer_locked.cpp +++ b/test/test_callback_timer_locked.cpp @@ -55,6 +55,11 @@ namespace { } + void clear() + { + lock_count = 0; + } + bool try_lock() { ++lock_count; @@ -74,6 +79,8 @@ namespace int lock_count; }; + Locks locks; + //*************************************************************************** // Class callback via etl::function //*************************************************************************** @@ -147,7 +154,7 @@ namespace //************************************************************************* TEST(callback_timer_locked_too_many_timers) { - static Locks locks; + locks.clear(); try_lock_type try_lock = try_lock_type::create(); lock_type lock = lock_type::create(); unlock_type unlock = unlock_type::create(); @@ -172,7 +179,7 @@ namespace //************************************************************************* TEST(callback_timer_locked_one_shot) { - static Locks locks; + locks.clear(); try_lock_type try_lock = try_lock_type::create(); lock_type lock = lock_type::create(); unlock_type unlock = unlock_type::create(); @@ -221,7 +228,7 @@ namespace //************************************************************************* TEST(message_timer_one_shot_after_timeout) { - static Locks locks; + locks.clear(); try_lock_type try_lock = try_lock_type::create(); lock_type lock = lock_type::create(); unlock_type unlock = unlock_type::create(); @@ -274,7 +281,7 @@ namespace //************************************************************************* TEST(callback_timer_locked_repeating) { - static Locks locks; + locks.clear(); try_lock_type try_lock = try_lock_type::create(); lock_type lock = lock_type::create(); unlock_type unlock = unlock_type::create(); @@ -323,7 +330,7 @@ namespace //************************************************************************* TEST(callback_timer_locked_repeating_bigger_step) { - static Locks locks; + locks.clear(); try_lock_type try_lock = try_lock_type::create(); lock_type lock = lock_type::create(); unlock_type unlock = unlock_type::create(); @@ -376,7 +383,7 @@ namespace //************************************************************************* TEST(callback_timer_locked_repeating_stop_start) { - static Locks locks; + locks.clear(); try_lock_type try_lock = try_lock_type::create(); lock_type lock = lock_type::create(); unlock_type unlock = unlock_type::create(); @@ -436,7 +443,7 @@ namespace //************************************************************************* TEST(callback_timer_locked_timer_starts_timer_small_step) { - static Locks locks; + locks.clear(); try_lock_type try_lock = try_lock_type::create(); lock_type lock = lock_type::create(); unlock_type unlock = unlock_type::create(); @@ -480,7 +487,7 @@ namespace //************************************************************************* TEST(callback_timer_locked_timer_starts_timer_big_step) { - static Locks locks; + locks.clear(); try_lock_type try_lock = try_lock_type::create(); lock_type lock = lock_type::create(); unlock_type unlock = unlock_type::create(); @@ -524,7 +531,7 @@ namespace //************************************************************************* TEST(callback_timer_locked_repeating_register_unregister) { - static Locks locks; + locks.clear(); try_lock_type try_lock = try_lock_type::create(); lock_type lock = lock_type::create(); unlock_type unlock = unlock_type::create(); @@ -580,7 +587,7 @@ namespace //************************************************************************* TEST(callback_timer_locked_repeating_clear) { - static Locks locks; + locks.clear(); try_lock_type try_lock = try_lock_type::create(); lock_type lock = lock_type::create(); unlock_type unlock = unlock_type::create(); @@ -635,7 +642,7 @@ namespace //************************************************************************* TEST(callback_timer_locked_delayed_immediate) { - static Locks locks; + locks.clear(); try_lock_type try_lock = try_lock_type::create(); lock_type lock = lock_type::create(); unlock_type unlock = unlock_type::create(); @@ -685,7 +692,7 @@ namespace //************************************************************************* TEST(callback_timer_locked_one_shot_big_step_short_delay_insert) { - static Locks locks; + locks.clear(); try_lock_type try_lock = try_lock_type::create(); lock_type lock = lock_type::create(); unlock_type unlock = unlock_type::create(); @@ -728,7 +735,7 @@ namespace //************************************************************************* TEST(callback_timer_locked_one_shot_empty_list_huge_tick_before_insert) { - static Locks locks; + locks.clear(); try_lock_type try_lock = try_lock_type::create(); lock_type lock = lock_type::create(); unlock_type unlock = unlock_type::create(); @@ -790,7 +797,7 @@ namespace test_object test_obj; callback_type delegate_callback = callback_type::create(test_obj); - static Locks locks; + locks.clear(); try_lock_type try_lock = try_lock_type::create(); lock_type lock = lock_type::create(); unlock_type unlock = unlock_type::create(); diff --git a/test/test_message_timer_locked.cpp b/test/test_message_timer_locked.cpp index 6abc241d..5c217aab 100644 --- a/test/test_message_timer_locked.cpp +++ b/test/test_message_timer_locked.cpp @@ -58,6 +58,11 @@ namespace { } + void clear() + { + lock_count = 0; + } + bool try_lock() { ++lock_count; @@ -77,6 +82,8 @@ namespace int lock_count; }; + Locks locks; + enum { MESSAGE1, @@ -170,7 +177,7 @@ namespace //************************************************************************* TEST(message_timer_too_many_timers) { - static Locks locks; + locks.clear(); try_lock_type try_lock = try_lock_type::create(); lock_type lock = lock_type::create(); unlock_type unlock = unlock_type::create(); @@ -195,7 +202,7 @@ namespace //************************************************************************* TEST(message_timer_one_shot) { - static Locks locks; + locks.clear(); try_lock_type try_lock = try_lock_type::create(); lock_type lock = lock_type::create(); unlock_type unlock = unlock_type::create(); @@ -238,7 +245,7 @@ namespace //************************************************************************* TEST(message_timer_one_shot_after_timeout) { - static Locks locks; + locks.clear(); try_lock_type try_lock = try_lock_type::create(); lock_type lock = lock_type::create(); unlock_type unlock = unlock_type::create(); @@ -291,7 +298,7 @@ namespace //************************************************************************* TEST(message_timer_repeating) { - static Locks locks; + locks.clear(); try_lock_type try_lock = try_lock_type::create(); lock_type lock = lock_type::create(); unlock_type unlock = unlock_type::create(); @@ -334,7 +341,7 @@ namespace //************************************************************************* TEST(message_timer_repeating_bigger_step) { - static Locks locks; + locks.clear(); try_lock_type try_lock = try_lock_type::create(); lock_type lock = lock_type::create(); unlock_type unlock = unlock_type::create(); @@ -381,7 +388,7 @@ namespace //************************************************************************* TEST(message_timer_repeating_stop_start) { - static Locks locks; + locks.clear(); try_lock_type try_lock = try_lock_type::create(); lock_type lock = lock_type::create(); unlock_type unlock = unlock_type::create(); @@ -435,7 +442,7 @@ namespace //************************************************************************* TEST(message_timer_repeating_register_unregister) { - static Locks locks; + locks.clear(); try_lock_type try_lock = try_lock_type::create(); lock_type lock = lock_type::create(); unlock_type unlock = unlock_type::create(); @@ -485,7 +492,7 @@ namespace //************************************************************************* TEST(message_timer_repeating_clear) { - static Locks locks; + locks.clear(); try_lock_type try_lock = try_lock_type::create(); lock_type lock = lock_type::create(); unlock_type unlock = unlock_type::create(); @@ -534,7 +541,7 @@ namespace //************************************************************************* TEST(message_timer_route_through_bus) { - static Locks locks; + locks.clear(); try_lock_type try_lock = try_lock_type::create(); lock_type lock = lock_type::create(); unlock_type unlock = unlock_type::create(); @@ -579,7 +586,7 @@ namespace //************************************************************************* TEST(message_timer_immediate_delayed) { - static Locks locks; + locks.clear(); try_lock_type try_lock = try_lock_type::create(); lock_type lock = lock_type::create(); unlock_type unlock = unlock_type::create(); @@ -627,7 +634,7 @@ namespace //************************************************************************* TEST(message_timer_one_shot_big_step_short_delay_insert) { - static Locks locks; + locks.clear(); try_lock_type try_lock = try_lock_type::create(); lock_type lock = lock_type::create(); unlock_type unlock = unlock_type::create(); @@ -666,7 +673,7 @@ namespace //************************************************************************* TEST(callback_timer_one_shot_empty_list_huge_tick_before_insert) { - static Locks locks; + locks.clear(); try_lock_type try_lock = try_lock_type::create(); lock_type lock = lock_type::create(); unlock_type unlock = unlock_type::create(); @@ -719,7 +726,7 @@ namespace #define FIX_PROCESSOR_AFFINITY #endif - static Locks locks; + locks.clear(); try_lock_type try_lock = try_lock_type::create(); lock_type lock = lock_type::create(); unlock_type unlock = unlock_type::create();