X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/3a1ea70a418f393ca1677074e928c664022295bd..c4da7e409e2f6d39b72ea32f61d04da85a126a28:/src/mc/sosp/Snapshot_test.cpp diff --git a/src/mc/sosp/Snapshot_test.cpp b/src/mc/sosp/Snapshot_test.cpp index 63c114cdde..0883e1ea8c 100644 --- a/src/mc/sosp/Snapshot_test.cpp +++ b/src/mc/sosp/Snapshot_test.cpp @@ -1,9 +1,9 @@ -/* Copyright (c) 2014-2020. 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" @@ -15,16 +15,19 @@ /**************** Class BOOST_tests *************************/ using simgrid::mc::Region; class snap_test_helper { + static simgrid::mc::PageStore page_store_; + static std::unique_ptr memory_; + 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(); @@ -32,17 +35,12 @@ public: static void compare_region_parts(); static void read_pointer(); - static void cleanup() - { - delete mc_model_checker; - mc_model_checker = nullptr; - } - - static std::unique_ptr process; + static void cleanup() { memory_ = nullptr; } }; // static member variables init. -std::unique_ptr snap_test_helper::process = nullptr; +simgrid::mc::PageStore snap_test_helper::page_store_(500); +std::unique_ptr snap_test_helper::memory_ = nullptr; void snap_test_helper::init_memory(void* mem, size_t size) { @@ -57,9 +55,8 @@ void snap_test_helper::Init() REQUIRE(xbt_pagesize == getpagesize()); REQUIRE(1 << xbt_pagebits == xbt_pagesize); - process = std::make_unique(getpid()); - process->init(); - mc_model_checker = new ::simgrid::mc::ModelChecker(std::move(process), -1); + memory_ = std::make_unique(getpid()); + memory_->init(nullptr); } snap_test_helper::prologue_return snap_test_helper::prologue(int n) @@ -67,26 +64,23 @@ 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); - auto* region0 = new simgrid::mc::Region(simgrid::mc::RegionType::Data, source, byte_size); + auto* region0 = + new simgrid::mc::Region(page_store_, *memory_.get(), simgrid::mc::RegionType::Data, source, byte_size); for (int i = 0; i < n; i += 2) { init_memory((char*)source + i * xbt_pagesize, xbt_pagesize); } - auto* region = new simgrid::mc::Region(simgrid::mc::RegionType::Data, source, byte_size); + auto* region = new simgrid::mc::Region(page_store_, *memory_.get(), 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() @@ -158,19 +152,20 @@ void snap_test_helper::compare_region_parts() } } +int some_global_variable = 42; +void* some_global_pointer = &some_global_variable; void snap_test_helper::read_pointer() { prologue_return ret = prologue(1); - memcpy(ret.src, &mc_model_checker, sizeof(void*)); - const simgrid::mc::Region* region2 = new simgrid::mc::Region(simgrid::mc::RegionType::Data, ret.src, ret.size); + memcpy(ret.src, &some_global_pointer, sizeof(void*)); + const simgrid::mc::Region region2(page_store_, *memory_.get(), 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) == some_global_pointer); munmap(ret.dstn, ret.size); munmap(ret.src, ret.size); delete ret.region0; delete ret.region; - delete region2; } /*************** End: class snap_test_helper *****************************/