Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make cunit memory clean
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Tue, 10 Jun 2008 15:40:58 +0000 (15:40 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Tue, 10 Jun 2008 15:40:58 +0000 (15:40 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@5601 48e7efb5-ca39-0410-a469-dd3cf9ba447f

include/xbt/cunit.h
src/xbt/cunit.c
tools/sg_unit_extractor.pl

index 6a6e8e6..ec4c43a 100644 (file)
@@ -52,6 +52,8 @@ XBT_PUBLIC(void)             xbt_test_suite_push (xbt_test_suite_t suite, const
 XBT_PUBLIC(int) xbt_test_run(char *selection);
 /* Show information about the selection of tests */
 XBT_PUBLIC(void) xbt_test_dump(char *selection);
+/* Cleanup the mess */
+XBT_PUBLIC(void) xbt_test_exit(void);
 
 /* test operations */
 XBT_PUBLIC(void)    _xbt_test_add(const char*file,int line, const char *fmt, ...)_XBT_GNUC_PRINTF(3,4);
index ab53a53..ac0ca35 100644 (file)
@@ -50,13 +50,6 @@ static void xbt_test_log_dump(xbt_test_log_t log) {
   else
     fprintf(stderr,"      log=NULL\n");           
 }
-static void xbt_test_log_free(xbt_test_log_t log) {
-  if (!log)
-    return;
-  if (log->text)
-    free(log->text);
-  free(log);
-}
 
 /* test suite test check */
 typedef struct s_xbt_test_test {
@@ -135,6 +128,25 @@ static void xbt_test_suite_free(void *s) {
   free(suite);
 }
 
+static void xbt_test_unit_free(void *unit) {
+   xbt_test_unit_t u = *(xbt_test_unit_t*)unit;
+   /* name is static */
+   free(u->title);
+   xbt_dynar_free(&u->tests);
+   free(u);
+}
+static void xbt_test_test_free(void *test) {
+   xbt_test_test_t t = *(xbt_test_test_t*)test;
+   free(t->title);
+   xbt_dynar_free(&(t->logs));
+   free(t);
+}
+static void xbt_test_log_free(void *log) {
+  xbt_test_log_t l= *(xbt_test_log_t*) log;
+  free(l->text);
+  free(l);
+}
+
 /** @brief create test suite */
 xbt_test_suite_t xbt_test_suite_new(const char *name, const char *fmt, ...) {
   xbt_test_suite_t suite = xbt_new0(struct s_xbt_test_suite,1);
@@ -145,7 +157,7 @@ xbt_test_suite_t xbt_test_suite_new(const char *name, const char *fmt, ...) {
 
   va_start(ap, fmt);
   vasprintf(&suite->title,fmt, ap);
-  suite->units = xbt_dynar_new(sizeof(xbt_test_unit_t), NULL);
+  suite->units = xbt_dynar_new(sizeof(xbt_test_unit_t), &xbt_test_unit_free);
   va_end(ap);
   suite->name = name;
   suite->enabled = 1;
@@ -210,7 +222,7 @@ void xbt_test_suite_push(xbt_test_suite_t suite, const char *name, ts_test_cb_t
   unit->file = NULL;
   unit->line = 0;
   unit->enabled = 1;
-  unit->tests = xbt_dynar_new(sizeof(xbt_test_test_t), NULL);
+  unit->tests = xbt_dynar_new(sizeof(xbt_test_test_t), xbt_test_test_free);
   
   xbt_dynar_push(suite->units, &unit);
   return;
@@ -623,7 +635,9 @@ int xbt_test_run(char *selection) {
   }
   return _xbt_test_unit_failed;
 }
-
+void xbt_test_exit(void) {
+   xbt_dynar_free(&_xbt_test_suites);
+}
 
 /* annotate test case with test */
 void _xbt_test_add(const char*file,int line, const char *fmt, ...) {
@@ -634,7 +648,7 @@ void _xbt_test_add(const char*file,int line, const char *fmt, ...) {
   xbt_assert(unit);
   xbt_assert(fmt);
 
-  test = xbt_new(struct s_xbt_test_test,1);
+  test = xbt_new0(struct s_xbt_test_test,1);
   va_start(ap, fmt);
   vasprintf(&test->title, fmt, ap);
   va_end(ap);
@@ -643,7 +657,7 @@ void _xbt_test_add(const char*file,int line, const char *fmt, ...) {
   test->ignored = 0;
   test->file = file;
   test->line = line;
-  test->logs = xbt_dynar_new(sizeof(xbt_test_log_t),NULL);
+  test->logs = xbt_dynar_new(sizeof(xbt_test_log_t),xbt_test_log_free);
   xbt_dynar_push(unit->tests,&test);
   return;
 }
index 30686a7..9ef69f9 100755 (executable)
@@ -148,6 +148,7 @@ int main(int argc, char *argv[]) {
   /* Got all my tests to do */
       
   res = xbt_test_run(selection);
+  xbt_test_exit();
   xbt_exit();
   return res;
 }