Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make XBT_TEST_UNIT() work in C++
authorGabriel Corona <gabriel.corona@loria.fr>
Thu, 7 Jan 2016 14:47:30 +0000 (15:47 +0100)
committerGabriel Corona <gabriel.corona@loria.fr>
Fri, 8 Jan 2016 10:42:06 +0000 (11:42 +0100)
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
src/mc/PageStore.cpp
src/mc/mc_snapshot.cpp

index 7a3c876..9da1a24 100644 (file)
@@ -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)
  */
  * @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)
 #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,
 
 /* test operations */
 XBT_PUBLIC(void) _xbt_test_add(const char *file, int line, const char *fmt,
index 0c33726..f5d7697 100644 (file)
@@ -185,8 +185,6 @@ static void* getpage()
   return mmap(NULL, getpagesize(), PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
 }
 
   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")
 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");
 }
 
   xbt_test_assert(store->size()==2, "Bad size");
 }
 
-}
-
 #endif /* SIMGRID_TEST */
 
 }
 #endif /* SIMGRID_TEST */
 
 }
index 23be00f..2d534f5 100644 (file)
@@ -191,6 +191,8 @@ const void* Snapshot::read_bytes(void* buffer, std::size_t size,
 }
 }
 
 }
 }
 
+}
+
 #ifdef SIMGRID_TEST
 
 #include <string.h>
 #ifdef SIMGRID_TEST
 
 #include <string.h>
@@ -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"
 
 #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)
 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;
 }
 
   mc_model_checker = NULL;
 }
 
-}
-
 #endif /* SIMGRID_TEST */
 
 #endif /* SIMGRID_TEST */
 
-}