1 /* Copyright (c) 2008-2018. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
10 * Some of the '#include's should not be here
12 * 2. Add a header file for 'mc_checkpoint.cpp'
13 * so that we can test the functions in 'mc_checkpoint.cpp'
27 #include "src/internal_config.h"
28 #include "src/mc/mc_private.hpp"
29 #include "src/smpi/include/private.hpp"
30 #include "xbt/file.hpp"
31 #include "xbt/mmalloc.h"
32 #include "xbt/module.h"
34 #include "src/xbt/mmalloc/mmprivate.h"
36 #include "src/simix/smx_private.hpp"
38 #include <libunwind.h>
41 #include "src/mc/mc_private.hpp"
44 #include "src/mc/mc_config.hpp"
45 #include "src/mc/mc_hash.hpp"
46 #include "src/mc/mc_mmu.hpp"
47 #include "src/mc/mc_smx.hpp"
48 #include "src/mc/mc_snapshot.hpp"
49 #include "src/mc/mc_unw.hpp"
50 #include "src/mc/remote/mc_protocol.h"
52 #include "src/mc/RegionSnapshot.hpp"
53 #include "src/mc/ObjectInformation.hpp"
54 #include "src/mc/Frame.hpp"
55 #include "src/mc/Variable.hpp"
60 #define BOOST_TEST_MODULE checkpoint
61 #define BOOST_TEST_DYN_LINK
62 #include <boost/test/unit_test.hpp>
64 #include <stdio.h> // perror()
65 #include <errno.h> // perror()
66 #include <stdlib.h> // exit()
75 void add_content(void*, int, size_t);
76 size_t make_hash(char*);
78 int add_region_BOOST()
81 RemoteClient* this_process = new RemoteClient(getpid(), -1);
82 /* read /proc/getpid()/maps into "this_process->memory_map", etc. */
84 simgrid::mc::Snapshot* snapshot = new simgrid::mc::Snapshot(this_process, 0); // first ckpt
85 simgrid::mc::RegionType type = simgrid::mc::RegionType::Unknown;
86 std::size_t PAGESIZE = 4096;
87 std::size_t region_num = 10;
88 std::size_t size = PAGESIZE * region_num;
90 int prot = PROT_READ|PROT_WRITE;
91 int flags = MAP_PRIVATE|MAP_ANONYMOUS;
92 if (mmap(addr, size, prot, flags, -1, 0) == (void *)-1) {
96 size_t hashes[region_num];
98 for(int i=0; i<region_num; ++i) {
99 source = (char*)addr + i*PAGESIZE;
100 add_content(source, i, PAGESIZE);
101 add_region(i, snaphot, type, NULL, source, source, size);
104 BOOST_TEST((snapshot->snapshot_regions).size == 10, "snapshot_regions size");
105 /* test retrieving regions from a snapshot*/
108 for (int i=2; i<region_num; ++) {
109 /* hashes of even regions should be equal
110 and hashes of odd regions should also be equal. */
111 src1 = (snapshot->snapshot_regions[i])->start_addr_;
112 src2 = (snapshot->snapshot_regions[i-2])->start_addr_;
113 BOOST_TEST(make_hash((char*)src1) == make_hash((char*)src2), "retrieval failed");
116 /* release memory before returning */
117 if (munmap(addr, size) == -1) {
121 return 1; // just for testing
126 BOOST_AUTO_TEST_SUITE(checkpoint)
127 BOOST_AUTO_TEST_CASE(add_region_test) {
128 BOOST_TEST(add_region_BOOST() == 1);
130 BOOST_AUTO_TEST_SUITE_END()
132 void add_content(void* addr, int index, size_t size) {
133 memset(addr, index%2+1, size);
134 memset(addr+size-1, 0, 1); // NULL-termination
137 st::hash<std::string> str_hash;
138 void make_hash(char* addr) {
139 return str_hash(string(addr));
142 #endif // SIMGRID_TEST