Skip to content
Snippets Groups Projects
MemoryTest.h 1.56 KiB
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() {
class MemoryTest : public CxxTest::TestSuite {
  void test_update() {
    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(), "");

    TS_ASSERT_LESS_THAN(
        0, mem.residentMem()); // Current process must use something
    TS_ASSERT_DIFFERS(mem.resUsageStr(), "");
    TS_ASSERT_LESS_THAN_EQUALS(0, mem.virtualMem());
    TS_ASSERT_DIFFERS(mem.vmUsageStr(), "");
  }

  /// Update in parallel to test thread safety
  void test_parallel() {
    for (int i = 0; i < 500; i++) {
  void test_parallel_threadpool() {
    for (int i = 0; i < 500; i++) {
      pool.schedule(new FunctionTask(&MemoryTest_myTaskFunction, 1.0));
    }
    pool.joinAll();
  }
};

#endif /* MANTID_KERNEL_MEMORYTEST_H_ */