1 /*************************************************
3 *************************************************/
4 #define BOOST_TEST_MODULE snapshots
5 #define BOOST_TEST_DYN_LINK
6 #include <boost/test/unit_test.hpp>
8 // /*******************************/
9 // /* GENERATED FILE, DO NOT EDIT */
10 // /*******************************/
14 // /*******************************/
15 // /* GENERATED FILE, DO NOT EDIT */
16 // /*******************************/
18 // #line 180 "mc/mc_snapshot.cpp"
25 #include "simgrid/src/mc/mc_config.hpp"
26 #include "simgrid/src/mc/mc_mmu.hpp"
27 #include "simgrid/src/mc/mc_private.hpp"
28 #include "simgrid/src/mc/mc_snapshot.hpp"
31 static inline void init_memory(void* mem, size_t size)
33 char* dest = (char*) mem;
34 for (size_t i = 0; i < size; ++i) {
35 dest[i] = rand() & 255;
39 static int test_snapshot(bool sparse_checkpoint);
41 BOOST_AUTO_TEST_SUITE(Snapshots)
42 BOOST_AUTO_TEST_CASE(flat_snapshots) {
43 BOOST_TEST(test_snapshot(0) == 1);
45 BOOST_AUTO_TEST_CASE(page_snapshots) {
46 BOOST_TEST(test_snapshot(1) == 1);
48 BOOST_AUTO_TEST_SUITE_END()
50 static int test_snapshot(bool sparse_checkpoint) {
52 // xbt_test_add("Initialization");
53 _sg_mc_sparse_checkpoint = sparse_checkpoint;
54 BOOST_TEST(xbt_pagesize == getpagesize());
55 BOOST_TEST(1 << xbt_pagebits == xbt_pagesize);
57 std::unique_ptr<simgrid::mc::RemoteClient> process(new simgrid::mc::RemoteClient(getpid(), -1));
59 mc_model_checker = new ::simgrid::mc::ModelChecker(std::move(process));
61 for(int n=1; n!=256; ++n) {
63 // Store region page(s):
64 size_t byte_size = n * xbt_pagesize;
65 void* source = mmap(nullptr, byte_size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
66 BOOST_TEST(source!=MAP_FAILED, "Could not allocate source memory");
68 // Init memory and take snapshots:
69 init_memory(source, byte_size);
70 simgrid::mc::RegionSnapshot region0 = simgrid::mc::sparse_region(
71 simgrid::mc::RegionType::Unknown, source, source, byte_size);
72 for(int i=0; i<n; i+=2) {
73 init_memory((char*) source + i*xbt_pagesize, xbt_pagesize);
75 simgrid::mc::RegionSnapshot region = simgrid::mc::sparse_region(
76 simgrid::mc::RegionType::Unknown, source, source, byte_size);
78 void* destination = mmap(nullptr, byte_size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
79 BOOST_TEST(source!=MAP_FAILED, "Could not allocate destination memory");
81 // xbt_test_add("Reading whole region data for %i page(s)", n);
82 const void* read = MC_region_read(®ion, destination, source, byte_size);
83 BOOST_TEST(not memcmp(source, read, byte_size), "Mismatch in MC_region_read()");
85 // xbt_test_add("Reading parts of region data for %i page(s)", n);
86 for(int j=0; j!=100; ++j) {
87 size_t offset = rand() % byte_size;
88 size_t size = rand() % (byte_size - offset);
89 const void* read = MC_region_read(®ion, destination, (const char*) source+offset, size);
90 BOOST_TEST(not memcmp((char*)source + offset, read, size), "Mismatch in MC_region_read()");
93 // xbt_test_add("Compare whole region data for %i page(s)", n);
95 BOOST_TEST(MC_snapshot_region_memcmp(source, ®ion0, source, ®ion, byte_size),
96 "Unexpected match in MC_snapshot_region_memcmp() with previous snapshot");
98 // xbt_test_add("Compare parts of region data for %i page(s) with itself", n);
99 for(int j=0; j!=100; ++j) {
100 size_t offset = rand() % byte_size;
101 size_t size = rand() % (byte_size - offset);
103 not MC_snapshot_region_memcmp((char*)source + offset, ®ion, (char*)source + offset, ®ion, size),
104 "Mismatch in MC_snapshot_region_memcmp()");
108 // xbt_test_add("Read pointer for %i page(s)", n);
109 memcpy(source, &mc_model_checker, sizeof(void*));
110 simgrid::mc::RegionSnapshot region2 = simgrid::mc::sparse_region(
111 simgrid::mc::RegionType::Unknown, source, source, byte_size);
112 BOOST_TEST(MC_region_read_pointer(®ion2, source) == mc_model_checker,
113 "Mismtach in MC_region_read_pointer()");
116 munmap(destination, byte_size);
117 munmap(source, byte_size);
120 delete mc_model_checker;
121 mc_model_checker = nullptr;
123 return 1; // dummy value, for BOOST unit test
126 /*******************************/
127 /* GENERATED FILE, DO NOT EDIT */
128 /*******************************/