Skip to content

Commit

Permalink
Added read count test
Browse files Browse the repository at this point in the history
  • Loading branch information
mina-beiki committed Oct 16, 2021
1 parent cbcb7f0 commit 6c165d7
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 9 deletions.
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ UPROGS=\
_wc\
_zombie\
_sysTest\
_getProcCount\
_getProcCountTest\
_getReadCountTest\

fs.img: mkfs README $(UPROGS)
./mkfs fs.img README $(UPROGS)
Expand Down Expand Up @@ -256,7 +257,8 @@ EXTRA=\
README dot-bochsrc *.pl toc.* runoff runoff1 runoff.list\
.gdbinit.tmpl gdbutil\
sysTest.c\
getProcCount.c\
getProcCountTest.c\
getReadCountTest.c\

dist:
rm -rf dist
Expand Down
2 changes: 1 addition & 1 deletion defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void wakeup(void*);
void yield(void);
int getHelloWorld(void);
int getProcCount(void);
int getReadCount(void);
int getReadCount(int);

// swtch.S
void swtch(struct context**, struct context*);
Expand Down
11 changes: 11 additions & 0 deletions getProcCountTest.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "types.h"
#include "stat.h"
#include "user.h"
#include "fcntl.h"

int main(void)
{
int result = getProcCount();
printf(1, "number of processes = %d\n", result);
exit();
}
3 changes: 2 additions & 1 deletion getProcCount.c → getReadCountTest.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

int main(void)
{
printf(1, "Number of processes: %d", getProcCount);
int result = getReadCount();
printf(1, "Number of reads: %d", result);
exit();
}
8 changes: 6 additions & 2 deletions proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -546,12 +546,16 @@ getProcCount(void)
struct proc *p;
int counter=0;

acquire(&ptable.lock);
for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){
if(p->state != UNUSED){
counter = counter+1;
}
}
release(&ptable.lock);
return counter;
}

int
getReadCount(int readCount)
{
return readCount;
}
4 changes: 2 additions & 2 deletions sysfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "file.h"
#include "fcntl.h"

readCount = 0;
int readCount = 0;

// Fetch the nth word-sized system call argument as a file descriptor
// and return both the descriptor and the corresponding struct file.
Expand Down Expand Up @@ -74,7 +74,7 @@ sys_read(void)
struct file *f;
int n;
char *p;
readCount = readCount + 1;
readCount ++;

if(argfd(0, 0, &f) < 0 || argint(2, &n) < 0 || argptr(1, &p, n) < 0)
return -1;
Expand Down
2 changes: 1 addition & 1 deletion sysproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,5 @@ sys_getProcCount(void)
int
sys_getReadCount(void)
{
return readCount;
return getReadCount(readCount);
}

0 comments on commit 6c165d7

Please sign in to comment.