diff --git a/UNITTESTS/target_h/nvic_wrapper.h b/UNITTESTS/target_h/nvic_wrapper.h deleted file mode 100644 index 056ba48..0000000 --- a/UNITTESTS/target_h/nvic_wrapper.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2017, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * 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. - */ - -#ifndef NVIC_WRAPPER_H -#define NVIC_WRAPPER_H - -#ifdef __cplusplus -extern "C" -{ -#endif /* __cplusplus */ - -void NVIC_SystemReset(void); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif //NVIC_WRAPPER_H diff --git a/UNITTESTS/target_h/platform/CThunk.h b/UNITTESTS/target_h/platform/CThunk.h deleted file mode 100644 index 79e19aa..0000000 --- a/UNITTESTS/target_h/platform/CThunk.h +++ /dev/null @@ -1,52 +0,0 @@ -/* Copyright (c) 2019 ARM Limited - * SPDX-License-Identifier: Apache-2.0 - * - * 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. - */ - -#ifndef __CTHUNK_H__ -#define __CTHUNK_H__ - -/** - * Class for created a pointer with data bound to it - * - * @note Synchronization level: Not protected - */ -template -class CThunk { -public: - typedef void (T::*CCallbackSimple)(void); - typedef void (T::*CCallback)(void *context); - CThunk() - {} - CThunk(T *instance) - {} - CThunk(T &instance) - {} - void callback(CCallback callback) - {} - - void callback(CCallbackSimple callback) - { - } - uint32_t entry(void) - { - - return 0; - } -}; - - -#endif/*__CTHUNK_H__*/ - - diff --git a/UNITTESTS/target_h/platform/cxxsupport/mstd_algorithm b/UNITTESTS/target_h/platform/cxxsupport/mstd_algorithm deleted file mode 100644 index d13e0f4..0000000 --- a/UNITTESTS/target_h/platform/cxxsupport/mstd_algorithm +++ /dev/null @@ -1,110 +0,0 @@ -/* mbed Microcontroller Library - * Copyright (c) 2019 ARM Limited - * SPDX-License-Identifier: Apache-2.0 - * - * 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. - */ -#ifndef MSTD_ALGORITHM_ -#define MSTD_ALGORITHM_ - -/* - * - * - provides - * - For ARM C 5, standard C++11/14 features: - * - std::min, std::max for std::initializer_list - * - std::all_of, std::any_of, std::none_of - * - std::find_if_not - * - std::equal (2-range forms) - * - std::copy_n, std::move, std::move_backward - * - mstd::min, mstd::max constexpr replacements - */ - -#include - -namespace mstd { -using std::min; -using std::max; -using std::minmax; -using std::initializer_list; -using std::all_of; -using std::any_of; -using std::none_of; -using std::for_each; -using std::find; -using std::find_if; -using std::find_if_not; -using std::find_end; -using std::find_first_of; -using std::adjacent_find; -using std::count; -using std::count_if; -using std::mismatch; -using std::equal; -using std::search; -using std::search_n; -using std::copy; -using std::copy_n; -using std::copy_if; -using std::move; -using std::move_backward; -using std::swap_ranges; -using std::iter_swap; -using std::transform; -using std::replace; -using std::replace_if; -using std::replace_copy; -using std::replace_copy_if; -using std::fill; -using std::fill_n; -using std::generate; -using std::generate_n; -using std::remove; -using std::remove_if; -using std::remove_copy; -using std::remove_copy_if; -using std::unique; -using std::unique_copy; -using std::reverse; -using std::reverse_copy; -using std::rotate; -using std::rotate_copy; -using std::partition; -using std::stable_partition; -using std::sort; -using std::stable_sort; -using std::partial_sort; -using std::partial_sort_copy; -using std::nth_element; -using std::lower_bound; -using std::upper_bound; -using std::equal_range; -using std::binary_search; -using std::merge; -using std::inplace_merge; -using std::includes; -using std::set_union; -using std::set_intersection; -using std::set_difference; -using std::set_symmetric_difference; -using std::push_heap; -using std::pop_heap; -using std::make_heap; -using std::sort_heap; -using std::min_element; -using std::max_element; -using std::lexicographical_compare; -using std::next_permutation; -using std::prev_permutation; -} - -#endif // MSTD_ALGORITHM_ diff --git a/UNITTESTS/target_h/platform/cxxsupport/mstd_atomic b/UNITTESTS/target_h/platform/cxxsupport/mstd_atomic deleted file mode 100644 index db3a442..0000000 --- a/UNITTESTS/target_h/platform/cxxsupport/mstd_atomic +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2017 ARM Limited - * SPDX-License-Identifier: Apache-2.0 - * - * 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. - */ - -#ifndef MSTD_ATOMIC_ -#define MSTD_ATOMIC_ - -#include - -namespace mstd { -using std::atomic; -using std::atomic_is_lock_free; -using std::atomic_store; -using std::atomic_store_explicit; -using std::atomic_load; -using std::atomic_load_explicit; -using std::atomic_exchange; -using std::atomic_exchange_explicit; -using std::atomic_compare_exchange_weak; -using std::atomic_compare_exchange_weak_explicit; -using std::atomic_compare_exchange_strong; -using std::atomic_compare_exchange_strong_explicit; -using std::atomic_fetch_add; -using std::atomic_fetch_add_explicit; -using std::atomic_fetch_sub; -using std::atomic_fetch_sub_explicit; -using std::atomic_fetch_and; -using std::atomic_fetch_and_explicit; -using std::atomic_fetch_or; -using std::atomic_fetch_or_explicit; -using std::atomic_fetch_xor; -using std::atomic_fetch_xor_explicit; -using std::atomic_flag; -using std::atomic_flag_test_and_set; -using std::atomic_flag_test_and_set_explicit; -using std::atomic_flag_clear; -using std::atomic_flag_clear_explicit; -using std::atomic_init; -using std::memory_order; -using std::kill_dependency; -using std::atomic_thread_fence; -using std::atomic_signal_fence; -} - -#endif diff --git a/UNITTESTS/target_h/platform/cxxsupport/mstd_cstddef b/UNITTESTS/target_h/platform/cxxsupport/mstd_cstddef deleted file mode 100644 index 326661e..0000000 --- a/UNITTESTS/target_h/platform/cxxsupport/mstd_cstddef +++ /dev/null @@ -1,54 +0,0 @@ -/* mbed Microcontroller Library - * Copyright (c) 2019 ARM Limited - * SPDX-License-Identifier: Apache-2.0 - * - * 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. - */ -#ifndef MSTD_CSTDDEF_ -#define MSTD_CSTDDEF_ - -/* - * - * - provides - * - For ARM C 5, standard C++11/14 features: - * - - adds macro replacements for alignof and alignas keywords - * - - adds missing std::nullptr_t - * - For all toolchains: - * - - MSTD_CONSTEXPR_XX_14 macros that can be used to mark - * things that are valid as constexpr only for C++14 or later, - * permitting constexpr use where ARM C 5 would reject it. - */ - -#include - -/* Macros that can be used to mark functions and objects that are - * constexpr in C++14 or later, but not in earlier versions. - */ -#if __cplusplus >= 201402 -#define MSTD_CONSTEXPR_FN_14 constexpr -#define MSTD_CONSTEXPR_OBJ_14 constexpr -#else -#define MSTD_CONSTEXPR_FN_14 inline -#define MSTD_CONSTEXPR_OBJ_14 const -#endif - -namespace mstd -{ -using std::size_t; -using std::ptrdiff_t; -using std::nullptr_t; -using std::max_align_t; - -} - -#endif // MSTD_CSTDDEF_ diff --git a/UNITTESTS/target_h/platform/cxxsupport/mstd_functional b/UNITTESTS/target_h/platform/cxxsupport/mstd_functional deleted file mode 100644 index ac867e1..0000000 --- a/UNITTESTS/target_h/platform/cxxsupport/mstd_functional +++ /dev/null @@ -1,141 +0,0 @@ -/* mbed Microcontroller Library - * Copyright (c) 2019 ARM Limited - * SPDX-License-Identifier: Apache-2.0 - * - * 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 tUNChe License. - */ -#ifndef MSTD_FUNCTIONAL_ -#define MSTD_FUNCTIONAL_ - -/* - * - * - includes toolchain's - * - For ARM C 5, standard C++11/14 features: - * - std::mem_fn, - * - std::reference_wrapper, std::ref, std::cref - * - transparent std::plus<> etc - * - std::bit_and, std::bit_or, std::bit_xor, std::bit_not - * - For all toolchains, C++17/20 backports: - * - mbed::not_fn (C++17) - * - mbed::invoke (C++17) - * - mstd::unwrap_reference, mstd::unwrap_ref_decay (C++20) - */ - -#include - -#include // addressof -#include // forward -#include - -namespace mstd { - -// [func.invoke] -#if __cpp_lib_invoke >= 201411 -using std::invoke; -#else -template -invoke_result_t invoke(F&& f, Args&&... args) -{ - return impl::INVOKE(std::forward(f), std::forward(args)...); -} -#endif // __cpp_lib_invoke - -} // namespace mstd - -namespace mstd { -using std::reference_wrapper; -using std::ref; -using std::cref; -using std::plus; -using std::minus; -using std::multiplies; -using std::divides; -using std::modulus; -using std::negate; -using std::equal_to; -using std::not_equal_to; -using std::greater; -using std::less; -using std::greater_equal; -using std::less_equal; -using std::logical_and; -using std::logical_or; -using std::logical_not; -using std::bit_and; -using std::bit_or; -using std::bit_xor; -using std::bit_not; - -#if __cpp_lib_not_fn >= 201603 -using std::not_fn; -#else -namespace impl { -// [func.not_fn] -template -class not_fn_t { - std::decay_t fn; -public: - explicit not_fn_t(F&& f) : fn(std::forward(f)) { } - not_fn_t(const not_fn_t &other) = default; - not_fn_t(not_fn_t &&other) = default; - - template - auto operator()(Args&&... args) & -> decltype(!std::declval &, Args...>>()) - { - return !mstd::invoke(fn, std::forward(args)...); - } - - template - auto operator()(Args&&... args) const & -> decltype(!std::declval const &, Args...>>()) - { - return !mstd::invoke(fn, std::forward(args)...); - } - - template - auto operator()(Args&&... args) && -> decltype(!std::declval, Args...>>()) - { - return !mstd::invoke(std::move(fn), std::forward(args)...); - } - - template - auto operator()(Args&&... args) const && -> decltype(!std::declval const, Args...>>()) - { - return !mstd::invoke(std::move(fn), std::forward(args)...); - } -}; -} - -template -impl::not_fn_t not_fn_t(F&& f) -{ - return impl::not_fn_t(std::forward(f)); -} -#endif - -/* C++20 unwrap_reference */ -template -struct unwrap_reference : type_identity { }; -template -struct unwrap_reference> : type_identity { }; -template -using unwrap_reference_t = typename unwrap_reference::type; - -/* C++20 unwrap_ref_decay */ -template -struct unwrap_ref_decay : unwrap_reference> { }; -template -using unwrap_ref_decay_t = typename unwrap_ref_decay::type; - -} - -#endif // MSTD_FUNCTIONAL_ diff --git a/UNITTESTS/target_h/platform/cxxsupport/mstd_iterator b/UNITTESTS/target_h/platform/cxxsupport/mstd_iterator deleted file mode 100644 index 49e6037..0000000 --- a/UNITTESTS/target_h/platform/cxxsupport/mstd_iterator +++ /dev/null @@ -1,149 +0,0 @@ -/* mbed Microcontroller Library - * Copyright (c) 2019 ARM Limited - * SPDX-License-Identifier: Apache-2.0 - * - * 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. - */ -#ifndef MSTD_ITERATOR_ -#define MSTD_ITERATOR_ - -/* - * - * - includes toolchain's - * - For ARM C 5, C++11/14 features: - * - std::begin, std::end, etc - * - std::move_iterator, std::make_move_iterator - * - For all toolchains, C++17/20 backports: - * - mbed::size - * - mbed::ssize - * - mbed::empty - * - mbed::data - */ - -#include -#include - -namespace mstd { -using std::initializer_list; -using std::iterator_traits; -// omitting deprecated std::iterator -using std::input_iterator_tag; -using std::output_iterator_tag; -using std::forward_iterator_tag; -using std::bidirectional_iterator_tag; -using std::random_access_iterator_tag; -using std::advance; -using std::distance; -using std::next; -using std::prev; -using std::reverse_iterator; -using std::make_reverse_iterator; -using std::back_insert_iterator; -using std::back_inserter; -using std::front_insert_iterator; -using std::front_inserter; -using std::insert_iterator; -using std::inserter; -using std::move_iterator; -using std::make_move_iterator; -using std::istream_iterator; -using std::ostream_iterator; -using std::istreambuf_iterator; -using std::ostreambuf_iterator; -using std::begin; -using std::end; -using std::cbegin; -using std::cend; -using std::rbegin; -using std::rend; -using std::crbegin; -using std::crend; - -#if __cpp_lib_nonmember_container_access >= 201411 -using std::size; -using std::empty; -using std::data; -#else -// [iterator.container] -template -constexpr auto size(const C &c) -> decltype(c.size()) -{ - return c.size(); -} - -template -constexpr size_t size(const T (&)[N]) noexcept -{ - return N; -} - -template -constexpr auto empty(const C &c) -> decltype(c.empty()) -{ - return c.empty(); -} - -template -constexpr bool empty(T (&)[N]) noexcept -{ - return false; -} - -template -constexpr bool empty(initializer_list il) -{ - return il.size() == 0; -} - -template -constexpr auto data(C &c) -> decltype(c.data()) -{ - return c.data(); -} - -template -constexpr auto data(const C &c) -> decltype(c.data()) -{ - return c.data(); -} - -template -constexpr T *data(T (&array)[N]) noexcept -{ - return array; -} - -template -constexpr const E *data(initializer_list il) -{ - return il.begin(); -} -#endif - -// C++20 -template -constexpr auto ssize(const C &c) -> common_type_t> -{ - return static_cast>>(c.size()); -} - -template -constexpr ptrdiff_t ssize(const T (&)[N]) noexcept -{ - return N; -} - -} - - -#endif // MSTD_ITERATOR_ diff --git a/UNITTESTS/target_h/platform/cxxsupport/mstd_memory b/UNITTESTS/target_h/platform/cxxsupport/mstd_memory deleted file mode 100644 index d44e5ed..0000000 --- a/UNITTESTS/target_h/platform/cxxsupport/mstd_memory +++ /dev/null @@ -1,138 +0,0 @@ -/* mbed Microcontroller Library - * Copyright (c) 2019 ARM Limited - * SPDX-License-Identifier: Apache-2.0 - * - * 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. - */ -#ifndef MSTD_MEMORY_ -#define MSTD_MEMORY_ - -/* - * - * - includes toolchain's - * - For ARM C 5, C++11/14 features: - * - std::align - * - std::addressof - * - std::uninitialized_copy_n - * - std::unique_ptr, std::make_unique, std::default_delete - * - For all toolchains, C++17 backports: - * - mstd::uninitialized_default_construct, mstd::uninitialized_value_construct - * - mstd::uninitialized_move, mstd::uninitialized_move_n - * - mstd::destroy_at, mstd::destroy, mstd::destroy_n - */ - -#include - -#include -#include // std::pair -#include // std::iterator_traits - -namespace mstd { - using std::align; - using std::allocator; - using std::addressof; - - // [uninitialized.construct.default] (C++17) - template - void uninitialized_default_construct(ForwardIterator first, ForwardIterator last) { - for (; first != last; ++first) { - ::new (static_cast(addressof(*first))) - typename std::iterator_traits::value_type; - } - } - - template - ForwardIterator uninitialized_default_construct_n(ForwardIterator first, Size n) { - for (; n; ++first, --n) { - ::new (static_cast(addressof(*first))) - typename std::iterator_traits::value_type; - } - - return first; - } - - // [uninitialized.construct.value] (C++17) - template - void uninitialized_value_construct(ForwardIterator first, ForwardIterator last) { - for (; first != last; ++first) { - ::new (static_cast(addressof(*first))) - typename std::iterator_traits::value_type(); - } - } - - template - ForwardIterator uninitialized_value_construct_n(ForwardIterator first, Size n) { - for (; n; ++first, --n) { - ::new (static_cast(addressof(*first))) - typename std::iterator_traits::value_type(); - } - - return first; - } - - // [uninitialized.move] (C++17) - template - ForwardIterator uninitialized_move(InputIterator first, InputIterator last, ForwardIterator result) { - for (; first != last; ++result, (void) ++first) { - ::new (static_cast(addressof(*result))) - typename std::iterator_traits::value_type(move(*first)); - } - - return result; - } - - template - std::pair uninitialized_move_n(InputIterator first, Size n, ForwardIterator result) { - for ( ; n > 0; ++result, (void) ++first, --n) { - ::new (static_cast(addressof(*result))) - typename std::iterator_traits::value_type(std::move(*first)); - } - - return { first, result }; - } - - using std::uninitialized_copy; - using std::uninitialized_copy_n; - using std::uninitialized_fill; - using std::uninitialized_fill_n; - - // [specialized.destroy] (C++17) - template - void destroy_at(T *location) - { - location->~T(); - } - - template - void destroy(ForwardIterator first, ForwardIterator last) - { - for (; first != last; ++first) { - destroy_at(addressof(*first)); - } - } - - template - ForwardIterator destroy_n(ForwardIterator first, Size n) - { - for (; n > 0; (void)++first, --n) { - destroy_at(addressof(*first)); - } - return first; - } - - using std::default_delete; - using std::unique_ptr; - using std::make_unique; -} - -#endif // MSTD_MEMORY_ diff --git a/UNITTESTS/target_h/platform/cxxsupport/mstd_mutex b/UNITTESTS/target_h/platform/cxxsupport/mstd_mutex deleted file mode 100644 index 88c6f82..0000000 --- a/UNITTESTS/target_h/platform/cxxsupport/mstd_mutex +++ /dev/null @@ -1,92 +0,0 @@ -/* mbed Microcontroller Library - * Copyright (c) 2019 ARM Limited - * SPDX-License-Identifier: Apache-2.0 - * - * 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. - */ -#ifndef MSTD_MUTEX_ -#define MSTD_MUTEX_ - -#include - -namespace mstd { -using std::defer_lock; -using std::defer_lock_t; -using std::try_to_lock; -using std::try_to_lock_t; -using std::adopt_lock; -using std::adopt_lock_t; - -using std::lock_guard; -using std::unique_lock; - -using std::try_lock; -using std::lock; - -#if __cpp_lib_scoped_lock >= 201703 -using std::scoped_lock; -#else -// [thread.lock.scoped] -// 2+ locks - use std::lock -template -class scoped_lock -#if 0 // no definition yet - needs tuple - tuple pm; - static void ignore(...) { } -public: - explicit scoped_lock(MutexTypes &... m) : pm(tie(m...)) { mstd::lock(m...); } - explicit scoped_lock(adopt_lock_t, MutexTypes &... m) noexcept : pm(mstd::tie(m...)) { } - ~scoped_lock() { mstd::apply([](MutexTypes &... m) { ignore( (void(m.unlock()),0) ...); }, pm); } - - scoped_lock(const scoped_lock &) = delete; - scoped_lock &operator=(const scoped_lock &) = delete; -} -#else -; -#endif - -// 0 locks - no-op -template <> -class scoped_lock<> { -public: - explicit scoped_lock() = default; - explicit scoped_lock(adopt_lock_t) noexcept { } - ~scoped_lock() = default; - - scoped_lock(const scoped_lock &) = delete; - scoped_lock &operator=(const scoped_lock &) = delete; -}; - -// 1 lock - simple lock, equivalent to lock_guard -template -class scoped_lock { - Mutex ± -public: - using mutex_type = Mutex; - explicit scoped_lock(Mutex &m) : pm(m) { m.lock(); } - explicit scoped_lock(adopt_lock_t, Mutex &m) noexcept : pm(m) { } - ~scoped_lock() { pm.unlock(); } - - scoped_lock(const scoped_lock &) = delete; - scoped_lock &operator=(const scoped_lock &) = delete; -}; -#endif - -using std::once_flag; -using std::call_once; - -using std::mutex; -using std::recursive_mutex; -} - -#endif // MSTD_MUTEX_ diff --git a/UNITTESTS/target_h/platform/cxxsupport/mstd_new b/UNITTESTS/target_h/platform/cxxsupport/mstd_new deleted file mode 100644 index b7e8154..0000000 --- a/UNITTESTS/target_h/platform/cxxsupport/mstd_new +++ /dev/null @@ -1,56 +0,0 @@ -/* mbed Microcontroller Library - * Copyright (c) 2019 ARM Limited - * SPDX-License-Identifier: Apache-2.0 - * - * 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. - */ -#ifndef MSTD_NEW_ -#define MSTD_NEW_ - -/* - * - * - includes toolchain's - * - For all toolchains, C++17 backports: - * - mstd::launder - */ - -#include -#if __cpp_lib_launder < 201606 -#include -#endif - -namespace mstd -{ -using std::nothrow_t; -using std::nothrow; -using std::new_handler; -using std::set_new_handler; - -#if __cpp_lib_launder >= 201606 -using std::launder; -#else -template -constexpr T *launder(T *p) noexcept -{ - static_assert(!std::is_function::value && !std::is_void::value, "Can only launder complete object types"); -#if defined __clang__ || __GNUC__ >= 9 - return __builtin_launder(p); -#else - return p; -#endif -} -#endif - -} // namespace mstd - -#endif // MSTD_NEW_ diff --git a/UNITTESTS/target_h/platform/cxxsupport/mstd_tuple b/UNITTESTS/target_h/platform/cxxsupport/mstd_tuple deleted file mode 100644 index d9e926a..0000000 --- a/UNITTESTS/target_h/platform/cxxsupport/mstd_tuple +++ /dev/null @@ -1,93 +0,0 @@ -/* mbed Microcontroller Library - * Copyright (c) 2019 ARM Limited - * SPDX-License-Identifier: Apache-2.0 - * - * 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 LEOR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef MSTD_TUPLE_ -#define MSTD_TUPLE_ - -/* - * - * - includes toolchain's - * - For all toolchains, C++17 backports: - * - mstd::apply - * - mstd::make_from_tuple - */ - -#include - -#if __cpp_lib_apply < 201603 || __cpp_lib_make_from_tuple < 201606 -#include // integer_sequence -#endif -#if __cpp_lib_apply < 201603 -#include // invoke -#endif - -namespace mstd { -using std::tuple; -using std::ignore; -using std::make_tuple; -using std::forward_as_tuple; -using std::tie; -using std::tuple_cat; -using std::tuple_size; -using std::tuple_element; -using std::tuple_element_t; -using std::get; - -// [tuple.apply] -#if __cpp_lib_apply >= 201603 -using std::apply; -#else -namespace impl { -template -invoke_result_t...> apply(F&& f, Tuple&& t, std::index_sequence) -{ - return mstd::invoke(std::forward(f), std::get(std::forward(t))...); -} -} - -// apply - works also for tuple-like objects such as array or pair -// user-defined types can specialize std::get and std::tuple_size to make this work -template -auto apply(F&& f, Tuple&& t) -> -decltype(impl::apply(std::forward(f), std::forward(t), std::make_index_sequence>::value>{})) -{ - return impl::apply(std::forward(f), std::forward(t), - std::make_index_sequence>::value>{}); -} -#endif - -#if __cpp_lib_make_from_tuple >= 201606 -using std::make_from_tuple; -#else -namespace impl { -template -T make_from_tuple(Tuple&& t, std::index_sequence) -{ - return T(std::get(std::forward(t))...); -} -} - -template -T make_from_tuple(Tuple&& t) -{ - return impl::make_from_tuple(std::forward(t), - std::make_index_sequence>::value>{}); -} -#endif - -} // namespace mstd - -#endif // MSTD_TUPLE_ diff --git a/UNITTESTS/target_h/platform/cxxsupport/mstd_type_traits b/UNITTESTS/target_h/platform/cxxsupport/mstd_type_traits deleted file mode 100644 index 0513ba9..0000000 --- a/UNITTESTS/target_h/platform/cxxsupport/mstd_type_traits +++ /dev/null @@ -1,475 +0,0 @@ -/* mbed Microcontroller Library - * Copyright (c) 2019 ARM Limited - * SPDX-License-Identifier: Apache-2.0 - * - * 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. - */ -#ifndef MSTD_TYPE_TRAITS_ -#define MSTD_TYPE_TRAITS_ - -/* - * - * - includes toolchain's - * - For all toolchains, C++17/20 backports: - * - mstd::type_identity - * - mstd::bool_constant - * - mstd::void_t - * - mstd::is_invocable, mbed::is_invocable_r, etc - * - mstd::invoke_result - * - logical operator traits (mstd::conjunction, mstd::disjunction, mstd::negation) - * - mstd::is_constant_evaluated - */ - -#include -#include - -// The template stuff in here is too confusing for astyle -// *INDENT-OFF* - -namespace mstd { - -/* C++20 type identity */ -template -struct type_identity { - using type = T; -}; - -template -using type_identity_t = typename type_identity::type; - -/* C++17 void_t (foundation for detection idiom) */ -/* void_t is void if args are valid, else a substitution failure */ -#if __cpp_lib_void_t >= 201411 -using std::void_t; -#else -template -using void_t = void; -#endif - -/* C++17 bool_constant */ -#if __cpp_lib_bool_constant >= 201505 -using std::bool_constant; -#else -template -using bool_constant = std::integral_constant; -#endif - -/* Forward declarations */ -#if __cpp_lib_is_invocable >= 201703 -using std::invoke_result; -#else -template -struct invoke_result; -#endif - -} // namespace mstd - -namespace mstd { - -using std::is_same; -using std::conditional; -using std::conditional_t; -using std::enable_if; -using std::enable_if_t; -using std::is_convertible; -using std::is_object; -using std::is_reference; - -/* Reinvent or pull in good stuff not in C++14 into namespace mstd */ -/* C++17 logical operations on traits */ -#if __cpp_lib_logical_traits >= 201510 -using std::conjunction; -using std::disjunction; -using std::negation; -#else -template -struct conjunction : std::true_type { }; -template -struct conjunction : B1 { }; -template -struct conjunction : std::conditional_t, B1> { }; - -template -struct disjunction : std::false_type { }; -template -struct disjunction : B1 { }; -template -struct disjunction : std::conditional_t> { }; - -template -struct negation : bool_constant { }; -#endif - -/* C++ detection idiom from Library fundamentals v2 TS */ -/* Place into mstd::experimental to match their std::experimental */ -namespace experimental { - -namespace impl { -template class Op, class... Args> -struct detector { - using value_t = std::false_type; - using type = Default; -}; - -template class Op, class... Args> -struct detector>, Op, Args...> { - using value_t = std::true_type; - using type = Op; -}; - -} // namespace impl - -struct nonesuch { - ~nonesuch() = delete; - nonesuch(nonesuch const &) = delete; - void operator=(nonesuch const &) = delete; -}; - -#if 0 -/* Deactivated because impl::detector appears to not work on ARM C 5; it seems to produce - * hard errors in the template template parameter expansion. You can use void_t directly instead. - * - * Reactivate if working ARM C 5 implementation discovered, or ARM C 5 support - * dropped. - */ - -template class Op, class... Args> -using is_detected = typename impl::detector::value_t; - -template class Op, class... Args> -using detected_t = typename impl::detector::type; - -template class Op, class... Args> -using detected_or = typename impl::detector; - -template class Op, class... Args> -using detected_or_t = typename detected_or::type; - -template class Op, class... Args> -using is_detected_exact = std::is_same>; - -template class Op, class... Args> -using is_detected_convertible = std::is_convertible, To>; -#endif // if 0 - deactivated detector idiom -} // namespace experimental -} // namespace mstd - -/* More post-C++14 stuff */ -namespace mstd { - -using std::remove_const; -using std::remove_const_t; -using std::remove_volatile; -using std::remove_volatile_t; -using std::remove_cv; -using std::remove_cv_t; -using std::add_const; -using std::add_const_t; -using std::add_volatile; -using std::add_volatile_t; -using std::add_cv; -using std::add_cv_t; -using std::remove_reference; -using std::remove_reference_t; -using std::add_lvalue_reference; -using std::add_rvalue_reference; -using std::is_void; -using std::is_null_pointer; -using std::is_integral; -using std::is_floating_point; -using std::is_array; -using std::is_pointer; -using std::is_lvalue_reference; -using std::is_rvalue_reference; -using std::is_enum; -using std::is_union; -using std::is_class; -using std::is_function; -using std::is_member_function_pointer; -using std::is_member_object_pointer; -using std::is_reference; -using std::is_arithmetic; -using std::is_fundamental; -using std::is_compound; -using std::is_member_pointer; -using std::is_scalar; -using std::is_object; -using std::is_const; -using std::is_volatile; -using std::is_trivial; -using std::is_trivially_copyable; -using std::is_standard_layout; -using std::is_pod; -using std::is_literal_type; -using std::is_empty; -using std::is_polymorphic; -using std::is_abstract; -using std::is_signed; -using std::is_unsigned; -using std::is_constructible; -using std::is_default_constructible; -using std::is_copy_constructible; -using std::is_move_constructible; -using std::is_assignable; -using std::is_copy_assignable; -using std::is_move_assignable; -using std::is_destructible; -using std::is_trivially_constructible; -using std::is_trivially_default_constructible; -using std::is_trivially_copy_constructible; -using std::is_trivially_move_constructible; -using std::is_trivially_assignable; -using std::is_trivially_copy_assignable; -using std::is_trivially_move_assignable; -using std::is_trivially_destructible; -// Exceptions are disabled in mbed, so short-circuit nothrow tests -// (Compilers don't make noexcept() return false with exceptions -// disabled, presumably to preserve binary compatibility, so the -// std versions of these are unduly pessimistic). -template -struct is_nothrow_constructible : is_constructible { }; -template -struct is_nothrow_default_constructible : is_default_constructible { }; -template -struct is_nothrow_copy_constructible : is_copy_constructible { }; -template -struct is_nothrow_move_constructible : is_move_constructible { }; -template -struct is_nothrow_assignable: is_assignable { }; -template -struct is_nothrow_copy_assignable : is_copy_assignable { }; -template -struct is_nothrow_move_assignable : is_move_assignable { }; -using std::has_virtual_destructor; -using std::alignment_of; -using std::rank; -using std::extent; -using std::is_convertible; -using std::is_base_of; -using std::make_signed; -using std::make_signed_t; -using std::make_unsigned; -using std::make_unsigned_t; -using std::remove_extent; -using std::remove_extent_t; -using std::remove_all_extents; -using std::remove_all_extents_t; -using std::remove_pointer; -using std::remove_pointer_t; -using std::add_pointer; -using std::add_pointer_t; -using std::aligned_storage; -using std::aligned_storage_t; -using std::decay; -using std::decay_t; -using std::common_type; -using std::common_type_t; -using std::result_of; -using std::result_of_t; - -/* C++20 remove_cvref */ -template -struct remove_cvref : type_identity>> { }; - -template -using remove_cvref_t = typename remove_cvref::type; - -} - -#if __cpp_lib_invoke < 201411 -#include // want std::forward -#include // want std::reference_wrapper -#elif __cpp_lib_is_invocable < 201703 -#include // want std::invoke -#endif - -namespace mstd { -/* C++17 invoke_result, is_invocable, invoke */ -#if __cpp_lib_is_invocable >= 201703 -/* Library has complete suite - pull it into mstd */ -using std::invoke_result; -using std::invoke_result_t; -using std::is_invocable; -using std::is_nothrow_invocable; -using std::is_invocable_r; -using std::is_nothrow_invocable_r; -#else // __cpp_lib_is_invocable -namespace impl { -#if __cpp_lib_invoke >= 201411 -/* Library has just invoke - make it our impl::INVOKE so we can create invoke_result */ -template -using INVOKE = std::invoke; -#else // __cpp_lib_invoke -/* Define our own INVOKE */ -template -struct is_reference_wrapper : std::false_type { }; - -template -struct is_reference_wrapper> : std::true_type { }; - -/* F is pointer to member function, and 1st arg decays to matching class */ -template -auto INVOKE(F Base::* fn, T1 &&target, Args &&...args) -// Noexcept specifications generate compiler errors unpacking args -//noexcept(noexcept((std::forward(target).*fn)(std::forward(args)...))) - -> std::enable_if_t::value && - std::is_base_of>::value, - decltype((std::forward(target).*fn)(std::forward(args)...))> -{ - return (std::forward(target).*fn)(std::forward(args)...); -} -/* F is pointer to member function, and 1st arg is a reference wrapper */ -template -auto INVOKE(F Base::* fn, T1 &&target, Args &&...args) -//noexcept(noexcept((std::forward(target).get().*fn)(std::forward(args)...))) - -> std::enable_if_t::value && - is_reference_wrapper>::value, - decltype((std::forward(target).get().*fn)(std::forward(args)...))> -{ - return (std::forward(target).get().*fn)(std::forward(args)...); -} -/* F is pointer to member function, and 1st arg doesn't match class and isn't reference wrapper - assume pointer */ -template -auto INVOKE(F Base::* fn, T1 &&target, Args &&...args) -//noexcept(noexcept(((*std::forward(target)).*fn)(std::forward(args)...))) - -> std::enable_if_t::value && - !std::is_base_of>::value && - !is_reference_wrapper>::value, - decltype(((*std::forward(target)).*fn)(std::forward(args)...))> -{ - return ((*std::forward(target)).*fn)(std::forward(args)...); -} -/* F is pointer to member object, and only arg decays to matching class */ -template -auto INVOKE(F Base::* obj, T1 &&target) -//noexcept(noexcept(std::forward(target).*obj)) - -> std::enable_if_t::value && - std::is_base_of>::value, - decltype(std::forward(target).*obj)> -{ - return std::forward(target).*obj; -} -/* F is pointer to member object, and only arg is a reference wrapper */ -template -auto INVOKE(F Base::* obj, T1 &&target) -//noexcept(noexcept(std::forward(target).get().*obj)) - -> std::enable_if_t::value && - is_reference_wrapper>::value, - decltype(std::forward(target).get().*obj)> -{ - return std::forward(target).get().*obj; -} -/* F is pointer to member object, and only arg doesn't match class and isn't reference wrapper - assume pointer */ -template -auto INVOKE(F Base::* obj, T1 &&target) -//noexcept(noexcept((*std::forward(target)).*obj)) - -> std::enable_if_t::value && - !std::is_base_of>::value && - !is_reference_wrapper>::value, - decltype((*std::forward(target)).*obj)> -{ - return (*std::forward(target)).*obj; -} -/* F is not a pointer to member */ -template -auto INVOKE(F&& f, Args&&... args) -//noexcept(noexcept(std::forward(f)(std::forward(args)...))) - -> std::enable_if_t>::value || - (std::is_member_object_pointer>::value && sizeof...(args) != 1), - decltype(std::forward(f)(std::forward(args)...))> -{ - return std::forward(f)(std::forward(args)...); -} -#endif // __cpp_lib_invoke - -template -struct invoke_result { }; -template // void_t appears not to work here - why? -struct invoke_result(), std::declval()...))), F, Args...> : - type_identity(), std::declval()...))> { }; - -// This would be a lot shorter if we could get the detector idiom to work and use it -template -struct is_invocable_r : std::false_type { }; -template -struct is_invocable_r > : - disjunction, std::is_convertible> { }; - -template -struct is_nothrow_invocable_r : std::false_type { }; -template -struct is_nothrow_invocable_r> : - disjunction, - conjunction, - std::is_nothrow_constructible>> { }; - -} //namespace impl - -template -struct invoke_result : impl::invoke_result { }; - -template -using invoke_result_t = typename invoke_result::type; - -template -struct is_invocable : impl::is_invocable_r> { }; - -#if 0 // No exceptions in mbed OS -template -struct is_nothrow_invocable : impl::is_nothrow_invocable_r> { }; -#else -template -struct is_nothrow_invocable : impl::is_invocable_r> { }; -#endif - -template -struct is_invocable_r : impl::is_invocable_r> { }; - -#if 0 // No exceptions in mbed OS -template -struct is_nothrow_invocable_r : conjunction>, - std::is_convertible, R>> { }; -#else -template -struct is_nothrow_invocable_r : impl::is_invocable_r> { }; -#endif - -#endif // __cpp_lib_is_invocable - -/* C++20 is_constant_evaluated */ -constexpr bool is_constant_evaluated() noexcept -{ -#ifdef __clang__ -#if __has_builtin(__builtin_is_constant_evaluated) -#define MSTD_HAS_IS_CONSTANT_EVALUATED 1 - return __builtin_is_constant_evaluated(); -#else - return false; -#endif -#elif __GNUC__ >= 9 -#define MSTD_HAS_IS_CONSTANT_EVALUATED 1 - return __builtin_is_constant_evaluated(); -#else - return false; -#endif -} - -#if MSTD_HAS_IS_CONSTANT_EVALUATED -#define MSTD_CONSTEXPR_IF_HAS_IS_CONSTANT_EVALUATED constexpr -#else -#define MSTD_CONSTEXPR_IF_HAS_IS_CONSTANT_EVALUATED -#endif - -} // namespace mstd - -#endif /* MSTD_TYPE_TRAITS_ */ diff --git a/UNITTESTS/target_h/platform/cxxsupport/mstd_utility b/UNITTESTS/target_h/platform/cxxsupport/mstd_utility deleted file mode 100644 index c05950e..0000000 --- a/UNITTESTS/target_h/platform/cxxsupport/mstd_utility +++ /dev/null @@ -1,75 +0,0 @@ -/* mbed Microcontroller Library - * Copyright (c) 2019 ARM Limited - * SPDX-License-Identifier: Apache-2.0 - * - * 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. - */ -#ifndef MSTD_UTILITY_ -#define MSTD_UTILITY_ - -/* - * - * - includes toolchain's - * - For ARM C 5, standard C++11/14 features: - * - include - * - std::move, std::forward, std::exchange - * - std::declval - * - std::integer_sequence - * - include to get default std::swap - * - mstd::swap - substitute for std::swap that can move - * - std::swap(array) - * - Swap assistance, to ensure moves happen on ARM C 5 - * - mstd::swap - alias for std::swap, or a local moving implementation for ARM C 5 - * - For all toolchains, C++17/20 backports: - * - mstd::as_const - */ - -#include - -namespace mstd { -using std::swap; - -namespace rel_ops { using namespace std::rel_ops; } -using std::initializer_list; -using std::exchange; -using std::forward; -using std::move; -// No exceptions in mbed OS -template -T &&move_if_noexcept(T &t) noexcept -{ - return mstd::move(t); -} -using std::declval; -using std::make_pair; -using std::get; -using std::pair; -using std::integer_sequence; - -// C++17 [utility.as_const] */ -#if __cpp_lib_as_const >= 201510 -using std::as_const; -#else -template -constexpr std::add_const_t<_TypeT> &as_const(_TypeT &__t) noexcept -{ - return __t; -} - -template -void as_const(_TypeT &&) = delete; -#endif - -} // namespace mstd - -#endif // MSTD_UTILITY_ diff --git a/UNITTESTS/target_h/platform/mbed_assert.h b/UNITTESTS/target_h/platform/mbed_assert.h deleted file mode 100644 index 1603c2e..0000000 --- a/UNITTESTS/target_h/platform/mbed_assert.h +++ /dev/null @@ -1,137 +0,0 @@ - -/** \addtogroup platform */ -/** @{*/ -/** - * \defgroup platform_Assert Assert macros - * @{ - */ -/* - * Copyright (c) 2018--2019 Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * 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. - */ -#ifndef MBED_ASSERT_H -#define MBED_ASSERT_H - -#include "mbed_preprocessor.h" -#include "mbed_toolchain.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** Internal mbed assert function which is invoked when MBED_ASSERT macro fails. - * This function is active only if NDEBUG is not defined prior to including this - * assert header file. - * In case of MBED_ASSERT failing condition, error() is called with the assertation message. - * @param expr Expression to be checked. - * @param file File where assertation failed. - * @param line Failing assertation line number. - */ -// mbed_assert_internal UT stub only prints an assert trace and returns, so therefore -// MBED_NORETURN must not be defined for UTs. -MBED_NORETURN -void mbed_assert_internal(const char *expr, const char *file, int line); - -#ifdef __cplusplus -} -#endif - -/** - * For unittests: Global flag to select whether MBED_ASSERT - * throws error. Default false. - */ -extern bool mbed_assert_throw_errors; - -/** MBED_ASSERT - * Declare runtime assertions: results in runtime error if condition is false - * - * @note - * Use of MBED_ASSERT is limited to Debug and Develop builds. - * - * @code - * - * int Configure(serial_t *obj) { - * MBED_ASSERT(obj); - * } - * @endcode - */ -#define MBED_ASSERT(expr) \ -do { \ - if (!(expr)) { \ - mbed_assert_internal(#expr, __FILE__, __LINE__); \ - } \ -} while (0) - -/** MBED_STATIC_ASSERT - * Declare compile-time assertions, results in compile-time error if condition is false - * - * The assertion acts as a declaration that can be placed at file scope, in a - * code block (except after a label), or as a member of a C++ class/struct/union. - * - * @note - * Use of MBED_STATIC_ASSERT as a member of a struct/union is limited: - * - In C++, MBED_STATIC_ASSERT is valid in class/struct/union scope. - * - In C, MBED_STATIC_ASSERT is not valid in struct/union scope, and - * MBED_STRUCT_STATIC_ASSERT is provided as an alternative that is valid - * in C and C++ class/struct/union scope. - * - * @code - * MBED_STATIC_ASSERT(MBED_LIBRARY_VERSION >= 120, - * "The mbed library must be at least version 120"); - * - * int main() { - * MBED_STATIC_ASSERT(sizeof(int) >= sizeof(char), - * "An int must be larger than a char"); - * } - * @endcode - */ -#if defined(__cplusplus) && (__cplusplus >= 201103L || __cpp_static_assert >= 200410L) -#define MBED_STATIC_ASSERT(expr, msg) static_assert(expr, msg) -#elif !defined(__cplusplus) && __STDC_VERSION__ >= 201112L -#define MBED_STATIC_ASSERT(expr, msg) _Static_assert(expr, msg) -#elif defined(__cplusplus) && defined(__GNUC__) && defined(__GXX_EXPERIMENTAL_CXX0X__) \ - && (__GNUC__*100 + __GNUC_MINOR__) > 403L -#define MBED_STATIC_ASSERT(expr, msg) __extension__ static_assert(expr, msg) -#elif !defined(__cplusplus) && defined(__GNUC__) \ - && (__GNUC__*100 + __GNUC_MINOR__) > 406L -#define MBED_STATIC_ASSERT(expr, msg) __extension__ _Static_assert(expr, msg) -#elif defined(__ICCARM__) -#define MBED_STATIC_ASSERT(expr, msg) static_assert(expr, msg) -#else -#define MBED_STATIC_ASSERT(expr, msg) \ - enum {MBED_CONCAT(MBED_ASSERTION_AT_, __LINE__) = sizeof(char[(expr) ? 1 : -1])} -#endif - -/** MBED_STRUCT_STATIC_ASSERT - * Declare compile-time assertions, results in compile-time error if condition is false - * - * Unlike MBED_STATIC_ASSERT, MBED_STRUCT_STATIC_ASSERT can and must be used - * as a member of a C/C++ class/struct/union. - * - * @code - * struct thing { - * MBED_STATIC_ASSERT(2 + 2 == 4, - * "Hopefully the universe is mathematically consistent"); - * }; - * @endcode - */ -#define MBED_STRUCT_STATIC_ASSERT(expr, msg) int : (expr) ? 0 : -1 - - -#endif - -/**@}*/ - -/**@}*/ diff --git a/UNITTESTS/target_h/platform/mbed_power_mgmt.h b/UNITTESTS/target_h/platform/mbed_power_mgmt.h deleted file mode 100644 index a8e83f7..0000000 --- a/UNITTESTS/target_h/platform/mbed_power_mgmt.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) , Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * 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. - */ - -/** Resets the processor and most of the sub-system - * - * @note Does not affect the debug sub-system - */ -#ifndef MBED_POWER_MGMT_H -#define MBED_POWER_MGMT_H - -extern void mock_system_reset(); - -static inline void system_reset(void) -{ - mock_system_reset(); -} - -void sleep_manager_unlock_deep_sleep(void); - -void sleep_manager_lock_deep_sleep(void); - -#endif - diff --git a/UNITTESTS/target_h/platform/mbed_retarget.h b/UNITTESTS/target_h/platform/mbed_retarget.h deleted file mode 100644 index e99d421..0000000 --- a/UNITTESTS/target_h/platform/mbed_retarget.h +++ /dev/null @@ -1,433 +0,0 @@ -/* - * Copyright (c) 2017, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * 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. - */ - -#ifndef RETARGET_H -#define RETARGET_H - -#include -#include -#include - -#include - -#if defined __has_include -# if __has_include () -# include -# define HAVE_SYS_STAT_H -# endif -#endif - - -namespace mbed { - -#define NAME_MAX 255 - -#undef EPERM -#define EPERM 1 /* Operation not permitted */ -#undef ENOENT -#define ENOENT 2 /* No such file or directory */ -#undef ESRCH -#define ESRCH 3 /* No such process */ -#undef EINTR -#define EINTR 4 /* Interrupted system call */ -#undef EIO -#define EIO 5 /* I/O error */ -#undef ENXIO -#define ENXIO 6 /* No such device or address */ -#undef E2BIG -#define E2BIG 7 /* Argument list too long */ -#undef ENOEXEC -#define ENOEXEC 8 /* Exec format error */ -#undef EBADF -#define EBADF 9 /* Bad file number */ -#undef ECHILD -#define ECHILD 10 /* No child processes */ -#undef EAGAIN -#define EAGAIN 11 /* Try again */ -#undef ENOMEM -#define ENOMEM 12 /* Out of memory */ -#undef EACCES -#define EACCES 13 /* Permission denied */ -#undef EFAULT -#define EFAULT 14 /* Bad address */ -#undef ENOTBLK -#define ENOTBLK 15 /* Block device required */ -#undef EBUSY -#define EBUSY 16 /* Device or resource busy */ -#undef EEXIST -#define EEXIST 17 /* File exists */ -#undef EXDEV -#define EXDEV 18 /* Cross-device link */ -#undef ENODEV -#define ENODEV 19 /* No such device */ -#undef ENOTDIR -#define ENOTDIR 20 /* Not a directory */ -#undef EISDIR -#define EISDIR 21 /* Is a directory */ -#undef EINVAL -#define EINVAL 22 /* Invalid argument */ -#undef ENFILE -#define ENFILE 23 /* File table overflow */ -#undef EMFILE -#define EMFILE 24 /* Too many open files */ -#undef ENOTTY -#define ENOTTY 25 /* Not a typewriter */ -#undef ETXTBSY -#define ETXTBSY 26 /* Text file busy */ -#undef EFBIG -#define EFBIG 27 /* File too large */ -#undef ENOSPC -#define ENOSPC 28 /* No space left on device */ -#undef ESPIPE -#define ESPIPE 29 /* Illegal seek */ -#undef EROFS -#define EROFS 30 /* Read-only file system */ -#undef EMLINK -#define EMLINK 31 /* Too many links */ -#undef EPIPE -#define EPIPE 32 /* Broken pipe */ -#undef EDOM -#define EDOM 33 /* Math argument out of domain of func */ -#undef ERANGE -#define ERANGE 34 /* Math result not representable */ -#undef EDEADLK -#define EDEADLK 35 /* Resource deadlock would occur */ -#undef ENAMETOOLONG -#define ENAMETOOLONG 36 /* File name too long */ -#undef ENOLCK -#define ENOLCK 37 /* No record locks available */ -#undef ENOSYS -#define ENOSYS 38 /* Function not implemented */ -#undef ENOTEMPTY -#define ENOTEMPTY 39 /* Directory not empty */ -#undef ELOOP -#define ELOOP 40 /* Too many symbolic links encountered */ -#undef EWOULDBLOCK -#define EWOULDBLOCK EAGAIN /* Operation would block */ -#undef ENOMSG -#define ENOMSG 42 /* No message of desired type */ -#undef EIDRM -#define EIDRM 43 /* Identifier removed */ -#undef ECHRNG -#define ECHRNG 44 /* Channel number out of range */ -#undef EL2NSYNC -#define EL2NSYNC 45 /* Level 2 not synchronized */ -#undef EL3HLT -#define EL3HLT 46 /* Level 3 halted */ -#undef EL3RST -#define EL3RST 47 /* Level 3 reset */ -#undef ELNRNG -#define ELNRNG 48 /* Link number out of range */ -#undef EUNATCH -#define EUNATCH 49 /* Protocol driver not attached */ -#undef ENOCSI -#define ENOCSI 50 /* No CSI structure available */ -#undef EL2HLT -#define EL2HLT 51 /* Level 2 halted */ -#undef EBADE -#define EBADE 52 /* Invalid exchange */ -#undef EBADR -#define EBADR 53 /* Invalid request descriptor */ -#undef EXFULL -#define EXFULL 54 /* Exchange full */ -#undef ENOANO -#define ENOANO 55 /* No anode */ -#undef EBADRQC -#define EBADRQC 56 /* Invalid request code */ -#undef EBADSLT -#define EBADSLT 57 /* Invalid slot */ -#undef EDEADLOCK -#define EDEADLOCK EDEADLK /* Resource deadlock would occur */ -#undef EBFONT -#define EBFONT 59 /* Bad font file format */ -#undef ENOSTR -#define ENOSTR 60 /* Device not a stream */ -#undef ENODATA -#define ENODATA 61 /* No data available */ -#undef ETIME -#define ETIME 62 /* Timer expired */ -#undef ENOSR -#define ENOSR 63 /* Out of streams resources */ -#undef ENONET -#define ENONET 64 /* Machine is not on the network */ -#undef ENOPKG -#define ENOPKG 65 /* Package not installed */ -#undef EREMOTE -#define EREMOTE 66 /* Object is remote */ -#undef ENOLINK -#define ENOLINK 67 /* Link has been severed */ -#undef EADV -#define EADV 68 /* Advertise error */ -#undef ESRMNT -#define ESRMNT 69 /* Srmount error */ -#undef ECOMM -#define ECOMM 70 /* Communication error on send */ -#undef EPROTO -#define EPROTO 71 /* Protocol error */ -#undef EMULTIHOP -#define EMULTIHOP 72 /* Multihop attempted */ -#undef EDOTDOT -#define EDOTDOT 73 /* RFS specific error */ -#undef EBADMSG -#define EBADMSG 74 /* Not a data message */ -#undef EOVERFLOW -#define EOVERFLOW 75 /* Value too large for defined data type */ -#undef ENOTUNIQ -#define ENOTUNIQ 76 /* Name not unique on network */ -#undef EBADFD -#define EBADFD 77 /* File descriptor in bad state */ -#undef EREMCHG -#define EREMCHG 78 /* Remote address changed */ -#undef ELIBACC -#define ELIBACC 79 /* Can not access a needed shared library */ -#undef ELIBBAD -#define ELIBBAD 80 /* Accessing a corrupted shared library */ -#undef ELIBSCN -#define ELIBSCN 81 /* .lib section in a.out corrupted */ -#undef ELIBMAX -#define ELIBMAX 82 /* Attempting to link in too many shared libraries */ -#undef ELIBEXEC -#define ELIBEXEC 83 /* Cannot exec a shared library directly */ -#undef EILSEQ -#define EILSEQ 84 /* Illegal byte sequence */ -#undef ERESTART -#define ERESTART 85 /* Interrupted system call should be restarted */ -#undef ESTRPIPE -#define ESTRPIPE 86 /* Streams pipe error */ -#undef EUSERS -#define EUSERS 87 /* Too many users */ -#undef ENOTSOCK -#define ENOTSOCK 88 /* Socket operation on non-socket */ -#undef EDESTADDRREQ -#define EDESTADDRREQ 89 /* Destination address required */ -#undef EMSGSIZE -#define EMSGSIZE 90 /* Message too long */ -#undef EPROTOTYPE -#define EPROTOTYPE 91 /* Protocol wrong type for socket */ -#undef ENOPROTOOPT -#define ENOPROTOOPT 92 /* Protocol not available */ -#undef EPROTONOSUPPORT -#define EPROTONOSUPPORT 93 /* Protocol not supported */ -#undef ESOCKTNOSUPPORT -#define ESOCKTNOSUPPORT 94 /* Socket type not supported */ -#undef EOPNOTSUPP -#define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */ -#undef EPFNOSUPPORT -#define EPFNOSUPPORT 96 /* Protocol family not supported */ -#undef EAFNOSUPPORT -#define EAFNOSUPPORT 97 /* Address family not supported by protocol */ -#undef EADDRINUSE -#define EADDRINUSE 98 /* Address already in use */ -#undef EADDRNOTAVAIL -#define EADDRNOTAVAIL 99 /* Cannot assign requested address */ -#undef ENETDOWN -#define ENETDOWN 100 /* Network is down */ -#undef ENETUNREACH -#define ENETUNREACH 101 /* Network is unreachable */ -#undef ENETRESET -#define ENETRESET 102 /* Network dropped connection because of reset */ -#undef ECONNABORTED -#define ECONNABORTED 103 /* Software caused connection abort */ -#undef ECONNRESET -#define ECONNRESET 104 /* Connection reset by peer */ -#undef ENOBUFS -#define ENOBUFS 105 /* No buffer space available */ -#undef EISCONN -#define EISCONN 106 /* Transport endpoint is already connected */ -#undef ENOTCONN -#define ENOTCONN 107 /* Transport endpoint is not connected */ -#undef ESHUTDOWN -#define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */ -#undef ETOOMANYREFS -#define ETOOMANYREFS 109 /* Too many references: cannot splice */ -#undef ETIMEDOUT -#define ETIMEDOUT 110 /* Connection timed out */ -#undef ECONNREFUSED -#define ECONNREFUSED 111 /* Connection refused */ -#undef EHOSTDOWN -#define EHOSTDOWN 112 /* Host is down */ -#undef EHOSTUNREACH -#define EHOSTUNREACH 113 /* No route to host */ -#undef EALREADY -#define EALREADY 114 /* Operation already in progress */ -#undef EINPROGRESS -#define EINPROGRESS 115 /* Operation now in progress */ -#undef ESTALE -#define ESTALE 116 /* Stale NFS file handle */ -#undef EUCLEAN -#define EUCLEAN 117 /* Structure needs cleaning */ -#undef ENOTNAM -#define ENOTNAM 118 /* Not a XENIX named type file */ -#undef ENAVAIL -#define ENAVAIL 119 /* No XENIX semaphores available */ -#undef EISNAM -#define EISNAM 120 /* Is a named type file */ -#undef EREMOTEIO -#define EREMOTEIO 121 /* Remote I/O error */ -#undef EDQUOT -#define EDQUOT 122 /* Quota exceeded */ -#undef ENOMEDIUM -#define ENOMEDIUM 123 /* No medium found */ -#undef EMEDIUMTYPE -#define EMEDIUMTYPE 124 /* Wrong medium type */ -#undef ECANCELED -#define ECANCELED 125 /* Operation Canceled */ -#undef ENOKEY -#define ENOKEY 126 /* Required key not available */ -#undef EKEYEXPIRED -#define EKEYEXPIRED 127 /* Key has expired */ -#undef EKEYREVOKED -#define EKEYREVOKED 128 /* Key has been revoked */ -#undef EKEYREJECTED -#define EKEYREJECTED 129 /* Key was rejected by service */ -#undef EOWNERDEAD -#define EOWNERDEAD 130 /* Owner died */ -#undef ENOTRECOVERABLE -#define ENOTRECOVERABLE 131 /* State not recoverable */ - -#define _IFMT 0170000 //< type of file -#define _IFSOCK 0140000 //< socket -#define _IFLNK 0120000 //< symbolic link -#define _IFREG 0100000 //< regular -#define _IFBLK 0060000 //< block special -#define _IFDIR 0040000 //< directory -#define _IFCHR 0020000 //< character special -#define _IFIFO 0010000 //< fifo special - -#ifndef S_IFMT -#define S_IFMT _IFMT //< type of file -#endif -#ifndef S_IFSOCK -#define S_IFSOCK _IFSOCK //< socket -#endif -#ifndef S_IFLNK -#define S_IFLNK _IFLNK //< symbolic link -#endif -#ifndef S_IFREG -#define S_IFREG _IFREG //< regular -#endif -#ifndef S_IFBLK -#define S_IFBLK _IFBLK //< block special -#endif -#ifndef S_IFDIR -#define S_IFDIR _IFDIR //< directory -#endif -#ifndef S_IFCHR -#define S_IFCHR _IFCHR //< character special -#endif -#ifndef S_IFIFO -#define S_IFIFO _IFIFO //< fifo special -#endif - -#ifndef S_IRWXU -#define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR) -#define S_IRUSR 0000400 ///< read permission, owner -#define S_IWUSR 0000200 ///< write permission, owner -#define S_IXUSR 0000100 ///< execute/search permission, owner -#endif /* S_IRWXU */ -#ifndef S_IRWXG -#define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP) -#define S_IRGRP 0000040 ///< read permission, group -#define S_IWGRP 0000020 ///< write permission, group -#define S_IXGRP 0000010 ///< execute/search permission, group -#endif /* S_IRWXG */ -#ifndef S_IRWXO -#define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH) -#define S_IROTH 0000004 ///< read permission, other -#define S_IWOTH 0000002 ///< write permission, other -#define S_IXOTH 0000001 ///< execute/search permission, other -#endif /* S_IRWXO */ - -#define O_RDONLY 0 ///< Open for reading -#define O_WRONLY 1 ///< Open for writing -#define O_RDWR 2 ///< Open for reading and writing -#define O_NONBLOCK 0x0004 ///< Non-blocking mode -#define O_APPEND 0x0008 ///< Set file offset to end of file prior to each write -#define O_CREAT 0x0200 ///< Create file if it does not exist -#define O_TRUNC 0x0400 ///< Truncate file to zero length -#define O_EXCL 0x0800 ///< Fail if file exists -#define O_BINARY 0x8000 ///< Open file in binary mode - -#define O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR) - -#define NAME_MAX 255 ///< Maximum size of a name in a file path - -#define STDIN_FILENO 0 -#define STDOUT_FILENO 1 -#define STDERR_FILENO 2 - -#ifndef HAVE_SYS_STAT_H -struct stat { - dev_t st_dev; ///< Device ID containing file - ino_t st_ino; ///< File serial number - mode_t st_mode; ///< Mode of file - nlink_t st_nlink; ///< Number of links to file - - uid_t st_uid; ///< User ID - gid_t st_gid; ///< Group ID - - off_t st_size; ///< Size of file in bytes - - time_t st_atime; ///< Time of last access - time_t st_mtime; ///< Time of last data modification - time_t st_ctime; ///< Time of last status change -}; -#endif - -struct statvfs { - unsigned long f_bsize; ///< Filesystem block size - unsigned long f_frsize; ///< Fragment size (block size) - - unsigned long long f_blocks; ///< Number of blocks - unsigned long long f_bfree; ///< Number of free blocks - unsigned long long f_bavail; ///< Number of free blocks for unprivileged users - - unsigned long f_fsid; ///< Filesystem ID - - unsigned long f_namemax; ///< Maximum filename length -}; - - -struct dirent { - char d_name[NAME_MAX + 1]; ///< Name of file - uint8_t d_type; ///< Type of file -}; - -enum { - DT_UNKNOWN, ///< The file type could not be determined. - DT_FIFO, ///< This is a named pipe (FIFO). - DT_CHR, ///< This is a character device. - DT_DIR, ///< This is a directory. - DT_BLK, ///< This is a block device. - DT_REG, ///< This is a regular file. - DT_LNK, ///< This is a symbolic link. - DT_SOCK, ///< This is a UNIX domain socket. -}; - -/* fcntl.h defines */ -#define F_GETFL 3 -#define F_SETFL 4 - -struct pollfd { - int fd; - short events; - short revents; -}; - -} - -#endif //RETARGET_H diff --git a/UNITTESTS/target_h/platform/mbed_wait_api.h b/UNITTESTS/target_h/platform/mbed_wait_api.h deleted file mode 100644 index 1659840..0000000 --- a/UNITTESTS/target_h/platform/mbed_wait_api.h +++ /dev/null @@ -1,32 +0,0 @@ - -/* mbed Microcontroller Library - * Copyright (c) 2018 ARM Limited - * SPDX-License-Identifier: Apache-2.0 - * - * 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. - */ -#ifndef MBED_WAIT_API_H -#define MBED_WAIT_API_H - -#ifdef __cplusplus -extern "C" { -#endif - -void wait_us(int us); - -#ifdef __cplusplus -} -#endif - -#endif - diff --git a/UNITTESTS/target_h/platform/platform.h b/UNITTESTS/target_h/platform/platform.h deleted file mode 100644 index 7dc963c..0000000 --- a/UNITTESTS/target_h/platform/platform.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2017, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * 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. - */ - -#ifndef MBED_PLATFORM_H -#define MBED_PLATFORM_H - -#include -#include -#include -#include - -#include "platform/mbed_retarget.h" -#include "nvic_wrapper.h" - -#endif diff --git a/platform/tests/UNITTESTS/doubles/CMakeLists.txt b/platform/tests/UNITTESTS/doubles/CMakeLists.txt index cb8bd7f..8d14bfc 100644 --- a/platform/tests/UNITTESTS/doubles/CMakeLists.txt +++ b/platform/tests/UNITTESTS/doubles/CMakeLists.txt @@ -4,6 +4,9 @@ add_library(mbed-headers-platform INTERFACE) target_include_directories(mbed-headers-platform INTERFACE + . + platform + platform/cxxsupport ${mbed-os_SOURCE_DIR}/platform/include ${mbed-os_SOURCE_DIR}/platform/include/platform ${mbed-os_SOURCE_DIR}/platform/randlib/include/mbed-client-randlib/ diff --git a/platform/tests/UNITTESTS/doubles/platform/CThunk.h b/platform/tests/UNITTESTS/doubles/platform/CThunk.h new file mode 100644 index 0000000..79e19aa --- /dev/null +++ b/platform/tests/UNITTESTS/doubles/platform/CThunk.h @@ -0,0 +1,52 @@ +/* Copyright (c) 2019 ARM Limited + * SPDX-License-Identifier: Apache-2.0 + * + * 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. + */ + +#ifndef __CTHUNK_H__ +#define __CTHUNK_H__ + +/** + * Class for created a pointer with data bound to it + * + * @note Synchronization level: Not protected + */ +template +class CThunk { +public: + typedef void (T::*CCallbackSimple)(void); + typedef void (T::*CCallback)(void *context); + CThunk() + {} + CThunk(T *instance) + {} + CThunk(T &instance) + {} + void callback(CCallback callback) + {} + + void callback(CCallbackSimple callback) + { + } + uint32_t entry(void) + { + + return 0; + } +}; + + +#endif/*__CTHUNK_H__*/ + + diff --git a/platform/tests/UNITTESTS/doubles/platform/cxxsupport/mstd_algorithm b/platform/tests/UNITTESTS/doubles/platform/cxxsupport/mstd_algorithm new file mode 100644 index 0000000..d13e0f4 --- /dev/null +++ b/platform/tests/UNITTESTS/doubles/platform/cxxsupport/mstd_algorithm @@ -0,0 +1,110 @@ +/* mbed Microcontroller Library + * Copyright (c) 2019 ARM Limited + * SPDX-License-Identifier: Apache-2.0 + * + * 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. + */ +#ifndef MSTD_ALGORITHM_ +#define MSTD_ALGORITHM_ + +/* + * + * - provides + * - For ARM C 5, standard C++11/14 features: + * - std::min, std::max for std::initializer_list + * - std::all_of, std::any_of, std::none_of + * - std::find_if_not + * - std::equal (2-range forms) + * - std::copy_n, std::move, std::move_backward + * - mstd::min, mstd::max constexpr replacements + */ + +#include + +namespace mstd { +using std::min; +using std::max; +using std::minmax; +using std::initializer_list; +using std::all_of; +using std::any_of; +using std::none_of; +using std::for_each; +using std::find; +using std::find_if; +using std::find_if_not; +using std::find_end; +using std::find_first_of; +using std::adjacent_find; +using std::count; +using std::count_if; +using std::mismatch; +using std::equal; +using std::search; +using std::search_n; +using std::copy; +using std::copy_n; +using std::copy_if; +using std::move; +using std::move_backward; +using std::swap_ranges; +using std::iter_swap; +using std::transform; +using std::replace; +using std::replace_if; +using std::replace_copy; +using std::replace_copy_if; +using std::fill; +using std::fill_n; +using std::generate; +using std::generate_n; +using std::remove; +using std::remove_if; +using std::remove_copy; +using std::remove_copy_if; +using std::unique; +using std::unique_copy; +using std::reverse; +using std::reverse_copy; +using std::rotate; +using std::rotate_copy; +using std::partition; +using std::stable_partition; +using std::sort; +using std::stable_sort; +using std::partial_sort; +using std::partial_sort_copy; +using std::nth_element; +using std::lower_bound; +using std::upper_bound; +using std::equal_range; +using std::binary_search; +using std::merge; +using std::inplace_merge; +using std::includes; +using std::set_union; +using std::set_intersection; +using std::set_difference; +using std::set_symmetric_difference; +using std::push_heap; +using std::pop_heap; +using std::make_heap; +using std::sort_heap; +using std::min_element; +using std::max_element; +using std::lexicographical_compare; +using std::next_permutation; +using std::prev_permutation; +} + +#endif // MSTD_ALGORITHM_ diff --git a/platform/tests/UNITTESTS/doubles/platform/cxxsupport/mstd_atomic b/platform/tests/UNITTESTS/doubles/platform/cxxsupport/mstd_atomic new file mode 100644 index 0000000..db3a442 --- /dev/null +++ b/platform/tests/UNITTESTS/doubles/platform/cxxsupport/mstd_atomic @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2017 ARM Limited + * SPDX-License-Identifier: Apache-2.0 + * + * 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. + */ + +#ifndef MSTD_ATOMIC_ +#define MSTD_ATOMIC_ + +#include + +namespace mstd { +using std::atomic; +using std::atomic_is_lock_free; +using std::atomic_store; +using std::atomic_store_explicit; +using std::atomic_load; +using std::atomic_load_explicit; +using std::atomic_exchange; +using std::atomic_exchange_explicit; +using std::atomic_compare_exchange_weak; +using std::atomic_compare_exchange_weak_explicit; +using std::atomic_compare_exchange_strong; +using std::atomic_compare_exchange_strong_explicit; +using std::atomic_fetch_add; +using std::atomic_fetch_add_explicit; +using std::atomic_fetch_sub; +using std::atomic_fetch_sub_explicit; +using std::atomic_fetch_and; +using std::atomic_fetch_and_explicit; +using std::atomic_fetch_or; +using std::atomic_fetch_or_explicit; +using std::atomic_fetch_xor; +using std::atomic_fetch_xor_explicit; +using std::atomic_flag; +using std::atomic_flag_test_and_set; +using std::atomic_flag_test_and_set_explicit; +using std::atomic_flag_clear; +using std::atomic_flag_clear_explicit; +using std::atomic_init; +using std::memory_order; +using std::kill_dependency; +using std::atomic_thread_fence; +using std::atomic_signal_fence; +} + +#endif diff --git a/platform/tests/UNITTESTS/doubles/platform/cxxsupport/mstd_cstddef b/platform/tests/UNITTESTS/doubles/platform/cxxsupport/mstd_cstddef new file mode 100644 index 0000000..326661e --- /dev/null +++ b/platform/tests/UNITTESTS/doubles/platform/cxxsupport/mstd_cstddef @@ -0,0 +1,54 @@ +/* mbed Microcontroller Library + * Copyright (c) 2019 ARM Limited + * SPDX-License-Identifier: Apache-2.0 + * + * 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. + */ +#ifndef MSTD_CSTDDEF_ +#define MSTD_CSTDDEF_ + +/* + * + * - provides + * - For ARM C 5, standard C++11/14 features: + * - - adds macro replacements for alignof and alignas keywords + * - - adds missing std::nullptr_t + * - For all toolchains: + * - - MSTD_CONSTEXPR_XX_14 macros that can be used to mark + * things that are valid as constexpr only for C++14 or later, + * permitting constexpr use where ARM C 5 would reject it. + */ + +#include + +/* Macros that can be used to mark functions and objects that are + * constexpr in C++14 or later, but not in earlier versions. + */ +#if __cplusplus >= 201402 +#define MSTD_CONSTEXPR_FN_14 constexpr +#define MSTD_CONSTEXPR_OBJ_14 constexpr +#else +#define MSTD_CONSTEXPR_FN_14 inline +#define MSTD_CONSTEXPR_OBJ_14 const +#endif + +namespace mstd +{ +using std::size_t; +using std::ptrdiff_t; +using std::nullptr_t; +using std::max_align_t; + +} + +#endif // MSTD_CSTDDEF_ diff --git a/platform/tests/UNITTESTS/doubles/platform/cxxsupport/mstd_functional b/platform/tests/UNITTESTS/doubles/platform/cxxsupport/mstd_functional new file mode 100644 index 0000000..ac867e1 --- /dev/null +++ b/platform/tests/UNITTESTS/doubles/platform/cxxsupport/mstd_functional @@ -0,0 +1,141 @@ +/* mbed Microcontroller Library + * Copyright (c) 2019 ARM Limited + * SPDX-License-Identifier: Apache-2.0 + * + * 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 tUNChe License. + */ +#ifndef MSTD_FUNCTIONAL_ +#define MSTD_FUNCTIONAL_ + +/* + * + * - includes toolchain's + * - For ARM C 5, standard C++11/14 features: + * - std::mem_fn, + * - std::reference_wrapper, std::ref, std::cref + * - transparent std::plus<> etc + * - std::bit_and, std::bit_or, std::bit_xor, std::bit_not + * - For all toolchains, C++17/20 backports: + * - mbed::not_fn (C++17) + * - mbed::invoke (C++17) + * - mstd::unwrap_reference, mstd::unwrap_ref_decay (C++20) + */ + +#include + +#include // addressof +#include // forward +#include + +namespace mstd { + +// [func.invoke] +#if __cpp_lib_invoke >= 201411 +using std::invoke; +#else +template +invoke_result_t invoke(F&& f, Args&&... args) +{ + return impl::INVOKE(std::forward(f), std::forward(args)...); +} +#endif // __cpp_lib_invoke + +} // namespace mstd + +namespace mstd { +using std::reference_wrapper; +using std::ref; +using std::cref; +using std::plus; +using std::minus; +using std::multiplies; +using std::divides; +using std::modulus; +using std::negate; +using std::equal_to; +using std::not_equal_to; +using std::greater; +using std::less; +using std::greater_equal; +using std::less_equal; +using std::logical_and; +using std::logical_or; +using std::logical_not; +using std::bit_and; +using std::bit_or; +using std::bit_xor; +using std::bit_not; + +#if __cpp_lib_not_fn >= 201603 +using std::not_fn; +#else +namespace impl { +// [func.not_fn] +template +class not_fn_t { + std::decay_t fn; +public: + explicit not_fn_t(F&& f) : fn(std::forward(f)) { } + not_fn_t(const not_fn_t &other) = default; + not_fn_t(not_fn_t &&other) = default; + + template + auto operator()(Args&&... args) & -> decltype(!std::declval &, Args...>>()) + { + return !mstd::invoke(fn, std::forward(args)...); + } + + template + auto operator()(Args&&... args) const & -> decltype(!std::declval const &, Args...>>()) + { + return !mstd::invoke(fn, std::forward(args)...); + } + + template + auto operator()(Args&&... args) && -> decltype(!std::declval, Args...>>()) + { + return !mstd::invoke(std::move(fn), std::forward(args)...); + } + + template + auto operator()(Args&&... args) const && -> decltype(!std::declval const, Args...>>()) + { + return !mstd::invoke(std::move(fn), std::forward(args)...); + } +}; +} + +template +impl::not_fn_t not_fn_t(F&& f) +{ + return impl::not_fn_t(std::forward(f)); +} +#endif + +/* C++20 unwrap_reference */ +template +struct unwrap_reference : type_identity { }; +template +struct unwrap_reference> : type_identity { }; +template +using unwrap_reference_t = typename unwrap_reference::type; + +/* C++20 unwrap_ref_decay */ +template +struct unwrap_ref_decay : unwrap_reference> { }; +template +using unwrap_ref_decay_t = typename unwrap_ref_decay::type; + +} + +#endif // MSTD_FUNCTIONAL_ diff --git a/platform/tests/UNITTESTS/doubles/platform/cxxsupport/mstd_iterator b/platform/tests/UNITTESTS/doubles/platform/cxxsupport/mstd_iterator new file mode 100644 index 0000000..49e6037 --- /dev/null +++ b/platform/tests/UNITTESTS/doubles/platform/cxxsupport/mstd_iterator @@ -0,0 +1,149 @@ +/* mbed Microcontroller Library + * Copyright (c) 2019 ARM Limited + * SPDX-License-Identifier: Apache-2.0 + * + * 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. + */ +#ifndef MSTD_ITERATOR_ +#define MSTD_ITERATOR_ + +/* + * + * - includes toolchain's + * - For ARM C 5, C++11/14 features: + * - std::begin, std::end, etc + * - std::move_iterator, std::make_move_iterator + * - For all toolchains, C++17/20 backports: + * - mbed::size + * - mbed::ssize + * - mbed::empty + * - mbed::data + */ + +#include +#include + +namespace mstd { +using std::initializer_list; +using std::iterator_traits; +// omitting deprecated std::iterator +using std::input_iterator_tag; +using std::output_iterator_tag; +using std::forward_iterator_tag; +using std::bidirectional_iterator_tag; +using std::random_access_iterator_tag; +using std::advance; +using std::distance; +using std::next; +using std::prev; +using std::reverse_iterator; +using std::make_reverse_iterator; +using std::back_insert_iterator; +using std::back_inserter; +using std::front_insert_iterator; +using std::front_inserter; +using std::insert_iterator; +using std::inserter; +using std::move_iterator; +using std::make_move_iterator; +using std::istream_iterator; +using std::ostream_iterator; +using std::istreambuf_iterator; +using std::ostreambuf_iterator; +using std::begin; +using std::end; +using std::cbegin; +using std::cend; +using std::rbegin; +using std::rend; +using std::crbegin; +using std::crend; + +#if __cpp_lib_nonmember_container_access >= 201411 +using std::size; +using std::empty; +using std::data; +#else +// [iterator.container] +template +constexpr auto size(const C &c) -> decltype(c.size()) +{ + return c.size(); +} + +template +constexpr size_t size(const T (&)[N]) noexcept +{ + return N; +} + +template +constexpr auto empty(const C &c) -> decltype(c.empty()) +{ + return c.empty(); +} + +template +constexpr bool empty(T (&)[N]) noexcept +{ + return false; +} + +template +constexpr bool empty(initializer_list il) +{ + return il.size() == 0; +} + +template +constexpr auto data(C &c) -> decltype(c.data()) +{ + return c.data(); +} + +template +constexpr auto data(const C &c) -> decltype(c.data()) +{ + return c.data(); +} + +template +constexpr T *data(T (&array)[N]) noexcept +{ + return array; +} + +template +constexpr const E *data(initializer_list il) +{ + return il.begin(); +} +#endif + +// C++20 +template +constexpr auto ssize(const C &c) -> common_type_t> +{ + return static_cast>>(c.size()); +} + +template +constexpr ptrdiff_t ssize(const T (&)[N]) noexcept +{ + return N; +} + +} + + +#endif // MSTD_ITERATOR_ diff --git a/platform/tests/UNITTESTS/doubles/platform/cxxsupport/mstd_memory b/platform/tests/UNITTESTS/doubles/platform/cxxsupport/mstd_memory new file mode 100644 index 0000000..d44e5ed --- /dev/null +++ b/platform/tests/UNITTESTS/doubles/platform/cxxsupport/mstd_memory @@ -0,0 +1,138 @@ +/* mbed Microcontroller Library + * Copyright (c) 2019 ARM Limited + * SPDX-License-Identifier: Apache-2.0 + * + * 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. + */ +#ifndef MSTD_MEMORY_ +#define MSTD_MEMORY_ + +/* + * + * - includes toolchain's + * - For ARM C 5, C++11/14 features: + * - std::align + * - std::addressof + * - std::uninitialized_copy_n + * - std::unique_ptr, std::make_unique, std::default_delete + * - For all toolchains, C++17 backports: + * - mstd::uninitialized_default_construct, mstd::uninitialized_value_construct + * - mstd::uninitialized_move, mstd::uninitialized_move_n + * - mstd::destroy_at, mstd::destroy, mstd::destroy_n + */ + +#include + +#include +#include // std::pair +#include // std::iterator_traits + +namespace mstd { + using std::align; + using std::allocator; + using std::addressof; + + // [uninitialized.construct.default] (C++17) + template + void uninitialized_default_construct(ForwardIterator first, ForwardIterator last) { + for (; first != last; ++first) { + ::new (static_cast(addressof(*first))) + typename std::iterator_traits::value_type; + } + } + + template + ForwardIterator uninitialized_default_construct_n(ForwardIterator first, Size n) { + for (; n; ++first, --n) { + ::new (static_cast(addressof(*first))) + typename std::iterator_traits::value_type; + } + + return first; + } + + // [uninitialized.construct.value] (C++17) + template + void uninitialized_value_construct(ForwardIterator first, ForwardIterator last) { + for (; first != last; ++first) { + ::new (static_cast(addressof(*first))) + typename std::iterator_traits::value_type(); + } + } + + template + ForwardIterator uninitialized_value_construct_n(ForwardIterator first, Size n) { + for (; n; ++first, --n) { + ::new (static_cast(addressof(*first))) + typename std::iterator_traits::value_type(); + } + + return first; + } + + // [uninitialized.move] (C++17) + template + ForwardIterator uninitialized_move(InputIterator first, InputIterator last, ForwardIterator result) { + for (; first != last; ++result, (void) ++first) { + ::new (static_cast(addressof(*result))) + typename std::iterator_traits::value_type(move(*first)); + } + + return result; + } + + template + std::pair uninitialized_move_n(InputIterator first, Size n, ForwardIterator result) { + for ( ; n > 0; ++result, (void) ++first, --n) { + ::new (static_cast(addressof(*result))) + typename std::iterator_traits::value_type(std::move(*first)); + } + + return { first, result }; + } + + using std::uninitialized_copy; + using std::uninitialized_copy_n; + using std::uninitialized_fill; + using std::uninitialized_fill_n; + + // [specialized.destroy] (C++17) + template + void destroy_at(T *location) + { + location->~T(); + } + + template + void destroy(ForwardIterator first, ForwardIterator last) + { + for (; first != last; ++first) { + destroy_at(addressof(*first)); + } + } + + template + ForwardIterator destroy_n(ForwardIterator first, Size n) + { + for (; n > 0; (void)++first, --n) { + destroy_at(addressof(*first)); + } + return first; + } + + using std::default_delete; + using std::unique_ptr; + using std::make_unique; +} + +#endif // MSTD_MEMORY_ diff --git a/platform/tests/UNITTESTS/doubles/platform/cxxsupport/mstd_mutex b/platform/tests/UNITTESTS/doubles/platform/cxxsupport/mstd_mutex new file mode 100644 index 0000000..88c6f82 --- /dev/null +++ b/platform/tests/UNITTESTS/doubles/platform/cxxsupport/mstd_mutex @@ -0,0 +1,92 @@ +/* mbed Microcontroller Library + * Copyright (c) 2019 ARM Limited + * SPDX-License-Identifier: Apache-2.0 + * + * 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. + */ +#ifndef MSTD_MUTEX_ +#define MSTD_MUTEX_ + +#include + +namespace mstd { +using std::defer_lock; +using std::defer_lock_t; +using std::try_to_lock; +using std::try_to_lock_t; +using std::adopt_lock; +using std::adopt_lock_t; + +using std::lock_guard; +using std::unique_lock; + +using std::try_lock; +using std::lock; + +#if __cpp_lib_scoped_lock >= 201703 +using std::scoped_lock; +#else +// [thread.lock.scoped] +// 2+ locks - use std::lock +template +class scoped_lock +#if 0 // no definition yet - needs tuple + tuple pm; + static void ignore(...) { } +public: + explicit scoped_lock(MutexTypes &... m) : pm(tie(m...)) { mstd::lock(m...); } + explicit scoped_lock(adopt_lock_t, MutexTypes &... m) noexcept : pm(mstd::tie(m...)) { } + ~scoped_lock() { mstd::apply([](MutexTypes &... m) { ignore( (void(m.unlock()),0) ...); }, pm); } + + scoped_lock(const scoped_lock &) = delete; + scoped_lock &operator=(const scoped_lock &) = delete; +} +#else +; +#endif + +// 0 locks - no-op +template <> +class scoped_lock<> { +public: + explicit scoped_lock() = default; + explicit scoped_lock(adopt_lock_t) noexcept { } + ~scoped_lock() = default; + + scoped_lock(const scoped_lock &) = delete; + scoped_lock &operator=(const scoped_lock &) = delete; +}; + +// 1 lock - simple lock, equivalent to lock_guard +template +class scoped_lock { + Mutex ± +public: + using mutex_type = Mutex; + explicit scoped_lock(Mutex &m) : pm(m) { m.lock(); } + explicit scoped_lock(adopt_lock_t, Mutex &m) noexcept : pm(m) { } + ~scoped_lock() { pm.unlock(); } + + scoped_lock(const scoped_lock &) = delete; + scoped_lock &operator=(const scoped_lock &) = delete; +}; +#endif + +using std::once_flag; +using std::call_once; + +using std::mutex; +using std::recursive_mutex; +} + +#endif // MSTD_MUTEX_ diff --git a/platform/tests/UNITTESTS/doubles/platform/cxxsupport/mstd_new b/platform/tests/UNITTESTS/doubles/platform/cxxsupport/mstd_new new file mode 100644 index 0000000..b7e8154 --- /dev/null +++ b/platform/tests/UNITTESTS/doubles/platform/cxxsupport/mstd_new @@ -0,0 +1,56 @@ +/* mbed Microcontroller Library + * Copyright (c) 2019 ARM Limited + * SPDX-License-Identifier: Apache-2.0 + * + * 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. + */ +#ifndef MSTD_NEW_ +#define MSTD_NEW_ + +/* + * + * - includes toolchain's + * - For all toolchains, C++17 backports: + * - mstd::launder + */ + +#include +#if __cpp_lib_launder < 201606 +#include +#endif + +namespace mstd +{ +using std::nothrow_t; +using std::nothrow; +using std::new_handler; +using std::set_new_handler; + +#if __cpp_lib_launder >= 201606 +using std::launder; +#else +template +constexpr T *launder(T *p) noexcept +{ + static_assert(!std::is_function::value && !std::is_void::value, "Can only launder complete object types"); +#if defined __clang__ || __GNUC__ >= 9 + return __builtin_launder(p); +#else + return p; +#endif +} +#endif + +} // namespace mstd + +#endif // MSTD_NEW_ diff --git a/platform/tests/UNITTESTS/doubles/platform/cxxsupport/mstd_tuple b/platform/tests/UNITTESTS/doubles/platform/cxxsupport/mstd_tuple new file mode 100644 index 0000000..d9e926a --- /dev/null +++ b/platform/tests/UNITTESTS/doubles/platform/cxxsupport/mstd_tuple @@ -0,0 +1,93 @@ +/* mbed Microcontroller Library + * Copyright (c) 2019 ARM Limited + * SPDX-License-Identifier: Apache-2.0 + * + * 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 LEOR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef MSTD_TUPLE_ +#define MSTD_TUPLE_ + +/* + * + * - includes toolchain's + * - For all toolchains, C++17 backports: + * - mstd::apply + * - mstd::make_from_tuple + */ + +#include + +#if __cpp_lib_apply < 201603 || __cpp_lib_make_from_tuple < 201606 +#include // integer_sequence +#endif +#if __cpp_lib_apply < 201603 +#include // invoke +#endif + +namespace mstd { +using std::tuple; +using std::ignore; +using std::make_tuple; +using std::forward_as_tuple; +using std::tie; +using std::tuple_cat; +using std::tuple_size; +using std::tuple_element; +using std::tuple_element_t; +using std::get; + +// [tuple.apply] +#if __cpp_lib_apply >= 201603 +using std::apply; +#else +namespace impl { +template +invoke_result_t...> apply(F&& f, Tuple&& t, std::index_sequence) +{ + return mstd::invoke(std::forward(f), std::get(std::forward(t))...); +} +} + +// apply - works also for tuple-like objects such as array or pair +// user-defined types can specialize std::get and std::tuple_size to make this work +template +auto apply(F&& f, Tuple&& t) -> +decltype(impl::apply(std::forward(f), std::forward(t), std::make_index_sequence>::value>{})) +{ + return impl::apply(std::forward(f), std::forward(t), + std::make_index_sequence>::value>{}); +} +#endif + +#if __cpp_lib_make_from_tuple >= 201606 +using std::make_from_tuple; +#else +namespace impl { +template +T make_from_tuple(Tuple&& t, std::index_sequence) +{ + return T(std::get(std::forward(t))...); +} +} + +template +T make_from_tuple(Tuple&& t) +{ + return impl::make_from_tuple(std::forward(t), + std::make_index_sequence>::value>{}); +} +#endif + +} // namespace mstd + +#endif // MSTD_TUPLE_ diff --git a/platform/tests/UNITTESTS/doubles/platform/cxxsupport/mstd_type_traits b/platform/tests/UNITTESTS/doubles/platform/cxxsupport/mstd_type_traits new file mode 100644 index 0000000..0513ba9 --- /dev/null +++ b/platform/tests/UNITTESTS/doubles/platform/cxxsupport/mstd_type_traits @@ -0,0 +1,475 @@ +/* mbed Microcontroller Library + * Copyright (c) 2019 ARM Limited + * SPDX-License-Identifier: Apache-2.0 + * + * 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. + */ +#ifndef MSTD_TYPE_TRAITS_ +#define MSTD_TYPE_TRAITS_ + +/* + * + * - includes toolchain's + * - For all toolchains, C++17/20 backports: + * - mstd::type_identity + * - mstd::bool_constant + * - mstd::void_t + * - mstd::is_invocable, mbed::is_invocable_r, etc + * - mstd::invoke_result + * - logical operator traits (mstd::conjunction, mstd::disjunction, mstd::negation) + * - mstd::is_constant_evaluated + */ + +#include +#include + +// The template stuff in here is too confusing for astyle +// *INDENT-OFF* + +namespace mstd { + +/* C++20 type identity */ +template +struct type_identity { + using type = T; +}; + +template +using type_identity_t = typename type_identity::type; + +/* C++17 void_t (foundation for detection idiom) */ +/* void_t is void if args are valid, else a substitution failure */ +#if __cpp_lib_void_t >= 201411 +using std::void_t; +#else +template +using void_t = void; +#endif + +/* C++17 bool_constant */ +#if __cpp_lib_bool_constant >= 201505 +using std::bool_constant; +#else +template +using bool_constant = std::integral_constant; +#endif + +/* Forward declarations */ +#if __cpp_lib_is_invocable >= 201703 +using std::invoke_result; +#else +template +struct invoke_result; +#endif + +} // namespace mstd + +namespace mstd { + +using std::is_same; +using std::conditional; +using std::conditional_t; +using std::enable_if; +using std::enable_if_t; +using std::is_convertible; +using std::is_object; +using std::is_reference; + +/* Reinvent or pull in good stuff not in C++14 into namespace mstd */ +/* C++17 logical operations on traits */ +#if __cpp_lib_logical_traits >= 201510 +using std::conjunction; +using std::disjunction; +using std::negation; +#else +template +struct conjunction : std::true_type { }; +template +struct conjunction : B1 { }; +template +struct conjunction : std::conditional_t, B1> { }; + +template +struct disjunction : std::false_type { }; +template +struct disjunction : B1 { }; +template +struct disjunction : std::conditional_t> { }; + +template +struct negation : bool_constant { }; +#endif + +/* C++ detection idiom from Library fundamentals v2 TS */ +/* Place into mstd::experimental to match their std::experimental */ +namespace experimental { + +namespace impl { +template class Op, class... Args> +struct detector { + using value_t = std::false_type; + using type = Default; +}; + +template class Op, class... Args> +struct detector>, Op, Args...> { + using value_t = std::true_type; + using type = Op; +}; + +} // namespace impl + +struct nonesuch { + ~nonesuch() = delete; + nonesuch(nonesuch const &) = delete; + void operator=(nonesuch const &) = delete; +}; + +#if 0 +/* Deactivated because impl::detector appears to not work on ARM C 5; it seems to produce + * hard errors in the template template parameter expansion. You can use void_t directly instead. + * + * Reactivate if working ARM C 5 implementation discovered, or ARM C 5 support + * dropped. + */ + +template class Op, class... Args> +using is_detected = typename impl::detector::value_t; + +template class Op, class... Args> +using detected_t = typename impl::detector::type; + +template class Op, class... Args> +using detected_or = typename impl::detector; + +template class Op, class... Args> +using detected_or_t = typename detected_or::type; + +template class Op, class... Args> +using is_detected_exact = std::is_same>; + +template class Op, class... Args> +using is_detected_convertible = std::is_convertible, To>; +#endif // if 0 - deactivated detector idiom +} // namespace experimental +} // namespace mstd + +/* More post-C++14 stuff */ +namespace mstd { + +using std::remove_const; +using std::remove_const_t; +using std::remove_volatile; +using std::remove_volatile_t; +using std::remove_cv; +using std::remove_cv_t; +using std::add_const; +using std::add_const_t; +using std::add_volatile; +using std::add_volatile_t; +using std::add_cv; +using std::add_cv_t; +using std::remove_reference; +using std::remove_reference_t; +using std::add_lvalue_reference; +using std::add_rvalue_reference; +using std::is_void; +using std::is_null_pointer; +using std::is_integral; +using std::is_floating_point; +using std::is_array; +using std::is_pointer; +using std::is_lvalue_reference; +using std::is_rvalue_reference; +using std::is_enum; +using std::is_union; +using std::is_class; +using std::is_function; +using std::is_member_function_pointer; +using std::is_member_object_pointer; +using std::is_reference; +using std::is_arithmetic; +using std::is_fundamental; +using std::is_compound; +using std::is_member_pointer; +using std::is_scalar; +using std::is_object; +using std::is_const; +using std::is_volatile; +using std::is_trivial; +using std::is_trivially_copyable; +using std::is_standard_layout; +using std::is_pod; +using std::is_literal_type; +using std::is_empty; +using std::is_polymorphic; +using std::is_abstract; +using std::is_signed; +using std::is_unsigned; +using std::is_constructible; +using std::is_default_constructible; +using std::is_copy_constructible; +using std::is_move_constructible; +using std::is_assignable; +using std::is_copy_assignable; +using std::is_move_assignable; +using std::is_destructible; +using std::is_trivially_constructible; +using std::is_trivially_default_constructible; +using std::is_trivially_copy_constructible; +using std::is_trivially_move_constructible; +using std::is_trivially_assignable; +using std::is_trivially_copy_assignable; +using std::is_trivially_move_assignable; +using std::is_trivially_destructible; +// Exceptions are disabled in mbed, so short-circuit nothrow tests +// (Compilers don't make noexcept() return false with exceptions +// disabled, presumably to preserve binary compatibility, so the +// std versions of these are unduly pessimistic). +template +struct is_nothrow_constructible : is_constructible { }; +template +struct is_nothrow_default_constructible : is_default_constructible { }; +template +struct is_nothrow_copy_constructible : is_copy_constructible { }; +template +struct is_nothrow_move_constructible : is_move_constructible { }; +template +struct is_nothrow_assignable: is_assignable { }; +template +struct is_nothrow_copy_assignable : is_copy_assignable { }; +template +struct is_nothrow_move_assignable : is_move_assignable { }; +using std::has_virtual_destructor; +using std::alignment_of; +using std::rank; +using std::extent; +using std::is_convertible; +using std::is_base_of; +using std::make_signed; +using std::make_signed_t; +using std::make_unsigned; +using std::make_unsigned_t; +using std::remove_extent; +using std::remove_extent_t; +using std::remove_all_extents; +using std::remove_all_extents_t; +using std::remove_pointer; +using std::remove_pointer_t; +using std::add_pointer; +using std::add_pointer_t; +using std::aligned_storage; +using std::aligned_storage_t; +using std::decay; +using std::decay_t; +using std::common_type; +using std::common_type_t; +using std::result_of; +using std::result_of_t; + +/* C++20 remove_cvref */ +template +struct remove_cvref : type_identity>> { }; + +template +using remove_cvref_t = typename remove_cvref::type; + +} + +#if __cpp_lib_invoke < 201411 +#include // want std::forward +#include // want std::reference_wrapper +#elif __cpp_lib_is_invocable < 201703 +#include // want std::invoke +#endif + +namespace mstd { +/* C++17 invoke_result, is_invocable, invoke */ +#if __cpp_lib_is_invocable >= 201703 +/* Library has complete suite - pull it into mstd */ +using std::invoke_result; +using std::invoke_result_t; +using std::is_invocable; +using std::is_nothrow_invocable; +using std::is_invocable_r; +using std::is_nothrow_invocable_r; +#else // __cpp_lib_is_invocable +namespace impl { +#if __cpp_lib_invoke >= 201411 +/* Library has just invoke - make it our impl::INVOKE so we can create invoke_result */ +template +using INVOKE = std::invoke; +#else // __cpp_lib_invoke +/* Define our own INVOKE */ +template +struct is_reference_wrapper : std::false_type { }; + +template +struct is_reference_wrapper> : std::true_type { }; + +/* F is pointer to member function, and 1st arg decays to matching class */ +template +auto INVOKE(F Base::* fn, T1 &&target, Args &&...args) +// Noexcept specifications generate compiler errors unpacking args +//noexcept(noexcept((std::forward(target).*fn)(std::forward(args)...))) + -> std::enable_if_t::value && + std::is_base_of>::value, + decltype((std::forward(target).*fn)(std::forward(args)...))> +{ + return (std::forward(target).*fn)(std::forward(args)...); +} +/* F is pointer to member function, and 1st arg is a reference wrapper */ +template +auto INVOKE(F Base::* fn, T1 &&target, Args &&...args) +//noexcept(noexcept((std::forward(target).get().*fn)(std::forward(args)...))) + -> std::enable_if_t::value && + is_reference_wrapper>::value, + decltype((std::forward(target).get().*fn)(std::forward(args)...))> +{ + return (std::forward(target).get().*fn)(std::forward(args)...); +} +/* F is pointer to member function, and 1st arg doesn't match class and isn't reference wrapper - assume pointer */ +template +auto INVOKE(F Base::* fn, T1 &&target, Args &&...args) +//noexcept(noexcept(((*std::forward(target)).*fn)(std::forward(args)...))) + -> std::enable_if_t::value && + !std::is_base_of>::value && + !is_reference_wrapper>::value, + decltype(((*std::forward(target)).*fn)(std::forward(args)...))> +{ + return ((*std::forward(target)).*fn)(std::forward(args)...); +} +/* F is pointer to member object, and only arg decays to matching class */ +template +auto INVOKE(F Base::* obj, T1 &&target) +//noexcept(noexcept(std::forward(target).*obj)) + -> std::enable_if_t::value && + std::is_base_of>::value, + decltype(std::forward(target).*obj)> +{ + return std::forward(target).*obj; +} +/* F is pointer to member object, and only arg is a reference wrapper */ +template +auto INVOKE(F Base::* obj, T1 &&target) +//noexcept(noexcept(std::forward(target).get().*obj)) + -> std::enable_if_t::value && + is_reference_wrapper>::value, + decltype(std::forward(target).get().*obj)> +{ + return std::forward(target).get().*obj; +} +/* F is pointer to member object, and only arg doesn't match class and isn't reference wrapper - assume pointer */ +template +auto INVOKE(F Base::* obj, T1 &&target) +//noexcept(noexcept((*std::forward(target)).*obj)) + -> std::enable_if_t::value && + !std::is_base_of>::value && + !is_reference_wrapper>::value, + decltype((*std::forward(target)).*obj)> +{ + return (*std::forward(target)).*obj; +} +/* F is not a pointer to member */ +template +auto INVOKE(F&& f, Args&&... args) +//noexcept(noexcept(std::forward(f)(std::forward(args)...))) + -> std::enable_if_t>::value || + (std::is_member_object_pointer>::value && sizeof...(args) != 1), + decltype(std::forward(f)(std::forward(args)...))> +{ + return std::forward(f)(std::forward(args)...); +} +#endif // __cpp_lib_invoke + +template +struct invoke_result { }; +template // void_t appears not to work here - why? +struct invoke_result(), std::declval()...))), F, Args...> : + type_identity(), std::declval()...))> { }; + +// This would be a lot shorter if we could get the detector idiom to work and use it +template +struct is_invocable_r : std::false_type { }; +template +struct is_invocable_r > : + disjunction, std::is_convertible> { }; + +template +struct is_nothrow_invocable_r : std::false_type { }; +template +struct is_nothrow_invocable_r> : + disjunction, + conjunction, + std::is_nothrow_constructible>> { }; + +} //namespace impl + +template +struct invoke_result : impl::invoke_result { }; + +template +using invoke_result_t = typename invoke_result::type; + +template +struct is_invocable : impl::is_invocable_r> { }; + +#if 0 // No exceptions in mbed OS +template +struct is_nothrow_invocable : impl::is_nothrow_invocable_r> { }; +#else +template +struct is_nothrow_invocable : impl::is_invocable_r> { }; +#endif + +template +struct is_invocable_r : impl::is_invocable_r> { }; + +#if 0 // No exceptions in mbed OS +template +struct is_nothrow_invocable_r : conjunction>, + std::is_convertible, R>> { }; +#else +template +struct is_nothrow_invocable_r : impl::is_invocable_r> { }; +#endif + +#endif // __cpp_lib_is_invocable + +/* C++20 is_constant_evaluated */ +constexpr bool is_constant_evaluated() noexcept +{ +#ifdef __clang__ +#if __has_builtin(__builtin_is_constant_evaluated) +#define MSTD_HAS_IS_CONSTANT_EVALUATED 1 + return __builtin_is_constant_evaluated(); +#else + return false; +#endif +#elif __GNUC__ >= 9 +#define MSTD_HAS_IS_CONSTANT_EVALUATED 1 + return __builtin_is_constant_evaluated(); +#else + return false; +#endif +} + +#if MSTD_HAS_IS_CONSTANT_EVALUATED +#define MSTD_CONSTEXPR_IF_HAS_IS_CONSTANT_EVALUATED constexpr +#else +#define MSTD_CONSTEXPR_IF_HAS_IS_CONSTANT_EVALUATED +#endif + +} // namespace mstd + +#endif /* MSTD_TYPE_TRAITS_ */ diff --git a/platform/tests/UNITTESTS/doubles/platform/cxxsupport/mstd_utility b/platform/tests/UNITTESTS/doubles/platform/cxxsupport/mstd_utility new file mode 100644 index 0000000..c05950e --- /dev/null +++ b/platform/tests/UNITTESTS/doubles/platform/cxxsupport/mstd_utility @@ -0,0 +1,75 @@ +/* mbed Microcontroller Library + * Copyright (c) 2019 ARM Limited + * SPDX-License-Identifier: Apache-2.0 + * + * 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. + */ +#ifndef MSTD_UTILITY_ +#define MSTD_UTILITY_ + +/* + * + * - includes toolchain's + * - For ARM C 5, standard C++11/14 features: + * - include + * - std::move, std::forward, std::exchange + * - std::declval + * - std::integer_sequence + * - include to get default std::swap + * - mstd::swap - substitute for std::swap that can move + * - std::swap(array) + * - Swap assistance, to ensure moves happen on ARM C 5 + * - mstd::swap - alias for std::swap, or a local moving implementation for ARM C 5 + * - For all toolchains, C++17/20 backports: + * - mstd::as_const + */ + +#include + +namespace mstd { +using std::swap; + +namespace rel_ops { using namespace std::rel_ops; } +using std::initializer_list; +using std::exchange; +using std::forward; +using std::move; +// No exceptions in mbed OS +template +T &&move_if_noexcept(T &t) noexcept +{ + return mstd::move(t); +} +using std::declval; +using std::make_pair; +using std::get; +using std::pair; +using std::integer_sequence; + +// C++17 [utility.as_const] */ +#if __cpp_lib_as_const >= 201510 +using std::as_const; +#else +template +constexpr std::add_const_t<_TypeT> &as_const(_TypeT &__t) noexcept +{ + return __t; +} + +template +void as_const(_TypeT &&) = delete; +#endif + +} // namespace mstd + +#endif // MSTD_UTILITY_ diff --git a/platform/tests/UNITTESTS/doubles/platform/mbed_assert.h b/platform/tests/UNITTESTS/doubles/platform/mbed_assert.h new file mode 100644 index 0000000..1603c2e --- /dev/null +++ b/platform/tests/UNITTESTS/doubles/platform/mbed_assert.h @@ -0,0 +1,137 @@ + +/** \addtogroup platform */ +/** @{*/ +/** + * \defgroup platform_Assert Assert macros + * @{ + */ +/* + * Copyright (c) 2018--2019 Arm Limited and affiliates. + * SPDX-License-Identifier: Apache-2.0 + * + * 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. + */ +#ifndef MBED_ASSERT_H +#define MBED_ASSERT_H + +#include "mbed_preprocessor.h" +#include "mbed_toolchain.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** Internal mbed assert function which is invoked when MBED_ASSERT macro fails. + * This function is active only if NDEBUG is not defined prior to including this + * assert header file. + * In case of MBED_ASSERT failing condition, error() is called with the assertation message. + * @param expr Expression to be checked. + * @param file File where assertation failed. + * @param line Failing assertation line number. + */ +// mbed_assert_internal UT stub only prints an assert trace and returns, so therefore +// MBED_NORETURN must not be defined for UTs. +MBED_NORETURN +void mbed_assert_internal(const char *expr, const char *file, int line); + +#ifdef __cplusplus +} +#endif + +/** + * For unittests: Global flag to select whether MBED_ASSERT + * throws error. Default false. + */ +extern bool mbed_assert_throw_errors; + +/** MBED_ASSERT + * Declare runtime assertions: results in runtime error if condition is false + * + * @note + * Use of MBED_ASSERT is limited to Debug and Develop builds. + * + * @code + * + * int Configure(serial_t *obj) { + * MBED_ASSERT(obj); + * } + * @endcode + */ +#define MBED_ASSERT(expr) \ +do { \ + if (!(expr)) { \ + mbed_assert_internal(#expr, __FILE__, __LINE__); \ + } \ +} while (0) + +/** MBED_STATIC_ASSERT + * Declare compile-time assertions, results in compile-time error if condition is false + * + * The assertion acts as a declaration that can be placed at file scope, in a + * code block (except after a label), or as a member of a C++ class/struct/union. + * + * @note + * Use of MBED_STATIC_ASSERT as a member of a struct/union is limited: + * - In C++, MBED_STATIC_ASSERT is valid in class/struct/union scope. + * - In C, MBED_STATIC_ASSERT is not valid in struct/union scope, and + * MBED_STRUCT_STATIC_ASSERT is provided as an alternative that is valid + * in C and C++ class/struct/union scope. + * + * @code + * MBED_STATIC_ASSERT(MBED_LIBRARY_VERSION >= 120, + * "The mbed library must be at least version 120"); + * + * int main() { + * MBED_STATIC_ASSERT(sizeof(int) >= sizeof(char), + * "An int must be larger than a char"); + * } + * @endcode + */ +#if defined(__cplusplus) && (__cplusplus >= 201103L || __cpp_static_assert >= 200410L) +#define MBED_STATIC_ASSERT(expr, msg) static_assert(expr, msg) +#elif !defined(__cplusplus) && __STDC_VERSION__ >= 201112L +#define MBED_STATIC_ASSERT(expr, msg) _Static_assert(expr, msg) +#elif defined(__cplusplus) && defined(__GNUC__) && defined(__GXX_EXPERIMENTAL_CXX0X__) \ + && (__GNUC__*100 + __GNUC_MINOR__) > 403L +#define MBED_STATIC_ASSERT(expr, msg) __extension__ static_assert(expr, msg) +#elif !defined(__cplusplus) && defined(__GNUC__) \ + && (__GNUC__*100 + __GNUC_MINOR__) > 406L +#define MBED_STATIC_ASSERT(expr, msg) __extension__ _Static_assert(expr, msg) +#elif defined(__ICCARM__) +#define MBED_STATIC_ASSERT(expr, msg) static_assert(expr, msg) +#else +#define MBED_STATIC_ASSERT(expr, msg) \ + enum {MBED_CONCAT(MBED_ASSERTION_AT_, __LINE__) = sizeof(char[(expr) ? 1 : -1])} +#endif + +/** MBED_STRUCT_STATIC_ASSERT + * Declare compile-time assertions, results in compile-time error if condition is false + * + * Unlike MBED_STATIC_ASSERT, MBED_STRUCT_STATIC_ASSERT can and must be used + * as a member of a C/C++ class/struct/union. + * + * @code + * struct thing { + * MBED_STATIC_ASSERT(2 + 2 == 4, + * "Hopefully the universe is mathematically consistent"); + * }; + * @endcode + */ +#define MBED_STRUCT_STATIC_ASSERT(expr, msg) int : (expr) ? 0 : -1 + + +#endif + +/**@}*/ + +/**@}*/ diff --git a/platform/tests/UNITTESTS/doubles/platform/mbed_power_mgmt.h b/platform/tests/UNITTESTS/doubles/platform/mbed_power_mgmt.h new file mode 100644 index 0000000..a8e83f7 --- /dev/null +++ b/platform/tests/UNITTESTS/doubles/platform/mbed_power_mgmt.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) , Arm Limited and affiliates. + * SPDX-License-Identifier: Apache-2.0 + * + * 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. + */ + +/** Resets the processor and most of the sub-system + * + * @note Does not affect the debug sub-system + */ +#ifndef MBED_POWER_MGMT_H +#define MBED_POWER_MGMT_H + +extern void mock_system_reset(); + +static inline void system_reset(void) +{ + mock_system_reset(); +} + +void sleep_manager_unlock_deep_sleep(void); + +void sleep_manager_lock_deep_sleep(void); + +#endif + diff --git a/platform/tests/UNITTESTS/doubles/platform/mbed_retarget.h b/platform/tests/UNITTESTS/doubles/platform/mbed_retarget.h new file mode 100644 index 0000000..e99d421 --- /dev/null +++ b/platform/tests/UNITTESTS/doubles/platform/mbed_retarget.h @@ -0,0 +1,433 @@ +/* + * Copyright (c) 2017, Arm Limited and affiliates. + * SPDX-License-Identifier: Apache-2.0 + * + * 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. + */ + +#ifndef RETARGET_H +#define RETARGET_H + +#include +#include +#include + +#include + +#if defined __has_include +# if __has_include () +# include +# define HAVE_SYS_STAT_H +# endif +#endif + + +namespace mbed { + +#define NAME_MAX 255 + +#undef EPERM +#define EPERM 1 /* Operation not permitted */ +#undef ENOENT +#define ENOENT 2 /* No such file or directory */ +#undef ESRCH +#define ESRCH 3 /* No such process */ +#undef EINTR +#define EINTR 4 /* Interrupted system call */ +#undef EIO +#define EIO 5 /* I/O error */ +#undef ENXIO +#define ENXIO 6 /* No such device or address */ +#undef E2BIG +#define E2BIG 7 /* Argument list too long */ +#undef ENOEXEC +#define ENOEXEC 8 /* Exec format error */ +#undef EBADF +#define EBADF 9 /* Bad file number */ +#undef ECHILD +#define ECHILD 10 /* No child processes */ +#undef EAGAIN +#define EAGAIN 11 /* Try again */ +#undef ENOMEM +#define ENOMEM 12 /* Out of memory */ +#undef EACCES +#define EACCES 13 /* Permission denied */ +#undef EFAULT +#define EFAULT 14 /* Bad address */ +#undef ENOTBLK +#define ENOTBLK 15 /* Block device required */ +#undef EBUSY +#define EBUSY 16 /* Device or resource busy */ +#undef EEXIST +#define EEXIST 17 /* File exists */ +#undef EXDEV +#define EXDEV 18 /* Cross-device link */ +#undef ENODEV +#define ENODEV 19 /* No such device */ +#undef ENOTDIR +#define ENOTDIR 20 /* Not a directory */ +#undef EISDIR +#define EISDIR 21 /* Is a directory */ +#undef EINVAL +#define EINVAL 22 /* Invalid argument */ +#undef ENFILE +#define ENFILE 23 /* File table overflow */ +#undef EMFILE +#define EMFILE 24 /* Too many open files */ +#undef ENOTTY +#define ENOTTY 25 /* Not a typewriter */ +#undef ETXTBSY +#define ETXTBSY 26 /* Text file busy */ +#undef EFBIG +#define EFBIG 27 /* File too large */ +#undef ENOSPC +#define ENOSPC 28 /* No space left on device */ +#undef ESPIPE +#define ESPIPE 29 /* Illegal seek */ +#undef EROFS +#define EROFS 30 /* Read-only file system */ +#undef EMLINK +#define EMLINK 31 /* Too many links */ +#undef EPIPE +#define EPIPE 32 /* Broken pipe */ +#undef EDOM +#define EDOM 33 /* Math argument out of domain of func */ +#undef ERANGE +#define ERANGE 34 /* Math result not representable */ +#undef EDEADLK +#define EDEADLK 35 /* Resource deadlock would occur */ +#undef ENAMETOOLONG +#define ENAMETOOLONG 36 /* File name too long */ +#undef ENOLCK +#define ENOLCK 37 /* No record locks available */ +#undef ENOSYS +#define ENOSYS 38 /* Function not implemented */ +#undef ENOTEMPTY +#define ENOTEMPTY 39 /* Directory not empty */ +#undef ELOOP +#define ELOOP 40 /* Too many symbolic links encountered */ +#undef EWOULDBLOCK +#define EWOULDBLOCK EAGAIN /* Operation would block */ +#undef ENOMSG +#define ENOMSG 42 /* No message of desired type */ +#undef EIDRM +#define EIDRM 43 /* Identifier removed */ +#undef ECHRNG +#define ECHRNG 44 /* Channel number out of range */ +#undef EL2NSYNC +#define EL2NSYNC 45 /* Level 2 not synchronized */ +#undef EL3HLT +#define EL3HLT 46 /* Level 3 halted */ +#undef EL3RST +#define EL3RST 47 /* Level 3 reset */ +#undef ELNRNG +#define ELNRNG 48 /* Link number out of range */ +#undef EUNATCH +#define EUNATCH 49 /* Protocol driver not attached */ +#undef ENOCSI +#define ENOCSI 50 /* No CSI structure available */ +#undef EL2HLT +#define EL2HLT 51 /* Level 2 halted */ +#undef EBADE +#define EBADE 52 /* Invalid exchange */ +#undef EBADR +#define EBADR 53 /* Invalid request descriptor */ +#undef EXFULL +#define EXFULL 54 /* Exchange full */ +#undef ENOANO +#define ENOANO 55 /* No anode */ +#undef EBADRQC +#define EBADRQC 56 /* Invalid request code */ +#undef EBADSLT +#define EBADSLT 57 /* Invalid slot */ +#undef EDEADLOCK +#define EDEADLOCK EDEADLK /* Resource deadlock would occur */ +#undef EBFONT +#define EBFONT 59 /* Bad font file format */ +#undef ENOSTR +#define ENOSTR 60 /* Device not a stream */ +#undef ENODATA +#define ENODATA 61 /* No data available */ +#undef ETIME +#define ETIME 62 /* Timer expired */ +#undef ENOSR +#define ENOSR 63 /* Out of streams resources */ +#undef ENONET +#define ENONET 64 /* Machine is not on the network */ +#undef ENOPKG +#define ENOPKG 65 /* Package not installed */ +#undef EREMOTE +#define EREMOTE 66 /* Object is remote */ +#undef ENOLINK +#define ENOLINK 67 /* Link has been severed */ +#undef EADV +#define EADV 68 /* Advertise error */ +#undef ESRMNT +#define ESRMNT 69 /* Srmount error */ +#undef ECOMM +#define ECOMM 70 /* Communication error on send */ +#undef EPROTO +#define EPROTO 71 /* Protocol error */ +#undef EMULTIHOP +#define EMULTIHOP 72 /* Multihop attempted */ +#undef EDOTDOT +#define EDOTDOT 73 /* RFS specific error */ +#undef EBADMSG +#define EBADMSG 74 /* Not a data message */ +#undef EOVERFLOW +#define EOVERFLOW 75 /* Value too large for defined data type */ +#undef ENOTUNIQ +#define ENOTUNIQ 76 /* Name not unique on network */ +#undef EBADFD +#define EBADFD 77 /* File descriptor in bad state */ +#undef EREMCHG +#define EREMCHG 78 /* Remote address changed */ +#undef ELIBACC +#define ELIBACC 79 /* Can not access a needed shared library */ +#undef ELIBBAD +#define ELIBBAD 80 /* Accessing a corrupted shared library */ +#undef ELIBSCN +#define ELIBSCN 81 /* .lib section in a.out corrupted */ +#undef ELIBMAX +#define ELIBMAX 82 /* Attempting to link in too many shared libraries */ +#undef ELIBEXEC +#define ELIBEXEC 83 /* Cannot exec a shared library directly */ +#undef EILSEQ +#define EILSEQ 84 /* Illegal byte sequence */ +#undef ERESTART +#define ERESTART 85 /* Interrupted system call should be restarted */ +#undef ESTRPIPE +#define ESTRPIPE 86 /* Streams pipe error */ +#undef EUSERS +#define EUSERS 87 /* Too many users */ +#undef ENOTSOCK +#define ENOTSOCK 88 /* Socket operation on non-socket */ +#undef EDESTADDRREQ +#define EDESTADDRREQ 89 /* Destination address required */ +#undef EMSGSIZE +#define EMSGSIZE 90 /* Message too long */ +#undef EPROTOTYPE +#define EPROTOTYPE 91 /* Protocol wrong type for socket */ +#undef ENOPROTOOPT +#define ENOPROTOOPT 92 /* Protocol not available */ +#undef EPROTONOSUPPORT +#define EPROTONOSUPPORT 93 /* Protocol not supported */ +#undef ESOCKTNOSUPPORT +#define ESOCKTNOSUPPORT 94 /* Socket type not supported */ +#undef EOPNOTSUPP +#define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */ +#undef EPFNOSUPPORT +#define EPFNOSUPPORT 96 /* Protocol family not supported */ +#undef EAFNOSUPPORT +#define EAFNOSUPPORT 97 /* Address family not supported by protocol */ +#undef EADDRINUSE +#define EADDRINUSE 98 /* Address already in use */ +#undef EADDRNOTAVAIL +#define EADDRNOTAVAIL 99 /* Cannot assign requested address */ +#undef ENETDOWN +#define ENETDOWN 100 /* Network is down */ +#undef ENETUNREACH +#define ENETUNREACH 101 /* Network is unreachable */ +#undef ENETRESET +#define ENETRESET 102 /* Network dropped connection because of reset */ +#undef ECONNABORTED +#define ECONNABORTED 103 /* Software caused connection abort */ +#undef ECONNRESET +#define ECONNRESET 104 /* Connection reset by peer */ +#undef ENOBUFS +#define ENOBUFS 105 /* No buffer space available */ +#undef EISCONN +#define EISCONN 106 /* Transport endpoint is already connected */ +#undef ENOTCONN +#define ENOTCONN 107 /* Transport endpoint is not connected */ +#undef ESHUTDOWN +#define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */ +#undef ETOOMANYREFS +#define ETOOMANYREFS 109 /* Too many references: cannot splice */ +#undef ETIMEDOUT +#define ETIMEDOUT 110 /* Connection timed out */ +#undef ECONNREFUSED +#define ECONNREFUSED 111 /* Connection refused */ +#undef EHOSTDOWN +#define EHOSTDOWN 112 /* Host is down */ +#undef EHOSTUNREACH +#define EHOSTUNREACH 113 /* No route to host */ +#undef EALREADY +#define EALREADY 114 /* Operation already in progress */ +#undef EINPROGRESS +#define EINPROGRESS 115 /* Operation now in progress */ +#undef ESTALE +#define ESTALE 116 /* Stale NFS file handle */ +#undef EUCLEAN +#define EUCLEAN 117 /* Structure needs cleaning */ +#undef ENOTNAM +#define ENOTNAM 118 /* Not a XENIX named type file */ +#undef ENAVAIL +#define ENAVAIL 119 /* No XENIX semaphores available */ +#undef EISNAM +#define EISNAM 120 /* Is a named type file */ +#undef EREMOTEIO +#define EREMOTEIO 121 /* Remote I/O error */ +#undef EDQUOT +#define EDQUOT 122 /* Quota exceeded */ +#undef ENOMEDIUM +#define ENOMEDIUM 123 /* No medium found */ +#undef EMEDIUMTYPE +#define EMEDIUMTYPE 124 /* Wrong medium type */ +#undef ECANCELED +#define ECANCELED 125 /* Operation Canceled */ +#undef ENOKEY +#define ENOKEY 126 /* Required key not available */ +#undef EKEYEXPIRED +#define EKEYEXPIRED 127 /* Key has expired */ +#undef EKEYREVOKED +#define EKEYREVOKED 128 /* Key has been revoked */ +#undef EKEYREJECTED +#define EKEYREJECTED 129 /* Key was rejected by service */ +#undef EOWNERDEAD +#define EOWNERDEAD 130 /* Owner died */ +#undef ENOTRECOVERABLE +#define ENOTRECOVERABLE 131 /* State not recoverable */ + +#define _IFMT 0170000 //< type of file +#define _IFSOCK 0140000 //< socket +#define _IFLNK 0120000 //< symbolic link +#define _IFREG 0100000 //< regular +#define _IFBLK 0060000 //< block special +#define _IFDIR 0040000 //< directory +#define _IFCHR 0020000 //< character special +#define _IFIFO 0010000 //< fifo special + +#ifndef S_IFMT +#define S_IFMT _IFMT //< type of file +#endif +#ifndef S_IFSOCK +#define S_IFSOCK _IFSOCK //< socket +#endif +#ifndef S_IFLNK +#define S_IFLNK _IFLNK //< symbolic link +#endif +#ifndef S_IFREG +#define S_IFREG _IFREG //< regular +#endif +#ifndef S_IFBLK +#define S_IFBLK _IFBLK //< block special +#endif +#ifndef S_IFDIR +#define S_IFDIR _IFDIR //< directory +#endif +#ifndef S_IFCHR +#define S_IFCHR _IFCHR //< character special +#endif +#ifndef S_IFIFO +#define S_IFIFO _IFIFO //< fifo special +#endif + +#ifndef S_IRWXU +#define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR) +#define S_IRUSR 0000400 ///< read permission, owner +#define S_IWUSR 0000200 ///< write permission, owner +#define S_IXUSR 0000100 ///< execute/search permission, owner +#endif /* S_IRWXU */ +#ifndef S_IRWXG +#define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP) +#define S_IRGRP 0000040 ///< read permission, group +#define S_IWGRP 0000020 ///< write permission, group +#define S_IXGRP 0000010 ///< execute/search permission, group +#endif /* S_IRWXG */ +#ifndef S_IRWXO +#define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH) +#define S_IROTH 0000004 ///< read permission, other +#define S_IWOTH 0000002 ///< write permission, other +#define S_IXOTH 0000001 ///< execute/search permission, other +#endif /* S_IRWXO */ + +#define O_RDONLY 0 ///< Open for reading +#define O_WRONLY 1 ///< Open for writing +#define O_RDWR 2 ///< Open for reading and writing +#define O_NONBLOCK 0x0004 ///< Non-blocking mode +#define O_APPEND 0x0008 ///< Set file offset to end of file prior to each write +#define O_CREAT 0x0200 ///< Create file if it does not exist +#define O_TRUNC 0x0400 ///< Truncate file to zero length +#define O_EXCL 0x0800 ///< Fail if file exists +#define O_BINARY 0x8000 ///< Open file in binary mode + +#define O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR) + +#define NAME_MAX 255 ///< Maximum size of a name in a file path + +#define STDIN_FILENO 0 +#define STDOUT_FILENO 1 +#define STDERR_FILENO 2 + +#ifndef HAVE_SYS_STAT_H +struct stat { + dev_t st_dev; ///< Device ID containing file + ino_t st_ino; ///< File serial number + mode_t st_mode; ///< Mode of file + nlink_t st_nlink; ///< Number of links to file + + uid_t st_uid; ///< User ID + gid_t st_gid; ///< Group ID + + off_t st_size; ///< Size of file in bytes + + time_t st_atime; ///< Time of last access + time_t st_mtime; ///< Time of last data modification + time_t st_ctime; ///< Time of last status change +}; +#endif + +struct statvfs { + unsigned long f_bsize; ///< Filesystem block size + unsigned long f_frsize; ///< Fragment size (block size) + + unsigned long long f_blocks; ///< Number of blocks + unsigned long long f_bfree; ///< Number of free blocks + unsigned long long f_bavail; ///< Number of free blocks for unprivileged users + + unsigned long f_fsid; ///< Filesystem ID + + unsigned long f_namemax; ///< Maximum filename length +}; + + +struct dirent { + char d_name[NAME_MAX + 1]; ///< Name of file + uint8_t d_type; ///< Type of file +}; + +enum { + DT_UNKNOWN, ///< The file type could not be determined. + DT_FIFO, ///< This is a named pipe (FIFO). + DT_CHR, ///< This is a character device. + DT_DIR, ///< This is a directory. + DT_BLK, ///< This is a block device. + DT_REG, ///< This is a regular file. + DT_LNK, ///< This is a symbolic link. + DT_SOCK, ///< This is a UNIX domain socket. +}; + +/* fcntl.h defines */ +#define F_GETFL 3 +#define F_SETFL 4 + +struct pollfd { + int fd; + short events; + short revents; +}; + +} + +#endif //RETARGET_H diff --git a/platform/tests/UNITTESTS/doubles/platform/mbed_wait_api.h b/platform/tests/UNITTESTS/doubles/platform/mbed_wait_api.h new file mode 100644 index 0000000..1659840 --- /dev/null +++ b/platform/tests/UNITTESTS/doubles/platform/mbed_wait_api.h @@ -0,0 +1,32 @@ + +/* mbed Microcontroller Library + * Copyright (c) 2018 ARM Limited + * SPDX-License-Identifier: Apache-2.0 + * + * 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. + */ +#ifndef MBED_WAIT_API_H +#define MBED_WAIT_API_H + +#ifdef __cplusplus +extern "C" { +#endif + +void wait_us(int us); + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/platform/tests/UNITTESTS/doubles/platform/nvic_wrapper.h b/platform/tests/UNITTESTS/doubles/platform/nvic_wrapper.h new file mode 100644 index 0000000..056ba48 --- /dev/null +++ b/platform/tests/UNITTESTS/doubles/platform/nvic_wrapper.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2017, Arm Limited and affiliates. + * SPDX-License-Identifier: Apache-2.0 + * + * 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. + */ + +#ifndef NVIC_WRAPPER_H +#define NVIC_WRAPPER_H + +#ifdef __cplusplus +extern "C" +{ +#endif /* __cplusplus */ + +void NVIC_SystemReset(void); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif //NVIC_WRAPPER_H diff --git a/platform/tests/UNITTESTS/doubles/platform/platform.h b/platform/tests/UNITTESTS/doubles/platform/platform.h new file mode 100644 index 0000000..7dc963c --- /dev/null +++ b/platform/tests/UNITTESTS/doubles/platform/platform.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2017, Arm Limited and affiliates. + * SPDX-License-Identifier: Apache-2.0 + * + * 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. + */ + +#ifndef MBED_PLATFORM_H +#define MBED_PLATFORM_H + +#include +#include +#include +#include + +#include "platform/mbed_retarget.h" +#include "nvic_wrapper.h" + +#endif