@@ -1588,6 +1588,62 @@ TEST(AllocatorTest, MallocAllocatorTest) {
15881588 allocator.deallocate (100 , ptr);
15891589}
15901590
1591+ TEST (AllocatorTest, MallocAllocatorTestNoRecoverable) {
1592+ // Since it is a wrapper around malloc, the test consists of requesting
1593+ // memory and verifying a non-zero pointer, unchanged size, and not recoverable.
1594+ Fw::MallocAllocator allocator;
1595+ Fw::MemAllocator& memAllocator = allocator;
1596+ FwSizeType size = 100 ; // one hundred bytes
1597+ void * ptr = memAllocator.allocate (10 , size);
1598+ ASSERT_EQ (100 , size);
1599+ ASSERT_NE (ptr, nullptr );
1600+ // deallocate memory
1601+ allocator.deallocate (100 , ptr);
1602+ }
1603+
1604+ TEST (AllocatorTest, MallocCheckedAllocate) {
1605+ // Since it is a wrapper around malloc, the test consists of requesting
1606+ // memory and verifying a non-zero pointer, unchanged size, and not recoverable.
1607+ Fw::MallocAllocator allocator;
1608+ FwSizeType size = 100 ; // one hundred bytes
1609+ bool recoverable;
1610+ void * ptr = allocator.checkedAllocate (10 , size, recoverable);
1611+ ASSERT_EQ (100 , size);
1612+ ASSERT_NE (ptr, nullptr );
1613+ ASSERT_FALSE (recoverable);
1614+ // deallocate memory
1615+ allocator.deallocate (100 , ptr);
1616+ }
1617+
1618+ TEST (AllocatorTest, MallocCheckedAllocateNoRecoverable) {
1619+ // Since it is a wrapper around malloc, the test consists of requesting
1620+ // memory and verifying a non-zero pointer, unchanged size, and not recoverable.
1621+ Fw::MallocAllocator allocator;
1622+ FwSizeType size = 100 ; // one hundred bytes
1623+ void * ptr = allocator.checkedAllocate (10 , size);
1624+ ASSERT_EQ (100 , size);
1625+ ASSERT_NE (ptr, nullptr );
1626+ // deallocate memory
1627+ allocator.deallocate (100 , ptr);
1628+ }
1629+
1630+ TEST (AllocatorTest, MallocCheckedAllocateTrapped) {
1631+ // Since it is a wrapper around malloc, the test consists of requesting
1632+ // memory and verifying a non-zero pointer, unchanged size, and not recoverable.
1633+ Fw::MallocAllocator allocator;
1634+ bool recoverable;
1635+ FwSizeType size = std::numeric_limits<FwSizeType>::max (); // Impossible number of bytes
1636+ ASSERT_DEATH (allocator.checkedAllocate (10 , size, recoverable), " .*" );
1637+ }
1638+
1639+ TEST (AllocatorTest, MallocCheckedAllocateNoRecoverableTrapped) {
1640+ // Since it is a wrapper around malloc, the test consists of requesting
1641+ // memory and verifying a non-zero pointer, unchanged size, and not recoverable.
1642+ Fw::MallocAllocator allocator;
1643+ FwSizeType size = std::numeric_limits<FwSizeType>::max (); // Impossible number of bytes
1644+ ASSERT_DEATH (allocator.checkedAllocate (10 , size), " .*" );
1645+ }
1646+
15911647TEST (Nominal, string_copy) {
15921648 const char * copy_string = " abc123\n " ; // Length of 7
15931649 char buffer_out_test[10 ];
0 commit comments