diff options
author | Russ Allbery <rra@stanford.edu> | 2008-04-24 02:02:49 +0000 |
---|---|---|
committer | Russ Allbery <rra@stanford.edu> | 2008-04-24 02:02:49 +0000 |
commit | 92ff7f21ad0b167f8d742a9d7b5f93704a57619c (patch) | |
tree | 7adae5f227b6463e07d5cd0f1dab82b7f1c6be47 /tests/util | |
parent | 34c58f9471b3df4fa8b719b3c3534940ba5cfe1b (diff) |
Major coding style cleanup. Updated all shared code from my other
projects.
The configure option requesting AFS kaserver support (and thus
building kasetkey) is now --with-kaserver instead of --with-afs.
If KRB5_CONFIG was explicitly set in the environment, don't use a
different krb5-config based on --with-krb4 or --with-krb5. If
krb5-config isn't executable, don't use it. This allows one to
force library probing by setting KRB5_CONFIG to point to a
nonexistent file.
Sanity-check the results of krb5-config before proceeding and error
out in configure if they don't work.
Stop setting Stanford-specific compile-time defaults for the wallet
server and port.
Diffstat (limited to 'tests/util')
-rw-r--r-- | tests/util/concat-t.c | 55 | ||||
-rw-r--r-- | tests/util/messages-t.c | 90 | ||||
-rw-r--r-- | tests/util/xmalloc-t.in | 44 | ||||
-rw-r--r-- | tests/util/xmalloc.c | 141 |
4 files changed, 192 insertions, 138 deletions
diff --git a/tests/util/concat-t.c b/tests/util/concat-t.c index c18cd19..2428d71 100644 --- a/tests/util/concat-t.c +++ b/tests/util/concat-t.c @@ -1,35 +1,40 @@ -/* $Id$ */ -/* concat test suite. */ - -/* Copyright (c) 2004, 2005, 2006 - by Internet Systems Consortium, Inc. ("ISC") - Copyright (c) 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, - 2002, 2003 by The Internet Software Consortium and Rich Salz - - This code is derived from software contributed to the Internet Software - Consortium by Rich Salz. - - Permission to use, copy, modify, and distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH - REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY - SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +/* $Id$ + * + * concat test suite. + * + * Copyright 2004, 2005, 2006 + * by Internet Systems Consortium, Inc. ("ISC") + * Copyright 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, + * 2003 by The Internet Software Consortium and Rich Salz + * + * This code is derived from software contributed to the Internet Software + * Consortium by Rich Salz. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ #include <config.h> -#include <system.h> +#include <portable/system.h> #include <tests/libtest.h> #include <util/util.h> -#define END (char *) 0 +#define END (char *) 0 + -/* Memory leaks everywhere! Whoo-hoo! */ +/* + * Memory leaks everywhere! Whoo-hoo! + */ int main(void) { diff --git a/tests/util/messages-t.c b/tests/util/messages-t.c index ef58737..434ef56 100644 --- a/tests/util/messages-t.c +++ b/tests/util/messages-t.c @@ -1,28 +1,30 @@ -/* $Id$ */ -/* Test suite for error handling routines. */ - -/* Copyright (c) 2004, 2005, 2006 - by Internet Systems Consortium, Inc. ("ISC") - Copyright (c) 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, - 2002, 2003 by The Internet Software Consortium and Rich Salz - - This code is derived from software contributed to the Internet Software - Consortium by Rich Salz. - - Permission to use, copy, modify, and distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH - REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY - SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +/* $Id$ + * + * Test suite for error handling routines. + * + * Copyright 2004, 2005, 2006 + * by Internet Systems Consortium, Inc. ("ISC") + * Copyright 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, + * 2003 by The Internet Software Consortium and Rich Salz + * + * This code is derived from software contributed to the Internet Software + * Consortium by Rich Salz. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ #include <config.h> -#include <system.h> +#include <portable/system.h> #include <errno.h> #include <fcntl.h> @@ -32,14 +34,17 @@ #include <tests/libtest.h> #include <util/util.h> -#define END (char *) 0 +#define END (char *) 0 /* Test function type. */ typedef void (*test_function_t)(void); -/* Fork and execute the provided function, connecting stdout and stderr to a - pipe. Captures the output into the provided buffer and returns the exit - status as a waitpid status value. */ + +/* + * Fork and execute the provided function, connecting stdout and stderr to a + * pipe. Captures the output into the provided buffer and returns the exit + * status as a waitpid status value. + */ static int run_test(test_function_t function, char *buf, size_t buflen) { @@ -70,8 +75,10 @@ run_test(test_function_t function, char *buf, size_t buflen) fflush(stdout); _exit(0); } else { - /* In the parent; close the extra file descriptor, read the output - if any, and then collect the exit status. */ + /* + * In the parent; close the extra file descriptor, read the output if + * any, and then collect the exit status. + */ close(fds[1]); count = 0; do { @@ -86,7 +93,10 @@ run_test(test_function_t function, char *buf, size_t buflen) return rval; } -/* Test functions. */ + +/* + * Test functions. + */ static void test1(void) { warn("warning"); } static void test2(void) { die("fatal"); } static void test3(void) { errno = EPERM; syswarn("permissions"); } @@ -192,8 +202,11 @@ static void test24(void) { notice("third"); } -/* Given the test number, intended exit status and message, and the function - to run, print ok or not ok. */ + +/* + * Given the test number, intended exit status and message, and the function + * to run, print ok or not ok. + */ static void test_error(int n, int status, const char *output, test_function_t function) { @@ -214,9 +227,11 @@ test_error(int n, int status, const char *output, test_function_t function) printf("%sok %d\n", succeeded ? "" : "not ", n); } -/* Given the test number, intended status, intended message sans the - appended strerror output, errno, and the function to run, print ok or not - ok. */ + +/* + * Given the test number, intended status, intended message sans the appended + * strerror output, errno, and the function to run, print ok or not ok. + */ static void test_strerror(int n, int status, const char *output, int error, test_function_t function) @@ -228,7 +243,10 @@ test_strerror(int n, int status, const char *output, int error, free(full_output); } -/* Run the tests. */ + +/* + * Run the tests. + */ int main(void) { diff --git a/tests/util/xmalloc-t.in b/tests/util/xmalloc-t.in index 504bbaa..f721822 100644 --- a/tests/util/xmalloc-t.in +++ b/tests/util/xmalloc-t.in @@ -3,18 +3,18 @@ # # Test suite for xmalloc and friends. # -# Copyright (c) 2004, 2005, 2006 +# Copyright 2004, 2005, 2006 # by Internet Systems Consortium, Inc. ("ISC") -# Copyright (c) 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, -# 2002, 2003 by The Internet Software Consortium and Rich Salz -# +# Copyright 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003 by The Internet Software Consortium and Rich Salz +# # This code is derived from software contributed to the Internet Software # Consortium by Rich Salz. -# +# # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. -# +# # THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH # REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY # AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, @@ -39,7 +39,7 @@ runsuccess () { printcount "ok" else if test $status = 2 ; then - printcount "ok" "# skip no data limit support" + printcount "ok" "# skip - no data limit support" else printcount "not ok" echo " $output" @@ -59,7 +59,7 @@ runfailure () { printcount "ok" else if test $status = 2 ; then - printcount "ok" "# skip no data limit support" + printcount "ok" "# skip - no data limit support" else printcount "not ok" echo " saw: $output" @@ -94,28 +94,28 @@ runsuccess "v" "128000" "0" # Now limit our memory to 120KB and then try the large ones again, all of # which should fail. runfailure "m" "128000" "120000" \ - "failed to malloc 128000 bytes at xmalloc.c line 54" + "failed to malloc 128000 bytes at xmalloc.c line 61" runfailure "r" "128000" "120000" \ - "failed to realloc 128000 bytes at xmalloc.c line 80" + "failed to realloc 128000 bytes at xmalloc.c line 90" runfailure "s" "64000" "120000" \ - "failed to strdup 64000 bytes at xmalloc.c line 109" + "failed to strdup 64000 bytes at xmalloc.c line 121" runfailure "n" "64000" "120000" \ - "failed to strndup 64000 bytes at xmalloc.c line 133" + "failed to strndup 64000 bytes at xmalloc.c line 148" runfailure "c" "128000" "120000" \ - "failed to calloc 128000 bytes at xmalloc.c line 155" + "failed to calloc 128000 bytes at xmalloc.c line 172" runfailure "a" "64000" "120000" \ - "failed to asprintf 64000 bytes at xmalloc.c line 177" + "failed to asprintf 64000 bytes at xmalloc.c line 241" runfailure "v" "64000" "120000" \ - "failed to vasprintf 64000 bytes at xmalloc.c line 196" + "failed to vasprintf 64000 bytes at xmalloc.c line 217" # Check our custom error handler. -runfailure "M" "128000" "120000" "malloc 128000 xmalloc.c 54" -runfailure "R" "128000" "120000" "realloc 128000 xmalloc.c 80" -runfailure "S" "64000" "120000" "strdup 64000 xmalloc.c 109" -runfailure "N" "64000" "120000" "strndup 64000 xmalloc.c 133" -runfailure "C" "128000" "120000" "calloc 128000 xmalloc.c 155" -runfailure "A" "64000" "120000" "asprintf 64000 xmalloc.c 177" -runfailure "V" "64000" "120000" "vasprintf 64000 xmalloc.c 196" +runfailure "M" "128000" "120000" "malloc 128000 xmalloc.c 61" +runfailure "R" "128000" "120000" "realloc 128000 xmalloc.c 90" +runfailure "S" "64000" "120000" "strdup 64000 xmalloc.c 121" +runfailure "N" "64000" "120000" "strndup 64000 xmalloc.c 148" +runfailure "C" "128000" "120000" "calloc 128000 xmalloc.c 172" +runfailure "A" "64000" "120000" "asprintf 64000 xmalloc.c 241" +runfailure "V" "64000" "120000" "vasprintf 64000 xmalloc.c 217" # Check the smaller ones again just for grins. runsuccess "m" "21" "96000" diff --git a/tests/util/xmalloc.c b/tests/util/xmalloc.c index 4327681..699d0c4 100644 --- a/tests/util/xmalloc.c +++ b/tests/util/xmalloc.c @@ -1,50 +1,57 @@ -/* $Id$ */ -/* Test suite for xmalloc and family. */ - -/* Copyright (c) 2004, 2005, 2006 - by Internet Systems Consortium, Inc. ("ISC") - Copyright (c) 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, - 2002, 2003 by The Internet Software Consortium and Rich Salz - - This code is derived from software contributed to the Internet Software - Consortium by Rich Salz. - - Permission to use, copy, modify, and distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH - REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY - SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +/* $Id$ + * + * Test suite for xmalloc and family. + * + * Copyright 2004, 2005, 2006 + * by Internet Systems Consortium, Inc. ("ISC") + * Copyright 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, + * 2003 by The Internet Software Consortium and Rich Salz + * + * This code is derived from software contributed to the Internet Software + * Consortium by Rich Salz. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ #include <config.h> -#include <system.h> +#include <portable/system.h> #include <ctype.h> #include <errno.h> #include <sys/time.h> -#include <unistd.h> /* Linux requires sys/time.h be included before sys/resource.h. */ #include <sys/resource.h> #include <util/util.h> -/* A customized error handler for checking xmalloc's support of them. - Prints out the error message and exits with status 1. */ + +/* + * A customized error handler for checking xmalloc's support of them. Prints + * out the error message and exits with status 1. + */ static void test_handler(const char *function, size_t size, const char *file, int line) { die("%s %lu %s %d", function, (unsigned long) size, file, line); } -/* Allocate the amount of memory given and write to all of it to make sure - we can, returning true if that succeeded and false on any sort of - detectable error. */ + +/* + * Allocate the amount of memory given and write to all of it to make sure we + * can, returning true if that succeeded and false on any sort of detectable + * error. + */ static int test_malloc(size_t size) { @@ -63,9 +70,12 @@ test_malloc(size_t size) return 1; } -/* Allocate half the memory given, write to it, then reallocate to the - desired size, writing to the rest and then checking it all. Returns true - on success, false on any failure. */ + +/* + * Allocate half the memory given, write to it, then reallocate to the desired + * size, writing to the rest and then checking it all. Returns true on + * success, false on any failure. + */ static int test_realloc(size_t size) { @@ -92,9 +102,11 @@ test_realloc(size_t size) return 1; } -/* Generate a string of the size indicated, call xstrdup on it, and then - ensure the result matches. Returns true on success, false on any - failure. */ + +/* + * Generate a string of the size indicated, call xstrdup on it, and then + * ensure the result matches. Returns true on success, false on any failure. + */ static int test_strdup(size_t size) { @@ -115,9 +127,12 @@ test_strdup(size_t size) return (match == 0); } -/* Generate a string of the size indicated plus some, call xstrndup on it, and - then ensure the result matches. Returns true on success, false on any - failure. */ + +/* + * Generate a string of the size indicated plus some, call xstrndup on it, and + * then ensure the result matches. Returns true on success, false on any + * failure. + */ static int test_strndup(size_t size) { @@ -140,9 +155,11 @@ test_strndup(size_t size) return (match == 0 && toomuch != 0); } -/* Allocate the amount of memory given and check that it's all zeroed, - returning true if that succeeded and false on any sort of detectable - error. */ + +/* + * Allocate the amount of memory given and check that it's all zeroed, + * returning true if that succeeded and false on any sort of detectable error. + */ static int test_calloc(size_t size) { @@ -162,8 +179,11 @@ test_calloc(size_t size) return 1; } -/* Test asprintf with a large string (essentially using it as strdup). - Returns true if successful, false otherwise. */ + +/* + * Test asprintf with a large string (essentially using it as strdup). + * Returns true if successful, false otherwise. + */ static int test_asprintf(size_t size) { @@ -185,6 +205,7 @@ test_asprintf(size_t size) return 1; } + /* Wrapper around vasprintf to do the va_list stuff. */ static int xvasprintf_wrapper(char **strp, const char *format, ...) @@ -198,8 +219,11 @@ xvasprintf_wrapper(char **strp, const char *format, ...) return status; } -/* Test vasprintf with a large string (essentially using it as strdup). - Returns true if successful, false otherwise. */ + +/* + * Test vasprintf with a large string (essentially using it as strdup). + * Returns true if successful, false otherwise. + */ static int test_vasprintf(size_t size) { @@ -221,8 +245,11 @@ test_vasprintf(size_t size) return 1; } -/* Take the amount of memory to allocate in bytes as a command-line argument - and call test_malloc with that amount of memory. */ + +/* + * Take the amount of memory to allocate in bytes as a command-line argument + * and call test_malloc with that amount of memory. + */ int main(int argc, char *argv[]) { @@ -243,11 +270,13 @@ main(int argc, char *argv[]) if (limit == 0 && errno != 0) sysdie("Invalid limit"); - /* If a memory limit was given and we can set memory limits, set it. - Otherwise, exit 2, signalling to the driver that the test should be - skipped. We do this here rather than in the driver due to some - pathological problems with Linux (setting ulimit in the shell caused - the shell to die). */ + /* + * If a memory limit was given and we can set memory limits, set it. + * Otherwise, exit 2, signalling to the driver that the test should be + * skipped. We do this here rather than in the driver due to some + * pathological problems with Linux (setting ulimit in the shell caused + * the shell to die). + */ if (limit > 0) { #if HAVE_SETRLIMIT && defined(RLIMIT_DATA) rl.rlim_cur = limit; @@ -269,9 +298,11 @@ main(int argc, char *argv[]) code = tolower(code); } - /* Decide if the allocation should fail. If it should, set willfail to - 2, so that if it unexpectedly succeeds, we exit with a status - indicating that the test should be skipped. */ + /* + * Decide if the allocation should fail. If it should, set willfail to 2, + * so that if it unexpectedly succeeds, we exit with a status indicating + * that the test should be skipped. + */ max = size; if (code == 's' || code == 'n' || code == 'a' || code == 'v') max *= 2; |