]> git.ozlabs.org Git - petitboot/commitdiff
tests/urls: Run URL tests under valgrind
authorJeremy Kerr <jk@ozlabs.org>
Thu, 26 Sep 2013 03:45:39 +0000 (11:45 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Thu, 26 Sep 2013 07:20:59 +0000 (15:20 +0800)
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
test/urls/Makefile.am
test/urls/parse-url.c
test/urls/run-url-test.in

index 2f7b3a479b1ce6c0f9653675be76b51c0f8eb832..fbdf792e9af80772ec10c36f903aeaacf40e47c8 100644 (file)
@@ -38,6 +38,10 @@ TESTS = data/double-slash.test \
 TEST_EXTENSIONS = .test
 TEST_LOG_COMPILER = $(builddir)/run-url-test
 
 TEST_EXTENSIONS = .test
 TEST_LOG_COMPILER = $(builddir)/run-url-test
 
+if ENABLE_TEST_VALGRIND
+TEST_LOG_FLAGS = --valgrind
+endif
+
 edit = sed \
        -e 's|@PACKAGE_NAME\@|$(PACKAGE_NAME)|g' \
        -e 's|@PACKAGE_VERSION\@|$(PACKAGE_VERSION)|g' \
 edit = sed \
        -e 's|@PACKAGE_NAME\@|$(PACKAGE_NAME)|g' \
        -e 's|@PACKAGE_VERSION\@|$(PACKAGE_VERSION)|g' \
index 1688eab9540a5f1331bbed76c47cdbab554b11bb..6637867c50497b5ff668a60194a02033080d0703 100644 (file)
@@ -2,19 +2,23 @@
 #include <stdlib.h>
 #include <stdio.h>
 
 #include <stdlib.h>
 #include <stdio.h>
 
+#include <talloc/talloc.h>
 #include <url/url.h>
 #include <log/log.h>
 
 int main(int argc, char **argv)
 {
        struct pb_url *url;
 #include <url/url.h>
 #include <log/log.h>
 
 int main(int argc, char **argv)
 {
        struct pb_url *url;
+       void *ctx;
 
        if (argc != 2 && argc != 3) {
                fprintf(stderr, "Usage: %s <URL> [update]\n", argv[0]);
                return EXIT_FAILURE;
        }
 
 
        if (argc != 2 && argc != 3) {
                fprintf(stderr, "Usage: %s <URL> [update]\n", argv[0]);
                return EXIT_FAILURE;
        }
 
-       url = pb_url_parse(NULL, argv[1]);
+       ctx = talloc_new(NULL);
+
+       url = pb_url_parse(ctx, argv[1]);
        if (!url)
                return EXIT_FAILURE;
 
        if (!url)
                return EXIT_FAILURE;
 
@@ -22,8 +26,11 @@ int main(int argc, char **argv)
                printf("%s\n", argv[1]);
 
        } else {
                printf("%s\n", argv[1]);
 
        } else {
+               struct pb_url *new_url;
                printf("%s %s\n", argv[1], argv[2]);
                printf("%s %s\n", argv[1], argv[2]);
-               url = pb_url_join(NULL, url, argv[2]);
+               new_url = pb_url_join(ctx, url, argv[2]);
+               talloc_free(url);
+               url = new_url;
        }
 
        printf("scheme\t%s\n", pb_url_scheme_name(url->scheme));
        }
 
        printf("scheme\t%s\n", pb_url_scheme_name(url->scheme));
@@ -33,5 +40,7 @@ int main(int argc, char **argv)
        printf("dir\t%s\n", url->dir);
        printf("file\t%s\n", url->file);
 
        printf("dir\t%s\n", url->dir);
        printf("file\t%s\n", url->file);
 
+       talloc_free(ctx);
+
        return EXIT_SUCCESS;
 }
        return EXIT_SUCCESS;
 }
index 834166f9e4cf8f7dcef595e4bdb540d23dbed155..c98fe8b660684894014db046f1819de2fa1a7b76 100755 (executable)
@@ -1,5 +1,12 @@
 #!/bin/bash
 
 #!/bin/bash
 
+valgrind=''
+if [ "$1" = "--valgrind" ]
+then
+       shift
+       valgrind='valgrind --leak-check=full --error-exitcode=1'
+fi
+
 parser="@abs_builddir@/parse-url"
 testfile=$1
 
 parser="@abs_builddir@/parse-url"
 testfile=$1
 
@@ -8,7 +15,7 @@ url=$(head -n1 $testfile)
 tmp=$(mktemp)
 trap "rm $tmp" EXIT
 
 tmp=$(mktemp)
 trap "rm $tmp" EXIT
 
-$parser $url > $tmp
+$valgrind $parser $url > $tmp
 if test $? -ne 0
 then
        echo "Error running $parser on $testfile"
 if test $? -ne 0
 then
        echo "Error running $parser on $testfile"