1 /****************************************************
3 ****************************************************/
4 #define BOOST_TEST_MODULE PAGESTORE
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 191 "mc/PageStore.cpp"
29 #include "src/mc/PageStore.hpp"
33 static void new_content(void* data, std::size_t size)
35 ::memset(data, ++value, size);
38 static void* getpage()
40 return mmap(nullptr, getpagesize(), PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
43 BOOST_AUTO_TEST_CASE(pageStore) {
44 // XBT_TEST_UNIT("base", test_mc_page_store, "Test adding/removing pages in the store")
47 using simgrid::mc::PageStore;
49 std::cout << "Test adding/removing pages in the store" << std::endl;
51 // xbt_test_add("Init");
52 std::size_t pagesize = (size_t) getpagesize();
53 std::unique_ptr<PageStore> store = std::unique_ptr<PageStore>(new simgrid::mc::PageStore(500));
54 void* data = getpage();
55 BOOST_CHECK_MESSAGE(store->size()==0, "Bad size");
57 // xbt_test_add("Store the page once");
58 new_content(data, pagesize);
59 size_t pageno1 = store->store_page(data);
60 BOOST_CHECK_MESSAGE(store->get_ref(pageno1)==1, "Bad refcount");
61 const void* copy = store->get_page(pageno1);
62 BOOST_CHECK_MESSAGE(::memcmp(data, copy, pagesize)==0, "Page data should be the same");
63 BOOST_CHECK_MESSAGE(store->size()==1, "Bad size");
65 // xbt_test_add("Store the same page again");
66 size_t pageno2 = store->store_page(data);
67 BOOST_CHECK_MESSAGE(pageno1==pageno2, "Page should be the same");
68 BOOST_CHECK_MESSAGE(store->get_ref(pageno1)==2, "Bad refcount");
69 BOOST_CHECK_MESSAGE(store->size()==1, "Bad size");
71 // xbt_test_add("Store a new page");
72 new_content(data, pagesize);
73 size_t pageno3 = store->store_page(data);
74 BOOST_CHECK_MESSAGE(pageno1 != pageno3, "New page should be different");
75 BOOST_CHECK_MESSAGE(store->size()==2, "Bad size");
77 // xbt_test_add("Unref pages");
78 store->unref_page(pageno1);
79 BOOST_CHECK_MESSAGE(store->get_ref(pageno1)==1, "Bad refcount");
80 BOOST_CHECK_MESSAGE(store->size()==2, "Bad size");
81 store->unref_page(pageno2);
82 BOOST_CHECK_MESSAGE(store->size()==1, "Bad size");
84 // xbt_test_add("Reallocate page");
85 new_content(data, pagesize);
86 size_t pageno4 = store->store_page(data);
87 BOOST_CHECK_MESSAGE(pageno1 == pageno4, "Page was not reused");
88 BOOST_CHECK_MESSAGE(store->get_ref(pageno4)==1, "Bad refcount");
89 BOOST_CHECK_MESSAGE(store->size()==2, "Bad size");
92 /*******************************/
93 /* GENERATED FILE, DO NOT EDIT */
94 /*******************************/