X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/db1df4b379b3e088b50f6e573ba9b0887b59c96a..1ffd336de7f3917df1d0cbbacc0e077b4b5c1363:/src/mc/sosp/mc_snapshot_test.cpp diff --git a/src/mc/sosp/mc_snapshot_test.cpp b/src/mc/sosp/mc_snapshot_test.cpp index 51f8b130ea..64fb6edb7f 100644 --- a/src/mc/sosp/mc_snapshot_test.cpp +++ b/src/mc/sosp/mc_snapshot_test.cpp @@ -1,14 +1,13 @@ -/* Copyright (c) 2014-2018. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2014-2019. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#define BOOST_TEST_MODULE snapshots -#define BOOST_TEST_DYN_LINK -#include +#include "src/include/catch.hpp" #include #include +#include #include @@ -19,7 +18,7 @@ /**************** Class BOOST_tests *************************/ using simgrid::mc::RegionSnapshot; -class BOOST_tests { +class snap_test_helper { public: static void init_memory(void* mem, size_t size); static void Init(bool sparse_ckpt); @@ -27,8 +26,8 @@ public: size_t size; void* src; void* dstn; - RegionSnapshot region0; - RegionSnapshot region; + RegionSnapshot* region0; + RegionSnapshot* region; } prologue_return; static prologue_return prologue(int n); // common to the below 5 fxs static void read_whole_region(); @@ -43,53 +42,56 @@ public: mc_model_checker = nullptr; } -public: + static std::default_random_engine rnd_engine; static bool sparse_checkpoint; static std::unique_ptr process; }; // static member variables init. -bool BOOST_tests::sparse_checkpoint = 0; -std::unique_ptr BOOST_tests::process = nullptr; +std::default_random_engine snap_test_helper::rnd_engine; +bool snap_test_helper::sparse_checkpoint = 0; +std::unique_ptr snap_test_helper::process = nullptr; -void BOOST_tests::init_memory(void* mem, size_t size) +void snap_test_helper::init_memory(void* mem, size_t size) { char* dest = (char*)mem; for (size_t i = 0; i < size; ++i) { - dest[i] = rand() & 255; + dest[i] = rnd_engine() & 255; } } -void BOOST_tests::Init(bool sparse_ckpt) +void snap_test_helper::Init(bool sparse_ckpt) { _sg_mc_sparse_checkpoint = sparse_ckpt; - BOOST_CHECK_EQUAL(xbt_pagesize, getpagesize()); - BOOST_CHECK_EQUAL(1 << xbt_pagebits, xbt_pagesize); + REQUIRE(xbt_pagesize == getpagesize()); + REQUIRE(1 << xbt_pagebits == xbt_pagesize); - process = std::unique_ptr(new simgrid::mc::RemoteClient(getpid(), -1)); + process.reset(new simgrid::mc::RemoteClient(getpid(), -1)); process->init(); mc_model_checker = new ::simgrid::mc::ModelChecker(std::move(process)); } -BOOST_tests::prologue_return BOOST_tests::prologue(int n) +snap_test_helper::prologue_return snap_test_helper::prologue(int n) { // Store region page(s): size_t byte_size = n * xbt_pagesize; void* source = mmap(nullptr, byte_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); - BOOST_CHECK_MESSAGE(source != MAP_FAILED, "Could not allocate source memory"); + INFO("Could not allocate source memory") + REQUIRE(source != MAP_FAILED); // Init memory and take snapshots: init_memory(source, byte_size); - simgrid::mc::RegionSnapshot region0 = - simgrid::mc::sparse_region(simgrid::mc::RegionType::Unknown, source, source, byte_size); + simgrid::mc::RegionSnapshot* region0 = + new simgrid::mc::RegionSparse(simgrid::mc::RegionType::Unknown, source, source, byte_size); for (int i = 0; i < n; i += 2) { init_memory((char*)source + i * xbt_pagesize, xbt_pagesize); } - simgrid::mc::RegionSnapshot region = - simgrid::mc::sparse_region(simgrid::mc::RegionType::Unknown, source, source, byte_size); + simgrid::mc::RegionSnapshot* region = + new simgrid::mc::RegionSparse(simgrid::mc::RegionType::Unknown, source, source, byte_size); void* destination = mmap(nullptr, byte_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); - BOOST_CHECK_MESSAGE(source != MAP_FAILED, "Could not allocate destination memory"); + INFO("Could not allocate destination memory"); + REQUIRE(source != MAP_FAILED); return {.size = byte_size, .src = source, @@ -98,160 +100,123 @@ BOOST_tests::prologue_return BOOST_tests::prologue(int n) .region = std::move(region)}; } -void BOOST_tests::read_whole_region() +void snap_test_helper::read_whole_region() { - for (int n = 1; n != 256; ++n) { + for (int n = 1; n != 32; ++n) { prologue_return ret = prologue(n); - const void* read = MC_region_read(&(ret.region), ret.dstn, ret.src, ret.size); - BOOST_CHECK_MESSAGE(not memcmp(ret.src, read, ret.size), "Mismatch in MC_region_read()"); + const void* read = MC_region_read(ret.region, ret.dstn, ret.src, ret.size); + INFO("Mismatch in MC_region_read()"); + REQUIRE(not memcmp(ret.src, read, ret.size)); munmap(ret.dstn, ret.size); munmap(ret.src, ret.size); + delete ret.region0; + delete ret.region; } } -void BOOST_tests::read_region_parts() +void snap_test_helper::read_region_parts() { - for (int n = 1; n != 256; ++n) { + for (int n = 1; n != 32; ++n) { prologue_return ret = prologue(n); for (int j = 0; j != 100; ++j) { - size_t offset = rand() % ret.size; - size_t size = rand() % (ret.size - offset); - const void* read = MC_region_read(&(ret.region), ret.dstn, (const char*)ret.src + offset, size); - BOOST_CHECK_MESSAGE(not memcmp((char*)ret.src + offset, read, size), "Mismatch in MC_region_read()"); + size_t offset = rnd_engine() % ret.size; + size_t size = rnd_engine() % (ret.size - offset); + const void* read = MC_region_read(ret.region, ret.dstn, (const char*)ret.src + offset, size); + INFO("Mismatch in MC_region_read()"); + REQUIRE(not memcmp((char*)ret.src + offset, read, size)); } munmap(ret.dstn, ret.size); munmap(ret.src, ret.size); + delete ret.region0; + delete ret.region; } } -void BOOST_tests::compare_whole_region() +void snap_test_helper::compare_whole_region() { - for (int n = 1; n != 256; ++n) { + for (int n = 1; n != 32; ++n) { prologue_return ret = prologue(n); - BOOST_CHECK_MESSAGE(MC_snapshot_region_memcmp(ret.src, &(ret.region0), ret.src, &(ret.region), ret.size), - "Unexpected match in MC_snapshot_region_memcmp() with previous snapshot"); + INFO("Unexpected match in MC_snapshot_region_memcmp() with previous snapshot"); + REQUIRE(MC_snapshot_region_memcmp(ret.src, ret.region0, ret.src, ret.region, ret.size)); munmap(ret.dstn, ret.size); munmap(ret.src, ret.size); + delete ret.region0; + delete ret.region; } } -void BOOST_tests::compare_region_parts() +void snap_test_helper::compare_region_parts() { - for (int n = 1; n != 256; ++n) { + for (int n = 1; n != 32; ++n) { prologue_return ret = prologue(n); - // xbt_test_add("Compare parts of region data for %i page(s) with itself", n); for (int j = 0; j != 100; ++j) { - size_t offset = rand() % ret.size; - size_t size = rand() % (ret.size - offset); - BOOST_CHECK_MESSAGE(not MC_snapshot_region_memcmp((char*)ret.src + offset, &(ret.region), (char*)ret.src + offset, - &(ret.region), size), - "Mismatch in MC_snapshot_region_memcmp()"); + size_t offset = rnd_engine() % ret.size; + size_t size = rnd_engine() % (ret.size - offset); + + INFO("Mismatch in MC_snapshot_region_memcmp()"); + REQUIRE(not MC_snapshot_region_memcmp((char*)ret.src + offset, ret.region, (char*)ret.src + offset, ret.region, + size)); } munmap(ret.dstn, ret.size); munmap(ret.src, ret.size); + delete ret.region0; + delete ret.region; } } -void BOOST_tests::read_pointer() +void snap_test_helper::read_pointer() { prologue_return ret = prologue(1); - // xbt_test_add("Read pointer for %i page(s)", n); memcpy(ret.src, &mc_model_checker, sizeof(void*)); - simgrid::mc::RegionSnapshot region2 = - simgrid::mc::sparse_region(simgrid::mc::RegionType::Unknown, ret.src, ret.src, ret.size); - BOOST_CHECK_MESSAGE(MC_region_read_pointer(®ion2, ret.src) == mc_model_checker, - "Mismtach in MC_region_read_pointer()"); + simgrid::mc::RegionSnapshot* region2 = + new simgrid::mc::RegionSparse(simgrid::mc::RegionType::Unknown, ret.src, ret.src, ret.size); + INFO("Mismtach in MC_region_read_pointer()"); + REQUIRE(MC_region_read_pointer(region2, ret.src) == mc_model_checker); munmap(ret.dstn, ret.size); munmap(ret.src, ret.size); + delete ret.region0; + delete ret.region; } -/*************** End: class BOOST_tests *****************************/ - -namespace utf = boost::unit_test; // for test case dependence - -BOOST_AUTO_TEST_SUITE(flat_snapshot) -BOOST_AUTO_TEST_CASE(Init) -{ - BOOST_tests::Init(0); -} - -BOOST_AUTO_TEST_CASE(read_whole_region, *utf::depends_on("flat_snapshot/Init")) -{ - BOOST_tests::read_whole_region(); -} - -BOOST_AUTO_TEST_CASE(read_region_parts, *utf::depends_on("flat_snapshot/read_whole_region")) -{ - BOOST_tests::read_region_parts(); -} +/*************** End: class snap_test_helper *****************************/ -BOOST_AUTO_TEST_CASE(compare_whole_region, *utf::depends_on("flat_snapshot/read_region_parts")) +TEST_CASE("MC::Snapshot: A copy/snapshot of a given memory region", "MC::Snapshot") { - BOOST_tests::compare_whole_region(); -} + auto sparse = GENERATE(false, true); -BOOST_AUTO_TEST_CASE(compare_region_parts, *utf::depends_on("flat_snapshot/compare_whole_region")) -{ - BOOST_tests::compare_region_parts(); -} - -BOOST_AUTO_TEST_CASE(read_pointer, *utf::depends_on("flat_snapshot/compare_region_parts")) -{ - BOOST_tests::read_pointer(); -} + if (sparse) { + INFO("Sparse snapshot (using pages)"); + } else { + INFO("Flat snapshot (no pages)"); + } -// not really a test, just for cleanup the resources -BOOST_AUTO_TEST_CASE(cleanup, *utf::depends_on("flat_snapshot/read_pointer")) -{ - BOOST_tests::cleanup(); -} -BOOST_AUTO_TEST_SUITE_END() + snap_test_helper::Init(sparse); -BOOST_AUTO_TEST_SUITE(page_snapshots) -BOOST_AUTO_TEST_CASE(Init) -{ - BOOST_tests::Init(1); -} + INFO("Read whole region"); + snap_test_helper::read_whole_region(); -BOOST_AUTO_TEST_CASE(read_whole_region, *utf::depends_on("page_snapshots/Init")) -{ - BOOST_tests::read_whole_region(); -} + INFO("Read region parts"); + snap_test_helper::read_region_parts(); -BOOST_AUTO_TEST_CASE(read_region_parts, *utf::depends_on("page_snapshots/read_whole_region")) -{ - BOOST_tests::read_region_parts(); -} + INFO("Compare whole region"); + snap_test_helper::compare_whole_region(); -BOOST_AUTO_TEST_CASE(compare_whole_region, *utf::depends_on("page_snapshots/read_region_parts")) -{ - BOOST_tests::compare_whole_region(); -} - -BOOST_AUTO_TEST_CASE(compare_region_parts, *utf::depends_on("page_snapshots/compare_whole_region")) -{ - BOOST_tests::compare_region_parts(); -} + INFO("Compare region parts"); + snap_test_helper::compare_region_parts(); -BOOST_AUTO_TEST_CASE(read_pointer, *utf::depends_on("page_snapshots/compare_region_parts")) -{ - BOOST_tests::read_pointer(); -} + INFO("Read pointer"); + snap_test_helper::read_pointer(); -// not really a test, just for cleanup the resources -BOOST_AUTO_TEST_CASE(cleanup, *utf::depends_on("page_snapshots/read_pointer")) -{ - BOOST_tests::cleanup(); + snap_test_helper::cleanup(); } -BOOST_AUTO_TEST_SUITE_END()