Skip to content
Snippets Groups Projects
Commit 1a5d14ab authored by Gigg, Martyn Anthony's avatar Gigg, Martyn Anthony
Browse files

Check MRULists in EventWorkspaceTest

Instead of checking memory, which is unreliable cross platform, test the size of the MRUList at various points
Refs #10168
parent 06e1a705
No related branches found
No related tags found
No related merge requests found
...@@ -16,13 +16,9 @@ ...@@ -16,13 +16,9 @@
#include "MantidDataObjects/EventWorkspace.h" #include "MantidDataObjects/EventWorkspace.h"
#include "MantidTestHelpers/WorkspaceCreationHelper.h" #include "MantidTestHelpers/WorkspaceCreationHelper.h"
#include "MantidTestHelpers/ComponentCreationHelper.h" #include "MantidTestHelpers/ComponentCreationHelper.h"
#include "MantidKernel/Memory.h"
#include "MantidKernel/Timer.h" #include "MantidKernel/Timer.h"
#ifndef _WIN32
#include <sys/resource.h>
#endif
using namespace Mantid; using namespace Mantid;
using namespace Mantid::DataObjects; using namespace Mantid::DataObjects;
using namespace Mantid::Kernel; using namespace Mantid::Kernel;
...@@ -453,48 +449,24 @@ public: ...@@ -453,48 +449,24 @@ public:
} }
} }
//------------------------------------------------------------------------------
/// Linux-only method for getting memory usage
int memory_usage()
{
// Linux only memory test
#ifdef _WIN32
//Temporarily disabled for non-linux OSs
#else
char buf[30];
snprintf(buf, 30, "/proc/%u/statm", (unsigned)getpid());
FILE* pf = fopen(buf, "r");
if (pf) {
int size; // total program size
int status = fscanf(pf, "%u" /* %u %u %u %u %u"*/, &size/*, &resident, &share, &text, &lib, &data*/);
(void) status;
fclose(pf);
return size*4; //On my system each number here = 4 kb
}
fclose(pf);
#endif
return 0;
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void test_histogram_cache() void test_histogram_cache()
{ {
//Try caching and most-recently-used MRU list. //Try caching and most-recently-used MRU list.
EventWorkspace_const_sptr ew2 = boost::dynamic_pointer_cast<const EventWorkspace>(ew); EventWorkspace_const_sptr ew2 = boost::dynamic_pointer_cast<const EventWorkspace>(ew);
//Are the returned arrays the right size? //Are the returned arrays the right size?
MantidVec data1 = ew2->dataY(1); MantidVec data1 = ew2->dataY(1);
TS_ASSERT_EQUALS( data1.size(), NUMBINS-1); TS_ASSERT_EQUALS( data1.size(), NUMBINS-1);
// A single cached value now
TS_ASSERT_EQUALS( ew2->MRUSize(), 1);
//This should get the cached one //This should get the cached one
MantidVec data2 = ew2->dataY(1); MantidVec data2 = ew2->dataY(1);
TS_ASSERT_EQUALS( data2.size(), NUMBINS-1); TS_ASSERT_EQUALS( data2.size(), NUMBINS-1);
// Still a single cached value
TS_ASSERT_EQUALS( ew2->MRUSize(), 1);
//All elements are the same //All elements are the same
for (std::size_t i=0; i<data1.size();i++) for (std::size_t i=0; i<data1.size();i++)
TS_ASSERT_EQUALS( data1[i], data2[i]); TS_ASSERT_EQUALS( data1[i], data2[i]);
...@@ -507,34 +479,23 @@ public: ...@@ -507,34 +479,23 @@ public:
data1 = ew2->dataY(0); data1 = ew2->dataY(0);
TS_ASSERT_DELTA( ew2->dataY(0)[1], 2.0, 1e-6); TS_ASSERT_DELTA( ew2->dataY(0)[1], 2.0, 1e-6);
TS_ASSERT_DELTA( data1[1], 2.0, 1e-6); TS_ASSERT_DELTA( data1[1], 2.0, 1e-6);
// Cache should now be full
TS_ASSERT_EQUALS( ew2->MRUSize(), 50);
int mem1 = memory_usage();
int mem2 = 0;
int last = 100; int last = 100;
//Read more; memory use should be the same? //Read more;
for (int i=last; i<last+100;i++) for (int i=last; i<last+100;i++)
data1 = ew2->dataY(i); data1 = ew2->dataY(i);
#ifndef WIN32 // Cache should now be full still
mem2 = memory_usage(); TS_ASSERT_EQUALS( ew2->MRUSize(), 50);
TS_ASSERT_LESS_THAN( mem2-mem1, 10); //Memory usage should be ~the same.
#endif
//Do it some more // Do it some more
last=200; mem1=mem2; last=200;
for (int i=last; i<last+100;i++) for (int i=last; i<last+100;i++)
data1 = ew2->dataY(i); data1 = ew2->dataY(i);
#ifndef WIN32
mem2 = memory_usage();
TS_ASSERT_LESS_THAN( mem2-mem1, 10); //Memory usage should be ~the same.
#endif
//----- Now we test that setAllX clears the memory ---- //----- Now we test that setAllX clears the memory ----
mem1=mem2;
//Yes, our eventworkspace MRU is full //Yes, our eventworkspace MRU is full
TS_ASSERT_EQUALS( ew->MRUSize(), 50); TS_ASSERT_EQUALS( ew->MRUSize(), 50);
...@@ -548,13 +509,6 @@ public: ...@@ -548,13 +509,6 @@ public:
//MRU should have been cleared now //MRU should have been cleared now
TS_ASSERT_EQUALS( ew->MRUSize(), 0); TS_ASSERT_EQUALS( ew->MRUSize(), 0);
TS_ASSERT_EQUALS( ew2->MRUSize(), 0); TS_ASSERT_EQUALS( ew2->MRUSize(), 0);
//#ifndef WIN32
// mem2 = memory_usage();
// std::cout << "Mem change " << mem2-mem1 << "\n";
// TS_ASSERT_LESS_THAN( mem2-mem1, 0); //Memory usage should be lower!.
//#endif
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment