Newer
Older
#ifndef MANTID_KERNEL_MEMORYTEST_H_
#define MANTID_KERNEL_MEMORYTEST_H_
#include <cxxtest/TestSuite.h>
#include "MantidKernel/Timer.h"
#include "MantidKernel/System.h"
#include "MantidKernel/Memory.h"
#include "MantidKernel/MultiThreaded.h"
#include "MantidKernel/FunctionTask.h"
#include "MantidKernel/ThreadPool.h"
using namespace Mantid::Kernel;
void MemoryTest_myTaskFunction() {
MemoryStats mem;
mem.update();
mem.getFreeRatio();
}
class MemoryTest : public CxxTest::TestSuite {
public:
MemoryStats mem;
TS_ASSERT_THROWS_NOTHING(mem.update());
TS_ASSERT_LESS_THAN_EQUALS(0, mem.availMem());
TS_ASSERT_DIFFERS(mem.availMemStr(), "");
TS_ASSERT_LESS_THAN_EQUALS(0, mem.reservedMem());
TS_ASSERT_LESS_THAN(0, mem.totalMem()); // The machine must have some memory
TS_ASSERT_DIFFERS(mem.totalMemStr(), "");
Gigg, Martyn Anthony
committed
// Current process stats
TS_ASSERT_LESS_THAN(
0, mem.residentMem()); // Current process must use something
TS_ASSERT_DIFFERS(mem.resUsageStr(), "");
Gigg, Martyn Anthony
committed
TS_ASSERT_LESS_THAN_EQUALS(0, mem.virtualMem());
TS_ASSERT_DIFFERS(mem.vmUsageStr(), "");
}
/// Update in parallel to test thread safety
PARALLEL_FOR_NO_WSP_CHECK()
MemoryStats mem;
mem.update();
mem.getFreeRatio();
}
}
void test_parallel_threadpool() {
ThreadPool pool;
for (int i = 0; i < 500; i++) {
pool.schedule(new FunctionTask(&MemoryTest_myTaskFunction, 1.0));
}
pool.joinAll();
}
};
#endif /* MANTID_KERNEL_MEMORYTEST_H_ */