Moved Tests

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2398 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Michael Phipps 2003-01-10 01:20:51 +00:00
parent f767d0eeab
commit 8bd24c033e
9 changed files with 757 additions and 0 deletions

View File

@ -0,0 +1,11 @@
SubDir OBOS_TOP src kernel vm2 tests ;
UseHeaders .. ;
BinCommand vmTest : test.C : root be libvm.so ;
BinCommand olTest : olTest.C : root be libvm.so ;
BinCommand hashTest : hashTest.C : root be libvm.so ;
BinCommand pmTest : pageManTest.C : root be libvm.so ;
BinCommand simpleTest : simpleTest.C : root be libvm.so ;
BinCommand setup : testSetup.C : root be libvm.so ;
BinCommand mmapTest1 : mmapTest1.C : root be libvm.so ;
BinCommand mmapTest2 : mmapTest2.C : root be libvm.so ;

View File

@ -0,0 +1,122 @@
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include "hashTable.h"
#include "OS.h"
#include "vmInterface.h"
vmInterface vm(30);
struct hashTest : public node {
hashTest(int i) {value=i;}
int value;
};
ulong hash(node &a) {
hashTest &a1=reinterpret_cast<hashTest &>(a);
return a1.value;
}
bool isEqual (node &a,node &b) {
hashTest &a1=reinterpret_cast<hashTest &>(a);
hashTest &b1=reinterpret_cast<hashTest &>(b);
return (a1.value==b1.value);
}
int main(int argc,char **argv) {
// Test 1 - Try to add to foo without setting an isLessThan function
try {
hashTable foo(40);
node tmp;
foo.add(&tmp);
}
catch (const char *badness)
{
if (strcmp(badness,"Attempting to use a hash table without setting up a 'hash' function"))
error ("Failure on adding with no hash, error = %s\n", badness);
error ("Success on adding with no hash, \n" );
}
catch(...)
{
error ("Failure on adding with no hash, unknown exception\n");
}
hashTable *moo;
moo=new hashTable(20);
hashTable &foo=*moo;
foo.setHash(hash);
foo.setIsEqual(isEqual);
error ("Add the first couple, in order (easy)\n");
hashTest first(1);
foo.add(&first);
hashTest second(2);
foo.add(&second);
foo.dump();
error ("Add the next three, not in order (harder)\n");
hashTest third(3);
hashTest fourth(4);
hashTest fifth(5);
foo.add(&fourth);
foo.add(&third);
foo.add(&fifth);
foo.dump();
error ("Create bar, populated with 1000 values");
hashTable bar(200);
bar.setHash(hash);
bar.setIsEqual(isEqual);
for (int a=0;a<100;a++)
bar.add(new hashTest(a));
for (int a=999;a>=100;a--)
bar.add(new hashTest(a));
bar.dump();
error ("Removing simple case: remove 1,leave 2,3,4,5 \n");
foo.remove(&first);
foo.dump();
error ("Removing simple case: remove 2,leave 3,4,5 \n");
foo.remove(&second);
foo.dump();
error ("Setting up middle case (reading 1 and 2)\n");
foo.add(&first);
foo.add(&second);
foo.dump();
error ("Removing middle case (removing 2)\n");
foo.remove(&second);
foo.dump();
error ("Removing middle case (removing 1)\n");
foo.remove(&first);
foo.dump();
error ("Finding 1\n");
hashTest findOne(1);
hashTest *found=(hashTest *)bar.find(&findOne);
error ("found value = %d\n",found->value);
error ("Finding 77\n");
hashTest findSeventySeven(77);
hashTest *found77=(hashTest *)bar.find(&findSeventySeven);
error ("found value = %d\n",found77->value);
error ("ensuringSane on smaller (foo) = %s\n",((foo.ensureSane())?"OK":"BAD!"));
error ("ensuringSane on larger (bar) = %s\n",((bar.ensureSane())?"OK":"BAD!"));
int count=0;
for (hashIterate hi(bar);node *next=hi.get();) {
count++;
if (next==NULL)
error ("Found a NULL at %d\n",count);
}
if (count==1000)
error ("found 1000, as expected!\n");
else
error ("did NOT find 1000, as expected, found %d!\n",count);
delete moo;
return 0;
}

View File

@ -0,0 +1,46 @@
#include "vmInterface.h"
#include <stdio.h>
#include <unistd.h>
#include <mman.h>
#include <errno.h>
#include <string.h>
vmInterface *vm;
void writeByte(unsigned long addr,unsigned int offset, char value) { vm->setByte(addr+offset,value); }
unsigned char readByte(unsigned long addr,unsigned int offset ) { char value=vm->getByte(addr+offset); return value; }
int main(int argc,char **argv)
{
try {
vm = new vmInterface (30);
error ("Starting Threads!\n");
int myfd=open("mmap_test_1_file",O_RDWR|O_CREAT,0707);
error ("error = %s\n",strerror(errno));
/*
close (myfd);
return 0;
*/
unsigned long result=(unsigned long)(vm->mmap(NULL,16384,PROT_WRITE|PROT_READ,MAP_SHARED,myfd,0));
for (int i=0;i<16384;i++)
writeByte(result,i,'A');
for (int i=0;i<16384;i++)
if ('A' != readByte(result,i))
error ("Non matching byte %c at offset %d");
vm->munmap((void *)result,16384);
close (myfd);
}
catch (const char *t)
{
error ("Exception thrown! %s\n",t);
exit(1);
}
catch (...)
{
error ("Unknown Exception thrown!\n");
exit(1);
}
return 0;
}

View File

@ -0,0 +1,57 @@
#include "vmInterface.h"
#include <stdio.h>
#include <unistd.h>
#include <mman.h>
#include <errno.h>
#include <string.h>
vmInterface *vm;
void writeByte(unsigned long addr,unsigned int offset, char value) { vm->setByte(addr+offset,value); }
unsigned char readByte(unsigned long addr,unsigned int offset ) { char value=vm->getByte(addr+offset); return value; }
int main(int argc,char **argv)
{
try {
vm = new vmInterface (90);
int myfd=open("mmap_test_2_file",O_RDWR|O_CREAT,0707);
if (myfd==-1)
error ("file opening error = %s\n",strerror(errno));
unsigned long result=(unsigned long)(vm->mmap(NULL,32768,PROT_WRITE|PROT_READ,MAP_SHARED,myfd,0));
for (int i=0;i<16384;i++) {
writeByte(result,i*2,'B');
writeByte(result,2*i+1,' ');
}
vm->munmap((void *)result,32768);
close (myfd);
//-----------------------------------------------------------------------------------------------------------
myfd=open("mmap_test_2_file",O_RDONLY,0444);
if (myfd==-1)
error ("file reopening error = %s\n",strerror(errno));
result=(unsigned long)(vm->mmap(NULL,32768,PROT_WRITE|PROT_READ,MAP_SHARED,myfd,0));
for (int i=0;i<16384;i++) {
if ('B' != readByte(result,i*2))
error ("Non matching byte %c at offset %d\n");
if (' ' != readByte(result,2*i+1))
error ("Non matching byte %c at offset %d\n");
}
vm->munmap((void *)result,32768);
close (myfd);
}
catch (const char *t)
{
error ("Exception thrown! %s\n",t);
exit(1);
}
catch (...)
{
error ("Unknown Exception thrown!\n");
exit(1);
}
return 0;
}

View File

@ -0,0 +1,103 @@
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include "olist.h"
#include "error.h"
#include "OS.h"
struct iltTest : public node
{
iltTest(int i) {value=i;}
int value;
};
bool ilt(void *a,void *b)
{
iltTest *a1=reinterpret_cast<iltTest *>(a);
iltTest *b1=reinterpret_cast<iltTest *>(b);
if (a1->value<b1->value)
return true;
return false;
}
int main(int argc,char **argv)
{
// Test 1 - Try to add to foo without setting an isLessThan function
try {
orderedList foo;
node tmp;
foo.add(&tmp);
}
catch (const char *badness)
{
if (strcmp(badness,"Attempting to use an ordered list without setting up a 'toLessThan' function"))
printf ("Failure on adding with no isLessThan, printf = %s\n", badness);
printf ("Success on adding with no isLessThan, \n" );
}
catch(...)
{
printf ("Failure on adding with no isLessThan, unknown exception\n");
}
orderedList foo;
foo.setIsLessThan(ilt);
printf ("Add the first couple, in order (easy)\n");
iltTest first(1);
foo.add(&first);
iltTest second(2);
foo.add(&second);
foo.dump();
printf ("Add the next three, not in order (harder)\n");
iltTest third(3);
iltTest fourth(4);
iltTest fifth(5);
foo.add(&fourth);
foo.add(&third);
foo.add(&fifth);
foo.dump();
while (iltTest *n=(iltTest *)(foo.next()))
printf ("Popped %d\n",n->value);
orderedList bar;
bar.setIsLessThan(ilt);
while (iltTest *n=(iltTest *)(bar.next()))
printf ("Popped %d\n",n->value);
for (int a=0;a<100;a++)
bar.add(new iltTest(a));
while (iltTest *n=(iltTest *)(bar.next()))
printf ("Popped %d\n",n->value);
for (int a=1000;a>=0;a--)
bar.add(new iltTest(a));
while (iltTest *n=(iltTest *)(bar.next()))
if (!(n->value%50)) printf ("Popped %d\n",n->value);
printf ("Setting up simple case\n");
foo.add(&first);
foo.dump();
printf ("Removing simple case\n");
foo.remove(&first);
foo.dump();
printf ("Setting up middle case\n");
foo.add(&first);
foo.add(&second);
foo.dump();
printf ("Removing middle case\n");
foo.remove(&second);
foo.dump();
foo.remove(&first);
printf ("Setting up final case\n");
foo.add(&first);
foo.add(&second);
foo.add(&third);
foo.dump();
printf ("Removing final case\n");
foo.remove(&second);
foo.dump();
return 0;
}

View File

@ -0,0 +1,102 @@
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include "pageManager.h"
#include "OS.h"
enum testType {clean,unused,inuse};
pageManager pm;
char *testName;
bool testCount (int expected, testType type)
{
int found;
switch (type) {
case clean:
if (found=pm.getCleanCount()!=expected) {
error ("%s, invalid cleanCount of %d, expected: %d\n",testName,found,expected);
return false;
}
break;
case unused:
if (found=pm.getUnusedCount()!=expected) {
error ("%s, invalid unusedCount of %d, expected: %d\n",testName,found,expected);
return false;
}
break;
case inuse:
if (found=pm.getInUseCount()!=expected) {
error ("%s, invalid InUseCount of %d, expected: %d\n",testName,found,expected);
return false;
}
break;
}
return true;
}
int main(int argc,char **argv)
{
testName="Setup";
pm.setup(malloc(PAGE_SIZE*100),100);
if (!(testCount(99,unused) || testCount (0,clean) || testCount (0,inuse))) {
pm.dump();
exit(1);
}
testName="Get One";
page *gotten = pm.getPage();
if (!(testCount(98,unused) || testCount (0,clean) || testCount (1,inuse))) {
pm.dump();
exit(1);
}
testName="Put One";
pm.freePage(gotten);
if (!(testCount(99,unused) || testCount (0,clean) || testCount (0,inuse))) {
pm.dump();
exit(1);
}
testName="Clean One";
pm.cleanOnePage();
if (!(testCount(98,unused) || testCount (1,clean) || testCount (0,inuse))) {
pm.dump();
exit(1);
}
testName="Get One Cleaned";
gotten = pm.getPage();
if (!(testCount(98,unused) || testCount (0,clean) || testCount (1,inuse))) {
pm.dump();
exit(1);
}
testName="Put One Cleaned";
pm.freePage(gotten);
if (!(testCount(99,unused) || testCount (0,clean) || testCount (0,inuse))) {
pm.dump();
exit(1);
}
testName="Get them all";
page *pages[100];
for (int i=0;i<99;i++)
pages[i]=pm.getPage();
if (!(testCount(0,unused) || testCount (0,clean) || testCount (99,inuse))) {
pm.dump();
exit(1);
}
testName="Free them all";
for (int i=0;i<99;i++)
pm.freePage(pages[i]);
if (!(testCount(99,unused) || testCount (0,clean) || testCount (0,inuse))) {
pm.dump();
exit(1);
}
exit(0);
}

View File

@ -0,0 +1,60 @@
#include "vmInterface.h"
#include <stdio.h>
#include <unistd.h>
#include <mman.h>
#include <errno.h>
#include <string.h>
vmInterface *vm;
void writeByte(unsigned long addr,unsigned int offset, char value) { vm->setByte(addr+offset,value); }
unsigned char readByte(unsigned long addr,unsigned int offset ) { char value=vm->getByte(addr+offset); return value; }
int createFillAndTest(int pages,char *name)
{
unsigned long addr;
int area1;
error ("%s: createFillAndTest: about to create \n",name);
area1=vm->createArea(name,pages,(void **)(&addr));
error ("%s: createFillAndTest: create done\n",name);
for (int i=0;i<pages*PAGE_SIZE;i++)
{
if (!(i%9024) )
error ("Writing to byte %d of area %s\n",i,name);
writeByte(addr,i,i%256);
}
error ("%s: createFillAndTest: writing done\n",name);
for (int i=0;i<pages*PAGE_SIZE;i++)
{
if (!(i%9024) )
error ("Reading from byte %d of area %s\n",i,name);
if (i%256!=readByte(addr,i))
error ("ERROR! Byte at offset %d does not match: expected: %d, found: %d\n",i,i%256,readByte(addr,i));
}
vm->freeArea(area1);
error ("%s: createFillAndTest: reading done\n",name);
return area1;
}
int main(int argc,char **argv)
{
try {
vm = new vmInterface (30);
error ("Starting Threads!\n");
for (int i=0;i<20;i++)
createFillAndTest(1,"myTest");
}
catch (const char *t)
{
error ("Exception thrown! %s\n",t);
exit(1);
}
catch (...)
{
error ("Unknown Exception thrown!\n");
exit(1);
}
return 0;
}

226
src/kernel/vm2/tests/test.C Normal file
View File

@ -0,0 +1,226 @@
#include "vmInterface.h"
#include <stdio.h>
#include <unistd.h>
#include <mman.h>
#include <errno.h>
#include <string.h>
vmInterface vm(30);
thread_id loop1,loop2,loop3,info1,mmap1,clone1;
void writeByte(unsigned long addr,unsigned int offset, char value) { vm.setByte(addr+offset,value); }
unsigned char readByte(unsigned long addr,unsigned int offset ) { char value=vm.getByte(addr+offset); return value; }
int createFillAndTest(int pages,char *name)
{
try{
unsigned long addr;
int area1;
error ("%s: createFillAndTest: about to create \n",name);
area1=vm.createArea("Mine",pages,(void **)(&addr));
error ("%s: createFillAndTest: create done\n",name);
for (int i=0;i<pages*PAGE_SIZE;i++)
{
if (!(i%9024) )
error ("Writing to byte %d of area %s\n",i,name);
writeByte(addr,i,i%256);
}
error ("%s: createFillAndTest: writing done\n",name);
for (int i=0;i<pages*PAGE_SIZE;i++)
{
if (!(i%9024) )
error ("Reading from byte %d of area %s\n",i,name);
if (i%256!=readByte(addr,i))
error ("ERROR! Byte at offset %d does not match: expected: %d, found: %d\n",i,i%256,readByte(addr,i));
}
error ("%s: createFillAndTest: reading done\n",name);
return area1;
}
catch (const char *t)
{
error ("Exception thrown! %s\n",t);
exit(1);
}
catch (...)
{
error ("Exception thrown!\n");
exit(1);
}
return 0;
}
struct loopTestParameters
{
char *name;
bigtime_t initialSnooze;
int areaSize;
bigtime_t holdSnooze;
bigtime_t loopSnooze;
};
int32 loopTest(void *parameters)
{
try{
error ("Starting Loop Test!\n");
loopTestParameters *params=((loopTestParameters *)parameters);
int area1;
while (1)
{
snooze(params->initialSnooze);
error ("Creating %s area\n",params->name);
area1=createFillAndTest(params->areaSize,params->name);
snooze(params->holdSnooze);
error ("Freeing %s area\n",params->name);
vm.freeArea(area1);
snooze(params->loopSnooze);
}
}
catch (const char *t)
{
error ("Exception thrown! %s\n",t);
exit(1);
}
catch (...)
{
error ("Exception thrown!\n");
exit(1);
}
}
int32 getInfoTest(void *parameters)
{
loopTestParameters *params=((loopTestParameters *)parameters);
area_info ai;
int area1;
try{
while (1)
{
snooze(params->initialSnooze);
//error ("Creating %s area\n",params->name);
area1=createFillAndTest(params->areaSize,params->name);
snooze(params->holdSnooze);
vm.getAreaInfo(area1,&ai);
error ("Area info : \n");
error ("name : %s\n",ai.name);
error ("size : %ld\n",ai.size);
error ("lock : %ld\n",ai.lock);
error ("team : %ld\n",ai.team);
error ("ram_size : %ld\n",ai.ram_size);
error ("in_count : %ld\n",ai.in_count);
error ("out_count : %ld\n",ai.out_count);
error ("copy_count : %ld\n",ai.copy_count);
error ("address : %p\n",ai.address);
error ("Freeing %s area\n",params->name);
vm.freeArea(area1);
snooze(params->loopSnooze);
}
}
catch (const char *t)
{
error ("Exception thrown! %s\n",t);
exit(1);
}
catch (...)
{
error ("Exception thrown!\n");
exit(1);
}
}
int32 mmapTest (void *parameters)
{
try{
void *map;
loopTestParameters *params=((loopTestParameters *)parameters);
int size=params->areaSize; // Note that this is in bytes, not in pages
while (1)
{
int fd = open ("OBOS_mmap",O_RDWR|O_CREAT,0x777);
error ("Opened file, fd = %d\n",fd);
snooze(params->initialSnooze);
error ("Creating %s mmap\n",params->name);
snooze(params->holdSnooze);
map=vm.mmap(NULL,size,PROT_WRITE|PROT_READ,MAP_SHARED,fd,0);
error ("mmap address = %p\n",map);
for (int i=0;i<size;i++)
writeByte((int32)map,i,i%256);
error ("mmapTest: writing done\n");
for (int i=0;i<size;i++)
if (i%256!=readByte((int32)map,i))
error ("ERROR! Byte at offset %d does not match: expected: %d, found: %d\n",i,i%256,readByte((int32)map,i));
error ("mmapTest: reading done\n");
snooze(params->loopSnooze);
vm.munmap(map,size);
close(fd);
error ("Closed file, fd = %d\n",fd);
}
}
catch (const char *t)
{
error ("Exception thrown! %s\n",t);
exit(1);
}
catch (...)
{
error ("Exception thrown!\n");
exit(1);
}
}
int32 cloneTest (void *parameters)
{
loopTestParameters *params=((loopTestParameters *)parameters);
int area1,area2;
void *cloneAddr=NULL;
try {
while (1)
{
snooze(params->initialSnooze);
// error ("Creating %s area, size = %d\n",params->name,params->areaSize);
area1=createFillAndTest(params->areaSize,params->name);
// error ("cloning, create done \n");
area2=vm.cloneArea(area1,"Clone1",&cloneAddr);
for (int i=0;i<params->areaSize*PAGE_SIZE;i++)
if (i%256!=readByte((int32)cloneAddr,i))
error ("ERROR! Clone Byte at offset %d of %p does not match: expected: %d, found: %d\n",i,cloneAddr,i%256,readByte((int32)cloneAddr,i));
// error ("Snoozing, compare done \n");
snooze(params->holdSnooze);
// error ("Freeing %s area\n",params->name);
vm.freeArea(area2);
vm.freeArea(area1);
snooze(params->loopSnooze);
}
}
catch (...)
{
error ("Exception thrown!\n");
exit(1);
}
}
int main(int argc,char **argv)
{
loopTestParameters area1Params={"area1",1000000,2,100000,100000};
loopTestParameters area2Params={"area2",1000000,2,200000,100000};
loopTestParameters area3Params={"area3",1000000,2,300000,200000};
loopTestParameters info1Params={"info1",500000,2,400000,30000};
loopTestParameters mmap1Params={"mmap",500000,8192,400000,1000000};
loopTestParameters clone1Params={"clone1",200000,2,300000,400000};
error ("Starting Threads!\n");
//resume_thread(loop1=spawn_thread(loopTest,"area test 1",0,&area1Params));
//resume_thread(loop2=spawn_thread(loopTest,"area test 2",0,&area2Params));
//resume_thread(loop3=spawn_thread(loopTest,"area test 3",0,&area3Params));
resume_thread(info1=spawn_thread(getInfoTest,"info test 1",0,&info1Params));
//resume_thread(mmap1=spawn_thread(mmapTest,"mmap test 1",0,&mmap1Params));
//resume_thread(clone1=spawn_thread(cloneTest,"clone test 1",0,&clone1Params));
snooze(1000000000);
return 0;
}

View File

@ -0,0 +1,30 @@
#include "vmInterface.h"
#include <stdio.h>
#include <unistd.h>
#include <mman.h>
#include <errno.h>
#include <string.h>
vmInterface *vm;
int main(int argc,char **argv)
{
try {
vm = new vmInterface (90);
while (1)
snooze(1000000);
}
catch (const char *t)
{
error ("Exception thrown! %s\n",t);
exit(1);
}
catch (...)
{
error ("Unknown Exception thrown!\n");
exit(1);
}
return 0;
}