Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add a basic tesh test about mmalloc
authorMartin Quinson <martin.quinson@loria.fr>
Mon, 8 Oct 2012 21:14:02 +0000 (23:14 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Mon, 8 Oct 2012 21:14:02 +0000 (23:14 +0200)
teshsuite/xbt/CMakeLists.txt
teshsuite/xbt/mmalloc.tesh [new file with mode: 0644]
teshsuite/xbt/mmalloc_test.c [moved from src/xbt/mmalloc/test/mmalloc_test.c with 60% similarity]

index 06873e6..0a26855 100644 (file)
@@ -4,14 +4,17 @@ set(EXECUTABLE_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}")
 
 add_executable(log_large_test log_large_test.c)
 add_executable(parallel_log_crashtest parallel_log_crashtest.c)
 
 add_executable(log_large_test log_large_test.c)
 add_executable(parallel_log_crashtest parallel_log_crashtest.c)
+add_executable(mmalloc_test mmalloc_test.c)
 
 ### Add definitions for compile
 if(NOT WIN32)
   target_link_libraries(log_large_test gras m pthread )
   target_link_libraries(parallel_log_crashtest gras m pthread )
 
 ### Add definitions for compile
 if(NOT WIN32)
   target_link_libraries(log_large_test gras m pthread )
   target_link_libraries(parallel_log_crashtest gras m pthread )
+  target_link_libraries(mmalloc_test gras m pthread )
 else(NOT WIN32)
   target_link_libraries(log_large_test gras)
   target_link_libraries(parallel_log_crashtest gras)
 else(NOT WIN32)
   target_link_libraries(log_large_test gras)
   target_link_libraries(parallel_log_crashtest gras)
+  target_link_libraries(mmalloc_test gras)
 endif(NOT WIN32)
 
 set(tesh_files
 endif(NOT WIN32)
 
 set(tesh_files
diff --git a/teshsuite/xbt/mmalloc.tesh b/teshsuite/xbt/mmalloc.tesh
new file mode 100644 (file)
index 0000000..d45a542
--- /dev/null
@@ -0,0 +1 @@
+$ ./mmalloc_test 
similarity index 60%
rename from src/xbt/mmalloc/test/mmalloc_test.c
rename to teshsuite/xbt/mmalloc_test.c
index 59c4a24..8606e3a 100644 (file)
@@ -1,4 +1,4 @@
-#include "../mmalloc.h"
+#include "xbt/mmalloc.h"
 #include <stdio.h>
 #include <assert.h>
 #include <fcntl.h>
 #include <stdio.h>
 #include <assert.h>
 #include <fcntl.h>
 
 int main()
 {
 
 int main()
 {
-  void *A, *B;
-  int fd1, fd2;
-  void *heapA, *heapB;
+  void *heapA;
   void *pointers[TESTSIZE];
   void *pointers[TESTSIZE];
-/*
-  unlink("heap1");
-  fd1=open("heap1",O_CREAT|O_RDWR,S_IRWXU|S_IRWXG|S_IRWXO);
-  assert(fd1>0);
-    close(fd1);
-    fd1=open("heap1",O_RDWR);
-    assert(fd1>0);
-  */
+  srand(0); // we need the test to be reproducible
 
 
-  heapA = xbt_mheap_new(-1, sbrk(0) + BUFFSIZE);
+  heapA = xbt_mheap_new(-1, ((char*)sbrk(0)) + BUFFSIZE);
   if (heapA == NULL) {
     perror("attach 1 failed");
     fprintf(stderr, "bye\n");
   if (heapA == NULL) {
     perror("attach 1 failed");
     fprintf(stderr, "bye\n");
@@ -34,15 +25,13 @@ int main()
   }
 
   fprintf(stderr, "HeapA=%p\n", heapA);
   }
 
   fprintf(stderr, "HeapA=%p\n", heapA);
-
+   fflush(stderr);
   int i, size;
   for (i = 0; i < TESTSIZE; i++) {
     size = rand() % 1000;
     pointers[i] = mmalloc(heapA, size);
   int i, size;
   for (i = 0; i < TESTSIZE; i++) {
     size = rand() % 1000;
     pointers[i] = mmalloc(heapA, size);
-    fprintf(stderr, "%d bytes allocated at %p\n", size, pointers[i]);
+    fprintf(stderr, "%d bytes allocated with offset %li\n", size, ((char*)pointers[i])-((char*)heapA));
   }
   }
-  char c;
-  scanf("%c", &c);
 
   for (i = 0; i < TESTSIZE; i++) {
     mfree(heapA, pointers[i]);
 
   for (i = 0; i < TESTSIZE; i++) {
     mfree(heapA, pointers[i]);