diff options
Diffstat (limited to 'tests/util')
-rw-r--r-- | tests/util/messages-krb5-t.c | 10 | ||||
-rw-r--r-- | tests/util/messages-t.c | 145 | ||||
-rwxr-xr-x | tests/util/xmalloc-t | 12 | ||||
-rw-r--r-- | tests/util/xmalloc.c | 16 |
4 files changed, 137 insertions, 46 deletions
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); } |