From a11ceba71e1ce6c3dc6dc6cb561dfd78edb745fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20R=C3=BChsen?= Date: Fri, 10 Oct 2014 15:19:00 +0200 Subject: [PATCH] changed valgrind testing --- README.md | 20 ++++++++++++++++++++ configure.ac | 6 ++++-- tests/Makefile.am | 3 ++- tests/libtest.c | 11 +++++++---- tests/test.c | 24 ++++++++++++++++-------- 5 files changed, 49 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 1d977c14..6d5449c0 100644 --- a/README.md +++ b/README.md @@ -170,6 +170,26 @@ To create Mget HTML documentation and man pages ./configure --enable-gtk-doc --enable-man make +Valgrind Testing +---------------- + +To run the test suite with valgrind memcheck + + TESTS_ENVIRONMENT="VALGRIND_TESTS=1" make check + +or if you want valgrind memcheck by default + + ./configure --enable-valgrind-tests + make check + +To run single tests with valgrind (e.g. test-k) + + cd tests + VALGRIND_TESTS=1 ./test-k + +Why not directly using valgrind like 'valgrind --leak-check=full ./test-k' ? +Well, you want to valgrind 'mget' and not the test program itself, right ? + Documentation ------------- diff --git a/configure.ac b/configure.ac index ea097ef2..b0299043 100644 --- a/configure.ac +++ b/configure.ac @@ -143,8 +143,10 @@ AC_ARG_ENABLE(valgrind-tests, if test "${ac_enable_valgrind}" != "no" ; then AC_CHECK_PROG(HAVE_VALGRIND, valgrind, yes, no) if test "$HAVE_VALGRIND" = "yes" ; then - VALGRIND_ENVIRONMENT="valgrind --error-exitcode=1 --leak-check=yes --show-reachable=yes --track-origins=yes" - AC_SUBST(VALGRIND_ENVIRONMENT) +# VALGRIND_ENVIRONMENT="valgrind --error-exitcode=1 --leak-check=yes --show-reachable=yes --track-origins=yes" +# AC_SUBST(VALGRIND_ENVIRONMENT) + VALGRIND_TESTS="1" + AC_SUBST(VALGRIND_TESTS) TESTS_INFO="Test suite will be run under Valgrind" else TESTS_INFO="Valgrind not found" diff --git a/tests/Makefile.am b/tests/Makefile.am index 3277d1e1..57c86c96 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -30,5 +30,6 @@ dist-hook: # cp $(top_srcdir)/data/public_suffixes.txt $(distdir)/files/ # rm -rf `find $(distdir)/files -name CVS` -AM_TESTS_ENVIRONMENT = TESTS_VALGRIND="@VALGRIND_ENVIRONMENT@" +#AM_TESTS_ENVIRONMENT = VALGRIND_TESTS"=@VALGRIND_ENVIRONMENT@" +AM_TESTS_ENVIRONMENT = export VALGRIND_TESTS"=@VALGRIND_TESTS@"; TESTS = $(MGET_TESTS) diff --git a/tests/libtest.c b/tests/libtest.c index 46d28677..a587436b 100644 --- a/tests/libtest.c +++ b/tests/libtest.c @@ -547,11 +547,14 @@ void mget_test(int first_key, ...) } } - const char *valgrind = getenv("TESTS_VALGRIND"); - if (valgrind) - mget_buffer_printf2(cmd, "%s %s %s", valgrind, executable, options); - else + const char *valgrind = getenv("VALGRIND_TESTS"); + if (!valgrind || !*valgrind || !strcmp(valgrind, "0")) { mget_buffer_printf2(cmd, "%s %s", executable, options); + } else if (!strcmp(valgrind, "1")) { + mget_buffer_printf2(cmd, "valgrind --error-exitcode=301 --leak-check=yes --show-reachable=yes --track-origins=yes %s %s", executable, options); + } else + mget_buffer_printf2(cmd, "%s %s %s", valgrind, executable, options); + for (it = 0; it < (size_t)mget_vector_size(request_urls); it++) { mget_buffer_printf_append2(cmd, " 'http://localhost:%d/%s'", server_port, (char *)mget_vector_get(request_urls, it)); diff --git a/tests/test.c b/tests/test.c index f24c5e8a..1d255421 100644 --- a/tests/test.c +++ b/tests/test.c @@ -403,7 +403,8 @@ static void test_iri_parse(void) { "http://example.com/index.html?#", NULL, MGET_IRI_SCHEME_HTTP, NULL, NULL, "example.com", NULL, "index.html", "", ""}, { "碼標準萬國碼.com", NULL, MGET_IRI_SCHEME_HTTP, NULL, NULL, "xn--9cs565brid46mda086o.com", NULL, NULL, NULL, NULL}, // { "ftp://cnn.example.com&story=breaking_news@10.0.0.1/top_story.htm", NULL,"ftp",NULL,NULL,"cnn.example.com",NULL,NULL,"story=breaking_news@10.0.0.1/top_story.htm",NULL } - { "ftp://cnn.example.com?story=breaking_news@10.0.0.1/top_story.htm", NULL, "ftp", NULL, NULL, "cnn.example.com", NULL, NULL, "story=breaking_news@10.0.0.1/top_story.htm", NULL} + { "ftp://cnn.example.com?story=breaking_news@10.0.0.1/top_story.htm", NULL, "ftp", NULL, NULL, "cnn.example.com", NULL, NULL, "story=breaking_news@10.0.0.1/top_story.htm", NULL}, +// { "site;sub:.html", NULL, MGET_IRI_SCHEME_HTTP, NULL, NULL, "site", NULL, ";sub:.html", NULL, NULL}, }; unsigned it; @@ -503,6 +504,7 @@ static void test_iri_relative_to_absolute(void) { H1, "/x.php?y=ftp://example.com/&z=1_2", H1"/x.php?y=ftp://example.com/&z=1_2" }, { H1, "//x.y.com/", "http://x.y.com/" }, { H1, "http://x.y.com/", "http://x.y.com/" }, +// { H1, "site;sub:.html", H1"/site;sub:.html" }, #undef H1 #define H1 "http://x.tld/" { H1, "", H1"" }, @@ -1363,15 +1365,21 @@ static void test_stringmap(void) int main(int argc, const char * const *argv) { // if VALGRIND testing is enabled, we have to call ourselves with valgrind checking - if (argc == 1) { - const char *valgrind = getenv("TESTS_VALGRIND"); + const char *valgrind = getenv("VALGRIND_TESTS"); - if (valgrind && *valgrind) { - char cmd[strlen(valgrind)+strlen(argv[0])+32]; + if (!valgrind || !*valgrind || !strcmp(valgrind, "0")) { + // fallthrough + } + else if (!strcmp(valgrind, "1")) { + char cmd[strlen(argv[0]) + 256]; - snprintf(cmd, sizeof(cmd), "TESTS_VALGRIND="" %s %s", valgrind, argv[0]); - return system(cmd) != 0; - } + snprintf(cmd, sizeof(cmd), "VALGRIND_TESTS=\"\" valgrind --error-exitcode=301 --leak-check=yes --show-reachable=yes --track-origins=yes %s", argv[0]); + return system(cmd) != 0; + } else { + char cmd[strlen(valgrind) + strlen(argv[0]) + 32]; + + snprintf(cmd, sizeof(cmd), "VALGRIND_TESTS="" %s %s", valgrind, argv[0]); + return system(cmd) != 0; } init(argc, argv); // allows us to test with options (e.g. with --debug)