From 54bd1b6efa900186d743718b9a8bd8c8211c8aa3 Mon Sep 17 00:00:00 2001 From: fastium Date: Sun, 20 Oct 2024 19:07:10 +0200 Subject: [PATCH 1/3] ADD raw pointer tests (run on onlineGDB) --- TESTS/simple-test/test-raw-ptr/main.cpp | 96 +++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 TESTS/simple-test/test-raw-ptr/main.cpp diff --git a/TESTS/simple-test/test-raw-ptr/main.cpp b/TESTS/simple-test/test-raw-ptr/main.cpp new file mode 100644 index 0000000..79ae80b --- /dev/null +++ b/TESTS/simple-test/test-raw-ptr/main.cpp @@ -0,0 +1,96 @@ +// Copyright 2022 Haute école d'ingénierie et d'architecture de Fribourg +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/**************************************************************************** + * @file main.cpp + * @author Serge Ayer + * + * @brief Simple example of test program for raw and shared pointers + * + * @date 2022-09-01 + * @version 0.1.0 + ***************************************************************************/ + +#include "greentea-client/test_env.h" +#include "mbed.h" +#include "unity/unity.h" +#include "utest/utest.h" + +using namespace utest::v1; +struct Test { + Test() { + _instanceCount++; + _value = kMagicNumber; + } + + ~Test() { + _instanceCount--; + _value = 0; + } + + int _value; + static constexpr uint32_t kMagicNumber = 33; + static uint32_t _instanceCount; +}; +uint32_t Test::_instanceCount = 0; + +/** + * Test that a shared pointer correctly manages the lifetime of the underlying raw pointer + */ +void test_single_raw_ptr_lifetime() { + // Sanity-check value of counter + TEST_ASSERT_EQUAL(0, Test::_instanceCount); + + // Create and destroy raw pointer in given scope + { + Test t1; + TEST_ASSERT_EQUAL(1, Test::_instanceCount); + TEST_ASSERT_EQUAL(Test::kMagicNumber, t1._value); + + Test * p1 = &t1; + TEST_ASSERT_EQUAL(1, Test::_instanceCount); + TEST_ASSERT_EQUAL(Test::kMagicNumber, p1->_value); + + const uint32_t number1 = 42; + p1->_value = number1; + TEST_ASSERT_EQUAL(number1, p1->_value); + TEST_ASSERT_EQUAL(number1, t1._value); + + p1 = nullptr; + TEST_ASSERT_EQUAL(1, Test::_instanceCount); + TEST_ASSERT(!p1); + + t1.~Test(); + TEST_ASSERT_EQUAL(0, Test::_instanceCount); + } + + // Destroy shared pointer + TEST_ASSERT_EQUAL(0, Test::_instanceCount); +} + + +static utest::v1::status_t greentea_setup(const size_t number_of_cases) { + // Here, we specify the timeout (60s) and the host test (a built-in host test or the + // name of our Python file) + GREENTEA_SETUP(60, "default_auto"); + return greentea_test_setup_handler(number_of_cases); +} + +// List of test cases in this file +static Case cases[] = { + Case("Test single raw pointer instance", test_single_raw_ptr_lifetime)}; + +static Specification specification(greentea_setup, cases); + +int main() { return !Harness::run(specification); } \ No newline at end of file From fd30e9cd8e6b6fbb87be5004e2270ba1dbb36fd0 Mon Sep 17 00:00:00 2001 From: fastium Date: Sun, 20 Oct 2024 19:10:52 +0200 Subject: [PATCH 2/3] UDP change name and description of the test --- TESTS/simple-test/test-raw-ptr/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/TESTS/simple-test/test-raw-ptr/main.cpp b/TESTS/simple-test/test-raw-ptr/main.cpp index 79ae80b..a689d47 100644 --- a/TESTS/simple-test/test-raw-ptr/main.cpp +++ b/TESTS/simple-test/test-raw-ptr/main.cpp @@ -14,9 +14,9 @@ /**************************************************************************** * @file main.cpp - * @author Serge Ayer + * @author Sierro Yann * - * @brief Simple example of test program for raw and shared pointers + * @brief Test of raw pointer * * @date 2022-09-01 * @version 0.1.0 @@ -93,4 +93,4 @@ static Case cases[] = { static Specification specification(greentea_setup, cases); -int main() { return !Harness::run(specification); } \ No newline at end of file +int main() { return !Harness::run(specification); } From 4dcb25a4554c75e6a51a0c403acd763cc0d5d41f Mon Sep 17 00:00:00 2001 From: Klagarge Date: Mon, 21 Oct 2024 15:41:38 +0200 Subject: [PATCH 3/3] UPD github workflow to include test-raw-ptr --- .github/workflows/build-test.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index b27e936..02152e9 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -14,7 +14,11 @@ jobs: matrix: target: [DISCO_H747I] profile: [develop, debug, release] - tests: [tests-simple-test-always-succeed, tests-simple-test-ptr-test] + tests: [ + tests-simple-test-always-succeed, + tests-simple-test-ptr-test, + tests-simple-test-raw-ptr + ] steps: