X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/5d54bb6496d427fbc8287da8eeecc600a5f7ce15..cd8cf3e33c5e55c7daa82efd1445475f4574eb92:/src/mc/sosp/PageStore_test.cpp diff --git a/src/mc/sosp/PageStore_test.cpp b/src/mc/sosp/PageStore_test.cpp index 9f93fb7d94..8de5bc98e6 100644 --- a/src/mc/sosp/PageStore_test.cpp +++ b/src/mc/sosp/PageStore_test.cpp @@ -1,14 +1,11 @@ -/* Copyright (c) 2015-2018. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2015-2023. 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. */ -#define BOOST_TEST_MODULE PAGESTORE -#define BOOST_TEST_DYN_LINK - -bool init_unit_test(); // boost sometimes forget to give this prototype (NetBSD and other), which does not fit our paranoid flags -#include +#include "src/3rd-party/catch.hpp" +#include #include #include #include @@ -20,129 +17,102 @@ bool init_unit_test(); // boost sometimes forget to give this prototype (NetBSD #include "src/mc/sosp/PageStore.hpp" -using simgrid::mc::PageStore; - /***********************************/ // a class to hold the variable used in the test cases -class BOOST_tests { +class pstore_test_helper { + const size_t pagesize = getpagesize(); + simgrid::mc::PageStore store{50}; + std::byte* data = + static_cast(mmap(nullptr, pagesize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0)); + std::array pageno = {0, 0, 0, 0}; + int value = 0; + + void new_content(std::byte* buf, size_t size); + public: - static std::size_t pagesize; - static std::unique_ptr store; - static void* data; - static size_t pageno[4]; - 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(); + // member functions used by the test suite(s) + void init(); + void store_page_once(); + void store_same_page(); + void store_new_page(); + void unref_pages(); + void reallocate_page(); }; -// 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::pageno[4] = {0, 0, 0, 0}; -int BOOST_tests::value = 0; - -void BOOST_tests::Init() +void pstore_test_helper::init() { - pagesize = (size_t)getpagesize(); - store = std::unique_ptr(new simgrid::mc::PageStore(500)); - data = getpage(); - BOOST_CHECK_MESSAGE(store->size() == 0, "Bad size"); + REQUIRE(data != nullptr); + REQUIRE(store.size() == 0); } -void BOOST_tests::store_page_once() +void pstore_test_helper::store_page_once() { new_content(data, pagesize); - pageno[0] = store->store_page(data); - BOOST_CHECK_MESSAGE(store->get_ref(pageno[0]) == 1, "Bad refcount"); - const void* copy = store->get_page(pageno[0]); - BOOST_CHECK_MESSAGE(::memcmp(data, copy, pagesize) == 0, "Page data should be the same"); - BOOST_CHECK_MESSAGE(store->size() == 1, "Bad size"); + pageno[0] = store.store_page(data); + REQUIRE(store.get_ref(pageno[0]) == 1); + const auto* copy = store.get_page(pageno[0]); + REQUIRE(::memcmp(data, copy, pagesize) == 0); // The page data should be the same + REQUIRE(store.size() == 1); } -void BOOST_tests::store_same_page() +void pstore_test_helper::store_same_page() { - pageno[1] = store->store_page(data); - BOOST_CHECK_MESSAGE(pageno[0] == pageno[1], "Page should be the same"); - BOOST_CHECK_MESSAGE(store->get_ref(pageno[0]) == 2, "Bad refcount"); - BOOST_CHECK_MESSAGE(store->size() == 1, "Bad size"); + pageno[1] = store.store_page(data); + REQUIRE(pageno[0] == pageno[1]); // Page should be the same + REQUIRE(store.get_ref(pageno[0]) == 2); + REQUIRE(store.size() == 1); } -void BOOST_tests::store_new_page() +void pstore_test_helper::store_new_page() { new_content(data, pagesize); - pageno[2] = store->store_page(data); - BOOST_CHECK_MESSAGE(pageno[0] != pageno[2], "New page should be different"); - BOOST_CHECK_MESSAGE(store->size() == 2, "Bad size"); + pageno[2] = store.store_page(data); + REQUIRE(pageno[0] != pageno[2]); // The new page should be different + REQUIRE(store.size() == 2); } -void BOOST_tests::unref_pages() +void pstore_test_helper::unref_pages() { - store->unref_page(pageno[0]); - BOOST_CHECK_MESSAGE(store->get_ref(pageno[0]) == 1, "Bad refcount"); - BOOST_CHECK_MESSAGE(store->size() == 2, "Bad size"); - store->unref_page(pageno[1]); - BOOST_CHECK_MESSAGE(store->size() == 1, "Bad size"); -} + store.unref_page(pageno[0]); + REQUIRE(store.get_ref(pageno[0]) == 1); + REQUIRE(store.size() == 2); -void BOOST_tests::reallocate_page() -{ - new_content(data, pagesize); - pageno[3] = store->store_page(data); - BOOST_CHECK_MESSAGE(pageno[0] == pageno[3], "Page was not reused"); - BOOST_CHECK_MESSAGE(store->get_ref(pageno[3]) == 1, "Bad refcount"); - BOOST_CHECK_MESSAGE(store->size() == 2, "Bad size"); + store.unref_page(pageno[1]); + REQUIRE(store.size() == 1); } -void BOOST_tests::new_content(void* data, std::size_t size) +void pstore_test_helper::reallocate_page() { - ::memset(data, ++value, size); + new_content(data, pagesize); + pageno[3] = store.store_page(data); + REQUIRE(pageno[0] == pageno[3]); // The old page should be reused + REQUIRE(store.get_ref(pageno[3]) == 1); + REQUIRE(store.size() == 2); } -void* BOOST_tests::getpage() +void pstore_test_helper::new_content(std::byte* buf, size_t size) { - return mmap(nullptr, getpagesize(), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + value++; + std::fill_n(buf, size, static_cast(value)); } -namespace utf = boost::unit_test; // for test case dependence - -BOOST_AUTO_TEST_SUITE(PAGESTORE) -BOOST_AUTO_TEST_CASE(Init) +TEST_CASE("MC page store, used during checkpoint", "MC::PageStore") { - BOOST_tests::Init(); -} + pstore_test_helper pstore_test; + pstore_test.init(); -BOOST_AUTO_TEST_CASE(store_page_once, *utf::depends_on("PAGESTORE/Init")) -{ - BOOST_tests::store_page_once(); -} + INFO("Store page once"); + pstore_test.store_page_once(); -BOOST_AUTO_TEST_CASE(store_same_page, *utf::depends_on("PAGESTORE/store_page_once")) -{ - BOOST_tests::store_same_page(); -} + INFO("Store the same page"); + pstore_test.store_same_page(); -BOOST_AUTO_TEST_CASE(store_new_page, *utf::depends_on("PAGESTORE/store_same_page")) -{ - BOOST_tests::store_new_page(); -} + INFO("Store a new page"); + pstore_test.store_new_page(); -BOOST_AUTO_TEST_CASE(unref_pages, *utf::depends_on("PAGESTORE/store_new_page")) -{ - BOOST_tests::unref_pages(); -} + INFO("Unref pages"); + pstore_test.unref_pages(); -BOOST_AUTO_TEST_CASE(reallocate_page, *utf::depends_on("PAGESTORE/unref_pages")) -{ - BOOST_tests::reallocate_page(); + INFO("Reallocate pages"); + pstore_test.reallocate_page(); } -BOOST_AUTO_TEST_SUITE_END()