summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRuss Allbery <eagle@eyrie.org>2019-09-02 14:05:18 -0700
committerRuss Allbery <eagle@eyrie.org>2019-09-02 14:05:18 -0700
commit8fb2bdc2a8cc69ba681d884e016510f4bd78529d (patch)
tree201babd342fb9d47f2618472edb488205295ac29 /tests
parent8c0c81e923baace5e40577c6f84c5f9a5b94b59a (diff)
Update to rra-c-util 8.0 and C TAP Harness 4.5
Update to rra-c-util 8.0: * Skip more Automake files in tests. * Fix warnings with current versions of GCC and cppcheck. Update to C TAP Harness 4.5: * Fix error checking for malloc failure in bstrndup.
Diffstat (limited to 'tests')
-rw-r--r--tests/TESTS2
-rw-r--r--tests/data/cppcheck.supp10
-rwxr-xr-xtests/docs/pod-spelling-t3
-rwxr-xr-xtests/docs/pod-t3
-rwxr-xr-xtests/docs/spdx-license-t48
-rwxr-xr-xtests/perl/module-version-t3
-rw-r--r--tests/portable/getaddrinfo-t.c14
-rw-r--r--tests/runtests.c41
-rwxr-xr-xtests/style/obsolete-strings-t (renamed from tests/docs/urls-t)24
-rw-r--r--tests/tap/basic.c174
-rw-r--r--tests/tap/basic.h22
-rw-r--r--tests/tap/libtap.sh4
-rw-r--r--tests/tap/macros.h2
-rw-r--r--tests/tap/perl/Test/RRA.pm75
-rw-r--r--tests/tap/perl/Test/RRA/Automake.pm14
-rw-r--r--tests/tap/perl/Test/RRA/Config.pm6
-rw-r--r--tests/tap/perl/Test/RRA/ModuleVersion.pm26
-rw-r--r--tests/util/network/client-t.c19
-rw-r--r--tests/util/network/server-t.c11
-rwxr-xr-xtests/util/xmalloc-t34
-rw-r--r--tests/util/xmalloc.c5
21 files changed, 336 insertions, 204 deletions
diff --git a/tests/TESTS b/tests/TESTS
index 021266d..cd5d005 100644
--- a/tests/TESTS
+++ b/tests/TESTS
@@ -19,7 +19,6 @@ client/timeout valgrind libtool
docs/pod
docs/pod-spelling
docs/spdx-license
-docs/urls
perl/module-version
portable/asprintf valgrind
portable/daemon valgrind
@@ -54,6 +53,7 @@ server/sudo valgrind
server/summary valgrind libtool
server/user
server/version valgrind libtool
+style/obsolete-strings
util/buffer valgrind
util/gss-tokens valgrind
util/messages valgrind
diff --git a/tests/data/cppcheck.supp b/tests/data/cppcheck.supp
index 5a421df..33ee332 100644
--- a/tests/data/cppcheck.supp
+++ b/tests/data/cppcheck.supp
@@ -4,7 +4,11 @@
// aren't in rra-c-util, for ease of sharing between projects. The ones that
// don't apply to a particular project should hopefully be harmless.
//
-// Copyright 2018 Russ Allbery <eagle@eyrie.org>
+// To determine the correct suppression to add for a new error, run cppcheck
+// with the --xml flag and then add a suppression for the error id, file
+// location, and line.
+//
+// Copyright 2018-2019 Russ Allbery <eagle@eyrie.org>
//
// Copying and distribution of this file, with or without modification, are
// permitted in any medium without royalty provided the copyright notice and
@@ -23,6 +27,10 @@ knownConditionTrueFalse:portable/getopt.c:146
// False positive since the string comes from a command-line define.
knownConditionTrueFalse:tests/tap/remctl.c:79
+// Stored in the returned ai struct, but cppcheck can't see the assignment
+// because of the struct sockaddr * cast.
+memleak:portable/getaddrinfo.c:236
+
// Setting the variable to NULL explicitly after deallocation.
redundantAssignment:tests/pam-util/options-t.c
diff --git a/tests/docs/pod-spelling-t b/tests/docs/pod-spelling-t
index 0419c24..fd9d3f0 100755
--- a/tests/docs/pod-spelling-t
+++ b/tests/docs/pod-spelling-t
@@ -36,10 +36,11 @@ use warnings;
use lib "$ENV{C_TAP_SOURCE}/tap/perl";
-use Test::More;
use Test::RRA qw(skip_unless_author use_prereq);
use Test::RRA::Automake qw(automake_setup perl_dirs);
+use Test::More;
+
# Only run this test for the module author since the required stopwords are
# too sensitive to the exact spell-checking program and dictionary.
skip_unless_author('Spelling tests');
diff --git a/tests/docs/pod-t b/tests/docs/pod-t
index 7ea3409..d5a7794 100755
--- a/tests/docs/pod-t
+++ b/tests/docs/pod-t
@@ -37,10 +37,11 @@ use warnings;
use lib "$ENV{C_TAP_SOURCE}/tap/perl";
-use Test::More;
use Test::RRA qw(skip_unless_automated use_prereq);
use Test::RRA::Automake qw(automake_setup perl_dirs);
+use Test::More;
+
# Skip this test for normal user installs, since we normally pre-generate all
# of the documentation and the end user doesn't care.
skip_unless_automated('POD syntax tests');
diff --git a/tests/docs/spdx-license-t b/tests/docs/spdx-license-t
index 1659f0d..d2131e3 100755
--- a/tests/docs/spdx-license-t
+++ b/tests/docs/spdx-license-t
@@ -37,26 +37,29 @@ use warnings;
use lib "$ENV{C_TAP_SOURCE}/tap/perl";
-use File::Basename qw(basename);
-use Test::More;
use Test::RRA qw(skip_unless_automated);
use Test::RRA::Automake qw(all_files automake_setup);
+use File::Basename qw(basename);
+use Test::More;
+
# File name (the file without any directory component) and path patterns to
# skip for this check.
## no critic (RegularExpressions::ProhibitFixedStringMatches)
my @IGNORE = (
- qr{ \A LICENSE \z }xms, # Generated file with no license itself
- qr{ \A (NEWS|THANKS|TODO) \z }xms, # Package license should be fine
- qr{ \A README ( [.] .* )? \z }xms, # Package license should be fine
- qr{ \A (Makefile|libtool) \z }xms, # Generated file
- qr{ [.] output \z }xms, # Test data
+ qr{ \A LICENSE \z }xms, # Generated file with no license itself
+ qr{ \A (NEWS|THANKS|TODO) \z }xms, # Package license should be fine
+ qr{ \A README ( [.] .* )? \z }xms, # Package license should be fine
+ qr{ \A (Makefile|libtool) \z }xms, # Generated file
+ qr{ [.] output \z }xms, # Test data
);
my @IGNORE_PATHS = (
+ qr{ \A debian/ }xms, # Found in debian/* branches
qr{ \A docs/metadata/ }xms, # Package license should be fine
qr{ \A docs/protocol[.](html|txt) \z }xms, # Generated by xml2rfc
qr{ \A m4/ (libtool|lt.*) [.] m4 \z }xms, # Files from Libtool
qr{ \A perl/Build \z }xms, # Perl build files
+ qr{ \A perl/MANIFEST \z }xms, # Perl build files
qr{ \A perl/MYMETA [.] }xms, # Perl build files
qr{ \A perl/blib/ }xms, # Perl build files
qr{ \A perl/cover_db/ }xms, # Perl test files
@@ -69,13 +72,13 @@ my @IGNORE_PATHS = (
qr{ \A php/configure [.] in \z }xms, # Created by phpize
qr{ \A php/ltmain [.] sh \z }xms, # Created by phpize
qr{ \A php/run-tests [.] php \z }xms, # Created by phpize
- qr{ [.] la \z }xms, # Created by libtool
+ qr{ [.] l?a \z }xms, # Created by libtool
);
## use critic
# Only run this test during automated testing, since failure doesn't indicate
# any user-noticable flaw in the package itself.
-skip_unless_automated('SPDX license identifier tests');
+skip_unless_automated('SPDX identifier tests');
# Set up Automake testing.
automake_setup();
@@ -89,9 +92,7 @@ sub check_file {
my ($path) = @_;
my $filename = basename($path);
- # Ignore files in the whitelist, binary files, and files under 1KB. The
- # latter can be rolled up into the overall project license and the license
- # notice may be a substantial portion of the file size.
+ # Ignore files in the whitelist and binary files.
for my $pattern (@IGNORE) {
return if $filename =~ $pattern;
}
@@ -99,16 +100,18 @@ sub check_file {
return if $path =~ $pattern;
}
return if !-T $path;
- return if -s $path < 1024;
# Scan the file.
- my ($saw_spdx, $skip_spdx);
- open(my $file, '<', $path) or BAIL_OUT("Cannot open $path");
+ my ($saw_legacy_notice, $saw_spdx, $skip_spdx);
+ open(my $file, '<', $path) or BAIL_OUT("Cannot open $path: $!");
while (defined(my $line = <$file>)) {
if ($line =~ m{ Generated [ ] by [ ] libtool [ ] }xms) {
- close($file);
+ close($file) or BAIL_OUT("Cannot close $path: $!");
return;
}
+ if ($line =~ m{ \b See \s+ LICENSE \s+ for \s+ licensing }xms) {
+ $saw_legacy_notice = 1;
+ }
if ($line =~ m{ \b SPDX-License-Identifier: \s+ \S+ }xms) {
$saw_spdx = 1;
last;
@@ -118,8 +121,17 @@ sub check_file {
last;
}
}
- close($file) or BAIL_OUT("Cannot close $path");
- ok($saw_spdx || $skip_spdx, $path);
+ close($file) or BAIL_OUT("Cannot close $path: $!");
+
+ # If there is a legacy license notice, report a failure regardless of file
+ # size. Otherwise, skip files under 1KB. They can be rolled up into the
+ # overall project license and the license notice may be a substantial
+ # portion of the file size.
+ if ($saw_legacy_notice) {
+ ok(!$saw_legacy_notice, "$path has legacy license notice");
+ } else {
+ ok($saw_spdx || $skip_spdx || -s $path < 1024, $path);
+ }
return;
}
diff --git a/tests/perl/module-version-t b/tests/perl/module-version-t
index 878cc2d..151796a 100755
--- a/tests/perl/module-version-t
+++ b/tests/perl/module-version-t
@@ -27,11 +27,12 @@ BEGIN {
}
}
-use Getopt::Long qw(GetOptions);
use Test::RRA qw(skip_unless_automated);
use Test::RRA::Automake qw(automake_setup);
use Test::RRA::ModuleVersion qw(test_module_versions update_module_versions);
+use Getopt::Long qw(GetOptions);
+
# Return the current version and, optionally, the package name from the NEWS
# file. Munges the version to be appropriate for Perl if necessary.
#
diff --git a/tests/portable/getaddrinfo-t.c b/tests/portable/getaddrinfo-t.c
index d123010..0d13d58 100644
--- a/tests/portable/getaddrinfo-t.c
+++ b/tests/portable/getaddrinfo-t.c
@@ -5,7 +5,7 @@
* which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
- * Copyright 2003-2005, 2016 Russ Allbery <eagle@eyrie.org>
+ * Copyright 2003-2005, 2016, 2019 Russ Allbery <eagle@eyrie.org>
* Copyright 2015 Julien ÉLIE <julien@trigofacile.com>
* Copyright 2007-2009, 2011-2013
* The Board of Trustees of the Leland Stanford Junior University
@@ -195,14 +195,14 @@ main(void)
}
/* Hopefully this will always resolve. */
- host = gethostbyname("www.isc.org");
+ host = gethostbyname("www.eyrie.org");
if (host == NULL)
- skip_block(9, "cannot look up www.isc.org");
+ skip_block(9, "cannot look up www.eyrie.org");
else {
hints.ai_flags = 0;
hints.ai_socktype = SOCK_STREAM;
- ok(test_getaddrinfo("www.isc.org", "80", &hints, &ai) == 0,
- "lookup of www.isc.org");
+ ok(test_getaddrinfo("www.eyrie.org", "80", &hints, &ai) == 0,
+ "lookup of www.eyrie.org");
is_int(SOCK_STREAM, ai->ai_socktype, "...right socktype");
is_string(NULL, ai->ai_canonname, "...no canonname");
saddr = (struct sockaddr_in *) (void *) ai->ai_addr;
@@ -212,8 +212,8 @@ main(void)
test_freeaddrinfo(ai);
hints.ai_flags = AI_CANONNAME;
- ok(test_getaddrinfo("www.isc.org", "80", &hints, &ai) == 0,
- "lookup of www.isc.org with A_CANONNAME");
+ ok(test_getaddrinfo("www.eyrie.org", "80", &hints, &ai) == 0,
+ "lookup of www.eyrie.org with A_CANONNAME");
ok(ai->ai_canonname != NULL, "...canonname isn't null");
saddr = (struct sockaddr_in *) (void *) ai->ai_addr;
is_int(htons(80), saddr->sin_port, "...right port");
diff --git a/tests/runtests.c b/tests/runtests.c
index af15a5c..95cc430 100644
--- a/tests/runtests.c
+++ b/tests/runtests.c
@@ -8,7 +8,7 @@
* should be sent to the e-mail address below. This program is part of C TAP
* Harness <https://www.eyrie.org/~eagle/software/c-tap-harness/>.
*
- * Copyright 2000-2001, 2004, 2006-2018 Russ Allbery <eagle@eyrie.org>
+ * Copyright 2000-2001, 2004, 2006-2019 Russ Allbery <eagle@eyrie.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -246,12 +246,13 @@ Failed Set Fail/Total (%) Skip Stat Failing Tests\n\
-------------------------- -------------- ---- ---- ------------------------";
/* Include the file name and line number in malloc failures. */
-#define xcalloc(n, size) x_calloc((n), (size), __FILE__, __LINE__)
-#define xmalloc(size) x_malloc((size), __FILE__, __LINE__)
+#define xcalloc(n, type) \
+ ((type *) x_calloc((n), sizeof(type), __FILE__, __LINE__))
+#define xmalloc(size) ((char *) x_malloc((size), __FILE__, __LINE__))
#define xstrdup(p) x_strdup((p), __FILE__, __LINE__)
#define xstrndup(p, size) x_strndup((p), (size), __FILE__, __LINE__)
-#define xreallocarray(p, n, size) \
- x_reallocarray((p), (n), (size), __FILE__, __LINE__)
+#define xreallocarray(p, n, type) \
+ ((type *) x_reallocarray((p), (n), sizeof(type), __FILE__, __LINE__))
/*
* __attribute__ is available in gcc 2.5 and later, but only with gcc 2.7
@@ -414,7 +415,7 @@ x_strdup(const char *s, const char *file, int line)
size_t len;
len = strlen(s) + 1;
- p = malloc(len);
+ p = (char *) malloc(len);
if (p == NULL)
sysdie("failed to strdup %lu bytes at %s line %d",
(unsigned long) len, file, line);
@@ -442,7 +443,7 @@ x_strndup(const char *s, size_t size, const char *file, int line)
for (p = s; (size_t) (p - s) < size && *p != '\0'; p++)
;
len = (size_t) (p - s);
- copy = malloc(len + 1);
+ copy = (char *) malloc(len + 1);
if (copy == NULL)
sysdie("failed to strndup %lu bytes at %s line %d",
(unsigned long) len, file, line);
@@ -670,10 +671,10 @@ resize_results(struct testset *ts, unsigned long n)
*/
if (ts->allocated == 0) {
s = (n > 32) ? n : 32;
- ts->results = xcalloc(s, sizeof(enum test_status));
+ ts->results = xcalloc(s, enum test_status);
} else {
s = (n > ts->allocated + 1024) ? n : ts->allocated + 1024;
- ts->results = xreallocarray(ts->results, s, sizeof(enum test_status));
+ ts->results = xreallocarray(ts->results, s, enum test_status);
}
/* Set the results for the newly-allocated test array. */
@@ -1321,11 +1322,9 @@ parse_test_list_line(const char *line, struct testset *ts, const char *source,
end = skip_non_whitespace(p);
if (strncmp(p, "libtool", end - p) == 0) {
use_libtool = 1;
- p = end;
} else if (strncmp(p, "valgrind", end - p) == 0) {
valgrind = getenv("C_TAP_VALGRIND");
use_valgrind = (valgrind != NULL);
- p = end;
} else {
option = xstrndup(p, end - p);
die("unknown test list option %s", option);
@@ -1346,7 +1345,7 @@ parse_test_list_line(const char *line, struct testset *ts, const char *source,
}
/* Now, build the command. */
- ts->command = xcalloc(len + 1, sizeof(char *));
+ ts->command = xcalloc(len + 1, char *);
i = 0;
if (use_valgrind && valgrind != NULL) {
if (use_libtool) {
@@ -1388,7 +1387,7 @@ read_test_list(const char *filename, const char *source, const char *build)
struct testlist *listhead, *current;
/* Create the initial container list that will hold our results. */
- listhead = xcalloc(1, sizeof(struct testlist));
+ listhead = xcalloc(1, struct testlist);
current = NULL;
/*
@@ -1419,10 +1418,10 @@ read_test_list(const char *filename, const char *source, const char *build)
if (current == NULL)
current = listhead;
else {
- current->next = xcalloc(1, sizeof(struct testlist));
+ current->next = xcalloc(1, struct testlist);
current = current->next;
}
- current->ts = xcalloc(1, sizeof(struct testset));
+ current->ts = xcalloc(1, struct testset);
current->ts->plan = PLAN_INIT;
/* Parse the line and store the results in the testset struct. */
@@ -1454,7 +1453,7 @@ build_test_list(char *argv[], int argc, const char *source, const char *build)
struct testlist *listhead, *current;
/* Create the initial container list that will hold our results. */
- listhead = xcalloc(1, sizeof(struct testlist));
+ listhead = xcalloc(1, struct testlist);
current = NULL;
/* Walk the list of arguments and create test sets for them. */
@@ -1462,13 +1461,13 @@ build_test_list(char *argv[], int argc, const char *source, const char *build)
if (current == NULL)
current = listhead;
else {
- current->next = xcalloc(1, sizeof(struct testlist));
+ current->next = xcalloc(1, struct testlist);
current = current->next;
}
- current->ts = xcalloc(1, sizeof(struct testset));
+ current->ts = xcalloc(1, struct testset);
current->ts->plan = PLAN_INIT;
current->ts->file = xstrdup(argv[i]);
- current->ts->command = xcalloc(2, sizeof(char *));
+ current->ts->command = xcalloc(2, char *);
current->ts->command[0] = find_test(current->ts->file, source, build);
current->ts->command[1] = NULL;
}
@@ -1575,10 +1574,10 @@ test_batch(struct testlist *tests, enum test_verbose verbose)
/* If the test fails, we shuffle it over to the fail list. */
if (!succeeded) {
if (failhead == NULL) {
- failhead = xmalloc(sizeof(struct testset));
+ failhead = xcalloc(1, struct testlist);
failtail = failhead;
} else {
- failtail->next = xmalloc(sizeof(struct testset));
+ failtail->next = xcalloc(1, struct testlist);
failtail = failtail->next;
}
failtail->ts = ts;
diff --git a/tests/docs/urls-t b/tests/style/obsolete-strings-t
index 9a87cca..1be6085 100755
--- a/tests/docs/urls-t
+++ b/tests/style/obsolete-strings-t
@@ -1,10 +1,10 @@
#!/usr/bin/perl
#
-# Check URLs in source files.
+# Check for obsolete strings in source files.
#
-# Examine all source files in a distribution for bad URL patterns and report
-# on files that fail this check. Currently, this just checks for my old email
-# address and that all the links to www.eyrie.org are https.
+# Examine all source files in a distribution for obsolete strings and report
+# on files that fail this check. This catches various transitions I want to
+# do globally in all my packages, like changing my personal URLs to https.
#
# The canonical version of this file is maintained in the rra-c-util package,
# which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
@@ -37,18 +37,22 @@ use warnings;
use lib "$ENV{C_TAP_SOURCE}/tap/perl";
-use File::Basename qw(basename);
-use Test::More;
use Test::RRA qw(skip_unless_author);
use Test::RRA::Automake qw(all_files automake_setup);
+use File::Basename qw(basename);
+use Test::More;
+
# Bad patterns to search for.
my @BAD_REGEXES = (qr{ http:// \S+ [.]eyrie[.]org }xms);
-my @BAD_STRINGS = qw(rra@stanford.edu);
+my @BAD_STRINGS = qw(rra@stanford.edu RRA_MAINTAINER_TESTS);
+
+# File names to exclude from this check.
+my %EXCLUDE = map { $_ => 1 } qw(NEWS obsolete-strings.t obsolete-strings-t);
# Only run this test for the package author, since it doesn't indicate any
# user-noticable flaw in the package itself.
-skip_unless_author('Documentation URL tests');
+skip_unless_author('Obsolete strings tests');
# Set up Automake testing.
automake_setup();
@@ -62,8 +66,8 @@ sub check_file {
my ($path) = @_;
my $filename = basename($path);
- # Ignore this check itself (or the Perl version of it) and binary files.
- return if ($filename eq 'urls.t' || $filename eq 'urls-t');
+ # Ignore excluded and binary files.
+ return if $EXCLUDE{$filename};
return if !-T $path;
# Scan the file.
diff --git a/tests/tap/basic.c b/tests/tap/basic.c
index 8624839..88a2100 100644
--- a/tests/tap/basic.c
+++ b/tests/tap/basic.c
@@ -13,7 +13,7 @@
* documentation is at <https://www.eyrie.org/~eagle/software/c-tap-harness/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
- * Copyright 2009-2018 Russ Allbery <eagle@eyrie.org>
+ * Copyright 2009-2019 Russ Allbery <eagle@eyrie.org>
* Copyright 2001-2002, 2004-2008, 2011-2014
* The Board of Trustees of the Leland Stanford Junior University
*
@@ -101,6 +101,8 @@ static int _aborted = 0;
*/
struct cleanup_func {
test_cleanup_func func;
+ test_cleanup_func_with_data func_with_data;
+ void *data;
struct cleanup_func *next;
};
static struct cleanup_func *cleanup_funcs = NULL;
@@ -171,7 +173,7 @@ concat(const char *first, ...)
length++;
/* Create the string. */
- result = bmalloc(length);
+ result = bcalloc_type(length, char);
va_start(args, first);
offset = 0;
for (string = first; string != NULL; string = va_arg(args, const char *)) {
@@ -185,6 +187,68 @@ concat(const char *first, ...)
/*
+ * Helper function for check_diag_files to handle a single line in a diag
+ * file.
+ *
+ * The general scheme here used is as follows: read one line of output. If we
+ * get NULL, check for an error. If there was one, bail out of the test
+ * program; otherwise, return, and the enclosing loop will check for EOF.
+ *
+ * If we get some data, see if it ends in a newline. If it doesn't end in a
+ * newline, we have one of two cases: our buffer isn't large enough, in which
+ * case we resize it and try again, or we have incomplete data in the file, in
+ * which case we rewind the file and will try again next time.
+ *
+ * Returns a boolean indicating whether the last line was incomplete.
+ */
+static int
+handle_diag_file_line(struct diag_file *file, fpos_t where)
+{
+ int size;
+ size_t length;
+
+ /* Read the next line from the file. */
+ size = file->bufsize > INT_MAX ? INT_MAX : (int) file->bufsize;
+ if (fgets(file->buffer, size, file->file) == NULL) {
+ if (ferror(file->file))
+ sysbail("cannot read from %s", file->name);
+ return 0;
+ }
+
+ /*
+ * See if the line ends in a newline. If not, see which error case we
+ * have.
+ */
+ length = strlen(file->buffer);
+ if (file->buffer[length - 1] != '\n') {
+ int incomplete = 0;
+
+ /* Check whether we ran out of buffer space and resize if so. */
+ if (length < file->bufsize - 1)
+ incomplete = 1;
+ else {
+ file->bufsize += BUFSIZ;
+ file->buffer
+ = breallocarray_type(file->buffer, file->bufsize, char);
+ }
+
+ /*
+ * On either incomplete lines or too small of a buffer, rewind
+ * and read the file again (on the next pass, if incomplete).
+ * It's simpler than trying to double-buffer the file.
+ */
+ if (fsetpos(file->file, &where) < 0)
+ sysbail("cannot set position in %s", file->name);
+ return incomplete;
+ }
+
+ /* We saw a complete line. Print it out. */
+ printf("# %s", file->buffer);
+ return 0;
+}
+
+
+/*
* Check all registered diag_files for any output. We only print out the
* output if we see a complete line; otherwise, we wait for the next newline.
*/
@@ -193,20 +257,10 @@ check_diag_files(void)
{
struct diag_file *file;
fpos_t where;
- size_t length;
- int size, incomplete;
+ int incomplete;
/*
- * Walk through each file and read each line of output available. The
- * general scheme here used is as follows: try to read a line of output at
- * a time. If we get NULL, check for EOF; on EOF, advance to the next
- * file.
- *
- * If we get some data, see if it ends in a newline. If it doesn't end in
- * a newline, we have one of two cases: our buffer isn't large enough, in
- * which case we resize it and try again, or we have incomplete data in
- * the file, in which case we rewind the file and will try again next
- * time.
+ * Walk through each file and read each line of output available.
*/
for (file = diag_files; file != NULL; file = file->next) {
clearerr(file->file);
@@ -218,41 +272,7 @@ check_diag_files(void)
/* Continue until we get EOF or an incomplete line of data. */
incomplete = 0;
while (!feof(file->file) && !incomplete) {
- size = file->bufsize > INT_MAX ? INT_MAX : (int) file->bufsize;
- if (fgets(file->buffer, size, file->file) == NULL) {
- if (ferror(file->file))
- sysbail("cannot read from %s", file->name);
- continue;
- }
-
- /*
- * See if the line ends in a newline. If not, see which error
- * case we have. Use UINT_MAX as a substitute for SIZE_MAX (see
- * the comment for breallocarray).
- */
- length = strlen(file->buffer);
- if (file->buffer[length - 1] != '\n') {
- if (length < file->bufsize - 1)
- incomplete = 1;
- else {
- if (file->bufsize >= UINT_MAX - BUFSIZ)
- sysbail("line too long in %s", file->name);
- file->bufsize += BUFSIZ;
- file->buffer = brealloc(file->buffer, file->bufsize);
- }
-
- /*
- * On either incomplete lines or too small of a buffer, rewind
- * and read the file again (on the next pass, if incomplete).
- * It's simpler than trying to double-buffer the file.
- */
- if (fsetpos(file->file, &where) < 0)
- sysbail("cannot set position in %s", file->name);
- continue;
- }
-
- /* We saw a complete line. Print it out. */
- printf("# %s", file->buffer);
+ incomplete = handle_diag_file_line(file, where);
}
}
}
@@ -305,7 +325,13 @@ finish(void)
*/
primary = (_process == 0 || getpid() == _process);
while (cleanup_funcs != NULL) {
- cleanup_funcs->func(success, primary);
+ if (cleanup_funcs->func_with_data) {
+ void *data = cleanup_funcs->data;
+
+ cleanup_funcs->func_with_data(success, primary, data);
+ } else {
+ cleanup_funcs->func(success, primary);
+ }
current = cleanup_funcs;
cleanup_funcs = cleanup_funcs->next;
free(current);
@@ -617,8 +643,8 @@ is_blob(const void *left, const void *right, size_t len, const char *format,
if (success)
printf("ok %lu", testnum++);
else {
- const unsigned char *left_c = left;
- const unsigned char *right_c = right;
+ const unsigned char *left_c = (const unsigned char *) left;
+ const unsigned char *right_c = (const unsigned char *) right;
for (i = 0; i < len; i++) {
if (left_c[i] != right_c[i])
@@ -728,12 +754,12 @@ diag_file_add(const char *name)
{
struct diag_file *file, *prev;
- file = bcalloc(1, sizeof(struct diag_file));
+ file = bcalloc_type(1, struct diag_file);
file->name = bstrdup(name);
file->file = fopen(file->name, "r");
if (file->file == NULL)
sysbail("cannot open %s", name);
- file->buffer = bmalloc(BUFSIZ);
+ file->buffer = bcalloc_type(BUFSIZ, char);
file->bufsize = BUFSIZ;
if (diag_files == NULL)
diag_files = file;
@@ -852,7 +878,7 @@ bstrdup(const char *s)
size_t len;
len = strlen(s) + 1;
- p = malloc(len);
+ p = (char *) malloc(len);
if (p == NULL)
sysbail("failed to strdup %lu bytes", (unsigned long) len);
memcpy(p, s, len);
@@ -876,8 +902,8 @@ bstrndup(const char *s, size_t n)
for (p = s; (size_t) (p - s) < n && *p != '\0'; p++)
;
length = (size_t) (p - s);
- copy = malloc(length + 1);
- if (p == NULL)
+ copy = (char *) malloc(length + 1);
+ if (copy == NULL)
sysbail("failed to strndup %lu bytes", (unsigned long) length);
memcpy(copy, s, length);
copy[length] = '\0';
@@ -965,21 +991,39 @@ test_tmpdir_free(char *path)
free(path);
}
-
-/*
- * Register a cleanup function that is called when testing ends. All such
- * registered functions will be run by finish.
- */
-void
-test_cleanup_register(test_cleanup_func func)
+static void
+register_cleanup(test_cleanup_func func,
+ test_cleanup_func_with_data func_with_data, void *data)
{
struct cleanup_func *cleanup, **last;
- cleanup = bmalloc(sizeof(struct cleanup_func));
+ cleanup = bcalloc_type(1, struct cleanup_func);
cleanup->func = func;
+ cleanup->func_with_data = func_with_data;
+ cleanup->data = data;
cleanup->next = NULL;
last = &cleanup_funcs;
while (*last != NULL)
last = &(*last)->next;
*last = cleanup;
}
+
+/*
+ * Register a cleanup function that is called when testing ends. All such
+ * registered functions will be run by finish.
+ */
+void
+test_cleanup_register(test_cleanup_func func)
+{
+ register_cleanup(func, NULL, NULL);
+}
+
+/*
+ * Same as above, but also allows an opaque pointer to be passed to the cleanup
+ * function.
+ */
+void
+test_cleanup_register_with_data(test_cleanup_func_with_data func, void *data)
+{
+ register_cleanup(NULL, func, data);
+}
diff --git a/tests/tap/basic.h b/tests/tap/basic.h
index 3f46e4f..677b823 100644
--- a/tests/tap/basic.h
+++ b/tests/tap/basic.h
@@ -5,7 +5,7 @@
* documentation is at <https://www.eyrie.org/~eagle/software/c-tap-harness/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
- * Copyright 2009-2018 Russ Allbery <eagle@eyrie.org>
+ * Copyright 2009-2019 Russ Allbery <eagle@eyrie.org>
* Copyright 2001-2002, 2004-2008, 2011-2012, 2014
* The Board of Trustees of the Leland Stanford Junior University
*
@@ -145,6 +145,14 @@ char *bstrndup(const char *, size_t)
__attribute__((__malloc__, __nonnull__, __warn_unused_result__));
/*
+ * Macros that cast the return value from b* memory functions, making them
+ * usable in C++ code and providing some additional type safety.
+ */
+#define bcalloc_type(n, type) ((type *) bcalloc((n), sizeof(type)))
+#define breallocarray_type(p, n, type) \
+ ((type *) breallocarray((p), (n), sizeof(type)))
+
+/*
* Find a test file under C_TAP_BUILD or C_TAP_SOURCE, returning the full
* path. The returned path should be freed with test_file_path_free().
*/
@@ -168,11 +176,21 @@ void test_tmpdir_free(char *path);
* The function must return void and will be passed two arguments: an int that
* will be true if the test completed successfully and false otherwise, and an
* int that will be true if the cleanup function is run in the primary process
- * (the one that called plan or plan_lazy) and false otherwise.
+ * (the one that called plan or plan_lazy) and false otherwise. If
+ * test_cleanup_register_with_data is used instead, a generic pointer can be
+ * provided and will be passed to the cleanup function as a third argument.
+ *
+ * test_cleanup_register_with_data is the better API and should have been the
+ * only API. test_cleanup_register was an API error preserved for backward
+ * cmpatibility.
*/
typedef void (*test_cleanup_func)(int, int);
+typedef void (*test_cleanup_func_with_data)(int, int, void *);
+
void test_cleanup_register(test_cleanup_func)
__attribute__((__nonnull__));
+void test_cleanup_register_with_data(test_cleanup_func_with_data, void *)
+ __attribute__((__nonnull__));
END_DECLS
diff --git a/tests/tap/libtap.sh b/tests/tap/libtap.sh
index 38181d9..1827a68 100644
--- a/tests/tap/libtap.sh
+++ b/tests/tap/libtap.sh
@@ -10,8 +10,8 @@
# <https://www.eyrie.org/~eagle/software/c-tap-harness/>.
#
# Written by Russ Allbery <eagle@eyrie.org>
-# Copyright 2009, 2010, 2011, 2012, 2016 Russ Allbery <eagle@eyrie.org>
-# Copyright 2006, 2007, 2008, 2013
+# Copyright 2009-2012, 2016 Russ Allbery <eagle@eyrie.org>
+# Copyright 2006-2008, 2013
# The Board of Trustees of the Leland Stanford Junior University
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
diff --git a/tests/tap/macros.h b/tests/tap/macros.h
index 32ed815..cc6d104 100644
--- a/tests/tap/macros.h
+++ b/tests/tap/macros.h
@@ -8,7 +8,7 @@
* This file is part of C TAP Harness. The current version plus supporting
* documentation is at <https://www.eyrie.org/~eagle/software/c-tap-harness/>.
*
- * Copyright 2008, 2012, 2013, 2015 Russ Allbery <eagle@eyrie.org>
+ * Copyright 2008, 2012-2013, 2015 Russ Allbery <eagle@eyrie.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
diff --git a/tests/tap/perl/Test/RRA.pm b/tests/tap/perl/Test/RRA.pm
index cbfdc42..e4075a7 100644
--- a/tests/tap/perl/Test/RRA.pm
+++ b/tests/tap/perl/Test/RRA.pm
@@ -14,9 +14,29 @@ use 5.006;
use strict;
use warnings;
+use Carp qw(croak);
use Exporter;
use File::Temp;
-use Test::More;
+
+# Abort if Test::More was loaded before Test::RRA to be sure that we get the
+# benefits of the Test::More probing below.
+if ($INC{'Test/More.pm'}) {
+ croak('Test::More loaded before Test::RRA');
+}
+
+# Red Hat's base perl package doesn't include Test::More (one has to install
+# the perl-core package in addition). Try to detect this and skip any Perl
+# tests if Test::More is not present. This relies on Test::RRA being included
+# before Test::More.
+eval {
+ require Test::More;
+ Test::More->import();
+};
+if ($@) {
+ print "1..0 # SKIP Test::More required for test\n"
+ or croak('Cannot write to stdout');
+ exit 0;
+}
# For Perl 5.006 compatibility.
## no critic (ClassHierarchies::ProhibitExplicitISA)
@@ -36,7 +56,7 @@ BEGIN {
# This version should match the corresponding rra-c-util release, but with
# two digits for the minor version, including a leading zero if necessary,
# so that it will sort properly.
- $VERSION = '7.01';
+ $VERSION = '8.00';
}
# Compare a string to the contents of a file, similar to the standard is()
@@ -61,22 +81,27 @@ sub is_file_contents {
return;
}
- # Otherwise, we show a diff, but only if we have IPC::System::Simple.
- eval { require IPC::System::Simple };
+ # Otherwise, we show a diff, but only if we have IPC::System::Simple and
+ # diff succeeds. Otherwise, we fall back on showing the full expected and
+ # seen output.
+ eval {
+ require IPC::System::Simple;
+
+ my $tmp = File::Temp->new();
+ my $tmpname = $tmp->filename;
+ print {$tmp} $got or BAIL_OUT("Cannot write to $tmpname: $!\n");
+ my @command = ('diff', '-u', $expected, $tmpname);
+ my $diff = IPC::System::Simple::capturex([0 .. 1], @command);
+ diag($diff);
+ };
if ($@) {
- ok(0, $message);
- return;
+ diag('Expected:');
+ diag($expected);
+ diag('Seen:');
+ diag($data);
}
- # They're not equal. Write out what we got so that we can run diff.
- my $tmp = File::Temp->new();
- my $tmpname = $tmp->filename;
- print {$tmp} $got or BAIL_OUT("Cannot write to $tmpname: $!\n");
- my @command = ('diff', '-u', $expected, $tmpname);
- my $diff = IPC::System::Simple::capturex([0 .. 1], @command);
- diag($diff);
-
- # Remove the temporary file and report failure.
+ # Report failure.
ok(0, $message);
return;
}
@@ -91,7 +116,7 @@ sub is_file_contents {
sub skip_unless_author {
my ($description) = @_;
if (!$ENV{AUTHOR_TESTING}) {
- plan skip_all => "$description only run for author";
+ plan(skip_all => "$description only run for author");
}
return;
}
@@ -110,7 +135,7 @@ sub skip_unless_automated {
for my $env (qw(AUTOMATED_TESTING RELEASE_TESTING AUTHOR_TESTING)) {
return if $ENV{$env};
}
- plan skip_all => "$description normally skipped";
+ plan(skip_all => "$description normally skipped");
return;
}
@@ -152,14 +177,14 @@ sub use_prereq {
use $module $version \@imports;
1;
};
- $error = $@;
+ $error = $@;
$sigdie = $SIG{__DIE__} || undef;
}
# If the use failed for any reason, skip the test.
if (!$result || $error) {
my $name = length($version) > 0 ? "$module $version" : $module;
- plan skip_all => "$name required for test";
+ plan(skip_all => "$name required for test");
}
# If the module set $SIG{__DIE__}, we cleared that via local. Restore it.
@@ -202,6 +227,14 @@ This module collects utility functions that are useful for Perl test scripts.
It assumes Russ Allbery's Perl module layout and test conventions and will
only be useful for other people if they use the same conventions.
+This module B<must> be loaded before Test::More or it will abort during
+import. It will skip the test (by printing a skip message to standard output
+and exiting with status 0, equivalent to C<plan skip_all>) during import if
+Test::More is not available. This allows tests written in Perl using this
+module to be skipped if run on a system with Perl but not Test::More, such as
+Red Hat systems with the C<perl> package but not the C<perl-core> package
+installed.
+
=head1 FUNCTIONS
None of these functions are imported by default. The ones used by a script
@@ -246,7 +279,9 @@ Russ Allbery <eagle@eyrie.org>
=head1 COPYRIGHT AND LICENSE
-Copyright 2013, 2014 The Board of Trustees of the Leland Stanford Junior
+Copyright 2016, 2018-2019 Russ Allbery <eagle@eyrie.org>
+
+Copyright 2013-2014 The Board of Trustees of the Leland Stanford Junior
University
Permission is hereby granted, free of charge, to any person obtaining a copy
diff --git a/tests/tap/perl/Test/RRA/Automake.pm b/tests/tap/perl/Test/RRA/Automake.pm
index 73f4100..0d79333 100644
--- a/tests/tap/perl/Test/RRA/Automake.pm
+++ b/tests/tap/perl/Test/RRA/Automake.pm
@@ -68,12 +68,14 @@ BEGIN {
# This version should match the corresponding rra-c-util release, but with
# two digits for the minor version, including a leading zero if necessary,
# so that it will sort properly.
- $VERSION = '7.01';
+ $VERSION = '8.00';
}
# Directories to skip globally when looking for all files, or for directories
# that could contain Perl files.
-my @GLOBAL_SKIP = qw(.git _build autom4te.cache build-aux);
+my @GLOBAL_SKIP = qw(
+ .git _build autom4te.cache build-aux perl/_build perl/blib
+);
# Additional paths to skip when building a list of all files in the
# distribution. This primarily skips build artifacts that aren't interesting
@@ -104,7 +106,7 @@ sub all_files {
my $file = $_;
my $path = $File::Find::name;
$path =~ s{ \A [.]/ }{}xms;
- if ($skip{$path} or $files_skip{$file} or $file =~ m{ [.] lo \z }xms) {
+ if ($skip{$path} || $files_skip{$file} || $file =~ m{ [.] lo \z }xms) {
$File::Find::prune = 1;
return;
}
@@ -187,7 +189,7 @@ sub automake_setup {
@builddirs = File::Spec->splitdir($builddirs);
pop(@builddirs);
my $libdir = File::Spec->catdir(@builddirs, $LIBRARY_PATH);
- my $path = File::Spec->catpath($buildvol, $libdir, q{});
+ my $path = File::Spec->catpath($buildvol, $libdir, q{});
if (-d "$path/.libs") {
$path .= '/.libs';
}
@@ -227,7 +229,7 @@ sub perl_dirs {
}
# Convert the skip lists into hashes for convenience.
- my %skip = map { $_ => 1 } @skip, 'tests';
+ my %skip = map { $_ => 1 } @skip, 'tests';
my %skip_tests = map { $_ => 1 } @skip_tests;
# Build the list of top-level directories to test.
@@ -449,7 +451,7 @@ Russ Allbery <eagle@eyrie.org>
=head1 COPYRIGHT AND LICENSE
-Copyright 2014, 2015, 2018 Russ Allbery <eagle@eyrie.org>
+Copyright 2014-2015, 2018 Russ Allbery <eagle@eyrie.org>
Copyright 2013 The Board of Trustees of the Leland Stanford Junior University
diff --git a/tests/tap/perl/Test/RRA/Config.pm b/tests/tap/perl/Test/RRA/Config.pm
index b2f9446..725524e 100644
--- a/tests/tap/perl/Test/RRA/Config.pm
+++ b/tests/tap/perl/Test/RRA/Config.pm
@@ -36,7 +36,7 @@ BEGIN {
# This version should match the corresponding rra-c-util release, but with
# two digits for the minor version, including a leading zero if necessary,
# so that it will sort properly.
- $VERSION = '7.01';
+ $VERSION = '8.00';
}
# If C_TAP_BUILD or C_TAP_SOURCE are set in the environment, look for
@@ -187,9 +187,9 @@ Russ Allbery <eagle@eyrie.org>
=head1 COPYRIGHT AND LICENSE
-Copyright 2015, 2016 Russ Allbery <eagle@eyrie.org>
+Copyright 2015-2016 Russ Allbery <eagle@eyrie.org>
-Copyright 2013, 2014 The Board of Trustees of the Leland Stanford Junior
+Copyright 2013-2014 The Board of Trustees of the Leland Stanford Junior
University
Permission is hereby granted, free of charge, to any person obtaining a copy
diff --git a/tests/tap/perl/Test/RRA/ModuleVersion.pm b/tests/tap/perl/Test/RRA/ModuleVersion.pm
index 3b3d674..549213f 100644
--- a/tests/tap/perl/Test/RRA/ModuleVersion.pm
+++ b/tests/tap/perl/Test/RRA/ModuleVersion.pm
@@ -33,7 +33,7 @@ BEGIN {
# This version should match the corresponding rra-c-util release, but with
# two digits for the minor version, including a leading zero if necessary,
# so that it will sort properly.
- $VERSION = '7.01';
+ $VERSION = '8.00';
}
# A regular expression matching the version string for a module using the
@@ -129,21 +129,23 @@ sub _module_version {
# Throws: Text exception on I/O failure or inability to find version
sub _update_module_version {
my ($file, $version) = @_;
- open(my $in, q{<}, $file) or die "$0: cannot open $file: $!\n";
- open(my $out, q{>}, "$file.new")
- or die "$0: cannot create $file.new: $!\n";
- # If the version starts with v, use it without quotes. Otherwise, quote
- # it to prevent removal of trailing zeroes.
- if ($version !~ m{ \A v }xms) {
- $version = "'$version'";
+ # The old-style syntax may require different quoting. If the version
+ # starts with v, use it without quotes. Otherwise, quote it to prevent
+ # removal of trailing zeroes.
+ my $old_version = $version;
+ if ($old_version !~ m{ \A v }xms) {
+ $old_version = "'$old_version'";
}
# Scan for the version and replace it.
+ open(my $in, q{<}, $file) or die "$0: cannot open $file: $!\n";
+ open(my $out, q{>}, "$file.new")
+ or die "$0: cannot create $file.new: $!\n";
SCAN:
while (defined(my $line = <$in>)) {
if ( $line =~ s{ $REGEX_VERSION_PACKAGE }{$1$version$3}xms
- || $line =~ s{ $REGEX_VERSION_OLD }{$1$version$3}xms)
+ || $line =~ s{ $REGEX_VERSION_OLD }{$1$old_version$3}xms)
{
print {$out} $line or die "$0: cannot write to $file.new: $!\n";
last SCAN;
@@ -153,8 +155,8 @@ sub _update_module_version {
# Copy the rest of the input file to the output file.
print {$out} <$in> or die "$0: cannot write to $file.new: $!\n";
- close($out) or die "$0: cannot flush $file.new: $!\n";
- close($in) or die "$0: error reading from $file: $!\n";
+ close($out) or die "$0: cannot flush $file.new: $!\n";
+ close($in) or die "$0: error reading from $file: $!\n";
# All done. Rename the new file over top of the old file.
rename("$file.new", $file)
@@ -267,7 +269,7 @@ Russ Allbery <eagle@eyrie.org>
=head1 COPYRIGHT AND LICENSE
-Copyright 2016 Russ Allbery <eagle@eyrie.org>
+Copyright 2016, 2018, 2019 Russ Allbery <eagle@eyrie.org>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/tests/util/network/client-t.c b/tests/util/network/client-t.c
index a2ad7ea..0eb2c84 100644
--- a/tests/util/network/client-t.c
+++ b/tests/util/network/client-t.c
@@ -5,7 +5,7 @@
* which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
- * Copyright 2005, 2013-2014, 2016-2018 Russ Allbery <eagle@eyrie.org>
+ * Copyright 2005, 2013-2014, 2016-2019 Russ Allbery <eagle@eyrie.org>
* Copyright 2009-2013
* The Board of Trustees of the Leland Stanford Junior University
*
@@ -221,7 +221,8 @@ test_timeout_ipv4(void)
socket_type fd, c;
pid_t child;
socket_type block[20];
- int i, err;
+ unsigned int conn, i;
+ int err;
/*
* Create the listening socket. We set the listening queue size to 1,
@@ -258,9 +259,9 @@ test_timeout_ipv4(void)
* actually timing out, and sometimes they never do.
*/
alarm(20);
- for (i = 0; i < (int) ARRAY_SIZE(block); i++) {
- block[i] = network_connect_host("127.0.0.1", 11119, NULL, 1);
- if (block[i] == INVALID_SOCKET)
+ for (conn = 0; conn < ARRAY_SIZE(block); conn++) {
+ block[conn] = network_connect_host("127.0.0.1", 11119, NULL, 1);
+ if (block[conn] == INVALID_SOCKET)
break;
}
err = socket_errno;
@@ -273,11 +274,11 @@ test_timeout_ipv4(void)
* expect a failure due to timeout in a reasonable amount of time (less
* than our 20-second alarm).
*/
- if (i == ARRAY_SIZE(block))
+ if (conn == ARRAY_SIZE(block))
skip_block(2, "short listen queue does not prevent connections");
else {
- diag("Finally timed out on socket %d", i);
- ok(block[i] == INVALID_SOCKET, "Later connection timed out");
+ diag("Finally timed out on socket %u", conn);
+ ok(block[conn] == INVALID_SOCKET, "Later connection timed out");
if (err == ECONNRESET || err == ECONNREFUSED)
skip("connections rejected without timeout");
else
@@ -289,7 +290,7 @@ test_timeout_ipv4(void)
kill(child, SIGTERM);
waitpid(child, NULL, 0);
socket_close(c);
- for (i--; i >= 0; i--)
+ for (i = 0; i < conn; i++)
if (block[i] != INVALID_SOCKET)
socket_close(block[i]);
socket_close(fd);
diff --git a/tests/util/network/server-t.c b/tests/util/network/server-t.c
index 944546c..bd7ce7a 100644
--- a/tests/util/network/server-t.c
+++ b/tests/util/network/server-t.c
@@ -388,7 +388,7 @@ test_all(const char *source_ipv4, const char *source_ipv6 UNUSED)
unsigned int count, i;
pid_t child;
struct sockaddr *saddr;
- int status;
+ int status, family;
/* Bind sockets for all available local addresses. */
if (!network_bind_all(SOCK_STREAM, 11119, &fds, &count))
@@ -412,6 +412,8 @@ test_all(const char *source_ipv4, const char *source_ipv6 UNUSED)
/* Get the socket type to determine what type of client to run. */
saddr = get_sockaddr(fd);
+ family = saddr->sa_family;
+ free(saddr);
/*
* Fork off a child writer and test the server accept. If IPV6_V6ONLY
@@ -422,23 +424,24 @@ test_all(const char *source_ipv4, const char *source_ipv6 UNUSED)
if (child < 0)
sysbail("cannot fork");
else if (child == 0) {
- if (saddr->sa_family == AF_INET) {
+ if (family == AF_INET) {
client_writer("::1", source_ipv6, false);
client_writer("127.0.0.1", source_ipv4, true);
#ifdef HAVE_INET6
- } else if (saddr->sa_family == AF_INET6) {
+ } else if (family == AF_INET6) {
# ifdef IPV6_V6ONLY
client_writer("127.0.0.1", source_ipv4, false);
# endif
client_writer("::1", source_ipv6, true);
#endif
+ } else {
+ die("unknown socket family %d", family);
}
} else {
test_server_accept(fd);
waitpid(child, &status, 0);
is_int(0, status, "client made correct connections");
}
- free(saddr);
}
network_bind_all_free(fds);
diff --git a/tests/util/xmalloc-t b/tests/util/xmalloc-t
index e73a7c6..8f2c22e 100755
--- a/tests/util/xmalloc-t
+++ b/tests/util/xmalloc-t
@@ -6,7 +6,7 @@
# which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
#
# Written by Russ Allbery <eagle@eyrie.org>
-# Copyright 2000-2001, 2006, 2014, 2016 Russ Allbery <eagle@eyrie.org>
+# Copyright 2000-2001, 2006, 2014, 2016, 2019 Russ Allbery <eagle@eyrie.org>
# Copyright 2008-2010, 2012
# The Board of Trustees of the Leland Stanford Junior University
#
@@ -101,46 +101,46 @@ ok_xmalloc "vasprintf large" 0 "" "v" "30000000" "0"
# We assume that there are enough miscellaneous allocations that an allocation
# exactly as large as the limit will always fail.
ok_xmalloc "malloc fail" 1 \
- "failed to malloc 30000000 bytes at xmalloc.c line 41" \
+ "failed to malloc 30000000 bytes at xmalloc.c line 42" \
"m" "30000000" "30000000"
ok_xmalloc "realloc fail" 1 \
- "failed to realloc 30000000 bytes at xmalloc.c line 69" \
+ "failed to realloc 30000000 bytes at xmalloc.c line 71" \
"r" "30000000" "30000000"
ok_xmalloc "reallocarray fail" 1 \
- "failed to reallocarray 30000000 bytes at xmalloc.c line 99" \
+ "failed to reallocarray 30000000 bytes at xmalloc.c line 100" \
"y" "30000000" "30000000"
ok_xmalloc "strdup fail" 1 \
- "failed to strdup 30000000 bytes at xmalloc.c line 130" \
+ "failed to strdup 30000000 bytes at xmalloc.c line 131" \
"s" "30000000" "30000000"
ok_xmalloc "strndup fail" 1 \
- "failed to strndup 30000000 bytes at xmalloc.c line 176" \
+ "failed to strndup 30000000 bytes at xmalloc.c line 177" \
"n" "30000000" "30000000"
ok_xmalloc "calloc fail" 1 \
- "failed to calloc 30000000 bytes at xmalloc.c line 200" \
+ "failed to calloc 30000000 bytes at xmalloc.c line 201" \
"c" "30000000" "30000000"
ok_xmalloc "asprintf fail" 1 \
- "failed to asprintf 30000000 bytes at xmalloc.c line 224" \
+ "failed to asprintf 30000000 bytes at xmalloc.c line 225" \
"a" "30000000" "30000000"
ok_xmalloc "vasprintf fail" 1 \
- "failed to vasprintf 30000000 bytes at xmalloc.c line 243" \
+ "failed to vasprintf 30000000 bytes at xmalloc.c line 244" \
"v" "30000000" "30000000"
# Check our custom error handler.
-ok_xmalloc "malloc custom" 1 "malloc 30000000 xmalloc.c 41" \
+ok_xmalloc "malloc custom" 1 "malloc 30000000 xmalloc.c 42" \
"M" "30000000" "30000000"
-ok_xmalloc "realloc custom" 1 "realloc 30000000 xmalloc.c 69" \
+ok_xmalloc "realloc custom" 1 "realloc 30000000 xmalloc.c 71" \
"R" "30000000" "30000000"
-ok_xmalloc "reallocarray custom" 1 "reallocarray 30000000 xmalloc.c 99" \
+ok_xmalloc "reallocarray custom" 1 "reallocarray 30000000 xmalloc.c 100" \
"Y" "30000000" "30000000"
-ok_xmalloc "strdup custom" 1 "strdup 30000000 xmalloc.c 130" \
+ok_xmalloc "strdup custom" 1 "strdup 30000000 xmalloc.c 131" \
"S" "30000000" "30000000"
-ok_xmalloc "strndup custom" 1 "strndup 30000000 xmalloc.c 176" \
+ok_xmalloc "strndup custom" 1 "strndup 30000000 xmalloc.c 177" \
"N" "30000000" "30000000"
-ok_xmalloc "calloc custom" 1 "calloc 30000000 xmalloc.c 200" \
+ok_xmalloc "calloc custom" 1 "calloc 30000000 xmalloc.c 201" \
"C" "30000000" "30000000"
-ok_xmalloc "asprintf custom" 1 "asprintf 30000000 xmalloc.c 224" \
+ok_xmalloc "asprintf custom" 1 "asprintf 30000000 xmalloc.c 225" \
"A" "30000000" "30000000"
-ok_xmalloc "vasprintf custom" 1 "vasprintf 30000000 xmalloc.c 243" \
+ok_xmalloc "vasprintf custom" 1 "vasprintf 30000000 xmalloc.c 244" \
"V" "30000000" "30000000"
# Check the smaller ones again just for grins.
diff --git a/tests/util/xmalloc.c b/tests/util/xmalloc.c
index d157bbb..75fd5ca 100644
--- a/tests/util/xmalloc.c
+++ b/tests/util/xmalloc.c
@@ -34,6 +34,7 @@
#include <config.h>
#include <portable/system.h>
+#include <assert.h>
#include <ctype.h>
#include <errno.h>
#ifdef HAVE_SYS_TIME_H
@@ -94,6 +95,7 @@ test_realloc(size_t size)
char *buffer;
size_t i;
+ assert(size > 10);
buffer = xmalloc(10);
if (buffer == NULL)
return 0;
@@ -101,8 +103,7 @@ test_realloc(size_t size)
buffer = xrealloc(buffer, size);
if (buffer == NULL)
return 0;
- if (size > 0)
- memset(buffer + 10, 2, size - 10);
+ memset(buffer + 10, 2, size - 10);
for (i = 0; i < 10; i++)
if (buffer[i] != 1)
return 0;