Example #1
0
int test_mem(int argc, char *argv[]) {

        unsigned int *array = NULL;
        int arraySize = 10;
        PKIX_UInt32 actualMinorVersion;
        PKIX_UInt32 j = 0;

        PKIX_TEST_STD_VARS();

        startTests("Memory Allocation");

        PKIX_TEST_EXPECT_NO_ERROR(
            PKIX_PL_NssContext_Create(0, PKIX_FALSE, NULL, &plContext));

        subTest("PKIX_PL_Malloc");
        testMalloc(&array);

        subTest("PKIX_PL_Realloc");
        testRealloc(&array);

        subTest("PKIX_PL_Free");
        testFree(array);

        /* --Negative Test Cases------------------- */
        /* Create an integer array of size 10 */
        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Malloc(
                            (PKIX_UInt32)(arraySize*sizeof (unsigned int)),
                            (void **) &array, plContext));

        (void) printf("Attempting to reallocate 0 sized memory...\n");

        PKIX_TEST_EXPECT_NO_ERROR
                (PKIX_PL_Realloc(array, 0, (void **) &array, plContext));

        (void) printf("Attempting to allocate to null pointer...\n");

        PKIX_TEST_EXPECT_ERROR(PKIX_PL_Malloc(10, NULL, plContext));

        (void) printf("Attempting to reallocate to null pointer...\n");

        PKIX_TEST_EXPECT_ERROR(PKIX_PL_Realloc(NULL, 10, NULL, plContext));

        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Free(array, plContext));

cleanup:

        PKIX_Shutdown(plContext);

        endTests("Memory Allocation");

        return (0);
}
Example #2
0
/*
 * Unit test framework entry point for this set of unit tests.
 *
 */
void testMem_runTests() {
  pcsl_mem_initialize(NULL, 5000);

  testAllocation();
  testMalloc();
  testAllocateChunk();
  /*
   * comment out this test. The implementation changes the
   * specified max size, to align with a page
   * need revisit: what the new max size is. So we can't
   * compare against it.
   */
  /*
  testModifyChunkSize();
  */
  testDoubleInit();
  testHeapSize();
  testCalloc();
  testRealloc();
  testStrdup();

  pcsl_mem_finalize();
}