[gxml/gsoc2013] test/vaglrind: add a couple new tests, fix the gtype.supp



commit e29fae13ca81de3ff281057869e92cfc6fffe364
Author: Richard Schwarting <aquarichy gmail com>
Date:   Sun Jul 28 01:30:11 2013 -0400

    test/vaglrind: add a couple new tests, fix the gtype.supp

 test/valgrind/Makefile                    |   30 +++++----------
 test/valgrind/document_create_minimal.c   |   55 ++++++++++++++++++++++++++
 test/valgrind/document_create_minimal_2.c |   60 +++++++++++++++++++++++++++++
 test/valgrind/gtype.supp                  |    5 ++
 4 files changed, 130 insertions(+), 20 deletions(-)
---
diff --git a/test/valgrind/Makefile b/test/valgrind/Makefile
index 6509fc4..27faafe 100644
--- a/test/valgrind/Makefile
+++ b/test/valgrind/Makefile
@@ -2,8 +2,9 @@ VALAC=valac
 VALAFLAGS=-g --save-temps --vapidir=../../gxml --pkg gxml
 CC=gcc
 CFLAGS=-g `pkg-config --cflags --libs glib-2.0 gobject-2.0 gxml gio-2.0`
+C_PROGS=unlink_unattached_nodes small2a small2b gfile gobject document document_create_minimal libxml2 
document_create_minimal_2
 
-all: unlink_unattached_nodes small2a small2b gobject document example attributes small small2 scope libxml2 
supp
+all: $(C_PROGS) example attributes small small2 scope supp
 
 example: example.vala
        $(VALAC) $(VALAFLAGS) example.vala -o example
@@ -20,30 +21,19 @@ small2: small2.vala
 scope: scope.vala
        $(VALAC) $(VALAFLAGS) scope.vala -o scope
 
-unlink_unattached_nodes: unlink_unattached_nodes.c
-
-small2a: small2a.c
-
-small2b: small2b.c
-
-gfile: gfile.c
-
-gobject: gobject.c
-
-document: document.c
-
-libxml2: libxml2.c
-
 clean:
-       rm example small small2 small2a small2b gobject document scope attributes unlink_unattached_nodes 
libxml2 *~ \#*\#
+       rm example small small2 scope attributes $(C_PROGS) *~ \#*\#
 
 runnew:
        (cd ../.. && make && make install); make clean; make
        make run
 
-run:
-       G_SLICE=always-malloc valgrind --leak-check=full --show-reachable=yes --suppressions=libxml2.supp 
--suppressions=gio.supp --suppressions=gtype.supp --suppressions=glib.supp --num-callers=40 ./example
-
 # we compile it for users of GXml
-supp:
+supp: *.supp
        cat *.supp > ../../gxml.supp
+
+run:
+       G_SLICE=always-malloc valgrind --leak-check=full --show-reachable=yes --suppressions=libxml2.supp 
--suppressions=gio.supp --suppressions=gtype.supp --suppressions=glib.supp --num-callers=40 
./document_create_minimal_2
+
+run_nosupp:
+       G_SLICE=always-malloc valgrind --leak-check=full --show-reachable=yes --num-callers=40 ./document
diff --git a/test/valgrind/document_create_minimal.c b/test/valgrind/document_create_minimal.c
new file mode 100644
index 0000000..b418320
--- /dev/null
+++ b/test/valgrind/document_create_minimal.c
@@ -0,0 +1,55 @@
+#include <gxml/gxml.h>
+#include <stdio.h>
+
+
+int main () {
+  GXmlDocument *doc;
+  GXmlElement *root;
+  GXmlElement *owner;
+  GXmlElement *books;
+  GXmlElement *book;
+  int i;
+  char *str;
+
+  char *authors[] = { "John Green", "Jane Austen", "J.D. Salinger" };
+  char *titles[] = { "The Fault in Our Stars", "Pride & Prejudice", "Nine Stories" };
+
+  doc = gxml_document_new ();
+
+  // Add a root node
+  root = gxml_document_create_element (doc, "Bookshelf");
+  gxml_node_append_child (GXML_NODE (doc), GXML_NODE (root));
+  // if we tried to add a second one, it would fail and a g_warning would be printed :)
+
+  // Add an owner node
+  owner = gxml_document_create_element (doc, "Owner");
+  gxml_node_append_child (GXML_NODE (root), GXML_NODE (owner));
+  gxml_element_set_attribute (owner, "fullname", "John Green");
+  // TODO: need to figure out what sort of errors these would return,
+  // want the devhelp pages to describe meaningful possible errors
+
+  // Add a collection of books
+  books = gxml_document_create_element (doc, "Books");
+  gxml_node_append_child (GXML_NODE (root), GXML_NODE (books));
+  for (i = 0; i < sizeof (authors) / sizeof (char*); i++) {
+    book = gxml_document_create_element (doc, "Book");
+    gxml_element_set_attribute (book, "author", authors[i]);
+    gxml_element_set_attribute (book, "title", titles[i]);
+    gxml_node_append_child (GXML_NODE (books), GXML_NODE (book));
+  }
+
+  str = gxml_node_to_string (GXML_NODE (doc), TRUE, 2);
+  printf ("%s:\n%s\n", __FILE__, str);
+  g_free (str);
+
+  g_object_unref (doc);
+  g_object_unref (root);
+  g_object_unref (owner);
+  g_object_unref (books);
+  g_object_unref (book);
+
+  // TODO: how do we clean them up?
+
+  return 0;
+}
+
diff --git a/test/valgrind/document_create_minimal_2.c b/test/valgrind/document_create_minimal_2.c
new file mode 100644
index 0000000..2cbd323
--- /dev/null
+++ b/test/valgrind/document_create_minimal_2.c
@@ -0,0 +1,60 @@
+#include <gxml/gxml.h>
+#include <stdio.h>
+
+
+int main () {
+  GXmlDocument *doc;
+  GXmlElement *root;
+  GXmlElement *owner;
+  GXmlElement *books;
+  GXmlElement *book;
+  int i;
+  char *str;
+
+  char *authors[] = { "John Green", "Jane Austen", "J.D. Salinger" };
+  char *titles[] = { "The Fault in Our Stars", "Pride & Prejudice", "Nine Stories" };
+
+  doc = gxml_document_new ();
+
+  // Add a root node
+  root = gxml_document_create_element (doc, "Bookshelf");
+  gxml_node_append_child (GXML_NODE (doc), GXML_NODE (root));
+  // if we tried to add a second one, it would fail and a g_warning would be printed :)
+
+  // Add an owner node
+  owner = gxml_document_create_element (doc, "Owner");
+  //gxml_node_append_child (GXML_NODE (doc), GXML_NODE (root));
+  /* gxml_node_append_child (GXML_NODE (root), GXML_NODE (owner)); */
+  /* gxml_element_set_attribute (owner, "fullname", "John Green"); */
+  /* // TODO: need to figure out what sort of errors these would return, */
+  /* // want the devhelp pages to describe meaningful possible errors */
+
+  /* // Add a collection of books */
+  /* books = gxml_document_create_element (doc, "Books"); */
+  /* gxml_node_append_child (GXML_NODE (root), GXML_NODE (books)); */
+  /* for (i = 0; i < sizeof (authors) / sizeof (char*); i++) { */
+  /*   book = gxml_document_create_element (doc, "Book"); */
+  /*   gxml_element_set_attribute (book, "author", authors[i]); */
+  /*   gxml_element_set_attribute (book, "title", titles[i]); */
+  /*   gxml_node_append_child (GXML_NODE (books), GXML_NODE (book)); */
+  /* } */
+
+  /* str = gxml_node_to_string (GXML_NODE (doc), TRUE, 2); */
+  /* printf ("%s:\n%s\n", __FILE__, str); */
+  /* g_free (str); */
+
+  /* g_object_unref (doc); */
+  /* g_object_unref (root); */
+  /* g_object_unref (owner); */
+  /* g_object_unref (books); */
+  /* g_object_unref (book); */
+
+  //g_object_unref (owner);
+  g_object_unref (root);
+  g_object_unref (doc);
+
+  // TODO: how do we clean them up?
+
+  return 0;
+}
+
diff --git a/test/valgrind/gtype.supp b/test/valgrind/gtype.supp
index de4f837..b22d0d8 100644
--- a/test/valgrind/gtype.supp
+++ b/test/valgrind/gtype.supp
@@ -23,6 +23,10 @@
   label
   Memcheck:Leak
   ...
+  fun:g_mutex_impl_new
+  fun:g_mutex_get_impl
+  fun:g_mutex_lock
+  ...
   fun:g_type_create_instance
   fun:g_object_constructor
 }
@@ -36,6 +40,7 @@
 {
   label
   Memcheck:Leak
+  fun:disabled
   fun:memalign
   ...
   fun:g_type_create_instance


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]