diff --git a/library/DFProcess.cpp b/library/DFProcess.cpp index ef1891496..6def32be5 100644 --- a/library/DFProcess.cpp +++ b/library/DFProcess.cpp @@ -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; diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 576e81285..9240a566e 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -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) @@ -23,4 +23,8 @@ 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) \ No newline at end of file +TARGET_LINK_LIBRARIES(creaturedump dfhack) + +# attachtest - 100x attach/detach, 100x reads, 100x writes +ADD_EXECUTABLE(attachtest attachtest.cpp) +TARGET_LINK_LIBRARIES(attachtest dfhack) \ No newline at end of file diff --git a/tools/attachtest.cpp b/tools/attachtest.cpp new file mode 100644 index 000000000..bf9fe0176 --- /dev/null +++ b/tools/attachtest.cpp @@ -0,0 +1,71 @@ +// Attach test +// attachtest - 100x attach/detach, 100x reads, 100x writes + +#include +#include +#include +#include +#include +using namespace std; + +#include +#include + +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; +} \ No newline at end of file