Assume Memory

A memory assumption/assertion checks for the proper allocation, usage, and deallocation of memory during the execution of a program. These assertions are used to ensure that memory management practices are correct, helping to detect issues like memory leaks, dangling pointers, and excessive memory consumption. Memory assertions are crucial for ensuring that software performs efficiently and securely, especially in long-running applications or systems with limited resources.

C, C++ REFERENCE #

/**
 * @brief Assumes that the given memory is zeroed.
 *
 * @param ptr A pointer to the memory to check.
 * @param size The size of the memory to check.
 */
#define ASSUME_ITS_ZERO_MEMORY(ptr, size) \
    FOSSIL_TEST_ASSUME(pizza_sys_memory_zero((ptr), (size)), "Expected memory at " #ptr " to be zeroed")

/**
 * @brief Assumes that the given memory is not zeroed.
 *
 * @param ptr A pointer to the memory to check.
 * @param size The size of the memory to check.
 */
#define ASSUME_NOT_ZERO_MEMORY(ptr, size) \
    FOSSIL_TEST_ASSUME(!pizza_sys_memory_zero((ptr), (size)), "Expected memory at " #ptr " to not be zero")

/**
 * @brief Assumes that the given memory regions are equal.
 *
 * @param ptr1 A pointer to the first memory region.
 * @param ptr2 A pointer to the second memory region.
 * @param size The size of the memory regions to compare.
 */
#define ASSUME_ITS_EQUAL_MEMORY(ptr1, ptr2, size) \
    FOSSIL_TEST_ASSUME(pizza_sys_memory_compare((ptr1), (ptr2), (size)) == 0, "Expected memory regions " #ptr1 " and " #ptr2 " to be equal")

/**
 * @brief Assumes that the given memory regions are not equal.
 *
 * @param ptr1 A pointer to the first memory region.
 * @param ptr2 A pointer to the second memory region.
 * @param size The size of the memory regions to compare.
 */
#define ASSUME_ITS_NOT_EQUAL_MEMORY(ptr1, ptr2, size) \
    FOSSIL_TEST_ASSUME(pizza_sys_memory_compare((ptr1), (ptr2), (size)) != 0, "Expected memory regions " #ptr1 " and " #ptr2 " to not be equal")

/**
 * @brief Assumes that the given memory region is more than the expected memory region.
 *
 * @param ptr1 A pointer to the first memory region.
 * @param ptr2 A pointer to the second memory region.
 * @param size The size of the memory regions to compare.
 */
#define ASSUME_ITS_MORE_THAN_MEMORY(ptr1, ptr2, size) \
    FOSSIL_TEST_ASSUME(pizza_sys_memory_compare((ptr1), (ptr2), (size)) > 0, "Expected memory region " #ptr1 " to be more than " #ptr2)

/**
 * @brief Assumes that the given memory region is less than the expected memory region.
 *
 * @param ptr1 A pointer to the first memory region.
 * @param ptr2 A pointer to the second memory region.
 * @param size The size of the memory regions to compare.
 */
#define ASSUME_ITS_LESS_THAN_MEMORY(ptr1, ptr2, size) \
    FOSSIL_TEST_ASSUME(pizza_sys_memory_compare((ptr1), (ptr2), (size)) < 0, "Expected memory region " #ptr1 " to be less than " #ptr2)

/**
 * @brief Assumes that the given memory region is more than or equal to the expected memory region.
 *
 * @param ptr1 A pointer to the first memory region.
 * @param ptr2 A pointer to the second memory region.
 * @param size The size of the memory regions to compare.
 */
#define ASSUME_ITS_MORE_OR_EQUAL_MEMORY(ptr1, ptr2, size) \
    FOSSIL_TEST_ASSUME(pizza_sys_memory_compare((ptr1), (ptr2), (size)) >= 0, "Expected memory region " #ptr1 " to be more than or equal to " #ptr2)

/**
 * @brief Assumes that the given memory region is less than or equal to the expected memory region.
 *
 * @param ptr1 A pointer to the first memory region.
 * @param ptr2 A pointer to the second memory region.
 * @param size The size of the memory regions to compare.
 */
#define ASSUME_ITS_LESS_OR_EQUAL_MEMORY(ptr1, ptr2, size) \
    FOSSIL_TEST_ASSUME(pizza_sys_memory_compare((ptr1), (ptr2), (size)) <= 0, "Expected memory region " #ptr1 " to be less than or equal to " #ptr2)

/**
 * @brief Assumes that the given memory region is not more than the expected memory region.
 *
 * @param ptr1 A pointer to the first memory region.
 * @param ptr2 A pointer to the second memory region.
 * @param size The size of the memory regions to compare.
 */
#define ASSUME_NOT_MORE_THAN_MEMORY(ptr1, ptr2, size) \
    FOSSIL_TEST_ASSUME(pizza_sys_memory_compare((ptr1), (ptr2), (size)) <= 0, "Expected memory region " #ptr1 " to not be more than " #ptr2)

/**
 * @brief Assumes that the given memory region is not less than the expected memory region.
 *
 * @param ptr1 A pointer to the first memory region.
 * @param ptr2 A pointer to the second memory region.
 * @param size The size of the memory regions to compare.
 */
#define ASSUME_NOT_LESS_THAN_MEMORY(ptr1, ptr2, size) \
    FOSSIL_TEST_ASSUME(pizza_sys_memory_compare((ptr1), (ptr2), (size)) >= 0, "Expected memory region " #ptr1 " to not be less than " #ptr2)

/**
 * @brief Assumes that the given memory region is not more than or equal to the expected memory region.
 *
 * @param ptr1 A pointer to the first memory region.
 * @param ptr2 A pointer to the second memory region.
 * @param size The size of the memory regions to compare.
 */
#define ASSUME_NOT_MORE_OR_EQUAL_MEMORY(ptr1, ptr2, size) \
    FOSSIL_TEST_ASSUME(pizza_sys_memory_compare((ptr1), (ptr2), (size)) < 0, "Expected memory region " #ptr1 " to not be more than or equal to " #ptr2)

/**
 * @brief Assumes that the given memory region is not less than or equal to the expected memory region.
 *
 * @param ptr1 A pointer to the first memory region.
 * @param ptr2 A pointer to the second memory region.
 * @param size The size of the memory regions to compare.
 */
#define ASSUME_NOT_LESS_OR_EQUAL_MEMORY(ptr1, ptr2, size) \
    FOSSIL_TEST_ASSUME(pizza_sys_memory_compare((ptr1), (ptr2), (size)) > 0, "Expected memory region " #ptr1 " to not be less than or equal to " #ptr2)

/**
 * @brief Assumes that the given memory pointer is valid.
 *
 * @param ptr A pointer to the memory to check.
 */
#define ASSUME_ITS_VALID_MEMORY(ptr) \
    FOSSIL_TEST_ASSUME(pizza_sys_memory_is_valid((ptr)), "Expected memory pointer " #ptr " to be valid")

/**
 * @brief Assumes that the given memory pointer is not valid.
 *
 * @param ptr A pointer to the memory to check.
 */
#define ASSUME_NOT_VALID_MEMORY(ptr) \
    FOSSIL_TEST_ASSUME(!pizza_sys_memory_is_valid((ptr)), "Expected memory pointer " #ptr " to not be valid")

PYTHON REFERENCE #

# TODO: add code here

What are your feelings

Updated on May 12, 2025