Esempio n. 1
0
/**
 * Ensure that the scheduler is using parc memory inside libevent
 */
LONGBOW_TEST_CASE(Global, parc_EventScheduler_Memory)
{
    PARCEventScheduler *parcEventScheduler = parcEventScheduler_Create();
    assertNotNull(parcEventScheduler, "parcEventScheduler_Create returned a null reference");

    size_t baseline = parcMemory_Outstanding();

    struct event *testEvent = event_new(parcEventScheduler_GetEvBase(parcEventScheduler), -1, 0, _test_memory_event, NULL);

    assertTrue(parcMemory_Outstanding() > baseline,
               "event_new() did not increase parcMemory_Outstanding: baseline %zu now %u",
               baseline,
               parcMemory_Outstanding());

    event_free(testEvent);

    assertTrue(parcMemory_Outstanding() == baseline,
               "event_free() did reduce to baseline: baseline %zu now %u",
               baseline,
               parcMemory_Outstanding());

    parcEventScheduler_Destroy(&parcEventScheduler);

    assertTrue(parcSafeMemory_ReportAllocation(STDOUT_FILENO) == 0, "Memory imbalance on create/destroy: %u", parcMemory_Outstanding());
}
Esempio n. 2
0
LONGBOW_TEST_CASE(Global, metisCommandParser_Create_Destroy)
{
    MetisCommandParser *parser = metisCommandParser_Create();
    assertNotNull(parser, "Got null parser from metisCommandParser_Create");
    metisCommandParser_Destroy(&parser);
    assertTrue(parcSafeMemory_ReportAllocation(STDOUT_FILENO) == 0, "Memory imbalance!");
    assertNull(parser, "metisCommandParser_Destroy did not null pointer");
}
Esempio n. 3
0
LONGBOW_TEST_CASE(ReportAllocation, parcSafeMemory_ReportAllocation_Empty)
{
    _parcSafeMemory_DeallocateAll();
    int fd = open("/dev/null", O_WRONLY);
    size_t result = parcSafeMemory_ReportAllocation(fd);
    close(fd);
    assertTrue(result == 0, "Expected 0, was %zd", result);
}
Esempio n. 4
0
static uint32_t
commonTearDown(TestData *data)
{
    uint32_t setupAllocations = data->setupAllocations;

    // NOTE: The `parcBufferComposer_AssertValid_IncrementSize` invalidates this object, so we must
    // restore it to a good state in order for all memory to be released correctly.
    (data->composer)->incrementHeuristic = sizeof(void *);

    parcBufferComposer_Release(&(data->composer));
    parcMemory_Deallocate((void **) &data);
    return parcSafeMemory_ReportAllocation(STDOUT_FILENO) - setupAllocations;
}
Esempio n. 5
0
LONGBOW_TEST_CASE(ReportAllocation, parcSafeMemory_ReportAllocation_One)
{
    void *memory;
    size_t size = 100;

    memory = parcSafeMemory_Allocate(size);

    int fd = open("/dev/null", O_WRONLY);
    size_t result = parcSafeMemory_ReportAllocation(fd);
    close(fd);
    assertTrue(result == 1, "Expected 1, was %zd", result);

    parcSafeMemory_Deallocate(&memory);
}
Esempio n. 6
0
LONGBOW_TEST_CASE(ReportAllocation, parcSafeMemory_ReportAllocation_Deallocated)
{
    size_t size = 100;
    void *memory = parcSafeMemory_Allocate(size);
    assertTrue(parcSafeMemory_Outstanding() != 0, "No memory allocated!");
    PARCSafeMemoryState state = _parcSafeMemory_GetState(memory);
    parcSafeMemory_Deallocate(&memory);
    assertTrue(state == PARCSafeMemoryState_OK, "Expected uncorrupted memory.");

    int fd = open("/dev/null", O_WRONLY);
    size_t result = parcSafeMemory_ReportAllocation(fd);
    close(fd);

    assertTrue(result == 0, "Expected 0, was %zd", result);
}