2009-10-29 09:23:01 -06:00
|
|
|
// Attach test
|
2010-03-26 06:01:46 -06:00
|
|
|
// attachtest - 1000x suspend/resume
|
2009-10-29 09:23:01 -06:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <climits>
|
|
|
|
#include <vector>
|
|
|
|
#include <ctime>
|
|
|
|
using namespace std;
|
2010-05-25 22:48:23 -06:00
|
|
|
#include <DFHack.h>
|
2011-05-14 22:10:47 -06:00
|
|
|
#include "termutil.h"
|
2009-10-29 09:23:01 -06:00
|
|
|
|
|
|
|
int main (void)
|
|
|
|
{
|
2011-05-14 22:10:47 -06:00
|
|
|
bool temporary_terminal = TemporaryTerminal();
|
2009-10-29 09:23:01 -06:00
|
|
|
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
|
2009-10-29 09:23:01 -06:00
|
|
|
{
|
2010-05-23 15:06:10 -06:00
|
|
|
DF = DFMgr.getSingleContext();
|
|
|
|
DF->Attach();
|
|
|
|
DF->Detach();
|
2009-10-29 09:23:01 -06:00
|
|
|
}
|
2010-03-26 06:01:46 -06:00
|
|
|
catch (exception& e)
|
2009-10-29 09:23:01 -06:00
|
|
|
{
|
2010-02-27 17:13:34 -07:00
|
|
|
cerr << e.what() << endl;
|
2011-05-14 22:10:47 -06:00
|
|
|
if(temporary_terminal)
|
2010-03-26 06:01:46 -06:00
|
|
|
cin.ignore();
|
2009-10-29 09:23:01 -06:00
|
|
|
return 1;
|
|
|
|
}
|
2010-03-18 12:55:01 -06:00
|
|
|
/*
|
2009-10-29 09:23:01 -06:00
|
|
|
// 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;
|
2010-03-18 12:55:01 -06:00
|
|
|
*/
|
2009-11-16 09:47:22 -07:00
|
|
|
cout << "Testing suspend/resume" << endl;
|
2010-05-23 15:06:10 -06:00
|
|
|
DF->Attach();
|
2009-11-16 09:47:22 -07:00
|
|
|
time(&start);
|
2010-02-28 10:08:44 -07:00
|
|
|
for (int i = 0; i < 1000; i++)
|
2009-11-16 09:47:22 -07:00
|
|
|
{
|
2010-05-23 15:06:10 -06:00
|
|
|
DF->Suspend();
|
2010-02-28 10:08:44 -07:00
|
|
|
if(i%10 == 0)
|
|
|
|
cout << i / 10 << "%" << endl;
|
2010-05-23 15:06:10 -06:00
|
|
|
DF->Resume();
|
2009-11-16 09:47:22 -07:00
|
|
|
}
|
|
|
|
time(&end);
|
2010-05-23 15:06:10 -06:00
|
|
|
DF->Detach();
|
2009-11-16 09:47:22 -07:00
|
|
|
time_diff = difftime(end, start);
|
|
|
|
cout << "suspend tests done in " << time_diff << " seconds." << endl;
|
2011-05-14 22:10:47 -06:00
|
|
|
|
|
|
|
if(temporary_terminal)
|
|
|
|
{
|
2010-03-26 06:01:46 -06:00
|
|
|
cout << "Done. Press any key to continue" << endl;
|
|
|
|
cin.ignore();
|
2011-05-14 22:10:47 -06:00
|
|
|
}
|
2009-10-29 09:23:01 -06:00
|
|
|
return 0;
|
2009-12-13 14:03:19 -07:00
|
|
|
}
|