attachtest utility to test 1000x attach/detach combos in a cycle

develop
Petr Mrázek 2009-10-29 15:23:01 +00:00
parent 1110786d4c
commit 33f8b627d0
3 changed files with 78 additions and 3 deletions

@ -113,7 +113,7 @@ bool Process::attach()
break;
}
}
cout << "Managed to attach to pid " << my_handle << endl;
//cout << "Managed to attach to pid " << my_handle << endl;
attached = true;
g_pProcess = this;

@ -5,7 +5,7 @@ IF(UNIX)
add_definitions(-DLINUX_BUILD)
ENDIF(UNIX)
# a benchmark program
# a benchmark program, reads the map 1000x
ADD_EXECUTABLE(expbench expbench.cpp)
TARGET_LINK_LIBRARIES(expbench dfhack)
@ -24,3 +24,7 @@ TARGET_LINK_LIBRARIES(cleanmap dfhack)
# creaturedump - basic creature dump - a test of the creature related exports
ADD_EXECUTABLE(creaturedump creaturedump.cpp)
TARGET_LINK_LIBRARIES(creaturedump dfhack)
# attachtest - 100x attach/detach, 100x reads, 100x writes
ADD_EXECUTABLE(attachtest attachtest.cpp)
TARGET_LINK_LIBRARIES(attachtest dfhack)

@ -0,0 +1,71 @@
// Attach test
// attachtest - 100x attach/detach, 100x reads, 100x writes
#include <iostream>
#include <climits>
#include <integers.h>
#include <vector>
#include <ctime>
using namespace std;
#include <DFTypes.h>
#include <DFHackAPI.h>
int main (void)
{
time_t start, end;
double time_diff;
DFHackAPI *pDF = CreateDFHackAPI("Memory.xml");
DFHackAPI &DF = *pDF;
if(!DF.Attach())
{
cerr << "DF not found" << endl;
return 1;
}
if(!DF.Detach())
{
cerr << "Can't detach from DF" << endl;
return 1;
}
// attach/detach test
cout << "Testing attach/detach" << endl;
time(&start);
bool all_ok = true;
for (int i = 0; i < 1000; i++)
{
if(DF.Attach())
{
if(DF.Detach())
{
continue;
}
else
{
cout << "cycle " << i << ", detach failed" << endl;
all_ok = false;
}
}
else
{
cout << "cycle " << i << ", attach failed" << endl;
all_ok = false;
}
}
if(!all_ok)
{
cerr << "failed to attach or detach in cycle! exiting" << endl;
return 1;
}
time(&end);
time_diff = difftime(end, start);
cout << "attach tests done in " << time_diff << " seconds." << endl;
cout << "Press any key to continue" << endl;
cin.ignore();
delete pDF;
return 0;
}