From 83c1ddcbbd23e018eceecc183677dbee9e962089 Mon Sep 17 00:00:00 2001 From: Ladislas de Toldi Date: Fri, 7 Jan 2022 12:39:38 +0100 Subject: [PATCH 1/5] :pushpin: (cmake): Set unit tests CXX_STANDARD to 20 --- tests/unit/CMakeLists.txt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index 0f5b97d5d0..073096245c 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -30,9 +30,13 @@ message(STATUS "") project(LekaOSUnitTests LANGUAGES C CXX) -# Set -std=gnu++17 -set(CMAKE_CXX_STANDARD 17) +# Set C/C++ standard +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_EXTENSIONS TRUE) set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_C_STANDARD 17) +set(CMAKE_C_EXTENSIONS TRUE) +set(CMAKE_C_STANDARD_REQUIRED ON) # Colored output for compilation if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") From 148146f6dcbe67afceeac9c488cb21220a0a79e7 Mon Sep 17 00:00:00 2001 From: Ladislas de Toldi Date: Fri, 7 Jan 2022 12:36:35 +0100 Subject: [PATCH 2/5] :wastebasket: (std): Deprecate lstd_array As we know use c++20, there is not need to keep lstd_array to access new features. --- .../tests/CoreFlashIS25LP016D_test.cpp | 10 +-- .../tests/CoreFlashManagerIS25LP016D_test.cpp | 22 ++--- drivers/CoreVideo/include/CGFont.hpp | 4 +- .../source/CoreLCDDriverOTM8009A.cpp | 3 +- include/cxxsupport/lstd_array | 80 ------------------- libs/FileSystemKit/tests/File_test.cpp | 24 +++--- libs/FirmwareKit/tests/FirmwareKit_test.cpp | 2 +- libs/Utils/tests/MathUtils_test_checksum.cpp | 18 ++--- spikes/lk_file_reception/Certificates.h | 4 +- spikes/lk_flash_memory/main.cpp | 4 +- spikes/stl_cxxsupport/main.cpp | 8 +- .../CoreFlashUtils.cpp | 4 +- 12 files changed, 51 insertions(+), 132 deletions(-) delete mode 100644 include/cxxsupport/lstd_array diff --git a/drivers/CoreFlashMemory/tests/CoreFlashIS25LP016D_test.cpp b/drivers/CoreFlashMemory/tests/CoreFlashIS25LP016D_test.cpp index ae422d9fa6..4c2b4c7a99 100644 --- a/drivers/CoreFlashMemory/tests/CoreFlashIS25LP016D_test.cpp +++ b/drivers/CoreFlashMemory/tests/CoreFlashIS25LP016D_test.cpp @@ -3,7 +3,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "CoreFlashIS25LP016D.h" -#include +#include #include "gtest/gtest.h" #include "mocks/leka/FlashManager.h" @@ -121,7 +121,7 @@ TEST_F(CoreFlashIS25LP016DTest, readFailChipIsNotAvailable) TEST_F(CoreFlashIS25LP016DTest, write) { uint32_t address = 0x2A; - auto buffer = lstd::to_array({0x61, 0x62, 0x63, 0x64, 0x65, 0x66}); // "abcdef" + auto buffer = std::to_array({0x61, 0x62, 0x63, 0x64, 0x65, 0x66}); // "abcdef" const auto bytes_to_write = 5; size_t expected_bytes_written = bytes_to_write; @@ -145,7 +145,7 @@ TEST_F(CoreFlashIS25LP016DTest, write) TEST_F(CoreFlashIS25LP016DTest, writeOverSize) { uint32_t address = flash::is25lp016d::size; - auto buffer = lstd::to_array({0x61, 0x62, 0x63, 0x64, 0x65, 0x66}); // "abcdef" + auto buffer = std::to_array({0x61, 0x62, 0x63, 0x64, 0x65, 0x66}); // "abcdef" const auto bytes_to_write = 5; size_t expected_bytes_written = 0; @@ -159,7 +159,7 @@ TEST_F(CoreFlashIS25LP016DTest, writeOverSize) TEST_F(CoreFlashIS25LP016DTest, writeFailNotEnableToWrite) { uint32_t address = 0x2A; - auto buffer = lstd::to_array({0x61, 0x62, 0x63, 0x64, 0x65, 0x66}); // "abcdef" + auto buffer = std::to_array({0x61, 0x62, 0x63, 0x64, 0x65, 0x66}); // "abcdef" const auto bytes_to_write = 5; size_t expected_bytes_written = 0; @@ -179,7 +179,7 @@ TEST_F(CoreFlashIS25LP016DTest, writeFailNotEnableToWrite) TEST_F(CoreFlashIS25LP016DTest, writeFailChipIsNotAvailable) { uint32_t address = 0x2A; - auto buffer = lstd::to_array({0x61, 0x62, 0x63, 0x64, 0x65, 0x66}); // "abcdef" + auto buffer = std::to_array({0x61, 0x62, 0x63, 0x64, 0x65, 0x66}); // "abcdef" const auto bytes_to_write = 5; size_t expected_bytes_written = 0; diff --git a/drivers/CoreFlashMemory/tests/CoreFlashManagerIS25LP016D_test.cpp b/drivers/CoreFlashMemory/tests/CoreFlashManagerIS25LP016D_test.cpp index 4109486891..949231c8c6 100644 --- a/drivers/CoreFlashMemory/tests/CoreFlashManagerIS25LP016D_test.cpp +++ b/drivers/CoreFlashMemory/tests/CoreFlashManagerIS25LP016D_test.cpp @@ -3,7 +3,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "CoreFlashManagerIS25LP016D.h" -#include +#include #include "gtest/gtest.h" #include "mocks/leka/QSPI.h" @@ -37,12 +37,12 @@ class CoreFlashManagerIS25LP016DTest : public ::testing::Test void MOCK_FUNCTION_chip_available(int times = 1) { auto work_not_in_progress = ~status::work_in_progress; - auto returned_value = lstd::to_array({work_not_in_progress}); + auto returned_value = std::to_array({work_not_in_progress}); EXPECT_CALL(qspimock, sendCommand(command::read_status, _, _, _, setArray(returned_value), _)).Times(times); } void MOCK_FUNCTION_chip_not_available() { - auto returned_value = lstd::to_array({status::work_in_progress}); + auto returned_value = std::to_array({status::work_in_progress}); EXPECT_CALL(qspimock, sendCommand(command::read_status, _, _, _, setArray(returned_value), _)).Times(1); } @@ -57,7 +57,7 @@ class CoreFlashManagerIS25LP016DTest : public ::testing::Test } void MOCK_FUNCTION_enable_write_and_write_is_enabled() { - auto returned_value = lstd::to_array({status::write_enable_latch}); + auto returned_value = std::to_array({status::write_enable_latch}); { InSequence seq; @@ -73,7 +73,7 @@ class CoreFlashManagerIS25LP016DTest : public ::testing::Test void MOCK_FUNCTION_enable_write_and_write_is_not_enabled() { auto write_not_enabled = ~status::write_enable_latch; - auto returned_value = lstd::to_array({write_not_enabled}); + auto returned_value = std::to_array({write_not_enabled}); { InSequence seq; @@ -98,7 +98,7 @@ TEST_F(CoreFlashManagerIS25LP016DTest, instantiation) TEST_F(CoreFlashManagerIS25LP016DTest, getStatusRegister) { - auto returned_value = lstd::to_array({0x2A}); + auto returned_value = std::to_array({0x2A}); auto expected_value = returned_value[0]; EXPECT_CALL(qspimock, sendCommand(command::read_status, _, _, _, setArray(returned_value), status::register_size)) @@ -113,7 +113,7 @@ TEST_F(CoreFlashManagerIS25LP016DTest, chipIsAvailable) auto expected_not_available = false; auto work_not_in_progress = ~status::work_in_progress; - auto returned_value = lstd::to_array({work_not_in_progress}); + auto returned_value = std::to_array({work_not_in_progress}); EXPECT_CALL(qspimock, sendCommand(command::read_status, _, _, _, setArray(returned_value), status::register_size)) .Times(1); @@ -126,7 +126,7 @@ TEST_F(CoreFlashManagerIS25LP016DTest, chipIsNotAvailable) { auto expected_not_available = true; - auto returned_value = lstd::to_array({status::work_in_progress}); + auto returned_value = std::to_array({status::work_in_progress}); EXPECT_CALL(qspimock, sendCommand(command::read_status, _, _, _, setArray(returned_value), status::register_size)) .Times(1); @@ -223,7 +223,7 @@ TEST_F(CoreFlashManagerIS25LP016DTest, writeIsEnabled) { auto expected_not_enabled = false; - auto returned_value = lstd::to_array({status::write_enable_latch}); + auto returned_value = std::to_array({status::write_enable_latch}); { InSequence seq; @@ -243,7 +243,7 @@ TEST_F(CoreFlashManagerIS25LP016DTest, writeIsNotEnabled) auto expected_not_enabled = true; auto write_not_enabled = ~status::write_enable_latch; - auto returned_value = lstd::to_array({write_not_enabled}); + auto returned_value = std::to_array({write_not_enabled}); { InSequence seq; @@ -262,7 +262,7 @@ TEST_F(CoreFlashManagerIS25LP016DTest, writeIsNotEnabledDueToChipNotAvailable) { auto expected_not_enabled = true; - auto returned_value = lstd::to_array({status::write_enable_latch}); + auto returned_value = std::to_array({status::write_enable_latch}); { InSequence seq; diff --git a/drivers/CoreVideo/include/CGFont.hpp b/drivers/CoreVideo/include/CGFont.hpp index 2876980531..062ddf3e07 100644 --- a/drivers/CoreVideo/include/CGFont.hpp +++ b/drivers/CoreVideo/include/CGFont.hpp @@ -6,8 +6,8 @@ #ifndef _LEKA_OS_DRIVER_CORE_VIDEO_FONT_TABLE_H_ #define _LEKA_OS_DRIVER_CORE_VIDEO_FONT_TABLE_H_ +#include #include -#include namespace leka { @@ -18,7 +18,7 @@ namespace leka { // Reading has to be done row of pixel by row of pixel. Hence, the row of 17 pixels is encoded on 3 bytes. // As consequence of the 2 previous sentences, the last 7 bits are not used in the third byte. -constexpr auto CGFontTable = lstd::to_array({ +constexpr auto CGFontTable = std::to_array({ // @0 ' ' (17 pixels wide) 0x00, 0x00, 0x00, // diff --git a/drivers/CoreVideo/source/CoreLCDDriverOTM8009A.cpp b/drivers/CoreVideo/source/CoreLCDDriverOTM8009A.cpp index 93994e7de4..f92e851f13 100644 --- a/drivers/CoreVideo/source/CoreLCDDriverOTM8009A.cpp +++ b/drivers/CoreVideo/source/CoreLCDDriverOTM8009A.cpp @@ -3,7 +3,6 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include "rtos/ThisThread.h" @@ -284,7 +283,7 @@ void CoreLCDDriverOTM8009A::setLandscapeOrientation() return std::to_integer(_settings); }; - constexpr auto command = lstd::to_array({madctr::command, settings()}); + constexpr auto command = std::to_array({madctr::command, settings()}); _dsi.write(command.data(), std::size(command)); diff --git a/include/cxxsupport/lstd_array b/include/cxxsupport/lstd_array deleted file mode 100644 index f7cca3355c..0000000000 --- a/include/cxxsupport/lstd_array +++ /dev/null @@ -1,80 +0,0 @@ -// vim: set filetype=cpp: -// Leka - LekaOS -// Copyright 2021 APF France handicap -// SPDX-License-Identifier: Apache-2.0 - -#ifndef _LEKA_OS_CXX_SUPPORT_ARRAY_H_ -#define _LEKA_OS_CXX_SUPPORT_ARRAY_H_ - -// clang-format off - -// ? Information about this header -// ? -// ? The purpose of this header is to provide C++ STL functionalities -// ? not yet available in C++17. -// ? -// ? The content of this header was inspired and/or copied from: -// ? > https://en.cppreference.com/w/cpp/container/array/to_array -// ? -// ? Under the following license: -// ? - Creative Commons Attribution-Sharealike 3.0 Unported License (CC-BY-SA) -// ? - GNU Free Documentation License (GFDL) -// ? -// ? It is therefore made available under the same terms. - -#if __cplusplus >= 201703L && __has_include() -#include -#endif - -#if __cpp_lib_to_array >= 201907L - -#include - -namespace lstd { - -using std::to_array; - -} // namespace lstd - -#else // __cpp_lib_to_array >= 201907L - -#include -#include - -// clang-format on - -namespace lstd { - -namespace details { - - template - constexpr auto _to_array(T (&arr)[N], std::index_sequence) -> std::array, N> - { - return {{arr[I]...}}; - } - - template - constexpr auto _to_array(T(&&arr)[N], std::index_sequence) -> std::array, N> - { - return {{std::move(arr[I])...}}; - } - -} // namespace details - -template -constexpr auto to_array(T (&arr)[N]) -{ - return details::_to_array(arr, std::make_index_sequence()); -} - -template -constexpr auto to_array(T(&&arr)[N]) -{ - return details::_to_array(std::move(arr), std::make_index_sequence()); -} - -} // namespace lstd - -#endif // __cpp_lib_to_array >= 202002L - -#endif // _LEKA_OS_CXX_SUPPORT_ARRAY_H_ diff --git a/libs/FileSystemKit/tests/File_test.cpp b/libs/FileSystemKit/tests/File_test.cpp index a035ab6197..7bdee6ec4e 100644 --- a/libs/FileSystemKit/tests/File_test.cpp +++ b/libs/FileSystemKit/tests/File_test.cpp @@ -2,9 +2,9 @@ // Copyright 2021 APF France handicap // SPDX-License-Identifier: Apache-2.0 +#include #include #include -#include #include #include @@ -124,7 +124,7 @@ TEST_F(FileTest, closeNoFile) TEST_F(FileTest, writeSpan) { - auto input_data = lstd::to_array({0x61, 0x62, 0x63, 0x64, 0x65, 0x66}); // "abcdef" + auto input_data = std::to_array({0x61, 0x62, 0x63, 0x64, 0x65, 0x66}); // "abcdef" file.open(tempFilename, "w"); auto size = file.write(input_data); @@ -140,7 +140,7 @@ TEST_F(FileTest, writeSpan) TEST_F(FileTest, writeSpanBinary) { - auto input_data = lstd::to_array({0x61, 0x62, 0x63, 0x64, 0x65, 0x66}); // "abcdef" + auto input_data = std::to_array({0x61, 0x62, 0x63, 0x64, 0x65, 0x66}); // "abcdef" file.open(tempFilename, "wb"); auto size = file.write(input_data); @@ -156,7 +156,7 @@ TEST_F(FileTest, writeSpanBinary) TEST_F(FileTest, writeCharSpan) { - auto input_data = lstd::to_array({'a', 'b', 'c', 'd', 'e', 'f'}); + auto input_data = std::to_array({'a', 'b', 'c', 'd', 'e', 'f'}); file.open(tempFilename, "w"); auto size = file.write(input_data); @@ -172,7 +172,7 @@ TEST_F(FileTest, writeCharSpan) TEST_F(FileTest, writeCharSpanBinary) { - auto input_data = lstd::to_array({'a', 'b', 'c', 'd', 'e', 'f'}); + auto input_data = std::to_array({'a', 'b', 'c', 'd', 'e', 'f'}); file.open(tempFilename, "wb"); auto size = file.write(input_data); @@ -252,7 +252,7 @@ TEST_F(FileTest, writeCharBufferAndSizeBinary) TEST_F(FileTest, readSpan) { - auto input_data = lstd::to_array({0x61, 0x62, 0x63, 0x64, 0x65, 0x66}); // "abcdef" + auto input_data = std::to_array({0x61, 0x62, 0x63, 0x64, 0x65, 0x66}); // "abcdef" writeTempFile(input_data); @@ -268,7 +268,7 @@ TEST_F(FileTest, readSpan) TEST_F(FileTest, readSpanBinary) { - auto input_data = lstd::to_array({0x61, 0x62, 0x63, 0x64, 0x65, 0x66}); // "abcdef" + auto input_data = std::to_array({0x61, 0x62, 0x63, 0x64, 0x65, 0x66}); // "abcdef" writeTempFile(input_data); @@ -284,7 +284,7 @@ TEST_F(FileTest, readSpanBinary) TEST_F(FileTest, readCharSpan) { - auto input_data = lstd::to_array({'a', 'b', 'c', 'd', 'e', 'f'}); + auto input_data = std::to_array({'a', 'b', 'c', 'd', 'e', 'f'}); writeTempFile(input_data); @@ -300,7 +300,7 @@ TEST_F(FileTest, readCharSpan) TEST_F(FileTest, readCharSpanBinary) { - auto input_data = lstd::to_array({'a', 'b', 'c', 'd', 'e', 'f'}); + auto input_data = std::to_array({'a', 'b', 'c', 'd', 'e', 'f'}); writeTempFile(input_data); @@ -401,7 +401,7 @@ TEST_F(FileTest, sizeEmptyFile) TEST_F(FileTest, sizeFile) { - auto input_data = lstd::to_array({0x61, 0x62, 0x63, 0x64, 0x65, 0x66}); // "abcdef" + auto input_data = std::to_array({0x61, 0x62, 0x63, 0x64, 0x65, 0x66}); // "abcdef" file.open(tempFilename); auto expected_size = file.write(input_data); @@ -413,7 +413,7 @@ TEST_F(FileTest, sizeFile) TEST_F(FileTest, writeThenRead) { - auto input_data = lstd::to_array({0x61, 0x62, 0x63, 0x64, 0x65, 0x66}); // "abcdef" + auto input_data = std::to_array({0x61, 0x62, 0x63, 0x64, 0x65, 0x66}); // "abcdef" auto output_data = std::array {}; file.open(tempFilename, "w+"); @@ -428,7 +428,7 @@ TEST_F(FileTest, writeThenRead) TEST_F(FileTest, seek) { - auto input_data = lstd::to_array({0x61, 0x62, 0x63, 0x64, 0x65, 0x66}); // "abcdef" + auto input_data = std::to_array({0x61, 0x62, 0x63, 0x64, 0x65, 0x66}); // "abcdef" auto output_data = std::array {}; auto expected_data = std::array {0x64, 0x65, 0x66, 0x00, 0x00, 0x00}; diff --git a/libs/FirmwareKit/tests/FirmwareKit_test.cpp b/libs/FirmwareKit/tests/FirmwareKit_test.cpp index b493b4e8b1..0cd3ec3ee7 100644 --- a/libs/FirmwareKit/tests/FirmwareKit_test.cpp +++ b/libs/FirmwareKit/tests/FirmwareKit_test.cpp @@ -2,9 +2,9 @@ // Copyright 2021 APF France handicap // SPDX-License-Identifier: Apache-2.0 +#include #include #include -#include #include "FirmwareKit.h" #include "gtest/gtest.h" diff --git a/libs/Utils/tests/MathUtils_test_checksum.cpp b/libs/Utils/tests/MathUtils_test_checksum.cpp index 90b19f45b7..86d57d6eee 100644 --- a/libs/Utils/tests/MathUtils_test_checksum.cpp +++ b/libs/Utils/tests/MathUtils_test_checksum.cpp @@ -2,7 +2,7 @@ // Copyright 2020 APF France handicap // SPDX-License-Identifier: Apache-2.0 -#include +#include #include "Utils.h" #include "gtest/gtest.h" @@ -11,7 +11,7 @@ using namespace leka::utils::math; TEST(MathUtilsTest, checksum8ForOneValue0x00) { - auto data = lstd::to_array({0x00}); + auto data = std::to_array({0x00}); auto checksum = checksum8(data); @@ -20,7 +20,7 @@ TEST(MathUtilsTest, checksum8ForOneValue0x00) TEST(MathUtilsTest, checksum8ForOneValue0xFF) { - auto data = lstd::to_array({0xFF}); + auto data = std::to_array({0xFF}); auto checksum = checksum8(data); @@ -29,7 +29,7 @@ TEST(MathUtilsTest, checksum8ForOneValue0xFF) TEST(MathUtilsTest, checksum8ForOneValueInfoCommand) { - auto data = lstd::to_array({0x70}); + auto data = std::to_array({0x70}); auto checksum = checksum8(data); @@ -39,7 +39,7 @@ TEST(MathUtilsTest, checksum8ForOneValueInfoCommand) TEST(MathUtilsTest, checksum8ForTwoValues) { { - auto data = lstd::to_array({0x00, 0xFF}); + auto data = std::to_array({0x00, 0xFF}); auto checksum = checksum8(data); @@ -47,7 +47,7 @@ TEST(MathUtilsTest, checksum8ForTwoValues) } { - auto data = lstd::to_array({0x01, 0xFF}); + auto data = std::to_array({0x01, 0xFF}); auto checksum = checksum8(data); @@ -55,7 +55,7 @@ TEST(MathUtilsTest, checksum8ForTwoValues) } { - auto data = lstd::to_array({0xFF, 0x01}); + auto data = std::to_array({0xFF, 0x01}); auto checksum = checksum8(data); @@ -65,7 +65,7 @@ TEST(MathUtilsTest, checksum8ForTwoValues) TEST(MathUtilsTest, checksum8ForMultipleValuesTurnOneLedOn) { - auto data = lstd::to_array({0x15, 0x00, 0xFF, 0x00, 0x00}); + auto data = std::to_array({0x15, 0x00, 0xFF, 0x00, 0x00}); auto checksum = checksum8(data); @@ -74,7 +74,7 @@ TEST(MathUtilsTest, checksum8ForMultipleValuesTurnOneLedOn) TEST(MathUtilsTest, checksum8ForMultipleValuesTurnAllLedsOn) { - auto data = lstd::to_array( + auto data = std::to_array( {0x15, 0x00, 0x33, 0x00, 0x00, 0x15, 0x01, 0x66, 0x00, 0x00, 0x15, 0x02, 0x99, 0x00, 0x00, 0x15, 0x03, 0xCC, 0x00, 0x00, 0x15, 0x04, 0xFF, 0x00, 0x00, 0x15, 0x05, 0x00, 0x00, 0x00, 0x15, 0x06, 0x00, 0x33, 0x00, 0x15, 0x07, 0x00, 0x66, 0x00, 0x15, 0x08, 0x00, 0x99, 0x00, 0x15, 0x09, 0x00, 0xCC, 0x00, 0x15, diff --git a/spikes/lk_file_reception/Certificates.h b/spikes/lk_file_reception/Certificates.h index 8389be5d81..9ff381100e 100644 --- a/spikes/lk_file_reception/Certificates.h +++ b/spikes/lk_file_reception/Certificates.h @@ -5,11 +5,11 @@ #ifndef _LEKA_OS_CERTIFICATES_H_ #define _LEKA_OS_CERTIFICATES_H_ -#include +#include namespace leka { -constexpr auto CERTIFICATES = lstd::to_array( +constexpr auto CERTIFICATES = std::to_array( "-----BEGIN CERTIFICATE-----\n" "MIIEGzCCAwOgAwIBAgIQBmcDW7sU/WOvwNaoU07+FjANBgkqhkiG9w0BAQsFADBs\n" "MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3\n" diff --git a/spikes/lk_flash_memory/main.cpp b/spikes/lk_flash_memory/main.cpp index 33886c0f95..82eb8af9e0 100644 --- a/spikes/lk_flash_memory/main.cpp +++ b/spikes/lk_flash_memory/main.cpp @@ -2,7 +2,7 @@ // Copyright 2020 APF France handicap // SPDX-License-Identifier: Apache-2.0 -#include +#include #include "drivers/BufferedSerial.h" #include "rtos/ThisThread.h" @@ -41,7 +41,7 @@ auto main() -> int const size_t bytes_to_read = 0x20; std::array buffer {}; - auto data = lstd::to_array({1, 2, 3, 4, 5, 6, 7, 8, 9}); + auto data = std::to_array({1, 2, 3, 4, 5, 6, 7, 8, 9}); uint32_t address = 0x00; coreis25lp.erase(); diff --git a/spikes/stl_cxxsupport/main.cpp b/spikes/stl_cxxsupport/main.cpp index 95daebea66..86cd5c7008 100644 --- a/spikes/stl_cxxsupport/main.cpp +++ b/spikes/stl_cxxsupport/main.cpp @@ -2,7 +2,7 @@ // Copyright 2021 APF France handicap // SPDX-License-Identifier: Apache-2.0 -#include +#include #include #include "drivers/BufferedSerial.h" @@ -34,12 +34,12 @@ auto main() -> int hello.start(); // - // MARK: - lstd::to_array + // MARK: - std::to_array // - log_info("Create array with lstd::to_array"); + log_info("Create array with std::to_array"); - auto arr = lstd::to_array({1, 2, 3, 4}); + auto arr = std::to_array({1, 2, 3, 4}); for (const auto &v: arr) { log_info("v: %i", v); diff --git a/tests/functional/cert/emc_bt_lcd_qspi_rfid_touch_wifi/CoreFlashUtils.cpp b/tests/functional/cert/emc_bt_lcd_qspi_rfid_touch_wifi/CoreFlashUtils.cpp index 4c7c7c9dea..748db9e9fc 100644 --- a/tests/functional/cert/emc_bt_lcd_qspi_rfid_touch_wifi/CoreFlashUtils.cpp +++ b/tests/functional/cert/emc_bt_lcd_qspi_rfid_touch_wifi/CoreFlashUtils.cpp @@ -2,7 +2,7 @@ // Copyright 2021 APF France handicap // SPDX-License-Identifier: Apache-2.0 -#include +#include #include "rtos/ThisThread.h" @@ -20,7 +20,7 @@ uint32_t address = 0x00; const size_t bytes_to_read = 0x20; std::array buffer {}; -auto data_to_write = lstd::to_array({1, 2, 3, 4, 5, 6, 7, 8, 9}); +auto data_to_write = std::to_array({1, 2, 3, 4, 5, 6, 7, 8, 9}); void flash_loop() { From 4d63fb7a19994966406f4f754d599601d05b1a76 Mon Sep 17 00:00:00 2001 From: Ladislas de Toldi Date: Fri, 7 Jan 2022 12:57:10 +0100 Subject: [PATCH 3/5] :wastebasket: (std): Deprecate lstd_span --- .../include/CoreFlashIS25LP016D.h | 7 +- .../source/CoreFlashIS25LP016D.cpp | 4 +- drivers/CoreQSPI/include/CoreQSPI.h | 10 +- drivers/CoreQSPI/source/CoreQSPI.cpp | 9 +- include/cxxsupport/lstd_span | 344 ------------------ include/interface/drivers/FlashManager.h | 2 +- include/interface/drivers/FlashMemory.h | 9 +- include/interface/drivers/QSPI.h | 12 +- include/interface/platform/File.h | 11 +- libs/FileSystemKit/include/FileSystemKit.h | 9 +- libs/FileSystemKit/source/File.cpp | 9 +- libs/FileSystemKit/tests/File_test.cpp | 6 +- libs/Utils/include/MathUtils.h | 4 +- libs/Utils/source/MathUtils.cpp | 3 +- spikes/stl_cxxsupport/main.cpp | 14 +- tests/unit/mocks/mocks/leka/File.h | 6 +- tests/unit/mocks/mocks/leka/FlashMemory.h | 6 +- tests/unit/mocks/mocks/leka/QSPI.h | 8 +- 18 files changed, 70 insertions(+), 403 deletions(-) delete mode 100644 include/cxxsupport/lstd_span diff --git a/drivers/CoreFlashMemory/include/CoreFlashIS25LP016D.h b/drivers/CoreFlashMemory/include/CoreFlashIS25LP016D.h index 24628d8c21..4ebb747bc1 100644 --- a/drivers/CoreFlashMemory/include/CoreFlashIS25LP016D.h +++ b/drivers/CoreFlashMemory/include/CoreFlashIS25LP016D.h @@ -5,7 +5,8 @@ #ifndef _LEKA_OS_DRIVER_CORE_FLASH_MEMORY_IS25LP016D_H_ #define _LEKA_OS_DRIVER_CORE_FLASH_MEMORY_IS25LP016D_H_ -#include +#include +#include #include "interface/drivers/FlashManager.h" #include "interface/drivers/FlashMemory.h" @@ -23,8 +24,8 @@ class CoreFlashIS25LP016D : public interface::FlashMemory void reset(); - auto read(uint32_t address, lstd::span rx_buffer, size_t rx_buffer_size) -> size_t final; - auto write(uint32_t address, lstd::span tx_buffer, size_t tx_buffer_size) -> size_t final; + auto read(uint32_t address, std::span rx_buffer, size_t rx_buffer_size) -> size_t final; + auto write(uint32_t address, std::span tx_buffer, size_t tx_buffer_size) -> size_t final; void erase() final; diff --git a/drivers/CoreFlashMemory/source/CoreFlashIS25LP016D.cpp b/drivers/CoreFlashMemory/source/CoreFlashIS25LP016D.cpp index c9479f133d..fd81722e10 100644 --- a/drivers/CoreFlashMemory/source/CoreFlashIS25LP016D.cpp +++ b/drivers/CoreFlashMemory/source/CoreFlashIS25LP016D.cpp @@ -21,7 +21,7 @@ void CoreFlashIS25LP016D::reset() _flash_manager.reset(); } -auto CoreFlashIS25LP016D::read(uint32_t address, lstd::span rx_buffer, size_t rx_buffer_size) -> size_t +auto CoreFlashIS25LP016D::read(uint32_t address, std::span rx_buffer, size_t rx_buffer_size) -> size_t { if (address + rx_buffer.size() > flash::is25lp016d::size) { return 0; @@ -36,7 +36,7 @@ auto CoreFlashIS25LP016D::read(uint32_t address, lstd::span rx_buffer, return bytes_read; } -auto CoreFlashIS25LP016D::write(uint32_t address, const lstd::span tx_buffer, size_t tx_buffer_size) -> size_t +auto CoreFlashIS25LP016D::write(uint32_t address, const std::span tx_buffer, size_t tx_buffer_size) -> size_t { if (address + tx_buffer.size() > getSize()) { return 0; diff --git a/drivers/CoreQSPI/include/CoreQSPI.h b/drivers/CoreQSPI/include/CoreQSPI.h index 45a635818d..1b6a2a6a3b 100644 --- a/drivers/CoreQSPI/include/CoreQSPI.h +++ b/drivers/CoreQSPI/include/CoreQSPI.h @@ -5,6 +5,8 @@ #ifndef _LEKA_OS_DRIVER_CORE_QSPI_H_ #define _LEKA_OS_DRIVER_CORE_QSPI_H_ +#include + #include "drivers/QSPI.h" #include "interface/drivers/QSPI.h" @@ -21,11 +23,11 @@ class CoreQSPI : public interface::QSPI void setDataTransmissionFormat() final; void setFrequency(int hz = ONE_MHZ) final; - auto read(uint8_t command, uint32_t address, lstd::span rx_buffer, size_t rx_buffer_size) -> size_t final; - auto write(uint8_t command, uint32_t address, lstd::span tx_buffer, size_t tx_buffer_size) -> size_t final; + auto read(uint8_t command, uint32_t address, std::span rx_buffer, size_t rx_buffer_size) -> size_t final; + auto write(uint8_t command, uint32_t address, std::span tx_buffer, size_t tx_buffer_size) -> size_t final; - auto sendCommand(uint8_t command, uint32_t address, lstd::span tx_buffer, size_t tx_buffer_size, - lstd::span rx_buffer, size_t rx_buffer_size) -> std::tuple final; + auto sendCommand(uint8_t command, uint32_t address, std::span tx_buffer, size_t tx_buffer_size, + std::span rx_buffer, size_t rx_buffer_size) -> std::tuple final; private: mbed::QSPI _qspi; diff --git a/drivers/CoreQSPI/source/CoreQSPI.cpp b/drivers/CoreQSPI/source/CoreQSPI.cpp index 12ed2a2075..355c4d2acd 100644 --- a/drivers/CoreQSPI/source/CoreQSPI.cpp +++ b/drivers/CoreQSPI/source/CoreQSPI.cpp @@ -25,7 +25,7 @@ void CoreQSPI::setFrequency(int hz) _qspi.set_frequency(hz); } -auto CoreQSPI::read(uint8_t command, uint32_t address, lstd::span rx_buffer, size_t rx_buffer_size) -> size_t +auto CoreQSPI::read(uint8_t command, uint32_t address, std::span rx_buffer, size_t rx_buffer_size) -> size_t { // ? Use local variable as Mbed's QSPI driver returns the number of bytes read as an in/out parameter auto size = rx_buffer_size; @@ -35,7 +35,7 @@ auto CoreQSPI::read(uint8_t command, uint32_t address, lstd::span rx_bu return size; } -auto CoreQSPI::write(uint8_t command, uint32_t address, const lstd::span tx_buffer, size_t tx_buffer_size) +auto CoreQSPI::write(uint8_t command, uint32_t address, const std::span tx_buffer, size_t tx_buffer_size) -> size_t { // ? Use local variable as Mbed's QSPI driver returns the number of bytes written as an in/out parameter @@ -46,9 +46,8 @@ auto CoreQSPI::write(uint8_t command, uint32_t address, const lstd::span tx_buffer, - size_t tx_buffer_size, lstd::span rx_buffer, size_t rx_buffer_size) - -> std::tuple +auto CoreQSPI::sendCommand(uint8_t command, uint32_t address, const std::span tx_buffer, size_t tx_buffer_size, + std::span rx_buffer, size_t rx_buffer_size) -> std::tuple { // ? Use local variable as Mbed's QSPI drivers returns the number of bytes read/written as an in/out parameter auto tx_size = tx_buffer_size; diff --git a/include/cxxsupport/lstd_span b/include/cxxsupport/lstd_span deleted file mode 100644 index 9d596ba802..0000000000 --- a/include/cxxsupport/lstd_span +++ /dev/null @@ -1,344 +0,0 @@ -// vim: set filetype=cpp: -// Leka - LekaOS -// Copyright 2021 APF France handicap -// SPDX-License-Identifier: Apache-2.0 - -#ifndef _LEKA_OS_CXX_SUPPORT_SPAN_H_ -#define _LEKA_OS_CXX_SUPPORT_SPAN_H_ - -// clang-format off - -// ? Information about this header -// ? -// ? The purpose of this header is to provide C++ STL functionalities -// ? not yet available in C++17. -// ? -// ? The content of this header was inspired and/or copied from: -// ? > https://github.com/ARMmbed/mbed-os/blob/5fe4dafc349c4b0e93e3d2daeb933977c6851653/platform/cxxsupport/mstd_span -// ? -// ? Under the following license(s): -// ? - Copyright (c) 2019 ARM Limited -// ? - Apache-2.0 -// ? -// ? It is therefore made available under the same terms. - -#if __cplusplus >= 201703L && __has_include() -#include -#endif - -#if __cpp_lib_span >= 202002L - -#include - -namespace lstd { - -using std::dynamic_extent; -using std::span; - -} // namespace lstd - -#else //__cpp_lib_span >= 202002L - -#include -#include -#include -#include -#include - -// clang-format on - -namespace lstd { - -constexpr std::size_t dynamic_extent = -1; - -template -class span; - -namespace detail { - - template - struct storage { - constexpr storage() noexcept = default; - - constexpr storage(ElementType *ptr, std::size_t size) noexcept : _data(ptr) {} - - ElementType *_data = nullptr; - static constexpr std::size_t _size = Extent; - }; - - template - constexpr std::size_t storage::_size; - - template - struct storage { - constexpr storage() noexcept = default; - - constexpr storage(ElementType *ptr, std::size_t size) noexcept : _data(ptr), _size(size) {} - - ElementType *_data = nullptr; - std::size_t _size = 0; - }; - - template - struct is_span : std::false_type { - }; - - template - struct is_span> : std::true_type { - }; - - template - struct is_std_array : std::false_type { - }; - - template - struct is_std_array> : std::true_type { - }; - - template - struct has_size : std::false_type { - }; - - template - struct has_size()))>> : std::true_type { - }; - - template - struct has_data : std::false_type { - }; - - template - struct has_data()))>> : std::true_type { - }; - - template > - struct is_container { - static constexpr bool value = !is_span::value && !is_std_array::value && !std::is_array::value && - has_size::value && has_data::value; - }; - - template - using iterator_t = decltype(std::begin(std::declval())); - - template - using range_reference_t = mstd::iter_reference_t>; - - template - struct is_compatible : std::false_type { - }; - - template - struct is_compatible()))>, void>::value>> - : std::is_convertible()))> (*)[], E (*)[]> { - }; - -} // namespace detail - -template -class span -{ - public: - using element_type = ElementType; - using value_type = typename std::remove_cv_t; - using index_type = std::size_t; - using difference_type = ptrdiff_t; - using pointer = element_type *; - using const_pointer = const element_type *; - using reference = element_type &; - using const_reference = const element_type &; - using iterator = pointer; - using reverse_iterator = std::reverse_iterator; - - static constexpr index_type extent = Extent; - - // Constructors, copy and assignment - template = 0> - constexpr span() noexcept - { - } - - template > (*)[], - ElementType (*)[]>::value, - int> = 0> - constexpr span(It ptr, index_type count) : _storage(ptr, count) - { - static_assert(extent == dynamic_extent || extent == count); - } - - template > (*)[], - ElementType (*)[]>::value, - int> = 0> - constexpr span(It first, It last) : _storage(first, last - first) - { - static_assert(first <= last); - static_assert(extent == dynamic_extent || extent == last - first); - static_assert(extent == 0 || nullptr != first); - } - - template - constexpr span( - mstd::type_identity_t (&arr)[N], - typename std::enable_if_t< - (Extent == dynamic_extent || Extent == N) && - std::is_convertible (*)[], ElementType (*)[]>::value, - int> /*unused*/ - = 0) noexcept - : _storage(arr, N) - { - } - - template - constexpr span( - std::array &arr, - typename std::enable_if_t< - (Extent == dynamic_extent || Extent == N) && - std::is_convertible (*)[], ElementType (*)[]>::value, - int> = 0) noexcept - : _storage(arr.data(), N) - { - } - - template - constexpr span( - const std::array &arr, - typename std::enable_if_t< - (Extent == dynamic_extent || Extent == N) && - std::is_convertible (*)[], ElementType (*)[]>::value, - int> = 0) noexcept - : _storage(arr.data(), N) - { - } - - template ::value && detail::is_compatible::value, int> = 0> - constexpr span(R &&r) : _storage(std::data(r), std::size(r)) - { - static_assert(extent == dynamic_extent || extent == std::size(r)); - } - - constexpr span(const span &other) noexcept = default; - - template ::value, - int> = 0> - constexpr span(const span &s) noexcept : _storage(s.data(), s.size()) - { - } - - ~span() noexcept = default; - - constexpr auto operator=(const span &other) noexcept -> span & = default; - - // Subviews - template - constexpr auto first() const -> span - { - static_assert(Count <= extent); - static_assert(Count <= size()); - return {data(), Count}; - } - - template - constexpr auto last() const -> span - { - static_assert(Count <= extent); - static_assert(Count <= size()); - return {data() + (size() - Count), Count}; - } - - template - constexpr auto subspan() const - -> span - { - static_assert(Offset <= extent && (Count == dynamic_extent || Count <= extent - Offset)); - // Only check against Offset == 0 to prevent a warning for subspan<0, N> - static_assert((Offset == 0 || Offset <= size()) && (Count == dynamic_extent || Count <= size() - Offset)); - return {data() + Offset, Count != dynamic_extent ? Count : size() - Offset}; - } - - constexpr auto first(index_type count) const -> span - { - static_assert(count <= size()); - return {data(), count}; - } - - constexpr auto last(index_type count) const -> span - { - static_assert(count <= size()); - return {data() + (size() - count), count}; - } - - constexpr auto subspan(index_type offset, index_type count = dynamic_extent) const - -> span - { - static_assert(offset <= size() && (count == dynamic_extent || count <= size() - offset)); - return {data() + offset, count == dynamic_extent ? size() - offset : count}; - } - - // Observers - [[nodiscard]] constexpr auto size() const noexcept -> index_type { return _storage._size; } - - [[nodiscard]] constexpr auto size_bytes() const noexcept -> index_type { return size() * sizeof(element_type); } - - [[nodiscard]] constexpr auto empty() const noexcept -> bool { return size() == 0; } - - // Element access - constexpr auto operator[](index_type idx) const -> reference { return *(data() + idx); } - - constexpr auto front() const -> reference { return *data(); } - - constexpr auto back() const -> reference { return *(data() + (size() - 1)); } - - constexpr auto data() const noexcept -> pointer { return _storage._data; } - - // Iterators - constexpr auto begin() const noexcept -> iterator { return data(); } - - constexpr auto end() const noexcept -> iterator { return data() + size(); } - - constexpr auto rbegin() const noexcept -> reverse_iterator { return reverse_iterator(end()); } - - constexpr auto rend() const noexcept -> reverse_iterator { return reverse_iterator(begin()); } - - private: - detail::storage _storage; -}; - -// clang-format off - -template -constexpr typename span::index_type span::extent; - -#if __cplusplus >= 201703L || __cpp_deduction_guides >= 201703L - -// Deduction guides -template -span(It, EndOrSize) -> span>>; - -template -span(T (&)[N]) -> span; - -template -span(std::array &) -> span; - -template -span(const std::array &) -> span; - -template -span(R &&) -> span>>; - -#endif //__cplusplus >= 201703L || __cpp_deduction_guides >= 201703L - -// clang-format on - -} // namespace lstd - -#endif //__cpp_lib_span >= 202002L - -#endif // _LEKA_OS_CXX_SUPPORT_SPAN_H_ diff --git a/include/interface/drivers/FlashManager.h b/include/interface/drivers/FlashManager.h index 242e1d1d41..b85fa03a2e 100644 --- a/include/interface/drivers/FlashManager.h +++ b/include/interface/drivers/FlashManager.h @@ -5,7 +5,7 @@ #ifndef _LEKA_OS_DRIVER_INTERFACE_FLASH_MANAGER_H_ #define _LEKA_OS_DRIVER_INTERFACE_FLASH_MANAGER_H_ -#include +#include namespace leka::interface { diff --git a/include/interface/drivers/FlashMemory.h b/include/interface/drivers/FlashMemory.h index 9c11751007..70da10f94c 100644 --- a/include/interface/drivers/FlashMemory.h +++ b/include/interface/drivers/FlashMemory.h @@ -5,9 +5,8 @@ #ifndef _LEKA_OS_DRIVER_INTERFACE_FLASH_MEMORY_DRIVER_H_ #define _LEKA_OS_DRIVER_INTERFACE_FLASH_MEMORY_DRIVER_H_ -#include - -#include "../../cxxsupport/lstd_span" +#include +#include namespace leka::interface { @@ -18,8 +17,8 @@ class FlashMemory virtual auto getSize() -> size_t = 0; - virtual auto read(uint32_t address, lstd::span rx_buffer, size_t rx_buffer_size) -> size_t = 0; - virtual auto write(uint32_t address, lstd::span tx_buffer, size_t tx_buffer_size) -> size_t = 0; + virtual auto read(uint32_t address, std::span rx_buffer, size_t rx_buffer_size) -> size_t = 0; + virtual auto write(uint32_t address, std::span tx_buffer, size_t tx_buffer_size) -> size_t = 0; virtual void erase() = 0; }; diff --git a/include/interface/drivers/QSPI.h b/include/interface/drivers/QSPI.h index d136ea964f..a4ea798da2 100644 --- a/include/interface/drivers/QSPI.h +++ b/include/interface/drivers/QSPI.h @@ -5,10 +5,10 @@ #ifndef _LEKA_OS_DRIVER_INTERFACE_QSPI_H_ #define _LEKA_OS_DRIVER_INTERFACE_QSPI_H_ +#include +#include #include -#include "../../cxxsupport/lstd_span" - namespace leka::interface { class QSPI @@ -19,13 +19,13 @@ class QSPI virtual void setDataTransmissionFormat() = 0; virtual void setFrequency(int hz = 1'000'000) = 0; - virtual auto read(uint8_t command, uint32_t address, lstd::span rx_buffer, size_t rx_buffer_size) + virtual auto read(uint8_t command, uint32_t address, std::span rx_buffer, size_t rx_buffer_size) -> size_t = 0; - virtual auto write(uint8_t command, uint32_t address, const lstd::span tx_buffer, size_t tx_buffer_size) + virtual auto write(uint8_t command, uint32_t address, const std::span tx_buffer, size_t tx_buffer_size) -> size_t = 0; - virtual auto sendCommand(uint8_t command, uint32_t address, const lstd::span tx_buffer, - size_t tx_buffer_size, lstd::span rx_buffer, size_t rx_buffer_size) + virtual auto sendCommand(uint8_t command, uint32_t address, const std::span tx_buffer, + size_t tx_buffer_size, std::span rx_buffer, size_t rx_buffer_size) -> std::tuple = 0; }; diff --git a/include/interface/platform/File.h b/include/interface/platform/File.h index 0bc11d12fb..12cdedf61f 100644 --- a/include/interface/platform/File.h +++ b/include/interface/platform/File.h @@ -5,7 +5,8 @@ #ifndef _LEKA_OS_INTERFACE_PLATFORM_FILE_H_ #define _LEKA_OS_INTERFACE_PLATFORM_FILE_H_ -#include "../../cxxsupport/lstd_span" +#include +#include namespace leka::interface { @@ -16,11 +17,11 @@ struct File { virtual void close() = 0; - virtual auto read(lstd::span buffer) -> size_t = 0; - virtual auto write(lstd::span data) -> size_t = 0; + virtual auto read(std::span buffer) -> size_t = 0; + virtual auto write(std::span data) -> size_t = 0; - virtual auto read(lstd::span buffer) -> size_t = 0; - virtual auto write(lstd::span data) -> size_t = 0; + virtual auto read(std::span buffer) -> size_t = 0; + virtual auto write(std::span data) -> size_t = 0; virtual auto read(uint8_t *buffer, uint32_t size) -> size_t = 0; virtual auto write(const uint8_t *data, uint32_t size) -> size_t = 0; diff --git a/libs/FileSystemKit/include/FileSystemKit.h b/libs/FileSystemKit/include/FileSystemKit.h index 4715bea1dc..3cd5553e55 100644 --- a/libs/FileSystemKit/include/FileSystemKit.h +++ b/libs/FileSystemKit/include/FileSystemKit.h @@ -6,6 +6,7 @@ #define _LEKA_OS_LIB_FILE_SYSTEM_KIT_H_ #include +#include #include "platform/NonCopyable.h" @@ -22,11 +23,11 @@ class FileSystemKit auto open(const char *path, const char *mode = "r") -> bool final; void close() final; - auto read(lstd::span buffer) -> size_t final; - auto write(lstd::span data) -> size_t final; + auto read(std::span buffer) -> size_t final; + auto write(std::span data) -> size_t final; - auto read(lstd::span buffer) -> size_t final; - auto write(lstd::span data) -> size_t final; + auto read(std::span buffer) -> size_t final; + auto write(std::span data) -> size_t final; auto read(uint8_t *buffer, uint32_t size) -> size_t final; auto write(const uint8_t *data, uint32_t size) -> size_t final; diff --git a/libs/FileSystemKit/source/File.cpp b/libs/FileSystemKit/source/File.cpp index 5e7679a212..b8a51477fd 100644 --- a/libs/FileSystemKit/source/File.cpp +++ b/libs/FileSystemKit/source/File.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include "FileSystemKit.h" @@ -34,22 +35,22 @@ void FileSystemKit::File::close() _file.reset(nullptr); } -auto FileSystemKit::File::read(lstd::span buffer) -> size_t +auto FileSystemKit::File::read(std::span buffer) -> size_t { return std::fread(buffer.data(), sizeof(uint8_t), buffer.size(), _file.get()); } -auto FileSystemKit::File::write(lstd::span data) -> size_t +auto FileSystemKit::File::write(std::span data) -> size_t { return std::fwrite(data.data(), sizeof(uint8_t), data.size(), _file.get()); } -auto FileSystemKit::File::read(lstd::span buffer) -> size_t +auto FileSystemKit::File::read(std::span buffer) -> size_t { return std::fread(buffer.data(), sizeof(char), buffer.size(), _file.get()); } -auto FileSystemKit::File::write(lstd::span data) -> size_t +auto FileSystemKit::File::write(std::span data) -> size_t { return std::fwrite(data.data(), sizeof(char), data.size(), _file.get()); } diff --git a/libs/FileSystemKit/tests/File_test.cpp b/libs/FileSystemKit/tests/File_test.cpp index 7bdee6ec4e..afbd8c74dd 100644 --- a/libs/FileSystemKit/tests/File_test.cpp +++ b/libs/FileSystemKit/tests/File_test.cpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #include "FileSystemKit.h" @@ -36,14 +36,14 @@ class FileTest : public ::testing::Test return out.str(); } - void writeTempFile(lstd::span data) + void writeTempFile(std::span data) { auto *file = fopen(tempFilename, "wb"); fwrite(data.data(), sizeof(uint8_t), data.size(), file); fclose(file); } - void writeTempFile(lstd::span data) + void writeTempFile(std::span data) { auto *file = fopen(tempFilename, "w"); fwrite(data.data(), sizeof(char), data.size(), file); diff --git a/libs/Utils/include/MathUtils.h b/libs/Utils/include/MathUtils.h index 1470a35ba6..dbb2f41d10 100644 --- a/libs/Utils/include/MathUtils.h +++ b/libs/Utils/include/MathUtils.h @@ -6,7 +6,7 @@ #define _LEKA_OS_LIB_UTILS_MATH_H_ #include -#include +#include namespace leka::utils::math { @@ -28,7 +28,7 @@ struct LinearCoefficients { auto computeLinearCoefficients(Point p1, Point p2) -> LinearCoefficients; -auto checksum8(lstd::span data) -> uint8_t; +auto checksum8(std::span data) -> uint8_t; } // namespace leka::utils::math diff --git a/libs/Utils/source/MathUtils.cpp b/libs/Utils/source/MathUtils.cpp index 9372ca0e85..73543cc120 100644 --- a/libs/Utils/source/MathUtils.cpp +++ b/libs/Utils/source/MathUtils.cpp @@ -3,6 +3,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "MathUtils.h" +#include using namespace leka::utils; @@ -19,7 +20,7 @@ auto math::computeLinearCoefficients(Point p1, Point p2) -> LinearCoefficients return coeffs; } -auto math::checksum8(lstd::span data) -> uint8_t +auto math::checksum8(std::span data) -> uint8_t { uint8_t checksum = 0; diff --git a/spikes/stl_cxxsupport/main.cpp b/spikes/stl_cxxsupport/main.cpp index 86cd5c7008..eff0ebd85a 100644 --- a/spikes/stl_cxxsupport/main.cpp +++ b/spikes/stl_cxxsupport/main.cpp @@ -3,7 +3,7 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include +#include #include "drivers/BufferedSerial.h" #include "rtos/ThisThread.h" @@ -14,7 +14,7 @@ using namespace leka; using namespace std::chrono; -void foo(lstd::span span) +void foo(std::span span) { log_info("from foo span size: %i", span.size()); for (const auto &v: span) { @@ -46,16 +46,16 @@ auto main() -> int } // - // MARK: - lstd::span + // MARK: - std::span // - log_info("Pass std::array to lstd::span"); + log_info("Pass std::array to std::span"); foo(arr); log_info("Create span from array, auto deduce size"); - auto span0 = lstd::span {arr}; + auto span0 = std::span {arr}; for (const auto &v: span0) { log_info("v: %i", v); @@ -65,7 +65,7 @@ auto main() -> int log_info("Create span from begin pointer and size"); - auto span1 = lstd::span {arr.begin(), 3}; + auto span1 = std::span {arr.begin(), 3}; for (const auto &v: span1) { log_info("v: %i", v); @@ -75,7 +75,7 @@ auto main() -> int log_info("Create span from specific i-th element and size - i"); - auto span2 = lstd::span {arr.begin() + 2, arr.size() - 2}; + auto span2 = std::span {arr.begin() + 2, arr.size() - 2}; for (const auto &v: span2) { log_info("v: %i", v); diff --git a/tests/unit/mocks/mocks/leka/File.h b/tests/unit/mocks/mocks/leka/File.h index b2a785000d..b6e75e751e 100644 --- a/tests/unit/mocks/mocks/leka/File.h +++ b/tests/unit/mocks/mocks/leka/File.h @@ -5,6 +5,8 @@ #ifndef _LEKA_OS_PLATFORM_FILE_MOCK_H_ #define _LEKA_OS_PLATFORM_FILE_MOCK_H_ +#include + #include "gmock/gmock.h" #include "interface/platform/File.h" @@ -17,8 +19,8 @@ class File : public interface::File MOCK_METHOD(void, close, (), (override)); - MOCK_METHOD(size_t, read, (lstd::span), (override)); - MOCK_METHOD(size_t, write, (lstd::span), (override)); + MOCK_METHOD(size_t, read, (std::span), (override)); + MOCK_METHOD(size_t, write, (std::span), (override)); MOCK_METHOD(size_t, read, (uint8_t *, uint32_t), (override)); MOCK_METHOD(size_t, write, (uint8_t *, uint32_t), (override)); diff --git a/tests/unit/mocks/mocks/leka/FlashMemory.h b/tests/unit/mocks/mocks/leka/FlashMemory.h index 334b22fedf..34718f8d62 100644 --- a/tests/unit/mocks/mocks/leka/FlashMemory.h +++ b/tests/unit/mocks/mocks/leka/FlashMemory.h @@ -5,6 +5,8 @@ #ifndef _LEKA_OS_DRIVERS_FLASH_MEMORY_MOCK_H_ #define _LEKA_OS_DRIVERS_FLASH_MEMORY_MOCK_H_ +#include + #include "gmock/gmock.h" #include "interface/drivers/FlashMemory.h" @@ -15,8 +17,8 @@ class FlashMemory : public interface::FlashMemory public: MOCK_METHOD(size_t, getSize, (), (override)); - MOCK_METHOD(size_t, read, (uint32_t, lstd::span, size_t), (override)); - MOCK_METHOD(size_t, write, (uint32_t, lstd::span, size_t), (override)); + MOCK_METHOD(size_t, read, (uint32_t, std::span, size_t), (override)); + MOCK_METHOD(size_t, write, (uint32_t, std::span, size_t), (override)); MOCK_METHOD(void, erase, (), (override)); }; diff --git a/tests/unit/mocks/mocks/leka/QSPI.h b/tests/unit/mocks/mocks/leka/QSPI.h index 8dfda20ba3..91663c3ea5 100644 --- a/tests/unit/mocks/mocks/leka/QSPI.h +++ b/tests/unit/mocks/mocks/leka/QSPI.h @@ -5,6 +5,8 @@ #ifndef _LEKA_OS_DRIVERS_QSPI_H_ #define _LEKA_OS_DRIVERS_QSPI_H_ +#include + #include "gmock/gmock.h" #include "interface/drivers/QSPI.h" @@ -16,11 +18,11 @@ class QSPI : public interface::QSPI MOCK_METHOD(void, setDataTransmissionFormat, (), (override)); MOCK_METHOD(void, setFrequency, (int), (override)); - MOCK_METHOD(size_t, read, (uint8_t, uint32_t, lstd::span, size_t), (override)); - MOCK_METHOD(size_t, write, (uint8_t, uint32_t, const lstd::span, size_t), (override)); + MOCK_METHOD(size_t, read, (uint8_t, uint32_t, std::span, size_t), (override)); + MOCK_METHOD(size_t, write, (uint8_t, uint32_t, const std::span, size_t), (override)); MOCK_METHOD((std::tuple), sendCommand, - (uint8_t, uint32_t, const lstd::span, size_t, lstd::span, size_t), (override)); + (uint8_t, uint32_t, const std::span, size_t, std::span, size_t), (override)); }; } // namespace leka::mock From e14b11f475b61fb2c2a0c14032856b9ac7535e1a Mon Sep 17 00:00:00 2001 From: Ladislas de Toldi Date: Fri, 7 Jan 2022 13:07:29 +0100 Subject: [PATCH 4/5] :construction_worker: (tests): Use gcc/g++-10 for unit tests --- .github/workflows/ci-code_analysis-sonarcloud.yml | 3 +++ .github/workflows/ci-unit_tests-gcc.yml | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-code_analysis-sonarcloud.yml b/.github/workflows/ci-code_analysis-sonarcloud.yml index 0402871cf5..30d5d40805 100644 --- a/.github/workflows/ci-code_analysis-sonarcloud.yml +++ b/.github/workflows/ci-code_analysis-sonarcloud.yml @@ -82,6 +82,9 @@ jobs: make ccache_prebuild - name: Config, build & run unit tests + env: + CC: /usr/bin/gcc-10 + CXX: /usr/bin/g++-10 run: | make config_unit_tests make unit_tests diff --git a/.github/workflows/ci-unit_tests-gcc.yml b/.github/workflows/ci-unit_tests-gcc.yml index 216a3fd1fe..c49a04a52f 100644 --- a/.github/workflows/ci-unit_tests-gcc.yml +++ b/.github/workflows/ci-unit_tests-gcc.yml @@ -29,8 +29,8 @@ jobs: runs-on: ubuntu-latest env: - CC: /usr/bin/gcc - CXX: /usr/bin/g++ + CC: /usr/bin/gcc-10 + CXX: /usr/bin/g++-10 steps: - uses: actions/checkout@v2 From b095afd0f66805081d400ae8f050507817971e30 Mon Sep 17 00:00:00 2001 From: Ladislas de Toldi Date: Fri, 7 Jan 2022 16:53:26 +0100 Subject: [PATCH 5/5] :wastebasket: (lstd): Clean up cmake files from lstd/cxxsupport --- CMakeLists.txt | 6 ------ tests/unit/CMakeLists.txt | 2 -- 2 files changed, 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 829fe60d3a..d3b36a5d14 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -98,12 +98,6 @@ if (${TARGET_BOARD} IN_LIST AVAILABLE_CUSTOM_TARGETS) add_subdirectory(${TARGETS_DIR}/TARGET_${TARGET_BOARD}) endif() -# Add c++ support, include directories -include_directories(BEFORE SYSTEM - ${INCLUDE_DIR}/cxxsupport - ${MBED_OS_DIR}/platform/cxxsupport -) - include_directories(BEFORE ${INCLUDE_DIR} ) diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index 073096245c..162f99e7a3 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -159,9 +159,7 @@ endfunction() # include_directories(BEFORE SYSTEM - ${EXTERN_MBED_OS_DIR}/UNITTESTS/target_h/platform/cxxsupport ${EXTERN_MBED_OS_DIR}/platform/cxxsupport - ${INCLUDE_DIR}/cxxsupport ${INCLUDE_DIR} )