Merge branch 'tmp-tests' into 'master'
Update testing routines
See merge request gnutls/libtasn1!64
diff --git a/fuzz/main.c b/fuzz/main.c
index 1521056..96a38cf 100644
--- a/fuzz/main.c
+++ b/fuzz/main.c
@@ -39,6 +39,41 @@
#include <dirent.h>
+static int test_single_file(const char *fname)
+{
+ int fd, ret;
+ struct stat st;
+ uint8_t *data;
+ ssize_t n;
+
+ if ((fd = open(fname, O_RDONLY)) == -1) {
+ fprintf(stderr, "Failed to open %s (%d)\n", fname, errno);
+ return -1;
+ }
+
+ if (fstat(fd, &st) != 0) {
+ fprintf(stderr, "Failed to stat %d (%d)\n", fd, errno);
+ close(fd);
+ return -1;
+ }
+
+ data = malloc(st.st_size);
+ if ((n = read(fd, data, st.st_size)) == st.st_size) {
+ printf("testing %llu bytes from '%s'\n", (unsigned long long) st.st_size, fname);
+ fflush(stdout);
+ LLVMFuzzerTestOneInput(data, st.st_size);
+ fflush(stderr);
+ ret = 0;
+ } else {
+ fprintf(stderr, "Failed to read %llu bytes from %s (%d), got %zd\n", (unsigned long long) st.st_size, fname, errno, n);
+ ret = -1;
+ }
+
+ free(data);
+ close(fd);
+ return ret;
+}
+
static void test_all_from(const char *dirname)
{
DIR *dirp;
@@ -103,6 +138,9 @@
}
}
+ if (argc > 1)
+ return test_single_file(argv[1]);
+
const char *target = strrchr(argv[0], '/');
target = target ? target + 1 : argv[0];
diff --git a/tests/Makefile.am b/tests/Makefile.am
index f850df7..82aa2c6 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -52,8 +52,10 @@
# For crlf.
EXTRA_DIST += crlf.cer crl.der ocsp.der
-dist_check_SCRIPTS = crlf benchmark threadsafety decoding decoding-invalid-x509 \
- decoding-invalid-pkcs7 coding parser.sh
+dist_check_SCRIPTS = crlf.sh benchmark.sh threadsafety.sh decoding.sh decoding-invalid-x509.sh \
+ decoding-invalid-pkcs7.sh coding.sh parser.sh
+
+TEST_EXTENSIONS = .sh
MOSTLYCLEANFILES = Test_parser_ERROR.asn CVE-2018-1000654-1_asn1_tab.h CVE-2018-1000654-2_asn1_tab.h
@@ -64,11 +66,11 @@
spc_pe_image_data setof CVE-2018-1000654 reproducers object-id-encoding
TESTS = Test_parser Test_tree Test_encoding Test_indefinite \
- Test_errors Test_simple Test_overflow crlf threadsafety \
+ Test_errors Test_simple Test_overflow crlf.sh threadsafety.sh \
Test_strings Test_choice Test_encdec copynode coding-decoding2 \
- strict-der Test_choice_ocsp decoding decoding-invalid-x509 \
+ strict-der Test_choice_ocsp decoding.sh decoding-invalid-x509.sh \
ocsp-basic-response octet-string coding-long-oid object-id-decoding \
- spc_pe_image_data decoding-invalid-pkcs7 coding setof \
+ spc_pe_image_data decoding-invalid-pkcs7.sh coding.sh setof \
CVE-2018-1000654 parser.sh reproducers object-id-encoding
CVE-2018-1000654-1_asn1_tab.h: $(srcdir)/CVE-2018-1000654-1.asn
@@ -80,6 +82,7 @@
CVE_2018_1000654_SOURCES = CVE-2018-1000654-1_asn1_tab.h CVE-2018-1000654-2_asn1_tab.h CVE-2018-1000654.c
LOG_COMPILER = $(VALGRIND)
+SH_LOG_COMPILER= env VALGRIND="$(VALGRIND)" LIBTOOL="$(LIBTOOL)"
TESTS_ENVIRONMENT = \
ASN1PARSER=$(srcdir)/Test_parser.asn \
diff --git a/tests/benchmark b/tests/benchmark.sh
similarity index 100%
rename from tests/benchmark
rename to tests/benchmark.sh
diff --git a/tests/coding b/tests/coding.sh
similarity index 97%
rename from tests/coding
rename to tests/coding.sh
index 922629b..576bf7b 100755
--- a/tests/coding
+++ b/tests/coding.sh
@@ -21,7 +21,7 @@
export ASAN_OPTIONS
if ! test -z "${VALGRIND}";then
-VALGRIND="${LIBTOOL:-libtool} --mode=execute ${VALGRIND} --error-exitcode=7 --leak-check=no"
+VALGRIND="${LIBTOOL:-libtool} --mode=execute ${VALGRIND} --error-exitcode=7"
fi
ASN1CODING="${ASN1CODING:-../src/asn1Coding$EXEEXT}"
diff --git a/tests/crlf b/tests/crlf.sh
similarity index 84%
rename from tests/crlf
rename to tests/crlf.sh
index 54a3199..de9bece 100755
--- a/tests/crlf
+++ b/tests/crlf.sh
@@ -22,6 +22,14 @@
set -e
srcdir=${srcdir:-.}
+
+ASAN_OPTIONS="detect_leaks=0:exitcode=6"
+export ASAN_OPTIONS
+
+if ! test -z "${VALGRIND}";then
+VALGRIND="${LIBTOOL:-libtool} --mode=execute ${VALGRIND} --error-exitcode=7"
+fi
+
ASN1DECODING=../src/asn1Decoding${EXEEXT}
# The crlf.cer file is a normal certificate which contains bytes 0x0A
@@ -29,7 +37,7 @@
# when using fopen/fgetc/fscanf on streams on some systems (read:
# Windows).
-$ASN1DECODING \
+$VALGRIND $ASN1DECODING \
$srcdir/../examples/pkix.asn \
$srcdir/crlf.cer \
PKIX1Implicit88.Certificate >/dev/null 2>&1
diff --git a/tests/decoding-invalid-pkcs7 b/tests/decoding-invalid-pkcs7.sh
similarity index 97%
rename from tests/decoding-invalid-pkcs7
rename to tests/decoding-invalid-pkcs7.sh
index b91d725..b04ed63 100755
--- a/tests/decoding-invalid-pkcs7
+++ b/tests/decoding-invalid-pkcs7.sh
@@ -18,7 +18,7 @@
srcdir="${srcdir:-.}"
if ! test -z "${VALGRIND}";then
-VALGRIND="${LIBTOOL:-libtool} --mode=execute ${VALGRIND} --error-exitcode=7 --leak-check=no"
+VALGRIND="${LIBTOOL:-libtool} --mode=execute ${VALGRIND} --error-exitcode=7"
fi
TMPFILE=decoding-invalid.$$.tmp
ASN1DECODING="${ASN1DECODING:-../src/asn1Decoding$EXEEXT}"
diff --git a/tests/decoding-invalid-x509 b/tests/decoding-invalid-x509.sh
similarity index 97%
rename from tests/decoding-invalid-x509
rename to tests/decoding-invalid-x509.sh
index b62bcc0..04a62ea 100755
--- a/tests/decoding-invalid-x509
+++ b/tests/decoding-invalid-x509.sh
@@ -18,7 +18,7 @@
srcdir="${srcdir:-.}"
if ! test -z "${VALGRIND}";then
-VALGRIND="${LIBTOOL:-libtool} --mode=execute ${VALGRIND} --error-exitcode=7 --leak-check=no"
+VALGRIND="${LIBTOOL:-libtool} --mode=execute ${VALGRIND} --error-exitcode=7"
fi
TMPFILE=decoding-invalid.$$.tmp
ASN1DECODING="${ASN1DECODING:-../src/asn1Decoding$EXEEXT}"
diff --git a/tests/decoding b/tests/decoding.sh
similarity index 97%
rename from tests/decoding
rename to tests/decoding.sh
index 6dccb1c..5c8239e 100755
--- a/tests/decoding
+++ b/tests/decoding.sh
@@ -18,7 +18,7 @@
srcdir="${srcdir:-.}"
if ! test -z "${VALGRIND}";then
-VALGRIND="${LIBTOOL:-libtool} --mode=execute ${VALGRIND} --error-exitcode=7 --leak-check=no"
+VALGRIND="${LIBTOOL:-libtool} --mode=execute ${VALGRIND} --error-exitcode=7"
fi
ASN1DECODING="${ASN1DECODING:-../src/asn1Decoding$EXEEXT}"
diff --git a/tests/threadsafety b/tests/threadsafety.sh
similarity index 100%
rename from tests/threadsafety
rename to tests/threadsafety.sh