From 8a58552a82a0c4c5f74126540a9548b068e91b4b Mon Sep 17 00:00:00 2001 From: onesphore Date: Thu, 28 Jun 2018 14:07:42 +0200 Subject: [PATCH] Fragmented the tests into smaller test cases. --- src/mc/snapshot/unitTest/PageStore_unit.cpp | 127 ++++++--- src/mc/snapshot/unitTest/mc_snapshot_unit.cpp | 252 ++++++++++++++---- tools/cmake/Tests.cmake | 11 - 3 files changed, 282 insertions(+), 108 deletions(-) diff --git a/src/mc/snapshot/unitTest/PageStore_unit.cpp b/src/mc/snapshot/unitTest/PageStore_unit.cpp index bf4b36eec7..2c5e870dca 100644 --- a/src/mc/snapshot/unitTest/PageStore_unit.cpp +++ b/src/mc/snapshot/unitTest/PageStore_unit.cpp @@ -1,4 +1,5 @@ -/* 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 +8,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 @@ -30,55 +19,117 @@ #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(); +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() diff --git a/src/mc/snapshot/unitTest/mc_snapshot_unit.cpp b/src/mc/snapshot/unitTest/mc_snapshot_unit.cpp index 4230b0b8ff..b2698ea549 100644 --- a/src/mc/snapshot/unitTest/mc_snapshot_unit.cpp +++ b/src/mc/snapshot/unitTest/mc_snapshot_unit.cpp @@ -17,89 +17,223 @@ #include "src/mc/mc_private.hpp" #include "src/mc/mc_snapshot.hpp" -static inline void init_memory(void* mem, size_t size) -{ +/**************** Class BOOST_tests *************************/ +using simgrid::mc::RegionSnapshot; +class BOOST_tests { + public: + static void init_memory(void* mem, size_t size); + static void Init(bool sparse_ckpt); + typedef struct { + size_t size; + void* src; + void* dstn; + RegionSnapshot region0; + RegionSnapshot region; + } prologue_return; + static prologue_return prologue(int n); + static void epilogue(); // common to the below 5 fxs + static void read_whole_region(); + static void read_region_parts(); + static void compare_whole_region(); + static void compare_region_parts(); + static void read_pointer(); + + static void cleanup() { + delete mc_model_checker; + mc_model_checker = nullptr; + } + + public: + static bool sparse_checkpoint; + static std::unique_ptr process; +}; + +// static member variables init. +bool BOOST_tests::sparse_checkpoint = 0; +std::unique_ptr BOOST_tests::process = nullptr; + +void +BOOST_tests::init_memory(void* mem, size_t size) { char* dest = (char*) mem; for (size_t i = 0; i < size; ++i) { dest[i] = rand() & 255; } } -static int test_snapshot(bool sparse_checkpoint); - -BOOST_AUTO_TEST_SUITE(Snapshots) -BOOST_AUTO_TEST_CASE(flat_snapshots) { - test_snapshot(0); -} -BOOST_AUTO_TEST_CASE(page_snapshots) { - test_snapshot(1); -} -BOOST_AUTO_TEST_SUITE_END() - -static int test_snapshot(bool sparse_checkpoint) { - - _sg_mc_sparse_checkpoint = sparse_checkpoint; +void +BOOST_tests::Init(bool sparse_ckpt) { + _sg_mc_sparse_checkpoint = sparse_ckpt; BOOST_CHECK_EQUAL(xbt_pagesize, getpagesize()); BOOST_CHECK_EQUAL(1 << xbt_pagebits, xbt_pagesize); - std::unique_ptr process(new simgrid::mc::RemoteClient(getpid(), -1)); + process = std::unique_ptr(new simgrid::mc::RemoteClient(getpid(), -1)); process->init(); mc_model_checker = new ::simgrid::mc::ModelChecker(std::move(process)); +} + + +BOOST_tests::prologue_return BOOST_tests::prologue(int n) { + // Store region page(s): + size_t byte_size = n * xbt_pagesize; + void* source = mmap(nullptr, byte_size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); + BOOST_CHECK_MESSAGE(source!=MAP_FAILED, "Could not allocate source memory"); + // Init memory and take snapshots: + init_memory(source, byte_size); + simgrid::mc::RegionSnapshot region0 = simgrid::mc::sparse_region( + simgrid::mc::RegionType::Unknown, source, source, byte_size); + for(int i=0; i