Esempio n. 1
0
int main(void)
{
	bool ret = true;

	talloc_disable_null_tracking();
	talloc_enable_null_tracking();

	ret &= test_ref1();
	ret &= test_ref2();
	ret &= test_ref3();
	ret &= test_ref4();
	ret &= test_unlink1(); 
	ret &= test_misc();
	ret &= test_realloc();
	ret &= test_realloc_child(); 
	ret &= test_steal(); 
	ret &= test_move(); 
	ret &= test_unref_reparent();
	ret &= test_realloc_fn(); 
	ret &= test_type();
	ret &= test_lifeless(); 
	ret &= test_loop();
	ret &= test_free_parent_deny_child(); 
	ret &= test_talloc_ptrtype();

	if (ret) {
		ret &= test_speed();
	}
	ret &= test_autofree();

	if (!ret)
		return -1;
	return 0;
}
Esempio n. 2
0
File: a.c Progetto: herumi/misc
int main()
{
	mie_init();
	printf("malloc=%p, free=%p\n", malloc, free);
	puts("main");
	test_realloc();
	char *p = malloc(7);
#ifdef USE_DLOPEN
	puts("dlopen");
	void *h = dlopen(soName, RTLD_LAZY);
	if (h == NULL) {
		perror("dlopen");
		return 1;
	}
	puts("dlsym");
	void (*f)() = dlsym(h, "sub_free");
	if (f == NULL) {
		perror("dlsym");
		return 1;
	}
	puts("call");
	f(p);
	puts("dlclose");
	dlclose(h);
#else
	sub_free(p);
#endif
	{
		char *q = malloc(3);
		printf("malloc size=%zd\n", malloc_usable_size(q));
		q[3] = 'a';
		free(q);
	}
	return 0;
}
Esempio n. 3
0
File: test.c Progetto: garodimb/rtos
int main(){
	int ch;
	print_menu();
	do{
		printf("Enter your choice: ");
		scanf("%d",&ch);
		switch(ch){
			case TEST_MALLOC:
								test_malloc();
								break;
			case TEST_CALLOC:
								test_calloc();
								break;
			case TEST_REALLOC:	
								test_realloc();
								break;
			case TEST_FREE:		
								test_free();
								break;
			case TEST_SPACE:	
								test_get_free_space();
								break;
			case PRINT_MMAP:
								test_print_mmap();
								break;
			case EXIT:			
								break;
			default: 			printf("Invalid selection!!! Try Again\n");
			}
		}while(ch!=EXIT);
	return 0;
	}
Esempio n. 4
0
int main(int argc, char**argv)
{
  char* buffer[ITER];
  int i, j;

  debug("Testing malloc\n");
  test_malloc();
  debug("1/2 done\n");
  compute(100000);

  test_malloc();
  debug("2/2 done\n");

  compute(100000);
  debug("Testing realloc\n");
  test_realloc();
  debug("realloc done\n");

  compute(100000);
  debug("Testing calloc\n");
  test_calloc();
  debug("calloc done\n");

  return 0;
}
Esempio n. 5
0
int main(int argc, const char * argv[]) {
  test_units();
  test_breaking();
  test_realloc();
  test_alignment();
  return 0;
}
Esempio n. 6
0
void
testcase_run(TestCaseState_t *tcs)
{
    char *argv_org[] = {"-tmmbcs1024", "-tsbct2048", "-trmbcmt100", "-tas", NULL, NULL};
    char *alg[] = {"af", "gf", "bf", "aobf", "aoff", NULL};
    int i;

    for (i = 0; alg[i]; i++) {
	Ulong sz;
	Allctr_t *a;
	char *argv[sizeof(argv_org)/sizeof(argv_org[0])];
	memcpy((void *) argv, (void *) argv_org, sizeof(argv_org));

	argv[4] = alg[i];
	testcase_printf(tcs, " *** Starting \"%s\" allocator *** \n", alg[i]);
	a = START_ALC("coalesce_", 0, argv);
	ASSERT(tcs, a);
	tcs->extra = (void *) a;

	sz = MIN_BLK_SZ(a) - ABLK_HDR_SZ;
	test_free(tcs, a, sz);
	sz += 1;
	test_free(tcs, a, sz);
	sz *= 4; 
	test_free(tcs, a, sz);
	sz += 1;
	test_free(tcs, a, sz);
	sz *= 10;
	test_free(tcs, a, sz);

	sz = MIN_BLK_SZ(a)*4 - ABLK_HDR_SZ;
	test_realloc(tcs, a, sz);
	sz += 1;
	test_realloc(tcs, a, sz);
	sz *= 4; 
	test_realloc(tcs, a, sz);
	sz += 1;
	test_realloc(tcs, a, sz);
	sz *= 10;
	test_realloc(tcs, a, sz);

	testcase_printf(tcs, " *** Stopping \"%s\" allocator *** \n", alg[i]);
	STOP_ALC(a);
	tcs->extra = NULL;
    }
}
Esempio n. 7
0
int
main (int   argc,
      char *argv[])
{
	test_new ();
	test_alloc ();
	test_realloc ();
	test_free ();
	test_discard ();
	test_ref ();
	test_unref ();
	test_parent ();
	test_local ();

	return 0;
}
int main ()
{
   mem_open (NULL);
   log_open (NULL,LOG_NOISY,LOG_HAVE_COLORS | LOG_PRINT_FUNCTION);
   atexit (mem_close);
   atexit (log_close);

#ifdef TEST_ALLOC
   test_alloc ();
#endif	/* #ifdef TEST_ALLOC */

#ifdef TEST_REALLOC
   test_realloc ();
#endif	/* #ifdef TEST_REALLOC */

   exit (EXIT_SUCCESS);
}
Esempio n. 9
0
int main()
{
  test_realloc();

  test_user_supplied_free();

  test_at();

  test_front_and_back();

  //test_vector_copy();
  
  test_vector_reserve();

  test_empty();

  return 0;
}
Esempio n. 10
0
bool torture_local_talloc(struct torture_context *tctx)
{
	bool ret = true;

	setlinebuf(stdout);

	talloc_disable_null_tracking();
	talloc_enable_null_tracking();

	ret &= test_ref1();
	ret &= test_ref2();
	ret &= test_ref3();
	ret &= test_ref4();
	ret &= test_unlink1(); 
	ret &= test_misc();
	ret &= test_realloc();
	ret &= test_realloc_child(); 
	ret &= test_steal(); 
	ret &= test_move(); 
	ret &= test_unref_reparent();
	ret &= test_realloc_fn(); 
	ret &= test_type();
	ret &= test_lifeless(); 
	ret &= test_loop();
	ret &= test_free_parent_deny_child(); 
	ret &= test_talloc_ptrtype();
	ret &= test_talloc_free_in_destructor();
	ret &= test_pool();

	if (ret) {
		ret &= test_speed();
	}
	ret &= test_autofree();

	return ret;
}
Esempio n. 11
0
rtems_task Init(
  rtems_task_argument argument
)
{
  void             *p1;
  rtems_time_of_day time;
  rtems_status_code status;

  TEST_BEGIN();

  build_time( &time, 12, 31, 1988, 9, 0, 0, 0 );
  status = rtems_clock_set( &time );
  directive_failed( status, "rtems_clock_set" );

  /*
   * Verify case where block is too large to calloc.
   */
  p1 = calloc( 1, SIZE_MAX );
  if (p1) {
    printf("ERROR on attempt to calloc SIZE_MAX block expected failure.");
    free( p1 );
  }

  /*
   * Verify error case where malloc of size 0.
   */
  p1 = malloc( 0 );
  if (p1) {
    printf("ERROR on attempt to malloc size 0 block expected failure.");
    free( p1 );
  }



  test_heap_initialize();
  test_heap_block_allocate();
  test_heap_allocate();
  test_heap_free();
  test_heap_resize_block();
  test_realloc();
  test_heap_cases_1();
  test_heap_extend();
  test_heap_extend_allocation_order();
  test_heap_extend_allocation_order_with_empty_heap();
  test_heap_no_extend();
  test_heap_info();
  test_heap_size_with_overhead();
  test_protected_heap_info();
  test_rtems_heap_allocate_aligned_with_boundary();
  test_greedy_allocate();

  test_posix_memalign();

  Task_name[ 1 ] = rtems_build_name( 'T', 'A', '1', ' ' );
  Task_name[ 2 ] = rtems_build_name( 'T', 'A', '2', ' ' );
  Task_name[ 3 ] = rtems_build_name( 'T', 'A', '3', ' ' );
  Task_name[ 4 ] = rtems_build_name( 'T', 'A', '4', ' ' );
  Task_name[ 5 ] = rtems_build_name( 'T', 'A', '5', ' ' );

  status = rtems_task_create(
     Task_name[ 1 ],
     1,
     TASK_STACK_SIZE,
     RTEMS_DEFAULT_MODES,
     RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT,
     &Task_id[ 1 ]
  );
  directive_failed( status, "rtems_task_create of TA1" );

  status = rtems_task_create(
     Task_name[ 2 ],
     1,
     TASK_STACK_SIZE,
     RTEMS_DEFAULT_MODES,
     RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT,
     &Task_id[ 2 ]
  );
  directive_failed( status, "rtems_task_create of TA2" );

  status = rtems_task_create(
     Task_name[ 3 ],
     1,
     TASK_STACK_SIZE,
     RTEMS_DEFAULT_MODES,
     RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT,
     &Task_id[ 3 ]
  );
  directive_failed( status, "rtems_task_create of TA3" );

  status = rtems_task_create(
     Task_name[ 4 ],
     1,
     TASK_STACK_SIZE,
     RTEMS_DEFAULT_MODES,
     RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT,
     &Task_id[ 4 ]
  );
  directive_failed( status, "rtems_task_create of TA4" );

  status = rtems_task_create(
     Task_name[ 5 ],
     1,
     TASK_STACK_SIZE,
     RTEMS_DEFAULT_MODES,
     RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT,
     &Task_id[ 5 ]
  );
  directive_failed( status, "rtems_task_create of TA5" );

  status = rtems_task_start( Task_id[ 1 ], Task_1_through_5, 0 );
  directive_failed( status, "rtems_task_start of TA1" );

  status = rtems_task_start( Task_id[ 2 ], Task_1_through_5, 0 );
  directive_failed( status, "rtems_task_start of TA2" );

  status = rtems_task_start( Task_id[ 3 ], Task_1_through_5, 0 );
  directive_failed( status, "rtems_task_start of TA3" );

  status = rtems_task_start( Task_id[ 4 ], Task_1_through_5, 0 );
  directive_failed( status, "rtems_task_start of TA4" );

  status = rtems_task_start( Task_id[ 5 ], Task_1_through_5, 0 );
  directive_failed( status, "rtems_task_start of TA5" );

  status = rtems_task_delete( RTEMS_SELF );
  directive_failed( status, "rtems_task_delete of RTEMS_SELF" );
}
Esempio n. 12
0
static void
test_mock_pool_allocs()
{
	void *real_address = ZALLOC(MOCK_POOL_SIZE * 2);
	addr = (void *)ALIGN_CEILING((uint64_t)real_address,
		(uint64_t)Ut_pagesize);
	mock_pop = &addr->p;
	mock_pop->addr = addr;
	mock_pop->size = MOCK_POOL_SIZE;
	mock_pop->rdonly = 0;
	mock_pop->is_pmem = 0;
	mock_pop->heap_offset = offsetof(struct mock_pop, ptr);
	UT_ASSERTeq(mock_pop->heap_offset % Ut_pagesize, 0);
	mock_pop->heap_size = MOCK_POOL_SIZE - mock_pop->heap_offset;
	mock_pop->nlanes = 1;
	mock_pop->lanes_offset = sizeof(PMEMobjpool);
	mock_pop->is_master_replica = 1;

	mock_pop->persist_local = (persist_local_fn)pmem_msync;
	mock_pop->flush_local = (flush_local_fn)pmem_msync;
	mock_pop->drain_local = drain_empty;

	mock_pop->p_ops.persist = obj_persist;
	mock_pop->p_ops.flush = obj_flush;
	mock_pop->p_ops.drain = obj_drain;
	mock_pop->p_ops.memcpy_persist = obj_memcpy;
	mock_pop->p_ops.memset_persist = obj_memset;
	mock_pop->p_ops.base = mock_pop;
	mock_pop->p_ops.pool_size = mock_pop->size;

	mock_pop->redo = redo_log_config_new(addr, &mock_pop->p_ops,
			redo_log_check_offset, mock_pop, REDO_NUM_ENTRIES);

	void *heap_start = (char *)mock_pop + mock_pop->heap_offset;
	uint64_t heap_size = mock_pop->heap_size;

	heap_init(heap_start, heap_size, &mock_pop->p_ops);
	heap_boot(&mock_pop->heap, heap_start, heap_size, mock_pop,
			&mock_pop->p_ops);

	/* initialize runtime lanes structure */
	mock_pop->lanes_desc.runtime_nlanes = (unsigned)mock_pop->nlanes;
	lane_boot(mock_pop);

	UT_ASSERTne(mock_pop->heap.rt, NULL);

	test_malloc_free_loop(MALLOC_FREE_SIZE);

	/*
	 * Allocating till OOM and freeing the objects in a loop for different
	 * buckets covers basically all code paths except error cases.
	 */
	test_oom_allocs(TEST_HUGE_ALLOC_SIZE);
	test_oom_allocs(TEST_TINY_ALLOC_SIZE);
	test_oom_allocs(TEST_HUGE_ALLOC_SIZE);
	test_oom_allocs(TEST_SMALL_ALLOC_SIZE);
	test_oom_allocs(TEST_MEGA_ALLOC_SIZE);

	test_realloc(TEST_SMALL_ALLOC_SIZE, TEST_MEDIUM_ALLOC_SIZE);
	test_realloc(TEST_HUGE_ALLOC_SIZE, TEST_MEGA_ALLOC_SIZE);

	lane_cleanup(mock_pop);
	heap_cleanup(&mock_pop->heap);

	FREE(real_address);
}
Esempio n. 13
0
/*
 * Take the amount of memory to allocate in bytes as a command-line argument
 * and call test_malloc with that amount of memory.
 */
int
main(int argc, char *argv[])
{
    size_t size, max;
    size_t limit = 0;
    int willfail = 0;
    unsigned char code;

    if (argc < 3)
        die("Usage error.  Type, size, and limit must be given.");
    errno = 0;
    size = strtol(argv[2], 0, 10);
    if (size == 0 && errno != 0)
        sysdie("Invalid size");
    errno = 0;
    limit = strtol(argv[3], 0, 10);
    if (limit == 0 && errno != 0)
        sysdie("Invalid limit");

    /* If the code is capitalized, install our customized error handler. */
    code = argv[1][0];
    if (isupper(code)) {
        xmalloc_error_handler = test_handler;
        code = tolower(code);
    }

    /*
     * Decide if the allocation should fail.  If it should, set willfail to 2,
     * so that if it unexpectedly succeeds, we exit with a status indicating
     * that the test should be skipped.
     */
    max = size;
    if (code == 's' || code == 'n' || code == 'a' || code == 'v') {
        max += size;
        if (limit > 0)
            limit += size;
    }
    if (limit > 0 && max > limit)
        willfail = 2;

    /*
     * If a memory limit was given and we can set memory limits, set it.
     * Otherwise, exit 2, signalling to the driver that the test should be
     * skipped.  We do this here rather than in the driver due to some
     * pathological problems with Linux (setting ulimit in the shell caused
     * the shell to die).
     */
    if (limit > 0) {
#if HAVE_SETRLIMIT && defined(RLIMIT_AS)
        struct rlimit rl;
        void *tmp;
        size_t test_size;

        rl.rlim_cur = limit;
        rl.rlim_max = limit;
        if (setrlimit(RLIMIT_AS, &rl) < 0) {
            syswarn("Can't set data limit to %lu", (unsigned long) limit);
            exit(2);
        }
        if (size < limit || code == 'r') {
            test_size = code == 'r' ? 10 : size;
            if (test_size == 0)
                test_size = 1;
            tmp = malloc(test_size);
            if (tmp == NULL) {
                syswarn("Can't allocate initial memory of %lu (limit %lu)",
                        (unsigned long) test_size, (unsigned long) limit);
                exit(2);
            }
            free(tmp);
        }
#else
        warn("Data limits aren't supported.");
        exit(2);
#endif
    }

    switch (code) {
    case 'c': exit(test_calloc(size) ? willfail : 1);
    case 'm': exit(test_malloc(size) ? willfail : 1);
    case 'r': exit(test_realloc(size) ? willfail : 1);
    case 's': exit(test_strdup(size) ? willfail : 1);
    case 'n': exit(test_strndup(size) ? willfail : 1);
    case 'a': exit(test_asprintf(size) ? willfail : 1);
    case 'v': exit(test_vasprintf(size) ? willfail : 1);
    default:
        die("Unknown mode %c", argv[1][0]);
        break;
    }
    exit(1);
}
Esempio n. 14
0
void            test_suite_malloc(void)
{
  test_malloc_0();
  test_malloc_atomic();
  test_realloc();
}