Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ BraceWrapping:
AfterStruct: true
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterUnion: true
AfterNamespace: true
Expand Down
6 changes: 4 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@
"strstream": "cpp",
"typeindex": "cpp",
"charconv": "cpp",
"csignal": "cpp"
}
"csignal": "cpp",
"format": "cpp"
},
"git-blame.gitWebUrl": ""
}
41 changes: 41 additions & 0 deletions cetlvast/include/cetlvast/helpers_gtest_memory_resource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,47 @@
namespace cetlvast
{

/// PF17 memory resource that does _not_ implement realloc.
class MaxAlignNewDeleteResourceWithoutRealloc : public cetl::pf17::pmr::memory_resource
{
protected:
void* do_allocate(std::size_t size_bytes, std::size_t alignment) override
{
if (alignment > alignof(std::max_align_t))
{
#if defined(__cpp_exceptions)
throw std::bad_alloc();
#endif
return nullptr;
}
return ::operator new(size_bytes);
}

void do_deallocate(void* p, std::size_t size_bytes, std::size_t alignment) override
{
(void) size_bytes;
(void) alignment;
::operator delete(p);
}

void* do_reallocate(void* ptr,
std::size_t old_size_bytes,
std::size_t new_size_bytes,
std::size_t alignment) override
{
(void) ptr;
(void) old_size_bytes;
(void) new_size_bytes;
(void) alignment;
return nullptr;
}

bool do_is_equal(const memory_resource& rhs) const noexcept override
{
return (&rhs == this);
}
};

/// Pf17 Mock of memory_resource.
class MockPf17MemoryResource : public cetl::pf17::pmr::memory_resource
{
Expand Down
2 changes: 0 additions & 2 deletions cetlvast/suites/docs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,6 @@ create_docs_target( DOCS_DOXY_ROOT ${CMAKE_CURRENT_SOURCE_DIR}
"Cyphal Embedded Template Library"
EXAMPLES_PATH
${CMAKE_CURRENT_SOURCE_DIR}/examples
MAIN_PAGE_PATH
"${CETL_ROOT}/README.md"
INCLUDE_PREFIX_STRIP
"\"${CETL_ROOT}/include\""
INPUT_LIST
Expand Down
60 changes: 0 additions & 60 deletions cetlvast/suites/docs/doxygen.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1226,49 +1226,6 @@ USE_HTAGS = NO

VERBATIM_HEADERS = NO

# If the CLANG_ASSISTED_PARSING tag is set to YES then doxygen will use the
# clang parser (see:
# http://clang.llvm.org/) for more accurate parsing at the cost of reduced
# performance. This can be particularly helpful with template rich C++ code for
# which doxygen's built-in parser lacks the necessary type information.
# Note: The availability of this option depends on whether or not doxygen was
# generated with the -Duse_libclang=ON option for CMake.
# The default value is: NO.

# TODO: cppreference tag file doesn't seem to be the right format when this is
# turned on. Wasn't able to figure out what the problem was but clang
# parsing does work if you remove the tag file.
CLANG_ASSISTED_PARSING = NO

# If the CLANG_ASSISTED_PARSING tag is set to YES and the CLANG_ADD_INC_PATHS
# tag is set to YES then doxygen will add the directory of each input to the
# include path.
# The default value is: YES.
# This tag requires that the tag CLANG_ASSISTED_PARSING is set to YES.

CLANG_ADD_INC_PATHS = NO

# If clang assisted parsing is enabled you can provide the compiler with command
# line options that you would normally use when invoking the compiler. Note that
# the include paths will already be set by doxygen for the files and directories
# specified with INPUT and INCLUDE_PATH.
# This tag requires that the tag CLANG_ASSISTED_PARSING is set to YES.

CLANG_OPTIONS =

# If clang assisted parsing is enabled you can provide the clang parser with the
# path to the directory containing a file called compile_commands.json. This
# file is the compilation database (see:
# http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html) containing the
# options used when the source files were built. This is equivalent to
# specifying the -p option to a clang tool, such as clang-check. These options
# will then be passed to the parser. Any options specified with CLANG_OPTIONS
# will be added as well.
# Note: The availability of this option depends on whether or not doxygen was
# generated with the -Duse_libclang=ON option for CMake.

CLANG_DATABASE_PATH =

#---------------------------------------------------------------------------
# Configuration options related to the alphabetical class index
#---------------------------------------------------------------------------
Expand Down Expand Up @@ -1426,15 +1383,6 @@ HTML_COLORSTYLE_SAT = 0

HTML_COLORSTYLE_GAMMA = 100

# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML
# page will contain the date and time when the page was generated. Setting this
# to YES can help to show when doxygen was last run and thus if the
# documentation is up to date.
# The default value is: NO.
# This tag requires that the tag GENERATE_HTML is set to YES.

HTML_TIMESTAMP = NO

# If the HTML_DYNAMIC_MENUS tag is set to YES then the generated HTML
# documentation will contain a main index with vertical navigation menus that
# are dynamically created via JavaScript. If disabled, the navigation index will
Expand Down Expand Up @@ -2095,14 +2043,6 @@ LATEX_HIDE_INDICES = NO

LATEX_BIB_STYLE = plain

# If the LATEX_TIMESTAMP tag is set to YES then the footer of each generated
# page will contain the date and time when the page was generated. Setting this
# to NO can help when comparing the output of multiple runs.
# The default value is: NO.
# This tag requires that the tag GENERATE_LATEX is set to YES.

LATEX_TIMESTAMP = NO

# The LATEX_EMOJI_DIRECTORY tag is used to specify the (relative or absolute)
# path from which the emoji images will be read. If a relative path is entered,
# it will be relative to the LATEX_OUTPUT directory. If left blank the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ struct Message
// but if there is less data the std::vector in the message will return the size() of that data (i.e. where an
// std::array would not).
static constexpr std::size_t SmallMessageSizeBytes = 64 * 8;
static cetl::pf17::byte small_message_buffer_[SmallMessageSizeBytes];
static struct alignas(std::max_align_t)
{
cetl::pf17::byte data[SmallMessageSizeBytes];
} small_message_buffer_;

TEST(example_04_buffer_memory_resource, example_a)
{
//![example_a]
cetl::pf17::pmr::UnsynchronizedBufferMemoryResource aResource{small_message_buffer_, SmallMessageSizeBytes};
cetl::pf17::pmr::UnsynchronizedBufferMemoryResource aResource{small_message_buffer_.data, SmallMessageSizeBytes};
cetl::pf17::pmr::polymorphic_allocator<std::uint64_t> aAlloc{&aResource};
Message a{aAlloc};

Expand Down Expand Up @@ -64,7 +67,7 @@ TEST(example_04_buffer_memory_resource, example_b)
// an upstream allocator to turn this into a "small buffer optimization" resource where the internal allocation
// is the small buffer and the upstream allocator becomes the larger allocator.

cetl::pf17::pmr::UnsynchronizedBufferMemoryResource bResource{small_message_buffer_,
cetl::pf17::pmr::UnsynchronizedBufferMemoryResource bResource{small_message_buffer_.data,
SmallMessageSizeBytes,
cetl::pf17::pmr::new_delete_resource(),
std::numeric_limits<std::size_t>::max()};
Expand Down Expand Up @@ -94,7 +97,7 @@ TEST(example_04_buffer_memory_resource, example_c)
// to the size of these buffers.
static cetl::pf17::byte upstream_buffer[SmallMessageSizeBytes];
cetl::pf17::pmr::UnsynchronizedBufferMemoryResource cUpstreamResource{&upstream_buffer, SmallMessageSizeBytes};
cetl::pf17::pmr::UnsynchronizedBufferMemoryResource cResource{small_message_buffer_,
cetl::pf17::pmr::UnsynchronizedBufferMemoryResource cResource{small_message_buffer_.data,
SmallMessageSizeBytes,
&cUpstreamResource,
std::numeric_limits<std::size_t>::max()};
Expand Down
9 changes: 6 additions & 3 deletions cetlvast/suites/unittest/test_buffer_memory_resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ using ::testing::Return;
using ::testing::Expectation;

constexpr std::size_t TestBufferSize = 0x100000;
static cetl::pf17::byte large_buffer[TestBufferSize];
static struct alignas(std::max_align_t)
{
cetl::pf17::byte data[TestBufferSize];
} large_buffer;

TEST(UnsynchronizedBufferMemoryResourceDelegateTest, TestNullBuffer)
{
Expand All @@ -41,7 +44,7 @@ TEST(UnsynchronizedBufferMemoryResourceDelegateTest, TestNullBuffer)
TEST(UnsynchronizedBufferMemoryResourceDelegateTest, TestLargeBuffer)
{
cetlvast::MockPf17MemoryResource mock_upstream{};
cetl::pmr::UnsynchronizedBufferMemoryResourceDelegate<cetl::pf17::pmr::memory_resource> test_subject{large_buffer,
cetl::pmr::UnsynchronizedBufferMemoryResourceDelegate<cetl::pf17::pmr::memory_resource> test_subject{large_buffer.data,
TestBufferSize,
&mock_upstream,
0};
Expand All @@ -68,7 +71,7 @@ TEST(UnsynchronizedBufferMemoryResourceDelegateTest, TestDataAccess)
TEST(UnsynchronizedBufferMemoryResourceDelegateTest, TestLocalReallocate)
{
cetlvast::MockMemoryResource mock_upstream{};
cetl::pmr::UnsynchronizedBufferMemoryResourceDelegate<cetlvast::MockMemoryResource> test_subject{large_buffer,
cetl::pmr::UnsynchronizedBufferMemoryResourceDelegate<cetlvast::MockMemoryResource> test_subject{large_buffer.data,
TestBufferSize,
&mock_upstream,
0};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "cetlvast/helpers_gtest_memory_resource.hpp"
#include "cetl/pf17/cetlpf.hpp"
#include <array>

using ::testing::_;
using ::testing::Return;
Expand Down
108 changes: 108 additions & 0 deletions cetlvast/suites/unittest/test_variable_length_array_bool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,112 @@ TYPED_TEST(VLABoolTests, TestBoolIterator)
ASSERT_EQ(false, *foo.cbegin());
ASSERT_EQ(true, *(foo.cend() - 1));
ASSERT_EQ(true, foo.cbegin()[2]);

typename decltype(foo)::const_iterator const_begin_iterator =
const_cast<typename std::add_pointer<typename std::add_const<decltype(foo)>::type>::type>(&foo)->begin();
typename decltype(foo)::const_iterator const_end_interator =
const_cast<typename std::add_pointer<typename std::add_const<decltype(foo)>::type>::type>(&foo)->end();

ASSERT_EQ(false, *const_begin_iterator);
ASSERT_EQ(true, *(const_end_interator - 1));
ASSERT_EQ(true, const_begin_iterator[2]);
Comment thread
skeetsaz marked this conversation as resolved.
}

TYPED_TEST(VLABoolTests, TestBoolPopBack)
{
auto test_subject = TypeParam::make_bool_container(
std::initializer_list<bool>{true, false, true, false, true, false, true, false, true});
std::size_t starting_size = test_subject.size();
ASSERT_EQ(9, starting_size);
while (starting_size > 0)
{
ASSERT_EQ((starting_size % 2), test_subject[starting_size - 1]);
test_subject.pop_back();
--starting_size;
ASSERT_EQ(starting_size, test_subject.size());
}
}

TYPED_TEST(VLABoolTests, TestBoolResize)
{
auto array = TypeParam::make_bool_container();
ASSERT_EQ(0, array.size());
for (std::size_t i = 1; i <= 64; ++i)
{
array.resize(i, false);
ASSERT_EQ(i, array.size());
ASSERT_EQ(false, array[i - 1]);
}
}

TYPED_TEST(VLABoolTests, TestBoolResizeToZero)
{
auto test_subject = TypeParam::make_bool_container(
std::initializer_list<bool>{true, false, true, false, true, false, true, false, true});
ASSERT_EQ(9, test_subject.size());
test_subject.resize(0);
ASSERT_EQ(0, test_subject.size());
ASSERT_LE(9, test_subject.capacity());
}

TYPED_TEST(VLABoolTests, TestBoolResizeWithDefault)
{
auto array = TypeParam::make_bool_container(std::initializer_list<bool>{false});
array.resize(22, true);
ASSERT_EQ(22, array.size());
ASSERT_EQ(false, array[0]);
for (std::size_t i = 1; i < array.size(); ++i)
{
ASSERT_EQ(true, array[i]);
}
// Remember that, if we resize down, the default argument is not used for anything.
array.resize(9, false);
ASSERT_EQ(9, array.size());
ASSERT_EQ(false, array[0]);
for (std::size_t i = 1; i < array.size(); ++i)
{
ASSERT_EQ(true, array[i]);
}
}

TYPED_TEST(VLABoolTests, TestBoolResizeOneBit)
{
auto array = TypeParam::make_bool_container(std::initializer_list<bool>{true, false, true});
ASSERT_EQ(3, array.size());
ASSERT_EQ(1, array[0]);
ASSERT_EQ(0, array[1]);
ASSERT_EQ(1, array[2]);
array.resize(4, 1);
ASSERT_EQ(4, array.size());
ASSERT_EQ(1, array[0]);
ASSERT_EQ(0, array[1]);
ASSERT_EQ(1, array[2]);
ASSERT_EQ(1, array[3]);
array.resize(5);
ASSERT_EQ(5, array.size());
ASSERT_EQ(1, array[0]);
ASSERT_EQ(0, array[1]);
ASSERT_EQ(1, array[2]);
ASSERT_EQ(1, array[3]);
ASSERT_EQ(0, array[4]);
}

TYPED_TEST(VLABoolTests, TestBoolFront)
{
auto array = TypeParam::make_bool_container(std::initializer_list<bool>{true, false, true});
ASSERT_TRUE(array.front());

typename decltype(array)::const_reference value =
const_cast<typename std::add_pointer<typename std::add_const<decltype(array)>::type>::type>(&array)->front();
ASSERT_TRUE(value);
}

TYPED_TEST(VLABoolTests, TestBoolBack)
{
auto array = TypeParam::make_bool_container(std::initializer_list<bool>{true, false, true});
ASSERT_TRUE(array.back());

typename decltype(array)::const_reference value =
const_cast<typename std::add_pointer<typename std::add_const<decltype(array)>::type>::type>(&array)->back();
ASSERT_TRUE(value);
}
Loading