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
25 changes: 25 additions & 0 deletions include/malloc_from_scratch/memory_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,31 @@ MemoryBlock* getMemoryBlockFromAddress(void* address);
size_t getSizeOfAllocatedMemoryBlock(MemoryBlock* block);
void* getErrorCodeInVoidPtr(size_t error_code);

// Test helper functions to inspect allocator state
inline size_t getTotalUsedMemory() { return total_memory_allocated; }
inline size_t getFreeBlockInfo(int type)
{
// type 0 = address of first free block
// type 1 = size of first free block
MemoryBlock* current = block_list_head;
while (current != nullptr)
{
if (!current->allocated_)
{
if (type == 0)
{
return reinterpret_cast<size_t>(getPayloadAddress(current));
}
else if (type == 1)
{
return current->size_;
}
}
current = current->next_;
}
return 0;
}

} // namespace internal
} // namespace mem

Expand Down
16 changes: 16 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ foreach(test_file ${TEST_SOURCES})
LABELS "${test_category}"
)
endif()

# Set default timeout for all tests (10 seconds)
set_tests_properties(${test_name} PROPERTIES
TIMEOUT 10
)

# Longer timeouts for specific categories that need more time
if(test_category MATCHES "stress")
set_tests_properties(${test_name} PROPERTIES
TIMEOUT 30
)
elseif(test_category MATCHES "concurrency")
set_tests_properties(${test_name} PROPERTIES
TIMEOUT 20
)
endif()
endforeach()

# Add strace tests for all categories except those that would produce false positives
Expand Down
5 changes: 5 additions & 0 deletions tests/test_utils.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef TEST_UTILS_H
#define TEST_UTILS_H

#include "malloc_from_scratch/memory_internal.h"
#include <cstring>
#include <iostream>

Expand Down Expand Up @@ -56,4 +57,8 @@ inline void test_pass()
#define ASSERT_NOT_NULL(ptr) assert_not_null((ptr), __FILE__, __LINE__)
#define TEST_PASS() test_pass()

// Internal test helpers for convenience
using mem::internal::getFreeBlockInfo;
using mem::internal::getTotalUsedMemory;

#endif // TEST_UTILS_H