infix
A JIT-Powered FFI Library for C
|
An advanced stress test that uses fault injection to find memory leaks in the library's error-handling code paths, adapted for the new arena model. More...
Macros | |
#define | infix_malloc test_malloc |
#define | infix_calloc test_calloc |
#define | infix_free test_free |
#define | infix_realloc test_realloc |
#define | DBLTAP_IMPLEMENTATION |
#define | ALLOCATOR_LOCK() pthread_mutex_lock(&allocator_mutex) |
#define | ALLOCATOR_UNLOCK() pthread_mutex_unlock(&allocator_mutex) |
#define | ALLOCATOR_INIT() ((void)0) |
Functions | |
void | setup_fault_injector (int fail_after_n_allocs) |
Configures the allocator to fail after a specific number of successful allocations. | |
void | reset_fault_injector () |
Resets the allocator to its default (non-failing) behavior. | |
void * | test_malloc (size_t size) |
void * | test_calloc (size_t num, size_t size) |
void | test_free (void *ptr) |
void * | test_realloc (void *ptr, size_t new_size) |
void | fault_injection_handler (void) |
subtest ("Leak test for infix_forward_create failures") | |
subtest ("Leak test for infix_reverse_create_callback failures") | |
subtest ("Leak test for infix_type_from_signature failures") | |
Variables | |
static int | allocation_countdown = -1 |
static int | allocation_counter = 0 |
static bool | fault_triggered = false |
static pthread_mutex_t | allocator_mutex = PTHREAD_MUTEX_INITIALIZER |
TEST | |
An advanced stress test that uses fault injection to find memory leaks in the library's error-handling code paths, adapted for the new arena model.
Copyright (c) 2025 Sanko Robinson
This source code is dual-licensed under the Artistic License 2.0 or the MIT License. You may choose to use this code under the terms of either license.
SPDX-License-Identifier: (Artistic-2.0 OR MIT)
The documentation blocks within this file are licensed under the Creative Commons Attribution 4.0 International License (CC BY 4.0).
SPDX-License-Identifier: CC-BY-4.0
This test replaces the standard malloc/calloc/free/realloc functions with a custom, thread-safe allocator that can be programmed to fail after a specific number of successful allocations.
By repeatedly attempting to create complex FFI objects and forcing a heap allocation failure at every possible point (e.g., arena creation, handle creation, executable memory allocation), this test rigorously exercises all error-handling and cleanup code in the library. It is designed to be run under Valgrind's memcheck tool.
The test is considered successful if two conditions are met:
INFIX_ERROR_ALLOCATION_FAILED
status codes up the call stack.This test targets the two most allocation-heavy high-level operations:
infix_reverse_create_callback
infix_type_from_signature
ALLOCATOR_INIT | ( | ) | ((void)0) |
#define ALLOCATOR_LOCK | ( | ) | pthread_mutex_lock(&allocator_mutex) |
#define ALLOCATOR_UNLOCK | ( | ) | pthread_mutex_unlock(&allocator_mutex) |
#define DBLTAP_IMPLEMENTATION |
#define infix_calloc test_calloc |
#define infix_free test_free |
#define infix_malloc test_malloc |
#define infix_realloc test_realloc |
void fault_injection_handler | ( | void | ) |
void reset_fault_injector | ( | ) |
Resets the allocator to its default (non-failing) behavior.
void setup_fault_injector | ( | int | fail_after_n_allocs | ) |
Configures the allocator to fail after a specific number of successful allocations.
subtest | ( | "Leak test for infix_forward_create failures" | ) |
subtest | ( | "Leak test for infix_reverse_create_callback failures" | ) |
subtest | ( | "Leak test for infix_type_from_signature failures" | ) |
void * test_calloc | ( | size_t | num, |
size_t | size | ||
) |
void test_free | ( | void * | ptr | ) |
void * test_malloc | ( | size_t | size | ) |
void * test_realloc | ( | void * | ptr, |
size_t | new_size | ||
) |
|
static |
|
static |
|
static |
|
static |