/** \brief test POSIX malloc ** ** get more memory than available ** **/ void testGetMoreThanAvailable(void) { void * ptr1 = NULL; void * ptr2 = (void *)0x300; /* get more bytes than available */ ptr1 = ciaaPOSIX_malloc(20); ptr2 = ciaaPOSIX_malloc(10000); /** TODO <- Replace with a macro */ TEST_ASSERT_TRUE(NULL != ptr1); TEST_ASSERT_TRUE(NULL == ptr2); }
/** \brief test POSIX malloc ** ** try to get memory ** **/ void testMalloc(void) { void * ptr = NULL; /* get 30 bytes */ ptr = ciaaPOSIX_malloc(30); TEST_ASSERT_TRUE(NULL != ptr); }
void *ciaak_malloc(size_t size) { /* try to alloc memory */ void* ret = ciaaPOSIX_malloc(size); /* kernel memory shall not failed :( */ if (NULL == ret) { ciaaPOSIX_printf("Kernel out of memory :( ...\n"); while(1) { /* TODO perform an kernel panic or like */ } } return ret; }
/*==================[external functions definition]==========================*/ extern ciaaLibs_CircBufType * ciaaLibs_circBufNew(size_t nbytes) { ciaaLibs_CircBufType * ret = NULL; /* check that size is at least 8 and power of 2 */ if ( (nbytes > 7) && (ciaaLibs_isPowerOfTwo(nbytes)) ) { ret = (ciaaLibs_CircBufType *) ciaaPOSIX_malloc(sizeof(ciaaLibs_CircBufType)+nbytes); /* if a valid pointer has been returned */ if (NULL != ret) { /* init the buffer */ ciaaLibs_circBufInit(ret, (void*) ( (intptr_t) ret + sizeof(ciaaLibs_CircBufType) ), nbytes); } } return ret; } /* end ciaaLibs_circBufNew */