forked from DFHack/dfhack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathattachtest.cpp
More file actions
86 lines (80 loc) · 1.86 KB
/
Copy pathattachtest.cpp
File metadata and controls
86 lines (80 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// 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>
#include <DFError.h>
int main (void)
{
time_t start, end;
double time_diff;
DFHack::API DF("Memory.xml");
try
{
DF.Attach();
DF.Detach();
}
catch (DFHack::Error::NoProcess& e)
{
cerr << e.what() << endl;
return 1;
}
// attach/detach test
cout << "Testing attach/detach" << endl;
time(&start);
bool all_ok = true;
for (int i = 0; i < 100; i++)
{
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;
}
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;
DF.Attach();
time(&start);
for (int i = 0; i < 1000; i++)
{
DF.Suspend();
if(i%10 == 0)
cout << i / 10 << "%" << endl;
DF.Resume();
}
time(&end);
DF.Detach();
time_diff = difftime(end, start);
cout << "suspend tests done in " << time_diff << " seconds." << endl;
#ifndef LINUX_BUILD
cout << "Done. Press any key to continue" << endl;
cin.ignore();
#endif
return 0;
}