2009-10-29 09:23:01 -06:00
|
|
|
// 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;
|
2009-11-10 20:37:28 -07:00
|
|
|
DFHack::API DF("Memory.xml");
|
2009-10-29 09:23:01 -06:00
|
|
|
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;
|
2009-11-16 09:47:22 -07:00
|
|
|
for (int i = 0; i < 100; i++)
|
2009-10-29 09:23:01 -06:00
|
|
|
{
|
2009-10-29 11:56:15 -06:00
|
|
|
cout << "Try " << i << endl;
|
2009-10-29 09:23:01 -06:00
|
|
|
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;
|
|
|
|
}
|
2009-10-29 11:56:15 -06:00
|
|
|
cout << endl;
|
2009-10-29 09:23:01 -06:00
|
|
|
}
|
|
|
|
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;
|
2009-11-16 09:47:22 -07:00
|
|
|
|
|
|
|
cout << "Testing suspend/resume" << endl;
|
|
|
|
DF.Attach();
|
|
|
|
time(&start);
|
2009-11-18 17:36:03 -07:00
|
|
|
for (int i = 0; i < 1000000; i++)
|
2009-11-16 09:47:22 -07:00
|
|
|
{
|
|
|
|
DF.Suspend();
|
2009-11-18 17:36:03 -07:00
|
|
|
if(i%10000 == 0)
|
|
|
|
cout << i / 10000 << "%" << endl;
|
2009-11-16 09:47:22 -07:00
|
|
|
DF.Resume();
|
|
|
|
}
|
|
|
|
time(&end);
|
|
|
|
DF.Detach();
|
|
|
|
time_diff = difftime(end, start);
|
|
|
|
cout << "suspend tests done in " << time_diff << " seconds." << endl;
|
|
|
|
|
2009-11-05 18:04:17 -07:00
|
|
|
#ifndef LINUX_BUILD
|
|
|
|
cout << "Done. Press any key to continue" << endl;
|
2009-10-29 09:23:01 -06:00
|
|
|
cin.ignore();
|
2009-11-05 18:04:17 -07:00
|
|
|
#endif
|
2009-10-29 09:23:01 -06:00
|
|
|
return 0;
|
|
|
|
}
|