예제 #1
0
int test_vheap()
{
  struct pentry *pptr = &proctab[currpid];

  kprintf("\n\nProcess with virtual heap in backing store %d.\n", pptr->store);

  print_free_mem_status();

  int size = 100; // get 100 bytes in the virtual memory
  char *words = vgetmem(size);
  char *words2 = vgetmem(size);
  char *words3 = vgetmem(size);
  char *words4 = vgetmem(size);

  words[0] = 'a'; words[1] = 'b'; words[2] = 'c'; words[3] = '\0';
  words2[0] = 'd'; words2[1] = 'e'; words2[2] = 'f'; words2[3] = 'g'; words2[4] = '\0';

  kprintf("0x%08x: %s\n", (unsigned)words, words);
  kprintf("0x%08x: %s\n", (unsigned)words2, words2);

  print_free_mem_status();

  vfreemem(words, size);
  print_free_mem_status();

  vfreemem(words3, size);
  print_free_mem_status();

  char *words5 = vgetmem(8000);

  words5[4095] = 'h'; words5[4096] = 'i'; words5[4097] = 'j'; words5[4098] = '\0';

  kprintf("0x%08x: %s\n", (unsigned)&words5[4095], &words5[4095]);

  vfreemem(words4, size);
  print_free_mem_status();

  vfreemem(words2, size);
  print_free_mem_status();


  vfreemem(words5, 8000);
  print_free_mem_status();

  char *words6 = vgetmem(200 * 4096);
  kprintf("#################checking for large space allocation \n");
  if (words6 == SYSERR) {
    kprintf("ERROR: cannot malloc space in virtual heap, the size to get is too large!\n");
    return 0;
  }

  words6[10*4096] = 'k'; words6[10*4096 + 1] = '\0';

  kprintf("0x%08x: %s\n", (unsigned)&words6[10*4096], &words[10*4096]);
  print_free_mem_status();

  return 0;
}
예제 #2
0
void badAccessTest(){
	int *x;
	x= vgetmem(sizeof(int));
	*x=123;
	kprintf("Value @ 0x%08x = %d\n",x,*x);
	vfreemem(x,sizeof(int));
	x= vgetmem(sizeof(int));
	x += 10*NBPG;
	*x = 432;
  kprintf("THIS should NOT print. Process Should have been killed\n");
	vfreemem(x,sizeof(int));
}
예제 #3
0
void test_free_mem(char *name, char *arg){
	kprintf("executing %s\n", name);
	kprintf("before getting memory\n");
	print_free_mem_status();
	kprintf("getting memory\n");
	int *x = vgetmem(1000);
	kprintf("freeing the memory \n");
	vfreemem(x, 1000);
	print_free_mem_status();
}
예제 #4
0
파일: main.c 프로젝트: pvthakka/XINU
proc_vcreate(char c) {
	//kprintf("\nInside proc\n");
	/*char *count = (char *)vgetmem(sizeof(char));
	//char count = 'A';
	*count = 'A';
	kprintf("\ncount is %d %c\n",count, *count);

	vfreemem(count, sizeof(char));

	count = (char *)vgetmem(sizeof(char));
	*count = 'B';
	kprintf("\ncount is %d %c\n",count, *count);

	vfreemem(count, sizeof(char));

	long int *ptr = (long int *)vgetmem(sizeof(long));
	*ptr = 34943743;
	kprintf("\nptr is %d %ld\n",ptr, *ptr);

	vfreemem(count, sizeof(long int));*/
	
	int i = 0;
	node *pt = (node *)vgetmem(sizeof(node));
	node *temp;
	while(pt != NULL)
	{
		pt->one = 1234+i;
		pt->two = 6789+i;
		pt->three = 356+i;
		pt->four = 'A'+i;
		//kprintf("\npt is %d, %ld, %ld, %d, %c\n",pt, pt->one, pt->two, pt->three, pt->four);
		i++;
		temp = pt;
		pt = (node *)vgetmem(sizeof(node));
	}

	kprintf("\n\nTest result %d. Should be 12800.",i);

	vfreemem(temp, sizeof(node));

	char *count = (char *)vgetmem(sizeof(char));
	if(count != NULL)
		kprintf("\n\nVFREEMEM working properly");
	else
		kprintf("\n\nVFREEMEM failed");

	pt = (node *)vgetmem(sizeof(node));
	if(pt == NULL)
		kprintf("\n\nVGETMEM boundary check passed");
	else
		kprintf("\n\nVGETMEM boundary check failed");
	
	kill(currpid);
}
예제 #5
0
void proc1_test2(char *msg, int lck) {
  int *x;

  kprintf("ready to allocate heap space\n");
  x = vgetmem(1024);
  kprintf("heap allocated at %x\n", x);
  *x = 100;
  *(x + 1) = 200;

  kprintf("heap variable: %d %d\n", *x, *(x + 1));
  vfreemem(x, 1024);
}
예제 #6
0
파일: main.c 프로젝트: mclarenrulz/csc501
int processVA() {
	kprintf("processVA lives\n");
	int *x;
	int temp;
	x = vgetmem(1000);  /* allocates some memory in the virtual heap which is in virtual memory */
	*x = 100;
	x++;
	*x = 200;
	temp = *x;  /* You are reading back from virtual heap to check if the previous write was successful */
	kprintf("data in virt mem of processVA = %d\n", temp);
   temp = vfreemem(--x, 1000); /* frees the allocation in the virtual heap */
   kprintf("vfree return %d\n", temp);
	return 0;
}
예제 #7
0
void test_zero_vgetmem(char *name){
	kprintf("\n testing vcreate \n");
		int *x;
		int temp;
		kprintf("\ngetting memory\n");
		x = vgetmem(0); /* allocates some memory in the virtual heap which is in virtual memory */
		/* the following  statement will cause a page fault. The page fault handling routing  will read in the required page from backing store into the main memory, set the proper page tables and the page directory entries and reexecute the statement. */
		*x = 100;
		x++;
		*x = 200;
		temp = *x; /* You are reading back from virtual heap to check if the previous write was successful */
		kprintf("data read from virtual heap = %d\n", temp);
		kprintf("\nfreeing memory through vgetmem\n");
		vfreemem(--x, 1000); /* frees the allocation in the virtual heap */
}
예제 #8
0
/*-------------------------------------------------------------------------------------*/
void proc1_test5(int* ret) {
  int *x;
  int *y;
  int *z;

  //kprintf("ready to allocate heap space\n");
  x = vgetmem(1024);
  if ((x == NULL) || (x < 0x1000000)
      || (x > 0x1000000 + 128 * NBPG - 1024)) {
    *ret = TFAILED;
  }
  if (x == NULL)
    return;

  *x = 100;
  *(x + 1) = 200;

  if ((*x != 100) || (*(x+1) != 200)) {
    *ret = TFAILED;
  }
  vfreemem(x, 1024);

  x = vgetmem(129*NBPG); //try to acquire a space that is bigger than size of one backing store
  if (x != NULL) {
    *ret = TFAILED;
  }

  x = vgetmem(50*NBPG);
  y = vgetmem(50*NBPG);
  z = vgetmem(50*NBPG);
  if ((x == NULL) || (y == NULL) || (z != NULL)){
    *ret = TFAILED;
    if (x != NULL) vfreemem(x, 50*NBPG);
    if (y != NULL) vfreemem(y, 50*NBPG);
    if (z != NULL) vfreemem(z, 50*NBPG);
    return;
  }
  vfreemem(y, 50*NBPG);
  z = vgetmem(50*NBPG);
  if (z == NULL){
    *ret = TFAILED;
  }
  if (x != NULL) vfreemem(x, 50*NBPG);
  if (z != NULL) vfreemem(z, 50*NBPG);
  return;


}
예제 #9
0
//////////////////////////////////////////////////////////////////////////
//  vheap_test
//////////////////////////////////////////////////////////////////////////
void vheaptask() {
    int i,x;
    char * str;
    char * pass = "******";
    char * fail = "FAIL";

    // Values for proc structure
    char pstate = 'Z';
    int pprio   = 100;
    int pesp    = 45;


    // Values for bs_map_t structure
    int pid    = 99;
    int npages = 32;
    int vpno   = 4200;

    // Values for frame_t structure
    int status = 75;
    int type   = 1;
    int refcnt = 7200;

    // Create a proc structure.. populate some print it out
    kprintf("Allocating pentry structure\n\n");
    struct pentry * pptr;
    pptr = vgetmem(sizeof(struct pentry));
    if (pptr == SYSERR) {
        kprintf("Could not allocate mem for pentry");
        return;
    }
    kprintf("Mem for pentry structure: 0x%08x\n", pptr);
    pptr->pstate = pstate;
    pptr->pprio  = pprio;
    pptr->pesp   = pesp;

    str = (pptr->pstate == pstate) ? pass : fail;
    kprintf("task1: UT1 pptr->pstate: \t%s\n", str);

    str = (pptr->pprio == pprio) ? pass : fail;
    kprintf("task1: UT2 pptr->pprio: \t%s\n", str);

    str = (pptr->pesp == pesp) ? pass : fail;
    kprintf("task1: UT3 pptr->pesp: \t%s\n", str);

    kprintf("\n\n");




    // Create a bs_map_t structure.. populate some print it out
    kprintf("Allocating bs_map_t structure\n\n");
    bs_map_t * bsmptr;
    bsmptr = vgetmem(sizeof(bs_map_t));
    if (bsmptr == SYSERR) {
        kprintf("Could not allocate mem for bs_map_t");
        return;
    }
    kprintf("Mem for bs_map_t structure: 0x%08x\n", bsmptr);
    bsmptr->pid    = pid;
    bsmptr->npages = npages;
    bsmptr->vpno   = vpno;

    str = (bsmptr->pid == pid) ? pass : fail;
    kprintf("task1: UT4 bsmptr->pid: \t%s\n", str);

    str = (bsmptr->npages == npages) ? pass : fail;
    kprintf("task1: UT5 bsmptr->npages: \t%s\n", str);

    str = (bsmptr->pid == pid) ? pass : fail;
    kprintf("task1: UT6 bsmptr->vpno: \t%s\n", str);

    kprintf("\n\n");



    // Free the proc structure
    kprintf("Freeing pentry structure\n\n");
    vfreemem((struct mblock *)pptr, sizeof(struct pentry));
    kprintf("\n\n");




    // Create a frame_t structure
    kprintf("Allocating frame_t structure\n\n");
    frame_t * frame;
    frame = vgetmem(sizeof(frame_t));
    if (frame == SYSERR) {
        kprintf("Could not allocate mem for frame_t");
        return;
    }
    kprintf("Mem for frame_t structure: 0x%08x\n", frame);
    frame->status = status;
    frame->type   = type;
    frame->refcnt = refcnt;

    str = (frame->status == status) ? pass : fail;
    kprintf("task1: UT7 frame->status: \t%s\n", str);

    str = (frame->type == type) ? pass : fail;
    kprintf("task1: UT8 frame->type: \t%s\n", str);

    str = (frame->refcnt == refcnt) ? pass : fail;
    kprintf("task1: UT9 frame->refcnt: \t%s\n", str);

    kprintf("\n\n");




    // Test the bs_map_t structure
    str = (bsmptr->pid == pid) ? pass : fail;
    kprintf("task1: UT10 bsmptr->pid: \t%s\n", str);

    str = (bsmptr->npages == npages) ? pass : fail;
    kprintf("task1: UT11 bsmptr->npages: \t%s\n", str);

    str = (bsmptr->pid == pid) ? pass : fail;
    kprintf("task1: UT12 bsmptr->vpno: \t%s\n", str);

    kprintf("\n\n");


    // Create a proc structure.. populate some print it out
    kprintf("Allocating pentry structure\n\n");
    struct pentry * pptr2;
    pptr2 = vgetmem(sizeof(struct pentry));
    if (pptr2 == SYSERR) {
        kprintf("Could not allocate mem for pentry");
        return;
    }
    kprintf("Mem for pentry structure: 0x%08x\n", pptr2);
    pptr2->pstate = pstate;
    pptr2->pprio  = pprio;
    pptr2->pesp   = pesp;

    str = (pptr2->pstate == pstate) ? pass : fail;
    kprintf("task1: UT13 pptr2->pstate: \t%s\n", str);

    str = (pptr2->pprio == pprio) ? pass : fail;
    kprintf("task1: UT14 pptr2->pprio: \t%s\n", str);

    str = (pptr2->pesp == pesp) ? pass : fail;
    kprintf("task1: UT15 pptr2->pesp: \t%s\n", str);

    kprintf("\n\n");



    // Free the bsmptr structure
    kprintf("Freeing bsmptr structure\n\n");
    vfreemem((struct mblock *)pptr, sizeof(bs_map_t));
    kprintf("\n\n");



    // Create a proc structure.. populate some print it out
    kprintf("Allocating pentry structure\n\n");
    struct pentry * pptr3;
    pptr3 = vgetmem(sizeof(struct pentry));
    if (pptr3 == SYSERR) {
        kprintf("Could not allocate mem for pentry");
        return;
    }
    kprintf("Mem for pentry structure: 0x%08x\n", pptr3);
    pptr3->pstate = pstate;
    pptr3->pprio  = pprio;
    pptr3->pesp   = pesp;

    str = (pptr3->pstate == pstate) ? pass : fail;
    kprintf("task1: UT16 pptr3->pstate: \t%s\n", str);

    str = (pptr3->pprio == pprio) ? pass : fail;
    kprintf("task1: UT17 pptr3->pprio: \t%s\n", str);

    str = (pptr3->pesp == pesp) ? pass : fail;
    kprintf("task1: UT18 pptr3->pesp: \t%s\n", str);

    kprintf("\n\n");





    // Final Tests.. So here is what we had:
    //  1. pptr =  vgetmem(sizeof(struct pentry *)
    //      -> Gets the first address (4096*NBPG)
    //  2. bsmptr = vgetmem(sizeof(bs_map_t)
    //      -> Gets addr immediately following
    //  3. vfreemem(pptr)
    //  4. frame = vgetmem(sizeof(frame_t)
    //      -> Since smaller -> Gets slot that pptr occupied
    //  5. pptr2 =  vgetmem(sizeof(struct pentry *)
    //      -> Gets address after frame
    //  6. vfreemem(bsmptr)
    //  5. pptr3 =  vgetmem(sizeof(struct pentry *)
    //      -> Since larger than bsmptr cannot occupy that space
    //      -> Gets address at end.
    //
    str = (pptr == 4096*NBPG) ? pass : fail;
    kprintf("task1: UT19 pptr mem: \t%s\n", str);

    x  = 4096*NBPG; 
    x += (int)roundmb(sizeof(struct pentry)); 
    x += (int)roundmb(sizeof(bs_map_t));
    str = (pptr2 == x) ? pass : fail;
    kprintf("task1: UT20 pptr2 mem: \t%s\n", str);

    x  = 4096*NBPG; 
    x += 2*(int)roundmb(sizeof(struct pentry)); 
    x += (int)roundmb(sizeof(bs_map_t));
    str = (pptr3 == x) ? pass : fail;
    kprintf("task1: UT21 pptr3 mem: \t%s\n", str);

    x = 4096*NBPG + sizeof(struct pentry);
    str = (bsmptr == x) ? pass : fail;
    kprintf("task1: UT22 bsmptr mem: \t%s\n", str);

    str = (frame == 4096*NBPG) ? pass : fail;
    kprintf("task1: UT23 frame mem: \t%s\n", str);


}
예제 #10
0
파일: main.c 프로젝트: dichen001/CSC501
void proc1_test2() {
	kprintf("\nRuning proc1_test2() \n\n");
	int i,temp;
	i = 0;
	kprintf("&i = %8x, i = %d\n",&i,i);
	
	int *y;
	struct	mblock	*x;
	
	kprintf("************************************\n");
	x = vgetmem(1000);
	//x= (struct	mblock *)x;
	kprintf("x=%8x \t x->mnext=%8x \t x->mlen=%d\n",x,x->mnext,x->mlen);
	y=x;
	kprintf("&y=%x y=%x *y=%d\n",&y,y,*y);
	*y = 100; 
	kprintf("&y=%x y=%x *y=%d\n",&y,y,*y);
    y++; 
    kprintf("&y=%x y=%x *y=%d\n",&y,y,*y);
    *y = 200; 
    kprintf("&y=%x y=%x *y=%d\n",&y,y,*y);
    temp = *y; 
    kprintf("temp=%d\n",temp);
	kprintf("####################################\n");
	vfreemem(--y,1000);
	kprintf("\n vfreemem(x,1000); \n\n");
	
	/*
	kprintf("************************************\n");
	x = vgetmem(1000);
	kprintf("####################################\n");
	vfreemem(x,500);
	kprintf("\n freemem(x,500); \n\n");
	
	kprintf("************************************\n");
	x = vgetmem(1000);
	kprintf("####################################\n");
	vfreemem(x+500,500);
	kprintf("\n freemem(x+500,500); \n\n");
	*/

	kprintf("************************************\n");
	i = get_bs(4, 100); 
	kprintf("i=%d\n",i);
	kprintf("####################################\n");
	
	xmmap(7000,4,100);
	char *addr =7000*4096;
	kprintf("&addr=%x addr=%x *addr=%c\n",&addr,addr,*addr);
	*addr = 'Y';
	kprintf("&addr=%x addr=%x *addr=%c\n",&addr,addr,*addr);
	char tem = *addr;
	kprintf("tem=%c\n",tem);

	xmunmap(7000);
	release_bs(4);
	kprintf("************************************\n");

	/*
	  int *x;

	  kprintf("ready to allocate heap space\n");
	  x = vgetmem(1024);
	  kprintf("heap allocated at %x\n", x);
	  *x = 100;
	  *(x + 1) = 200;

	  kprintf("heap variable: %d %d\n", *x, *(x + 1));
	  vfreemem(x, 1024);
	*/
}
예제 #11
0
void peakLoadTest(int pIdx){
	char *x,*y;
	int i,mypno,m;
	get_bs(15,128);
	mypno = PEAK_VPNO - pIdx;
	//kprintf("get_bs DOne pIdx=%d currpid=%d\n",pIdx,currpid);
	x = vgetmem(128*NBPG);
	//kprintf("vgetmem DOne pIdx=%d currpid=%d x=%x-%x\n",pIdx,currpid, x, x+128*NBPG);
	xmmap(mypno,15,128);
	//kprintf("xmmap DOne pIdx=%d currpid=%d\n",pIdx,currpid);
#if 1
	for(i=0; i<128; i++) {
		x[i] = (char) (pIdx + i);
    //print_PA(x);
		x[i+NBPG-1] = (char) (pIdx*2 +i);
#if 0
    i++;
    x[i] = (char) (pIdx + i);
		x[i+NBPG-1] = (char) (pIdx*2 +i);
    i++;
    x[i] = (char) (pIdx + i);
		x[i+NBPG-1] = (char) (pIdx*2 +i);
    i++;
    x[i] = (char) (pIdx + i);
		x[i+NBPG-1] = (char) (pIdx*2 +i);

    i++;
    x[i] = (char) (pIdx + i);
		x[i+NBPG-1] = (char) (pIdx*2 +i);
    //print_PA(x+i);
#endif

    //sleep(20);
    //kprintf(" writing to %x %x\n", (unsigned int)&x[i], (unsigned int)&x[i+NBPG-1]);
		if(i%15 == pIdx && i!=127) {
			*(char *)( (mypno + i)*NBPG ) = (char) (pIdx+3);
			*(char *)( (mypno + i)*NBPG + NBPG -1) = (char) (pIdx+4);
		}
	}
#endif
	kprintf("Writing DOne pIdx=%d currpid=%d\n",pIdx,currpid);
	xmunmap(mypno);
	//kprintf("Unmap DOne pIdx=%d currpid=%d\n",pIdx,currpid);
	sleep(20);
	//kprintf("Wake DOne pIdx=%d currpid=%d\n",pIdx,currpid);
	mypno--;
	xmmap(mypno,15,128);
#if 1

	xmunmap(mypno);
	sleep(20);
	mypno--;
	xmmap(mypno,15,128);
	y= (char *)((mypno)*NBPG );
	for(i=0; i<128; i++){
		if(x[i] != (char) (pIdx + i) ) kprintf("pIdx=%d Test Fail. x[%d] did not match\n",pIdx, i);
		if(x[i+NBPG-1] != (char) (pIdx*2 + i) ) kprintf("pIdx=%d Test Fail. x[%d] did not match\n",pIdx, i+NBPG-1);
		if(i!=127) {
			m=i%15;
			if( y[i*NBPG] != (char) (m+3) ) kprintf("pIdx=%d Test Fail. y[%d] at i=%d did not match.\n", pIdx, i*NBPG, i);
			if( y[i*NBPG + NBPG -1 ] != (char) (m+4) ) kprintf("pIdx=%d Test Fail. y[%d] at i=%d did not match\n", pIdx, i*NBPG + NBPG -1, i);
		}
	}
	i = NBPG*128 -1;
	if( y[i] != 'L' ) kprintf("pIdx=%d mypno=%x Test Fail. y[0x%08x]=%d (@ 0x%08x )is not L (%d) \n", pIdx,mypno,i,y[i],&y[i],'L');
	kprintf("peakLoadTest pIdx=%d finished. If no errors have been printed yet, it is a pass.\n",pIdx);
#endif
	xmunmap(mypno);
	vfreemem(x,128*NBPG);
	sleep(10);
	release_bs(15);
}
예제 #12
0
void memTest(char *msg, int a, int b, char *string){
	int i,sum,exp;
	int *x,*y;
#if 1
	kprintf("Let's check one allocation\n");
	x = vgetmem(1);
	if(x != SYSERR) {
		kprintf("heap allocated at %x =  %d -before\n", x, *x);
		*x = 100;
		kprintf("heap allocated at %x =  %d -after\n", x, *x);
		vfreemem(x,1);
	}


	kprintf("\nLet's check one page allocation.\n");
	x = vgetmem(NBPG);
	if(x != SYSERR) {
		kprintf("heap allocated at %x\n", x);
		for(i=0,sum=0,exp=0; i<1024; i++) { x[i] = i; sum+=x[i]; exp+=i; }
		if(sum != exp) { kprintf("Sum mismatch. Test FAIL\n"); }
		else kprintf("Initial sum = %d, exp = %d. Test PASS\n",sum,exp);
		vfreemem(x,NBPG);
	}

	kprintf("\nLet's check 2 page allocation with non-multiple size.\n");
	x = vgetmem(1000*4);
	y = vgetmem(1000*4);
	if(x != SYSERR && y!=SYSERR) {
		kprintf("heap allocated at %x and %x\n", x, y);
		for(i=0,sum=0,exp=0; i<1000; i++) { x[i] = i; y[i]=i*2; sum+=x[i]+y[i]; exp+=i*3; }
		if(sum != exp) { kprintf("Sum mismatch. Test FAIL\n"); }
		else kprintf("Initial sum = %d, exp = %d. Test PASS\n",sum,exp);
	}
	if(x != SYSERR) {  vfreemem(x,1000*4); }
	if(y != SYSERR) {  vfreemem(y,1000*4); }

	kprintf("\nLet's check full allocation.\n");
	x = vgetmem(2*NBPG);
  if(x != SYSERR) {
    kprintf("heap allocated at %x\n", x);
    for(i=0,sum=0,exp=0; i<(2*NBPG)/4; i++) { x[i] = i; sum+=x[i]; exp+=i; }
    if(sum != exp) { kprintf("Sum mismatch. Test FAIL\n"); }
    else kprintf("Initial sum = %d, exp = %d. Test PASS\n",sum,exp);
    if(vfreemem(x,8193) == SYSERR){
      vfreemem(x,2*NBPG);
      kprintf("Doing illegal free check: Test PASS\n");
    } else {
      kprintf("Too many data elements freed: Test FAIL\n");
    }
  }

	kprintf("\nLet's ask for extra space. Check for SYSERR\n");
	x = vgetmem(8193);
	if(x != SYSERR) {
		kprintf("ERROR: Too many data elements mapped\n");
		kprintf("heap allocated at %x\n", x);
		vfreemem(x,8193);
	} else {
		kprintf("Warning of Insufficient space should have printed. Test PASS\n");
	}

#endif
	//kprintf("\nMulti arg check: %d %d %s \n",a,b,string);
}