changed valgrind testing

This commit is contained in:
Tim Rühsen
2014-10-10 15:19:00 +02:00
parent 658abf2450
commit a11ceba71e
5 changed files with 49 additions and 15 deletions

View File

@ -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
-------------

View File

@ -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"

View File

@ -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)

View File

@ -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));

View File

@ -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)