summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/README (renamed from tests/HOWTO)36
-rw-r--r--tests/client/basic-t.in15
-rw-r--r--tests/client/full-t.in23
-rw-r--r--tests/client/prompt-t.in23
-rw-r--r--tests/client/rekey-t.in15
-rwxr-xr-xtests/data/cmd-wrapper5
-rwxr-xr-xtests/docs/pod-spelling-t9
-rwxr-xr-xtests/docs/pod-t9
-rwxr-xr-xtests/perl/minimum-version-t9
-rwxr-xr-xtests/perl/module-version-t14
-rwxr-xr-xtests/perl/strict-t11
-rw-r--r--tests/portable/asprintf-t.c23
-rw-r--r--tests/portable/mkstemp-t.c17
-rw-r--r--tests/portable/setenv-t.c18
-rw-r--r--tests/portable/snprintf-t.c11
-rw-r--r--tests/runtests.c331
-rwxr-xr-xtests/server/admin-t5
-rwxr-xr-xtests/server/backend-t5
-rwxr-xr-xtests/server/keytab-t9
-rwxr-xr-xtests/server/report-t5
-rw-r--r--tests/tap/basic.c136
-rw-r--r--tests/tap/basic.h34
-rw-r--r--tests/tap/kerberos.c35
-rw-r--r--tests/tap/kerberos.h15
-rw-r--r--tests/tap/kerberos.sh10
-rw-r--r--tests/tap/libtap.sh28
-rw-r--r--tests/tap/macros.h4
-rw-r--r--tests/tap/messages.c9
-rw-r--r--tests/tap/messages.h7
-rw-r--r--tests/tap/perl/Test/RRA.pm57
-rw-r--r--tests/tap/perl/Test/RRA/Automake.pm189
-rw-r--r--tests/tap/perl/Test/RRA/Config.pm36
-rw-r--r--tests/tap/perl/Test/RRA/ModuleVersion.pm10
-rw-r--r--tests/tap/process.c16
-rw-r--r--tests/tap/process.h6
-rw-r--r--tests/tap/remctl.sh9
-rw-r--r--tests/tap/string.c6
-rw-r--r--tests/tap/string.h6
-rw-r--r--tests/util/messages-krb5-t.c10
-rw-r--r--tests/util/messages-t.c145
-rwxr-xr-xtests/util/xmalloc-t12
-rw-r--r--tests/util/xmalloc.c16
42 files changed, 986 insertions, 403 deletions
diff --git a/tests/HOWTO b/tests/README
index b94985d..186d2d5 100644
--- a/tests/HOWTO
+++ b/tests/README
@@ -70,18 +70,20 @@ Writing TAP Tests
One of the special features of C TAP Harness is the environment that
it sets up for your test cases. If your test program is called under
- the runtests driver, the environment variables SOURCE and BUILD will
- be set to the top of the test directory in the source tree and the top
- of the build tree, respectively. You can use those environment
- variables to locate additional test data, programs and libraries built
- as part of your software build, and other supporting information
- needed by tests.
+ the runtests driver, the environment variables C_TAP_SOURCE and
+ C_TAP_BUILD will be set to the top of the test directory in the source
+ tree and the top of the build tree, respectively. You can use those
+ environment variables to locate additional test data, programs and
+ libraries built as part of your software build, and other supporting
+ information needed by tests.
The C and shell TAP libraries support a test_file_path() function,
which looks for a file under the build tree and then under the source
- tree, using the BUILD and SOURCE environment variables, and return the
- full path to the file. This can be used to locate supporting data
- files.
+ tree, using the C_TAP_BUILD and C_TAP_SOURCE environment variables,
+ and return the full path to the file. This can be used to locate
+ supporting data files. They also support a test_tmpdir() function
+ that returns a directory that can be used for temporary files during
+ tests.
Perl
@@ -151,7 +153,7 @@ Writing TAP Tests
Complete API documentation for the basic C TAP library that comes with
C TAP Harness is available at:
- <http://www.eyrie.org/~eagle/software/c-tap-harness/>
+ <https://www.eyrie.org/~eagle/software/c-tap-harness/>
It's common to need additional test functions and utility functions
for your C tests, particularly if you have to set up and tear down a
@@ -168,7 +170,7 @@ Writing TAP Tests
Libraries of additional useful TAP test functions are available in
rra-c-util at:
- <http://www.eyrie.org/~eagle/software/rra-c-util/>
+ <https://www.eyrie.org/~eagle/software/rra-c-util/>
Some of the code there is particularly useful when testing programs
that require Kerberos keys.
@@ -190,15 +192,15 @@ Writing TAP Tests
your test suite area. It can then be loaded by tests written in shell
using the environment set up by runtests with:
- . "$SOURCE"/tap/libtap.sh
+ . "$C_TAP_SOURCE"/tap/libtap.sh
Here is a complete test case written in shell which produces the same
output as the TAP sample above:
#!/bin/sh
- . "$SOURCE"/tap/libtap.sh
- cd "$BUILD"
+ . "$C_TAP_SOURCE"/tap/libtap.sh
+ cd "$C_TAP_BUILD"
plan 4
ok 'the first test' true
@@ -238,11 +240,13 @@ Writing TAP Tests
License
This file is part of the documentation of C TAP Harness, which can be
- found at <http://www.eyrie.org/~eagle/software/c-tap-harness/>.
+ found at <https://www.eyrie.org/~eagle/software/c-tap-harness/>.
- Copyright 2010 Russ Allbery <eagle@eyrie.org>
+ Copyright 2010, 2016 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 this notice are preserved. This file is offered as-is,
without any warranty.
+
+ SPDX-License-Identifier: FSFAP
diff --git a/tests/client/basic-t.in b/tests/client/basic-t.in
index 974b636..f9dc6dd 100644
--- a/tests/client/basic-t.in
+++ b/tests/client/basic-t.in
@@ -3,16 +3,17 @@
# Test suite for the wallet command-line client.
#
# Written by Russ Allbery <eagle@eyrie.org>
-# Copyright 2006, 2007, 2008, 2010
+# Copyright 2018 Russ Allbery <eagle@eyrie.org>
+# Copyright 2006-2008, 2010
# The Board of Trustees of the Leland Stanford Junior University
#
# See LICENSE for licensing terms.
# Load the test library.
-. "$SOURCE/tap/libtap.sh"
-. "$SOURCE/tap/kerberos.sh"
-. "$SOURCE/tap/remctl.sh"
-cd "$SOURCE"
+. "$C_TAP_SOURCE/tap/libtap.sh"
+. "$C_TAP_SOURCE/tap/kerberos.sh"
+. "$C_TAP_SOURCE/tap/remctl.sh"
+cd "$C_TAP_SOURCE"
# We need a modified krb5.conf file to test wallet configuration settings in
# krb5.conf. Despite the hard-coding of test-k5.stanford.edu, this test isn't
@@ -54,8 +55,8 @@ elif [ -z '@REMCTLD@' ] ; then
else
plan 36
fi
-remctld_start '@REMCTLD@' "$SOURCE/data/basic.conf"
-wallet="$BUILD/../client/wallet"
+remctld_start '@REMCTLD@' "$C_TAP_SOURCE/data/basic.conf"
+wallet="$C_TAP_BUILD/../client/wallet"
# Make sure everything's clean.
rm -f output output.bak keytab keytab.bak srvtab srvtab.bak autocreated
diff --git a/tests/client/full-t.in b/tests/client/full-t.in
index 80bb20f..1ad486c 100644
--- a/tests/client/full-t.in
+++ b/tests/client/full-t.in
@@ -4,6 +4,7 @@
# End-to-end tests for the wallet client.
#
# Written by Russ Allbery <eagle@eyrie.org>
+# Copyright 2018 Russ Allbery <eagle@eyrie.org>
# Copyright 2008, 2010, 2014
# The Board of Trustees of the Leland Stanford Junior University
#
@@ -14,14 +15,14 @@ use warnings;
# Point to our server configuration. This must be done before Wallet::Config
# is loaded, and it's pulled in as a prerequisite for Wallet::Admin.
-BEGIN { $ENV{WALLET_CONFIG} = "$ENV{SOURCE}/data/wallet.conf" }
+BEGIN { $ENV{WALLET_CONFIG} = "$ENV{C_TAP_SOURCE}/data/wallet.conf" }
use Test::More tests => 59;
-use lib "$ENV{SOURCE}/../perl/lib";
+use lib "$ENV{C_TAP_SOURCE}/../perl/lib";
use Wallet::Admin;
-use lib "$ENV{SOURCE}/../perl/t/lib";
+use lib "$ENV{C_TAP_SOURCE}/../perl/t/lib";
use Util;
# Make a call to the wallet client. Takes the principal used by the server
@@ -37,9 +38,9 @@ sub wallet {
or die "cannot create wallet.out: $!\n";
open (STDERR, '>', 'wallet.err')
or die "cannot create wallet.err: $!\n";
- exec ("$ENV{BUILD}/../client/wallet", '-k', $principal, '-p',
+ exec ("$ENV{C_TAP_BUILD}/../client/wallet", '-k', $principal, '-p',
'14373', '-s', 'localhost', @command)
- or die "cannot run $ENV{BUILD}/client/wallet: $!\n";
+ or die "cannot run $ENV{C_TAP_BUILD}/client/wallet: $!\n";
} else {
waitpid ($pid, 0);
}
@@ -56,23 +57,23 @@ sub wallet {
}
# cd to the correct directory.
-chdir "$ENV{SOURCE}" or die "Cannot chdir to $ENV{SOURCE}: $!\n";
+chdir "$ENV{C_TAP_SOURCE}" or die "Cannot chdir to $ENV{C_TAP_SOURCE}: $!\n";
SKIP: {
skip 'no keytab configuration', 59
- unless -f "$ENV{BUILD}/config/keytab";
+ unless -f "$ENV{C_TAP_BUILD}/config/keytab";
my $remctld = '@REMCTLD@';
skip 'remctld not found', 59 unless $remctld;
# Spawn remctld and get local tickets. Don't destroy the user's Kerberos
# ticket cache.
unlink ('krb5cc_test', 'test-pid');
- my $principal = contents ("$ENV{BUILD}/config/principal");
+ my $principal = contents ("$ENV{C_TAP_BUILD}/config/principal");
remctld_spawn ($remctld, $principal,
- "$ENV{BUILD}/config/keytab",
- "$ENV{SOURCE}/data/full.conf");
+ "$ENV{C_TAP_BUILD}/config/keytab",
+ "$ENV{C_TAP_SOURCE}/data/full.conf");
$ENV{KRB5CCNAME} = 'krb5cc_test';
- getcreds ("$ENV{BUILD}/config/keytab", $principal);
+ getcreds ("$ENV{C_TAP_BUILD}/config/keytab", $principal);
# Use Wallet::Admin to set up the database.
db_setup;
diff --git a/tests/client/prompt-t.in b/tests/client/prompt-t.in
index d3a1eac..d5e9f17 100644
--- a/tests/client/prompt-t.in
+++ b/tests/client/prompt-t.in
@@ -4,6 +4,7 @@
# Password prompting tests for the wallet client.
#
# Written by Russ Allbery <eagle@eyrie.org>
+# Copyright 2018 Russ Allbery <eagle@eyrie.org>
# Copyright 2008, 2010, 2014
# The Board of Trustees of the Leland Stanford Junior University
#
@@ -14,18 +15,18 @@ use warnings;
use Test::More tests => 5;
-use lib "$ENV{SOURCE}/../perl/lib";
+use lib "$ENV{C_TAP_SOURCE}/../perl/lib";
use Wallet::Admin;
-use lib "$ENV{SOURCE}/../perl/t/lib";
+use lib "$ENV{C_TAP_SOURCE}/../perl/t/lib";
use Util;
# cd to the correct directory.
-chdir "$ENV{SOURCE}" or die "Cannot chdir to $ENV{SOURCE}: $!\n";
+chdir "$ENV{C_TAP_SOURCE}" or die "Cannot chdir to $ENV{C_TAP_SOURCE}: $!\n";
SKIP: {
skip 'no password configuration', 5
- unless -f "$ENV{BUILD}/config/password";
+ unless -f "$ENV{C_TAP_BUILD}/config/password";
my $remctld = '@REMCTLD@';
skip 'remctld not found', 5 unless $remctld;
eval { require Expect };
@@ -38,21 +39,21 @@ SKIP: {
# Spawn remctld and set up with a different ticket cache.
unlink ('krb5cc_test', 'test-pid');
- my $principal = contents ("$ENV{BUILD}/config/principal");
- remctld_spawn ($remctld, $principal, "$ENV{BUILD}/config/keytab",
- "$ENV{SOURCE}/data/basic.conf");
+ my $principal = contents ("$ENV{C_TAP_BUILD}/config/principal");
+ remctld_spawn ($remctld, $principal, "$ENV{C_TAP_BUILD}/config/keytab",
+ "$ENV{C_TAP_SOURCE}/data/basic.conf");
$ENV{KRB5CCNAME} = 'krb5cc_test';
# Read in the principal and password.
- open (PASS, '<', "$ENV{BUILD}/config/password")
- or die "Cannot open $ENV{BUILD}/config/password: $!\n";
+ open (PASS, '<', "$ENV{C_TAP_BUILD}/config/password")
+ or die "Cannot open $ENV{C_TAP_BUILD}/config/password: $!\n";
my $user = <PASS>;
my $password = <PASS>;
close PASS;
chomp ($user, $password);
# Spawn wallet and check an invalid password.
- my $wallet = Expect->spawn ("$ENV{BUILD}/../client/wallet", '-k',
+ my $wallet = Expect->spawn ("$ENV{C_TAP_BUILD}/../client/wallet", '-k',
$principal, '-p', 14373, '-s', 'localhost',
'-c', 'fake-wallet', '-u', $user, 'get',
'keytab', 'service/fake-output');
@@ -63,7 +64,7 @@ SKIP: {
$wallet->soft_close;
# Now check a valid password.
- $wallet = Expect->spawn ("$ENV{BUILD}/../client/wallet", '-k',
+ $wallet = Expect->spawn ("$ENV{C_TAP_BUILD}/../client/wallet", '-k',
$principal, '-p', 14373, '-s', 'localhost',
'-c', 'fake-wallet', '-u', $user, 'get',
'keytab', 'service/fake-output');
diff --git a/tests/client/rekey-t.in b/tests/client/rekey-t.in
index c93b8eb..2e95a4e 100644
--- a/tests/client/rekey-t.in
+++ b/tests/client/rekey-t.in
@@ -3,16 +3,17 @@
# Test suite for the wallet-rekey command-line client.
#
# Written by Russ Allbery <eagle@eyrie.org>
-# Copyright 2006, 2007, 2008, 2010
+# Copyright 2018 Russ Allbery <eagle@eyrie.org>
+# Copyright 2006-2008, 2010
# The Board of Trustees of the Leland Stanford Junior University
#
# See LICENSE for licensing terms.
# Load the test library.
-. "$SOURCE/tap/libtap.sh"
-. "$SOURCE/tap/kerberos.sh"
-. "$SOURCE/tap/remctl.sh"
-cd "$SOURCE"
+. "$C_TAP_SOURCE/tap/libtap.sh"
+. "$C_TAP_SOURCE/tap/kerberos.sh"
+. "$C_TAP_SOURCE/tap/remctl.sh"
+cd "$C_TAP_SOURCE"
# We need a modified krb5.conf file to test wallet configuration settings in
# krb5.conf. Despite the hard-coding of test-k5.stanford.edu, this test isn't
@@ -47,8 +48,8 @@ elif [ -z '@REMCTLD@' ] ; then
else
plan 8
fi
-remctld_start '@REMCTLD@' "$SOURCE/data/basic.conf"
-wallet="$BUILD/../client/wallet-rekey"
+remctld_start '@REMCTLD@' "$C_TAP_SOURCE/data/basic.conf"
+wallet="$C_TAP_BUILD/../client/wallet-rekey"
# Rekeying should result in a merged keytab with both the old and new keys.
cp data/fake-keytab-old keytab
diff --git a/tests/data/cmd-wrapper b/tests/data/cmd-wrapper
index b5b6d26..c2d5da1 100755
--- a/tests/data/cmd-wrapper
+++ b/tests/data/cmd-wrapper
@@ -3,6 +3,7 @@
# Wrapper around the standard wallet-backend script that sets the Perl INC
# path and the WALLET_CONFIG environment variable appropriately.
-WALLET_CONFIG="$SOURCE/data/wallet.conf"
+WALLET_CONFIG="$C_TAP_SOURCE/data/wallet.conf"
export WALLET_CONFIG
-exec perl -I"$SOURCE/../perl/lib" "$SOURCE/../server/wallet-backend" -q "$@"
+exec perl -I"$C_TAP_SOURCE/../perl/lib" \
+ "$C_TAP_SOURCE/../server/wallet-backend" -q "$@"
diff --git a/tests/docs/pod-spelling-t b/tests/docs/pod-spelling-t
index 7b61c86..0419c24 100755
--- a/tests/docs/pod-spelling-t
+++ b/tests/docs/pod-spelling-t
@@ -3,10 +3,11 @@
# Checks all POD files in the tree for spelling errors using Test::Spelling.
#
# The canonical version of this file is maintained in the rra-c-util package,
-# which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
+# which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
#
# Written by Russ Allbery <eagle@eyrie.org>
-# Copyright 2012, 2013, 2014
+# Copyright 2016 Russ Allbery <eagle@eyrie.org>
+# Copyright 2012-2014
# The Board of Trustees of the Leland Stanford Junior University
#
# Permission is hereby granted, free of charge, to any person obtaining a
@@ -26,12 +27,14 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
+#
+# SPDX-License-Identifier: MIT
use 5.006;
use strict;
use warnings;
-use lib "$ENV{SOURCE}/tap/perl";
+use lib "$ENV{C_TAP_SOURCE}/tap/perl";
use Test::More;
use Test::RRA qw(skip_unless_author use_prereq);
diff --git a/tests/docs/pod-t b/tests/docs/pod-t
index 53f9925..7ea3409 100755
--- a/tests/docs/pod-t
+++ b/tests/docs/pod-t
@@ -4,10 +4,11 @@
# distribution, for POD formatting errors.
#
# The canonical version of this file is maintained in the rra-c-util package,
-# which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
+# which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
#
# Written by Russ Allbery <eagle@eyrie.org>
-# Copyright 2012, 2013, 2014
+# Copyright 2016 Russ Allbery <eagle@eyrie.org>
+# Copyright 2012-2014
# The Board of Trustees of the Leland Stanford Junior University
#
# Permission is hereby granted, free of charge, to any person obtaining a
@@ -27,12 +28,14 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
+#
+# SPDX-License-Identifier: MIT
use 5.006;
use strict;
use warnings;
-use lib "$ENV{SOURCE}/tap/perl";
+use lib "$ENV{C_TAP_SOURCE}/tap/perl";
use Test::More;
use Test::RRA qw(skip_unless_automated use_prereq);
diff --git a/tests/perl/minimum-version-t b/tests/perl/minimum-version-t
index 8c49327..7d81b46 100755
--- a/tests/perl/minimum-version-t
+++ b/tests/perl/minimum-version-t
@@ -7,10 +7,11 @@
# required for internal tools than for public code.
#
# The canonical version of this file is maintained in the rra-c-util package,
-# which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
+# which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
#
# Written by Russ Allbery <eagle@eyrie.org>
-# Copyright 2012, 2013, 2014
+# Copyright 2016 Russ Allbery <eagle@eyrie.org>
+# Copyright 2012-2014
# The Board of Trustees of the Leland Stanford Junior University
#
# Permission is hereby granted, free of charge, to any person obtaining a
@@ -30,12 +31,14 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
+#
+# SPDX-License-Identifier: MIT
use 5.006;
use strict;
use warnings;
-use lib "$ENV{SOURCE}/tap/perl";
+use lib "$ENV{C_TAP_SOURCE}/tap/perl";
use Test::More;
use Test::RRA qw(skip_unless_automated use_prereq);
diff --git a/tests/perl/module-version-t b/tests/perl/module-version-t
index f1ebf0f..878cc2d 100755
--- a/tests/perl/module-version-t
+++ b/tests/perl/module-version-t
@@ -9,17 +9,19 @@
#
# When given the --update option, instead fixes all of the Perl modules found
# to have the correct version.
+#
+# SPDX-License-Identifier: MIT
use 5.006;
use strict;
use warnings;
-# SOURCE may not be set if we're running this script manually to update
+# C_TAP_SOURCE may not be set if we're running this script manually to update
# version numbers. If it isn't, assume we're being run from the top of the
# tree.
BEGIN {
- if ($ENV{SOURCE}) {
- unshift(@INC, "$ENV{SOURCE}/tap/perl");
+ if ($ENV{C_TAP_SOURCE}) {
+ unshift(@INC, "$ENV{C_TAP_SOURCE}/tap/perl");
} else {
unshift(@INC, 'tests/tap/perl');
}
@@ -178,6 +180,10 @@ SOFTWARE.
=head1 SEE ALSO
This module is maintained in the rra-c-util package. The current version is
-available from L<http://www.eyrie.org/~eagle/software/rra-c-util/>.
+available from L<https://www.eyrie.org/~eagle/software/rra-c-util/>.
=cut
+
+# Local Variables:
+# copyright-at-end-flag: t
+# End:
diff --git a/tests/perl/strict-t b/tests/perl/strict-t
index 2df6d58..09ce157 100755
--- a/tests/perl/strict-t
+++ b/tests/perl/strict-t
@@ -7,10 +7,11 @@
# all pass a syntax check. Currently, test suite coverage is not checked.
#
# The canonical version of this file is maintained in the rra-c-util package,
-# which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
+# which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
#
# Written by Russ Allbery <eagle@eyrie.org>
-# Copyright 2012, 2013, 2014
+# Copyright 2016 Russ Allbery <eagle@eyrie.org>
+# Copyright 2012-2014
# The Board of Trustees of the Leland Stanford Junior University
#
# Permission is hereby granted, free of charge, to any person obtaining a
@@ -30,12 +31,14 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
+#
+# SPDX-License-Identifier: MIT
use 5.006;
use strict;
use warnings;
-use lib "$ENV{SOURCE}/tap/perl";
+use lib "$ENV{C_TAP_SOURCE}/tap/perl";
use Test::More;
use Test::RRA qw(skip_unless_automated use_prereq);
@@ -46,7 +49,7 @@ use Test::RRA::Config qw(@STRICT_IGNORE @STRICT_PREREQ);
skip_unless_automated('Strictness tests');
# Load prerequisite modules.
-use_prereq('Test::Strict');
+use_prereq('Test::Strict', '0.25');
# Check whether all prerequisites are available, and skip the test if any of
# them are not.
diff --git a/tests/portable/asprintf-t.c b/tests/portable/asprintf-t.c
index e556d95..3b10a66 100644
--- a/tests/portable/asprintf-t.c
+++ b/tests/portable/asprintf-t.c
@@ -2,17 +2,19 @@
* asprintf and vasprintf test suite.
*
* The canonical version of this file is maintained in the rra-c-util package,
- * which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
+ * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
+ * Copyright 2014, 2018 Russ Allbery <eagle@eyrie.org>
+ * Copyright 2006-2009, 2011
+ * The Board of Trustees of the Leland Stanford Junior University
*
- * The authors hereby relinquish any claim to any copyright that they may have
- * in this work, whether granted under contract or by operation of law or
- * international treaty, and hereby commit to the public, at large, that they
- * shall not, at any time in the future, seek to enforce any copyright in this
- * work against any person or entity, or prevent any person or entity from
- * copying, publishing, distributing or creating derivative works of this
- * work.
+ * Copying and distribution of this file, with or without modification, are
+ * permitted in any medium without royalty provided the copyright notice and
+ * this notice are preserved. This file is offered as-is, without any
+ * warranty.
+ *
+ * SPDX-License-Identifier: FSFAP
*/
#include <config.h>
@@ -23,9 +25,10 @@
int test_asprintf(char **, const char *, ...)
__attribute__((__format__(printf, 2, 3)));
-int test_vasprintf(char **, const char *, va_list);
+int test_vasprintf(char **, const char *, va_list)
+ __attribute__((__format__(printf, 2, 0)));
-static int
+static int __attribute__((__format__(printf, 2, 3)))
vatest(char **result, const char *format, ...)
{
va_list args;
diff --git a/tests/portable/mkstemp-t.c b/tests/portable/mkstemp-t.c
index 20a83fc..dc26821 100644
--- a/tests/portable/mkstemp-t.c
+++ b/tests/portable/mkstemp-t.c
@@ -2,17 +2,18 @@
* mkstemp test suite.
*
* The canonical version of this file is maintained in the rra-c-util package,
- * which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
+ * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
+ * Copyright 2009, 2011
+ * The Board of Trustees of the Leland Stanford Junior University
*
- * The authors hereby relinquish any claim to any copyright that they may have
- * in this work, whether granted under contract or by operation of law or
- * international treaty, and hereby commit to the public, at large, that they
- * shall not, at any time in the future, seek to enforce any copyright in this
- * work against any person or entity, or prevent any person or entity from
- * copying, publishing, distributing or creating derivative works of this
- * work.
+ * Copying and distribution of this file, with or without modification, are
+ * permitted in any medium without royalty provided the copyright notice and
+ * this notice are preserved. This file is offered as-is, without any
+ * warranty.
+ *
+ * SPDX-License-Identifier: FSFAP
*/
#include <config.h>
diff --git a/tests/portable/setenv-t.c b/tests/portable/setenv-t.c
index 15ed1fd..92a8c95 100644
--- a/tests/portable/setenv-t.c
+++ b/tests/portable/setenv-t.c
@@ -2,17 +2,19 @@
* setenv test suite.
*
* The canonical version of this file is maintained in the rra-c-util package,
- * which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
+ * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
+ * Copyright 2000-2006, 2017 Russ Allbery <eagle@eyrie.org>
+ * Copyright 2006-2009, 2011
+ * The Board of Trustees of the Leland Stanford Junior University
*
- * The authors hereby relinquish any claim to any copyright that they may have
- * in this work, whether granted under contract or by operation of law or
- * international treaty, and hereby commit to the public, at large, that they
- * shall not, at any time in the future, seek to enforce any copyright in this
- * work against any person or entity, or prevent any person or entity from
- * copying, publishing, distributing or creating derivative works of this
- * work.
+ * Copying and distribution of this file, with or without modification, are
+ * permitted in any medium without royalty provided the copyright notice and
+ * this notice are preserved. This file is offered as-is, without any
+ * warranty.
+ *
+ * SPDX-License-Identifier: FSFAP
*/
#include <config.h>
diff --git a/tests/portable/snprintf-t.c b/tests/portable/snprintf-t.c
index cc8cf00..7e8a68f 100644
--- a/tests/portable/snprintf-t.c
+++ b/tests/portable/snprintf-t.c
@@ -2,12 +2,11 @@
* snprintf test suite.
*
* The canonical version of this file is maintained in the rra-c-util package,
- * which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
+ * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
- * Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006
- * Russ Allbery <eagle@eyrie.org>
- * Copyright 2009, 2010
+ * Copyright 2000-2006, 2018 Russ Allbery <eagle@eyrie.org>
+ * Copyright 2009-2010
* The Board of Trustees of the Leland Stanford Junior University
* Copyright 1995 Patrick Powell
* Copyright 2001 Hrvoje Niksic
@@ -15,6 +14,8 @@
* This code is based on code written by Patrick Powell (papowell@astart.com)
* It may be used for any purpose as long as this notice remains intact
* on all source code distributions
+ *
+ * There is no SPDX-License-Identifier registered for this license.
*/
#include <config.h>
@@ -159,7 +160,7 @@ main(void)
&count, string, &lcount);
is_int(0, count, "correct output from two %%n");
is_int(31, lcount, "correct output from long %%ln");
- test_format(true, "(null)", 6, "%s", NULL);
+ test_format(true, "(null)", 6, "%s", (char *) NULL);
for (i = 0; fp_formats[i] != NULL; i++)
for (j = 0; j < ARRAY_SIZE(fp_nums); j++) {
diff --git a/tests/runtests.c b/tests/runtests.c
index 42a73ea..af15a5c 100644
--- a/tests/runtests.c
+++ b/tests/runtests.c
@@ -1,6 +1,37 @@
/*
* Run a set of tests, reporting results.
*
+ * Test suite driver that runs a set of tests implementing a subset of the
+ * Test Anything Protocol (TAP) and reports the results.
+ *
+ * Any bug reports, bug fixes, and improvements are very much welcome and
+ * 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>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+/*
* Usage:
*
* runtests [-hv] [-b <build-dir>] [-s <source-dir>] -l <test-list>
@@ -8,9 +39,10 @@
* runtests -o [-h] [-b <build-dir>] [-s <source-dir>] <test>
*
* In the first case, expects a list of executables located in the given file,
- * one line per executable. For each one, runs it as part of a test suite,
- * reporting results. In the second case, use the same infrastructure, but
- * run only the tests listed on the command line.
+ * one line per executable, possibly followed by a space-separated list of
+ * options. For each one, runs it as part of a test suite, reporting results.
+ * In the second case, use the same infrastructure, but run only the tests
+ * listed on the command line.
*
* Test output should start with a line containing the number of tests
* (numbered from 1 to this number), optionally preceded by "1..", although
@@ -48,41 +80,16 @@
* output. This is intended for use with failing tests so that the person
* running the test suite can get more details about what failed.
*
- * If built with the C preprocessor symbols SOURCE and BUILD defined, C TAP
- * Harness will export those values in the environment so that tests can find
- * the source and build directory and will look for tests under both
- * directories. These paths can also be set with the -b and -s command-line
- * options, which will override anything set at build time.
+ * If built with the C preprocessor symbols C_TAP_SOURCE and C_TAP_BUILD
+ * defined, C TAP Harness will export those values in the environment so that
+ * tests can find the source and build directory and will look for tests under
+ * both directories. These paths can also be set with the -b and -s
+ * command-line options, which will override anything set at build time.
*
* If the -v option is given, or the C_TAP_VERBOSE environment variable is set,
* display the full output of each test as it runs rather than showing a
* summary of the results of each test.
- *
- * Any bug reports, bug fixes, and improvements are very much welcome and
- * should be sent to the e-mail address below. This program is part of C TAP
- * Harness <http://www.eyrie.org/~eagle/software/c-tap-harness/>.
- *
- * Copyright 2000, 2001, 2004, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013,
- * 2014, 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"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
-*/
+ */
/* Required for fdopen(), getopt(), and putenv(). */
#if defined(__STRICT_ANSI__) || defined(PEDANTIC)
@@ -135,15 +142,17 @@
/*
* The source and build versions of the tests directory. This is used to set
- * the SOURCE and BUILD environment variables and find test programs, if set.
- * Normally, this should be set as part of the build process to the test
- * subdirectories of $(abs_top_srcdir) and $(abs_top_builddir) respectively.
+ * the C_TAP_SOURCE and C_TAP_BUILD environment variables (and the SOURCE and
+ * BUILD environment variables set for backward compatibility) and find test
+ * programs, if set. Normally, this should be set as part of the build
+ * process to the test subdirectories of $(abs_top_srcdir) and
+ * $(abs_top_builddir) respectively.
*/
-#ifndef SOURCE
-# define SOURCE NULL
+#ifndef C_TAP_SOURCE
+# define C_TAP_SOURCE NULL
#endif
-#ifndef BUILD
-# define BUILD NULL
+#ifndef C_TAP_BUILD
+# define C_TAP_BUILD NULL
#endif
/* Test status codes. */
@@ -177,7 +186,7 @@ enum plan_status {
/* Structure to hold data for a set of tests. */
struct testset {
char *file; /* The file name of the test. */
- char *path; /* The path to the test program. */
+ char **command; /* The argv vector to run the command. */
enum plan_status plan; /* The status of our plan. */
unsigned long count; /* Expected count of tests. */
unsigned long current; /* The last seen test number. */
@@ -188,7 +197,7 @@ struct testset {
unsigned long allocated; /* The size of the results table. */
enum test_status *results; /* Table of results by test number. */
unsigned int aborted; /* Whether the set was aborted. */
- int reported; /* Whether the results were reported. */
+ unsigned int reported; /* Whether the results were reported. */
int status; /* The exit status of the test. */
unsigned int all_skipped; /* Whether all tests were skipped. */
char *reason; /* Why all tests were skipped. */
@@ -240,6 +249,7 @@ Failed Set Fail/Total (%) Skip Stat Failing Tests\n\
#define xcalloc(n, size) x_calloc((n), (size), __FILE__, __LINE__)
#define xmalloc(size) 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__)
@@ -280,6 +290,8 @@ Failed Set Fail/Total (%) Skip Stat Failing Tests\n\
#endif
/* Declare internal functions that benefit from compiler attributes. */
+static void die(const char *, ...)
+ __attribute__((__nonnull__, __noreturn__, __format__(printf, 1, 2)));
static void sysdie(const char *, ...)
__attribute__((__nonnull__, __noreturn__, __format__(printf, 1, 2)));
static void *x_calloc(size_t, size_t, const char *, int)
@@ -290,6 +302,26 @@ static void *x_reallocarray(void *, size_t, size_t, const char *, int)
__attribute__((__alloc_size__(2, 3), __malloc__, __nonnull__(4)));
static char *x_strdup(const char *, const char *, int)
__attribute__((__malloc__, __nonnull__));
+static char *x_strndup(const char *, size_t, const char *, int)
+ __attribute__((__malloc__, __nonnull__));
+
+
+/*
+ * Report a fatal error and exit.
+ */
+static void
+die(const char *format, ...)
+{
+ va_list args;
+
+ fflush(stdout);
+ fprintf(stderr, "runtests: ");
+ va_start(args, format);
+ vfprintf(stderr, format, args);
+ va_end(args);
+ fprintf(stderr, "\n");
+ exit(1);
+}
/*
@@ -392,6 +424,35 @@ x_strdup(const char *s, const char *file, int line)
/*
+ * Copy the first n characters of a string, reporting a fatal error and
+ * existing on failure.
+ *
+ * Avoid using the system strndup function since it may not exist (on Mac OS
+ * X, for example), and there's no need to introduce another portability
+ * requirement.
+ */
+char *
+x_strndup(const char *s, size_t size, const char *file, int line)
+{
+ const char *p;
+ size_t len;
+ char *copy;
+
+ /* Don't assume that the source string is nul-terminated. */
+ for (p = s; (size_t) (p - s) < size && *p != '\0'; p++)
+ ;
+ len = (size_t) (p - s);
+ copy = malloc(len + 1);
+ if (copy == NULL)
+ sysdie("failed to strndup %lu bytes at %s line %d",
+ (unsigned long) len, file, line);
+ memcpy(copy, s, len);
+ copy[len] = '\0';
+ return copy;
+}
+
+
+/*
* Form a new string by concatenating multiple strings. The arguments must be
* terminated by (const char *) 0.
*
@@ -447,7 +508,7 @@ concat(const char *first, ...)
static double
tv_seconds(const struct timeval *tv)
{
- return difftime(tv->tv_sec, 0) + tv->tv_usec * 1e-6;
+ return difftime(tv->tv_sec, 0) + (double) tv->tv_usec * 1e-6;
}
@@ -485,12 +546,25 @@ skip_whitespace(const char *p)
/*
+ * Given a pointer to a string, skip any non-whitespace characters and return
+ * a pointer to the first whitespace character, or to the end of the string.
+ */
+static const char *
+skip_non_whitespace(const char *p)
+{
+ while (*p != '\0' && !isspace((unsigned char)(*p)))
+ p++;
+ return p;
+}
+
+
+/*
* Start a program, connecting its stdout to a pipe on our end and its stderr
* to /dev/null, and storing the file descriptor to read from in the two
* argument. Returns the PID of the new process. Errors are fatal.
*/
static pid_t
-test_start(const char *path, int *fd)
+test_start(char *const *command, int *fd)
{
int fds[2], infd, errfd;
pid_t child;
@@ -541,8 +615,9 @@ test_start(const char *path, int *fd)
}
/* Now, exec our process. */
- if (execl(path, path, (char *) 0) == -1)
+ if (execv(command[0], command) == -1)
_exit(CHILDERR_EXEC);
+ break;
/* In parent. Close the extra file descriptor. */
default:
@@ -1035,7 +1110,7 @@ test_run(struct testset *ts, enum test_verbose verbose)
char buffer[BUFSIZ];
/* Run the test program. */
- testpid = test_start(ts->path, &outfd);
+ testpid = test_start(ts->command, &outfd);
output = fdopen(outfd, "r");
if (!output) {
puts("ABORTED");
@@ -1097,6 +1172,7 @@ test_fail_summary(const struct testlist *fails)
struct testset *ts;
unsigned int chars;
unsigned long i, first, last, total;
+ double failed;
puts(header);
@@ -1105,8 +1181,9 @@ test_fail_summary(const struct testlist *fails)
for (; fails; fails = fails->next) {
ts = fails->ts;
total = ts->count - ts->skipped;
+ failed = (double) ts->failed;
printf("%-26.26s %4lu/%-4lu %3.0f%% %4lu ", ts->file, ts->failed,
- total, total ? (ts->failed * 100.0) / total : 0,
+ total, total ? (failed * 100.0) / (double) total : 0,
ts->skipped);
if (WIFEXITED(ts->status))
printf("%4d ", WEXITSTATUS(ts->status));
@@ -1203,19 +1280,111 @@ find_test(const char *name, const char *source, const char *build)
/*
+ * Parse a single line of a test list and store the test name and command to
+ * execute it in the given testset struct.
+ *
+ * Normally, each line is just the name of the test, which is located in the
+ * test directory and turned into a command to run. However, each line may
+ * have whitespace-separated options, which change the command that's run.
+ * Current supported options are:
+ *
+ * valgrind
+ * Run the test under valgrind if C_TAP_VALGRIND is set. The contents
+ * of that environment variable are taken as the valgrind command (with
+ * options) to run. The command is parsed with a simple split on
+ * whitespace and no quoting is supported.
+ *
+ * libtool
+ * If running under valgrind, use libtool to invoke valgrind. This avoids
+ * running valgrind on the wrapper shell script generated by libtool. If
+ * set, C_TAP_LIBTOOL must be set to the full path to the libtool program
+ * to use to run valgrind and thus the test. Ignored if the test isn't
+ * being run under valgrind.
+ */
+static void
+parse_test_list_line(const char *line, struct testset *ts, const char *source,
+ const char *build)
+{
+ const char *p, *end, *option, *libtool;
+ const char *valgrind = NULL;
+ unsigned int use_libtool = 0;
+ unsigned int use_valgrind = 0;
+ size_t len, i;
+
+ /* Determine the name of the test. */
+ p = skip_non_whitespace(line);
+ ts->file = xstrndup(line, p - line);
+
+ /* Check if any test options are set. */
+ p = skip_whitespace(p);
+ while (*p != '\0') {
+ 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);
+ }
+ p = skip_whitespace(end);
+ }
+
+ /* Construct the argv to run the test. First, find the length. */
+ len = 1;
+ if (use_valgrind && valgrind != NULL) {
+ p = skip_whitespace(valgrind);
+ while (*p != '\0') {
+ len++;
+ p = skip_whitespace(skip_non_whitespace(p));
+ }
+ if (use_libtool)
+ len += 2;
+ }
+
+ /* Now, build the command. */
+ ts->command = xcalloc(len + 1, sizeof(char *));
+ i = 0;
+ if (use_valgrind && valgrind != NULL) {
+ if (use_libtool) {
+ libtool = getenv("C_TAP_LIBTOOL");
+ if (libtool == NULL)
+ die("valgrind with libtool requested, but C_TAP_LIBTOOL is not"
+ " set");
+ ts->command[i++] = xstrdup(libtool);
+ ts->command[i++] = xstrdup("--mode=execute");
+ }
+ p = skip_whitespace(valgrind);
+ while (*p != '\0') {
+ end = skip_non_whitespace(p);
+ ts->command[i++] = xstrndup(p, end - p);
+ p = skip_whitespace(end);
+ }
+ }
+ if (i != len - 1)
+ die("internal error while constructing command line");
+ ts->command[i++] = find_test(ts->file, source, build);
+ ts->command[i] = NULL;
+}
+
+
+/*
* Read a list of tests from a file, returning the list of tests as a struct
* testlist, or NULL if there were no tests (such as a file containing only
* comments). Reports an error to standard error and exits if the list of
* tests cannot be read.
*/
static struct testlist *
-read_test_list(const char *filename)
+read_test_list(const char *filename, const char *source, const char *build)
{
FILE *file;
unsigned int line;
size_t length;
char buffer[BUFSIZ];
- const char *testname;
+ const char *start;
struct testlist *listhead, *current;
/* Create the initial container list that will hold our results. */
@@ -1240,10 +1409,10 @@ read_test_list(const char *filename)
buffer[length] = '\0';
/* Skip comments, leading spaces, and blank lines. */
- testname = skip_whitespace(buffer);
- if (strlen(testname) == 0)
+ start = skip_whitespace(buffer);
+ if (strlen(start) == 0)
continue;
- if (testname[0] == '#')
+ if (start[0] == '#')
continue;
/* Allocate the new testset structure. */
@@ -1255,7 +1424,9 @@ read_test_list(const char *filename)
}
current->ts = xcalloc(1, sizeof(struct testset));
current->ts->plan = PLAN_INIT;
- current->ts->file = xstrdup(testname);
+
+ /* Parse the line and store the results in the testset struct. */
+ parse_test_list_line(start, current->ts, source, build);
}
fclose(file);
@@ -1277,7 +1448,7 @@ read_test_list(const char *filename)
* freeing.
*/
static struct testlist *
-build_test_list(char *argv[], int argc)
+build_test_list(char *argv[], int argc, const char *source, const char *build)
{
int i;
struct testlist *listhead, *current;
@@ -1297,6 +1468,9 @@ build_test_list(char *argv[], int argc)
current->ts = xcalloc(1, sizeof(struct testset));
current->ts->plan = PLAN_INIT;
current->ts->file = xstrdup(argv[i]);
+ current->ts->command = xcalloc(2, sizeof(char *));
+ current->ts->command[0] = find_test(current->ts->file, source, build);
+ current->ts->command[1] = NULL;
}
/* If there were no tests, current is still NULL. */
@@ -1314,8 +1488,12 @@ build_test_list(char *argv[], int argc)
static void
free_testset(struct testset *ts)
{
+ size_t i;
+
free(ts->file);
- free(ts->path);
+ for (i = 0; ts->command[i] != NULL; i++)
+ free(ts->command[i]);
+ free(ts->command);
free(ts->results);
free(ts->reason);
free(ts);
@@ -1330,8 +1508,7 @@ free_testset(struct testset *ts)
* frees the test list that's passed in.
*/
static int
-test_batch(struct testlist *tests, const char *source, const char *build,
- enum test_verbose verbose)
+test_batch(struct testlist *tests, enum test_verbose verbose)
{
size_t length, i;
size_t longest = 0;
@@ -1382,7 +1559,6 @@ test_batch(struct testlist *tests, const char *source, const char *build,
fflush(stdout);
/* Run the test. */
- ts->path = find_test(ts->file, source, build);
succeeded = test_run(ts, verbose);
fflush(stdout);
if (verbose)
@@ -1446,7 +1622,7 @@ test_batch(struct testlist *tests, const char *source, const char *build,
fputs("All tests successful", stdout);
else
printf("Failed %lu/%lu tests, %.2f%% okay", failed, total,
- (total - failed) * 100.0 / total);
+ (double) (total - failed) * 100.0 / (double) total);
if (skipped != 0) {
if (skipped == 1)
printf(", %lu test skipped", skipped);
@@ -1479,8 +1655,9 @@ test_single(const char *program, const char *source, const char *build)
/*
- * Main routine. Set the SOURCE and BUILD environment variables and then,
- * given a file listing tests, run each test listed.
+ * Main routine. Set the C_TAP_SOURCE, C_TAP_BUILD, SOURCE, and BUILD
+ * environment variables and then, given a file listing tests, run each test
+ * listed.
*/
int
main(int argc, char *argv[])
@@ -1489,13 +1666,15 @@ main(int argc, char *argv[])
int status = 0;
int single = 0;
enum test_verbose verbose = CONCISE;
+ char *c_tap_source_env = NULL;
+ char *c_tap_build_env = NULL;
char *source_env = NULL;
char *build_env = NULL;
const char *program;
const char *shortlist;
const char *list = NULL;
- const char *source = SOURCE;
- const char *build = BUILD;
+ const char *source = C_TAP_SOURCE;
+ const char *build = C_TAP_BUILD;
struct testlist *tests;
program = argv[0];
@@ -1537,13 +1716,23 @@ main(int argc, char *argv[])
if (getenv("C_TAP_VERBOSE") != NULL)
verbose = VERBOSE;
- /* Set SOURCE and BUILD environment variables. */
+ /*
+ * Set C_TAP_SOURCE and C_TAP_BUILD environment variables. Also set
+ * SOURCE and BUILD for backward compatibility, although we're trying to
+ * migrate to the ones with a C_TAP_* prefix.
+ */
if (source != NULL) {
+ c_tap_source_env = concat("C_TAP_SOURCE=", source, (const char *) 0);
+ if (putenv(c_tap_source_env) != 0)
+ sysdie("cannot set C_TAP_SOURCE in the environment");
source_env = concat("SOURCE=", source, (const char *) 0);
if (putenv(source_env) != 0)
sysdie("cannot set SOURCE in the environment");
}
if (build != NULL) {
+ c_tap_build_env = concat("C_TAP_BUILD=", build, (const char *) 0);
+ if (putenv(c_tap_build_env) != 0)
+ sysdie("cannot set C_TAP_BUILD in the environment");
build_env = concat("BUILD=", build, (const char *) 0);
if (putenv(build_env) != 0)
sysdie("cannot set BUILD in the environment");
@@ -1559,20 +1748,24 @@ main(int argc, char *argv[])
else
shortlist++;
printf(banner, shortlist);
- tests = read_test_list(list);
- status = test_batch(tests, source, build, verbose) ? 0 : 1;
+ tests = read_test_list(list, source, build);
+ status = test_batch(tests, verbose) ? 0 : 1;
} else {
- tests = build_test_list(argv, argc);
- status = test_batch(tests, source, build, verbose) ? 0 : 1;
+ tests = build_test_list(argv, argc, source, build);
+ status = test_batch(tests, verbose) ? 0 : 1;
}
/* For valgrind cleanliness, free all our memory. */
if (source_env != NULL) {
+ putenv((char *) "C_TAP_SOURCE=");
putenv((char *) "SOURCE=");
+ free(c_tap_source_env);
free(source_env);
}
if (build_env != NULL) {
+ putenv((char *) "C_TAP_BUILD=");
putenv((char *) "BUILD=");
+ free(c_tap_build_env);
free(build_env);
}
exit(status);
diff --git a/tests/server/admin-t b/tests/server/admin-t
index f025d98..8fde012 100755
--- a/tests/server/admin-t
+++ b/tests/server/admin-t
@@ -3,7 +3,8 @@
# Tests for the wallet-admin dispatch code.
#
# Written by Russ Allbery <eagle@eyrie.org>
-# Copyright 2008, 2009, 2010, 2011, 2014
+# Copyright 2018 Russ Allbery <eagle@eyrie.org>
+# Copyright 2008-2011, 2014
# The Board of Trustees of the Leland Stanford Junior University
#
# See LICENSE for licensing terms.
@@ -68,7 +69,7 @@ sub upgrade {
# Wallet::Admin package has already been loaded.
package main;
$INC{'Wallet/Admin.pm'} = 'FAKE';
-eval { do "$ENV{SOURCE}/../server/wallet-admin" };
+eval { do "$ENV{C_TAP_SOURCE}/../server/wallet-admin" };
# Run the wallet admin client. This fun hack takes advantage of the fact that
# the wallet admin client is written in Perl so that we can substitute our own
diff --git a/tests/server/backend-t b/tests/server/backend-t
index 2ed8404..e8ea1ce 100755
--- a/tests/server/backend-t
+++ b/tests/server/backend-t
@@ -3,7 +3,8 @@
# Tests for the wallet-backend dispatch code.
#
# Written by Russ Allbery <eagle@eyrie.org>
-# Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014
+# Copyright 2018 Russ Allbery <eagle@eyrie.org>
+# Copyright 2006-2014
# The Board of Trustees of the Leland Stanford Junior University
#
# See LICENSE for licensing terms.
@@ -189,7 +190,7 @@ $INC{'Wallet/Server.pm'} = 'FAKE';
my $OUTPUT;
our $SYSLOG = \$OUTPUT;
my $INPUT = '';
-eval { do "$ENV{SOURCE}/../server/wallet-backend" };
+eval { do "$ENV{C_TAP_SOURCE}/../server/wallet-backend" };
# Run the wallet backend. This fun hack takes advantage of the fact that the
# wallet backend is written in Perl so that we can substitute our own
diff --git a/tests/server/keytab-t b/tests/server/keytab-t
index 94c1bd8..00c6e92 100755
--- a/tests/server/keytab-t
+++ b/tests/server/keytab-t
@@ -3,7 +3,8 @@
# Tests for the keytab-backend dispatch code.
#
# Written by Russ Allbery <eagle@eyrie.org>
-# Copyright 2006, 2007, 2010
+# Copyright 2018 Russ Allbery <eagle@eyrie.org>
+# Copyright 2006-2007, 2010
# The Board of Trustees of the Leland Stanford Junior University
#
# See LICENSE for licensing terms.
@@ -16,9 +17,9 @@ use Test::More tests => 63;
# Load the keytab-backend code and override various settings.
my $OUTPUT;
$SYSLOG = \$OUTPUT;
-eval { do "$ENV{SOURCE}/../server/keytab-backend" };
-$CONFIG = "$ENV{SOURCE}/data/allow-extract";
-$KADMIN = "$ENV{SOURCE}/data/fake-kadmin";
+eval { do "$ENV{C_TAP_SOURCE}/../server/keytab-backend" };
+$CONFIG = "$ENV{C_TAP_SOURCE}/data/allow-extract";
+$KADMIN = "$ENV{C_TAP_SOURCE}/data/fake-kadmin";
$TMP = '.';
# Run the keytab backend.
diff --git a/tests/server/report-t b/tests/server/report-t
index ad05363..2e0cef7 100755
--- a/tests/server/report-t
+++ b/tests/server/report-t
@@ -3,7 +3,8 @@
# Tests for the wallet-report dispatch code.
#
# Written by Russ Allbery <eagle@eyrie.org>
-# Copyright 2008, 2009, 2010
+# Copyright 2018 Russ Allbery <eagle@eyrie.org>
+# Copyright 2008-2010
# The Board of Trustees of the Leland Stanford Junior University
#
# See LICENSE for licensing terms.
@@ -72,7 +73,7 @@ sub owners {
# Wallet::Report package has already been loaded.
package main;
$INC{'Wallet/Report.pm'} = 'FAKE';
-eval { do "$ENV{SOURCE}/../server/wallet-report" };
+eval { do "$ENV{C_TAP_SOURCE}/../server/wallet-report" };
# Run the wallet report client. This fun hack takes advantage of the fact
# that the wallet report client is written in Perl so that we can substitute
diff --git a/tests/tap/basic.c b/tests/tap/basic.c
index 4f8be04..8624839 100644
--- a/tests/tap/basic.c
+++ b/tests/tap/basic.c
@@ -10,11 +10,11 @@
* up the TAP output format, or finding things in the test environment.
*
* This file is part of C TAP Harness. The current version plus supporting
- * documentation is at <http://www.eyrie.org/~eagle/software/c-tap-harness/>.
+ * documentation is at <https://www.eyrie.org/~eagle/software/c-tap-harness/>.
*
- * Copyright 2009, 2010, 2011, 2012, 2013, 2014, 2015
- * Russ Allbery <eagle@eyrie.org>
- * Copyright 2001, 2002, 2004, 2005, 2006, 2007, 2008, 2011, 2012, 2013, 2014
+ * Written by Russ Allbery <eagle@eyrie.org>
+ * Copyright 2009-2018 Russ Allbery <eagle@eyrie.org>
+ * Copyright 2001-2002, 2004-2008, 2011-2014
* The Board of Trustees of the Leland Stanford Junior University
*
* Permission is hereby granted, free of charge, to any person obtaining a
@@ -34,6 +34,8 @@
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
+ *
+ * SPDX-License-Identifier: MIT
*/
#include <errno.h>
@@ -128,8 +130,7 @@ static struct diag_file *diag_files = NULL;
do { \
if (format != NULL) { \
va_list args; \
- if (prefix != NULL) \
- printf("%s", prefix); \
+ printf("%s", prefix); \
va_start(args, format); \
vprintf(format, args); \
va_end(args); \
@@ -489,22 +490,81 @@ skip_block(unsigned long count, const char *reason, ...)
/*
- * Takes an expected integer and a seen integer and assumes the test passes
- * if those two numbers match.
+ * Takes two boolean values and requires the truth value of both match.
+ */
+int
+is_bool(int left, int right, const char *format, ...)
+{
+ int success;
+
+ fflush(stderr);
+ check_diag_files();
+ success = (!!left == !!right);
+ if (success)
+ printf("ok %lu", testnum++);
+ else {
+ diag(" left: %s", !!left ? "true" : "false");
+ diag("right: %s", !!right ? "true" : "false");
+ printf("not ok %lu", testnum++);
+ _failed++;
+ }
+ PRINT_DESC(" - ", format);
+ putchar('\n');
+ return success;
+}
+
+
+/*
+ * Takes two integer values and requires they match.
+ */
+int
+is_int(long left, long right, const char *format, ...)
+{
+ int success;
+
+ fflush(stderr);
+ check_diag_files();
+ success = (left == right);
+ if (success)
+ printf("ok %lu", testnum++);
+ else {
+ diag(" left: %ld", left);
+ diag("right: %ld", right);
+ printf("not ok %lu", testnum++);
+ _failed++;
+ }
+ PRINT_DESC(" - ", format);
+ putchar('\n');
+ return success;
+}
+
+
+/*
+ * Takes two strings and requires they match (using strcmp). NULL arguments
+ * are permitted and handled correctly.
*/
int
-is_int(long wanted, long seen, const char *format, ...)
+is_string(const char *left, const char *right, const char *format, ...)
{
int success;
fflush(stderr);
check_diag_files();
- success = (wanted == seen);
+
+ /* Compare the strings, being careful of NULL. */
+ if (left == NULL)
+ success = (right == NULL);
+ else if (right == NULL)
+ success = 0;
+ else
+ success = (strcmp(left, right) == 0);
+
+ /* Report the results. */
if (success)
printf("ok %lu", testnum++);
else {
- diag("wanted: %ld", wanted);
- diag(" seen: %ld", seen);
+ diag(" left: %s", left == NULL ? "(null)" : left);
+ diag("right: %s", right == NULL ? "(null)" : right);
printf("not ok %lu", testnum++);
_failed++;
}
@@ -515,26 +575,22 @@ is_int(long wanted, long seen, const char *format, ...)
/*
- * Takes a string and what the string should be, and assumes the test passes
- * if those strings match (using strcmp).
+ * Takes two unsigned longs and requires they match. On failure, reports them
+ * in hex.
*/
int
-is_string(const char *wanted, const char *seen, const char *format, ...)
+is_hex(unsigned long left, unsigned long right, const char *format, ...)
{
int success;
- if (wanted == NULL)
- wanted = "(null)";
- if (seen == NULL)
- seen = "(null)";
fflush(stderr);
check_diag_files();
- success = (strcmp(wanted, seen) == 0);
+ success = (left == right);
if (success)
printf("ok %lu", testnum++);
else {
- diag("wanted: %s", wanted);
- diag(" seen: %s", seen);
+ diag(" left: %lx", (unsigned long) left);
+ diag("right: %lx", (unsigned long) right);
printf("not ok %lu", testnum++);
_failed++;
}
@@ -545,22 +601,30 @@ is_string(const char *wanted, const char *seen, const char *format, ...)
/*
- * Takes an expected unsigned long and a seen unsigned long and assumes the
- * test passes if the two numbers match. Otherwise, reports them in hex.
+ * Takes pointers to a regions of memory and requires that len bytes from each
+ * match. Otherwise reports any bytes which didn't match.
*/
int
-is_hex(unsigned long wanted, unsigned long seen, const char *format, ...)
+is_blob(const void *left, const void *right, size_t len, const char *format,
+ ...)
{
int success;
+ size_t i;
fflush(stderr);
check_diag_files();
- success = (wanted == seen);
+ success = (memcmp(left, right, len) == 0);
if (success)
printf("ok %lu", testnum++);
else {
- diag("wanted: %lx", (unsigned long) wanted);
- diag(" seen: %lx", (unsigned long) seen);
+ const unsigned char *left_c = left;
+ const unsigned char *right_c = right;
+
+ for (i = 0; i < len; i++) {
+ if (left_c[i] != right_c[i])
+ diag("offset %lu: left %02x, right %02x", (unsigned long) i,
+ left_c[i], right_c[i]);
+ }
printf("not ok %lu", testnum++);
_failed++;
}
@@ -769,6 +833,8 @@ breallocarray(void *p, size_t n, size_t size)
{
if (n > 0 && UINT_MAX / n <= size)
bail("reallocarray too large");
+ if (n == 0)
+ n = 1;
p = realloc(p, n * size);
if (p == NULL)
sysbail("failed to realloc %lu bytes", (unsigned long) (n * size));
@@ -820,17 +886,17 @@ bstrndup(const char *s, size_t n)
/*
- * Locate a test file. Given the partial path to a file, look under BUILD and
- * then SOURCE for the file and return the full path to the file. Returns
- * NULL if the file doesn't exist. A non-NULL return should be freed with
- * test_file_path_free().
+ * Locate a test file. Given the partial path to a file, look under
+ * C_TAP_BUILD and then C_TAP_SOURCE for the file and return the full path to
+ * the file. Returns NULL if the file doesn't exist. A non-NULL return
+ * should be freed with test_file_path_free().
*/
char *
test_file_path(const char *file)
{
char *base;
char *path = NULL;
- const char *envs[] = { "BUILD", "SOURCE", NULL };
+ const char *envs[] = { "C_TAP_BUILD", "C_TAP_SOURCE", NULL };
int i;
for (i = 0; envs[i] != NULL; i++) {
@@ -860,7 +926,7 @@ test_file_path_free(char *path)
/*
- * Create a temporary directory, tmp, under BUILD if set and the current
+ * Create a temporary directory, tmp, under C_TAP_BUILD if set and the current
* directory if it does not. Returns the path to the temporary directory in
* newly allocated memory, and calls bail on any failure. The return value
* should be freed with test_tmpdir_free.
@@ -875,7 +941,7 @@ test_tmpdir(void)
const char *build;
char *path = NULL;
- build = getenv("BUILD");
+ build = getenv("C_TAP_BUILD");
if (build == NULL)
build = ".";
path = concat(build, "/tmp", (const char *) 0);
diff --git a/tests/tap/basic.h b/tests/tap/basic.h
index 4ecaaec..3f46e4f 100644
--- a/tests/tap/basic.h
+++ b/tests/tap/basic.h
@@ -2,11 +2,11 @@
* Basic utility routines for the TAP protocol.
*
* This file is part of C TAP Harness. The current version plus supporting
- * documentation is at <http://www.eyrie.org/~eagle/software/c-tap-harness/>.
+ * documentation is at <https://www.eyrie.org/~eagle/software/c-tap-harness/>.
*
- * Copyright 2009, 2010, 2011, 2012, 2013, 2014, 2015
- * Russ Allbery <eagle@eyrie.org>
- * Copyright 2001, 2002, 2004, 2005, 2006, 2007, 2008, 2011, 2012, 2014
+ * Written by Russ Allbery <eagle@eyrie.org>
+ * Copyright 2009-2018 Russ Allbery <eagle@eyrie.org>
+ * Copyright 2001-2002, 2004-2008, 2011-2012, 2014
* The Board of Trustees of the Leland Stanford Junior University
*
* Permission is hereby granted, free of charge, to any person obtaining a
@@ -26,6 +26,8 @@
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
+ *
+ * SPDX-License-Identifier: MIT
*/
#ifndef TAP_BASIC_H
@@ -88,15 +90,21 @@ void skip_block(unsigned long count, const char *reason, ...)
__attribute__((__format__(printf, 2, 3)));
/*
- * Check an expected value against a seen value. Returns true if the test
- * passes and false if it fails.
+ * Compare two values. Returns true if the test passes and false if it fails.
+ * is_bool takes an int since the bool type isn't fully portable yet, but
+ * interprets both arguments for their truth value, not for their numeric
+ * value.
*/
-int is_int(long wanted, long seen, const char *format, ...)
+int is_bool(int, int, const char *format, ...)
+ __attribute__((__format__(printf, 3, 4)));
+int is_int(long, long, const char *format, ...)
__attribute__((__format__(printf, 3, 4)));
-int is_string(const char *wanted, const char *seen, const char *format, ...)
+int is_string(const char *, const char *, const char *format, ...)
__attribute__((__format__(printf, 3, 4)));
-int is_hex(unsigned long wanted, unsigned long seen, const char *format, ...)
+int is_hex(unsigned long, unsigned long, const char *format, ...)
__attribute__((__format__(printf, 3, 4)));
+int is_blob(const void *, const void *, size_t, const char *format, ...)
+ __attribute__((__format__(printf, 4, 5)));
/* Bail out with an error. sysbail appends strerror(errno). */
void bail(const char *format, ...)
@@ -137,16 +145,16 @@ char *bstrndup(const char *, size_t)
__attribute__((__malloc__, __nonnull__, __warn_unused_result__));
/*
- * Find a test file under BUILD or SOURCE, returning the full path. The
- * returned path should be freed with test_file_path_free().
+ * 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().
*/
char *test_file_path(const char *file)
__attribute__((__malloc__, __nonnull__, __warn_unused_result__));
void test_file_path_free(char *path);
/*
- * Create a temporary directory relative to BUILD and return the path. The
- * returned path should be freed with test_tmpdir_free.
+ * Create a temporary directory relative to C_TAP_BUILD and return the path.
+ * The returned path should be freed with test_tmpdir_free().
*/
char *test_tmpdir(void)
__attribute__((__malloc__, __warn_unused_result__));
diff --git a/tests/tap/kerberos.c b/tests/tap/kerberos.c
index 6a5025a..89a36a3 100644
--- a/tests/tap/kerberos.c
+++ b/tests/tap/kerberos.c
@@ -12,10 +12,11 @@
* are available.
*
* The canonical version of this file is maintained in the rra-c-util package,
- * which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
+ * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
- * Copyright 2006, 2007, 2009, 2010, 2011, 2012, 2013, 2014
+ * Copyright 2017 Russ Allbery <eagle@eyrie.org>
+ * Copyright 2006-2007, 2009-2014
* The Board of Trustees of the Leland Stanford Junior University
*
* Permission is hereby granted, free of charge, to any person obtaining a
@@ -35,6 +36,8 @@
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
+ *
+ * SPDX-License-Identifier: MIT
*/
#include <config.h>
@@ -361,7 +364,7 @@ kerberos_setup(enum kerberos_needs needs)
path = test_file_path("config/pkinit-principal");
if (path != NULL)
file = fopen(path, "r");
- if (file != NULL) {
+ if (path != NULL && file != NULL) {
if (fgets(buffer, sizeof(buffer), file) == NULL)
bail("cannot read %s", path);
if (buffer[strlen(buffer) - 1] != '\n')
@@ -457,17 +460,19 @@ kerberos_generate_conf(const char *realm)
/*
- * Report a Kerberos error and bail out.
+ * Report a Kerberos error and bail out. Takes a long instead of a
+ * krb5_error_code because it can also handle a kadm5_ret_t (which may be a
+ * different size).
*/
void
-bail_krb5(krb5_context ctx, krb5_error_code code, const char *format, ...)
+bail_krb5(krb5_context ctx, long code, const char *format, ...)
{
const char *k5_msg = NULL;
char *message;
va_list args;
if (ctx != NULL)
- k5_msg = krb5_get_error_message(ctx, code);
+ k5_msg = krb5_get_error_message(ctx, (krb5_error_code) code);
va_start(args, format);
bvasprintf(&message, format, args);
va_end(args);
@@ -479,17 +484,19 @@ bail_krb5(krb5_context ctx, krb5_error_code code, const char *format, ...)
/*
- * Report a Kerberos error as a diagnostic to stderr.
+ * Report a Kerberos error as a diagnostic to stderr. Takes a long instead of
+ * a krb5_error_code because it can also handle a kadm5_ret_t (which may be a
+ * different size).
*/
void
-diag_krb5(krb5_context ctx, krb5_error_code code, const char *format, ...)
+diag_krb5(krb5_context ctx, long code, const char *format, ...)
{
const char *k5_msg = NULL;
char *message;
va_list args;
if (ctx != NULL)
- k5_msg = krb5_get_error_message(ctx, code);
+ k5_msg = krb5_get_error_message(ctx, (krb5_error_code) code);
va_start(args, format);
bvasprintf(&message, format, args);
va_end(args);
@@ -524,14 +531,12 @@ kerberos_keytab_principal(krb5_context ctx, const char *path)
if (status != 0)
bail_krb5(ctx, status, "error reading %s", path);
status = krb5_kt_next_entry(ctx, keytab, &entry, &cursor);
- if (status == 0) {
- status = krb5_copy_principal(ctx, entry.principal, &princ);
- if (status != 0)
- bail_krb5(ctx, status, "error copying principal from %s", path);
- krb5_kt_free_entry(ctx, &entry);
- }
if (status != 0)
bail("no principal found in keytab file %s", path);
+ status = krb5_copy_principal(ctx, entry.principal, &princ);
+ if (status != 0)
+ bail_krb5(ctx, status, "error copying principal from %s", path);
+ krb5_kt_free_entry(ctx, &entry);
krb5_kt_end_seq_get(ctx, keytab, &cursor);
krb5_kt_close(ctx, keytab);
return princ;
diff --git a/tests/tap/kerberos.h b/tests/tap/kerberos.h
index 26f45f9..c256822 100644
--- a/tests/tap/kerberos.h
+++ b/tests/tap/kerberos.h
@@ -2,10 +2,11 @@
* Utility functions for tests that use Kerberos.
*
* The canonical version of this file is maintained in the rra-c-util package,
- * which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
+ * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
- * Copyright 2006, 2007, 2009, 2011, 2012, 2013, 2014
+ * Copyright 2017 Russ Allbery <eagle@eyrie.org>
+ * Copyright 2006-2007, 2009, 2011-2014
* The Board of Trustees of the Leland Stanford Junior University
*
* Permission is hereby granted, free of charge, to any person obtaining a
@@ -25,6 +26,8 @@
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
+ *
+ * SPDX-License-Identifier: MIT
*/
#ifndef TAP_KERBEROS_H
@@ -107,12 +110,12 @@ void kerberos_cleanup_conf(void);
#ifdef HAVE_KRB5
/* Bail out with an error, appending the Kerberos error message. */
-void bail_krb5(krb5_context, krb5_error_code, const char *format, ...)
- __attribute__((__noreturn__, __nonnull__, __format__(printf, 3, 4)));
+void bail_krb5(krb5_context, long, const char *format, ...)
+ __attribute__((__noreturn__, __nonnull__(3), __format__(printf, 3, 4)));
/* Report a diagnostic with Kerberos error to stderr prefixed with #. */
-void diag_krb5(krb5_context, krb5_error_code, const char *format, ...)
- __attribute__((__nonnull__, __format__(printf, 3, 4)));
+void diag_krb5(krb5_context, long, const char *format, ...)
+ __attribute__((__nonnull__(3), __format__(printf, 3, 4)));
/*
* Given a Kerberos context and the path to a keytab, retrieve the principal
diff --git a/tests/tap/kerberos.sh b/tests/tap/kerberos.sh
index e970ae5..13b540d 100644
--- a/tests/tap/kerberos.sh
+++ b/tests/tap/kerberos.sh
@@ -6,10 +6,11 @@
# Bourne shell. Instead, all private variables are prefixed with "tap_".
#
# The canonical version of this file is maintained in the rra-c-util package,
-# which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
+# which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
#
# Written by Russ Allbery <eagle@eyrie.org>
-# Copyright 2009, 2010, 2011, 2012
+# Copyright 2016 Russ Allbery <eagle@eyrie.org>
+# Copyright 2009-2012
# The Board of Trustees of the Leland Stanford Junior University
#
# Permission is hereby granted, free of charge, to any person obtaining a
@@ -29,9 +30,10 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
+#
+# SPDX-License-Identifier: MIT
-# We use test_tmpdir.
-. "${SOURCE}/tap/libtap.sh"
+. "${C_TAP_SOURCE}/tap/libtap.sh"
# Set up Kerberos, including the ticket cache environment variable. Bail out
# if not successful, return 0 if successful, and return 1 if Kerberos is not
diff --git a/tests/tap/libtap.sh b/tests/tap/libtap.sh
index 9731032..38181d9 100644
--- a/tests/tap/libtap.sh
+++ b/tests/tap/libtap.sh
@@ -7,10 +7,10 @@
#
# This file provides a TAP-compatible shell function library useful for
# writing test cases. It is part of C TAP Harness, which can be found at
-# <http://www.eyrie.org/~eagle/software/c-tap-harness/>.
+# <https://www.eyrie.org/~eagle/software/c-tap-harness/>.
#
# Written by Russ Allbery <eagle@eyrie.org>
-# Copyright 2009, 2010, 2011, 2012 Russ Allbery <eagle@eyrie.org>
+# Copyright 2009, 2010, 2011, 2012, 2016 Russ Allbery <eagle@eyrie.org>
# Copyright 2006, 2007, 2008, 2013
# The Board of Trustees of the Leland Stanford Junior University
#
@@ -31,6 +31,8 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
+#
+# SPDX-License-Identifier: MIT
# Print out the number of test cases we expect to run.
plan () {
@@ -212,32 +214,32 @@ diag () {
echo '#' "$@"
}
-# Search for the given file first in $BUILD and then in $SOURCE and echo the
-# path where the file was found, or the empty string if the file wasn't
-# found.
+# Search for the given file first in $C_TAP_BUILD and then in $C_TAP_SOURCE
+# and echo the path where the file was found, or the empty string if the file
+# wasn't found.
#
# This macro uses puts, so don't run it using backticks inside double quotes
# or bizarre quoting behavior will happen with Solaris sh.
test_file_path () {
- if [ -n "$BUILD" ] && [ -f "$BUILD/$1" ] ; then
- puts "$BUILD/$1"
- elif [ -n "$SOURCE" ] && [ -f "$SOURCE/$1" ] ; then
- puts "$SOURCE/$1"
+ if [ -n "$C_TAP_BUILD" ] && [ -f "$C_TAP_BUILD/$1" ] ; then
+ puts "$C_TAP_BUILD/$1"
+ elif [ -n "$C_TAP_SOURCE" ] && [ -f "$C_TAP_SOURCE/$1" ] ; then
+ puts "$C_TAP_SOURCE/$1"
else
echo ''
fi
}
-# Create $BUILD/tmp for use by tests for storing temporary files and return
-# the path (via standard output).
+# Create $C_TAP_BUILD/tmp for use by tests for storing temporary files and
+# return the path (via standard output).
#
# This macro uses puts, so don't run it using backticks inside double quotes
# or bizarre quoting behavior will happen with Solaris sh.
test_tmpdir () {
- if [ -z "$BUILD" ] ; then
+ if [ -z "$C_TAP_BUILD" ] ; then
tap_tmpdir="./tmp"
else
- tap_tmpdir="$BUILD"/tmp
+ tap_tmpdir="$C_TAP_BUILD"/tmp
fi
if [ ! -d "$tap_tmpdir" ] ; then
mkdir "$tap_tmpdir" || bail "Error creating $tap_tmpdir"
diff --git a/tests/tap/macros.h b/tests/tap/macros.h
index 139cff0..32ed815 100644
--- a/tests/tap/macros.h
+++ b/tests/tap/macros.h
@@ -6,7 +6,7 @@
* everyone can pull them in.
*
* This file is part of C TAP Harness. The current version plus supporting
- * documentation is at <http://www.eyrie.org/~eagle/software/c-tap-harness/>.
+ * documentation is at <https://www.eyrie.org/~eagle/software/c-tap-harness/>.
*
* Copyright 2008, 2012, 2013, 2015 Russ Allbery <eagle@eyrie.org>
*
@@ -27,6 +27,8 @@
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
+ *
+ * SPDX-License-Identifier: MIT
*/
#ifndef TAP_MACROS_H
diff --git a/tests/tap/messages.c b/tests/tap/messages.c
index 9c28789..a720ec7 100644
--- a/tests/tap/messages.c
+++ b/tests/tap/messages.c
@@ -6,10 +6,11 @@
* handling.
*
* The canonical version of this file is maintained in the rra-c-util package,
- * which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
+ * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
- * Copyright 2002, 2004, 2005, 2015 Russ Allbery <eagle@eyrie.org>
- * Copyright 2006, 2007, 2009, 2012, 2014
+ * Written by Russ Allbery <eagle@eyrie.org>
+ * Copyright 2002, 2004-2005, 2015 Russ Allbery <eagle@eyrie.org>
+ * Copyright 2006-2007, 2009, 2012, 2014
* The Board of Trustees of the Leland Stanford Junior University
*
* Permission is hereby granted, free of charge, to any person obtaining a
@@ -29,6 +30,8 @@
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
+ *
+ * SPDX-License-Identifier: MIT
*/
#include <config.h>
diff --git a/tests/tap/messages.h b/tests/tap/messages.h
index 985b9cd..3076113 100644
--- a/tests/tap/messages.h
+++ b/tests/tap/messages.h
@@ -2,10 +2,11 @@
* Utility functions to test message handling.
*
* The canonical version of this file is maintained in the rra-c-util package,
- * which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
+ * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
+ * Written by Russ Allbery <eagle@eyrie.org>
* Copyright 2002 Russ Allbery <eagle@eyrie.org>
- * Copyright 2006, 2007, 2009
+ * Copyright 2006-2007, 2009
* The Board of Trustees of the Leland Stanford Junior University
*
* Permission is hereby granted, free of charge, to any person obtaining a
@@ -25,6 +26,8 @@
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
+ *
+ * SPDX-License-Identifier: MIT
*/
#ifndef TAP_MESSAGES_H
diff --git a/tests/tap/perl/Test/RRA.pm b/tests/tap/perl/Test/RRA.pm
index 8608e31..807508c 100644
--- a/tests/tap/perl/Test/RRA.pm
+++ b/tests/tap/perl/Test/RRA.pm
@@ -5,6 +5,8 @@
# by both C packages with Automake and by stand-alone Perl modules. See
# Test::RRA::Automake for additional functions specifically for C Automake
# distributions.
+#
+# SPDX-License-Identifier: MIT
package Test::RRA;
@@ -13,6 +15,7 @@ use strict;
use warnings;
use Exporter;
+use File::Temp;
use Test::More;
# For Perl 5.006 compatibility.
@@ -26,12 +29,56 @@ our (@EXPORT_OK, @ISA, $VERSION);
# consistency is good).
BEGIN {
@ISA = qw(Exporter);
- @EXPORT_OK = qw(skip_unless_author skip_unless_automated use_prereq);
+ @EXPORT_OK = qw(
+ is_file_contents skip_unless_author skip_unless_automated use_prereq
+ );
# 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 = '5.10';
+ $VERSION = '7.02';
+}
+
+# Compare a string to the contents of a file, similar to the standard is()
+# function, but to show the line-based unified diff between them if they
+# differ.
+#
+# $got - The output that we received
+# $expected - The path to the file containing the expected output
+# $message - The message to use when reporting the test results
+#
+# Returns: undef
+# Throws: Exception on failure to read or write files or run diff
+sub is_file_contents {
+ my ($got, $expected, $message) = @_;
+
+ # If they're equal, this is simple.
+ open(my $fh, '<', $expected) or BAIL_OUT("Cannot open $expected: $!\n");
+ my $data = do { local $/ = undef; <$fh> };
+ close($fh) or BAIL_OUT("Cannot close $expected: $!\n");
+ if ($got eq $data) {
+ is($got, $data, $message);
+ return;
+ }
+
+ # Otherwise, we show a diff, but only if we have IPC::System::Simple.
+ eval { require IPC::System::Simple };
+ if ($@) {
+ ok(0, $message);
+ return;
+ }
+
+ # 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.
+ ok(0, $message);
+ return;
}
# Skip this test unless author tests are requested. Takes a short description
@@ -225,10 +272,14 @@ SOFTWARE.
Test::More(3), Test::RRA::Automake(3), Test::RRA::Config(3)
This module is maintained in the rra-c-util package. The current version is
-available from L<http://www.eyrie.org/~eagle/software/rra-c-util/>.
+available from L<https://www.eyrie.org/~eagle/software/rra-c-util/>.
The functions to control when tests are run use environment variables defined
by the L<Lancaster
Consensus|https://github.com/Perl-Toolchain-Gang/toolchain-site/blob/master/lancaster-consensus.md>.
=cut
+
+# Local Variables:
+# copyright-at-end-flag: t
+# End:
diff --git a/tests/tap/perl/Test/RRA/Automake.pm b/tests/tap/perl/Test/RRA/Automake.pm
index c6399ec..804c193 100644
--- a/tests/tap/perl/Test/RRA/Automake.pm
+++ b/tests/tap/perl/Test/RRA/Automake.pm
@@ -7,8 +7,11 @@
# require closely following the conventions implemented by the rra-c-util
# utility collection.
#
-# All the functions here assume that BUILD and SOURCE are set in the
-# environment. This is normally done via the C TAP Harness runtests wrapper.
+# All the functions here assume that C_TAP_BUILD and C_TAP_SOURCE are set in
+# the environment. This is normally done via the C TAP Harness runtests
+# wrapper.
+#
+# SPDX-License-Identifier: MIT
package Test::RRA::Automake;
@@ -20,6 +23,7 @@ use warnings;
## no critic (ClassHierarchies::ProhibitExplicitISA)
use Exporter;
+use File::Find qw(find);
use File::Spec;
use Test::More;
use Test::RRA::Config qw($LIBRARY_PATH);
@@ -34,9 +38,9 @@ BEGIN {
$PERL_BLIB_ARCH = File::Spec->catdir(qw(perl blib arch));
$PERL_BLIB_LIB = File::Spec->catdir(qw(perl blib lib));
- # If BUILD is set, we can come up with better values.
- if (defined($ENV{BUILD})) {
- my ($vol, $dirs) = File::Spec->splitpath($ENV{BUILD}, 1);
+ # If C_TAP_BUILD is set, we can come up with better values.
+ if (defined($ENV{C_TAP_BUILD})) {
+ my ($vol, $dirs) = File::Spec->splitpath($ENV{C_TAP_BUILD}, 1);
my @dirs = File::Spec->splitdir($dirs);
pop(@dirs);
$PERL_BLIB_ARCH = File::Spec->catdir(@dirs, qw(perl blib arch));
@@ -57,47 +61,93 @@ our (@EXPORT_OK, @ISA, $VERSION);
# consistency is good).
BEGIN {
@ISA = qw(Exporter);
- @EXPORT_OK = qw(automake_setup perl_dirs test_file_path test_tmpdir);
+ @EXPORT_OK = qw(
+ all_files automake_setup perl_dirs test_file_path test_tmpdir
+ );
# 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 = '5.10';
+ $VERSION = '7.02';
}
-# Perl directories to skip globally for perl_dirs. We ignore the perl
-# directory if it exists since, in my packages, it is treated as a Perl module
-# distribution and has its own standalone test suite.
-my @GLOBAL_SKIP = qw(.git _build perl);
+# 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);
+
+# Additional paths to skip when building a list of all files in the
+# distribution. This primarily skips build artifacts that aren't interesting
+# to any of the tests. These match any path component.
+my @FILES_SKIP = qw(
+ .deps .dirstamp .libs aclocal.m4 config.h config.h.in config.h.in~ config.log
+ config.status configure
+);
# The temporary directory created by test_tmpdir, if any. If this is set,
# attempt to remove the directory stored here on program exit (but ignore
# failure to do so).
my $TMPDIR;
+# Returns a list of all files in the distribution.
+#
+# Returns: List of files
+sub all_files {
+ my @files;
+
+ # Turn the skip lists into hashes for ease of querying.
+ my %skip = map { $_ => 1 } @GLOBAL_SKIP;
+ my %files_skip = map { $_ => 1 } @FILES_SKIP;
+
+ # Wanted function for find. Prune anything matching either of the skip
+ # lists, or *.lo files, and then add all regular files to the list.
+ my $wanted = sub {
+ my $file = $_;
+ my $path = $File::Find::name;
+ $path =~ s{ \A [.]/ }{}xms;
+ if ($skip{$path} or $files_skip{$file} or $file =~ m{ [.] lo \z }xms) {
+ $File::Find::prune = 1;
+ return;
+ }
+ if (-f $file) {
+ push(@files, $path);
+ }
+ };
+
+ # Do the recursive search and return the results.
+ find($wanted, q{.});
+ return @files;
+}
+
# Perform initial test setup for running a Perl test in an Automake package.
-# This verifies that BUILD and SOURCE are set and then changes directory to
-# the SOURCE directory by default. Sets LD_LIBRARY_PATH if the $LIBRARY_PATH
-# configuration option is set. Calls BAIL_OUT if BUILD or SOURCE are missing
-# or if anything else fails.
+# This verifies that C_TAP_BUILD and C_TAP_SOURCE are set and then changes
+# directory to the C_TAP_SOURCE directory by default. Sets LD_LIBRARY_PATH if
+# the $LIBRARY_PATH configuration option is set. Calls BAIL_OUT if
+# C_TAP_BUILD or C_TAP_SOURCE are missing or if anything else fails.
#
# $args_ref - Reference to a hash of arguments to configure behavior:
-# chdir_build - If set to a true value, changes to BUILD instead of SOURCE
+# chdir_build - If set to a true value, changes to C_TAP_BUILD instead of
+# C_TAP_SOURCE
#
# Returns: undef
sub automake_setup {
my ($args_ref) = @_;
- # Bail if BUILD or SOURCE are not set.
- if (!$ENV{BUILD}) {
- BAIL_OUT('BUILD not defined (run under runtests)');
+ # Bail if C_TAP_BUILD or C_TAP_SOURCE are not set.
+ if (!$ENV{C_TAP_BUILD}) {
+ BAIL_OUT('C_TAP_BUILD not defined (run under runtests)');
}
- if (!$ENV{SOURCE}) {
- BAIL_OUT('SOURCE not defined (run under runtests)');
+ if (!$ENV{C_TAP_SOURCE}) {
+ BAIL_OUT('C_TAP_SOURCE not defined (run under runtests)');
}
- # BUILD or SOURCE will be the test directory. Change to the parent.
- my $start = $args_ref->{chdir_build} ? $ENV{BUILD} : $ENV{SOURCE};
+ # C_TAP_BUILD or C_TAP_SOURCE will be the test directory. Change to the
+ # parent.
+ my $start;
+ if ($args_ref->{chdir_build}) {
+ $start = $ENV{C_TAP_BUILD};
+ } else {
+ $start = $ENV{C_TAP_SOURCE};
+ }
my ($vol, $dirs) = File::Spec->splitpath($start, 1);
my @dirs = File::Spec->splitdir($dirs);
pop(@dirs);
@@ -116,8 +166,9 @@ sub automake_setup {
my $root = File::Spec->catpath($vol, File::Spec->catdir(@dirs), q{});
chdir($root) or BAIL_OUT("cannot chdir to $root: $!");
- # If BUILD is a subdirectory of SOURCE, add it to the global ignore list.
- my ($buildvol, $builddirs) = File::Spec->splitpath($ENV{BUILD}, 1);
+ # If C_TAP_BUILD is a subdirectory of C_TAP_SOURCE, add it to the global
+ # ignore list.
+ my ($buildvol, $builddirs) = File::Spec->splitpath($ENV{C_TAP_BUILD}, 1);
my @builddirs = File::Spec->splitdir($builddirs);
pop(@builddirs);
if ($buildvol eq $vol && @builddirs == @dirs + 1) {
@@ -162,9 +213,11 @@ sub automake_setup {
sub perl_dirs {
my ($args_ref) = @_;
- # Add the global skip list.
+ # Add the global skip list. We also ignore the perl directory if it
+ # exists since, in my packages, it is treated as a Perl module
+ # distribution and has its own standalone test suite.
my @skip = $args_ref->{skip} ? @{ $args_ref->{skip} } : ();
- push(@skip, @GLOBAL_SKIP);
+ push(@skip, @GLOBAL_SKIP, 'perl');
# Separate directories to skip under tests from top-level directories.
my @skip_tests = grep { m{ \A tests/ }xms } @skip;
@@ -206,9 +259,9 @@ sub perl_dirs {
return @dirs;
}
-# Find a configuration file for the test suite. Searches relative to BUILD
-# first and then SOURCE and returns whichever is found first. Calls BAIL_OUT
-# if the file could not be found.
+# Find a configuration file for the test suite. Searches relative to
+# C_TAP_BUILD first and then C_TAP_SOURCE and returns whichever is found
+# first. Calls BAIL_OUT if the file could not be found.
#
# $file - Partial path to the file
#
@@ -216,7 +269,7 @@ sub perl_dirs {
sub test_file_path {
my ($file) = @_;
BASE:
- for my $base ($ENV{BUILD}, $ENV{SOURCE}) {
+ for my $base ($ENV{C_TAP_BUILD}, $ENV{C_TAP_SOURCE}) {
next if !defined($base);
if (-f "$base/$file") {
return "$base/$file";
@@ -236,11 +289,16 @@ sub test_tmpdir {
my $path;
# If we already figured out what directory to use, reuse the same path.
- # Otherwise, create a directory relative to BUILD if set.
+ # Otherwise, create a directory relative to C_TAP_BUILD if set.
if (defined($TMPDIR)) {
$path = $TMPDIR;
} else {
- my $base = defined($ENV{BUILD}) ? $ENV{BUILD} : File::Spec->curdir;
+ my $base;
+ if (defined($ENV{C_TAP_BUILD})) {
+ $base = $ENV{C_TAP_BUILD};
+ } else {
+ $base = File::Spec->curdir;
+ }
$path = File::Spec->catdir($base, 'tmp');
}
@@ -297,11 +355,11 @@ layout of a package that uses rra-c-util and C TAP Harness for the test
structure.
Loading this module will also add the directories C<perl/blib/arch> and
-C<perl/blib/lib> to the Perl library search path, relative to BUILD if that
-environment variable is set. This is harmless for C Automake projects that
-don't contain an embedded Perl module, and for those projects that do, this
-will allow subsequent C<use> calls to find modules that are built as part of
-the package build process.
+C<perl/blib/lib> to the Perl library search path, relative to C_TAP_BUILD if
+that environment variable is set. This is harmless for C Automake projects
+that don't contain an embedded Perl module, and for those projects that do,
+this will allow subsequent C<use> calls to find modules that are built as part
+of the package build process.
The automake_setup() function should be called before calling any other
functions provided by this module.
@@ -314,11 +372,20 @@ BAIL_OUT (from Test::More).
=over 4
+=item all_files()
+
+Returns a list of all "interesting" files in the distribution that a test
+suite may want to look at. This excludes various products of the build system,
+the build directory if it's under the source directory, and a few other
+uninteresting directories like F<.git>. The returned paths will be paths
+relative to the root of the package.
+
=item automake_setup([ARGS])
-Verifies that the BUILD and SOURCE environment variables are set and then
-changes directory to the top of the source tree (which is one directory up
-from the SOURCE path, since SOURCE points to the top of the tests directory).
+Verifies that the C_TAP_BUILD and C_TAP_SOURCE environment variables are set
+and then changes directory to the top of the source tree (which is one
+directory up from the C_TAP_SOURCE path, since C_TAP_SOURCE points to the top
+of the tests directory).
If ARGS is given, it should be a reference to a hash of configuration options.
Only one option is supported: C<chdir_build>. If it is set to a true value,
@@ -343,30 +410,46 @@ C<tests/> that should be skipped.
Given FILE, which should be a relative path, locates that file relative to the
test directory in either the source or build tree. FILE will be checked for
-relative to the environment variable BUILD first, and then relative to SOURCE.
-test_file_path() returns the full path to FILE or calls BAIL_OUT if FILE could
-not be found.
+relative to the environment variable C_TAP_BUILD first, and then relative to
+C_TAP_SOURCE. test_file_path() returns the full path to FILE or calls
+BAIL_OUT if FILE could not be found.
=item test_tmpdir()
Create a temporary directory for tests to use for transient files and return
-the path to that directory. The directory is created relative to the BUILD
-environment variable, which must be set. Permissions on the directory are set
-using the current umask. test_tmpdir() returns the full path to the temporary
-directory or calls BAIL_OUT if it could not be created.
+the path to that directory. The directory is created relative to the
+C_TAP_BUILD environment variable, which must be set. Permissions on the
+directory are set using the current umask. test_tmpdir() returns the full
+path to the temporary directory or calls BAIL_OUT if it could not be created.
The directory is automatically removed if possible on program exit. Failure
to remove the directory on exit is reported with diag() and otherwise ignored.
=back
+=head1 ENVIRONMENT
+
+=over 4
+
+=item C_TAP_BUILD
+
+The root of the tests directory in Automake build directory for this package,
+used to find files as documented above.
+
+=item C_TAP_SOURCE
+
+The root of the tests directory in the source tree for this package, used to
+find files as documented above.
+
+=back
+
=head1 AUTHOR
Russ Allbery <eagle@eyrie.org>
=head1 COPYRIGHT AND LICENSE
-Copyright 2014, 2015 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
@@ -393,9 +476,13 @@ SOFTWARE.
Test::More(3), Test::RRA(3), Test::RRA::Config(3)
This module is maintained in the rra-c-util package. The current version is
-available from L<http://www.eyrie.org/~eagle/software/rra-c-util/>.
+available from L<https://www.eyrie.org/~eagle/software/rra-c-util/>.
The C TAP Harness test driver and libraries for TAP-based C testing are
-available from L<http://www.eyrie.org/~eagle/software/c-tap-harness/>.
+available from L<https://www.eyrie.org/~eagle/software/c-tap-harness/>.
=cut
+
+# Local Variables:
+# copyright-at-end-flag: t
+# End:
diff --git a/tests/tap/perl/Test/RRA/Config.pm b/tests/tap/perl/Test/RRA/Config.pm
index a5b0d0d..7cb0916 100644
--- a/tests/tap/perl/Test/RRA/Config.pm
+++ b/tests/tap/perl/Test/RRA/Config.pm
@@ -4,6 +4,8 @@
# configuration file to store some package-specific data. This module loads
# that configuration and provides the namespace for the configuration
# settings.
+#
+# SPDX-License-Identifier: MIT
package Test::RRA::Config;
@@ -34,16 +36,16 @@ 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 = '5.10';
+ $VERSION = '7.02';
}
-# If BUILD or SOURCE are set in the environment, look for data/perl.conf under
-# those paths for a C Automake package. Otherwise, look in t/data/perl.conf
-# for a standalone Perl module or tests/data/perl.conf for Perl tests embedded
-# in a larger distribution. Don't use Test::RRA::Automake since it may not
-# exist.
+# If C_TAP_BUILD or C_TAP_SOURCE are set in the environment, look for
+# data/perl.conf under those paths for a C Automake package. Otherwise, look
+# in t/data/perl.conf for a standalone Perl module or tests/data/perl.conf for
+# Perl tests embedded in a larger distribution. Don't use Test::RRA::Automake
+# since it may not exist.
our $PATH;
-for my $base ($ENV{BUILD}, $ENV{SOURCE}, 't', 'tests') {
+for my $base ($ENV{C_TAP_BUILD}, $ENV{C_TAP_SOURCE}, './t', './tests') {
next if !defined($base);
my $path = "$base/data/perl.conf";
if (-r $path) {
@@ -70,7 +72,7 @@ our @STRICT_PREREQ;
# Load the configuration.
if (!do($PATH)) {
my $error = $@ || $! || 'loading file did not return true';
- BAIL_OUT("cannot load data/perl.conf: $error");
+ BAIL_OUT("cannot load $PATH: $error");
}
1;
@@ -98,10 +100,10 @@ for both C Automake packages and stand-alone Perl modules.
Test::RRA::Config looks for a file named F<data/perl.conf> relative to the
root of the test directory. That root is taken from the environment variables
-BUILD or SOURCE (in that order) if set, which will be the case for C Automake
-packages using C TAP Harness. If neither is set, it expects the root of the
-test directory to be a directory named F<t> relative to the current directory,
-which will be the case for stand-alone Perl modules.
+C_TAP_BUILD or C_TAP_SOURCE (in that order) if set, which will be the case for
+C Automake packages using C TAP Harness. If neither is set, it expects the
+root of the test directory to be a directory named F<t> relative to the
+current directory, which will be the case for stand-alone Perl modules.
The following variables are supported:
@@ -185,6 +187,8 @@ Russ Allbery <eagle@eyrie.org>
=head1 COPYRIGHT AND LICENSE
+Copyright 2015, 2016 Russ Allbery <eagle@eyrie.org>
+
Copyright 2013, 2014 The Board of Trustees of the Leland Stanford Junior
University
@@ -212,9 +216,13 @@ perlcritic(1), Test::MinimumVersion(3), Test::RRA(3), Test::RRA::Automake(3),
Test::Strict(3)
This module is maintained in the rra-c-util package. The current version is
-available from L<http://www.eyrie.org/~eagle/software/rra-c-util/>.
+available from L<https://www.eyrie.org/~eagle/software/rra-c-util/>.
The C TAP Harness test driver and libraries for TAP-based C testing are
-available from L<http://www.eyrie.org/~eagle/software/c-tap-harness/>.
+available from L<https://www.eyrie.org/~eagle/software/c-tap-harness/>.
=cut
+
+# Local Variables:
+# copyright-at-end-flag: t
+# End:
diff --git a/tests/tap/perl/Test/RRA/ModuleVersion.pm b/tests/tap/perl/Test/RRA/ModuleVersion.pm
index f02877a..49acac4 100644
--- a/tests/tap/perl/Test/RRA/ModuleVersion.pm
+++ b/tests/tap/perl/Test/RRA/ModuleVersion.pm
@@ -3,6 +3,8 @@
# This module contains the common code for testing and updating Perl module
# versions for consistency within a Perl module distribution and within a
# larger package that contains both Perl modules and other code.
+#
+# SPDX-License-Identifier: MIT
package Test::RRA::ModuleVersion;
@@ -31,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 = '5.10';
+ $VERSION = '7.02';
}
# A regular expression matching the version string for a module using the
@@ -290,6 +292,10 @@ SOFTWARE.
Test::More(3), Test::RRA::Config(3)
This module is maintained in the rra-c-util package. The current version
-is available from L<http://www.eyrie.org/~eagle/software/rra-c-util/>.
+is available from L<https://www.eyrie.org/~eagle/software/rra-c-util/>.
=cut
+
+# Local Variables:
+# copyright-at-end-flag: t
+# End:
diff --git a/tests/tap/process.c b/tests/tap/process.c
index 8c22324..d9e94d8 100644
--- a/tests/tap/process.c
+++ b/tests/tap/process.c
@@ -11,11 +11,11 @@
* mkstemp.
*
* The canonical version of this file is maintained in the rra-c-util package,
- * which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
+ * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
- * Copyright 2002, 2004, 2005, 2013 Russ Allbery <eagle@eyrie.org>
- * Copyright 2009, 2010, 2011, 2013, 2014
+ * Copyright 2002, 2004-2005, 2013, 2016-2017 Russ Allbery <eagle@eyrie.org>
+ * Copyright 2009-2011, 2013-2014
* The Board of Trustees of the Leland Stanford Junior University
*
* Permission is hereby granted, free of charge, to any person obtaining a
@@ -35,6 +35,8 @@
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
+ *
+ * SPDX-License-Identifier: MIT
*/
#include <config.h>
@@ -134,6 +136,8 @@ run_child_function(test_function_type function, void *data, int *status,
count = 0;
do {
ret = read(fds[0], buf + count, buflen - count - 1);
+ if (SSIZE_MAX - count <= ret)
+ bail("maximum output size exceeded in run_child_function");
if (ret > 0)
count += ret;
if (count >= buflen - 1) {
@@ -141,7 +145,7 @@ run_child_function(test_function_type function, void *data, int *status,
buf = brealloc(buf, buflen);
}
} while (ret > 0);
- buf[count < 0 ? 0 : count] = '\0';
+ buf[count] = '\0';
if (waitpid(child, &rval, 0) == (pid_t) -1)
sysbail("waitpid failed");
close(fds[0]);
@@ -364,7 +368,7 @@ process_stop_all(int success UNUSED, int primary)
* Read the PID of a process from a file. This is necessary when running
* under fakeroot to get the actual PID of the remctld process.
*/
-static long
+static pid_t
read_pidfile(const char *path)
{
FILE *file;
@@ -380,7 +384,7 @@ read_pidfile(const char *path)
pid = strtol(buffer, NULL, 10);
if (pid <= 0)
bail("cannot read PID from %s", path);
- return pid;
+ return (pid_t) pid;
}
diff --git a/tests/tap/process.h b/tests/tap/process.h
index 8137d5d..da21ad3 100644
--- a/tests/tap/process.h
+++ b/tests/tap/process.h
@@ -2,10 +2,10 @@
* Utility functions for tests that use subprocesses.
*
* The canonical version of this file is maintained in the rra-c-util package,
- * which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
+ * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
- * Copyright 2009, 2010, 2013
+ * Copyright 2009-2010, 2013
* The Board of Trustees of the Leland Stanford Junior University
*
* Permission is hereby granted, free of charge, to any person obtaining a
@@ -25,6 +25,8 @@
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
+ *
+ * SPDX-License-Identifier: MIT
*/
#ifndef TAP_PROCESS_H
diff --git a/tests/tap/remctl.sh b/tests/tap/remctl.sh
index 0a511a0..e39b88f 100644
--- a/tests/tap/remctl.sh
+++ b/tests/tap/remctl.sh
@@ -6,9 +6,10 @@
# Bourne shell. Instead, all private variables are prefixed with "tap_".
#
# The canonical version of this file is maintained in the rra-c-util package,
-# which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
+# which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
#
# Written by Russ Allbery <eagle@eyrie.org>
+# Copyright 2016 Russ Allbery <eagle@eyrie.org>
# Copyright 2009, 2012
# The Board of Trustees of the Leland Stanford Junior University
#
@@ -29,6 +30,10 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
+#
+# SPDX-License-Identifier: MIT
+
+. "${C_TAP_SOURCE}/tap/libtap.sh"
# Start remctld. Takes the path to remctld, which may be found via configure,
# and the path to the configuration file.
@@ -45,7 +50,7 @@ remctld_start () {
( "$VALGRIND" --log-file=valgrind.%p --leak-check=full "$1" -m \
-p 14373 -s "$tap_principal" -P "$tap_pidfile" -f "$2" -d -S -F \
-k "$tap_keytab" &)
- [ -f "$BUILD/data/remctld.pid" ] || sleep 5
+ [ -f "$tap_pidfile" ] || sleep 5
else
( "$1" -m -p 14373 -s "$tap_principal" -P "$tap_pidfile" -f "$2" \
-d -S -F -k "$tap_keytab" &)
diff --git a/tests/tap/string.c b/tests/tap/string.c
index 6ed7e68..71cf571 100644
--- a/tests/tap/string.c
+++ b/tests/tap/string.c
@@ -5,9 +5,9 @@
* because they rely on additional portability code from rra-c-util.
*
* The canonical version of this file is maintained in the rra-c-util package,
- * which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
+ * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
- * Copyright 2011, 2012 Russ Allbery <eagle@eyrie.org>
+ * Copyright 2011-2012 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"),
@@ -26,6 +26,8 @@
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
+ *
+ * SPDX-License-Identifier: MIT
*/
#include <config.h>
diff --git a/tests/tap/string.h b/tests/tap/string.h
index d58f75d..a520210 100644
--- a/tests/tap/string.h
+++ b/tests/tap/string.h
@@ -5,9 +5,9 @@
* because they rely on additional portability code from rra-c-util.
*
* The canonical version of this file is maintained in the rra-c-util package,
- * which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
+ * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
- * Copyright 2011, 2012 Russ Allbery <eagle@eyrie.org>
+ * Copyright 2011-2012 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"),
@@ -26,6 +26,8 @@
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
+ *
+ * SPDX-License-Identifier: MIT
*/
#ifndef TAP_STRING_H
diff --git a/tests/util/messages-krb5-t.c b/tests/util/messages-krb5-t.c
index c6de5a5..b22c4cf 100644
--- a/tests/util/messages-krb5-t.c
+++ b/tests/util/messages-krb5-t.c
@@ -2,10 +2,10 @@
* Test suite for Kerberos error handling routines.
*
* The canonical version of this file is maintained in the rra-c-util package,
- * which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
+ * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
- * Copyright 2010, 2011, 2013, 2014
+ * Copyright 2010-2011, 2013-2014
* The Board of Trustees of the Leland Stanford Junior University
*
* Permission is hereby granted, free of charge, to any person obtaining a
@@ -25,6 +25,8 @@
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
+ *
+ * SPDX-License-Identifier: MIT
*/
#include <config.h>
@@ -56,7 +58,7 @@ main(void)
/*
* Test functions.
*/
-static void
+static void __attribute__((__noreturn__))
test_warn(void *data UNUSED)
{
krb5_context ctx;
@@ -74,7 +76,7 @@ test_warn(void *data UNUSED)
exit(0);
}
-static void
+static void __attribute__((__noreturn__))
test_die(void *data UNUSED)
{
krb5_context ctx;
diff --git a/tests/util/messages-t.c b/tests/util/messages-t.c
index 1098314..e8a7835 100644
--- a/tests/util/messages-t.c
+++ b/tests/util/messages-t.c
@@ -2,11 +2,11 @@
* Test suite for error handling routines.
*
* The canonical version of this file is maintained in the rra-c-util package,
- * which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
+ * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
- * Copyright 2002, 2004, 2005, 2015 Russ Allbery <eagle@eyrie.org>
- * Copyright 2009, 2010, 2011, 2012
+ * Copyright 2002, 2004-2005, 2015, 2017 Russ Allbery <eagle@eyrie.org>
+ * Copyright 2009-2012
* The Board of Trustees of the Leland Stanford Junior University
*
* Permission is hereby granted, free of charge, to any person obtaining a
@@ -26,6 +26,8 @@
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
+ *
+ * SPDX-License-Identifier: MIT
*/
#include <config.h>
@@ -46,45 +48,87 @@
/*
* Test functions.
*/
-static void test1(void *data UNUSED) { warn("warning"); }
-static void test2(void *data UNUSED) { die("fatal"); }
-static void test3(void *data UNUSED) { errno = EPERM; syswarn("permissions"); }
-static void test4(void *data UNUSED) {
+static void
+test1(void *data UNUSED)
+{
+ warn("warning");
+}
+
+static void __attribute__((__noreturn__))
+test2(void *data UNUSED)
+{
+ die("fatal");
+}
+
+static void
+test3(void *data UNUSED)
+{
+ errno = EPERM;
+ syswarn("permissions");
+}
+
+static void __attribute__((__noreturn__))
+test4(void *data UNUSED)
+{
errno = EACCES;
sysdie("fatal access");
}
-static void test5(void *data UNUSED) {
+
+static void
+test5(void *data UNUSED)
+{
message_program_name = "test5";
warn("warning");
}
-static void test6(void *data UNUSED) {
+
+static void __attribute__((__noreturn__))
+test6(void *data UNUSED)
+{
message_program_name = "test6";
die("fatal");
}
-static void test7(void *data UNUSED) {
+
+static void
+test7(void *data UNUSED)
+{
message_program_name = "test7";
errno = EPERM;
syswarn("perms %d", 7);
}
-static void test8(void *data UNUSED) {
+
+static void __attribute__((__noreturn__))
+test8(void *data UNUSED)
+{
message_program_name = "test8";
errno = EACCES;
sysdie("%st%s", "fa", "al");
}
-static int return10(void) { return 10; }
+static int
+return10(void)
+{
+ return 10;
+}
-static void test9(void *data UNUSED) {
+static void __attribute__((__noreturn__))
+test9(void *data UNUSED)
+{
message_fatal_cleanup = return10;
die("fatal");
}
-static void test10(void *data UNUSED) {
+
+static void __attribute__((__noreturn__))
+test10(void *data UNUSED)
+{
message_program_name = 0;
message_fatal_cleanup = return10;
errno = EPERM;
sysdie("fatal perm");
}
-static void test11(void *data UNUSED) {
+
+static void __attribute__((__noreturn__))
+test11(void *data UNUSED)
+{
message_program_name = "test11";
message_fatal_cleanup = return10;
errno = EPERM;
@@ -93,61 +137,104 @@ static void test11(void *data UNUSED) {
}
static void __attribute__((__format__(printf, 2, 0)))
-log_msg(size_t len, const char *format, va_list args, int error) {
+log_msg(size_t len, const char *format, va_list args, int error)
+{
fprintf(stderr, "%lu %d ", (unsigned long) len, error);
vfprintf(stderr, format, args);
fprintf(stderr, "\n");
}
-static void test12(void *data UNUSED) {
+static void
+test12(void *data UNUSED)
+{
message_handlers_warn(1, log_msg);
warn("warning");
}
-static void test13(void *data UNUSED) {
+
+static void __attribute__((__noreturn__))
+test13(void *data UNUSED)
+{
message_handlers_die(1, log_msg);
die("fatal");
}
-static void test14(void *data UNUSED) {
+
+static void
+test14(void *data UNUSED)
+{
message_handlers_warn(2, log_msg, log_msg);
errno = EPERM;
syswarn("warning");
}
-static void test15(void *data UNUSED) {
+
+static void __attribute__((__noreturn__))
+test15(void *data UNUSED)
+{
message_handlers_die(2, log_msg, log_msg);
message_fatal_cleanup = return10;
errno = EPERM;
sysdie("fatal");
}
-static void test16(void *data UNUSED) {
+
+static void
+test16(void *data UNUSED)
+{
message_handlers_warn(2, message_log_stderr, log_msg);
message_program_name = "test16";
errno = EPERM;
syswarn("warning");
}
-static void test17(void *data UNUSED) { notice("notice"); }
-static void test18(void *data UNUSED) {
+
+static void
+test17(void *data UNUSED)
+{
+ notice("notice");
+}
+
+static void
+test18(void *data UNUSED)
+{
message_program_name = "test18";
notice("notice");
}
-static void test19(void *data UNUSED) { debug("debug"); }
-static void test20(void *data UNUSED) {
+
+static void
+test19(void *data UNUSED)
+{
+ debug("debug");
+}
+
+static void
+test20(void *data UNUSED)
+{
message_handlers_notice(1, log_msg);
notice("foo");
}
-static void test21(void *data UNUSED) {
+
+static void
+test21(void *data UNUSED)
+{
message_handlers_debug(1, message_log_stdout);
message_program_name = "test23";
debug("baz");
}
-static void test22(void *data UNUSED) {
+
+static void __attribute__((__noreturn__))
+test22(void *data UNUSED)
+{
message_handlers_die(0);
die("hi mom!");
}
-static void test23(void *data UNUSED) {
+
+static
+void test23(void *data UNUSED)
+{
message_handlers_warn(0);
warn("this is a test");
}
-static void test24(void *data UNUSED) {
+
+static
+void test24(void *data UNUSED)
+{
notice("first");
message_handlers_notice(0);
notice("second");
diff --git a/tests/util/xmalloc-t b/tests/util/xmalloc-t
index af604ed..e73a7c6 100755
--- a/tests/util/xmalloc-t
+++ b/tests/util/xmalloc-t
@@ -3,11 +3,11 @@
# Test suite for xmalloc and friends.
#
# The canonical version of this file is maintained in the rra-c-util package,
-# which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
+# 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 Russ Allbery <eagle@eyrie.org>
-# Copyright 2008, 2009, 2010, 2012
+# Copyright 2000-2001, 2006, 2014, 2016 Russ Allbery <eagle@eyrie.org>
+# Copyright 2008-2010, 2012
# The Board of Trustees of the Leland Stanford Junior University
#
# Permission is hereby granted, free of charge, to any person obtaining a
@@ -27,9 +27,11 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
+#
+# SPDX-License-Identifier: MIT
-. "$SOURCE/tap/libtap.sh"
-cd "$BUILD/util"
+. "$C_TAP_SOURCE/tap/libtap.sh"
+cd "$C_TAP_BUILD/util"
# Run an xmalloc test. Takes the description, the expectd exit status, the
# output, and the arguments.
diff --git a/tests/util/xmalloc.c b/tests/util/xmalloc.c
index 84ba081..d157bbb 100644
--- a/tests/util/xmalloc.c
+++ b/tests/util/xmalloc.c
@@ -2,10 +2,10 @@
* Test suite for xmalloc and family.
*
* The canonical version of this file is maintained in the rra-c-util package,
- * which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
+ * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
- * Copyright 2000, 2001, 2006 Russ Allbery <eagle@eyrie.org>
- * Copyright 2008, 2012, 2013, 2014
+ * Copyright 2000-2001, 2006, 2017 Russ Allbery <eagle@eyrie.org>
+ * Copyright 2008, 2012-2014
* The Board of Trustees of the Leland Stanford Junior University
*
* Permission is hereby granted, free of charge, to any person obtaining a
@@ -25,6 +25,8 @@
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
+ *
+ * SPDX-License-Identifier: MIT
*/
#line 1 "xmalloc.c"
@@ -50,7 +52,7 @@
* A customized error handler for checking xmalloc's support of them. Prints
* out the error message and exits with status 1.
*/
-static void
+static void __attribute__((__noreturn__))
test_handler(const char *function, size_t size, const char *file, int line)
{
die("%s %lu %s %d", function, (unsigned long) size, file, line);
@@ -327,7 +329,7 @@ main(int argc, char *argv[])
code = argv[1][0];
if (isupper(code)) {
xmalloc_error_handler = test_handler;
- code = tolower(code);
+ code = (unsigned char) tolower(code);
}
/*
@@ -390,9 +392,7 @@ main(int argc, char *argv[])
case 'n': exit(test_strndup(size) ? willfail : 1);
case 'a': exit(test_asprintf(size) ? willfail : 1);
case 'v': exit(test_vasprintf(size) ? willfail : 1);
- default:
- die("Unknown mode %c", argv[1][0]);
- break;
+ default: die("Unknown mode %c", argv[1][0]);
}
exit(1);
}