dfhack/tools/supported/attachtest.cpp

91 lines
2.0 KiB
C++

// Attach test
// attachtest - 1000x suspend/resume
#include <iostream>
#include <climits>
#include <vector>
#include <ctime>
using namespace std;
2010-05-25 22:48:23 -06:00
#include <DFHack.h>
#include "termutil.h"
int main (void)
{
bool temporary_terminal = TemporaryTerminal();
time_t start, end;
double time_diff;
2010-05-23 15:06:10 -06:00
DFHack::ContextManager DFMgr("Memory.xml");
DFHack::Context* DF;
2010-02-27 17:13:34 -07:00
try
{
2010-05-23 15:06:10 -06:00
DF = DFMgr.getSingleContext();
DF->Attach();
DF->Detach();
}
catch (exception& e)
{
2010-02-27 17:13:34 -07:00
cerr << e.what() << endl;
if(temporary_terminal)
cin.ignore();
return 1;
}
/*
// attach/detach test
cout << "Testing attach/detach" << endl;
time(&start);
bool all_ok = true;
for (int i = 0; i < 100; i++)
{
2009-10-29 11:56:15 -06:00
cout << "Try " << i << endl;
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;
}
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 << "Testing suspend/resume" << endl;
2010-05-23 15:06:10 -06:00
DF->Attach();
time(&start);
for (int i = 0; i < 1000; i++)
{
2010-05-23 15:06:10 -06:00
DF->Suspend();
if(i%10 == 0)
cout << i / 10 << "%" << endl;
2010-05-23 15:06:10 -06:00
DF->Resume();
}
time(&end);
2010-05-23 15:06:10 -06:00
DF->Detach();
time_diff = difftime(end, start);
cout << "suspend tests done in " << time_diff << " seconds." << endl;
if(temporary_terminal)
{
cout << "Done. Press any key to continue" << endl;
cin.ignore();
}
return 0;
}