1
0
mirror of https://github.com/mirror/wget.git synced 2025-03-26 11:42:23 +08:00

Use a LOG_COMPILER for running fuzz tests

This prevents needing a special case in the fuzz tests to detect
valgrind usage and a new exec. Instead, we simply detect the environment
in a shell script and start the test with valgrind in the first place.

* fuzz/test-runner.sh: New script for running the fuzz tests
* fuzz/main.c (main): Remove code for re-running under valgrind
* fuzz/Makefile.am: Set the LOG_COMPILER to test-runner.sh and remember
  to add it to the list of extra files for packaging
This commit is contained in:
Darshit Shah 2021-03-16 21:44:49 +01:00
parent db4d5b6eb3
commit cf788d60e4
3 changed files with 12 additions and 17 deletions

View File

@ -21,6 +21,8 @@ WGET_TESTS = \
wget_robots_fuzzer$(EXEEXT) \
wget_url_fuzzer$(EXEEXT)
EXTRA_DIST = test-runner.sh
if WITH_NTLM
WGET_TESTS += wget_ntlm_fuzzer$(EXEEXT)
endif
@ -33,6 +35,7 @@ if FUZZING
else
AM_CPPFLAGS += -DTEST_RUN
AM_TESTS_ENVIRONMENT = export VALGRIND_TESTS"=@VALGRIND_TESTS@";
LOG_COMPILER = $(top_srcdir)/fuzz/test-runner.sh
TESTS = $(WGET_TESTS)
check_PROGRAMS = $(WGET_TESTS)
MAIN = main.c fuzzer.h

View File

@ -68,26 +68,9 @@ static int test_all_from(const char *dirname)
int main(int argc, char **argv)
{
// if VALGRIND testing is enabled, we have to call ourselves with valgrind checking
const char *valgrind = getenv("VALGRIND_TESTS");
const char *target;
size_t target_len;
if (!valgrind || !*valgrind || !strcmp(valgrind, "0")) {
// fallthrough
}
else if (!strcmp(valgrind, "1")) {
char cmd[strlen(argv[0]) + 256];
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;
}
if ((target = strrchr(argv[0], SLASH))) {
if (strrchr(target, '/'))
target = strrchr(target, '/');

9
fuzz/test-runner.sh Executable file
View File

@ -0,0 +1,9 @@
#!/usr/bin/env sh
WRAPPER=""
if [ -n "$VALGRIND_TESTS" ]; then
WRAPPER="valgrind --error-exitcode=301 --leak-check=yes --show-reachable=yes --track-origins=yes"
fi
exec $WRAPPER "$@"