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 | |
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')
-rw-r--r-- | tests/libtest.c | 124 | ||||
-rw-r--r-- | tests/libtest.h | 80 | ||||
-rw-r--r-- | tests/portable/asprintf-t.c | 26 | ||||
-rw-r--r-- | tests/portable/snprintf-t.c | 50 | ||||
-rw-r--r-- | tests/portable/strlcat-t.c | 2 | ||||
-rw-r--r-- | tests/portable/strlcpy-t.c | 2 | ||||
-rw-r--r-- | tests/runtests.c | 254 | ||||
-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 |
11 files changed, 489 insertions, 379 deletions
diff --git a/tests/libtest.c b/tests/libtest.c index 10e6024..76d5207 100644 --- a/tests/libtest.c +++ b/tests/libtest.c @@ -1,37 +1,37 @@ -/* $Id$ -** -** Some utility routines for writing tests. -** -** Herein are a variety of utility routines for writing tests. All -** routines of the form ok*() take a test number and some number of -** appropriate arguments, check to be sure the results match the expected -** output using the arguments, and print out something appropriate for that -** test number. Other utility routines help in constructing more complex -** tests. -** -** 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$ + * + * Some utility routines for writing tests. + * + * Herein are a variety of utility routines for writing tests. All routines + * of the form ok*() take a test number and some number of appropriate + * arguments, check to be sure the results match the expected output using the + * arguments, and print out something appropriate for that test number. Other + * utility routines help in constructing more complex tests. + * + * Copyright 2006, 2007 Board of Trustees, Leland Stanford Jr. University + * 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. + */ #include <config.h> -#include <system.h> +#include <portable/system.h> #include <sys/time.h> #include <sys/wait.h> @@ -44,9 +44,9 @@ char *errors = NULL; /* -** Initialize things. Turns on line buffering on stdout and then prints out -** the number of tests in the test suite. -*/ + * Initialize things. Turns on line buffering on stdout and then prints out + * the number of tests in the test suite. + */ void test_init(int count) { @@ -57,9 +57,9 @@ test_init(int count) /* -** Takes a boolean success value and assumes the test passes if that value -** is true and fails if that value is false. -*/ + * Takes a boolean success value and assumes the test passes if that value + * is true and fails if that value is false. + */ void ok(int n, int success) { @@ -68,9 +68,9 @@ ok(int n, int success) /* -** Takes an expected integer and a seen integer and assumes the test passes -** if those two numbers match. -*/ + * Takes an expected integer and a seen integer and assumes the test passes + * if those two numbers match. + */ void ok_int(int n, int wanted, int seen) { @@ -82,9 +82,9 @@ ok_int(int n, int wanted, int seen) /* -** Takes a string and what the string should be, and assumes the test -** passes if those strings match (using strcmp). -*/ + * Takes a string and what the string should be, and assumes the test passes + * if those strings match (using strcmp). + */ void ok_string(int n, const char *wanted, const char *seen) { @@ -100,9 +100,9 @@ ok_string(int n, const char *wanted, const char *seen) /* -** Takes an expected integer and a seen integer and assumes the test passes -** if those two numbers match. -*/ + * Takes an expected integer and a seen integer and assumes the test passes if + * those two numbers match. + */ void ok_double(int n, double wanted, double seen) { @@ -114,8 +114,8 @@ ok_double(int n, double wanted, double seen) /* -** Skip a test. -*/ + * Skip a test. + */ void skip(int n, const char *reason) { @@ -127,8 +127,8 @@ skip(int n, const char *reason) /* -** Report the same status on the next count tests. -*/ + * Report the same status on the next count tests. + */ void ok_block(int n, int count, int status) { @@ -140,8 +140,8 @@ ok_block(int n, int count, int status) /* -** Skip the next count tests. -*/ + * Skip the next count tests. + */ void skip_block(int n, int count, const char *reason) { @@ -153,9 +153,9 @@ skip_block(int n, int count, const char *reason) /* -** An error handler that appends all errors to the errors global. Used by -** error_capture. -*/ + * An error handler that appends all errors to the errors global. Used by + * error_capture. + */ static void message_log_buffer(int len, const char *fmt, va_list args, int error UNUSED) { @@ -177,10 +177,10 @@ message_log_buffer(int len, const char *fmt, va_list args, int error UNUSED) /* -** Turn on the capturing of errors. Errors will be stored in the global -** errors variable where they can be checked by the test suite. Capturing is -** turned off with errors_uncapture. -*/ + * Turn on the capturing of errors. Errors will be stored in the global + * errors variable where they can be checked by the test suite. Capturing is + * turned off with errors_uncapture. + */ void errors_capture(void) { @@ -194,8 +194,8 @@ errors_capture(void) /* -** Turn off the capturing of errors again. -*/ + * Turn off the capturing of errors again. + */ void errors_uncapture(void) { diff --git a/tests/libtest.h b/tests/libtest.h index 7c4aca7..ac2b083 100644 --- a/tests/libtest.h +++ b/tests/libtest.h @@ -1,49 +1,41 @@ -/* $Id$ -** -** Some utility routines for writing tests. -** -** 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$ + * + * Some utility routines for writing tests. + * + * Copyright 2006, 2007 Board of Trustees, Leland Stanford Jr. University + * 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. + */ #ifndef LIBTEST_H #define LIBTEST_H 1 #include <config.h> +#include <portable/macros.h> -/* BEGIN_DECLS is used at the beginning of declarations so that C++ - compilers don't mangle their names. END_DECLS is used at the end. */ -#undef BEGIN_DECLS -#undef END_DECLS -#ifdef __cplusplus -# define BEGIN_DECLS extern "C" { -# define END_DECLS } -#else -# define BEGIN_DECLS /* empty */ -# define END_DECLS /* empty */ -#endif - -/* Used for iterating through arrays. ARRAY_SIZE returns the number of - elements in the array (useful for a < upper bound in a for loop) and - ARRAY_END returns a pointer to the element past the end (ISO C99 makes it - legal to refer to such a pointer as long as it's never dereferenced). */ +/* + * Used for iterating through arrays. ARRAY_SIZE returns the number of + * elements in the array (useful for a < upper bound in a for loop) and + * ARRAY_END returns a pointer to the element past the end (ISO C99 makes it + * legal to refer to such a pointer as long as it's never dereferenced). + */ #define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0])) #define ARRAY_END(array) (&(array)[ARRAY_SIZE(array)]) @@ -65,9 +57,11 @@ void skip_block(int n, int count, const char *reason); /* Print out the number of tests and set standard output to line buffered. */ void test_init(int count); -/* Turn on capturing of errors with errors_capture. Errors reported by warn - will be stored in the global errors variable. Turn this off again with - errors_uncapture. Caller is responsible for freeing errors when done. */ +/* + * Turn on capturing of errors with errors_capture. Errors reported by warn + * will be stored in the global errors variable. Turn this off again with + * errors_uncapture. Caller is responsible for freeing errors when done. + */ void errors_capture(void); void errors_uncapture(void); diff --git a/tests/portable/asprintf-t.c b/tests/portable/asprintf-t.c index a79c7f4..d42e740 100644 --- a/tests/portable/asprintf-t.c +++ b/tests/portable/asprintf-t.c @@ -1,15 +1,21 @@ -/* $Id$ */ -/* asprintf and vasprintf test suite. */ - -/* Written by Russ Allbery <rra@stanford.edu> - Copyright 2006 Board of Trustees, Leland Stanford Jr. University - See LICENSE for licensing terms. */ +/* $Id$ + * + * asprintf and vasprintf test suite. + * + * Written by Russ Allbery <rra@stanford.edu> + * Copyright 2006, 2008 Board of Trustees, Leland Stanford Jr. University + * + * See LICENSE for licensing terms. + */ #include <config.h> -#include <system.h> +#include <portable/system.h> #include <tests/libtest.h> +int test_asprintf(char **, const char *, ...); +int test_vasprintf(char **, const char *, va_list); + static int vatest(char **result, const char *format, ...) { @@ -17,7 +23,7 @@ vatest(char **result, const char *format, ...) int status; va_start(args, format); - status = vasprintf(result, format, args); + status = test_vasprintf(result, format, args); va_end(args); return status; } @@ -29,11 +35,11 @@ main(void) test_init(12); - ok_int(1, 7, asprintf(&result, "%s", "testing")); + ok_int(1, 7, test_asprintf(&result, "%s", "testing")); ok_string(2, "testing", result); free(result); ok(3, 1); - ok_int(4, 0, asprintf(&result, "%s", "")); + ok_int(4, 0, test_asprintf(&result, "%s", "")); ok_string(5, "", result); free(result); ok(6, 1); diff --git a/tests/portable/snprintf-t.c b/tests/portable/snprintf-t.c index 9159fcf..c33e0e7 100644 --- a/tests/portable/snprintf-t.c +++ b/tests/portable/snprintf-t.c @@ -1,28 +1,30 @@ -/* $Id$ */ -/* snprintf 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$ + * + * snprintf 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. + */ #include <config.h> -#include <system.h> +#include <portable/system.h> #include <tests/libtest.h> @@ -90,6 +92,7 @@ static unsigned long long ullong_nums[] = { 0 }; + static void test_format(int n, int truncate, const char *expected, int count, const char *format, ...) @@ -113,6 +116,7 @@ test_format(int n, int truncate, const char *expected, int count, } } + int main(void) { diff --git a/tests/portable/strlcat-t.c b/tests/portable/strlcat-t.c index 5ad8b6f..c860803 100644 --- a/tests/portable/strlcat-t.c +++ b/tests/portable/strlcat-t.c @@ -24,7 +24,7 @@ */ #include <config.h> -#include <system.h> +#include <portable/system.h> #include <tests/libtest.h> diff --git a/tests/portable/strlcpy-t.c b/tests/portable/strlcpy-t.c index 6427374..8fb1f9c 100644 --- a/tests/portable/strlcpy-t.c +++ b/tests/portable/strlcpy-t.c @@ -24,7 +24,7 @@ */ #include <config.h> -#include <system.h> +#include <portable/system.h> #include <tests/libtest.h> diff --git a/tests/runtests.c b/tests/runtests.c index d15d19c..abad3b6 100644 --- a/tests/runtests.c +++ b/tests/runtests.c @@ -1,52 +1,52 @@ -/* $Id$ -** -** Run a set of tests, reporting results. -** -** Usage: -** -** runtests <test-list> -** -** 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. Test output should start with a line containing the number of -** tests (numbered from 1 to this number), and then each line should be in -** the following format: -** -** ok <number> -** not ok <number> -** ok <number> # skip -** -** where <number> is the number of the test. ok indicates success, not ok -** indicates failure, and "# skip" indicates the test was skipped for some -** reason (maybe because it doesn't apply to this platform). -** -** Any bug reports, bug fixes, and improvements are very much welcome and -** should be sent to the e-mail address below. -** -** Copyright 2000, 2001, 2004 Russ Allbery <rra@stanford.edu> -** -** 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. +/* $Id$ + * + * Run a set of tests, reporting results. + * + * Usage: + * + * runtests <test-list> + * + * 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. Test output should start with a line containing the number of + * tests (numbered from 1 to this number), and then each line should be in the + * following format: + * + * ok <number> + * not ok <number> + * ok <number> # skip + * + * where <number> is the number of the test. ok indicates success, not ok + * indicates failure, and "# skip" indicates the test was skipped for some + * reason (maybe because it doesn't apply to this platform). + * + * Any bug reports, bug fixes, and improvements are very much welcome and + * should be sent to the e-mail address below. + * + * Copyright 2000, 2001, 2004, 2006, 2007, 2008 + * Russ Allbery <rra@stanford.edu> + * + * 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. */ #include <config.h> -#include <system.h> +#include <portable/system.h> #include <ctype.h> #include <errno.h> @@ -98,8 +98,10 @@ struct testlist { struct testlist *next; }; -/* Header used for test output. %s is replaced by the file name of the list - of tests. */ +/* + * Header used for test output. %s is replaced by the file name of the list + * of tests. + */ static const char banner[] = "\n\ Running all tests listed in %s. If any tests fail, run the failing\n\ test program by hand to see more details. The test program will have the\n\ @@ -131,7 +133,9 @@ static double tv_seconds(const struct timeval *); static double tv_sum(const struct timeval *, const struct timeval *); -/* Report a fatal error, including the results of strerror, and exit. */ +/* + * Report a fatal error, including the results of strerror, and exit. + */ static void sysdie(const char *format, ...) { @@ -149,7 +153,9 @@ sysdie(const char *format, ...) } -/* Allocate memory, reporting a fatal error and exiting on failure. */ +/* + * Allocate memory, reporting a fatal error and exiting on failure. + */ static void * x_malloc(size_t size, const char *file, int line) { @@ -163,7 +169,9 @@ x_malloc(size_t size, const char *file, int line) } -/* Copy a string, reporting a fatal error and exiting on failure. */ +/* + * Copy a string, reporting a fatal error and exiting on failure. + */ static char * x_strdup(const char *s, const char *file, int line) { @@ -180,22 +188,30 @@ x_strdup(const char *s, const char *file, int line) } -/* Given a struct timeval, return the number of seconds it represents as a - double. Use difftime() to convert a time_t to a double. */ +/* + * Given a struct timeval, return the number of seconds it represents as a + * double. Use difftime() to convert a time_t to a double. + */ static double tv_seconds(const struct timeval *tv) { return difftime(tv->tv_sec, 0) + tv->tv_usec * 1e-6; } -/* Given two struct timevals, return the difference in seconds. */ + +/* + * Given two struct timevals, return the difference in seconds. + */ static double tv_diff(const struct timeval *tv1, const struct timeval *tv0) { return tv_seconds(tv1) - tv_seconds(tv0); } -/* Given two struct timevals, return the sum in seconds as a double. */ + +/* + * Given two struct timevals, return the sum in seconds as a double. + */ static double tv_sum(const struct timeval *tv1, const struct timeval *tv2) { @@ -203,18 +219,22 @@ tv_sum(const struct timeval *tv1, const struct timeval *tv2) } -/* Read the first line of test output, which should contain the range of - test numbers, and initialize the testset structure. Assume it was zeroed - before being passed in. Return true if initialization succeeds, false - otherwise. */ +/* + * Read the first line of test output, which should contain the range of + * test numbers, and initialize the testset structure. Assume it was zeroed + * before being passed in. Return true if initialization succeeds, false + * otherwise. + */ static int test_init(const char *line, struct testset *ts) { int i; - /* Prefer a simple number of tests, but if the count is given as a range - such as 1..10, accept that too for compatibility with Perl's - Test::Harness. */ + /* + * Prefer a simple number of tests, but if the count is given as a range + * such as 1..10, accept that too for compatibility with Perl's + * Test::Harness. + */ while (isspace((unsigned char)(*line))) line++; if (strncmp(line, "1..", 3) == 0) @@ -236,9 +256,11 @@ test_init(const char *line, struct testset *ts) } -/* 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. */ +/* + * 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) { @@ -278,7 +300,9 @@ test_start(const char *path, int *fd) } -/* Back up over the output saying what test we were executing. */ +/* + * Back up over the output saying what test we were executing. + */ static void test_backspace(struct testset *ts) { @@ -296,18 +320,22 @@ test_backspace(struct testset *ts) } -/* Given a single line of output from a test, parse it and return the - success status of that test. Anything printed to stdout not matching the - form /^(not )?ok \d+/ is ignored. Sets ts->current to the test number - that just reported status. */ +/* + * Given a single line of output from a test, parse it and return the success + * status of that test. Anything printed to stdout not matching the form + * /^(not )?ok \d+/ is ignored. Sets ts->current to the test number that just + * reported status. + */ static void test_checkline(const char *line, struct testset *ts) { enum test_status status = TEST_PASS; int current; - /* If the given line isn't newline-terminated, it was too big for an - fgets(), which means ignore it. */ + /* + * If the given line isn't newline-terminated, it was too big for an + * fgets(), which means ignore it. + */ if (line[strlen(line) - 1] != '\n') return; @@ -369,11 +397,13 @@ test_checkline(const char *line, struct testset *ts) } -/* Print out a range of test numbers, returning the number of characters it - took up. Add a comma and a space before the range if chars indicates - that something has already been printed on the line, and print - ... instead if chars plus the space needed would go over the limit (use a - limit of 0 to disable this. */ +/* + * Print out a range of test numbers, returning the number of characters it + * took up. Add a comma and a space before the range if chars indicates that + * something has already been printed on the line, and print ... instead if + * chars plus the space needed would go over the limit (use a limit of 0 to + * disable this. + */ static int test_print_range(int first, int last, int chars, int limit) { @@ -404,10 +434,12 @@ test_print_range(int first, int last, int chars, int limit) } -/* Summarize a single test set. The second argument is 0 if the set exited - cleanly, a positive integer representing the exit status if it exited - with a non-zero status, and a negative integer representing the signal - that terminated it if it was killed by a signal. */ +/* + * Summarize a single test set. The second argument is 0 if the set exited + * cleanly, a positive integer representing the exit status if it exited + * with a non-zero status, and a negative integer representing the signal + * that terminated it if it was killed by a signal. + */ static void test_summarize(struct testset *ts, int status) { @@ -479,9 +511,11 @@ test_summarize(struct testset *ts, int status) } -/* Given a test set, analyze the results, classify the exit status, handle a - few special error messages, and then pass it along to test_summarize() - for the regular output. */ +/* + * Given a test set, analyze the results, classify the exit status, handle a + * few special error messages, and then pass it along to test_summarize() + * for the regular output. + */ static int test_analyze(struct testset *ts) { @@ -516,9 +550,11 @@ test_analyze(struct testset *ts) } -/* Runs a single test set, accumulating and then reporting the results. - Returns true if the test set was successfully run and all tests passed, - false otherwise. */ +/* + * Runs a single test set, accumulating and then reporting the results. + * Returns true if the test set was successfully run and all tests passed, + * false otherwise. + */ static int test_run(struct testset *ts) { @@ -528,8 +564,10 @@ test_run(struct testset *ts) char buffer[BUFSIZ]; char *file; - /* Initialize the test and our data structures, flagging this set in - error if the initialization fails. */ + /* + * Initialize the test and our data structures, flagging this set in error + * if the initialization fails. + */ file = xmalloc(strlen(ts->file) + 3); strcpy(file, ts->file); strcat(file, "-t"); @@ -556,8 +594,10 @@ test_run(struct testset *ts) ts->aborted = 1; test_backspace(ts); - /* Close the output descriptor, retrieve the exit status, and pass that - information to test_analyze() for eventual output. */ + /* + * Close the output descriptor, retrieve the exit status, and pass that + * information to test_analyze() for eventual output. + */ fclose(output); child = waitpid(testpid, &ts->status, 0); if (child == (pid_t) -1) { @@ -626,9 +666,11 @@ test_fail_summary(const struct testlist *fails) } -/* Run a batch of tests from a given file listing each test on a line by - itself. The file must be rewindable. Returns true iff all tests - passed. */ +/* + * Run a batch of tests from a given file listing each test on a line by + * itself. The file must be rewindable. Returns true iff all tests + * passed. + */ static int test_batch(const char *testlist) { @@ -648,8 +690,10 @@ test_batch(const char *testlist) int failed = 0; int aborted = 0; - /* Open our file of tests to run and scan it, checking for lines that - are too long and searching for the longest line. */ + /* + * Open our file of tests to run and scan it, checking for lines that + * are too long and searching for the longest line. + */ tests = fopen(testlist, "r"); if (!tests) sysdie("can't open %s", testlist); @@ -667,8 +711,10 @@ test_batch(const char *testlist) if (fseek(tests, 0, SEEK_SET) == -1) sysdie("can't rewind %s", testlist); - /* Add two to longest and round up to the nearest tab stop. This is how - wide the column for printing the current test name will be. */ + /* + * Add two to longest and round up to the nearest tab stop. This is how + * wide the column for printing the current test name will be. + */ longest += 2; if (longest % 8) longest += 8 - (longest % 8); @@ -676,8 +722,10 @@ test_batch(const char *testlist) /* Start the wall clock timer. */ gettimeofday(&start, NULL); - /* Now, plow through our tests again, running each one. Check line - length again out of paranoia. */ + /* + * Now, plow through our tests again, running each one. Check line + * length again out of paranoia. + */ line = 0; while (fgets(buffer, sizeof(buffer), tests)) { line++; @@ -690,6 +738,8 @@ test_batch(const char *testlist) fputs(buffer, stdout); for (i = length; i < longest; i++) putchar('.'); + if (isatty(STDOUT_FILENO)) + fflush(stdout); memset(&ts, 0, sizeof(ts)); ts.file = xstrdup(buffer); if (!test_run(&ts)) { @@ -750,7 +800,9 @@ test_batch(const char *testlist) } -/* Main routine. Given a file listing tests, run each test listed. */ +/* + * Main routine. Given a file listing tests, run each test listed. + */ int main(int argc, char *argv[]) { 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; |