Ejemplo n.º 1
0
static int test_mm_macros(void)
{
   memblock_t        mblocks[2] ;
   test_errortimer_t errtimer ;
   size_t            size = SIZEALLOCATED_MM() ;

   // TEST ALLOC_ERR_MM
   memset(mblocks, 255 ,sizeof(mblocks)) ;
   for (unsigned i = 0; i < lengthof(mblocks); ++i) {
      init_testerrortimer(&errtimer, 2, ENOMEM) ;
      TEST(0 == ALLOC_ERR_MM(&errtimer, 32 + 32 * i, &mblocks[i])) ;
      TEST(mblocks[i].addr != 0) ;
      TEST(mblocks[i].size >= 32 + 32 * i) ;
      size += mblocks[i].size ;
      TEST(size == SIZEALLOCATED_MM()) ;
      memblock_t dummy = mblocks[i] ;
      TEST(ENOMEM == ALLOC_ERR_MM(&errtimer, 32 + 32 * i, &dummy)) ;
      TEST(dummy.addr == mblocks[i].addr) ;
      TEST(dummy.size == mblocks[i].size) ;
      TEST(size == SIZEALLOCATED_MM()) ;
   }

   // TEST RESIZE_ERR_MM
   for (unsigned i = 0; i < lengthof(mblocks); ++i) {
      init_testerrortimer(&errtimer, 2, ENOMEM) ;
      size -= mblocks[i].size ;
      TEST(0 == RESIZE_ERR_MM(&errtimer, 1024, &mblocks[i])) ;
      TEST(mblocks[i].addr != 0) ;
      TEST(mblocks[i].size >= 1024) ;
      size += mblocks[i].size ;
      TEST(size == SIZEALLOCATED_MM()) ;
      memblock_t dummy = mblocks[i] ;
      TEST(ENOMEM == RESIZE_ERR_MM(&errtimer, 3000, &dummy)) ;
      TEST(dummy.addr == mblocks[i].addr) ;
      TEST(dummy.size == mblocks[i].size) ;
      TEST(size == SIZEALLOCATED_MM()) ;
   }

   // TEST FREE_ERR_MM
   for (unsigned i = 0; i < lengthof(mblocks); ++i) {
      init_testerrortimer(&errtimer, 1, ENOMEM) ;
      size -= mblocks[i].size ;
      TEST(ENOMEM == FREE_ERR_MM(&errtimer, &mblocks[i])) ;
      TEST(0 == mblocks[i].addr) ;
      TEST(0 == mblocks[i].size) ;
      TEST(size == SIZEALLOCATED_MM()) ;
   }

   return 0 ;
ONERR:
   return EINVAL ;
}
Ejemplo n.º 2
0
int initfiltered_eglconfig(/*out*/eglconfig_t * eglconf, struct opengl_display_t * egldisp, const int32_t config_attributes[], eglconfig_filter_f filter, void * user)
{
   int err;
   EGLint      egl_attrib_list[2*gconfig__NROF];
   EGLConfig * eglconfig = 0;
   memblock_t  mblock;

   err = convertConfigListToEGL_eglconfig(&egl_attrib_list, config_attributes);
   if (err) goto ONERR;

   EGLint      num_config;
   EGLBoolean  isOK = eglChooseConfig( egldisp, egl_attrib_list, 0, 0, &num_config);
   if (!isOK) {
      err = EINVAL;
      goto ONERR;
   }

   // TODO: implement tempstack_memory_allocator
   //       allocate memory from tempstack instead of real stack
   err = ALLOC_ERR_MM(&s_eglconfig_errtimer, sizeof(EGLConfig) * (unsigned)num_config, &mblock);
   if (err) goto ONERR;

   eglconfig = (EGLConfig *) mblock.addr;
   isOK = eglChooseConfig( egldisp, egl_attrib_list, eglconfig, num_config, &num_config);
   if (!isOK) {
      err = EINVAL;
      goto ONERR;
   }

   EGLint i;
   for (i = 0; i < num_config; ++i) {
      EGLint visualid;
      isOK = eglGetConfigAttrib( egldisp, eglconfig[i], EGL_NATIVE_VISUAL_ID, &visualid);
      if (filter(eglconfig[i], visualid, user)) {
         // set out param
         *eglconf = eglconfig[i];
         break;
      }
   }

   (void) FREE_ERR_MM(&s_eglconfig_errtimer, &mblock);

   if (i == num_config) return ESRCH;

   return 0;
ONERR:
   if (eglconfig) (void) FREE_MM(&mblock);
   TRACEEXIT_ERRLOG(err);
   return err;
}
Ejemplo n.º 3
0
static int test_releasemode(void)
{
   test_errortimer_t errtimer;
   memblock_t mblock = memblock_FREE;
   size_t     size   = SIZEALLOCATED_MM();

   // prepare
   init_testerrortimer(&errtimer, 1, ENOMEM);

   // TEST ALLOC_ERR_MM
   TEST(0 == ALLOC_ERR_MM(&errtimer, 64, &mblock));
   TEST(0 != mblock.addr);
   TEST(64 <= mblock.size);
   size += mblock.size;
   TEST(size == SIZEALLOCATED_MM());
   TEST(1 == errtimer.timercount);

   // TEST RESIZE_ERR_MM
   size -= mblock.size;
   TEST(0 == RESIZE_ERR_MM(&errtimer, 1024, &mblock));
   TEST(0 != mblock.addr);
   TEST(1024 <= mblock.size);
   size += mblock.size;
   TEST(size == SIZEALLOCATED_MM());
   TEST(1 == errtimer.timercount);

   // TEST FREE_ERR_MM
   size -= mblock.size ;
   TEST(0 == FREE_ERR_MM(&errtimer, &mblock));
   TEST(0 == mblock.addr);
   TEST(0 == mblock.size);
   TEST(size == SIZEALLOCATED_MM());
   TEST(1 == errtimer.timercount);

   return 0;
ONERR:
   return EINVAL;
}