X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/f23b0fb864cb60978c1fcfd48d50f62dd054fe31..2d2995483b57463581ffdc4365fe1999ddc306c2:/src/mc/snapshot/unitTest/PageStore_unit.cpp diff --git a/src/mc/snapshot/unitTest/PageStore_unit.cpp b/src/mc/snapshot/unitTest/PageStore_unit.cpp index bf4b36eec7..6a33e9e4c6 100644 --- a/src/mc/snapshot/unitTest/PageStore_unit.cpp +++ b/src/mc/snapshot/unitTest/PageStore_unit.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2014-2018. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2015-2018. 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. */ @@ -7,18 +7,6 @@ #define BOOST_TEST_DYN_LINK #include -// /*******************************/ -// /* GENERATED FILE, DO NOT EDIT */ -// /*******************************/ -// -// #include -// #include "xbt.h" -// /*******************************/ -// /* GENERATED FILE, DO NOT EDIT */ -// /*******************************/ -// -// #line 191 "mc/PageStore.cpp" - #include #include #include @@ -28,57 +16,119 @@ #include -#include "src/mc/PageStore.hpp" - -static int value = 0; - -static void new_content(void* data, std::size_t size) -{ - ::memset(data, ++value, size); -} - -static void* getpage() -{ - return mmap(nullptr, getpagesize(), PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); -} - -BOOST_AUTO_TEST_CASE(pageStore) { - - using simgrid::mc::PageStore; - - std::cout << "Test adding/removing pages in the store" << std::endl; - - std::size_t pagesize = (size_t) getpagesize(); - std::unique_ptr store = std::unique_ptr(new simgrid::mc::PageStore(500)); - void* data = getpage(); +#include "src/mc/sosp/PageStore.hpp" + +using simgrid::mc::PageStore; + +/***********************************/ +// a class to hold the variable used in the test cases +class BOOST_tests { + public: + static std::size_t pagesize; + static std::unique_ptr store; + static void* data; + static size_t pageno1, pageno2, pageno3, pageno4; + static int value; + public: // member functions used by the test suite(s) + static void Init(); + static void store_page_once(); + static void store_same_page(); + static void store_new_page(); + static void unref_pages(); + static void reallocate_page(); + + static void new_content(void* data, std::size_t size); + static void* getpage(); +}; + +// static member datat initialization +std::size_t BOOST_tests::pagesize = 0; +std::unique_ptr BOOST_tests::store = nullptr; +void* BOOST_tests::data = nullptr; +size_t BOOST_tests::pageno1 = 0; +size_t BOOST_tests::pageno2 = 0; +size_t BOOST_tests::pageno3 = 0; +size_t BOOST_tests::pageno4 = 0; +int BOOST_tests::value = 0; + +void BOOST_tests::Init() { + pagesize = (size_t) getpagesize(); + store = std::unique_ptr(new simgrid::mc::PageStore(500)); + data = getpage(); BOOST_CHECK_MESSAGE(store->size()==0, "Bad size"); +} +void BOOST_tests::store_page_once() { new_content(data, pagesize); - size_t pageno1 = store->store_page(data); + pageno1 = store->store_page(data); BOOST_CHECK_MESSAGE(store->get_ref(pageno1)==1, "Bad refcount"); const void* copy = store->get_page(pageno1); BOOST_CHECK_MESSAGE(::memcmp(data, copy, pagesize)==0, "Page data should be the same"); BOOST_CHECK_MESSAGE(store->size()==1, "Bad size"); +} - size_t pageno2 = store->store_page(data); +void BOOST_tests::store_same_page() { + pageno2 = store->store_page(data); BOOST_CHECK_MESSAGE(pageno1==pageno2, "Page should be the same"); BOOST_CHECK_MESSAGE(store->get_ref(pageno1)==2, "Bad refcount"); BOOST_CHECK_MESSAGE(store->size()==1, "Bad size"); +} +void BOOST_tests::store_new_page() { new_content(data, pagesize); - size_t pageno3 = store->store_page(data); + pageno3 = store->store_page(data); BOOST_CHECK_MESSAGE(pageno1 != pageno3, "New page should be different"); BOOST_CHECK_MESSAGE(store->size()==2, "Bad size"); +} +void BOOST_tests::unref_pages() { store->unref_page(pageno1); BOOST_CHECK_MESSAGE(store->get_ref(pageno1)==1, "Bad refcount"); BOOST_CHECK_MESSAGE(store->size()==2, "Bad size"); store->unref_page(pageno2); BOOST_CHECK_MESSAGE(store->size()==1, "Bad size"); +} +void BOOST_tests::reallocate_page() { new_content(data, pagesize); - size_t pageno4 = store->store_page(data); + pageno4 = store->store_page(data); BOOST_CHECK_MESSAGE(pageno1 == pageno4, "Page was not reused"); BOOST_CHECK_MESSAGE(store->get_ref(pageno4)==1, "Bad refcount"); BOOST_CHECK_MESSAGE(store->size()==2, "Bad size"); } + +void BOOST_tests::new_content(void* data, std::size_t size) { + ::memset(data, ++value, size); +} + +void* BOOST_tests::getpage() { + return mmap(nullptr, getpagesize(), PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); +} + +namespace utf = boost::unit_test; // for test case dependence + +BOOST_AUTO_TEST_SUITE(PAGESTORE) +BOOST_AUTO_TEST_CASE(Init) { + BOOST_tests::Init(); +} + +BOOST_AUTO_TEST_CASE(store_page_once, * utf::depends_on("PAGESTORE/Init")) { + BOOST_tests::store_page_once(); +} + +BOOST_AUTO_TEST_CASE(store_same_page, * utf::depends_on("PAGESTORE/store_page_once")) { + BOOST_tests::store_same_page(); +} + +BOOST_AUTO_TEST_CASE(store_new_page, * utf::depends_on("PAGESTORE/store_same_page")) { + BOOST_tests::store_new_page(); +} + +BOOST_AUTO_TEST_CASE(unref_pages, * utf::depends_on("PAGESTORE/store_new_page")) { + BOOST_tests::unref_pages(); +} + +BOOST_AUTO_TEST_CASE(reallocate_page, * utf::depends_on("PAGESTORE/unref_pages")) { + BOOST_tests::reallocate_page(); +} +BOOST_AUTO_TEST_SUITE_END()