diff --git a/src/kernel/vm2/tests/Jamfile b/src/kernel/vm2/tests/Jamfile index 2de91efff0..c94243dca7 100644 --- a/src/kernel/vm2/tests/Jamfile +++ b/src/kernel/vm2/tests/Jamfile @@ -10,3 +10,5 @@ BinCommand setup : testSetup.C : root be libvm.so ; BinCommand mmapTest1 : mmapTest1.C : root be libvm.so ; BinCommand mmapTest2 : mmapTest2.C : root be libvm.so ; BinCommand mmapTest3 : mmapTest3.C : root be libvm.so ; +BinCommand createAreaFails : createAreaFails.C : root be libvm.so ; +BinCommand createAreaTestsGood : createAreaTestsGood.C : root be libvm.so ; diff --git a/src/kernel/vm2/tests/createAreaFails.C b/src/kernel/vm2/tests/createAreaFails.C new file mode 100644 index 0000000000..8684584958 --- /dev/null +++ b/src/kernel/vm2/tests/createAreaFails.C @@ -0,0 +1,56 @@ +#include "vmInterface.h" +#include +#include +#include +#include +#include +#include + +vmInterface *vm; + +int main(int argc,char **argv) +{ + void *location; + char *testName; + + location=NULL; + testName="vmInterface construction"; + try { vm = new vmInterface (30); } + catch (const char *t) { error ("Exception thrown in %s! %s\n",testName,t); exit(1); } + + testName="NULL name vm->createArea test"; + try { if (vm->createArea(NULL,1,&location)>=0) throw (testName); else error ("%s passed!\n",testName); } + catch (const char *t) { error ("Exception thrown in %s!\n",t); } + + testName="HUGE name vm->createArea test"; + try { if (vm->createArea("This is a crazy, way too long name that should never, ever be permited to work at any time and under any circumstances!",1,&location)>=0) throw (testName); else error ("%s passed!\n",testName); } + catch (const char *t) { error ("Exception thrown in %s!\n",t); } + + testName="0 page count vm->createArea test"; + try { if (vm->createArea("test",0,&location)>=0) throw (testName); else error ("%s passed!\n",testName); } + catch (const char *t) { error ("Exception thrown in %s!\n",t); } + + testName="page count larger than VM vm->createArea test"; + try { if (vm->createArea("test",131,&location)>=0) throw (testName); else error ("%s passed!\n",testName); } + catch (const char *t) { error ("Exception thrown in %s!\n",t); } + error ("Previous test is expected to fail, until sizing of VM file is worked out\n"); + + testName="page count larger than physical memory vm->createArea test"; + try { if (vm->createArea("test",31,&location,ANY,FULL)>=0) throw (testName); else error ("%s passed!\n",testName); } + catch (const char *t) { error ("Exception thrown in %s!\n",t); } + + testName="clone vm->createArea test"; + try { if (vm->createArea("test",1,&location,CLONE)>=0) throw (testName); else error ("%s passed!\n",testName); } + catch (const char *t) { error ("Exception thrown in %s!\n",t); } + + catch (const char *t) { + error ("Exception thrown! %s\n",t); + exit(1); + } + catch (...) { + error ("Unknown Exception thrown!\n"); + exit(1); + } + + return 0; +} diff --git a/src/kernel/vm2/tests/createAreaTestsGood.C b/src/kernel/vm2/tests/createAreaTestsGood.C new file mode 100644 index 0000000000..7422430a7f --- /dev/null +++ b/src/kernel/vm2/tests/createAreaTestsGood.C @@ -0,0 +1,82 @@ +#include "vmInterface.h" +#include +#include +#include +#include +#include +#include + +vmInterface *vm; +/* - specified address (EXACT) + - base address (BASE) + - kernel address (ANY_KERNEL) + - FULL_LOCK + - CONTIGUOUS + - LAZY_LOCK + - NO_LOCK + - LOMEM + */ + +static void *orig; +void assignAddress(unsigned long a, void *&b) {b=(void *)a;orig=b;} + +int main(int argc,char **argv) +{ + void *location; + char *testName; + + location=NULL; + testName="vmInterface construction"; + try { vm = new vmInterface (60); } + catch (const char *t) { error ("Exception thrown in %s! %s\n",testName,t); exit(1); } + + testName="Specified Address succeeds"; + try {assignAddress(0x14000000,location) ; if (vm->createArea(testName,1,&location,EXACT)<0) throw (testName); + if (location != orig) throw (testName); else error ("%s passed!\n",testName); } + catch (const char *t) { error ("Exception thrown in %s!\n",t); exit(1);} + + testName="Specified Address fails"; // Because we want the same space + try {assignAddress(0x14000000,location) ; if (vm->createArea(testName,1,&location,EXACT)>=0) throw (testName); else error ("%s passed!\n",testName); } + catch (const char *t) { error ("Exception thrown in %s!\n",t); } + + testName="Base Address"; + try {assignAddress(0x12000000,location) ; if (vm->createArea(testName,1,&location,EXACT)<0) throw (testName); + if (location != orig) throw (testName); else error ("%s passed!\n",testName); } + catch (const char *t) { error ("Exception thrown in %s!\n",t); } + + testName="Kernel Address"; + try {assignAddress(0,location) ; if (vm->createArea(testName,1,&location,ANY_KERNEL)<0) throw (testName); + if (location != orig) throw (testName); else error ("%s passed!\n",testName); } + catch (const char *t) { error ("Exception thrown in %s!\n",t); } + + testName="Specified Address ";// This needs more and better testing + try {assignAddress(0,location) ; if (vm->createArea(testName,1,&location,ANY,FULL)<0) throw (testName); else error ("%s passed!\n",testName); } + catch (const char *t) { error ("Exception thrown in %s!\n",t); exit(1);} + + testName="Contiguous Memory "; // This needs more and better testing + try {assignAddress(0,location) ; if (vm->createArea(testName,1,&location,ANY,CONTIGUOUS)<0) throw (testName); else error ("%s passed!\n",testName); } + catch (const char *t) { error ("Exception thrown in %s!\n",t); exit(1);} + + testName="Lazy Lock "; // This needs more and better testing + try {assignAddress(0,location) ; if (vm->createArea(testName,1,&location,ANY,LAZY)<0) throw (testName); else error ("%s passed!\n",testName); } + catch (const char *t) { error ("Exception thrown in %s!\n",t); exit(1);} + + testName="No Lock "; // This needs more and better testing + try {assignAddress(0,location) ; if (vm->createArea(testName,1,&location,ANY,NO_LOCK)<0) throw (testName); else error ("%s passed!\n",testName); } + catch (const char *t) { error ("Exception thrown in %s!\n",t); exit(1);} + + testName="LOMEM "; // This needs more and better testing + try {assignAddress(0,location) ; if (vm->createArea(testName,1,&location,ANY,LOMEM)<0) throw (testName); else error ("%s passed!\n",testName); } + catch (const char *t) { error ("Exception thrown in %s!\n",t); exit(1);} + + catch (const char *t) { + error ("Exception thrown! %s\n",t); + exit(1); + } + catch (...) { + error ("Unknown Exception thrown!\n"); + exit(1); + } + + return 0; +}