diff options
author | ngie <ngie@FreeBSD.org> | 2014-12-21 08:30:18 +0000 |
---|---|---|
committer | ngie <ngie@FreeBSD.org> | 2014-12-21 08:30:18 +0000 |
commit | dc3ad5131fa6525673d58aa537f9d67ba69edb94 (patch) | |
tree | 1473124a62111de8a694012ddb628f25f249137d /contrib/atf/atf-c | |
parent | 1a3934911c5c7b282bc36336bafe16e321f63922 (diff) | |
download | FreeBSD-src-dc3ad5131fa6525673d58aa537f9d67ba69edb94.zip FreeBSD-src-dc3ad5131fa6525673d58aa537f9d67ba69edb94.tar.gz |
MFC r273929:
r273929 (by jmmv):
MFV: Import atf-0.21.
Diffstat (limited to 'contrib/atf/atf-c')
64 files changed, 1282 insertions, 996 deletions
diff --git a/contrib/atf/atf-c/Kyuafile b/contrib/atf/atf-c/Kyuafile index 2f3b82e..40fdb92 100644 --- a/contrib/atf/atf-c/Kyuafile +++ b/contrib/atf/atf-c/Kyuafile @@ -5,7 +5,6 @@ test_suite("atf") atf_test_program{name="atf_c_test"} atf_test_program{name="build_test"} atf_test_program{name="check_test"} -atf_test_program{name="config_test"} atf_test_program{name="error_test"} atf_test_program{name="macros_test"} atf_test_program{name="pkg_config_test"} diff --git a/contrib/atf/atf-c/atf-c.3 b/contrib/atf/atf-c/atf-c.3 new file mode 100644 index 0000000..edb7207 --- /dev/null +++ b/contrib/atf/atf-c/atf-c.3 @@ -0,0 +1,793 @@ +.\" Copyright (c) 2008 The NetBSD Foundation, Inc. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND +.\" CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, +.\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +.\" IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY +.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +.\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +.\" IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +.Dd October 13, 2014 +.Dt ATF-C 3 +.Os +.Sh NAME +.Nm atf-c , +.Nm ATF_CHECK , +.Nm ATF_CHECK_MSG , +.Nm ATF_CHECK_EQ , +.Nm ATF_CHECK_EQ_MSG , +.Nm ATF_CHECK_MATCH , +.Nm ATF_CHECK_MATCH_MSG , +.Nm ATF_CHECK_STREQ , +.Nm ATF_CHECK_STREQ_MSG , +.Nm ATF_CHECK_ERRNO , +.Nm ATF_REQUIRE , +.Nm ATF_REQUIRE_MSG , +.Nm ATF_REQUIRE_EQ , +.Nm ATF_REQUIRE_EQ_MSG , +.Nm ATF_REQUIRE_MATCH , +.Nm ATF_REQUIRE_MATCH_MSG , +.Nm ATF_REQUIRE_STREQ , +.Nm ATF_REQUIRE_STREQ_MSG , +.Nm ATF_REQUIRE_ERRNO , +.Nm ATF_TC , +.Nm ATF_TC_BODY , +.Nm ATF_TC_BODY_NAME , +.Nm ATF_TC_CLEANUP , +.Nm ATF_TC_CLEANUP_NAME , +.Nm ATF_TC_HEAD , +.Nm ATF_TC_HEAD_NAME , +.Nm ATF_TC_NAME , +.Nm ATF_TC_WITH_CLEANUP , +.Nm ATF_TC_WITHOUT_HEAD , +.Nm ATF_TP_ADD_TC , +.Nm ATF_TP_ADD_TCS , +.Nm atf_tc_get_config_var , +.Nm atf_tc_get_config_var_wd , +.Nm atf_tc_get_config_var_as_bool , +.Nm atf_tc_get_config_var_as_bool_wd , +.Nm atf_tc_get_config_var_as_long , +.Nm atf_tc_get_config_var_as_long_wd , +.Nm atf_no_error , +.Nm atf_tc_expect_death , +.Nm atf_tc_expect_exit , +.Nm atf_tc_expect_fail , +.Nm atf_tc_expect_pass , +.Nm atf_tc_expect_signal , +.Nm atf_tc_expect_timeout , +.Nm atf_tc_fail , +.Nm atf_tc_fail_nonfatal , +.Nm atf_tc_pass , +.Nm atf_tc_skip , +.Nm atf_utils_cat_file , +.Nm atf_utils_compare_file , +.Nm atf_utils_copy_file , +.Nm atf_utils_create_file , +.Nm atf_utils_file_exists , +.Nm atf_utils_fork , +.Nm atf_utils_free_charpp , +.Nm atf_utils_grep_file , +.Nm atf_utils_grep_string , +.Nm atf_utils_readline , +.Nm atf_utils_redirect , +.Nm atf_utils_wait +.Nd C API to write ATF-based test programs +.Sh SYNOPSIS +.In atf-c.h +.\" NO_CHECK_STYLE_BEGIN +.Fn ATF_CHECK "expression" +.Fn ATF_CHECK_MSG "expression" "fail_msg_fmt" ... +.Fn ATF_CHECK_EQ "expected_expression" "actual_expression" +.Fn ATF_CHECK_EQ_MSG "expected_expression" "actual_expression" "fail_msg_fmt" ... +.Fn ATF_CHECK_MATCH "regexp" "string" +.Fn ATF_CHECK_MATCH_MSG "regexp" "string" "fail_msg_fmt" ... +.Fn ATF_CHECK_STREQ "string_1" "string_2" +.Fn ATF_CHECK_STREQ_MSG "string_1" "string_2" "fail_msg_fmt" ... +.Fn ATF_CHECK_ERRNO "expected_errno" "bool_expression" +.Fn ATF_REQUIRE "expression" +.Fn ATF_REQUIRE_MSG "expression" "fail_msg_fmt" ... +.Fn ATF_REQUIRE_EQ "expected_expression" "actual_expression" +.Fn ATF_REQUIRE_EQ_MSG "expected_expression" "actual_expression" "fail_msg_fmt" ... +.Fn ATF_REQUIRE_MATCH "regexp" "string" +.Fn ATF_REQUIRE_MATCH_MSG "regexp" "string" "fail_msg_fmt" ... +.Fn ATF_REQUIRE_STREQ "expected_string" "actual_string" +.Fn ATF_REQUIRE_STREQ_MSG "expected_string" "actual_string" "fail_msg_fmt" ... +.Fn ATF_REQUIRE_ERRNO "expected_errno" "bool_expression" +.\" NO_CHECK_STYLE_END +.Fn ATF_TC "name" +.Fn ATF_TC_BODY "name" "tc" +.Fn ATF_TC_BODY_NAME "name" +.Fn ATF_TC_CLEANUP "name" "tc" +.Fn ATF_TC_CLEANUP_NAME "name" +.Fn ATF_TC_HEAD "name" "tc" +.Fn ATF_TC_HEAD_NAME "name" +.Fn ATF_TC_NAME "name" +.Fn ATF_TC_WITH_CLEANUP "name" +.Fn ATF_TC_WITHOUT_HEAD "name" +.Fn ATF_TP_ADD_TC "tp_name" "tc_name" +.Fn ATF_TP_ADD_TCS "tp_name" +.Fn atf_tc_get_config_var "tc" "varname" +.Fn atf_tc_get_config_var_wd "tc" "variable_name" "default_value" +.Fn atf_tc_get_config_var_as_bool "tc" "variable_name" +.Fn atf_tc_get_config_var_as_bool_wd "tc" "variable_name" "default_value" +.Fn atf_tc_get_config_var_as_long "tc" "variable_name" +.Fn atf_tc_get_config_var_as_long_wd "tc" "variable_name" "default_value" +.Fn atf_no_error +.Fn atf_tc_expect_death "reason" "..." +.Fn atf_tc_expect_exit "exitcode" "reason" "..." +.Fn atf_tc_expect_fail "reason" "..." +.Fn atf_tc_expect_pass +.Fn atf_tc_expect_signal "signo" "reason" "..." +.Fn atf_tc_expect_timeout "reason" "..." +.Fn atf_tc_fail "reason" +.Fn atf_tc_fail_nonfatal "reason" +.Fn atf_tc_pass +.Fn atf_tc_skip "reason" +.Ft void +.Fo atf_utils_cat_file +.Fa "const char *file" +.Fa "const char *prefix" +.Fc +.Ft bool +.Fo atf_utils_compare_file +.Fa "const char *file" +.Fa "const char *contents" +.Fc +.Ft void +.Fo atf_utils_copy_file +.Fa "const char *source" +.Fa "const char *destination" +.Fc +.Ft void +.Fo atf_utils_create_file +.Fa "const char *file" +.Fa "const char *contents" +.Fa "..." +.Fc +.Ft void +.Fo atf_utils_file_exists +.Fa "const char *file" +.Fc +.Ft pid_t +.Fo atf_utils_fork +.Fa "void" +.Fc +.Ft void +.Fo atf_utils_free_charpp +.Fa "char **argv" +.Fc +.Ft bool +.Fo atf_utils_grep_file +.Fa "const char *regexp" +.Fa "const char *file" +.Fa "..." +.Fc +.Ft bool +.Fo atf_utils_grep_string +.Fa "const char *regexp" +.Fa "const char *str" +.Fa "..." +.Fc +.Ft char * +.Fo atf_utils_readline +.Fa "int fd" +.Fc +.Ft void +.Fo atf_utils_redirect +.Fa "const int fd" +.Fa "const char *file" +.Fc +.Ft void +.Fo atf_utils_wait +.Fa "const pid_t pid" +.Fa "const int expected_exit_status" +.Fa "const char *expected_stdout" +.Fa "const char *expected_stderr" +.Fc +.Sh DESCRIPTION +ATF provides a C programming interface to implement test programs. +C-based test programs follow this template: +.Bd -literal -offset indent +.Ns ... C-specific includes go here ... + +#include <atf-c.h> + +ATF_TC(tc1); +ATF_TC_HEAD(tc1, tc) +{ + ... first test case's header ... +} +ATF_TC_BODY(tc1, tc) +{ + ... first test case's body ... +} + +ATF_TC_WITH_CLEANUP(tc2); +ATF_TC_HEAD(tc2, tc) +{ + ... second test case's header ... +} +ATF_TC_BODY(tc2, tc) +{ + ... second test case's body ... +} +ATF_TC_CLEANUP(tc2, tc) +{ + ... second test case's cleanup ... +} + +ATF_TC_WITHOUT_HEAD(tc3); +ATF_TC_BODY(tc3, tc) +{ + ... third test case's body ... +} + +.Ns ... additional test cases ... + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tcs, tc1); + ATF_TP_ADD_TC(tcs, tc2); + ATF_TP_ADD_TC(tcs, tc3); + ... add additional test cases ... + + return atf_no_error(); +} +.Ed +.Ss Definition of test cases +Test cases have an identifier and are composed of three different parts: +the header, the body and an optional cleanup routine, all of which are +described in +.Xr atf-test-case 4 . +To define test cases, one can use the +.Fn ATF_TC , +.Fn ATF_TC_WITH_CLEANUP +or the +.Fn ATF_TC_WITHOUT_HEAD +macros, which take a single parameter specifiying the test case's name. +.Fn ATF_TC , +requires to define a head and a body for the test case, +.Fn ATF_TC_WITH_CLEANUP +requires to define a head, a body and a cleanup for the test case and +.Fn ATF_TC_WITHOUT_HEAD +requires only a body for the test case. +It is important to note that these +.Em do not +set the test case up for execution when the program is run. +In order to do so, a later registration is needed with the +.Fn ATF_TP_ADD_TC +macro detailed in +.Sx Program initialization . +.Pp +Later on, one must define the three parts of the body by means of three +functions. +Their headers are given by the +.Fn ATF_TC_HEAD , +.Fn ATF_TC_BODY +and +.Fn ATF_TC_CLEANUP +macros, all of which take the test case name provided to the +.Fn ATF_TC +.Fn ATF_TC_WITH_CLEANUP , +or +.Fn ATF_TC_WITHOUT_HEAD +macros and the name of the variable that will hold a pointer to the +test case data. +Following each of these, a block of code is expected, surrounded by the +opening and closing brackets. +.Ss Program initialization +The library provides a way to easily define the test program's +.Fn main +function. +You should never define one on your own, but rely on the +library to do it for you. +This is done by using the +.Fn ATF_TP_ADD_TCS +macro, which is passed the name of the object that will hold the test +cases; i.e. the test program instance. +This name can be whatever you want as long as it is a valid variable +identifier. +.Pp +After the macro, you are supposed to provide the body of a function, which +should only use the +.Fn ATF_TP_ADD_TC +macro to register the test cases the test program will execute and return +a success error code. +The first parameter of this macro matches the name you provided in the +former call. +The success status can be returned using the +.Fn atf_no_error +function. +.Ss Header definitions +The test case's header can define the meta-data by using the +.Fn atf_tc_set_md_var +method, which takes three parameters: the first one points to the test +case data, the second one specifies the meta-data variable to be set +and the third one specifies its value. +Both of them are strings. +.Ss Configuration variables +The test case has read-only access to the current configuration variables +by means of the +.Ft bool +.Fn atf_tc_has_config_var , +.Ft const char * +.Fn atf_tc_get_config_var , +.Ft const char * +.Fn atf_tc_get_config_var_wd , +.Ft bool +.Fn atf_tc_get_config_var_as_bool , +.Ft bool +.Fn atf_tc_get_config_var_as_bool_wd , +.Ft long +.Fn atf_tc_get_config_var_as_long , +and the +.Ft long +.Fn atf_tc_get_config_var_as_long_wd +functions, which can be called in any of the three parts of a test case. +.Pp +The +.Sq _wd +variants take a default value for the variable which is returned if the +variable is not defined. +The other functions without the +.Sq _wd +suffix +.Em require +the variable to be defined. +.Ss Access to the source directory +It is possible to get the path to the test case's source directory from any +of its three components by querying the +.Sq srcdir +configuration variable. +.Ss Requiring programs +Aside from the +.Va require.progs +meta-data variable available in the header only, one can also check for +additional programs in the test case's body by using the +.Fn atf_tc_require_prog +function, which takes the base name or full path of a single binary. +Relative paths are forbidden. +If it is not found, the test case will be automatically skipped. +.Ss Test case finalization +The test case finalizes either when the body reaches its end, at which +point the test is assumed to have +.Em passed , +unless any non-fatal errors were raised using +.Fn atf_tc_fail_nonfatal , +or at any explicit call to +.Fn atf_tc_pass , +.Fn atf_tc_fail +or +.Fn atf_tc_skip . +These three functions terminate the execution of the test case immediately. +The cleanup routine will be processed afterwards in a completely automated +way, regardless of the test case's termination reason. +.Pp +.Fn atf_tc_pass +does not take any parameters. +.Fn atf_tc_fail , +.Fn atf_tc_fail_nonfatal +and +.Fn atf_tc_skip +take a format string and a variable list of parameters, which describe, in +a user-friendly manner, why the test case failed or was skipped, +respectively. +It is very important to provide a clear error message in both cases so that +the user can quickly know why the test did not pass. +.Ss Expectations +Everything explained in the previous section changes when the test case +expectations are redefined by the programmer. +.Pp +Each test case has an internal state called +.Sq expect +that describes what the test case expectations are at any point in time. +The value of this property can change during execution by any of: +.Bl -tag -width indent +.It Fn atf_tc_expect_death "reason" "..." +Expects the test case to exit prematurely regardless of the nature of the +exit. +.It Fn atf_tc_expect_exit "exitcode" "reason" "..." +Expects the test case to exit cleanly. +If +.Va exitcode +is not +.Sq -1 , +the runtime engine will validate that the exit code of the test case +matches the one provided in this call. +Otherwise, the exact value will be ignored. +.It Fn atf_tc_expect_fail "reason" "..." +Any failure (be it fatal or non-fatal) raised in this mode is recorded. +However, such failures do not report the test case as failed; instead, the +test case finalizes cleanly and is reported as +.Sq expected failure ; +this report includes the provided +.Fa reason +as part of it. +If no error is raised while running in this mode, then the test case is +reported as +.Sq failed . +.Pp +This mode is useful to reproduce actual known bugs in tests. +Whenever the developer fixes the bug later on, the test case will start +reporting a failure, signaling the developer that the test case must be +adjusted to the new conditions. +In this situation, it is useful, for example, to set +.Fa reason +as the bug number for tracking purposes. +.It Fn atf_tc_expect_pass +This is the normal mode of execution. +In this mode, any failure is reported as such to the user and the test case +is marked as +.Sq failed . +.It Fn atf_tc_expect_signal "signo" "reason" "..." +Expects the test case to terminate due to the reception of a signal. +If +.Va signo +is not +.Sq -1 , +the runtime engine will validate that the signal that terminated the test +case matches the one provided in this call. +Otherwise, the exact value will be ignored. +.It Fn atf_tc_expect_timeout "reason" "..." +Expects the test case to execute for longer than its timeout. +.El +.Ss Helper macros for common checks +The library provides several macros that are very handy in multiple +situations. +These basically check some condition after executing a given statement or +processing a given expression and, if the condition is not met, they +report the test case as failed. +.Pp +The +.Sq REQUIRE +variant of the macros immediately abort the test case as soon as an error +condition is detected by calling the +.Fn atf_tc_fail +function. +Use this variant whenever it makes no sense to continue the execution of a +test case when the checked condition is not met. +The +.Sq CHECK +variant, on the other hand, reports a failure as soon as it is encountered +using the +.Fn atf_tc_fail_nonfatal +function, but the execution of the test case continues as if nothing had +happened. +Use this variant whenever the checked condition is important as a result of +the test case, but there are other conditions that can be subsequently +checked on the same run without aborting. +.Pp +Additionally, the +.Sq MSG +variants take an extra set of parameters to explicitly specify the failure +message. +This failure message is formatted according to the +.Xr printf 3 +formatters. +.Pp +.Fn ATF_CHECK , +.Fn ATF_CHECK_MSG , +.Fn ATF_REQUIRE +and +.Fn ATF_REQUIRE_MSG +take an expression and fail if the expression evaluates to false. +.Pp +.Fn ATF_CHECK_EQ , +.Fn ATF_CHECK_EQ_MSG , +.Fn ATF_REQUIRE_EQ +and +.Fn ATF_REQUIRE_EQ_MSG +take two expressions and fail if the two evaluated values are not equal. +The common style is to put the expected value in the first parameter and the +actual value in the second parameter. +.Pp +.Fn ATF_CHECK_MATCH , +.Fn ATF_CHECK_MATCH_MSG , +.Fn ATF_REQUIRE_MATCH +and +.Fn ATF_REQUIRE_MATCH_MSG +take a regular expression and a string and fail if the regular expression does +not match the given string. +Note that the regular expression is not anchored, so it will match anywhere in +the string. +.Pp +.Fn ATF_CHECK_STREQ , +.Fn ATF_CHECK_STREQ_MSG , +.Fn ATF_REQUIRE_STREQ +and +.Fn ATF_REQUIRE_STREQ_MSG +take two strings and fail if the two are not equal character by character. +The common style is to put the expected string in the first parameter and the +actual string in the second parameter. +.Pp +.Fn ATF_CHECK_ERRNO +and +.Fn ATF_REQUIRE_ERRNO +take, first, the error code that the check is expecting to find in the +.Va errno +variable and, second, a boolean expression that, if evaluates to true, +means that a call failed and +.Va errno +has to be checked against the first value. +.Ss Utility functions +The following functions are provided as part of the +.Nm +API to simplify the creation of a variety of tests. +In particular, these are useful to write tests for command-line interfaces. +.Pp +.Ft void +.Fo atf_utils_cat_file +.Fa "const char *file" +.Fa "const char *prefix" +.Fc +.Bd -ragged -offset indent +Prints the contents of +.Fa file +to the standard output, prefixing every line with the string in +.Fa prefix . +.Ed +.Pp +.Ft bool +.Fo atf_utils_compare_file +.Fa "const char *file" +.Fa "const char *contents" +.Fc +.Bd -ragged -offset indent +Returns true if the given +.Fa file +matches exactly the expected inlined +.Fa contents . +.Ed +.Pp +.Ft void +.Fo atf_utils_copy_file +.Fa "const char *source" +.Fa "const char *destination" +.Fc +.Bd -ragged -offset indent +Copies the file +.Fa source +to +.Fa destination . +The permissions of the file are preserved during the code. +.Ed +.Pp +.Ft void +.Fo atf_utils_create_file +.Fa "const char *file" +.Fa "const char *contents" +.Fa "..." +.Fc +.Bd -ragged -offset indent +Creates +.Fa file +with the text given in +.Fa contents , +which is a formatting string that uses the rest of the variable arguments. +.Ed +.Pp +.Ft void +.Fo atf_utils_file_exists +.Fa "const char *file" +.Fc +.Bd -ragged -offset indent +Checks if +.Fa file +exists. +.Ed +.Pp +.Ft pid_t +.Fo atf_utils_fork +.Fa "void" +.Fc +.Bd -ragged -offset indent +Forks a process and redirects the standard output and standard error of the +child to files for later validation with +.Fn atf_utils_wait . +Fails the test case if the fork fails, so this does not return an error. +.Ed +.Pp +.Ft void +.Fo atf_utils_free_charpp +.Fa "char **argv" +.Fc +.Bd -ragged -offset indent +Frees a dynamically-allocated array of dynamically-allocated strings. +.Ed +.Pp +.Ft bool +.Fo atf_utils_grep_file +.Fa "const char *regexp" +.Fa "const char *file" +.Fa "..." +.Fc +.Bd -ragged -offset indent +Searches for the +.Fa regexp , +which is a formatting string representing the regular expression, +in the +.Fa file . +The variable arguments are used to construct the regular expression. +.Ed +.Pp +.Ft bool +.Fo atf_utils_grep_string +.Fa "const char *regexp" +.Fa "const char *str" +.Fa "..." +.Fc +.Bd -ragged -offset indent +Searches for the +.Fa regexp , +which is a formatting string representing the regular expression, +in the literal string +.Fa str . +The variable arguments are used to construct the regular expression. +.Ed +.Pp +.Ft char * +.Fo atf_utils_readline +.Fa "int fd" +.Fc +.Bd -ragged -offset indent +Reads a line from the file descriptor +.Fa fd . +The line, if any, is returned as a dynamically-allocated buffer that must be +released with +.Xr free 3 . +If there was nothing to read, returns +.Sq NULL . +.Ed +.Pp +.Ft void +.Fo atf_utils_redirect +.Fa "const int fd" +.Fa "const char *file" +.Fc +.Bd -ragged -offset indent +Redirects the given file descriptor +.Fa fd +to +.Fa file . +This function exits the process in case of an error and does not properly mark +the test case as failed. +As a result, it should only be used in subprocesses of the test case; specially +those spawned by +.Fn atf_utils_fork . +.Ed +.Pp +.Ft void +.Fo atf_utils_wait +.Fa "const pid_t pid" +.Fa "const int expected_exit_status" +.Fa "const char *expected_stdout" +.Fa "const char *expected_stderr" +.Fc +.Bd -ragged -offset indent +Waits and validates the result of a subprocess spawned with +.Fn atf_utils_wait . +The validation involves checking that the subprocess exited cleanly and returned +the code specified in +.Fa expected_exit_status +and that its standard output and standard error match the strings given in +.Fa expected_stdout +and +.Fa expected_stderr . +.Pp +If any of the +.Fa expected_stdout +or +.Fa expected_stderr +strings are prefixed with +.Sq save: , +then they specify the name of the file into which to store the stdout or stderr +of the subprocess, and no comparison is performed. +.Ed +.Sh ENVIRONMENT +The following variables are recognized by +.Nm +but should not be overridden other than for testing purposes: +.Pp +.Bl -tag -width ATFXBUILDXCXXFLAGSXX -compact +.It Va ATF_BUILD_CC +Path to the C compiler. +.It Va ATF_BUILD_CFLAGS +C compiler flags. +.It Va ATF_BUILD_CPP +Path to the C/C++ preprocessor. +.It Va ATF_BUILD_CPPFLAGS +C/C++ preprocessor flags. +.It Va ATF_BUILD_CXX +Path to the C++ compiler. +.It Va ATF_BUILD_CXXFLAGS +C++ compiler flags. +.El +.Sh EXAMPLES +The following shows a complete test program with a single test case that +validates the addition operator: +.Bd -literal -offset indent +#include <atf-c.h> + +ATF_TC(addition); +ATF_TC_HEAD(addition, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Sample tests for the addition operator"); +} +ATF_TC_BODY(addition, tc) +{ + ATF_CHECK_EQ(0, 0 + 0); + ATF_CHECK_EQ(1, 0 + 1); + ATF_CHECK_EQ(1, 1 + 0); + + ATF_CHECK_EQ(2, 1 + 1); + + ATF_CHECK_EQ(300, 100 + 200); +} + +ATF_TC(string_formatting); +ATF_TC_HEAD(string_formatting, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Sample tests for the snprintf"); +} +ATF_TC_BODY(string_formatting, tc) +{ + char buf[1024]; + snprintf(buf, sizeof(buf), "a %s", "string"); + ATF_CHECK_STREQ_MSG("a string", buf, "%s is not working"); +} + +ATF_TC(open_failure); +ATF_TC_HEAD(open_failure, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Sample tests for the open function"); +} +ATF_TC_BODY(open_failure, tc) +{ + ATF_CHECK_ERRNO(ENOENT, open("non-existent", O_RDONLY) == -1); +} + +ATF_TC(known_bug); +ATF_TC_HEAD(known_bug, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Reproduces a known bug"); +} +ATF_TC_BODY(known_bug, tc) +{ + atf_tc_expect_fail("See bug number foo/bar"); + ATF_CHECK_EQ(3, 1 + 1); + atf_tc_expect_pass(); + ATF_CHECK_EQ(3, 1 + 2); +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, addition); + ATF_TP_ADD_TC(tp, string_formatting); + ATF_TP_ADD_TC(tp, open_failure); + ATF_TP_ADD_TC(tp, known_bug); + + return atf_no_error(); +} +.Ed +.Sh SEE ALSO +.Xr atf-test-program 1 , +.Xr atf-test-case 4 diff --git a/contrib/atf/atf-c/atf_c_test.c b/contrib/atf/atf-c/atf_c_test.c index f44d87f..eda9596 100644 --- a/contrib/atf/atf-c/atf_c_test.c +++ b/contrib/atf/atf-c/atf_c_test.c @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2008 The NetBSD Foundation, Inc. +/* Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,12 +21,11 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include <atf-c.h> -#include "detail/test_helpers.h" +#include "atf-c/detail/test_helpers.h" /* --------------------------------------------------------------------- * Tests cases for the header file. diff --git a/contrib/atf/atf-c/build.c b/contrib/atf/atf-c/build.c index 2483303..c119fc9 100644 --- a/contrib/atf/atf-c/build.c +++ b/contrib/atf/atf-c/build.c @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2009 The NetBSD Foundation, Inc. +/* Copyright (c) 2009 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,31 +21,31 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +#include "atf-c/build.h" #include <stdlib.h> #include <string.h> -#include "atf-c/build.h" -#include "atf-c/config.h" +#include "atf-c/detail/env.h" +#include "atf-c/detail/sanity.h" +#include "atf-c/detail/text.h" #include "atf-c/error.h" -#include "detail/sanity.h" -#include "detail/text.h" - /* --------------------------------------------------------------------- * Auxiliary functions. * --------------------------------------------------------------------- */ static atf_error_t -append_config_var(const char *var, atf_list_t *argv) +append_config_var(const char *var, const char *default_value, atf_list_t *argv) { atf_error_t err; atf_list_t words; - err = atf_text_split(atf_config_get(var), " ", &words); + err = atf_text_split(atf_env_get_with_default(var, default_value), + " ", &words); if (atf_is_error(err)) goto out; @@ -158,15 +155,16 @@ atf_build_c_o(const char *sfile, if (atf_is_error(err)) goto out; - err = append_config_var("atf_build_cc", &argv_list); + err = append_config_var("ATF_BUILD_CC", ATF_BUILD_CC, &argv_list); if (atf_is_error(err)) goto out_list; - err = append_config_var("atf_build_cppflags", &argv_list); + err = append_config_var("ATF_BUILD_CPPFLAGS", ATF_BUILD_CPPFLAGS, + &argv_list); if (atf_is_error(err)) goto out_list; - err = append_config_var("atf_build_cflags", &argv_list); + err = append_config_var("ATF_BUILD_CFLAGS", ATF_BUILD_CFLAGS, &argv_list); if (atf_is_error(err)) goto out_list; @@ -203,11 +201,12 @@ atf_build_cpp(const char *sfile, if (atf_is_error(err)) goto out; - err = append_config_var("atf_build_cpp", &argv_list); + err = append_config_var("ATF_BUILD_CPP", ATF_BUILD_CPP, &argv_list); if (atf_is_error(err)) goto out_list; - err = append_config_var("atf_build_cppflags", &argv_list); + err = append_config_var("ATF_BUILD_CPPFLAGS", ATF_BUILD_CPPFLAGS, + &argv_list); if (atf_is_error(err)) goto out_list; @@ -248,15 +247,17 @@ atf_build_cxx_o(const char *sfile, if (atf_is_error(err)) goto out; - err = append_config_var("atf_build_cxx", &argv_list); + err = append_config_var("ATF_BUILD_CXX", ATF_BUILD_CXX, &argv_list); if (atf_is_error(err)) goto out_list; - err = append_config_var("atf_build_cppflags", &argv_list); + err = append_config_var("ATF_BUILD_CPPFLAGS", ATF_BUILD_CPPFLAGS, + &argv_list); if (atf_is_error(err)) goto out_list; - err = append_config_var("atf_build_cxxflags", &argv_list); + err = append_config_var("ATF_BUILD_CXXFLAGS", ATF_BUILD_CXXFLAGS, + &argv_list); if (atf_is_error(err)) goto out_list; diff --git a/contrib/atf/atf-c/build.h b/contrib/atf/atf-c/build.h index 2e981cf..a263f50 100644 --- a/contrib/atf/atf-c/build.h +++ b/contrib/atf/atf-c/build.h @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2009 The NetBSD Foundation, Inc. +/* Copyright (c) 2009 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,8 +21,7 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #if !defined(ATF_C_BUILD_H) #define ATF_C_BUILD_H @@ -39,4 +35,4 @@ atf_error_t atf_build_cpp(const char *, const char *, const char *const [], atf_error_t atf_build_cxx_o(const char *, const char *, const char *const [], char ***); -#endif /* ATF_C_BUILD_H */ +#endif /* !defined(ATF_C_BUILD_H) */ diff --git a/contrib/atf/atf-c/build_test.c b/contrib/atf/atf-c/build_test.c index b08c9a5..c24b573 100644 --- a/contrib/atf/atf-c/build_test.c +++ b/contrib/atf/atf-c/build_test.c @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2009 The NetBSD Foundation, Inc. +/* Copyright (c) 2009 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,8 +21,9 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +#include "atf-c/build.h" #include <stdio.h> #include <stdlib.h> @@ -33,20 +31,15 @@ #include <atf-c.h> -#include "atf-c/build.h" -#include "atf-c/config.h" +#include "atf-c/detail/env.h" +#include "atf-c/detail/test_helpers.h" +#include "atf-c/h_build.h" #include "atf-c/utils.h" -#include "detail/env.h" -#include "detail/test_helpers.h" -#include "h_build.h" - /* --------------------------------------------------------------------- * Auxiliary functions. * --------------------------------------------------------------------- */ -void __atf_config_reinit(void); - static bool equal_arrays(const char *const *exp_array, char **actual_array) @@ -167,7 +160,6 @@ ATF_TC_BODY(c_o, tc) verbose_set_env("ATF_BUILD_CC", test->cc); verbose_set_env("ATF_BUILD_CFLAGS", test->cflags); verbose_set_env("ATF_BUILD_CPPFLAGS", test->cppflags); - __atf_config_reinit(); { char **argv; @@ -196,7 +188,6 @@ ATF_TC_BODY(cpp, tc) verbose_set_env("ATF_BUILD_CPP", test->cpp); verbose_set_env("ATF_BUILD_CPPFLAGS", test->cppflags); - __atf_config_reinit(); { char **argv; @@ -226,7 +217,6 @@ ATF_TC_BODY(cxx_o, tc) verbose_set_env("ATF_BUILD_CXX", test->cxx); verbose_set_env("ATF_BUILD_CXXFLAGS", test->cxxflags); verbose_set_env("ATF_BUILD_CPPFLAGS", test->cppflags); - __atf_config_reinit(); { char **argv; @@ -242,12 +232,6 @@ ATF_TC_BODY(cxx_o, tc) } /* --------------------------------------------------------------------- - * Tests cases for the header file. - * --------------------------------------------------------------------- */ - -HEADER_TC(include, "atf-c/build.h"); - -/* --------------------------------------------------------------------- * Main. * --------------------------------------------------------------------- */ @@ -261,8 +245,5 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, cpp); ATF_TP_ADD_TC(tp, cxx_o); - /* Add the test cases for the header file. */ - ATF_TP_ADD_TC(tp, include); - return atf_no_error(); } diff --git a/contrib/atf/atf-c/check.c b/contrib/atf/atf-c/check.c index d7a908d..38afdf3 100644 --- a/contrib/atf/atf-c/check.c +++ b/contrib/atf/atf-c/check.c @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2008 The NetBSD Foundation, Inc. +/* Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,8 +21,9 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +#include "atf-c/check.h" #include <sys/wait.h> @@ -37,18 +35,16 @@ #include <unistd.h> #include "atf-c/build.h" -#include "atf-c/check.h" -#include "atf-c/config.h" #include "atf-c/defs.h" +#include "atf-c/detail/dynstr.h" +#include "atf-c/detail/env.h" +#include "atf-c/detail/fs.h" +#include "atf-c/detail/list.h" +#include "atf-c/detail/process.h" +#include "atf-c/detail/sanity.h" #include "atf-c/error.h" #include "atf-c/utils.h" -#include "detail/dynstr.h" -#include "detail/fs.h" -#include "detail/list.h" -#include "detail/process.h" -#include "detail/sanity.h" - /* --------------------------------------------------------------------- * Auxiliary functions. * --------------------------------------------------------------------- */ @@ -60,7 +56,7 @@ create_tmpdir(atf_fs_path_t *dir) atf_error_t err; err = atf_fs_path_init_fmt(dir, "%s/check.XXXXXX", - atf_config_get("atf_workdir")); + atf_env_get_with_default("TMPDIR", "/tmp")); if (atf_is_error(err)) goto out; diff --git a/contrib/atf/atf-c/check.h b/contrib/atf/atf-c/check.h index f36aa3e..1eb2267 100644 --- a/contrib/atf/atf-c/check.h +++ b/contrib/atf/atf-c/check.h @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2008 The NetBSD Foundation, Inc. +/* Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,8 +21,7 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #if !defined(ATF_C_CHECK_H) #define ATF_C_CHECK_H @@ -70,4 +66,4 @@ atf_error_t atf_check_build_cxx_o(const char *, const char *, bool *); atf_error_t atf_check_exec_array(const char *const *, atf_check_result_t *); -#endif /* ATF_C_CHECK_H */ +#endif /* !defined(ATF_C_CHECK_H) */ diff --git a/contrib/atf/atf-c/check_test.c b/contrib/atf/atf-c/check_test.c index a26e032..adaca64 100644 --- a/contrib/atf/atf-c/check_test.c +++ b/contrib/atf/atf-c/check_test.c @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2008 The NetBSD Foundation, Inc. +/* Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,8 +21,9 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +#include "atf-c/check.h" #include <fcntl.h> #include <signal.h> @@ -36,13 +34,10 @@ #include <atf-c.h> -#include "atf-c/check.h" -#include "atf-c/config.h" - -#include "detail/fs.h" -#include "detail/map.h" -#include "detail/process.h" -#include "detail/test_helpers.h" +#include "atf-c/detail/fs.h" +#include "atf-c/detail/map.h" +#include "atf-c/detail/process.h" +#include "atf-c/detail/test_helpers.h" /* --------------------------------------------------------------------- * Auxiliary functions. @@ -494,12 +489,8 @@ ATF_TC_HEAD(exec_unknown, tc) } ATF_TC_BODY(exec_unknown, tc) { - char buf[1024]; - snprintf(buf, sizeof(buf), "%s/non-existent", - atf_config_get("atf_workdir")); - const char *argv[2]; - argv[0] = buf; + argv[0] = "/foo/bar/non-existent"; argv[1] = NULL; atf_check_result_t result; @@ -510,12 +501,6 @@ ATF_TC_BODY(exec_unknown, tc) } /* --------------------------------------------------------------------- - * Tests cases for the header file. - * --------------------------------------------------------------------- */ - -HEADER_TC(include, "atf-c/check.h"); - -/* --------------------------------------------------------------------- * Main. * --------------------------------------------------------------------- */ @@ -532,8 +517,5 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, exec_umask); ATF_TP_ADD_TC(tp, exec_unknown); - /* Add the test cases for the header file. */ - ATF_TP_ADD_TC(tp, include); - return atf_no_error(); } diff --git a/contrib/atf/atf-c/config.c b/contrib/atf/atf-c/config.c deleted file mode 100644 index 3c2c8a9..0000000 --- a/contrib/atf/atf-c/config.c +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2008 The NetBSD Foundation, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND - * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER - * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include <ctype.h> -#include <stdbool.h> -#include <stdlib.h> -#include <string.h> - -#include "atf-c/config.h" - -#include "detail/env.h" -#include "detail/sanity.h" - -static bool initialized = false; - -static struct var { - const char *name; - const char *default_value; - const char *value; - bool can_be_empty; -} vars[] = { - { "atf_build_cc", ATF_BUILD_CC, NULL, false, }, - { "atf_build_cflags", ATF_BUILD_CFLAGS, NULL, true, }, - { "atf_build_cpp", ATF_BUILD_CPP, NULL, false, }, - { "atf_build_cppflags", ATF_BUILD_CPPFLAGS, NULL, true, }, - { "atf_build_cxx", ATF_BUILD_CXX, NULL, false, }, - { "atf_build_cxxflags", ATF_BUILD_CXXFLAGS, NULL, true, }, - { "atf_includedir", ATF_INCLUDEDIR, NULL, false, }, - { "atf_libexecdir", ATF_LIBEXECDIR, NULL, false, }, - { "atf_pkgdatadir", ATF_PKGDATADIR, NULL, false, }, - { "atf_shell", ATF_SHELL, NULL, false, }, - { "atf_workdir", ATF_WORKDIR, NULL, false, }, - { NULL, NULL, NULL, false, }, -}; - -/* Only used for unit testing, so this prototype is private. */ -void __atf_config_reinit(void); - -/* --------------------------------------------------------------------- - * Auxiliary functions. - * --------------------------------------------------------------------- */ - -static -char * -string_to_upper(const char *str) -{ - char *uc; - - uc = (char *)malloc(strlen(str) + 1); - if (uc != NULL) { - char *ucptr = uc; - while (*str != '\0') { - *ucptr = toupper((int)*str); - - str++; - ucptr++; - } - *ucptr = '\0'; - } - - return uc; -} - -static -void -initialize_var(struct var *var, const char *envname) -{ - PRE(var->value == NULL); - - if (atf_env_has(envname)) { - const char *val = atf_env_get(envname); - if (strlen(val) > 0 || var->can_be_empty) - var->value = val; - else - var->value = var->default_value; - } else - var->value = var->default_value; - - POST(var->value != NULL); -} - -static -void -initialize(void) -{ - struct var *var; - - PRE(!initialized); - - for (var = vars; var->name != NULL; var++) { - char *envname; - - envname = string_to_upper(var->name); - initialize_var(var, envname); - free(envname); - } - - initialized = true; -} - -/* --------------------------------------------------------------------- - * Free functions. - * --------------------------------------------------------------------- */ - -const char * -atf_config_get(const char *name) -{ - const struct var *var; - const char *value; - - if (!initialized) { - initialize(); - INV(initialized); - } - - value = NULL; - for (var = vars; value == NULL && var->name != NULL; var++) - if (strcmp(var->name, name) == 0) - value = var->value; - INV(value != NULL); - - return value; -} - -void -__atf_config_reinit(void) -{ - struct var *var; - - initialized = false; - - for (var = vars; var->name != NULL; var++) - var->value = NULL; -} diff --git a/contrib/atf/atf-c/config.h b/contrib/atf/atf-c/config.h deleted file mode 100644 index 19b86e2..0000000 --- a/contrib/atf/atf-c/config.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2008 The NetBSD Foundation, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND - * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER - * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#if !defined(ATF_C_CONFIG_H) -#define ATF_C_CONFIG_H - -#include <stdbool.h> - -const char *atf_config_get(const char *); - -#endif /* !defined(ATF_C_CONFIG_H) */ diff --git a/contrib/atf/atf-c/config_test.c b/contrib/atf/atf-c/config_test.c deleted file mode 100644 index aed1814..0000000 --- a/contrib/atf/atf-c/config_test.c +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2007 The NetBSD Foundation, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND - * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER - * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include <stdio.h> -#include <string.h> - -#include <atf-c.h> - -#include "atf-c/config.h" - -#include "detail/env.h" -#include "detail/test_helpers.h" - -static const char *test_value = "env-value"; - -static struct varnames { - const char *lc; - const char *uc; - bool can_be_empty; -} all_vars[] = { - { "atf_build_cc", "ATF_BUILD_CC", false }, - { "atf_build_cflags", "ATF_BUILD_CFLAGS", true }, - { "atf_build_cpp", "ATF_BUILD_CPP", false }, - { "atf_build_cppflags", "ATF_BUILD_CPPFLAGS", true }, - { "atf_build_cxx", "ATF_BUILD_CXX", false }, - { "atf_build_cxxflags", "ATF_BUILD_CXXFLAGS", true }, - { "atf_includedir", "ATF_INCLUDEDIR", false }, - { "atf_libexecdir", "ATF_LIBEXECDIR", false }, - { "atf_pkgdatadir", "ATF_PKGDATADIR", false }, - { "atf_shell", "ATF_SHELL", false }, - { "atf_workdir", "ATF_WORKDIR", false }, - { NULL, NULL, false } -}; - -/* --------------------------------------------------------------------- - * Auxiliary functions. - * --------------------------------------------------------------------- */ - -void __atf_config_reinit(void); - -static -void -unset_all(void) -{ - const struct varnames *v; - for (v = all_vars; v->lc != NULL; v++) - RE(atf_env_unset(v->uc)); -} - -static -void -compare_one(const char *var, const char *expvalue) -{ - const struct varnames *v; - - printf("Checking that %s is set to %s\n", var, expvalue); - - for (v = all_vars; v->lc != NULL; v++) { - if (strcmp(v->lc, var) == 0) - ATF_CHECK_STREQ(atf_config_get(v->lc), test_value); - else - ATF_CHECK(strcmp(atf_config_get(v->lc), test_value) != 0); - } -} - -/* --------------------------------------------------------------------- - * Test cases for the free functions. - * --------------------------------------------------------------------- */ - -ATF_TC(get); -ATF_TC_HEAD(get, tc) -{ - atf_tc_set_md_var(tc, "descr", "Tests the atf_config_get function"); -} -ATF_TC_BODY(get, tc) -{ - const struct varnames *v; - - /* Unset all known environment variables and make sure the built-in - * values do not match the bogus value we will use for testing. */ - unset_all(); - __atf_config_reinit(); - for (v = all_vars; v->lc != NULL; v++) - ATF_CHECK(strcmp(atf_config_get(v->lc), test_value) != 0); - - /* Test the behavior of empty values. */ - for (v = all_vars; v->lc != NULL; v++) { - unset_all(); - if (strcmp(atf_config_get(v->lc), "") != 0) { - RE(atf_env_set(v->uc, "")); - __atf_config_reinit(); - if (v->can_be_empty) - ATF_CHECK(strlen(atf_config_get(v->lc)) == 0); - else - ATF_CHECK(strlen(atf_config_get(v->lc)) > 0); - } - } - - /* Check if every variable is recognized individually. */ - for (v = all_vars; v->lc != NULL; v++) { - unset_all(); - RE(atf_env_set(v->uc, test_value)); - __atf_config_reinit(); - compare_one(v->lc, test_value); - } -} - -/* --------------------------------------------------------------------- - * Tests cases for the header file. - * --------------------------------------------------------------------- */ - -HEADER_TC(include, "atf-c/config.h"); - -/* --------------------------------------------------------------------- - * Main. - * --------------------------------------------------------------------- */ - -ATF_TP_ADD_TCS(tp) -{ - ATF_TP_ADD_TC(tp, get); - - /* Add the test cases for the header file. */ - ATF_TP_ADD_TC(tp, include); - - return atf_no_error(); -} diff --git a/contrib/atf/atf-c/defs.h.in b/contrib/atf/atf-c/defs.h.in index 7925107..6059e7f 100644 --- a/contrib/atf/atf-c/defs.h.in +++ b/contrib/atf/atf-c/defs.h.in @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2008 The NetBSD Foundation, Inc. +/* Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,8 +21,7 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #if !defined(ATF_C_DEFS_H) #define ATF_C_DEFS_H diff --git a/contrib/atf/atf-c/detail/dynstr.c b/contrib/atf/atf-c/detail/dynstr.c index e533a81..424a1c9 100644 --- a/contrib/atf/atf-c/detail/dynstr.c +++ b/contrib/atf/atf-c/detail/dynstr.c @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2008 The NetBSD Foundation, Inc. +/* Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,8 +21,9 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +#include "atf-c/detail/dynstr.h" #include <errno.h> #include <stdarg.h> @@ -34,12 +32,10 @@ #include <stdlib.h> #include <string.h> +#include "atf-c/detail/sanity.h" +#include "atf-c/detail/text.h" #include "atf-c/error.h" -#include "dynstr.h" -#include "sanity.h" -#include "text.h" - /* --------------------------------------------------------------------- * Auxiliary functions. * --------------------------------------------------------------------- */ diff --git a/contrib/atf/atf-c/detail/dynstr.h b/contrib/atf/atf-c/detail/dynstr.h index c82209a..60b8e42 100644 --- a/contrib/atf/atf-c/detail/dynstr.h +++ b/contrib/atf/atf-c/detail/dynstr.h @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2008 The NetBSD Foundation, Inc. +/* Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,11 +21,10 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#if !defined(ATF_C_DYNSTR_H) -#define ATF_C_DYNSTR_H +#if !defined(ATF_C_DETAIL_DYNSTR_H) +#define ATF_C_DETAIL_DYNSTR_H #include <stdarg.h> #include <stdbool.h> @@ -78,4 +74,4 @@ atf_error_t atf_dynstr_prepend_fmt(atf_dynstr_t *, const char *, ...); bool atf_equal_dynstr_cstring(const atf_dynstr_t *, const char *); bool atf_equal_dynstr_dynstr(const atf_dynstr_t *, const atf_dynstr_t *); -#endif /* ATF_C_DYNSTR_H */ +#endif /* !defined(ATF_C_DETAIL_DYNSTR_H) */ diff --git a/contrib/atf/atf-c/detail/dynstr_test.c b/contrib/atf/atf-c/detail/dynstr_test.c index 1b68d38..2512752 100644 --- a/contrib/atf/atf-c/detail/dynstr_test.c +++ b/contrib/atf/atf-c/detail/dynstr_test.c @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2008 The NetBSD Foundation, Inc. +/* Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,8 +21,9 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +#include "atf-c/detail/dynstr.h" #include <stdarg.h> #include <stdint.h> @@ -35,8 +33,7 @@ #include <atf-c.h> -#include "dynstr.h" -#include "test_helpers.h" +#include "atf-c/detail/test_helpers.h" /* --------------------------------------------------------------------- * Tests for the "atf_dynstr" type. diff --git a/contrib/atf/atf-c/detail/env.c b/contrib/atf/atf-c/detail/env.c index feb4ee5..8ee3d69 100644 --- a/contrib/atf/atf-c/detail/env.c +++ b/contrib/atf/atf-c/detail/env.c @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2007 The NetBSD Foundation, Inc. +/* Copyright (c) 2007 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,22 +21,21 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +#include "atf-c/detail/env.h" #if defined(HAVE_CONFIG_H) -#include "bconfig.h" +#include "config.h" #endif #include <errno.h> #include <stdlib.h> +#include "atf-c/detail/sanity.h" +#include "atf-c/detail/text.h" #include "atf-c/error.h" -#include "env.h" -#include "sanity.h" -#include "text.h" - const char * atf_env_get(const char *name) { @@ -48,6 +44,16 @@ atf_env_get(const char *name) return val; } +const char * +atf_env_get_with_default(const char *name, const char *default_value) +{ + const char* val = getenv(name); + if (val == NULL) + return default_value; + else + return val; +} + bool atf_env_has(const char *name) { diff --git a/contrib/atf/atf-c/detail/env.h b/contrib/atf/atf-c/detail/env.h index c0d07a3..5d29440 100644 --- a/contrib/atf/atf-c/detail/env.h +++ b/contrib/atf/atf-c/detail/env.h @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2008 The NetBSD Foundation, Inc. +/* Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,19 +21,19 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#if !defined(ATF_C_ENV_H) -#define ATF_C_ENV_H +#if !defined(ATF_C_DETAIL_ENV_H) +#define ATF_C_DETAIL_ENV_H #include <stdbool.h> #include <atf-c/error_fwd.h> const char *atf_env_get(const char *); +const char *atf_env_get_with_default(const char *, const char *); bool atf_env_has(const char *); atf_error_t atf_env_set(const char *, const char *); atf_error_t atf_env_unset(const char *); -#endif /* !defined(ATF_C_ENV_H) */ +#endif /* !defined(ATF_C_DETAIL_ENV_H) */ diff --git a/contrib/atf/atf-c/detail/env_test.c b/contrib/atf/atf-c/detail/env_test.c index 6ebf36c..3909c29 100644 --- a/contrib/atf/atf-c/detail/env_test.c +++ b/contrib/atf/atf-c/detail/env_test.c @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2007 The NetBSD Foundation, Inc. +/* Copyright (c) 2007 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,17 +21,17 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +#include "atf-c/detail/env.h" #include <stdlib.h> #include <string.h> #include <atf-c.h> -#include "env.h" -#include "test_helpers.h" -#include "text.h" +#include "atf-c/detail/test_helpers.h" +#include "atf-c/detail/text.h" /* --------------------------------------------------------------------- * Test cases for the free functions. @@ -67,6 +64,25 @@ ATF_TC_BODY(get, tc) ATF_REQUIRE(strchr(val, ':') != NULL); } +ATF_TC(get_with_default); +ATF_TC_HEAD(get_with_default, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the atf_env_get_with_default " + "function"); +} +ATF_TC_BODY(get_with_default, tc) +{ + const char *val; + + ATF_REQUIRE(atf_env_has("PATH")); + + val = atf_env_get_with_default("PATH", "unknown"); + ATF_REQUIRE(strcmp(val, "unknown") != 0); + + val = atf_env_get_with_default("_UNKNOWN_VARIABLE_", "foo bar"); + ATF_REQUIRE(strcmp(val, "foo bar") == 0); +} + ATF_TC(set); ATF_TC_HEAD(set, tc) { @@ -109,6 +125,7 @@ ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, has); ATF_TP_ADD_TC(tp, get); + ATF_TP_ADD_TC(tp, get_with_default); ATF_TP_ADD_TC(tp, set); ATF_TP_ADD_TC(tp, unset); diff --git a/contrib/atf/atf-c/detail/fs.c b/contrib/atf/atf-c/detail/fs.c index 22cbca4..5ff7648 100644 --- a/contrib/atf/atf-c/detail/fs.c +++ b/contrib/atf/atf-c/detail/fs.c @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2007 The NetBSD Foundation, Inc. +/* Copyright (c) 2007 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,11 +21,12 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +#include "atf-c/detail/fs.h" #if defined(HAVE_CONFIG_H) -#include "bconfig.h" +#include "config.h" #endif #include <sys/types.h> @@ -47,13 +45,11 @@ #include <unistd.h> #include "atf-c/defs.h" +#include "atf-c/detail/sanity.h" +#include "atf-c/detail/text.h" +#include "atf-c/detail/user.h" #include "atf-c/error.h" -#include "fs.h" -#include "sanity.h" -#include "text.h" -#include "user.h" - /* --------------------------------------------------------------------- * Prototypes for auxiliary functions. * --------------------------------------------------------------------- */ diff --git a/contrib/atf/atf-c/detail/fs.h b/contrib/atf/atf-c/detail/fs.h index ec77c3b..1c6c0eb 100644 --- a/contrib/atf/atf-c/detail/fs.h +++ b/contrib/atf/atf-c/detail/fs.h @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2008 The NetBSD Foundation, Inc. +/* Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,11 +21,10 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#if !defined(ATF_C_FS_H) -#define ATF_C_FS_H +#if !defined(ATF_C_DETAIL_FS_H) +#define ATF_C_DETAIL_FS_H #include <sys/types.h> #include <sys/stat.h> @@ -36,10 +32,9 @@ #include <stdarg.h> #include <stdbool.h> +#include <atf-c/detail/dynstr.h> #include <atf-c/error_fwd.h> -#include "dynstr.h" - /* --------------------------------------------------------------------- * The "atf_fs_path" type. * --------------------------------------------------------------------- */ @@ -130,4 +125,4 @@ atf_error_t atf_fs_mkstemp(atf_fs_path_t *, int *); atf_error_t atf_fs_rmdir(const atf_fs_path_t *); atf_error_t atf_fs_unlink(const atf_fs_path_t *); -#endif /* !defined(ATF_C_FS_H) */ +#endif /* !defined(ATF_C_DETAIL_FS_H) */ diff --git a/contrib/atf/atf-c/detail/fs_test.c b/contrib/atf/atf-c/detail/fs_test.c index 043304a..3dbc4d3 100644 --- a/contrib/atf/atf-c/detail/fs_test.c +++ b/contrib/atf/atf-c/detail/fs_test.c @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2007 The NetBSD Foundation, Inc. +/* Copyright (c) 2007 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,8 +21,9 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +#include "atf-c/detail/fs.h" #include <sys/types.h> #include <sys/stat.h> @@ -39,9 +37,8 @@ #include <atf-c.h> -#include "fs.h" -#include "test_helpers.h" -#include "user.h" +#include "atf-c/detail/test_helpers.h" +#include "atf-c/detail/user.h" /* --------------------------------------------------------------------- * Auxiliary functions. diff --git a/contrib/atf/atf-c/detail/list.c b/contrib/atf/atf-c/detail/list.c index 0d005ad..d14216e 100644 --- a/contrib/atf/atf-c/detail/list.c +++ b/contrib/atf/atf-c/detail/list.c @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2008 The NetBSD Foundation, Inc. +/* Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,18 +21,17 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +#include "atf-c/detail/list.h" #include <stdlib.h> #include <string.h> +#include "atf-c/detail/sanity.h" #include "atf-c/error.h" #include "atf-c/utils.h" -#include "list.h" -#include "sanity.h" - /* --------------------------------------------------------------------- * Auxiliary functions. * --------------------------------------------------------------------- */ diff --git a/contrib/atf/atf-c/detail/list.h b/contrib/atf/atf-c/detail/list.h index 2c0fbcb..b250066 100644 --- a/contrib/atf/atf-c/detail/list.h +++ b/contrib/atf/atf-c/detail/list.h @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2008 The NetBSD Foundation, Inc. +/* Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,11 +21,10 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#if !defined(ATF_C_LIST_H) -#define ATF_C_LIST_H +#if !defined(ATF_C_DETAIL_LIST_H) +#define ATF_C_DETAIL_LIST_H #include <stdarg.h> #include <stdbool.h> @@ -112,4 +108,4 @@ void atf_list_append_list(atf_list_t *, atf_list_t *); !atf_equal_list_citer_list_citer((iter), atf_list_end_c(list)); \ iter = atf_list_citer_next(iter)) -#endif /* ATF_C_LIST_H */ +#endif /* !defined(ATF_C_DETAIL_LIST_H) */ diff --git a/contrib/atf/atf-c/detail/list_test.c b/contrib/atf/atf-c/detail/list_test.c index 3aa576c..82a715d 100644 --- a/contrib/atf/atf-c/detail/list_test.c +++ b/contrib/atf/atf-c/detail/list_test.c @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2008 The NetBSD Foundation, Inc. +/* Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,19 +21,18 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +#include "atf-c/detail/list.h" #include <stdio.h> #include <string.h> #include <atf-c.h> +#include "atf-c/detail/test_helpers.h" #include "atf-c/utils.h" -#include "list.h" -#include "test_helpers.h" - /* --------------------------------------------------------------------- * Tests for the "atf_list" type. * --------------------------------------------------------------------- */ diff --git a/contrib/atf/atf-c/detail/map.c b/contrib/atf/atf-c/detail/map.c index 7395adf..34aaae2 100644 --- a/contrib/atf/atf-c/detail/map.c +++ b/contrib/atf/atf-c/detail/map.c @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2008 The NetBSD Foundation, Inc. +/* Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,19 +21,18 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +#include "atf-c/detail/map.h" #include <errno.h> #include <stdlib.h> #include <string.h> +#include "atf-c/detail/sanity.h" #include "atf-c/error.h" #include "atf-c/utils.h" -#include "map.h" -#include "sanity.h" - /* --------------------------------------------------------------------- * Auxiliary functions. * --------------------------------------------------------------------- */ diff --git a/contrib/atf/atf-c/detail/map.h b/contrib/atf/atf-c/detail/map.h index a3ed7a2..7ca8e8a 100644 --- a/contrib/atf/atf-c/detail/map.h +++ b/contrib/atf/atf-c/detail/map.h @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2008 The NetBSD Foundation, Inc. +/* Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,19 +21,17 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#if !defined(ATF_C_MAP_H) -#define ATF_C_MAP_H +#if !defined(ATF_C_DETAIL_MAP_H) +#define ATF_C_DETAIL_MAP_H #include <stdarg.h> #include <stdbool.h> +#include <atf-c/detail/list.h> #include <atf-c/error_fwd.h> -#include "list.h" - /* --------------------------------------------------------------------- * The "atf_map_citer" type. * --------------------------------------------------------------------- */ @@ -116,4 +111,4 @@ atf_error_t atf_map_insert(atf_map_t *, const char *, void *, bool); !atf_equal_map_citer_map_citer((iter), atf_map_end_c(map)); \ iter = atf_map_citer_next(iter)) -#endif /* ATF_C_MAP_H */ +#endif /* !defined(ATF_C_DETAIL_MAP_H) */ diff --git a/contrib/atf/atf-c/detail/map_test.c b/contrib/atf/atf-c/detail/map_test.c index 644ab69..0982e20f 100644 --- a/contrib/atf/atf-c/detail/map_test.c +++ b/contrib/atf/atf-c/detail/map_test.c @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2008 The NetBSD Foundation, Inc. +/* Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,19 +21,18 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +#include "atf-c/detail/map.h" #include <stdio.h> #include <string.h> #include <atf-c.h> +#include "atf-c/detail/test_helpers.h" #include "atf-c/utils.h" -#include "map.h" -#include "test_helpers.h" - /* --------------------------------------------------------------------- * Tests for the "atf_map" type. * --------------------------------------------------------------------- */ diff --git a/contrib/atf/atf-c/detail/process.c b/contrib/atf/atf-c/detail/process.c index bc36b57..8e08b6c 100644 --- a/contrib/atf/atf-c/detail/process.c +++ b/contrib/atf/atf-c/detail/process.c @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2007 The NetBSD Foundation, Inc. +/* Copyright (c) 2007 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,8 +21,9 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +#include "atf-c/detail/process.h" #include <sys/types.h> #include <sys/wait.h> @@ -38,11 +36,9 @@ #include <unistd.h> #include "atf-c/defs.h" +#include "atf-c/detail/sanity.h" #include "atf-c/error.h" -#include "process.h" -#include "sanity.h" - /* This prototype is not in the header file because this is a private * function; however, we need to access it during testing. */ atf_error_t atf_process_status_init(atf_process_status_t *, int); diff --git a/contrib/atf/atf-c/detail/process.h b/contrib/atf/atf-c/detail/process.h index b4aad3d..81158d0 100644 --- a/contrib/atf/atf-c/detail/process.h +++ b/contrib/atf/atf-c/detail/process.h @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2008 The NetBSD Foundation, Inc. +/* Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,21 +21,19 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#if !defined(ATF_C_PROCESS_H) -#define ATF_C_PROCESS_H +#if !defined(ATF_C_DETAIL_PROCESS_H) +#define ATF_C_DETAIL_PROCESS_H #include <sys/types.h> #include <stdbool.h> +#include <atf-c/detail/fs.h> +#include <atf-c/detail/list.h> #include <atf-c/error_fwd.h> -#include "fs.h" -#include "list.h" - /* --------------------------------------------------------------------- * The "atf_process_stream" type. * --------------------------------------------------------------------- */ @@ -133,4 +128,4 @@ atf_error_t atf_process_exec_list(atf_process_status_t *, const atf_process_stream_t *, void (*)(void)); -#endif /* !defined(ATF_C_PROCESS_H) */ +#endif /* !defined(ATF_C_DETAIL_PROCESS_H) */ diff --git a/contrib/atf/atf-c/detail/process_helpers.c b/contrib/atf/atf-c/detail/process_helpers.c index 61f1b67..47b90bc 100644 --- a/contrib/atf/atf-c/detail/process_helpers.c +++ b/contrib/atf/atf-c/detail/process_helpers.c @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2008 The NetBSD Foundation, Inc. +/* Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,8 +21,7 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include <sys/types.h> diff --git a/contrib/atf/atf-c/detail/process_test.c b/contrib/atf/atf-c/detail/process_test.c index 9e55f70..5ae5565 100644 --- a/contrib/atf/atf-c/detail/process_test.c +++ b/contrib/atf/atf-c/detail/process_test.c @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2008 The NetBSD Foundation, Inc. +/* Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,8 +21,9 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +#include "atf-c/detail/process.h" #include <sys/types.h> #include <sys/time.h> @@ -43,10 +41,8 @@ #include <atf-c.h> #include "atf-c/defs.h" - -#include "process.h" -#include "sanity.h" -#include "test_helpers.h" +#include "atf-c/detail/sanity.h" +#include "atf-c/detail/test_helpers.h" atf_error_t atf_process_status_init(atf_process_status_t *, int); diff --git a/contrib/atf/atf-c/detail/sanity.c b/contrib/atf/atf-c/detail/sanity.c index d8a8905..cfc8676 100644 --- a/contrib/atf/atf-c/detail/sanity.c +++ b/contrib/atf/atf-c/detail/sanity.c @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2008 The NetBSD Foundation, Inc. +/* Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,11 +21,12 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +#include "atf-c/detail/sanity.h" #if defined(HAVE_CONFIG_H) -#include "bconfig.h" +#include "config.h" #endif #include <err.h> @@ -36,8 +34,6 @@ #include <stdio.h> #include <stdlib.h> -#include "sanity.h" - static void fail(const char *fmt, ...) @@ -53,7 +49,7 @@ fail(const char *fmt, ...) warnx("This is probably a bug in this application or one of the " "libraries it uses. If you believe this problem is caused " "by, or is related to " PACKAGE_STRING ", please report it " - "to " PACKAGE_BUGREPORT " and provide as many detatils as " + "to " PACKAGE_BUGREPORT " and provide as many details as " "possible describing how you got to this condition."); abort(); diff --git a/contrib/atf/atf-c/detail/sanity.h b/contrib/atf/atf-c/detail/sanity.h index 0b4f3e4..7f51fe0 100644 --- a/contrib/atf/atf-c/detail/sanity.h +++ b/contrib/atf/atf-c/detail/sanity.h @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2008 The NetBSD Foundation, Inc. +/* Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,11 +21,10 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#if !defined(ATF_C_SANITY_H) -#define ATF_C_SANITY_H +#if !defined(ATF_C_DETAIL_SANITY_H) +#define ATF_C_DETAIL_SANITY_H void atf_sanity_inv(const char *, int, const char *); void atf_sanity_pre(const char *, int, const char *); @@ -70,4 +66,4 @@ void atf_sanity_post(const char *, int, const char *); #define UNREACHABLE INV(0) -#endif /* ATF_C_SANITY_H */ +#endif /* !defined(ATF_C_DETAIL_SANITY_H) */ diff --git a/contrib/atf/atf-c/detail/sanity_test.c b/contrib/atf/atf-c/detail/sanity_test.c index 7c8285b..a986c32 100644 --- a/contrib/atf/atf-c/detail/sanity_test.c +++ b/contrib/atf/atf-c/detail/sanity_test.c @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2008 The NetBSD Foundation, Inc. +/* Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,11 +21,12 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +#include "atf-c/detail/sanity.h" #if defined(HAVE_CONFIG_H) -#include "bconfig.h" +#include "config.h" #endif #include <sys/types.h> @@ -42,10 +40,9 @@ #include <atf-c.h> -#include "dynstr.h" -#include "process.h" -#include "sanity.h" -#include "test_helpers.h" +#include "atf-c/detail/dynstr.h" +#include "atf-c/detail/process.h" +#include "atf-c/detail/test_helpers.h" /* --------------------------------------------------------------------- * Auxiliary functions. diff --git a/contrib/atf/atf-c/detail/test_helpers.c b/contrib/atf/atf-c/detail/test_helpers.c index aacbf32..827d46e 100644 --- a/contrib/atf/atf-c/detail/test_helpers.c +++ b/contrib/atf/atf-c/detail/test_helpers.c @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2008 The NetBSD Foundation, Inc. +/* Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,24 +21,24 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +#include "atf-c/detail/test_helpers.h" #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> +#include <atf-c.h> + #include "atf-c/build.h" #include "atf-c/check.h" -#include "atf-c/config.h" +#include "atf-c/detail/dynstr.h" +#include "atf-c/detail/env.h" +#include "atf-c/detail/fs.h" +#include "atf-c/detail/process.h" #include "atf-c/error.h" -#include "atf-c/macros.h" - -#include "dynstr.h" -#include "fs.h" -#include "process.h" -#include "test_helpers.h" bool build_check_c_o(const char *path) @@ -50,7 +47,8 @@ build_check_c_o(const char *path) atf_dynstr_t iflag; const char *optargs[4]; - RE(atf_dynstr_init_fmt(&iflag, "-I%s", atf_config_get("atf_includedir"))); + RE(atf_dynstr_init_fmt(&iflag, "-I%s", atf_env_get_with_default( + "ATF_INCLUDEDIR", ATF_INCLUDEDIR))); optargs[0] = atf_dynstr_cstring(&iflag); optargs[1] = "-Wall"; diff --git a/contrib/atf/atf-c/detail/test_helpers.h b/contrib/atf/atf-c/detail/test_helpers.h index 3037ba4..a601c29 100644 --- a/contrib/atf/atf-c/detail/test_helpers.h +++ b/contrib/atf/atf-c/detail/test_helpers.h @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2008 The NetBSD Foundation, Inc. +/* Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,18 +21,20 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#if defined(TESTS_ATF_ATF_C_TEST_HELPERS_H) +#if defined(ATF_C_DETAIL_TEST_HELPERS_H) # error "Cannot include test_helpers.h more than once." #else -# define TESTS_ATF_ATF_C_TEST_HELPERS_H +# define ATF_C_DETAIL_TEST_HELPERS_H #endif #include <stdbool.h> -#include "atf-c/error_fwd.h" +#include <atf-c.h> + +#include <atf-c/error_fwd.h> +#include <atf-c/tc.h> struct atf_dynstr; struct atf_fs_path; diff --git a/contrib/atf/atf-c/detail/text.c b/contrib/atf/atf-c/detail/text.c index d91e8d1..3b1d7e7 100644 --- a/contrib/atf/atf-c/detail/text.c +++ b/contrib/atf/atf-c/detail/text.c @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2008 The NetBSD Foundation, Inc. +/* Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,20 +21,19 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +#include "atf-c/detail/text.h" #include <errno.h> #include <limits.h> #include <string.h> #include <stdlib.h> +#include "atf-c/detail/dynstr.h" +#include "atf-c/detail/sanity.h" #include "atf-c/error.h" -#include "dynstr.h" -#include "sanity.h" -#include "text.h" - atf_error_t atf_text_for_each_word(const char *instr, const char *sep, atf_error_t (*func)(const char *, void *), diff --git a/contrib/atf/atf-c/detail/text.h b/contrib/atf/atf-c/detail/text.h index 8f8ddf4..b2820b6 100644 --- a/contrib/atf/atf-c/detail/text.h +++ b/contrib/atf/atf-c/detail/text.h @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2008 The NetBSD Foundation, Inc. +/* Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,19 +21,17 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#if !defined(ATF_C_TEXT_H) -#define ATF_C_TEXT_H +#if !defined(ATF_C_DETAIL_TEXT_H) +#define ATF_C_DETAIL_TEXT_H #include <stdarg.h> #include <stdbool.h> +#include <atf-c/detail/list.h> #include <atf-c/error_fwd.h> -#include "list.h" - atf_error_t atf_text_for_each_word(const char *, const char *, atf_error_t (*)(const char *, void *), void *); @@ -46,4 +41,4 @@ atf_error_t atf_text_split(const char *, const char *, atf_list_t *); atf_error_t atf_text_to_bool(const char *, bool *); atf_error_t atf_text_to_long(const char *, long *); -#endif /* ATF_C_TEXT_H */ +#endif /* !defined(ATF_C_DETAIL_TEXT_H) */ diff --git a/contrib/atf/atf-c/detail/text_test.c b/contrib/atf/atf-c/detail/text_test.c index 7bdf9c8..5d6c8e5 100644 --- a/contrib/atf/atf-c/detail/text_test.c +++ b/contrib/atf/atf-c/detail/text_test.c @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2008 The NetBSD Foundation, Inc. +/* Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,8 +21,9 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +#include "atf-c/detail/text.h" #include <stdio.h> #include <stdlib.h> @@ -33,9 +31,8 @@ #include <atf-c.h> -#include "sanity.h" -#include "test_helpers.h" -#include "text.h" +#include "atf-c/detail/sanity.h" +#include "atf-c/detail/test_helpers.h" /* --------------------------------------------------------------------- * Auxiliary functions. diff --git a/contrib/atf/atf-c/detail/tp_main.c b/contrib/atf/atf-c/detail/tp_main.c index a62ae0a..439384b4 100644 --- a/contrib/atf/atf-c/detail/tp_main.c +++ b/contrib/atf/atf-c/detail/tp_main.c @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2008 The NetBSD Foundation, Inc. +/* Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,11 +21,10 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #if defined(HAVE_CONFIG_H) -#include "bconfig.h" +#include "config.h" #endif #include <ctype.h> @@ -38,17 +34,16 @@ #include <string.h> #include <unistd.h> +#include "atf-c/detail/dynstr.h" +#include "atf-c/detail/env.h" +#include "atf-c/detail/fs.h" +#include "atf-c/detail/map.h" +#include "atf-c/detail/sanity.h" #include "atf-c/error.h" #include "atf-c/tc.h" #include "atf-c/tp.h" #include "atf-c/utils.h" -#include "dynstr.h" -#include "env.h" -#include "fs.h" -#include "map.h" -#include "sanity.h" - #if defined(HAVE_GNU_GETOPT) # define GETOPT_POSIX "+" #else @@ -499,7 +494,7 @@ run_tc(const atf_tp_t *tp, struct params *p, int *exitcode) if (!atf_env_has("__RUNNING_INSIDE_ATF_RUN") || strcmp(atf_env_get( "__RUNNING_INSIDE_ATF_RUN"), "internal-yes-value") != 0) { - print_warning("Running test cases without atf-run(1) is unsupported"); + print_warning("Running test cases outside of kyua(1) is unsupported"); print_warning("No isolation nor timeout control is being applied; you " "may get unexpected failures; see atf-test-case(4)"); } diff --git a/contrib/atf/atf-c/detail/user.c b/contrib/atf/atf-c/detail/user.c index 5a89bf4..bbb4ded 100644 --- a/contrib/atf/atf-c/detail/user.c +++ b/contrib/atf/atf-c/detail/user.c @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2007 The NetBSD Foundation, Inc. +/* Copyright (c) 2007 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,16 +21,16 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +#include "atf-c/detail/user.h" #include <sys/param.h> #include <sys/types.h> #include <limits.h> #include <unistd.h> -#include "sanity.h" -#include "user.h" +#include "atf-c/detail/sanity.h" /* --------------------------------------------------------------------- * Free functions. diff --git a/contrib/atf/atf-c/detail/user.h b/contrib/atf/atf-c/detail/user.h index d682bcf..14a3e96 100644 --- a/contrib/atf/atf-c/detail/user.h +++ b/contrib/atf/atf-c/detail/user.h @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2007 The NetBSD Foundation, Inc. +/* Copyright (c) 2007 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,11 +21,10 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#if !defined(ATF_C_USER_H) -#define ATF_C_USER_H +#if !defined(ATF_C_DETAIL_USER_H) +#define ATF_C_DETAIL_USER_H #include <sys/types.h> @@ -46,4 +42,4 @@ bool atf_user_is_member_of_group(gid_t); bool atf_user_is_root(void); bool atf_user_is_unprivileged(void); -#endif /* !defined(ATF_C_USER_H) */ +#endif /* !defined(ATF_C_DETAIL_USER_H) */ diff --git a/contrib/atf/atf-c/detail/user_test.c b/contrib/atf/atf-c/detail/user_test.c index 0bf37e7..6a0f6e1 100644 --- a/contrib/atf/atf-c/detail/user_test.c +++ b/contrib/atf/atf-c/detail/user_test.c @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2007 The NetBSD Foundation, Inc. +/* Copyright (c) 2007 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,8 +21,9 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +#include "atf-c/detail/user.h" #include <sys/param.h> #include <sys/types.h> @@ -36,8 +34,7 @@ #include <atf-c.h> -#include "test_helpers.h" -#include "user.h" +#include "atf-c/detail/test_helpers.h" /* --------------------------------------------------------------------- * Test cases for the free functions. diff --git a/contrib/atf/atf-c/detail/version_helper.c b/contrib/atf/atf-c/detail/version_helper.c index b75ff36..fd48466 100644 --- a/contrib/atf/atf-c/detail/version_helper.c +++ b/contrib/atf/atf-c/detail/version_helper.c @@ -29,7 +29,7 @@ */ #if defined(HAVE_CONFIG_H) -#include "bconfig.h" +#include "config.h" #endif #include <stdio.h> diff --git a/contrib/atf/atf-c/error.c b/contrib/atf/atf-c/error.c index aeb55a8..071daf6 100644 --- a/contrib/atf/atf-c/error.c +++ b/contrib/atf/atf-c/error.c @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2008 The NetBSD Foundation, Inc. +/* Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,17 +21,16 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +#include "atf-c/error.h" #include <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include "atf-c/error.h" - -#include "detail/sanity.h" +#include "atf-c/detail/sanity.h" /* Theoretically, there can only be a single error intance at any given * point in time, because errors are raised at one point and must be diff --git a/contrib/atf/atf-c/error.h b/contrib/atf/atf-c/error.h index a850280..260c0d0 100644 --- a/contrib/atf/atf-c/error.h +++ b/contrib/atf/atf-c/error.h @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2008 The NetBSD Foundation, Inc. +/* Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,17 +21,16 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #if !defined(ATF_C_ERROR_H) #define ATF_C_ERROR_H +#include <atf-c/error_fwd.h> + #include <stdbool.h> #include <stddef.h> -#include <atf-c/error_fwd.h> - /* --------------------------------------------------------------------- * The "atf_error" type. * --------------------------------------------------------------------- */ @@ -68,4 +64,4 @@ const char *atf_libc_error_msg(const atf_error_t); atf_error_t atf_no_memory_error(void); -#endif /* ATF_C_ERROR_H */ +#endif /* !defined(ATF_C_ERROR_H) */ diff --git a/contrib/atf/atf-c/error_fwd.h b/contrib/atf/atf-c/error_fwd.h index 69d7e7d..d73e164 100644 --- a/contrib/atf/atf-c/error_fwd.h +++ b/contrib/atf/atf-c/error_fwd.h @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2008 The NetBSD Foundation, Inc. +/* Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,8 +21,7 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #if !defined(ATF_C_ERROR_FWD_H) #define ATF_C_ERROR_FWD_H @@ -37,4 +33,4 @@ struct atf_error; typedef struct atf_error *atf_error_t; -#endif /* ATF_C_ERROR_FWD_H */ +#endif /* !defined(ATF_C_ERROR_FWD_H) */ diff --git a/contrib/atf/atf-c/error_test.c b/contrib/atf/atf-c/error_test.c index 2c2a307..8bfa124 100644 --- a/contrib/atf/atf-c/error_test.c +++ b/contrib/atf/atf-c/error_test.c @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2008 The NetBSD Foundation, Inc. +/* Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,8 +21,9 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +#include "atf-c/error.h" #include <errno.h> #include <stdint.h> @@ -35,9 +33,6 @@ #include <atf-c.h> #include "atf-c/defs.h" -#include "atf-c/error.h" - -#include "detail/test_helpers.h" /* --------------------------------------------------------------------- * Auxiliary functions. @@ -277,13 +272,6 @@ ATF_TC_BODY(no_memory_twice, tc) } /* --------------------------------------------------------------------- - * Tests cases for the header file. - * --------------------------------------------------------------------- */ - -HEADER_TC(include, "atf-c/error.h"); -HEADER_TC(include_fwd, "atf-c/error_fwd.h"); - -/* --------------------------------------------------------------------- * Main. * --------------------------------------------------------------------- */ @@ -305,9 +293,5 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, no_memory_format); ATF_TP_ADD_TC(tp, no_memory_twice); - /* Add the test cases for the header file. */ - ATF_TP_ADD_TC(tp, include); - ATF_TP_ADD_TC(tp, include_fwd); - return atf_no_error(); } diff --git a/contrib/atf/atf-c/h_build.h b/contrib/atf/atf-c/h_build.h index 9454fdf..c5ad1c7 100644 --- a/contrib/atf/atf-c/h_build.h +++ b/contrib/atf/atf-c/h_build.h @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2009 The NetBSD Foundation, Inc. +/* Copyright (c) 2009 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,13 +21,12 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#if defined(TESTS_ATF_ATF_C_H_BUILD_H) +#if defined(ATF_C_H_BUILD_H) # error "Cannot include h_build.h more than once." #else -# define TESTS_ATF_ATF_C_H_BUILD_H +# define ATF_C_H_BUILD_H #endif /* --------------------------------------------------------------------- diff --git a/contrib/atf/atf-c/macros.h b/contrib/atf/atf-c/macros.h index 7c33ccb..485a159 100644 --- a/contrib/atf/atf-c/macros.h +++ b/contrib/atf/atf-c/macros.h @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2008 The NetBSD Foundation, Inc. +/* Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,8 +21,7 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #if !defined(ATF_C_MACROS_H) #define ATF_C_MACROS_H @@ -131,55 +127,63 @@ return atfu_err; \ } while (0) -#define ATF_REQUIRE_MSG(x, fmt, ...) \ +#define ATF_REQUIRE_MSG(expression, fmt, ...) \ do { \ - if (!(x)) \ + if (!(expression)) \ atf_tc_fail_requirement(__FILE__, __LINE__, fmt, ##__VA_ARGS__); \ } while(0) -#define ATF_CHECK_MSG(x, fmt, ...) \ +#define ATF_CHECK_MSG(expression, fmt, ...) \ do { \ - if (!(x)) \ + if (!(expression)) \ atf_tc_fail_check(__FILE__, __LINE__, fmt, ##__VA_ARGS__); \ } while(0) -#define ATF_REQUIRE(x) \ +#define ATF_REQUIRE(expression) \ do { \ - if (!(x)) \ - atf_tc_fail_requirement(__FILE__, __LINE__, "%s", #x " not met"); \ + if (!(expression)) \ + atf_tc_fail_requirement(__FILE__, __LINE__, "%s", \ + #expression " not met"); \ } while(0) -#define ATF_CHECK(x) \ +#define ATF_CHECK(expression) \ do { \ - if (!(x)) \ - atf_tc_fail_check(__FILE__, __LINE__, "%s", #x " not met"); \ + if (!(expression)) \ + atf_tc_fail_check(__FILE__, __LINE__, "%s", \ + #expression " not met"); \ } while(0) -#define ATF_REQUIRE_EQ(x, y) \ - ATF_REQUIRE_MSG((x) == (y), "%s != %s", #x, #y) +#define ATF_REQUIRE_EQ(expected, actual) \ + ATF_REQUIRE_MSG((expected) == (actual), "%s != %s", #expected, #actual) -#define ATF_CHECK_EQ(x, y) \ - ATF_CHECK_MSG((x) == (y), "%s != %s", #x, #y) +#define ATF_CHECK_EQ(expected, actual) \ + ATF_CHECK_MSG((expected) == (actual), "%s != %s", #expected, #actual) -#define ATF_REQUIRE_EQ_MSG(x, y, fmt, ...) \ - ATF_REQUIRE_MSG((x) == (y), "%s != %s: " fmt, #x, #y, ##__VA_ARGS__) +#define ATF_REQUIRE_EQ_MSG(expected, actual, fmt, ...) \ + ATF_REQUIRE_MSG((expected) == (actual), "%s != %s: " fmt, \ + #expected, #actual, ##__VA_ARGS__) -#define ATF_CHECK_EQ_MSG(x, y, fmt, ...) \ - ATF_CHECK_MSG((x) == (y), "%s != %s: " fmt, #x, #y, ##__VA_ARGS__) +#define ATF_CHECK_EQ_MSG(expected, actual, fmt, ...) \ + ATF_CHECK_MSG((expected) == (actual), "%s != %s: " fmt, \ + #expected, #actual, ##__VA_ARGS__) -#define ATF_REQUIRE_STREQ(x, y) \ - ATF_REQUIRE_MSG(strcmp(x, y) == 0, "%s != %s (%s != %s)", #x, #y, x, y) +#define ATF_REQUIRE_STREQ(expected, actual) \ + ATF_REQUIRE_MSG(strcmp(expected, actual) == 0, "%s != %s (%s != %s)", \ + #expected, #actual, expected, actual) -#define ATF_CHECK_STREQ(x, y) \ - ATF_CHECK_MSG(strcmp(x, y) == 0, "%s != %s (%s != %s)", #x, #y, x, y) +#define ATF_CHECK_STREQ(expected, actual) \ + ATF_CHECK_MSG(strcmp(expected, actual) == 0, "%s != %s (%s != %s)", \ + #expected, #actual, expected, actual) -#define ATF_REQUIRE_STREQ_MSG(x, y, fmt, ...) \ - ATF_REQUIRE_MSG(strcmp(x, y) == 0, "%s != %s (%s != %s): " fmt, \ - #x, #y, x, y, ##__VA_ARGS__) +#define ATF_REQUIRE_STREQ_MSG(expected, actual, fmt, ...) \ + ATF_REQUIRE_MSG(strcmp(expected, actual) == 0, \ + "%s != %s (%s != %s): " fmt, \ + #expected, #actual, expected, actual, ##__VA_ARGS__) -#define ATF_CHECK_STREQ_MSG(x, y, fmt, ...) \ - ATF_CHECK_MSG(strcmp(x, y) == 0, "%s != %s (%s != %s): " fmt, \ - #x, #y, x, y, ##__VA_ARGS__) +#define ATF_CHECK_STREQ_MSG(expected, actual, fmt, ...) \ + ATF_CHECK_MSG(strcmp(expected, actual) == 0, \ + "%s != %s (%s != %s): " fmt, \ + #expected, #actual, expected, actual, ##__VA_ARGS__) #define ATF_REQUIRE_MATCH(regexp, string) \ ATF_REQUIRE_MSG(atf_utils_grep_string("%s", string, regexp), \ diff --git a/contrib/atf/atf-c/macros_h_test.c b/contrib/atf/atf-c/macros_h_test.c index 64c6786..9525fca 100644 --- a/contrib/atf/atf-c/macros_h_test.c +++ b/contrib/atf/atf-c/macros_h_test.c @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2008 The NetBSD Foundation, Inc. +/* Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,8 +21,7 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include <atf-c/macros.h> diff --git a/contrib/atf/atf-c/macros_test.c b/contrib/atf/atf-c/macros_test.c index adfc77c..83578cd 100644 --- a/contrib/atf/atf-c/macros_test.c +++ b/contrib/atf/atf-c/macros_test.c @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2008 The NetBSD Foundation, Inc. +/* Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,8 +21,9 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +#include "atf-c/macros.h" #include <sys/types.h> #include <sys/wait.h> @@ -41,10 +39,10 @@ #include <atf-c.h> -#include "detail/fs.h" -#include "detail/process.h" -#include "detail/test_helpers.h" -#include "detail/text.h" +#include "atf-c/detail/fs.h" +#include "atf-c/detail/process.h" +#include "atf-c/detail/test_helpers.h" +#include "atf-c/detail/text.h" /* --------------------------------------------------------------------- * Auxiliary functions. @@ -837,7 +835,6 @@ ATF_TC_BODY(msg_embedded_fmt, tc) * Tests cases for the header file. * --------------------------------------------------------------------- */ -HEADER_TC(include, "atf-c/macros.h"); BUILD_TC(use, "macros_h_test.c", "Tests that the macros provided by the atf-c/macros.h file " "do not cause syntax errors when used", @@ -889,7 +886,6 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, msg_embedded_fmt); /* Add the test cases for the header file. */ - ATF_TP_ADD_TC(tp, include); ATF_TP_ADD_TC(tp, use); ATF_TP_ADD_TC(tp, detect_unused_tests); diff --git a/contrib/atf/atf-c/pkg_config_test.sh b/contrib/atf/atf-c/pkg_config_test.sh index d913ec9..ddffdb0 100644 --- a/contrib/atf/atf-c/pkg_config_test.sh +++ b/contrib/atf/atf-c/pkg_config_test.sh @@ -1,6 +1,3 @@ -# -# Automated Testing Framework (atf) -# # Copyright (c) 2008 The NetBSD Foundation, Inc. # All rights reserved. # @@ -25,7 +22,6 @@ # IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN # IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# # The following tests assume that the atf-c.pc file is installed in a # directory that is known by pkg-config. Otherwise they will fail, diff --git a/contrib/atf/atf-c/tc.c b/contrib/atf/atf-c/tc.c index cbdd00c..92c3e12 100644 --- a/contrib/atf/atf-c/tc.c +++ b/contrib/atf/atf-c/tc.c @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2008 The NetBSD Foundation, Inc. +/* Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,8 +21,9 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +#include "atf-c/tc.h" #include <sys/types.h> #include <sys/stat.h> @@ -41,14 +39,12 @@ #include <unistd.h> #include "atf-c/defs.h" +#include "atf-c/detail/env.h" +#include "atf-c/detail/fs.h" +#include "atf-c/detail/map.h" +#include "atf-c/detail/sanity.h" +#include "atf-c/detail/text.h" #include "atf-c/error.h" -#include "atf-c/tc.h" - -#include "detail/env.h" -#include "detail/fs.h" -#include "detail/map.h" -#include "detail/sanity.h" -#include "detail/text.h" /* --------------------------------------------------------------------- * Auxiliary functions. diff --git a/contrib/atf/atf-c/tc.h b/contrib/atf/atf-c/tc.h index 3f24186..3fb6955 100644 --- a/contrib/atf/atf-c/tc.h +++ b/contrib/atf/atf-c/tc.h @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2008 The NetBSD Foundation, Inc. +/* Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,8 +21,7 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #if !defined(ATF_C_TC_H) #define ATF_C_TC_H @@ -137,4 +133,4 @@ void atf_tc_check_errno(const char *, const size_t, const int, void atf_tc_require_errno(const char *, const size_t, const int, const char *, const bool); -#endif /* ATF_C_TC_H */ +#endif /* !defined(ATF_C_TC_H) */ diff --git a/contrib/atf/atf-c/tc_test.c b/contrib/atf/atf-c/tc_test.c index 4aaf9a5..616c37e 100644 --- a/contrib/atf/atf-c/tc_test.c +++ b/contrib/atf/atf-c/tc_test.c @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2008 The NetBSD Foundation, Inc. +/* Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,15 +21,16 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +#include "atf-c/tc.h" #include <stdbool.h> #include <string.h> #include <atf-c.h> -#include "detail/test_helpers.h" +#include "atf-c/detail/test_helpers.h" /* --------------------------------------------------------------------- * Auxiliary test cases. @@ -167,12 +165,6 @@ ATF_TC_BODY(config, tcin) * testing done later on. */ /* --------------------------------------------------------------------- - * Tests cases for the header file. - * --------------------------------------------------------------------- */ - -HEADER_TC(include, "atf-c/tc.h"); - -/* --------------------------------------------------------------------- * Main. * --------------------------------------------------------------------- */ @@ -187,8 +179,5 @@ ATF_TP_ADD_TCS(tp) /* Add the test cases for the free functions. */ /* TODO */ - /* Add the test cases for the header file. */ - ATF_TP_ADD_TC(tp, include); - return atf_no_error(); } diff --git a/contrib/atf/atf-c/tp.c b/contrib/atf/atf-c/tp.c index 7833498..f4f2257 100644 --- a/contrib/atf/atf-c/tp.c +++ b/contrib/atf/atf-c/tp.c @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2008 The NetBSD Foundation, Inc. +/* Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,21 +21,20 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +#include "atf-c/tp.h" #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> +#include "atf-c/detail/fs.h" +#include "atf-c/detail/map.h" +#include "atf-c/detail/sanity.h" #include "atf-c/error.h" #include "atf-c/tc.h" -#include "atf-c/tp.h" - -#include "detail/fs.h" -#include "detail/map.h" -#include "detail/sanity.h" struct atf_tp_impl { atf_list_t m_tcs; diff --git a/contrib/atf/atf-c/tp.h b/contrib/atf/atf-c/tp.h index e4f9ba4..c176f7d 100644 --- a/contrib/atf/atf-c/tp.h +++ b/contrib/atf/atf-c/tp.h @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2008 The NetBSD Foundation, Inc. +/* Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,8 +21,7 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #if !defined(ATF_C_TP_H) #define ATF_C_TP_H @@ -66,4 +62,4 @@ atf_error_t atf_tp_add_tc(atf_tp_t *, struct atf_tc *); atf_error_t atf_tp_run(const atf_tp_t *, const char *, const char *); atf_error_t atf_tp_cleanup(const atf_tp_t *, const char *); -#endif /* ATF_C_TP_H */ +#endif /* !defined(ATF_C_TP_H) */ diff --git a/contrib/atf/atf-c/tp_test.c b/contrib/atf/atf-c/tp_test.c index 5da18b2..de334a9 100644 --- a/contrib/atf/atf-c/tp_test.c +++ b/contrib/atf/atf-c/tp_test.c @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2010 The NetBSD Foundation, Inc. +/* Copyright (c) 2010 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,16 +21,15 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +#include "atf-c/tp.h" #include <string.h> #include <unistd.h> #include <atf-c.h> -#include "detail/test_helpers.h" - ATF_TC(getopt); ATF_TC_HEAD(getopt, tc) { @@ -81,12 +77,6 @@ ATF_TC_BODY(getopt, tc) } /* --------------------------------------------------------------------- - * Tests cases for the header file. - * --------------------------------------------------------------------- */ - -HEADER_TC(include, "atf-c/tp.h"); - -/* --------------------------------------------------------------------- * Main. * --------------------------------------------------------------------- */ @@ -94,8 +84,5 @@ ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, getopt); - /* Add the test cases for the header file. */ - ATF_TP_ADD_TC(tp, include); - return atf_no_error(); } diff --git a/contrib/atf/atf-c/unused_test.c b/contrib/atf/atf-c/unused_test.c index e8de682..1c5fda9 100644 --- a/contrib/atf/atf-c/unused_test.c +++ b/contrib/atf/atf-c/unused_test.c @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2012 The NetBSD Foundation, Inc. +/* Copyright (c) 2012 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,10 +21,9 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include <atf-c/macros.h> +#include <atf-c.h> ATF_TC(this_is_used); ATF_TC_HEAD(this_is_used, tc) diff --git a/contrib/atf/atf-c/utils.c b/contrib/atf/atf-c/utils.c index 4409f7a..1e2aac1 100644 --- a/contrib/atf/atf-c/utils.c +++ b/contrib/atf/atf-c/utils.c @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2010 The NetBSD Foundation, Inc. +/* Copyright (c) 2010 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,8 +21,7 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "atf-c/utils.h" @@ -43,7 +39,35 @@ #include <atf-c.h> -#include "detail/dynstr.h" +#include "atf-c/detail/dynstr.h" + +/** Allocate a filename to be used by atf_utils_{fork,wait}. + * + * In case of a failure, marks the calling test as failed when in_parent is + * true, else terminates execution. + * + * \param [out] name String to contain the generated file. + * \param pid PID of the process that will write to the file. + * \param suffix Either "out" or "err". + * \param in_parent If true, fail with atf_tc_fail; else use err(3). */ +static void +init_out_filename(atf_dynstr_t *name, const pid_t pid, const char *suffix, + const bool in_parent) +{ + atf_error_t error; + + error = atf_dynstr_init_fmt(name, "atf_utils_fork_%d_%s.txt", + (int)pid, suffix); + if (atf_is_error(error)) { + char buffer[1024]; + atf_error_format(error, buffer, sizeof(buffer)); + if (in_parent) { + atf_tc_fail("Failed to create output file: %s", buffer); + } else { + err(EXIT_FAILURE, "Failed to create output file: %s", buffer); + } + } +} /** Searches for a regexp in a string. * @@ -232,8 +256,17 @@ atf_utils_fork(void) atf_tc_fail("fork failed"); if (pid == 0) { - atf_utils_redirect(STDOUT_FILENO, "atf_utils_fork_out.txt"); - atf_utils_redirect(STDERR_FILENO, "atf_utils_fork_err.txt"); + atf_dynstr_t out_name; + init_out_filename(&out_name, getpid(), "out", false); + + atf_dynstr_t err_name; + init_out_filename(&err_name, getpid(), "err", false); + + atf_utils_redirect(STDOUT_FILENO, atf_dynstr_cstring(&out_name)); + atf_utils_redirect(STDERR_FILENO, atf_dynstr_cstring(&err_name)); + + atf_dynstr_fini(&err_name); + atf_dynstr_fini(&out_name); } return pid; } @@ -385,8 +418,14 @@ atf_utils_wait(const pid_t pid, const int exitstatus, const char *expout, int status; ATF_REQUIRE(waitpid(pid, &status, 0) != -1); - atf_utils_cat_file("atf_utils_fork_out.txt", "subprocess stdout: "); - atf_utils_cat_file("atf_utils_fork_err.txt", "subprocess stderr: "); + atf_dynstr_t out_name; + init_out_filename(&out_name, pid, "out", true); + + atf_dynstr_t err_name; + init_out_filename(&err_name, pid, "err", true); + + atf_utils_cat_file(atf_dynstr_cstring(&out_name), "subprocess stdout: "); + atf_utils_cat_file(atf_dynstr_cstring(&err_name), "subprocess stderr: "); ATF_REQUIRE(WIFEXITED(status)); ATF_REQUIRE_EQ(exitstatus, WEXITSTATUS(status)); @@ -396,20 +435,22 @@ atf_utils_wait(const pid_t pid, const int exitstatus, const char *expout, if (strlen(expout) > save_prefix_length && strncmp(expout, save_prefix, save_prefix_length) == 0) { - atf_utils_copy_file("atf_utils_fork_out.txt", + atf_utils_copy_file(atf_dynstr_cstring(&out_name), expout + save_prefix_length); } else { - ATF_REQUIRE(atf_utils_compare_file("atf_utils_fork_out.txt", expout)); + ATF_REQUIRE(atf_utils_compare_file(atf_dynstr_cstring(&out_name), + expout)); } if (strlen(experr) > save_prefix_length && strncmp(experr, save_prefix, save_prefix_length) == 0) { - atf_utils_copy_file("atf_utils_fork_err.txt", + atf_utils_copy_file(atf_dynstr_cstring(&err_name), experr + save_prefix_length); } else { - ATF_REQUIRE(atf_utils_compare_file("atf_utils_fork_err.txt", experr)); + ATF_REQUIRE(atf_utils_compare_file(atf_dynstr_cstring(&err_name), + experr)); } - ATF_REQUIRE(unlink("atf_utils_fork_out.txt") != -1); - ATF_REQUIRE(unlink("atf_utils_fork_err.txt") != -1); + ATF_REQUIRE(unlink(atf_dynstr_cstring(&out_name)) != -1); + ATF_REQUIRE(unlink(atf_dynstr_cstring(&err_name)) != -1); } diff --git a/contrib/atf/atf-c/utils.h b/contrib/atf/atf-c/utils.h index 666804d..e4162b2 100644 --- a/contrib/atf/atf-c/utils.h +++ b/contrib/atf/atf-c/utils.h @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2010 The NetBSD Foundation, Inc. +/* Copyright (c) 2010 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,8 +21,7 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #if !defined(ATF_C_UTILS_H) #define ATF_C_UTILS_H @@ -51,4 +47,4 @@ char *atf_utils_readline(int); void atf_utils_redirect(const int, const char *); void atf_utils_wait(const pid_t, const int, const char *, const char *); -#endif /* ATF_C_UTILS_H */ +#endif /* !defined(ATF_C_UTILS_H) */ diff --git a/contrib/atf/atf-c/utils_test.c b/contrib/atf/atf-c/utils_test.c index 57d6af8..fb81cd3 100644 --- a/contrib/atf/atf-c/utils_test.c +++ b/contrib/atf/atf-c/utils_test.c @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2010 The NetBSD Foundation, Inc. +/* Copyright (c) 2010 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,8 +21,9 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +#include "atf-c/utils.h" #include <sys/stat.h> #include <sys/wait.h> @@ -39,9 +37,8 @@ #include <atf-c.h> -#include "atf-c/utils.h" - -#include "detail/test_helpers.h" +#include "atf-c/detail/dynstr.h" +#include "atf-c/detail/test_helpers.h" /** Reads the contents of a file into a buffer. * @@ -246,11 +243,19 @@ ATF_TC_BODY(fork, tc) ATF_REQUIRE(WIFEXITED(status)); ATF_REQUIRE_EQ(EXIT_SUCCESS, WEXITSTATUS(status)); + atf_dynstr_t out_name; + RE(atf_dynstr_init_fmt(&out_name, "atf_utils_fork_%d_out.txt", (int)pid)); + atf_dynstr_t err_name; + RE(atf_dynstr_init_fmt(&err_name, "atf_utils_fork_%d_err.txt", (int)pid)); + char buffer[1024]; - read_file("atf_utils_fork_out.txt", buffer, sizeof(buffer)); + read_file(atf_dynstr_cstring(&out_name), buffer, sizeof(buffer)); ATF_REQUIRE_STREQ("Child stdout\n", buffer); - read_file("atf_utils_fork_err.txt", buffer, sizeof(buffer)); + read_file(atf_dynstr_cstring(&err_name), buffer, sizeof(buffer)); ATF_REQUIRE_STREQ("Child stderr\n", buffer); + + atf_dynstr_fini(&err_name); + atf_dynstr_fini(&out_name); } ATF_TC_WITHOUT_HEAD(free_charpp__empty); @@ -384,6 +389,7 @@ static void fork_and_wait(const int exitstatus, const char* expout, const char* experr) { const pid_t pid = atf_utils_fork(); + ATF_REQUIRE(pid != -1); if (pid == 0) { fprintf(stdout, "Some output\n"); fprintf(stderr, "Some error\n"); @@ -408,6 +414,35 @@ ATF_TC_BODY(wait__ok, tc) } } +ATF_TC_WITHOUT_HEAD(wait__ok_nested); +ATF_TC_BODY(wait__ok_nested, tc) +{ + const pid_t parent = atf_utils_fork(); + ATF_REQUIRE(parent != -1); + if (parent == 0) { + const pid_t child = atf_utils_fork(); + ATF_REQUIRE(child != -1); + if (child == 0) { + fflush(stderr); + fprintf(stdout, "Child output\n"); + fflush(stdout); + fprintf(stderr, "Child error\n"); + exit(50); + } else { + fprintf(stdout, "Parent output\n"); + fprintf(stderr, "Parent error\n"); + atf_utils_wait(child, 50, "Child output\n", "Child error\n"); + exit(40); + } + } else { + atf_utils_wait(parent, 40, + "Parent output\n" + "subprocess stdout: Child output\n" + "subprocess stderr: Child error\n", + "Parent error\n"); + } +} + ATF_TC_WITHOUT_HEAD(wait__invalid_exitstatus); ATF_TC_BODY(wait__invalid_exitstatus, tc) { @@ -487,8 +522,6 @@ ATF_TC_BODY(wait__save_stderr, tc) } } -HEADER_TC(include, "atf-c/utils.h"); - ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, cat_file__empty); @@ -526,13 +559,12 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, redirect__other); ATF_TP_ADD_TC(tp, wait__ok); + ATF_TP_ADD_TC(tp, wait__ok_nested); ATF_TP_ADD_TC(tp, wait__save_stdout); ATF_TP_ADD_TC(tp, wait__save_stderr); ATF_TP_ADD_TC(tp, wait__invalid_exitstatus); ATF_TP_ADD_TC(tp, wait__invalid_stdout); ATF_TP_ADD_TC(tp, wait__invalid_stderr); - ATF_TP_ADD_TC(tp, include); - return atf_no_error(); } |