From 38bce2fa8a8e830d31ae32dff044c0e471d5a028 Mon Sep 17 00:00:00 2001 From: Gabriel Corona Date: Thu, 7 Jan 2016 15:47:30 +0100 Subject: [PATCH] Make XBT_TEST_UNIT() work in C++ testall.c expects the unit test functions (XBT_TEST_UNIT()) to use the C linkage "C" so we have to define them so. Before this commit, they had to be manually placed in a extern "C" {} block. --- include/xbt/cunit.h | 7 ++++++- src/mc/PageStore.cpp | 4 ---- src/mc/mc_snapshot.cpp | 7 ++----- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/include/xbt/cunit.h b/include/xbt/cunit.h index 7a3c876b17..9da1a246b0 100644 --- a/include/xbt/cunit.h +++ b/include/xbt/cunit.h @@ -117,10 +117,15 @@ XBT_PUBLIC(void) xbt_test_exit(void); * @param func a valid function name that will be used to contain all code of this unit * @param title human informative description of your test (displayed in testall) */ +#ifdef __cplusplus +#define XBT_TEST_UNIT(name,func,title) \ + extern "C" void func(void); /*prototype*/ \ + void func(void) +#else #define XBT_TEST_UNIT(name,func,title) \ void func(void); /*prototype*/ \ void func(void) - +#endif /* test operations */ XBT_PUBLIC(void) _xbt_test_add(const char *file, int line, const char *fmt, diff --git a/src/mc/PageStore.cpp b/src/mc/PageStore.cpp index 0c33726b21..f5d769769a 100644 --- a/src/mc/PageStore.cpp +++ b/src/mc/PageStore.cpp @@ -185,8 +185,6 @@ static void* getpage() return mmap(NULL, getpagesize(), PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); } -extern "C" { - XBT_TEST_SUITE("mc_page_store", "Page store"); XBT_TEST_UNIT("base", test_mc_page_store, "Test adding/removing pages in the store") @@ -235,8 +233,6 @@ XBT_TEST_UNIT("base", test_mc_page_store, "Test adding/removing pages in the sto xbt_test_assert(store->size()==2, "Bad size"); } -} - #endif /* SIMGRID_TEST */ } diff --git a/src/mc/mc_snapshot.cpp b/src/mc/mc_snapshot.cpp index 23be00f669..2d534f516e 100644 --- a/src/mc/mc_snapshot.cpp +++ b/src/mc/mc_snapshot.cpp @@ -191,6 +191,8 @@ const void* Snapshot::read_bytes(void* buffer, std::size_t size, } } +} + #ifdef SIMGRID_TEST #include @@ -202,8 +204,6 @@ const void* Snapshot::read_bytes(void* buffer, std::size_t size, #include "src/mc/mc_snapshot.h" #include "src/mc/mc_mmu.h" -extern "C" { - XBT_TEST_SUITE("mc_snapshot", "Snapshots"); static inline void init_memory(void* mem, size_t size) @@ -297,8 +297,5 @@ static void test_snapshot(bool sparse_checkpoint) { mc_model_checker = NULL; } -} - #endif /* SIMGRID_TEST */ -} -- 2.20.1