Skip to content

Commit

Permalink
Almost completed coding for testcases in isprmgr.c
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkhy committed May 2, 2014
1 parent 2f2094e commit 0f417ee
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 14 deletions.
3 changes: 2 additions & 1 deletion nachos/test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,11 @@ start.o: start.s syscall.h
%.coff: %.o $(NLIB)
$(LD) $(LDFLAGS) -o $@ $< start.o -lnachos

test.coff: ./testprj2/exittest.c ./testprj2/loopawhile.c
test.coff: ./testprj2/exittest.c ./testprj2/loopawhile.c ./testprj2/exception.c
$(CC) $(CFLAGS) -c $?
$(LD) $(LDFLAGS) -o exittest.coff exittest.o start.o -lnachos
$(LD) $(LDFLAGS) -o loopawhile.coff loopawhile.o start.o -lnachos
$(LD) $(LDFLAGS) -o exception.coff exception.o start.o -lnachos

isprmgr.coff: ./testprj2/isprmgr.c
$(CC) $(CFLAGS) -c $<
Expand Down
15 changes: 6 additions & 9 deletions nachos/test/out
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
++TESTEXIT: invoke exit
5
++ISPRMGR VAR5: [STARTED]
++ISPRMGR VAR5: invoke exec with unmatched argc
++ISPRMGR VAR5: exec exittest.coff
++ISPRMGR VAR5: invoke exec with unmatched argc when argv varies
++ISPRMGR VAR5: exec exittest.coff
++ISPRMGR VAR5: Retval of exec is 3
++ISPRMGR VAR5: [END] SUCCESS
++ISPRMGR: ARG[1] is 7
++ISPRMGR VAR7: [STARTED]
++ISPRMGR VAR7: exec exception.coff
++ISPRMGR VAR7: [END] FAIL to invoke exec
++ISPRMGR VAR7: Issue join to child with pid= 2
++ISPRMGR VAR7: [ENDED] FAIL
20 changes: 20 additions & 0 deletions nachos/test/testprj2/exception.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*prolog******************************************************************************
*
* cname: loopawhile.c
* desc: Make the code to hit an unhandled exception in VM
* author: thinkhy
* tccall: java nachos.machine.Machine -x exception.coff
*
* env: nachos 5.0j
* compile:test/make
* Change activity:
* $BC,EPT 5/2/2014 - initial release
*************************************************************************************/
#define LOOPTIME (1000L)

void main() {
int i = 0, j = 0;
int s = 0;

s = i / j;
}
74 changes: 71 additions & 3 deletions nachos/test/testprj2/isprmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ int main(int argc, char *argv[]) {
* Var 2 : runs exec multiple times and checks each child gets unique PID
* Var 3 : tests your syscall join to a child
* Var 4 : tests exec with error arguments (e.g. bad file name)
* Var 5 : tests your syscall join to a non-child
* Var 6 : tests your syscall join to a child that caused unhandled exception
* Var 7 : tests that your exit syscall releases all resources
* Var 5: tests exec with error arguments: unmatched argc
* Var 6 : tests your syscall join to a non-child
* Var 7 : tests your syscall join to a child that caused unhandled exception
* Var 8 : tests that your exit syscall releases all resources
*
******************************************************************************************/
int i;
Expand Down Expand Up @@ -170,6 +171,8 @@ void route(int variation, char dbg_flag)
LOG("++ISPRMGR VAR3: [ENDED] FAIL\n");
}

break;

case 4:
/*************************************************************************/
/* */
Expand All @@ -189,6 +192,8 @@ void route(int variation, char dbg_flag)
else
LOG("++ISPRMGR VAR4: [END] FAIL\n");

break;

case 5:
/*************************************************************************/
/* */
Expand Down Expand Up @@ -225,10 +230,73 @@ void route(int variation, char dbg_flag)
else
LOG("++ISPRMGR VAR5: [END] FAIL\n");

break;

case 6:
/*************************************************************************/
/* */
/* Var 6 : tests your syscall join to a non-child */
/* */
/*************************************************************************/
LOG("++ISPRMGR VAR6: [STARTED]\n");

LOG("++ISPRMGR VAR6: Issue join to a non-chold with pid=0\n");
retval = join(0, &exitstatus);
if (retval == 0) {
LOG("++ISPRMGR VAR6: [ENDED] FAIL\n");
break;
}

LOG("++ISPRMGR VAR6: Issue join to myself with pid=1\n");
retval = join(1, &exitstatus);
if (retval == 0) {
LOG("++ISPRMGR VAR6: [ENDED] FAIL\n");
break;
}

LOG("++ISPRMGR VAR6: [ENDED] SUCCESS\n");

case 7:
/*************************************************************************/
/* */
/* Var 7 : tests your syscall join to a child */
/* that caused unhandled exception */
/* */
/*************************************************************************/
LOG("++ISPRMGR VAR7: [STARTED]\n");

executable = "exception.coff";
_argv[0] = executable;
_argv[1] = NULL;
_argc = 1;
LOG("++ISPRMGR VAR7: exec %s\n", executable);
pid[0] = exec(executable, _argc, _argv);
if (pid[0] != 0) {
LOG("++ISPRMGR VAR7: [END] FAIL to invoke exec\n");
}

LOG("++ISPRMGR VAR7: Issue join to child with pid=%d\n", pid[0]);
retval = join(pid[0], &exitstatus);
if (retval == 0) {
LOG("++ISPRMGR VAR7: [ENDED] FAIL\n");
/home/huangye/study/CS162/nachos/test/testprj2 break;
}
else {
LOG("++ISPRMGR VAR7: [ENDED] SUCCESS\n");
}

break;
case 8:
/*************************************************************************/
/* */
/* Var 8: tests that your exit syscall releases all resources */
/* */
/*************************************************************************/
/* TODO: it's difficult to write code for this case */


break;

default:
0;
}
Expand Down
23 changes: 23 additions & 0 deletions nachos/test/testprj2/loopawhile.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*prolog******************************************************************************
*
* cname: loopawhile.c
* desc: loop lots of time. this program will be exec'ed by test cases in isprmgr.c
* author: thinkhy
* tccall: java nachos.machine.Machine -x loopawhile.coff
*
* env: nachos 5.0j
* compile:test/make
* Change activity:
* $BC,EPT 5/2/2014 - initial release
*************************************************************************************/
#define LOOPTIME (1000L)

void main() {
int i = 0, j = 0;
int s = 0;
for (i = 0; i < LOOPTIME; i++) {
for (j = 0; j < LOOPTIME; j++) {
s = s + 100;
}
}
}
2 changes: 1 addition & 1 deletion nachos/userprog/UserKernel.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public void run() {
// [added by hy 12/31/2013]
Lib.debug('a', "Shell program: " + shellProgram);

Lib.assertTrue(process.execute(shellProgram, new String[] {shellProgram, "5" }));
Lib.assertTrue(process.execute(shellProgram, new String[] {shellProgram, "7" }));

KThread.currentThread().finish();
}
Expand Down
3 changes: 3 additions & 0 deletions nachos/userprog/UserProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,9 @@ public void handleException(int cause) {
default:
Lib.debug(dbgProcess, "Unexpected exception: " +
Processor.exceptionNames[cause]);

/* Fix defect by isprmgr, Var7 */
handleExit(-1); /*@BCA*/

This comment has been minimized.

Copy link
@thinkhy

thinkhy May 2, 2014

Author Owner

#3 At here, I meet a design problem ...

Lib.assertNotReached("Unexpected exception");
}
}
Expand Down

0 comments on commit 0f417ee

Please sign in to comment.