X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/8bf8303f84623a9346997d71d828a2e843c685d3..8c6bbb14f44b8daed5ea43d80880c6bf2155118b:/src/mc/sosp/Snapshot_test.cpp diff --git a/src/mc/sosp/Snapshot_test.cpp b/src/mc/sosp/Snapshot_test.cpp index cadb7bdf43..ff2ff0bd0d 100644 --- a/src/mc/sosp/Snapshot_test.cpp +++ b/src/mc/sosp/Snapshot_test.cpp @@ -1,15 +1,16 @@ -/* Copyright (c) 2014-2019. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2014-2023. 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. */ -#include "src/include/catch.hpp" +#include "src/3rd-party/catch.hpp" #include "src/mc/mc_config.hpp" #include "src/mc/sosp/Snapshot.hpp" #include -#include +#include #include +#include /**************** Class BOOST_tests *************************/ using simgrid::mc::Region; @@ -17,13 +18,13 @@ class snap_test_helper { public: static void init_memory(void* mem, size_t size); static void Init(); - typedef struct { + struct prologue_return { size_t size; void* src; void* dstn; Region* region0; Region* region; - } prologue_return; + }; static prologue_return prologue(int n); // common to the below 5 fxs static void read_whole_region(); static void read_region_parts(); @@ -37,19 +38,17 @@ public: mc_model_checker = nullptr; } - static std::default_random_engine rnd_engine; - static std::unique_ptr process; + static std::unique_ptr process; }; // static member variables init. -std::default_random_engine snap_test_helper::rnd_engine; -std::unique_ptr snap_test_helper::process = nullptr; +std::unique_ptr snap_test_helper::process = nullptr; void snap_test_helper::init_memory(void* mem, size_t size) { - char* dest = (char*)mem; + auto* dest = static_cast(mem); for (size_t i = 0; i < size; ++i) { - dest[i] = rnd_engine() & 255; + dest[i] = simgrid::xbt::random::uniform_int(0, 0xff); } } @@ -58,9 +57,9 @@ void snap_test_helper::Init() REQUIRE(xbt_pagesize == getpagesize()); REQUIRE(1 << xbt_pagebits == xbt_pagesize); - process.reset(new simgrid::mc::RemoteClient(getpid(), -1)); - process->init(); - mc_model_checker = new ::simgrid::mc::ModelChecker(std::move(process)); + process = std::make_unique(getpid()); + process->init(nullptr, nullptr); + mc_model_checker = new ::simgrid::mc::ModelChecker(std::move(process), -1); } snap_test_helper::prologue_return snap_test_helper::prologue(int n) @@ -68,32 +67,27 @@ 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); - INFO("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::Region* region0 = new simgrid::mc::Region(simgrid::mc::RegionType::Data, source, byte_size); + auto* region0 = new simgrid::mc::Region(simgrid::mc::RegionType::Data, source, byte_size); for (int i = 0; i < n; i += 2) { init_memory((char*)source + i * xbt_pagesize, xbt_pagesize); } - simgrid::mc::Region* region = new simgrid::mc::Region(simgrid::mc::RegionType::Data, source, byte_size); + auto* region = new simgrid::mc::Region(simgrid::mc::RegionType::Data, source, byte_size); void* destination = mmap(nullptr, byte_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); INFO("Could not allocate destination memory"); - REQUIRE(source != MAP_FAILED); + REQUIRE(destination != MAP_FAILED); - return {.size = byte_size, - .src = source, - .dstn = destination, - .region0 = std::move(region0), - .region = std::move(region)}; + return {.size = byte_size, .src = source, .dstn = destination, .region0 = region0, .region = region}; } void snap_test_helper::read_whole_region() { for (int n = 1; n != 32; ++n) { - prologue_return ret = prologue(n); const void* read = ret.region->read(ret.dstn, ret.src, ret.size); INFO("Mismatch in MC_region_read()"); @@ -109,12 +103,11 @@ void snap_test_helper::read_whole_region() void snap_test_helper::read_region_parts() { for (int n = 1; n != 32; ++n) { - prologue_return ret = prologue(n); for (int j = 0; j != 100; ++j) { - size_t offset = rnd_engine() % ret.size; - size_t size = rnd_engine() % (ret.size - offset); + size_t offset = simgrid::xbt::random::uniform_int(0, ret.size - 1); + size_t size = simgrid::xbt::random::uniform_int(0, ret.size - offset - 1); const void* read = ret.region->read(ret.dstn, (const char*)ret.src + offset, size); INFO("Mismatch in MC_region_read()"); REQUIRE(not memcmp((char*)ret.src + offset, read, size)); @@ -129,7 +122,6 @@ void snap_test_helper::read_region_parts() void snap_test_helper::compare_whole_region() { for (int n = 1; n != 32; ++n) { - prologue_return ret = prologue(n); INFO("Unexpected match in MC_snapshot_region_memcmp() with previous snapshot"); @@ -145,12 +137,11 @@ void snap_test_helper::compare_whole_region() void snap_test_helper::compare_region_parts() { for (int n = 1; n != 32; ++n) { - prologue_return ret = prologue(n); for (int j = 0; j != 100; ++j) { - size_t offset = rnd_engine() % ret.size; - size_t size = rnd_engine() % (ret.size - offset); + size_t offset = simgrid::xbt::random::uniform_int(0, ret.size - 1); + size_t size = simgrid::xbt::random::uniform_int(0, ret.size - offset - 1); 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, @@ -165,25 +156,22 @@ void snap_test_helper::compare_region_parts() void snap_test_helper::read_pointer() { - prologue_return ret = prologue(1); memcpy(ret.src, &mc_model_checker, sizeof(void*)); - simgrid::mc::Region* region2 = new simgrid::mc::Region(simgrid::mc::RegionType::Data, ret.src, ret.size); + const simgrid::mc::Region region2(simgrid::mc::RegionType::Data, ret.src, ret.size); INFO("Mismtach in MC_region_read_pointer()"); - REQUIRE(MC_region_read_pointer(region2, ret.src) == mc_model_checker); + REQUIRE(MC_region_read_pointer(®ion2, ret.src) == mc_model_checker); munmap(ret.dstn, ret.size); munmap(ret.src, ret.size); delete ret.region0; delete ret.region; - delete region2; } /*************** End: class snap_test_helper *****************************/ TEST_CASE("MC::Snapshot: A copy/snapshot of a given memory region", "MC::Snapshot") { - INFO("Sparse snapshot (using pages)"); snap_test_helper::Init();