1 /*************************************************
3 *************************************************/
4 #define BOOST_TEST_MODULE snapshots
5 #define BOOST_TEST_DYN_LINK
6 #include <boost/test/unit_test.hpp>
9 // /*******************************/
10 // /* GENERATED FILE, DO NOT EDIT */
11 // /*******************************/
15 // /*******************************/
16 // /* GENERATED FILE, DO NOT EDIT */
17 // /*******************************/
19 // #line 180 "mc/mc_snapshot.cpp"
26 #include "src/mc/mc_config.hpp"
27 #include "src/mc/mc_mmu.hpp"
28 #include "src/mc/mc_private.hpp"
29 #include "src/mc/mc_snapshot.hpp"
32 static inline void init_memory(void* mem, size_t size)
34 char* dest = (char*) mem;
35 for (size_t i = 0; i < size; ++i) {
36 dest[i] = rand() & 255;
40 static int test_snapshot(bool sparse_checkpoint);
42 BOOST_AUTO_TEST_SUITE(Snapshots)
43 BOOST_AUTO_TEST_CASE(flat_snapshots) {
44 BOOST_CHECK_EQUAL(test_snapshot(0), 1);
46 BOOST_AUTO_TEST_CASE(page_snapshots) {
47 BOOST_CHECK_EQUAL(test_snapshot(1), 1);
49 BOOST_AUTO_TEST_SUITE_END()
51 static int test_snapshot(bool sparse_checkpoint) {
53 // xbt_test_add("Initialization");
54 _sg_mc_sparse_checkpoint = sparse_checkpoint;
55 BOOST_CHECK_EQUAL(xbt_pagesize, getpagesize());
56 BOOST_CHECK_EQUAL(1 << xbt_pagebits, xbt_pagesize);
58 std::unique_ptr<simgrid::mc::RemoteClient> process(new simgrid::mc::RemoteClient(getpid(), -1));
60 mc_model_checker = new ::simgrid::mc::ModelChecker(std::move(process));
62 for(int n=1; n!=256; ++n) {
64 // Store region page(s):
65 size_t byte_size = n * xbt_pagesize;
66 void* source = mmap(nullptr, byte_size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
67 BOOST_CHECK_MESSAGE(source!=MAP_FAILED, "Could not allocate source memory");
69 // Init memory and take snapshots:
70 init_memory(source, byte_size);
71 simgrid::mc::RegionSnapshot region0 = simgrid::mc::sparse_region(
72 simgrid::mc::RegionType::Unknown, source, source, byte_size);
73 for(int i=0; i<n; i+=2) {
74 init_memory((char*) source + i*xbt_pagesize, xbt_pagesize);
76 simgrid::mc::RegionSnapshot region = simgrid::mc::sparse_region(
77 simgrid::mc::RegionType::Unknown, source, source, byte_size);
79 void* destination = mmap(nullptr, byte_size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
80 BOOST_CHECK_MESSAGE(source!=MAP_FAILED, "Could not allocate destination memory");
82 // xbt_test_add("Reading whole region data for %i page(s)", n);
83 const void* read = MC_region_read(®ion, destination, source, byte_size);
84 BOOST_CHECK_MESSAGE(not memcmp(source, read, byte_size), "Mismatch in MC_region_read()");
86 // xbt_test_add("Reading parts of region data for %i page(s)", n);
87 for(int j=0; j!=100; ++j) {
88 size_t offset = rand() % byte_size;
89 size_t size = rand() % (byte_size - offset);
90 const void* read = MC_region_read(®ion, destination, (const char*) source+offset, size);
91 BOOST_CHECK_MESSAGE(not memcmp((char*)source + offset, read, size), "Mismatch in MC_region_read()");
94 // xbt_test_add("Compare whole region data for %i page(s)", n);
96 BOOST_CHECK_MESSAGE(MC_snapshot_region_memcmp(source, ®ion0, source, ®ion, byte_size),
97 "Unexpected match in MC_snapshot_region_memcmp() with previous snapshot");
99 // xbt_test_add("Compare parts of region data for %i page(s) with itself", n);
100 for(int j=0; j!=100; ++j) {
101 size_t offset = rand() % byte_size;
102 size_t size = rand() % (byte_size - offset);
104 not MC_snapshot_region_memcmp((char*)source + offset, ®ion, (char*)source + offset, ®ion, size),
105 "Mismatch in MC_snapshot_region_memcmp()");
109 // xbt_test_add("Read pointer for %i page(s)", n);
110 memcpy(source, &mc_model_checker, sizeof(void*));
111 simgrid::mc::RegionSnapshot region2 = simgrid::mc::sparse_region(
112 simgrid::mc::RegionType::Unknown, source, source, byte_size);
113 BOOST_CHECK_MESSAGE(MC_region_read_pointer(®ion2, source) == mc_model_checker,
114 "Mismtach in MC_region_read_pointer()");
117 munmap(destination, byte_size);
118 munmap(source, byte_size);
121 delete mc_model_checker;
122 mc_model_checker = nullptr;
124 return 1; // dummy value, for BOOST unit test
127 /*******************************/
128 /* GENERATED FILE, DO NOT EDIT */
129 /*******************************/