/* Tests to allocate and free memory */
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>

#include <ios.h>
#include <iostypes.h>
#define NUM_ITER 3
#include <errno.h>

#define STACK_SIZE 16*1024
void
mem(u32 id)
{
  u32 *tst;
  int i = 0;
  for ( i = 0; i < 10; ++i ) {
    tst = IOS_Alloc(STACK_SIZE/4096);
    printf("itr[%d]:allocated %d pages\n", i, STACK_SIZE/4096);
    if (NULL != tst) 
      IOS_Free(tst);
    printf("itr[%d]:freed %d pages\n", i, STACK_SIZE/4096);
  }
  tst = IOS_Alloc(STACK_SIZE/4096);
  tst = IOS_Alloc(STACK_SIZE/4096);
  tst = IOS_Alloc(STACK_SIZE/4096);
  IOS_Free( (tst + 2*1024));
  IOS_DebugMemDump();
  IOS_ThreadExit(0);
}
