Exemplo n.º 1
0
int main(int argc, char *argv[])
{
  int retval = 0;
  int i;

  for (i = 1; argv[i]; i++) {
    if (strcmp(argv[i], "-v") == 0)
      tstflags |= tst_verbatim;
    else if (strcmp(argv[i], "-a") == 0)
      tstflags |= tst_abort;
    else
      usage(1);
  }
#if HAVE_OPEN_C
  tstflags |= tst_verbatim;
#endif

  retval |= test_alloc();
  retval |= test_lock();
  retval |= test_strdupcat();
  retval |= test_sprintf("%s.%s", "foo", "bar");
  retval |= test_strlst();
  retval |= test_vectors();
  retval |= test_auto();

  return retval;
}
Exemplo n.º 2
0
int
main(int argc, char *argv[])
{
	START(argc, argv, "obj_out_of_memory");

	if (argc < 3)
		FATAL("usage: %s size filename ...", argv[0]);

	size_t size = atoll(argv[1]);

	for (int i = 2; i < argc; i++) {
		const char *path = argv[i];

		PMEMobjpool *pop = pmemobj_create(path, LAYOUT_NAME, 0,
					S_IWUSR | S_IRUSR);
		if (pop == NULL)
			FATAL("!pmemobj_create: %s", path);

		test_alloc(pop, size);

		pmemobj_close(pop);

		ASSERTeq(pmemobj_check(path, LAYOUT_NAME), 1);

		ASSERTne(pop = pmemobj_open(path, LAYOUT_NAME), NULL);

		test_free(pop);

		pmemobj_close(pop);
	}

	DONE(NULL);
}
Exemplo n.º 3
0
void *psivshmem_alloc_mem(ivshmem_pci_dev_t *dev, size_t sizeByte)
{
   long n;
   long index;
   long frame_qnt = 0;
   void *ptr = NULL;

    frame_qnt = (sizeByte + (dev->frame_size - 1)) / dev->frame_size;

    pthread_spin_lock(dev->spinlock);

    	index = test_alloc(dev ,frame_qnt);

	DPRINT(5,"ivshmem: psivshmem_alloc_memory: index= %ld\n",index);

	if(index == -1) return ptr;  // error! not enough memory


    	for (n = index; n<index + frame_qnt; n++)
    	{
		SET_BIT(dev->bitmap,n);  //ToDo: maybe possible: macro to set more bits "at once"
		DPRINT(5,"ivshmem: psivshmem_alloc_memory:  <SET_BIT no %ld>\n",n);
	}

    pthread_spin_unlock(dev->spinlock);

    ptr = (void*)(dev->ivshmem_base + (long long)(index * dev->frame_size));

    return ptr;
}
Exemplo n.º 4
0
int
main(int argc, char *argv[])
{
    test_alloc();
    test_draw_when_box_fits_canvas();
    test_alloc_string();
    test_alloc_from_string();
    return EXIT_SUCCESS;
}
Exemplo n.º 5
0
int test_nolld2()
{
  bool pass = true;
  int a = 0;

  a = test_alloc();  // 31
  print_integer(a);  // a = 1
  if (a != 31) pass = false;
  return pass;
}
Exemplo n.º 6
0
int main()
{
    std::srand(static_cast<unsigned>(std::time(0)));

    test();
    test_alloc();
    test_mem_usage();
    test_void();

    return boost::report_errors();
}
void TaObjectPool::replenish (void)
{
	int size = object_size_ * chunk_size_;
	char * start = static_cast<char *>(ap_block_allocator->allocate(size));
	test_alloc(start);
	char * last = &start[(chunk_size_-1) * object_size_];
	for ( char * p = start; p < last; p += object_size_ ) {
		reinterpret_cast<Link *>(p)->p_next = reinterpret_cast<Link *>(p + object_size_);
	}
	reinterpret_cast<Link *>(last)->p_next = 0;
	p_free_list_ = reinterpret_cast<Link *>(start);
}
Exemplo n.º 8
0
int main()
{
	int Error(0);

	Error += test_alloc();
	Error += test_textureCubeArray_textureCube_size();
	Error += test_textureCubeArray_query();
	Error += test_textureCubeArray_textureCube_access();
	Error += clear::run();

	return Error;
}
Exemplo n.º 9
0
int main()
{
	int Error(0);

	Error += test_alloc();
	Error += test_texture3d_size();
	Error += test_texture3d_query();
	Error += test_texture3d_clear();
	Error += test_texture3d_access();

	return Error;
}
Exemplo n.º 10
0
int test_staticlink()
{
  char *ptr = "Hello world!";
  char *np = 0;
  int i = 5;
  unsigned int bs = sizeof(int)*8;
  int mi;
  char buf[80];

  int a = 0;

  a = test_global();  // gI = 100
  printf("global variable gI = %d", a);
  if (a == 100)
    printf(", PASS\n");
  else
    printf(", FAIL\n");
  a = select_1();
  printf("select_1() = %d\n", a); // a = 1
  a = select_2();
  printf("select_2() = %d\n", a); // a = 1
  a = select_3();
  printf("select_3() = %d\n", a); // a = 1
  a = test_select_global_pic(); // test global of pic llc -O1 option
  printf("test_select_global_pic() = %d", a); // a = 100
  if (a == 100)
    printf(", PASS\n");
  else
    printf(", FAIL\n");
  a = test_func_arg_struct();
  a = test_contructor();
  a = test_template();
  printf("test_template() = %d", a); // a = 15
  if (a == 15)
    printf(", PASS\n");
  else
    printf(", FAIL\n");
  a = test_alloc();  // 31
  printf("test_alloc() = %d", a);
  if (a == 31)
    printf(", PASS\n");
  else
    printf(", FAIL\n");
  a = test_inlineasm();
  printf("test_inlineasm() = %d", a); // a = 53
  if (a == 53)
    printf(", PASS\n");
  else
    printf(", FAIL\n");

  return 0;
}
TaObjectPool::TaObjectPool (int object_size, int chunk_size)
:	ap_block_allocator()
,	object_size_( (size_t)object_size >= sizeof(Link) ? object_size : sizeof(Link) )
,	chunk_size_( chunk_size > 0 ? chunk_size : DEFAULT_CHUNK_SIZE )
,	instance_count_(0)
,	p_free_list_(0)
{
	assert( object_size > 0 );
	MemoryBlock * mb = new MemoryBlock();
	test_alloc(mb);
	ap_block_allocator = StrictPointerT<MemoryBlock>(mb);
	assert( ap_block_allocator->valid() );
}
Exemplo n.º 12
0
int main()
{
	int Error(0);

	Error += test_alloc();
	Error += test_texture2d_image_size();
	Error += test_texture2d_query();
	Error += test_texture2d_clear();
	Error += test_texture2d_image_access();
	Error += test_create();
	Error += fetch::test();

	return Error;
}
Exemplo n.º 13
0
int main()
{
	int Error(0);

	Error += loader::test();
	Error += test_alloc();
	Error += test_textureCube_texture2D_size();
	Error += test_textureCube_query();
	Error += test_textureCube_texture2D_access();
	Error += clear::test();
	Error += load_store::test();

	return Error;
}
Exemplo n.º 14
0
static void *test_init_and_alloc(
  uintptr_t alloc_size,
  uintptr_t alignment,
  uintptr_t boundary,
  void *expected_alloc_begin_ptr
)
{
  test_heap_init( TEST_DEFAULT_PAGE_SIZE );

  return test_alloc(
    alloc_size,
    alignment,
    boundary,
    expected_alloc_begin_ptr
  );
}
Exemplo n.º 15
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;
}
Exemplo n.º 16
0
static void
test_dpkg_arch_get_list(void)
{
	struct dpkg_arch *arch;
	int count = 1;

	/* Must never return NULL. */
	arch = dpkg_arch_get_list();
	test_alloc(arch);

	while ((arch = arch->next))
		count++;

	/* The default list should contain 3 architectures. */
	test_pass(count == 3);
}
Exemplo n.º 17
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);
}
Exemplo n.º 18
0
int
main(int argc, char *argv[])
{
	START(argc, argv, "obj_out_of_memory");

	if (argc < 3)
		FATAL("usage: %s size filename ...", argv[0]);

	size_t size = atoll(argv[1]);

	for (int i = 2; i < argc; i++) {
		const char *path = argv[i];

		PMEMobjpool *pop = pmemobj_create(path, LAYOUT_NAME, 0,
					S_IWUSR | S_IRUSR);
		if (pop == NULL)
			FATAL("!pmemobj_create: %s", path);

		test_alloc(pop, size);

		pmemobj_close(pop);

		ASSERTeq(pmemobj_check(path, LAYOUT_NAME), 1);

		/*
		 * To prevent subsequent opens from receiving exactly the same
		 * volatile memory addresses a dummy malloc has to be made.
		 * This can expose issues in which traces of previous volatile
		 * state are leftover in the persistent pool.
		 */
		void *heap_touch = MALLOC(1);

		ASSERTne(pop = pmemobj_open(path, LAYOUT_NAME), NULL);

		test_free(pop);

		pmemobj_close(pop);

		FREE(heap_touch);
	}

	DONE(NULL);
}
Exemplo n.º 19
0
void oom(int testcase, int mempolicy, int lite)
{
	pid_t pid;
	int status;
#if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \
	&& HAVE_MPOL_CONSTANTS
	unsigned long nmask = 2;
#endif

	switch(pid = fork()) {
	case -1:
		tst_brkm(TBROK|TERRNO, cleanup, "fork");
	case 0:
#if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \
	&& HAVE_MPOL_CONSTANTS
		if (mempolicy)
			if (set_mempolicy(MPOL_BIND, &nmask, MAXNODES) == -1)
				tst_brkm(TBROK|TERRNO, cleanup,
					"set_mempolicy");
#endif
		test_alloc(testcase, lite);
		exit(0);
	default:
		break;
	}
	tst_resm(TINFO, "expected victim is %d.", pid);
	if (waitpid(-1, &status, 0) == -1)
		tst_brkm(TBROK|TERRNO, cleanup, "waitpid");

	if (testcase == OVERCOMMIT) {
		if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
			tst_resm(TFAIL, "the victim unexpectedly failed: %d",
				status);
	} else {
		if (!WIFSIGNALED(status) || WTERMSIG(status) != SIGKILL)
			tst_resm(TFAIL, "the victim unexpectedly failed: %d",
				status);
	}
}
Exemplo n.º 20
0
static void
test_fdio_hash(void)
{
	char hash[MD5HASHLEN + 1];
	char *test_file;
	int fd;

	test_file = test_alloc(strdup("test.XXXXXX"));
	fd = mkstemp(test_file);
	test_pass(fd >= 0);

	test_pass(fd_md5(fd, hash, -1, NULL) >= 0);
	test_str(hash, ==, ref_hash_empty);

	test_pass(write(fd, str_test, strlen(str_test)) == strlen(str_test));
	test_pass(lseek(fd, 0, SEEK_SET) == 0);

	test_pass(fd_md5(fd, hash, -1, NULL) >= 0);
	test_str(hash, ==, ref_hash_test);

	test_pass(unlink(test_file) == 0);
}
Exemplo n.º 21
0
int mding_mm_init(void)
{
//	long * mem_map_addr = 0xc0a0a080;
//	struct mm_struct *init_mm_p = 0xc088a1a0;	//addr of init_mm in [arch/x86/kernel/init_task.c]
/*
	struct resource *iomem_resource;

	iomem_resource = 0xc0894140;
	trave_resources(iomem_resource,0);	//test for:test kernel resource tree
*/

	test_page_virtual();
	test_alloc();				//test for:test alloc_page() function and address
/*
	get_all_vm_area(init_mm_p->mmap);	//test for:get all vm area for current process
*/

/*
	trave_process();
	printk("%x\n",(*mem_map_addr));
*/
	return 0;
}
Exemplo n.º 22
0
static void test_heap_allocate(void)
{
  void *p1 = NULL;
  void *p2 = NULL;
  void *p3 = NULL;
  uintptr_t alloc_size = 0;
  uintptr_t alignment = 0;
  uintptr_t boundary = 0;
  uintptr_t page_size = 0;
  uintptr_t first_page_begin = 0;
  uintptr_t previous_last_block_begin = 0;
  uintptr_t previous_last_page_begin = 0;

  uintptr_t last_block_begin = 0;
  uintptr_t last_alloc_begin = 0;

  test_heap_init( TEST_DEFAULT_PAGE_SIZE );

  last_block_begin = (uintptr_t) TestHeap.last_block;
  last_alloc_begin = _Heap_Alloc_area_of_block( TestHeap.last_block );

  puts( "run tests for _Heap_Allocate_aligned_with_boundary()");

  puts( "\tcheck if NULL will be returned if size causes integer overflow" );

  alloc_size = (uintptr_t ) -1;
  alignment = 0;
  boundary = 0;
  test_init_and_alloc( alloc_size, alignment, boundary, NULL );

  puts( "\ttry to allocate more space than the one which fits in the boundary" );

  alloc_size = 2;
  alignment = 0;
  boundary = alloc_size - 1;
  test_init_and_alloc( alloc_size, alignment, boundary, NULL );

  puts( "\tcheck if alignment will be set to page size if only a boundary is given" );

  alloc_size = 1;
  boundary = 1;

  alignment = 0;
  p1 = test_init_and_alloc_simple( alloc_size, alignment, boundary );

  alignment = test_page_size();
  test_init_and_alloc( alloc_size, alignment, boundary, p1 );

  puts( "\tcreate a block which is bigger then the first free space" );

  alignment = 0;
  boundary = 0;

  alloc_size = test_page_size();
  p1 = test_init_and_alloc_simple( alloc_size, alignment, boundary );
  p2 = test_alloc_simple( alloc_size, alignment, boundary );
  rtems_test_assert( p2 );

  test_free( p1 );

  alloc_size = 2 * alloc_size;
  p3 = test_alloc_simple( alloc_size, alignment, boundary );
  rtems_test_assert( p1 != p3 );

  puts( "\tset boundary before allocation begin" );

  alloc_size = 1;
  alignment = 0;
  boundary = last_alloc_begin - test_page_size();
  p1 = test_init_and_alloc_simple( alloc_size, alignment, boundary );
  rtems_test_assert( (uintptr_t ) p1 >= boundary );

  puts( "\tset boundary between allocation begin and end" );
  alloc_size = test_page_size();
  alignment = 0;
  boundary = last_alloc_begin - alloc_size / 2;
  p1 = test_init_and_alloc_simple( alloc_size, alignment, boundary );
  rtems_test_assert( (uintptr_t ) p1 + alloc_size <= boundary );

  puts( "\tset boundary after allocation end" );
  alloc_size = 1;
  alignment = 0;
  boundary = last_alloc_begin;
  p1 = test_init_and_alloc_simple( alloc_size, alignment, boundary );
  rtems_test_assert( (uintptr_t ) p1 + alloc_size < boundary );

  puts( "\tset boundary on allocation end" );
  alloc_size = TEST_DEFAULT_PAGE_SIZE - HEAP_BLOCK_HEADER_SIZE;
  alignment = 0;
  boundary = last_block_begin;
  p1 = (void *) (last_alloc_begin - TEST_DEFAULT_PAGE_SIZE);
  test_init_and_alloc( alloc_size, alignment, boundary, p1);

  puts( "\talign the allocation to different positions in the block header" );

  page_size = sizeof(uintptr_t);
  alloc_size = 1;
  boundary = 0;

  test_heap_init( page_size );

  /* Force the page size to a small enough value */
  TestHeap.page_size = page_size;

  alignment = first_page_begin - sizeof(uintptr_t);
  p1 = test_alloc( alloc_size, alignment, boundary, NULL );

  first_page_begin = ((uintptr_t) TestHeap.first_block ) + HEAP_BLOCK_HEADER_SIZE;
  alignment = first_page_begin + sizeof(uintptr_t);
  p1 = test_alloc( alloc_size, alignment, boundary, NULL );

  first_page_begin = ((uintptr_t) TestHeap.first_block )
	  + HEAP_BLOCK_HEADER_SIZE;
  alignment = first_page_begin;
  p1 = test_alloc_simple( alloc_size, alignment, boundary );

  puts( "\tallocate last block with different boundarys" );
  page_size = TEST_DEFAULT_PAGE_SIZE;
  test_heap_init( page_size );
  previous_last_block_begin = ((uintptr_t) TestHeap.last_block )
	  - TestHeap.min_block_size;
  previous_last_page_begin = previous_last_block_begin
	  + HEAP_BLOCK_HEADER_SIZE;
  alloc_size = TestHeap.page_size - HEAP_BLOCK_HEADER_SIZE;
  alignment = sizeof(uintptr_t);
  boundary = 0;
  p1 = test_alloc( alloc_size, alignment, boundary, (void *) (previous_last_page_begin + sizeof(uintptr_t)));

  test_heap_init( page_size );
  boundary = ((uintptr_t) TestHeap.last_block );
  p1 = test_alloc( alloc_size, alignment, boundary, (void *) previous_last_page_begin );

  puts( "\tbreak the boundaries and aligns more than one time" );

  page_size = CPU_ALIGNMENT * 20;
  alloc_size = page_size / 4;
  alignment = page_size / 5;
  boundary = page_size / 4;
  test_heap_init( page_size );
  p1 = (void *) (_Heap_Alloc_area_of_block( TestHeap.last_block ) - page_size );
  test_alloc( alloc_size, alignment, boundary, p1);

  puts( "\tdifferent combinations, so that there is no valid block at the end" );

  page_size = sizeof(uintptr_t);

  test_heap_init( 0 );

  /* Force the page size to a small enough value */
  TestHeap.page_size = page_size;

  alloc_size = 1;
  alignment = (uintptr_t) TestHeap.last_block;
  boundary = 0;
  p1 = test_alloc( alloc_size, alignment, boundary, NULL );

  boundary = (uintptr_t) TestHeap.last_block;
  p1 = test_alloc( alloc_size, alignment, boundary, NULL );

  alloc_size = 0;
  p1 = test_alloc( alloc_size, alignment, boundary, NULL );

  alloc_size = 1;
  alignment = sizeof(uintptr_t);
  boundary = 0;
  p1 = test_alloc_simple( alloc_size, alignment, boundary );

  puts( "\ttry to create a block, which is not possible because of the alignment and boundary" );

  alloc_size = 2;
  boundary = _Heap_Alloc_area_of_block( TestHeap.first_block )
	  + _Heap_Block_size( TestHeap.first_block ) / 2;
  alignment = boundary - 1;
  p1 = test_init_and_alloc( alloc_size, alignment, boundary, NULL );

  alloc_size = 2;
  alignment = _Heap_Alloc_area_of_block( TestHeap.first_block );
  boundary = alignment + 1;
  p1 = test_init_and_alloc( alloc_size, alignment, boundary, NULL );
}
Exemplo n.º 23
0
int main(void)
{
    test_alloc(0);
    test_alloc(1);
    test_alloc(MY_PAGE_SZ);
    test_alloc(MY_PAGE_SZ-1);
    test_alloc(MY_PAGE_SZ+1);
    test_alloc(HOW_MUCH);
    test_alloc(HOW_MUCH-1);
    test_alloc(HOW_MUCH+1);
    test_alloc(BIG_SIZE);
    test_alloc(BIG_SIZE-1);
    test_alloc(BIG_SIZE+1);
    
    test_alloc_memset(0);
    test_alloc_memset(1);
    test_alloc_memset(MY_PAGE_SZ);
    test_alloc_memset(MY_PAGE_SZ-1);
    test_alloc_memset(MY_PAGE_SZ+1);
    test_alloc_memset(HOW_MUCH);
    test_alloc_memset(HOW_MUCH-1);
    test_alloc_memset(HOW_MUCH+1);
    test_alloc_memset(BIG_SIZE);
    test_alloc_memset(BIG_SIZE-1);
    test_alloc_memset(BIG_SIZE+1);

    return 0;
}
Exemplo n.º 24
0
int main(int argc , char ** argv) {
  
  int_vector_type * int_vector = int_vector_alloc( 0 , 99);
  
  test_abort();
  test_assert_int_equal( -1 , int_vector_index(int_vector , 100));
  test_assert_int_equal( -1 , int_vector_index_sorted(int_vector , 100));

  test_assert_true( int_vector_is_instance( int_vector ));
  test_assert_false( double_vector_is_instance( int_vector ));
  int_vector_iset( int_vector , 2 , 0);       
  int_vector_insert( int_vector , 2 , 77 );   
  int_vector_iset( int_vector , 5 , -10);     
  
  assert_equal( int_vector_iget(int_vector , 0 ) == 99 );
  assert_equal( int_vector_iget(int_vector , 1 ) == 99 );
  assert_equal( int_vector_iget(int_vector , 2 ) == 77 );
  assert_equal( int_vector_iget(int_vector , 3 ) == 00 );
  assert_equal( int_vector_iget(int_vector , 4 ) == 99 );
  assert_equal( int_vector_iget(int_vector , 5 ) == -10 );
  
  {
    int N1 = 100000;
    int N2 = 10*N1;
    int_vector_type * v1 = int_vector_alloc( N1 , 0 );
    int_vector_type * v2;
    int * data1 = int_vector_get_ptr( v1 );
    int_vector_iset( v1 , N1 - 1, 99);

    int_vector_free_container( v1 );
    v2 = int_vector_alloc( N2 , 0 );
    int_vector_iset(v2 , N2 - 1, 77 );
    
    test_assert_int_equal(  data1[N1-1] , 99);
    int_vector_free( v2 );
    free( data1 );
  }                 
  
  
  test_assert_true( int_vector_init_range( int_vector , 100 , 1000 , 115 ) );
  test_assert_int_equal( int_vector_iget( int_vector , 0 ) , 100);
  test_assert_int_equal( int_vector_iget( int_vector , 1 ) , 215);
  test_assert_int_equal( int_vector_iget( int_vector , 2 ) , 330);
  test_assert_int_equal( int_vector_iget( int_vector , 3 ) , 445);
  test_assert_int_equal( int_vector_get_last( int_vector ) , 1000);
  
  test_assert_false( int_vector_init_range( int_vector , 100 , -1000 , 115 ) );
  test_assert_int_equal( int_vector_iget( int_vector , 0 ) , 100);
  test_assert_int_equal( int_vector_iget( int_vector , 1 ) , 215);
  test_assert_int_equal( int_vector_iget( int_vector , 2 ) , 330);
  test_assert_int_equal( int_vector_iget( int_vector , 3 ) , 445);
  test_assert_int_equal( int_vector_get_last( int_vector ) , 1000);

  {
    int_vector_type * v1 = int_vector_alloc(0,0);
    int_vector_type * v2 = int_vector_alloc(0,0);
    int_vector_append(v1 , 10);
    int_vector_append(v1 , 15);
    int_vector_append(v1 , 20);

    int_vector_append(v2 , 1);
    int_vector_append(v2 , 2);
    int_vector_append(v2 , 3);

    int_vector_append_vector( v1 , v2 );
    test_assert_int_equal( int_vector_size( v1 ) , 6 );
    test_assert_int_equal( int_vector_iget (v1 ,  0 ), 10 );
    test_assert_int_equal( int_vector_iget (v1 ,  1 ), 15 );
    test_assert_int_equal( int_vector_iget (v1 ,  2 ), 20 );
                                                               
    test_assert_int_equal( int_vector_iget (v1 ,  3 ), 1 );
    test_assert_int_equal( int_vector_iget (v1 ,  4 ), 2 );
    test_assert_int_equal( int_vector_iget (v1 ,  5 ), 3 );

    int_vector_free( v1 );
    int_vector_free( v2 );
  }
  test_contains();
  test_contains_sorted();
  test_shift();
  test_alloc();
  test_div();
  test_memcpy_from_data();
  test_idel_insert();
  test_del();
  test_range_fill();
  test_iset_block();
  test_resize();
  test_empty();
  test_insert_double();
  exit(0);
}