diff --git a/ObsoleteFiles.inc b/ObsoleteFiles.inc index 789822520910..7c8f8987f505 100644 --- a/ObsoleteFiles.inc +++ b/ObsoleteFiles.inc @@ -374,7 +374,6 @@ OLD_FILES+=usr/share/man/man1/atf-report.1.gz OLD_FILES+=usr/share/man/man1/atf-run.1.gz OLD_FILES+=usr/share/man/man1/atf-version.1.gz OLD_FILES+=usr/share/man/man5/atf-formats.5.gz -OLD_FILES+=usr/share/man/man7/atf.7.gz OLD_FILES+=usr/share/xml/atf/tests-results.dtd OLD_FILES+=usr/share/xsl/atf/tests-results.xsl # 20131009: freebsd-version moved from /libexec to /bin diff --git a/contrib/atf/FREEBSD-Xlist b/contrib/atf/FREEBSD-Xlist index 5af9ed5e9aac..05ea871eb95c 100644 --- a/contrib/atf/FREEBSD-Xlist +++ b/contrib/atf/FREEBSD-Xlist @@ -1,22 +1,12 @@ -*/*/Atffile */*/Makefile* -*/Atffile */Makefile* */*.m4 */*.pc.in -Atffile INSTALL Makefile* aclocal.m4 admin/ -atf-config/ -atf-report/ -atf-run/ -atf-version/ -bconfig.h.in +config.h.in bootstrap/ configure* -doc/atf-formats.5 -doc/atf.7.in m4/ -tools/ diff --git a/contrib/atf/NEWS b/contrib/atf/NEWS index 7a7ed2fb9d02..f1764e0d9dda 100644 --- a/contrib/atf/NEWS +++ b/contrib/atf/NEWS @@ -1,6 +1,62 @@ Major changes between releases Automated Testing Framework =========================================================================== +Changes in version 0.21 +*********************** + +Released on October 23rd, 2014. + +* Restored the atf(7) manual page to serve as a reference to all the other + manual pages shipped by ATF. + +* Added the -s flag to atf-sh to support specifying the shell interpreter + to be used. + +* Removed ATF_WORKDIR. The only remaining consumers have been converted to + use the standard TMPDIR environment variable. As a benefit, and because + Kyua forces the TMPDIR to live within the test case's work directory, + any stale files left behind by ATF will be automatically cleaned up. + +* Documented the environment variables recognized by each component in the + relevant manual pages. This information was lost with the atf-config(1) + removal. + +* Added a new "require.diskspace" metadata property to test cases so that + they can specify the minimum amount of disk space required for the test + to run. + +* Renamed the atf-{c,c++,sh}-api(3) manual pages to atf-{c,c++,sh}(3) for + discoverability purposes. Symbolic links are provided for the time + being to still make the old names visible. + +* Issue #5: Recommend the (expected, actual) idiom for calls to the test + macros in the manual pages. + +* Issue #7: Stopped catching unhandled exceptions in atf-c++ tests. This + propagates the crash to the caller, which in turn allows it to obtain + proper debugging information. In particular, Kyua should now be able to + extract a stacktrace pinpointing the problem. + +* Issue #8: Fixed atf-c/macros_test:use test failures spotted by the clang + that ships with FreeBSD 11.0-CURRENT. + +* Issue #12: Improved documentation of atf-sh(3) and atf-check(1) by better + explaining how they relate to each other. + +* Issue #14: Stopped setting 'set -e' in atf-sh. This setting was + initially added as a way to enable a "strict" mode in the library and to + make test cases fail fast when they run unprotected commands. However, + doing so in the library is surprising as the responsibility of enabling + 'set -e' should be on the user's code. Also, 'set -e' introduces + inconsistent behavior on subshells and users do not expect that. + +* Issue #15: Fixed atf_utils_{fork,wait} to support nested calls. + +* Issue #16: Fixed test failures (by removing a long-standing hack) on + systems that lack \e support in printf(1). + +* Issue #19: Removed stale references to atf-config and atf-run. + Changes in version 0.20 *********************** diff --git a/contrib/atf/atf-c++.hpp b/contrib/atf/atf-c++.hpp index e915aef20164..747353dd1319 100644 --- a/contrib/atf/atf-c++.hpp +++ b/contrib/atf/atf-c++.hpp @@ -1,6 +1,3 @@ -// -// Automated Testing Framework (atf) -// // Copyright (c) 2007 The NetBSD Foundation, Inc. // All rights reserved. // @@ -25,12 +22,11 @@ // 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_CXX_HPP_) -#define _ATF_CXX_HPP_ +#if !defined(ATF_CXX_HPP) +#define ATF_CXX_HPP #include #include -#endif // !defined(_ATF_CXX_HPP_) +#endif // !defined(ATF_CXX_HPP) diff --git a/contrib/atf/atf-c++/Kyuafile b/contrib/atf/atf-c++/Kyuafile index 6df836f27847..9fd43af76c4c 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="macros_test"} atf_test_program{name="pkg_config_test"} atf_test_program{name="tests_test"} diff --git a/contrib/atf/atf-c++/atf-c++.3 b/contrib/atf/atf-c++/atf-c++.3 new file mode 100644 index 000000000000..984ec936446a --- /dev/null +++ b/contrib/atf/atf-c++/atf-c++.3 @@ -0,0 +1,649 @@ +.\" 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_ADD_TEST_CASE , +.Nm ATF_CHECK_ERRNO , +.Nm ATF_FAIL , +.Nm ATF_INIT_TEST_CASES , +.Nm ATF_PASS , +.Nm ATF_REQUIRE , +.Nm ATF_REQUIRE_EQ , +.Nm ATF_REQUIRE_ERRNO , +.Nm ATF_REQUIRE_IN , +.Nm ATF_REQUIRE_MATCH , +.Nm ATF_REQUIRE_NOT_IN , +.Nm ATF_REQUIRE_THROW , +.Nm ATF_REQUIRE_THROW_RE , +.Nm ATF_SKIP , +.Nm ATF_TEST_CASE , +.Nm ATF_TEST_CASE_BODY , +.Nm ATF_TEST_CASE_CLEANUP , +.Nm ATF_TEST_CASE_HEAD , +.Nm ATF_TEST_CASE_NAME , +.Nm ATF_TEST_CASE_USE , +.Nm ATF_TEST_CASE_WITH_CLEANUP , +.Nm ATF_TEST_CASE_WITHOUT_HEAD , +.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::grep_collection , +.Nm atf::utils::grep_file , +.Nm atf::utils::grep_string , +.Nm atf::utils::redirect , +.Nm atf::utils::wait +.Nd C++ API to write ATF-based test programs +.Sh SYNOPSIS +.In atf-c++.hpp +.Fn ATF_ADD_TEST_CASE "tcs" "name" +.Fn ATF_CHECK_ERRNO "expected_errno" "bool_expression" +.Fn ATF_FAIL "reason" +.Fn ATF_INIT_TEST_CASES "tcs" +.Fn ATF_PASS +.Fn ATF_REQUIRE "expression" +.Fn ATF_REQUIRE_EQ "expected_expression" "actual_expression" +.Fn ATF_REQUIRE_ERRNO "expected_errno" "bool_expression" +.Fn ATF_REQUIRE_IN "element" "collection" +.Fn ATF_REQUIRE_MATCH "regexp" "string_expression" +.Fn ATF_REQUIRE_NOT_IN "element" "collection" +.Fn ATF_REQUIRE_THROW "expected_exception" "statement" +.Fn ATF_REQUIRE_THROW_RE "expected_exception" "regexp" "statement" +.Fn ATF_SKIP "reason" +.Fn ATF_TEST_CASE "name" +.Fn ATF_TEST_CASE_BODY "name" +.Fn ATF_TEST_CASE_CLEANUP "name" +.Fn ATF_TEST_CASE_HEAD "name" +.Fn ATF_TEST_CASE_NAME "name" +.Fn ATF_TEST_CASE_USE "name" +.Fn ATF_TEST_CASE_WITH_CLEANUP "name" +.Fn ATF_TEST_CASE_WITHOUT_HEAD "name" +.Ft void +.Fo atf::utils::cat_file +.Fa "const std::string& path" +.Fa "const std::string& prefix" +.Fc +.Ft bool +.Fo atf::utils::compare_file +.Fa "const std::string& path" +.Fa "const std::string& contents" +.Fc +.Ft void +.Fo atf::utils::copy_file +.Fa "const std::string& source" +.Fa "const std::string& destination" +.Fc +.Ft void +.Fo atf::utils::create_file +.Fa "const std::string& path" +.Fa "const std::string& contents" +.Fc +.Ft void +.Fo atf::utils::file_exists +.Fa "const std::string& path" +.Fc +.Ft pid_t +.Fo atf::utils::fork +.Fa "void" +.Fc +.Ft bool +.Fo atf::utils::grep_collection +.Fa "const std::string& regexp" +.Fa "const Collection& collection" +.Fc +.Ft bool +.Fo atf::utils::grep_file +.Fa "const std::string& regexp" +.Fa "const std::string& path" +.Fc +.Ft bool +.Fo atf::utils::grep_string +.Fa "const std::string& regexp" +.Fa "const std::string& path" +.Fc +.Ft void +.Fo atf::utils::redirect +.Fa "const int fd" +.Fa "const std::string& path" +.Fc +.Ft void +.Fo atf::utils::wait +.Fa "const pid_t pid" +.Fa "const int expected_exit_status" +.Fa "const std::string& expected_stdout" +.Fa "const std::string& 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 +extern "C" { +.Ns ... C-specific includes go here ... +} + +.Ns ... C++-specific includes go here ... + +#include + +ATF_TEST_CASE(tc1); +ATF_TEST_CASE_HEAD(tc1) +{ + ... first test case's header ... +} +ATF_TEST_CASE_BODY(tc1) +{ + ... first test case's body ... +} + +ATF_TEST_CASE_WITH_CLEANUP(tc2); +ATF_TEST_CASE_HEAD(tc2) +{ + ... second test case's header ... +} +ATF_TEST_CASE_BODY(tc2) +{ + ... second test case's body ... +} +ATF_TEST_CASE_CLEANUP(tc2) +{ + ... second test case's cleanup ... +} + +ATF_TEST_CASE(tc3); +ATF_TEST_CASE_BODY(tc3) +{ + ... third test case's body ... +} + +.Ns ... additional test cases ... + +ATF_INIT_TEST_CASES(tcs) +{ + ATF_ADD_TEST_CASE(tcs, tc1); + ATF_ADD_TEST_CASE(tcs, tc2); + ATF_ADD_TEST_CASE(tcs, tc3); + ... add additional test cases ... +} +.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_TEST_CASE , +.Fn ATF_TEST_CASE_WITH_CLEANUP +or the +.Fn ATF_TEST_CASE_WITHOUT_HEAD +macros, which take a single parameter specifiying the test case's +name. +.Fn ATF_TEST_CASE , +requires to define a head and a body for the test case, +.Fn ATF_TEST_CASE_WITH_CLEANUP +requires to define a head, a body and a cleanup for the test case and +.Fn ATF_TEST_CASE_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 through the +.Fn ATF_ADD_TEST_CASE +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_TEST_CASE_HEAD , +.Fn ATF_TEST_CASE_BODY +and +.Fn ATF_TEST_CASE_CLEANUP +macros, all of which take the test case's name. +Following each of these, a block of code is expected, surrounded by the +opening and closing brackets. +.Pp +Additionally, the +.Fn ATF_TEST_CASE_NAME +macro can be used to obtain the name of the class corresponding to a +particular test case, as the name is internally manged by the library to +prevent clashes with other user identifiers. +Similarly, the +.Fn ATF_TEST_CASE_USE +macro can be executed on a particular test case to mark it as "used" and +thus prevent compiler warnings regarding unused symbols. +Note that +.Em you should never have to use these macros during regular operation. +.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_INIT_TEST_CASES +macro, which is passed the name of the list that will hold the test cases. +This name can be whatever you want as long as it is a valid variable value. +.Pp +After the macro, you are supposed to provide the body of a function, which +should only use the +.Fn ATF_ADD_TEST_CASE +macro to register the test cases the test program will execute. +The first parameter of this macro matches the name you provided in the +former call. +.Ss Header definitions +The test case's header can define the meta-data by using the +.Fn set_md_var +method, which takes two parameters: the first one specifies the +meta-data variable to be set and the second 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 has_config_var +and the +.Ft std::string +.Fn get_config_var +methods, which can be called in any of the three parts of a test case. +.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 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 , +or at any explicit call to +.Fn ATF_PASS , +.Fn ATF_FAIL +or +.Fn ATF_SKIP . +These three macros 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_PASS +does not take any parameters. +.Fn ATF_FAIL +and +.Fn ATF_SKIP +take a single string that describes 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 expect_death "reason" +Expects the test case to exit prematurely regardless of the nature of the +exit. +.It Fn 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 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 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 expect_race "reason" +Any failure or timeout during the execution of the test case will be +considered as if a race condition has been triggered and reported as such. +If no problems arise, the test will continue execution as usual. +.It Fn 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 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 +automatically call +.Fn ATF_FAIL +with an appropriate error message. +.Pp +.Fn ATF_REQUIRE +takes an expression and raises a failure if it evaluates to false. +.Pp +.Fn ATF_REQUIRE_EQ +takes two expressions and raises a failure if the two do not evaluate to +the same exact value. +The common style is to put the expected value in the first parameter and the +actual value in the second parameter. +.Pp +.Fn ATF_REQUIRE_IN +takes an element and a collection and validates that the element is present in +the collection. +.Pp +.Fn ATF_REQUIRE_MATCH +takes a regular expression and a string and raises a failure if the regular +expression does not match the string. +.Pp +.Fn ATF_REQUIRE_NOT_IN +takes an element and a collection and validates that the element is not present +in the collection. +.Pp +.Fn ATF_REQUIRE_THROW +takes the name of an exception and a statement and raises a failure if +the statement does not throw the specified exception. +.Fn ATF_REQUIRE_THROW_RE +takes the name of an exception, a regular expresion and a statement and raises a +failure if the statement does not throw the specified exception and if the +message of the exception does not match the regular expression. +.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 std::string& path" +.Fa "const std::string& prefix" +.Fc +.Bd -ragged -offset indent +Prints the contents of +.Fa path +to the standard output, prefixing every line with the string in +.Fa prefix . +.Ed +.Pp +.Ft bool +.Fo atf::utils::compare_file +.Fa "const std::string& path" +.Fa "const std::string& contents" +.Fc +.Bd -ragged -offset indent +Returns true if the given +.Fa path +matches exactly the expected inlined +.Fa contents . +.Ed +.Pp +.Ft void +.Fo atf::utils::copy_file +.Fa "const std::string& source" +.Fa "const std::string& 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 std::string& path" +.Fa "const std::string& contents" +.Fc +.Bd -ragged -offset indent +Creates +.Fa file +with the text given in +.Fa contents . +.Ed +.Pp +.Ft void +.Fo atf::utils::file_exists +.Fa "const std::string& path" +.Fc +.Bd -ragged -offset indent +Checks if +.Fa path +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 bool +.Fo atf::utils::grep_collection +.Fa "const std::string& regexp" +.Fa "const Collection& collection" +.Fc +.Bd -ragged -offset indent +Searches for the regular expression +.Fa regexp +in any of the strings contained in the +.Fa collection . +This is a template that accepts any one-dimensional container of strings. +.Ed +.Pp +.Ft bool +.Fo atf::utils::grep_file +.Fa "const std::string& regexp" +.Fa "const std::string& path" +.Fc +.Bd -ragged -offset indent +Searches for the regular expression +.Fa regexp +in the file +.Fa path . +The variable arguments are used to construct the regular expression. +.Ed +.Pp +.Ft bool +.Fo atf::utils::grep_string +.Fa "const std::string& regexp" +.Fa "const std::string& str" +.Fc +.Bd -ragged -offset indent +Searches for the regular expression +.Fa regexp +in the string +.Fa str . +.Ed +.Ft void +.Fo atf::utils::redirect +.Fa "const int fd" +.Fa "const std::string& path" +.Fc +.Bd -ragged -offset indent +Redirects the given file descriptor +.Fa fd +to the file +.Fa path . +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 std::string& expected_stdout" +.Fa "const std::string& 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_TEST_CASE(addition); +ATF_TEST_CASE_HEAD(addition) +{ + set_md_var("descr", "Sample tests for the addition operator"); +} +ATF_TEST_CASE_BODY(addition) +{ + ATF_REQUIRE_EQ(0, 0 + 0); + ATF_REQUIRE_EQ(1, 0 + 1); + ATF_REQUIRE_EQ(1, 1 + 0); + + ATF_REQUIRE_EQ(2, 1 + 1); + + ATF_REQUIRE_EQ(300, 100 + 200); +} + +ATF_TEST_CASE(open_failure); +ATF_TEST_CASE_HEAD(open_failure) +{ + set_md_var("descr", "Sample tests for the open function"); +} +ATF_TEST_CASE_BODY(open_failure) +{ + ATF_REQUIRE_ERRNO(ENOENT, open("non-existent", O_RDONLY) == -1); +} + +ATF_TEST_CASE(known_bug); +ATF_TEST_CASE_HEAD(known_bug) +{ + set_md_var("descr", "Reproduces a known bug"); +} +ATF_TEST_CASE_BODY(known_bug) +{ + expect_fail("See bug number foo/bar"); + ATF_REQUIRE_EQ(3, 1 + 1); + expect_pass(); + ATF_REQUIRE_EQ(3, 1 + 2); +} + +ATF_INIT_TEST_CASES(tcs) +{ + ATF_ADD_TEST_CASE(tcs, addition); + ATF_ADD_TEST_CASE(tcs, open_failure); + ATF_ADD_TEST_CASE(tcs, known_bug); +} +.Ed +.Sh SEE ALSO +.Xr atf-test-program 1 , +.Xr atf-test-case 4 diff --git a/contrib/atf/atf-c++/atf_c++_test.cpp b/contrib/atf/atf-c++/atf_c++_test.cpp index c09e4b1019bb..cc708863f6cf 100644 --- a/contrib/atf/atf-c++/atf_c++_test.cpp +++ b/contrib/atf/atf-c++/atf_c++_test.cpp @@ -1,6 +1,3 @@ -// -// Automated Testing Framework (atf) -// // Copyright (c) 2009 The NetBSD Foundation, Inc. // All rights reserved. // @@ -25,11 +22,10 @@ // 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 "macros.hpp" +#include -#include "detail/test_helpers.hpp" +#include "atf-c++/detail/test_helpers.hpp" // ------------------------------------------------------------------------ // Tests cases for the header file. diff --git a/contrib/atf/atf-c++/build.cpp b/contrib/atf/atf-c++/build.cpp index 9ce134c8e9b8..f2f80f4eb453 100644 --- a/contrib/atf/atf-c++/build.cpp +++ b/contrib/atf/atf-c++/build.cpp @@ -1,6 +1,3 @@ -// -// Automated Testing Framework (atf) -// // Copyright (c) 2009 The NetBSD Foundation, Inc. // All rights reserved. // @@ -25,7 +22,8 @@ // 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 "atf-c++/build.hpp" extern "C" { #include "atf-c/build.h" @@ -33,10 +31,8 @@ extern "C" { #include "atf-c/utils.h" } -#include "build.hpp" - -#include "detail/exceptions.hpp" -#include "detail/process.hpp" +#include "atf-c++/detail/exceptions.hpp" +#include "atf-c++/detail/process.hpp" namespace impl = atf::build; #define IMPL_NAME "atf::build" diff --git a/contrib/atf/atf-c++/build.hpp b/contrib/atf/atf-c++/build.hpp index 5a291b4cc879..7aa5a978d99a 100644 --- a/contrib/atf/atf-c++/build.hpp +++ b/contrib/atf/atf-c++/build.hpp @@ -1,6 +1,3 @@ -// -// Automated Testing Framework (atf) -// // Copyright (c) 2009 The NetBSD Foundation, Inc. // All rights reserved. // @@ -25,10 +22,9 @@ // 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_CXX_BUILD_HPP_) -#define _ATF_CXX_BUILD_HPP_ +#if !defined(ATF_CXX_BUILD_HPP) +#define ATF_CXX_BUILD_HPP #include @@ -54,4 +50,4 @@ process::argv_array cxx_o(const std::string&, const std::string&, } // namespace build } // namespace atf -#endif // !defined(_ATF_CXX_BUILD_HPP_) +#endif // !defined(ATF_CXX_BUILD_HPP) diff --git a/contrib/atf/atf-c++/build_test.cpp b/contrib/atf/atf-c++/build_test.cpp index 68529053940e..0a5ab9668af0 100644 --- a/contrib/atf/atf-c++/build_test.cpp +++ b/contrib/atf/atf-c++/build_test.cpp @@ -1,6 +1,3 @@ -// -// Automated Testing Framework (atf) -// // Copyright (c) 2009 The NetBSD Foundation, Inc. // All rights reserved. // @@ -25,31 +22,25 @@ // 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 "atf-c++/build.hpp" #include #include -#include "../atf-c/h_build.h" +#include -#include "build.hpp" -#include "config.hpp" -#include "macros.hpp" +extern "C" { +#include "atf-c/h_build.h" +} -#include "detail/env.hpp" -#include "detail/process.hpp" -#include "detail/test_helpers.hpp" +#include "atf-c++/detail/env.hpp" +#include "atf-c++/detail/process.hpp" // ------------------------------------------------------------------------ // Auxiliary functions. // ------------------------------------------------------------------------ -namespace atf { - namespace config { - void __reinit(void); - } -} - template< class C > void print_col(const char* prefix, const C& c) @@ -168,7 +159,6 @@ ATF_TEST_CASE_BODY(c_o) 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(); atf::process::argv_array argv = atf::build::c_o(test->sfile, test->ofile, @@ -190,7 +180,6 @@ ATF_TEST_CASE_BODY(cpp) verbose_set_env("ATF_BUILD_CPP", test->cpp); verbose_set_env("ATF_BUILD_CPPFLAGS", test->cppflags); - atf::config::__reinit(); atf::process::argv_array argv = atf::build::cpp(test->sfile, test->ofile, @@ -213,7 +202,6 @@ ATF_TEST_CASE_BODY(cxx_o) 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(); atf::process::argv_array argv = atf::build::cxx_o(test->sfile, test->ofile, @@ -222,12 +210,6 @@ ATF_TEST_CASE_BODY(cxx_o) } } -// ------------------------------------------------------------------------ -// Tests cases for the header file. -// ------------------------------------------------------------------------ - -HEADER_TC(include, "atf-c++/build.hpp"); - // ------------------------------------------------------------------------ // Main. // ------------------------------------------------------------------------ @@ -241,7 +223,4 @@ ATF_INIT_TEST_CASES(tcs) ATF_ADD_TEST_CASE(tcs, c_o); ATF_ADD_TEST_CASE(tcs, cpp); ATF_ADD_TEST_CASE(tcs, cxx_o); - - // Add the test cases for the header file. - ATF_ADD_TEST_CASE(tcs, include); } diff --git a/contrib/atf/atf-c++/check.cpp b/contrib/atf/atf-c++/check.cpp index b099b07a753a..e4d7db4d49a6 100644 --- a/contrib/atf/atf-c++/check.cpp +++ b/contrib/atf/atf-c++/check.cpp @@ -1,6 +1,3 @@ -// -// Automated Testing Framework (atf) -// // Copyright (c) 2007 The NetBSD Foundation, Inc. // All rights reserved. // @@ -25,7 +22,8 @@ // 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 "atf-c++/check.hpp" #include @@ -34,11 +32,9 @@ extern "C" { #include "atf-c/error.h" } -#include "check.hpp" - -#include "detail/exceptions.hpp" -#include "detail/process.hpp" -#include "detail/sanity.hpp" +#include "atf-c++/detail/exceptions.hpp" +#include "atf-c++/detail/process.hpp" +#include "atf-c++/detail/sanity.hpp" namespace impl = atf::check; #define IMPL_NAME "atf::check" diff --git a/contrib/atf/atf-c++/check.hpp b/contrib/atf/atf-c++/check.hpp index f838efb5adf1..0144dedb2841 100644 --- a/contrib/atf/atf-c++/check.hpp +++ b/contrib/atf/atf-c++/check.hpp @@ -1,6 +1,3 @@ -// -// Automated Testing Framework (atf) -// // Copyright (c) 2007 The NetBSD Foundation, Inc. // All rights reserved. // @@ -25,10 +22,9 @@ // 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_CXX_CHECK_HPP_) -#define _ATF_CXX_CHECK_HPP_ +#if !defined(ATF_CXX_CHECK_HPP) +#define ATF_CXX_CHECK_HPP extern "C" { #include @@ -132,4 +128,4 @@ check_result test_constructor(void); } // namespace check } // namespace atf -#endif // !defined(_ATF_CXX_CHECK_HPP_) +#endif // !defined(ATF_CXX_CHECK_HPP) diff --git a/contrib/atf/atf-c++/check_test.cpp b/contrib/atf/atf-c++/check_test.cpp index a92511c2f209..7baf3fa19692 100644 --- a/contrib/atf/atf-c++/check_test.cpp +++ b/contrib/atf/atf-c++/check_test.cpp @@ -1,6 +1,3 @@ -// -// Automated Testing Framework (atf) -// // Copyright (c) 2007 The NetBSD Foundation, Inc. // All rights reserved. // @@ -25,7 +22,8 @@ // 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 "atf-c++/check.hpp" extern "C" { #include @@ -43,14 +41,11 @@ extern "C" { #include -#include "check.hpp" -#include "config.hpp" -#include "utils.hpp" - -#include "detail/fs.hpp" -#include "detail/process.hpp" -#include "detail/test_helpers.hpp" -#include "detail/text.hpp" +#include "atf-c++/detail/fs.hpp" +#include "atf-c++/detail/process.hpp" +#include "atf-c++/detail/test_helpers.hpp" +#include "atf-c++/detail/text.hpp" +#include "atf-c++/utils.hpp" // ------------------------------------------------------------------------ // Auxiliary functions. @@ -374,7 +369,7 @@ ATF_TEST_CASE_HEAD(exec_unknown) ATF_TEST_CASE_BODY(exec_unknown) { std::vector< std::string > argv; - argv.push_back(atf::config::get("atf_workdir") + "/non-existent"); + argv.push_back("/foo/bar/non-existent"); atf::process::argv_array argva(argv); std::auto_ptr< atf::check::check_result > r = atf::check::exec(argva); @@ -382,12 +377,6 @@ ATF_TEST_CASE_BODY(exec_unknown) ATF_REQUIRE_EQ(r->exitcode(), 127); } -// ------------------------------------------------------------------------ -// Tests cases for the header file. -// ------------------------------------------------------------------------ - -HEADER_TC(include, "atf-c++/check.hpp"); - // ------------------------------------------------------------------------ // Main. // ------------------------------------------------------------------------ @@ -402,7 +391,4 @@ ATF_INIT_TEST_CASES(tcs) ATF_ADD_TEST_CASE(tcs, exec_exitstatus); ATF_ADD_TEST_CASE(tcs, exec_stdout_stderr); ATF_ADD_TEST_CASE(tcs, exec_unknown); - - // Add the test cases for the header file. - ATF_ADD_TEST_CASE(tcs, include); } diff --git a/contrib/atf/atf-c++/config.cpp b/contrib/atf/atf-c++/config.cpp deleted file mode 100644 index 1890ac0e66c7..000000000000 --- a/contrib/atf/atf-c++/config.cpp +++ /dev/null @@ -1,119 +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 - -extern "C" { -#include "atf-c/config.h" -} - -#include "config.hpp" - -#include "detail/env.hpp" -#include "detail/sanity.hpp" - -static std::map< std::string, std::string > m_variables; - -// -// Adds all predefined standard build-time variables to the m_variables -// map, considering the values a user may have provided in the environment. -// -// Can only be called once during the program's lifetime. -// -static -void -init_variables(void) -{ - PRE(m_variables.empty()); - - m_variables["atf_build_cc"] = atf_config_get("atf_build_cc"); - m_variables["atf_build_cflags"] = atf_config_get("atf_build_cflags"); - m_variables["atf_build_cpp"] = atf_config_get("atf_build_cpp"); - m_variables["atf_build_cppflags"] = atf_config_get("atf_build_cppflags"); - m_variables["atf_build_cxx"] = atf_config_get("atf_build_cxx"); - m_variables["atf_build_cxxflags"] = atf_config_get("atf_build_cxxflags"); - m_variables["atf_includedir"] = atf_config_get("atf_includedir"); - m_variables["atf_libexecdir"] = atf_config_get("atf_libexecdir"); - m_variables["atf_pkgdatadir"] = atf_config_get("atf_pkgdatadir"); - m_variables["atf_shell"] = atf_config_get("atf_shell"); - m_variables["atf_workdir"] = atf_config_get("atf_workdir"); - - POST(!m_variables.empty()); -} - -const std::string& -atf::config::get(const std::string& varname) -{ - if (m_variables.empty()) - init_variables(); - - PRE(has(varname)); - return m_variables[varname]; -} - -const std::map< std::string, std::string >& -atf::config::get_all(void) -{ - if (m_variables.empty()) - init_variables(); - - return m_variables; -} - -bool -atf::config::has(const std::string& varname) -{ - if (m_variables.empty()) - init_variables(); - - return m_variables.find(varname) != m_variables.end(); -} - -extern "C" { -void __atf_config_reinit(void); -} - -namespace atf { -namespace config { -// -// Auxiliary function for the t_config test program so that it can -// revert the configuration's global status to an empty state and -// do new tests from there on. -// -// Ideally this shouldn't be part of the production library... but -// this is so small that it does not matter. -// -void -__reinit(void) -{ - __atf_config_reinit(); - m_variables.clear(); -} -} // namespace config -} // namespace atf diff --git a/contrib/atf/atf-c++/config.hpp b/contrib/atf/atf-c++/config.hpp deleted file mode 100644 index e11b9bb21d20..000000000000 --- a/contrib/atf/atf-c++/config.hpp +++ /dev/null @@ -1,75 +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. -// - -#if !defined(_ATF_CXX_CONFIG_HPP_) -#define _ATF_CXX_CONFIG_HPP_ - -#include -#include - -namespace atf { - -namespace config { - -//! -//! \brief Gets a build-time configuration variable's value. -//! -//! Given the name of a build-time configuration variable, returns its -//! textual value. The user is free to override these by setting their -//! corresponding environment variables. Therefore always use this -//! interface to get the value of these variables. -//! -//! \pre The variable must exist. -//! -const std::string& get(const std::string&); - -//! -//! \brief Returns all the build-time configuration variables. -//! -//! Returns a name to value map containing all build-time configuration -//! variables. -//! -const std::map< std::string, std::string >& get_all(void); - -//! -//! \brief Checks whether a build-time configuration variable exists. -//! -//! Given the name of a build-time configuration variable, checks -//! whether it is defined and returns a boolean indicating this -//! condition. The program only has to use this function to sanity-check -//! a variable name provided by the user. Otherwise it can assume that -//! the variables are defined. -//! -bool has(const std::string&); - -} // namespace config - -} // namespace atf - -#endif // !defined(_ATF_CXX_CONFIG_HPP_) diff --git a/contrib/atf/atf-c++/config_test.cpp b/contrib/atf/atf-c++/config_test.cpp deleted file mode 100644 index 78e1584a5455..000000000000 --- a/contrib/atf/atf-c++/config_test.cpp +++ /dev/null @@ -1,227 +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 -#include - -#include "config.hpp" -#include "macros.hpp" - -#include "detail/env.hpp" -#include "detail/exceptions.hpp" -#include "detail/test_helpers.hpp" - -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. -// ------------------------------------------------------------------------ - -namespace atf { - namespace config { - void __reinit(void); - } -} - -static -void -set_env_var(const char* name, const char* val) -{ - try { - atf::env::set(name, val); - } catch (const atf::system_error&) { - ATF_FAIL(std::string("set_env_var(") + name + ", " + val + - ") failed"); - } -} - -static -void -unset_env_var(const char* name) -{ - try { - atf::env::unset(name); - } catch (const atf::system_error&) { - ATF_FAIL(std::string("unset_env_var(") + name + ") failed"); - } -} - -static -size_t -all_vars_count(void) -{ - size_t count = 0; - for (const struct varnames* v = all_vars; v->lc != NULL; v++) - count++; - return count; -} - -static -void -unset_all(void) -{ - for (const struct varnames* v = all_vars; v->lc != NULL; v++) - unset_env_var(v->uc); -} - -static -void -compare_one(const char* var, const char* expvalue) -{ - std::cout << "Checking that " << var << " is set to " << expvalue << "\n"; - - for (const struct varnames* v = all_vars; v->lc != NULL; v++) { - if (std::strcmp(v->lc, var) == 0) - ATF_REQUIRE_EQ(atf::config::get(v->lc), test_value); - else - ATF_REQUIRE(atf::config::get(v->lc) != test_value); - } -} - -// ------------------------------------------------------------------------ -// Test cases for the free functions. -// ------------------------------------------------------------------------ - -ATF_TEST_CASE(get); -ATF_TEST_CASE_HEAD(get) -{ - set_md_var("descr", "Tests the config::get function"); -} -ATF_TEST_CASE_BODY(get) -{ - // 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 (const struct varnames* v = all_vars; v->lc != NULL; v++) - ATF_REQUIRE(atf::config::get(v->lc) != test_value); - - // Test the behavior of empty values. - for (const struct varnames* v = all_vars; v->lc != NULL; v++) { - unset_all(); - if (!atf::config::get(v->lc).empty()) { - set_env_var(v->uc, ""); - atf::config::__reinit(); - if (v->can_be_empty) - ATF_REQUIRE(atf::config::get(v->lc).empty()); - else - ATF_REQUIRE(!atf::config::get(v->lc).empty()); - } - } - - // Check if the ATF_ARCH variable is recognized. - for (const struct varnames* v = all_vars; v->lc != NULL; v++) { - unset_all(); - set_env_var(v->uc, test_value); - atf::config::__reinit(); - compare_one(v->lc, test_value); - } -} - -ATF_TEST_CASE(get_all); -ATF_TEST_CASE_HEAD(get_all) -{ - set_md_var("descr", "Tests the config::get_all function"); -} -ATF_TEST_CASE_BODY(get_all) -{ - atf::config::__reinit(); - - // Check that the valid variables, and only those, are returned. - std::map< std::string, std::string > vars = atf::config::get_all(); - ATF_REQUIRE_EQ(vars.size(), all_vars_count()); - for (const struct varnames* v = all_vars; v->lc != NULL; v++) - ATF_REQUIRE(vars.find(v->lc) != vars.end()); -} - -ATF_TEST_CASE(has); -ATF_TEST_CASE_HEAD(has) -{ - set_md_var("descr", "Tests the config::has function"); -} -ATF_TEST_CASE_BODY(has) -{ - atf::config::__reinit(); - - // Check for all the variables that must exist. - for (const struct varnames* v = all_vars; v->lc != NULL; v++) - ATF_REQUIRE(atf::config::has(v->lc)); - - // Same as above, but using uppercase (which is incorrect). - for (const struct varnames* v = all_vars; v->lc != NULL; v++) - ATF_REQUIRE(!atf::config::has(v->uc)); - - // Check for some other variables that cannot exist. - ATF_REQUIRE(!atf::config::has("foo")); - ATF_REQUIRE(!atf::config::has("BAR")); - ATF_REQUIRE(!atf::config::has("atf_foo")); - ATF_REQUIRE(!atf::config::has("ATF_BAR")); - ATF_REQUIRE(!atf::config::has("atf_shel")); - ATF_REQUIRE(!atf::config::has("atf_shells")); -} - -// ------------------------------------------------------------------------ -// Tests cases for the header file. -// ------------------------------------------------------------------------ - -HEADER_TC(include, "atf-c++/config.hpp"); - -// ------------------------------------------------------------------------ -// Main. -// ------------------------------------------------------------------------ - -ATF_INIT_TEST_CASES(tcs) -{ - // Add the test cases for the free functions. - ATF_ADD_TEST_CASE(tcs, has); - ATF_ADD_TEST_CASE(tcs, get); - ATF_ADD_TEST_CASE(tcs, get_all); - - // Add the test cases for the header file. - ATF_ADD_TEST_CASE(tcs, include); -} diff --git a/contrib/atf/atf-c++/detail/Kyuafile b/contrib/atf/atf-c++/detail/Kyuafile index 03388bafc60e..fc799e64df69 100644 --- a/contrib/atf/atf-c++/detail/Kyuafile +++ b/contrib/atf/atf-c++/detail/Kyuafile @@ -8,5 +8,4 @@ atf_test_program{name="env_test"} atf_test_program{name="exceptions_test"} atf_test_program{name="fs_test"} atf_test_program{name="process_test"} -atf_test_program{name="sanity_test"} atf_test_program{name="text_test"} diff --git a/contrib/atf/atf-c++/detail/application.cpp b/contrib/atf/atf-c++/detail/application.cpp index 454bc64daf43..37086eb3ae8c 100644 --- a/contrib/atf/atf-c++/detail/application.cpp +++ b/contrib/atf/atf-c++/detail/application.cpp @@ -1,6 +1,3 @@ -// -// Automated Testing Framework (atf) -// // Copyright (c) 2007 The NetBSD Foundation, Inc. // All rights reserved. // @@ -25,10 +22,11 @@ // 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 "atf-c++/detail/application.hpp" #if defined(HAVE_CONFIG_H) -#include "bconfig.h" +#include "config.h" #endif extern "C" { @@ -45,8 +43,7 @@ extern "C" { #include "atf-c/defs.h" } -#include "application.hpp" -#include "sanity.hpp" +#include "atf-c++/detail/sanity.hpp" #if !defined(HAVE_VSNPRINTF_IN_STD) namespace std { diff --git a/contrib/atf/atf-c++/detail/application.hpp b/contrib/atf/atf-c++/detail/application.hpp index d12b267d57b8..cdb4073ad807 100644 --- a/contrib/atf/atf-c++/detail/application.hpp +++ b/contrib/atf/atf-c++/detail/application.hpp @@ -1,6 +1,3 @@ -// -// Automated Testing Framework (atf) -// // Copyright (c) 2007 The NetBSD Foundation, Inc. // All rights reserved. // @@ -25,10 +22,9 @@ // 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_CXX_APPLICATION_HPP_) -#define _ATF_CXX_APPLICATION_HPP_ +#if !defined(ATF_CXX_DETAIL_APPLICATION_HPP) +#define ATF_CXX_DETAIL_APPLICATION_HPP #include #include @@ -108,4 +104,4 @@ class app { } // namespace application } // namespace atf -#endif // !defined(_ATF_CXX_APPLICATION_HPP_) +#endif // !defined(ATF_CXX_DETAIL_APPLICATION_HPP) diff --git a/contrib/atf/atf-c++/detail/application_test.cpp b/contrib/atf/atf-c++/detail/application_test.cpp index 4664a3aa4bf8..28b7a2f72fa7 100644 --- a/contrib/atf/atf-c++/detail/application_test.cpp +++ b/contrib/atf/atf-c++/detail/application_test.cpp @@ -1,6 +1,3 @@ -// -// Automated Testing Framework (atf) -// // Copyright (c) 2009 The NetBSD Foundation, Inc. // All rights reserved. // @@ -25,15 +22,14 @@ // 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 "atf-c++/detail/application.hpp" extern "C" { #include } -#include "application.hpp" - -#include "../macros.hpp" +#include class getopt_app : public atf::application::app { public: diff --git a/contrib/atf/atf-c++/detail/auto_array.hpp b/contrib/atf/atf-c++/detail/auto_array.hpp index 1459284e3b67..b434a5808235 100644 --- a/contrib/atf/atf-c++/detail/auto_array.hpp +++ b/contrib/atf/atf-c++/detail/auto_array.hpp @@ -1,6 +1,3 @@ -// -// Automated Testing Framework (atf) -// // Copyright (c) 2007 The NetBSD Foundation, Inc. // All rights reserved. // @@ -25,10 +22,9 @@ // 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_CXX_AUTO_ARRAY_HPP_) -#define _ATF_CXX_AUTO_ARRAY_HPP_ +#if !defined(ATF_CXX_DETAIL_AUTO_ARRAY_HPP) +#define ATF_CXX_DETAIL_AUTO_ARRAY_HPP #include @@ -176,4 +172,4 @@ auto_array< T >::operator auto_array_ref< T >(void) } // namespace atf -#endif // !defined(_ATF_CXX_AUTO_ARRAY_HPP_) +#endif // !defined(ATF_CXX_DETAIL_AUTO_ARRAY_HPP) diff --git a/contrib/atf/atf-c++/detail/auto_array_test.cpp b/contrib/atf/atf-c++/detail/auto_array_test.cpp index dcfe41551ce4..aaad90e15295 100644 --- a/contrib/atf/atf-c++/detail/auto_array_test.cpp +++ b/contrib/atf/atf-c++/detail/auto_array_test.cpp @@ -1,6 +1,3 @@ -// -// Automated Testing Framework (atf) -// // Copyright (c) 2007 The NetBSD Foundation, Inc. // All rights reserved. // @@ -25,7 +22,8 @@ // 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 "atf-c++/detail/auto_array.hpp" extern "C" { #include @@ -33,11 +31,11 @@ extern "C" { #include +#include + +extern "C" { #include "atf-c/defs.h" - -#include "../macros.hpp" - -#include "auto_array.hpp" +} // ------------------------------------------------------------------------ // Tests for the "auto_array" class. diff --git a/contrib/atf/atf-c++/detail/env.cpp b/contrib/atf/atf-c++/detail/env.cpp index 5ca7f09c4f0a..8855dcbc9a58 100644 --- a/contrib/atf/atf-c++/detail/env.cpp +++ b/contrib/atf/atf-c++/detail/env.cpp @@ -1,6 +1,3 @@ -// -// Automated Testing Framework (atf) -// // Copyright (c) 2007 The NetBSD Foundation, Inc. // All rights reserved. // @@ -25,17 +22,16 @@ // 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 "atf-c++/detail/env.hpp" extern "C" { -#include "../../atf-c/error.h" - -#include "../../atf-c/detail/env.h" +#include "atf-c/detail/env.h" +#include "atf-c/error.h" } -#include "env.hpp" -#include "exceptions.hpp" -#include "sanity.hpp" +#include "atf-c++/detail/exceptions.hpp" +#include "atf-c++/detail/sanity.hpp" namespace impl = atf::env; #define IMPL_NAME "atf::env" @@ -50,6 +46,12 @@ impl::get(const std::string& name) return atf_env_get(name.c_str()); } +std::string +impl::get(const std::string& name, const std::string& default_value) +{ + return atf_env_get_with_default(name.c_str(), default_value.c_str()); +} + bool impl::has(const std::string& name) { diff --git a/contrib/atf/atf-c++/detail/env.hpp b/contrib/atf/atf-c++/detail/env.hpp index afdf69be5935..e1dcbc0faefd 100644 --- a/contrib/atf/atf-c++/detail/env.hpp +++ b/contrib/atf/atf-c++/detail/env.hpp @@ -1,6 +1,3 @@ -// -// Automated Testing Framework (atf) -// // Copyright (c) 2007 The NetBSD Foundation, Inc. // All rights reserved. // @@ -25,10 +22,9 @@ // 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_CXX_ENV_HPP_) -#define _ATF_CXX_ENV_HPP_ +#if !defined(ATF_CXX_DETAIL_ENV_HPP) +#define ATF_CXX_DETAIL_ENV_HPP #include @@ -47,6 +43,11 @@ namespace env { //! std::string get(const std::string&); +//! +//! \brief Returns the value of an environment variable with a default. +//! +std::string get(const std::string&, const std::string&); + //! //! \brief Checks if the environment has a variable. //! @@ -81,4 +82,4 @@ void unset(const std::string&); } // namespace env } // namespace atf -#endif // !defined(_ATF_CXX_ENV_HPP_) +#endif // !defined(ATF_CXX_DETAIL_ENV_HPP) diff --git a/contrib/atf/atf-c++/detail/env_test.cpp b/contrib/atf/atf-c++/detail/env_test.cpp index a7b681d14e11..91616f38f044 100644 --- a/contrib/atf/atf-c++/detail/env_test.cpp +++ b/contrib/atf/atf-c++/detail/env_test.cpp @@ -1,6 +1,3 @@ -// -// Automated Testing Framework (atf) -// // Copyright (c) 2007 The NetBSD Foundation, Inc. // All rights reserved. // @@ -25,11 +22,10 @@ // 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 "../macros.hpp" +#include "atf-c++/detail/env.hpp" -#include "env.hpp" +#include // ------------------------------------------------------------------------ // Test cases for the free functions. @@ -48,6 +44,19 @@ ATF_TEST_CASE_BODY(has_get) ATF_REQUIRE(!atf::env::has("_UNDEFINED_VARIABLE_")); } +ATF_TEST_CASE(get_with_default); +ATF_TEST_CASE_HEAD(get_with_default) +{ + set_md_var("descr", "Tests the get function with a default value"); +} +ATF_TEST_CASE_BODY(get_with_default) +{ + ATF_REQUIRE(atf::env::has("PATH")); + ATF_REQUIRE(atf::env::get("PATH", "default value") != "default value"); + + ATF_REQUIRE_EQ(atf::env::get("_UNDEFINED_VARIABLE_", "foo bar"), "foo bar"); +} + ATF_TEST_CASE(set); ATF_TEST_CASE_HEAD(set) { @@ -86,6 +95,7 @@ ATF_INIT_TEST_CASES(tcs) { // Add the test cases for the free functions. ATF_ADD_TEST_CASE(tcs, has_get); + ATF_ADD_TEST_CASE(tcs, get_with_default); ATF_ADD_TEST_CASE(tcs, set); ATF_ADD_TEST_CASE(tcs, unset); } diff --git a/contrib/atf/atf-c++/detail/exceptions.cpp b/contrib/atf/atf-c++/detail/exceptions.cpp index 79c5b489e747..a5b74a370e4a 100644 --- a/contrib/atf/atf-c++/detail/exceptions.cpp +++ b/contrib/atf/atf-c++/detail/exceptions.cpp @@ -1,6 +1,3 @@ -// -// Automated Testing Framework (atf) -// // Copyright (c) 2007 The NetBSD Foundation, Inc. // All rights reserved. // @@ -25,10 +22,11 @@ // 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 "atf-c++/detail/exceptions.hpp" #if defined(HAVE_CONFIG_H) -#include "bconfig.h" +#include "config.h" #endif #include @@ -37,11 +35,10 @@ #include extern "C" { -#include "../../atf-c/error.h" -}; +#include "atf-c/error.h" +} -#include "exceptions.hpp" -#include "sanity.hpp" +#include "atf-c++/detail/sanity.hpp" // ------------------------------------------------------------------------ // The "system_error" type. diff --git a/contrib/atf/atf-c++/detail/exceptions.hpp b/contrib/atf/atf-c++/detail/exceptions.hpp index 9bda62b163da..0728ad1c6dc1 100644 --- a/contrib/atf/atf-c++/detail/exceptions.hpp +++ b/contrib/atf/atf-c++/detail/exceptions.hpp @@ -1,6 +1,3 @@ -// -// Automated Testing Framework (atf) -// // Copyright (c) 2007 The NetBSD Foundation, Inc. // All rights reserved. // @@ -25,10 +22,9 @@ // 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_CXX_EXCEPTIONS_HPP_) -#define _ATF_CXX_EXCEPTIONS_HPP_ +#if !defined(ATF_CXX_DETAIL_EXCEPTIONS_HPP) +#define ATF_CXX_DETAIL_EXCEPTIONS_HPP #include #include @@ -55,4 +51,4 @@ void throw_atf_error(struct atf_error *); } // namespace atf -#endif // !defined(_ATF_CXX_EXCEPTIONS_HPP_) +#endif // !defined(ATF_CXX_DETAIL_EXCEPTIONS_HPP) diff --git a/contrib/atf/atf-c++/detail/exceptions_test.cpp b/contrib/atf/atf-c++/detail/exceptions_test.cpp index 821c192dd229..c0bf4fc2f065 100644 --- a/contrib/atf/atf-c++/detail/exceptions_test.cpp +++ b/contrib/atf/atf-c++/detail/exceptions_test.cpp @@ -1,6 +1,3 @@ -// -// Automated Testing Framework (atf) -// // Copyright (c) 2009 The NetBSD Foundation, Inc. // All rights reserved. // @@ -25,19 +22,19 @@ // 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 "atf-c++/detail/exceptions.hpp" extern "C" { -#include "../../atf-c/error.h" +#include "atf-c/error.h" } #include #include -#include "../macros.hpp" +#include -#include "exceptions.hpp" -#include "sanity.hpp" +#include "atf-c++/detail/sanity.hpp" // ------------------------------------------------------------------------ // The "test" error. diff --git a/contrib/atf/atf-c++/detail/fs.cpp b/contrib/atf/atf-c++/detail/fs.cpp index 3517e261f939..bcef9204d129 100644 --- a/contrib/atf/atf-c++/detail/fs.cpp +++ b/contrib/atf/atf-c++/detail/fs.cpp @@ -1,6 +1,3 @@ -// -// Automated Testing Framework (atf) -// // Copyright (c) 2007 The NetBSD Foundation, Inc. // All rights reserved. // @@ -25,10 +22,11 @@ // 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 "atf-c++/detail/fs.hpp" #if defined(HAVE_CONFIG_H) -#include "bconfig.h" +#include "config.h" #endif extern "C" { @@ -47,17 +45,15 @@ extern "C" { #include extern "C" { -#include "../../atf-c/error.h" +#include "atf-c/error.h" } -#include "../utils.hpp" - -#include "exceptions.hpp" -#include "env.hpp" -#include "fs.hpp" -#include "process.hpp" -#include "sanity.hpp" -#include "text.hpp" +#include "atf-c++/detail/env.hpp" +#include "atf-c++/detail/exceptions.hpp" +#include "atf-c++/detail/process.hpp" +#include "atf-c++/detail/sanity.hpp" +#include "atf-c++/detail/text.hpp" +#include "atf-c++/utils.hpp" namespace impl = atf::fs; #define IMPL_NAME "atf::fs" diff --git a/contrib/atf/atf-c++/detail/fs.hpp b/contrib/atf/atf-c++/detail/fs.hpp index 4ffb39b2a582..d6670f6e679f 100644 --- a/contrib/atf/atf-c++/detail/fs.hpp +++ b/contrib/atf/atf-c++/detail/fs.hpp @@ -1,6 +1,3 @@ -// -// Automated Testing Framework (atf) -// // Copyright (c) 2007 The NetBSD Foundation, Inc. // All rights reserved. // @@ -25,10 +22,9 @@ // 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_CXX_FS_HPP_) -#define _ATF_CXX_FS_HPP_ +#if !defined(ATF_CXX_DETAIL_FS_HPP) +#define ATF_CXX_DETAIL_FS_HPP extern "C" { #include @@ -42,7 +38,7 @@ extern "C" { #include extern "C" { -#include "../../atf-c/detail/fs.h" +#include "atf-c/detail/fs.h" } namespace atf { @@ -388,4 +384,4 @@ void rmdir(const path&); } // namespace fs } // namespace atf -#endif // !defined(_ATF_CXX_FS_HPP_) +#endif // !defined(ATF_CXX_DETAIL_FS_HPP) diff --git a/contrib/atf/atf-c++/detail/fs_test.cpp b/contrib/atf/atf-c++/detail/fs_test.cpp index 6cf9bf6c636c..bf64ab2bf0a4 100644 --- a/contrib/atf/atf-c++/detail/fs_test.cpp +++ b/contrib/atf/atf-c++/detail/fs_test.cpp @@ -1,6 +1,3 @@ -// -// Automated Testing Framework (atf) -// // Copyright (c) 2007 The NetBSD Foundation, Inc. // All rights reserved. // @@ -25,7 +22,8 @@ // 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 "atf-c++/detail/fs.hpp" extern "C" { #include @@ -36,10 +34,9 @@ extern "C" { #include #include -#include "../macros.hpp" +#include -#include "exceptions.hpp" -#include "fs.hpp" +#include "atf-c++/detail/exceptions.hpp" // ------------------------------------------------------------------------ // Auxiliary functions. diff --git a/contrib/atf/atf-c++/detail/process.cpp b/contrib/atf/atf-c++/detail/process.cpp index f7ae6d49de00..8139536d39e3 100644 --- a/contrib/atf/atf-c++/detail/process.cpp +++ b/contrib/atf/atf-c++/detail/process.cpp @@ -1,6 +1,3 @@ -// -// Automated Testing Framework (atf) -// // Copyright (c) 2008 The NetBSD Foundation, Inc. // All rights reserved. // @@ -25,21 +22,20 @@ // 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 "atf-c++/detail/process.hpp" extern "C" { #include -#include "../../atf-c/error.h" - -#include "../../atf-c/detail/process.h" +#include "atf-c/detail/process.h" +#include "atf-c/error.h" } #include -#include "exceptions.hpp" -#include "process.hpp" -#include "sanity.hpp" +#include "atf-c++/detail/exceptions.hpp" +#include "atf-c++/detail/sanity.hpp" namespace detail = atf::process::detail; namespace impl = atf::process; @@ -341,11 +337,6 @@ impl::child::stderr_fd(void) void detail::flush_streams(void) { - // This is a weird hack to ensure that the output of the parent process - // is flushed before executing a child which prevents, for example, the - // output of the atf-run hooks to appear before the output of atf-run - // itself. - // // TODO: This should only be executed when inheriting the stdout or // stderr file descriptors. However, the flushing is specific to the // iostreams, so we cannot do it from the C library where all the process diff --git a/contrib/atf/atf-c++/detail/process.hpp b/contrib/atf/atf-c++/detail/process.hpp index bc55a5721c74..0d4989a4f40b 100644 --- a/contrib/atf/atf-c++/detail/process.hpp +++ b/contrib/atf/atf-c++/detail/process.hpp @@ -1,6 +1,3 @@ -// -// Automated Testing Framework (atf) -// // Copyright (c) 2008 The NetBSD Foundation, Inc. // All rights reserved. // @@ -25,25 +22,23 @@ // 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_CXX_PROCESS_HPP_) -#define _ATF_CXX_PROCESS_HPP_ +#if !defined(ATF_CXX_DETAIL_PROCESS_HPP) +#define ATF_CXX_DETAIL_PROCESS_HPP extern "C" { #include -#include "../../atf-c/error.h" - -#include "../../atf-c/detail/process.h" +#include +#include } #include #include -#include "auto_array.hpp" -#include "exceptions.hpp" -#include "fs.hpp" +#include +#include +#include namespace atf { namespace process { @@ -276,4 +271,4 @@ exec(const atf::fs::path& prog, const argv_array& argv, } // namespace process } // namespace atf -#endif // !defined(_ATF_CXX_PROCESS_HPP_) +#endif // !defined(ATF_CXX_DETAIL_PROCESS_HPP) diff --git a/contrib/atf/atf-c++/detail/process_test.cpp b/contrib/atf/atf-c++/detail/process_test.cpp index a40f663108f3..0686d2a1911c 100644 --- a/contrib/atf/atf-c++/detail/process_test.cpp +++ b/contrib/atf/atf-c++/detail/process_test.cpp @@ -1,6 +1,3 @@ -// -// Automated Testing Framework (atf) -// // Copyright (c) 2008 The NetBSD Foundation, Inc. // All rights reserved. // @@ -25,15 +22,15 @@ // 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 "atf-c++/detail/process.hpp" #include #include -#include "../macros.hpp" +#include -#include "process.hpp" -#include "test_helpers.hpp" +#include "atf-c++/detail/test_helpers.hpp" // TODO: Testing the fork function is a huge task and I'm afraid of // copy/pasting tons of stuff from the C version. I'd rather not do that diff --git a/contrib/atf/atf-c++/detail/sanity.hpp b/contrib/atf/atf-c++/detail/sanity.hpp index 6021a6e6890c..3d89ab4b03fe 100644 --- a/contrib/atf/atf-c++/detail/sanity.hpp +++ b/contrib/atf/atf-c++/detail/sanity.hpp @@ -1,6 +1,3 @@ -// -// Automated Testing Framework (atf) -// // Copyright (c) 2007 The NetBSD Foundation, Inc. // All rights reserved. // @@ -25,13 +22,12 @@ // 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_CXX_SANITY_HPP_) -#define _ATF_CXX_SANITY_HPP_ +#if !defined(ATF_CXX_DETAIL_SANITY_HPP) +#define ATF_CXX_DETAIL_SANITY_HPP extern "C" { -#include "../../atf-c/detail/sanity.h" +#include } -#endif // !defined(_ATF_CXX_SANITY_HPP_) +#endif // !defined(ATF_CXX_DETAIL_SANITY_HPP) diff --git a/contrib/atf/atf-c++/detail/sanity_test.cpp b/contrib/atf/atf-c++/detail/sanity_test.cpp deleted file mode 100644 index 8d3a07eb8bd5..000000000000 --- a/contrib/atf/atf-c++/detail/sanity_test.cpp +++ /dev/null @@ -1,41 +0,0 @@ -// -// Automated Testing Framework (atf) -// -// Copyright (c) 2009 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 "../macros.hpp" - -ATF_TEST_CASE_WITHOUT_HEAD(nothing); -ATF_TEST_CASE_BODY(nothing) -{ - // TODO -} - -ATF_INIT_TEST_CASES(tcs) -{ - ATF_ADD_TEST_CASE(tcs, nothing); -} diff --git a/contrib/atf/atf-c++/detail/test_helpers.cpp b/contrib/atf/atf-c++/detail/test_helpers.cpp index 38e651634dde..d3f94003ac31 100644 --- a/contrib/atf/atf-c++/detail/test_helpers.cpp +++ b/contrib/atf/atf-c++/detail/test_helpers.cpp @@ -1,6 +1,3 @@ -// -// Automated Testing Framework (atf) -// // Copyright (c) 2009 The NetBSD Foundation, Inc. // All rights reserved. // @@ -25,20 +22,20 @@ // 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 "atf-c++/detail/test_helpers.hpp" #include #include #include #include -#include "../check.hpp" -#include "../config.hpp" -#include "../macros.hpp" +#include -#include "fs.hpp" -#include "process.hpp" -#include "test_helpers.hpp" +#include "atf-c++/check.hpp" +#include "atf-c++/detail/env.hpp" +#include "atf-c++/detail/fs.hpp" +#include "atf-c++/detail/process.hpp" // Path to the directory containing the libatf-c tests, used to locate the // process_helpers program. If NULL (the default), the code will use a @@ -56,7 +53,7 @@ bool build_check_cxx_o(const char* sfile) { std::vector< std::string > optargs; - optargs.push_back("-I" + atf::config::get("atf_includedir")); + optargs.push_back("-I" + atf::env::get("ATF_INCLUDEDIR", ATF_INCLUDEDIR)); optargs.push_back("-Wall"); optargs.push_back("-Werror"); diff --git a/contrib/atf/atf-c++/detail/test_helpers.hpp b/contrib/atf/atf-c++/detail/test_helpers.hpp index 342a07dba9ce..f166ee218a13 100644 --- a/contrib/atf/atf-c++/detail/test_helpers.hpp +++ b/contrib/atf/atf-c++/detail/test_helpers.hpp @@ -1,6 +1,3 @@ -// -// Automated Testing Framework (atf) -// // Copyright (c) 2009 The NetBSD Foundation, Inc. // All rights reserved. // @@ -25,12 +22,11 @@ // 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(TESTS_ATF_ATF_CXX_TEST_HELPERS_H) +#if defined(ATF_CXX_DETAIL_TEST_HELPERS_H) # error "Cannot include test_helpers.hpp more than once." #else -# define TESTS_ATF_ATF_CXX_TEST_HELPERS_H +# define ATF_CXX_DETAIL_TEST_HELPERS_H #endif #include @@ -38,9 +34,9 @@ #include #include -#include "../macros.hpp" -#include "../tests.hpp" -#include "process.hpp" +#include + +#include #define HEADER_TC(name, hdrname) \ ATF_TEST_CASE(name); \ diff --git a/contrib/atf/atf-c++/detail/text.cpp b/contrib/atf/atf-c++/detail/text.cpp index 66eebf0a77e7..35a0beca95b9 100644 --- a/contrib/atf/atf-c++/detail/text.cpp +++ b/contrib/atf/atf-c++/detail/text.cpp @@ -1,6 +1,3 @@ -// -// Automated Testing Framework (atf) -// // Copyright (c) 2007 The NetBSD Foundation, Inc. // All rights reserved. // @@ -25,7 +22,8 @@ // 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 "atf-c++/detail/text.hpp" extern "C" { #include @@ -35,13 +33,11 @@ extern "C" { #include extern "C" { -#include "../../atf-c/error.h" - -#include "../../atf-c/detail/text.h" +#include "atf-c/detail/text.h" +#include "atf-c/error.h" } -#include "exceptions.hpp" -#include "text.hpp" +#include "atf-c++/detail/exceptions.hpp" namespace impl = atf::text; #define IMPL_NAME "atf::text" diff --git a/contrib/atf/atf-c++/detail/text.hpp b/contrib/atf/atf-c++/detail/text.hpp index 6a1b027c1896..63c3190a37c1 100644 --- a/contrib/atf/atf-c++/detail/text.hpp +++ b/contrib/atf/atf-c++/detail/text.hpp @@ -1,6 +1,3 @@ -// -// Automated Testing Framework (atf) -// // Copyright (c) 2007 The NetBSD Foundation, Inc. // All rights reserved. // @@ -25,10 +22,9 @@ // 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_CXX_TEXT_HPP_) -#define _ATF_CXX_TEXT_HPP_ +#if !defined(ATF_CXX_DETAIL_TEXT_HPP) +#define ATF_CXX_DETAIL_TEXT_HPP extern "C" { #include @@ -150,4 +146,4 @@ to_type(const std::string& str) } // namespace text } // namespace atf -#endif // !defined(_ATF_CXX_TEXT_HPP_) +#endif // !defined(ATF_CXX_DETAIL_TEXT_HPP) diff --git a/contrib/atf/atf-c++/detail/text_test.cpp b/contrib/atf/atf-c++/detail/text_test.cpp index b7c0ba1af827..49d37741b414 100644 --- a/contrib/atf/atf-c++/detail/text_test.cpp +++ b/contrib/atf/atf-c++/detail/text_test.cpp @@ -1,6 +1,3 @@ -// -// Automated Testing Framework (atf) -// // Copyright (c) 2007 The NetBSD Foundation, Inc. // All rights reserved. // @@ -25,15 +22,14 @@ // 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 "atf-c++/detail/text.hpp" #include #include #include -#include "../macros.hpp" - -#include "text.hpp" +#include // ------------------------------------------------------------------------ // Test cases for the free functions. diff --git a/contrib/atf/atf-c++/detail/version_helper.cpp b/contrib/atf/atf-c++/detail/version_helper.cpp index b1101c92a009..0ee47913e2dd 100644 --- a/contrib/atf/atf-c++/detail/version_helper.cpp +++ b/contrib/atf/atf-c++/detail/version_helper.cpp @@ -27,7 +27,7 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #if defined(HAVE_CONFIG_H) -#include "bconfig.h" +#include "config.h" #endif #include diff --git a/contrib/atf/atf-c++/macros.hpp b/contrib/atf/atf-c++/macros.hpp index c6ce9c2be59e..ea0b2dc08060 100644 --- a/contrib/atf/atf-c++/macros.hpp +++ b/contrib/atf/atf-c++/macros.hpp @@ -1,6 +1,3 @@ -// -// Automated Testing Framework (atf) -// // Copyright (c) 2007 The NetBSD Foundation, Inc. // All rights reserved. // @@ -25,10 +22,9 @@ // 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_CXX_MACROS_HPP_) -#define _ATF_CXX_MACROS_HPP_ +#if !defined(ATF_CXX_MACROS_HPP) +#define ATF_CXX_MACROS_HPP #include #include @@ -99,21 +95,23 @@ #define ATF_PASS() atf::tests::tc::pass() -#define ATF_REQUIRE(x) \ +#define ATF_REQUIRE(expression) \ do { \ - if (!(x)) { \ + if (!(expression)) { \ std::ostringstream atfu_ss; \ - atfu_ss << "Line " << __LINE__ << ": " << #x << " not met"; \ + atfu_ss << "Line " << __LINE__ << ": " << #expression \ + << " not met"; \ atf::tests::tc::fail(atfu_ss.str()); \ } \ } while (false) -#define ATF_REQUIRE_EQ(x, y) \ +#define ATF_REQUIRE_EQ(expected, actual) \ do { \ - if ((x) != (y)) { \ + if ((expected) != (actual)) { \ std::ostringstream atfu_ss; \ - atfu_ss << "Line " << __LINE__ << ": " << #x << " != " << #y \ - << " (" << (x) << " != " << (y) << ")"; \ + atfu_ss << "Line " << __LINE__ << ": " \ + << #expected << " != " << #actual \ + << " (" << (expected) << " != " << (actual) << ")"; \ atf::tests::tc::fail(atfu_ss.str()); \ } \ } while (false) @@ -134,69 +132,74 @@ } \ } while (false) -#define ATF_REQUIRE_THROW(e, x) \ +#define ATF_REQUIRE_THROW(expected_exception, statement) \ do { \ try { \ - x; \ + statement; \ std::ostringstream atfu_ss; \ - atfu_ss << "Line " << __LINE__ << ": " #x " did not throw " \ - #e " as expected"; \ + atfu_ss << "Line " << __LINE__ \ + << ": " #statement " did not throw " #expected_exception \ + " as expected"; \ atf::tests::tc::fail(atfu_ss.str()); \ - } catch (const e&) { \ + } catch (const expected_exception&) { \ } catch (const std::exception& atfu_e) { \ std::ostringstream atfu_ss; \ - atfu_ss << "Line " << __LINE__ << ": " #x " threw an " \ - "unexpected error (not " #e "): " << atfu_e.what(); \ + atfu_ss << "Line " << __LINE__ << ": " #statement " threw an " \ + "unexpected error (not " #expected_exception "): " \ + << atfu_e.what(); \ atf::tests::tc::fail(atfu_ss.str()); \ } catch (...) { \ std::ostringstream atfu_ss; \ - atfu_ss << "Line " << __LINE__ << ": " #x " threw an " \ - "unexpected error (not " #e ")"; \ + atfu_ss << "Line " << __LINE__ << ": " #statement " threw an " \ + "unexpected error (not " #expected_exception ")"; \ atf::tests::tc::fail(atfu_ss.str()); \ } \ } while (false) -#define ATF_REQUIRE_THROW_RE(type, regexp, x) \ +#define ATF_REQUIRE_THROW_RE(expected_exception, regexp, statement) \ do { \ try { \ - x; \ + statement; \ std::ostringstream atfu_ss; \ - atfu_ss << "Line " << __LINE__ << ": " #x " did not throw " \ - #type " as expected"; \ + atfu_ss << "Line " << __LINE__ \ + << ": " #statement " did not throw " #expected_exception \ + " as expected"; \ atf::tests::tc::fail(atfu_ss.str()); \ - } catch (const type& e) { \ + } catch (const expected_exception& e) { \ if (!atf::tests::detail::match(regexp, e.what())) { \ std::ostringstream atfu_ss; \ - atfu_ss << "Line " << __LINE__ << ": " #x " threw " #type "(" \ + atfu_ss << "Line " << __LINE__ \ + << ": " #statement " threw " #expected_exception "(" \ << e.what() << "), but does not match '" << regexp \ << "'"; \ atf::tests::tc::fail(atfu_ss.str()); \ } \ } catch (const std::exception& atfu_e) { \ std::ostringstream atfu_ss; \ - atfu_ss << "Line " << __LINE__ << ": " #x " threw an " \ - "unexpected error (not " #type "): " << atfu_e.what(); \ + atfu_ss << "Line " << __LINE__ << ": " #statement " threw an " \ + "unexpected error (not " #expected_exception "): " \ + << atfu_e.what(); \ atf::tests::tc::fail(atfu_ss.str()); \ } catch (...) { \ std::ostringstream atfu_ss; \ - atfu_ss << "Line " << __LINE__ << ": " #x " threw an " \ - "unexpected error (not " #type ")"; \ + atfu_ss << "Line " << __LINE__ << ": " #statement " threw an " \ + "unexpected error (not " #expected_exception ")"; \ atf::tests::tc::fail(atfu_ss.str()); \ } \ } while (false) -#define ATF_CHECK_ERRNO(exp_errno, bool_expr) \ - atf::tests::tc::check_errno(__FILE__, __LINE__, exp_errno, #bool_expr, \ - bool_expr) +#define ATF_CHECK_ERRNO(expected_errno, bool_expr) \ + atf::tests::tc::check_errno(__FILE__, __LINE__, expected_errno, \ + #bool_expr, bool_expr) -#define ATF_REQUIRE_ERRNO(exp_errno, bool_expr) \ - atf::tests::tc::require_errno(__FILE__, __LINE__, exp_errno, #bool_expr, \ - bool_expr) +#define ATF_REQUIRE_ERRNO(expected_errno, bool_expr) \ + atf::tests::tc::require_errno(__FILE__, __LINE__, expected_errno, \ + #bool_expr, bool_expr) #define ATF_INIT_TEST_CASES(tcs) \ namespace atf { \ namespace tests { \ - int run_tp(int, char* const*, \ + int run_tp(int, char**, \ void (*)(std::vector< atf::tests::tc * >&)); \ } \ } \ @@ -204,7 +207,7 @@ static void atfu_init_tcs(std::vector< atf::tests::tc * >&); \ \ int \ - main(int argc, char* const* argv) \ + main(int argc, char** argv) \ { \ return atf::tests::run_tp(argc, argv, atfu_init_tcs); \ } \ @@ -219,4 +222,4 @@ (tcs).push_back(atfu_tcptr_ ## tcname); \ } while (0); -#endif // !defined(_ATF_CXX_MACROS_HPP_) +#endif // !defined(ATF_CXX_MACROS_HPP) diff --git a/contrib/atf/atf-c++/macros_hpp_test.cpp b/contrib/atf/atf-c++/macros_hpp_test.cpp index 2cb75360a4d7..0bc27c60cb9b 100644 --- a/contrib/atf/atf-c++/macros_hpp_test.cpp +++ b/contrib/atf/atf-c++/macros_hpp_test.cpp @@ -1,6 +1,3 @@ -// -// Automated Testing Framework (atf) -// // Copyright (c) 2008 The NetBSD Foundation, Inc. // All rights reserved. // @@ -25,12 +22,11 @@ // 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 #include +#include + void atf_check_errno_semicolons(void) { diff --git a/contrib/atf/atf-c++/macros_test.cpp b/contrib/atf/atf-c++/macros_test.cpp index 4113ed0e61ce..23b5e5cbb6d8 100644 --- a/contrib/atf/atf-c++/macros_test.cpp +++ b/contrib/atf/atf-c++/macros_test.cpp @@ -1,6 +1,3 @@ -// -// Automated Testing Framework (atf) -// // Copyright (c) 2008 The NetBSD Foundation, Inc. // All rights reserved. // @@ -25,7 +22,8 @@ // 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 "atf-c++/macros.hpp" extern "C" { #include @@ -37,14 +35,14 @@ extern "C" { #include #include -#include "macros.hpp" -#include "utils.hpp" +#include -#include "detail/fs.hpp" -#include "detail/process.hpp" -#include "detail/sanity.hpp" -#include "detail/test_helpers.hpp" -#include "detail/text.hpp" +#include "atf-c++/detail/fs.hpp" +#include "atf-c++/detail/process.hpp" +#include "atf-c++/detail/sanity.hpp" +#include "atf-c++/detail/test_helpers.hpp" +#include "atf-c++/detail/text.hpp" +#include "atf-c++/utils.hpp" // ------------------------------------------------------------------------ // Auxiliary functions. @@ -757,7 +755,6 @@ ATF_TEST_CASE_BODY(require_errno) // Tests cases for the header file. // ------------------------------------------------------------------------ -HEADER_TC(include, "atf-c++/macros.hpp"); BUILD_TC(use, "macros_hpp_test.cpp", "Tests that the macros provided by the atf-c++/macros.hpp file " "do not cause syntax errors when used", @@ -809,7 +806,6 @@ ATF_INIT_TEST_CASES(tcs) ATF_ADD_TEST_CASE(tcs, require_errno); // Add the test cases for the header file. - ATF_ADD_TEST_CASE(tcs, include); ATF_ADD_TEST_CASE(tcs, use); ATF_ADD_TEST_CASE(tcs, detect_unused_tests); } diff --git a/contrib/atf/atf-c++/pkg_config_test.sh b/contrib/atf/atf-c++/pkg_config_test.sh index d0b06569ac21..af541f6d767c 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 atfc++.pc file is installed in a # directory that is known by pkg-config. Otherwise they will fail, diff --git a/contrib/atf/atf-c++/tests.cpp b/contrib/atf/atf-c++/tests.cpp index 801ed7cd49c8..ede9609e32d6 100644 --- a/contrib/atf/atf-c++/tests.cpp +++ b/contrib/atf/atf-c++/tests.cpp @@ -1,6 +1,3 @@ -// -// Automated Testing Framework (atf) -// // Copyright (c) 2007 The NetBSD Foundation, Inc. // All rights reserved. // @@ -25,7 +22,12 @@ // 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 "atf-c++/tests.hpp" + +#if defined(HAVE_CONFIG_H) +#include "config.h" +#endif extern "C" { #include @@ -55,20 +57,26 @@ extern "C" { #include "atf-c/utils.h" } -#include "tests.hpp" +#include "atf-c++/detail/application.hpp" +#include "atf-c++/detail/auto_array.hpp" +#include "atf-c++/detail/env.hpp" +#include "atf-c++/detail/exceptions.hpp" +#include "atf-c++/detail/fs.hpp" +#include "atf-c++/detail/sanity.hpp" +#include "atf-c++/detail/text.hpp" -#include "detail/application.hpp" -#include "detail/auto_array.hpp" -#include "detail/env.hpp" -#include "detail/exceptions.hpp" -#include "detail/fs.hpp" -#include "detail/sanity.hpp" -#include "detail/text.hpp" +#if defined(HAVE_GNU_GETOPT) +# define GETOPT_POSIX "+" +#else +# define GETOPT_POSIX "" +#endif namespace impl = atf::tests; namespace detail = atf::tests::detail; #define IMPL_NAME "atf::tests" +using atf::application::usage_error; + // ------------------------------------------------------------------------ // The "atf_tp_writer" class. // ------------------------------------------------------------------------ @@ -109,6 +117,21 @@ detail::atf_tp_writer::tc_meta_data(const std::string& name, // Free helper functions. // ------------------------------------------------------------------------ +std::string Program_Name; + +static void +set_program_name(const char* argv0) +{ + const std::string program_name = atf::fs::path(argv0).leaf_name(); + // Libtool workaround: if running from within the source tree (binaries + // that are not installed yet), skip the "lt-" prefix added to files in + // the ".libs" directory to show the real (not temporary) name. + if (program_name.substr(0, 3) == "lt-") + Program_Name = program_name.substr(3); + else + Program_Name = program_name; +} + bool detail::match(const std::string& regexp, const std::string& str) { @@ -153,14 +176,7 @@ struct impl::tc_impl { std::map< const atf_tc_t*, const impl::tc* >::const_iterator iter = cwraps.find(tc); INV(iter != cwraps.end()); - try { - (*iter).second->body(); - } catch (const std::exception& e) { - (*iter).second->fail("Caught unhandled exception: " + std::string( - e.what())); - } catch (...) { - (*iter).second->fail("Caught unknown exception"); - } + (*iter).second->body(); } static void @@ -384,197 +400,70 @@ impl::tc::expect_timeout(const std::string& reason) } // ------------------------------------------------------------------------ -// The "tp" class. +// Test program main code. // ------------------------------------------------------------------------ -class tp : public atf::application::app { -public: - typedef std::vector< impl::tc * > tc_vector; +namespace { -private: - static const char* m_description; +typedef std::vector< impl::tc * > tc_vector; - bool m_lflag; - atf::fs::path m_resfile; - std::string m_srcdir_arg; - atf::fs::path m_srcdir; +enum tc_part { BODY, CLEANUP }; - atf::tests::vars_map m_vars; - - std::string specific_args(void) const; - options_set specific_options(void) const; - void process_option(int, const char*); - - void (*m_add_tcs)(tc_vector&); - tc_vector m_tcs; - - void parse_vflag(const std::string&); - void handle_srcdir(void); - - tc_vector init_tcs(void); - - enum tc_part { - BODY, - CLEANUP, - }; - - void list_tcs(void); - impl::tc* find_tc(tc_vector, const std::string&); - static std::pair< std::string, tc_part > process_tcarg(const std::string&); - int run_tc(const std::string&); - -public: - tp(void (*)(tc_vector&)); - ~tp(void); - - int main(void); -}; - -const char* tp::m_description = - "This is an independent atf test program."; - -tp::tp(void (*add_tcs)(tc_vector&)) : - app(m_description, "atf-test-program(1)"), - m_lflag(false), - m_resfile("/dev/stdout"), - m_srcdir("."), - m_add_tcs(add_tcs) -{ -} - -tp::~tp(void) -{ - for (tc_vector::iterator iter = m_tcs.begin(); - iter != m_tcs.end(); iter++) { - impl::tc* tc = *iter; - - delete tc; - } -} - -std::string -tp::specific_args(void) - const -{ - return "test_case"; -} - -tp::options_set -tp::specific_options(void) - const -{ - using atf::application::option; - options_set opts; - opts.insert(option('l', "", "List test cases and their purpose")); - opts.insert(option('r', "resfile", "The file to which the test program " - "will write the results of the " - "executed test case")); - opts.insert(option('s', "srcdir", "Directory where the test's data " - "files are located")); - opts.insert(option('v', "var=value", "Sets the configuration variable " - "`var' to `value'")); - return opts; -} - -void -tp::process_option(int ch, const char* arg) -{ - switch (ch) { - case 'l': - m_lflag = true; - break; - - case 'r': - m_resfile = atf::fs::path(arg); - break; - - case 's': - m_srcdir_arg = arg; - break; - - case 'v': - parse_vflag(arg); - break; - - default: - UNREACHABLE; - } -} - -void -tp::parse_vflag(const std::string& str) +static void +parse_vflag(const std::string& str, atf::tests::vars_map& vars) { if (str.empty()) throw std::runtime_error("-v requires a non-empty argument"); std::vector< std::string > ws = atf::text::split(str, "="); if (ws.size() == 1 && str[str.length() - 1] == '=') { - m_vars[ws[0]] = ""; + vars[ws[0]] = ""; } else { if (ws.size() != 2) throw std::runtime_error("-v requires an argument of the form " "var=value"); - m_vars[ws[0]] = ws[1]; + vars[ws[0]] = ws[1]; } } -void -tp::handle_srcdir(void) +static atf::fs::path +handle_srcdir(const char* argv0, const std::string& srcdir_arg) { - if (m_srcdir_arg.empty()) { - m_srcdir = atf::fs::path(m_argv0).branch_path(); - if (m_srcdir.leaf_name() == ".libs") - m_srcdir = m_srcdir.branch_path(); + atf::fs::path srcdir("."); + + if (srcdir_arg.empty()) { + srcdir = atf::fs::path(argv0).branch_path(); + if (srcdir.leaf_name() == ".libs") + srcdir = srcdir.branch_path(); } else - m_srcdir = atf::fs::path(m_srcdir_arg); + srcdir = atf::fs::path(srcdir_arg); - if (!atf::fs::exists(m_srcdir / m_prog_name)) - throw std::runtime_error("Cannot find the test program in the " - "source directory `" + m_srcdir.str() + "'"); + if (!atf::fs::exists(srcdir / Program_Name)) + throw usage_error("Cannot find the test program in the source " + "directory `%s'", srcdir.c_str()); - if (!m_srcdir.is_absolute()) - m_srcdir = m_srcdir.to_absolute(); + if (!srcdir.is_absolute()) + srcdir = srcdir.to_absolute(); - m_vars["srcdir"] = m_srcdir.str(); + return srcdir; } -tp::tc_vector -tp::init_tcs(void) +static void +init_tcs(void (*add_tcs)(tc_vector&), tc_vector& tcs, + const atf::tests::vars_map& vars) { - m_add_tcs(m_tcs); - for (tc_vector::iterator iter = m_tcs.begin(); - iter != m_tcs.end(); iter++) { + add_tcs(tcs); + for (tc_vector::iterator iter = tcs.begin(); iter != tcs.end(); iter++) { impl::tc* tc = *iter; - tc->init(m_vars); + tc->init(vars); } - return m_tcs; } -// -// An auxiliary unary predicate that compares the given test case's -// identifier to the identifier stored in it. -// -class tc_equal_to_ident { - const std::string& m_ident; - -public: - tc_equal_to_ident(const std::string& i) : - m_ident(i) - { - } - - bool operator()(const impl::tc* tc) - { - return tc->get_md_var("ident") == m_ident; - } -}; - -void -tp::list_tcs(void) +static int +list_tcs(const tc_vector& tcs) { - tc_vector tcs = init_tcs(); detail::atf_tp_writer writer(std::cout); for (tc_vector::const_iterator iter = tcs.begin(); @@ -596,10 +485,12 @@ tp::list_tcs(void) writer.end_tc(); } + + return EXIT_SUCCESS; } -impl::tc* -tp::find_tc(tc_vector tcs, const std::string& name) +static impl::tc* +find_tc(tc_vector tcs, const std::string& name) { std::vector< std::string > ids; for (tc_vector::iterator iter = tcs.begin(); @@ -609,12 +500,11 @@ tp::find_tc(tc_vector tcs, const std::string& name) if (tc->get_md_var("ident") == name) return tc; } - throw atf::application::usage_error("Unknown test case `%s'", - name.c_str()); + throw usage_error("Unknown test case `%s'", name.c_str()); } -std::pair< std::string, tp::tc_part > -tp::process_tcarg(const std::string& tcarg) +static std::pair< std::string, tc_part > +process_tcarg(const std::string& tcarg) { const std::string::size_type pos = tcarg.find(':'); if (pos == std::string::npos) { @@ -628,83 +518,141 @@ tp::process_tcarg(const std::string& tcarg) else if (partname == "cleanup") return std::make_pair(tcname, CLEANUP); else { - using atf::application::usage_error; throw usage_error("Invalid test case part `%s'", partname.c_str()); } } } -int -tp::run_tc(const std::string& tcarg) +static int +run_tc(tc_vector& tcs, const std::string& tcarg, const atf::fs::path& resfile) { const std::pair< std::string, tc_part > fields = process_tcarg(tcarg); - impl::tc* tc = find_tc(init_tcs(), fields.first); + impl::tc* tc = find_tc(tcs, fields.first); if (!atf::env::has("__RUNNING_INSIDE_ATF_RUN") || atf::env::get( "__RUNNING_INSIDE_ATF_RUN") != "internal-yes-value") { - std::cerr << m_prog_name << ": WARNING: Running test cases without " - "atf-run(1) is unsupported\n"; - std::cerr << m_prog_name << ": WARNING: No isolation nor timeout " + std::cerr << Program_Name << ": WARNING: Running test cases outside " + "of kyua(1) is unsupported\n"; + std::cerr << Program_Name << ": WARNING: No isolation nor timeout " "control is being applied; you may get unexpected failures; see " "atf-test-case(4)\n"; } - try { - switch (fields.second) { - case BODY: - tc->run(m_resfile.str()); - break; - case CLEANUP: - tc->run_cleanup(); - break; - default: - UNREACHABLE; - } - return EXIT_SUCCESS; - } catch (const std::runtime_error& e) { - std::cerr << "ERROR: " << e.what() << "\n"; - return EXIT_FAILURE; + switch (fields.second) { + case BODY: + tc->run(resfile.str()); + break; + case CLEANUP: + tc->run_cleanup(); + break; + default: + UNREACHABLE; } + return EXIT_SUCCESS; } -int -tp::main(void) +static int +safe_main(int argc, char** argv, void (*add_tcs)(tc_vector&)) { - using atf::application::usage_error; + const char* argv0 = argv[0]; + + bool lflag = false; + atf::fs::path resfile("/dev/stdout"); + std::string srcdir_arg; + atf::tests::vars_map vars; + + int ch; + int old_opterr; + + old_opterr = opterr; + ::opterr = 0; + while ((ch = ::getopt(argc, argv, GETOPT_POSIX ":lr:s:v:")) != -1) { + switch (ch) { + case 'l': + lflag = true; + break; + + case 'r': + resfile = atf::fs::path(::optarg); + break; + + case 's': + srcdir_arg = ::optarg; + break; + + case 'v': + parse_vflag(::optarg, vars); + break; + + case ':': + throw usage_error("Option -%c requires an argument.", ::optopt); + break; + + case '?': + default: + throw usage_error("Unknown option -%c.", ::optopt); + } + } + argc -= optind; + argv += optind; + + // Clear getopt state just in case the test wants to use it. + ::opterr = old_opterr; + ::optind = 1; +#if defined(HAVE_OPTRESET) + ::optreset = 1; +#endif + + vars["srcdir"] = handle_srcdir(argv0, srcdir_arg).str(); int errcode; - handle_srcdir(); - - if (m_lflag) { - if (m_argc > 0) + tc_vector tcs; + if (lflag) { + if (argc > 0) throw usage_error("Cannot provide test case names with -l"); - list_tcs(); - errcode = EXIT_SUCCESS; + init_tcs(add_tcs, tcs, vars); + errcode = list_tcs(tcs); } else { - if (m_argc == 0) + if (argc == 0) throw usage_error("Must provide a test case name"); - else if (m_argc > 1) + else if (argc > 1) throw usage_error("Cannot provide more than one test case name"); - INV(m_argc == 1); + INV(argc == 1); - errcode = run_tc(m_argv[0]); + init_tcs(add_tcs, tcs, vars); + errcode = run_tc(tcs, argv[0], resfile); + } + for (tc_vector::iterator iter = tcs.begin(); iter != tcs.end(); iter++) { + impl::tc* tc = *iter; + + delete tc; } return errcode; } +} // anonymous namespace + namespace atf { namespace tests { - int run_tp(int, char* const*, void (*)(tp::tc_vector&)); + int run_tp(int, char**, void (*)(tc_vector&)); } } int -impl::run_tp(int argc, char* const* argv, void (*add_tcs)(tp::tc_vector&)) +impl::run_tp(int argc, char** argv, void (*add_tcs)(tc_vector&)) { - return tp(add_tcs).run(argc, argv); + try { + set_program_name(argv[0]); + return ::safe_main(argc, argv, add_tcs); + } catch (const usage_error& e) { + std::cerr + << Program_Name << ": ERROR: " << e.what() << '\n' + << Program_Name << ": See atf-test-program(1) for usage details.\n"; + return EXIT_FAILURE; + } } diff --git a/contrib/atf/atf-c++/tests.hpp b/contrib/atf/atf-c++/tests.hpp index 4c8ca913d97b..ce2fb1d165c8 100644 --- a/contrib/atf/atf-c++/tests.hpp +++ b/contrib/atf/atf-c++/tests.hpp @@ -1,6 +1,3 @@ -// -// Automated Testing Framework (atf) -// // Copyright (c) 2007 The NetBSD Foundation, Inc. // All rights reserved. // @@ -25,10 +22,9 @@ // 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_CXX_TESTS_HPP_) -#define _ATF_CXX_TESTS_HPP_ +#if !defined(ATF_CXX_TESTS_HPP) +#define ATF_CXX_TESTS_HPP #include #include @@ -126,4 +122,4 @@ class tc { } // namespace tests } // namespace atf -#endif // !defined(_ATF_CXX_TESTS_HPP_) +#endif // !defined(ATF_CXX_TESTS_HPP) diff --git a/contrib/atf/atf-c++/tests_test.cpp b/contrib/atf/atf-c++/tests_test.cpp index 5f19a4e176c0..ed9fef0d0140 100644 --- a/contrib/atf/atf-c++/tests_test.cpp +++ b/contrib/atf/atf-c++/tests_test.cpp @@ -1,6 +1,3 @@ -// -// Automated Testing Framework (atf) -// // Copyright (c) 2007 The NetBSD Foundation, Inc. // All rights reserved. // @@ -25,7 +22,8 @@ // 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 "atf-c++/tests.hpp" extern "C" { #include @@ -36,12 +34,12 @@ extern "C" { } #include +#include #include -#include "macros.hpp" +#include -#include "detail/test_helpers.hpp" -#include "detail/text.hpp" +#include "atf-c++/detail/text.hpp" // ------------------------------------------------------------------------ // Tests for the "atf_tp_writer" class. @@ -181,12 +179,6 @@ ATF_TEST_CASE_BODY(atf_tp_writer) #undef RESET } -// ------------------------------------------------------------------------ -// Tests cases for the header file. -// ------------------------------------------------------------------------ - -HEADER_TC(include, "atf-c++/tests.hpp"); - // ------------------------------------------------------------------------ // Main. // ------------------------------------------------------------------------ @@ -195,7 +187,4 @@ ATF_INIT_TEST_CASES(tcs) { // Add tests for the "atf_tp_writer" class. ATF_ADD_TEST_CASE(tcs, atf_tp_writer); - - // Add the test cases for the header file. - ATF_ADD_TEST_CASE(tcs, include); } diff --git a/contrib/atf/atf-c++/unused_test.cpp b/contrib/atf/atf-c++/unused_test.cpp index 2a18a455a7e2..1a577e14be19 100644 --- a/contrib/atf/atf-c++/unused_test.cpp +++ b/contrib/atf/atf-c++/unused_test.cpp @@ -1,6 +1,3 @@ -// -// Automated Testing Framework (atf) -// // Copyright (c) 2012 The NetBSD Foundation, Inc. // All rights reserved. // @@ -25,9 +22,8 @@ // 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 +#include ATF_TEST_CASE(this_is_used); ATF_TEST_CASE_HEAD(this_is_used) diff --git a/contrib/atf/atf-c++/utils.cpp b/contrib/atf/atf-c++/utils.cpp index cc338bb89230..a6ab08f0d770 100644 --- a/contrib/atf/atf-c++/utils.cpp +++ b/contrib/atf/atf-c++/utils.cpp @@ -1,6 +1,3 @@ -// -// Automated Testing Framework (atf) -// // Copyright (c) 2007 The NetBSD Foundation, Inc. // All rights reserved. // @@ -25,7 +22,8 @@ // 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 "atf-c++/utils.hpp" extern "C" { #include "atf-c/utils.h" @@ -34,8 +32,6 @@ extern "C" { #include #include -#include "utils.hpp" - void atf::utils::cat_file(const std::string& path, const std::string& prefix) { diff --git a/contrib/atf/atf-c++/utils.hpp b/contrib/atf/atf-c++/utils.hpp index b8596aecdc0c..8f5c5e337455 100644 --- a/contrib/atf/atf-c++/utils.hpp +++ b/contrib/atf/atf-c++/utils.hpp @@ -1,6 +1,3 @@ -// -// Automated Testing Framework (atf) -// // Copyright (c) 2007 The NetBSD Foundation, Inc. // All rights reserved. // @@ -25,10 +22,9 @@ // 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_CXX_UTILS_HPP_) -#define _ATF_CXX_UTILS_HPP_ +#if !defined(ATF_CXX_UTILS_HPP) +#define ATF_CXX_UTILS_HPP extern "C" { #include @@ -65,4 +61,4 @@ grep_collection(const std::string& regexp, const Collection& collection) } // namespace utils } // namespace atf -#endif // !defined(_ATF_CXX_UTILS_HPP_) +#endif // !defined(ATF_CXX_UTILS_HPP) diff --git a/contrib/atf/atf-c++/utils_test.cpp b/contrib/atf/atf-c++/utils_test.cpp index 37457ff2b838..34e0709f580a 100644 --- a/contrib/atf/atf-c++/utils_test.cpp +++ b/contrib/atf/atf-c++/utils_test.cpp @@ -1,6 +1,3 @@ -// -// Automated Testing Framework (atf) -// // Copyright (c) 2007 The NetBSD Foundation, Inc. // All rights reserved. // @@ -25,7 +22,8 @@ // 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 "atf-c++/utils.hpp" extern "C" { #include @@ -38,22 +36,20 @@ extern "C" { #include #include #include +#include #include #include -#include "macros.hpp" -#include "utils.hpp" - -#include "detail/test_helpers.hpp" +#include static std::string -read_file(const char *path) +read_file(const std::string& path) { char buffer[1024]; - const int fd = open(path, O_RDONLY); + const int fd = open(path.c_str(), O_RDONLY); if (fd == -1) - ATF_FAIL("Cannot open " + std::string(path)); + ATF_FAIL("Cannot open " + path); const ssize_t length = read(fd, buffer, sizeof(buffer) - 1); close(fd); ATF_REQUIRE(length != -1); @@ -238,8 +234,13 @@ ATF_TEST_CASE_BODY(fork) ATF_REQUIRE(WIFEXITED(status)); ATF_REQUIRE_EQ(EXIT_SUCCESS, WEXITSTATUS(status)); - ATF_REQUIRE_EQ("Child stdout\n", read_file("atf_utils_fork_out.txt")); - ATF_REQUIRE_EQ("Child stderr\n", read_file("atf_utils_fork_err.txt")); + std::ostringstream out_name; + out_name << "atf_utils_fork_" << pid << "_out.txt"; + std::ostringstream err_name; + err_name << "atf_utils_fork_" << pid << "_err.txt"; + + ATF_REQUIRE_EQ("Child stdout\n", read_file(out_name.str())); + ATF_REQUIRE_EQ("Child stderr\n", read_file(err_name.str())); } ATF_TEST_CASE_WITHOUT_HEAD(grep_collection__set); @@ -353,6 +354,35 @@ ATF_TEST_CASE_BODY(wait__ok) } } +ATF_TEST_CASE_WITHOUT_HEAD(wait__ok_nested); +ATF_TEST_CASE_BODY(wait__ok_nested) +{ + 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) { + std::cerr.flush(); + std::cout << "Child output\n"; + std::cout.flush(); + std::cerr << "Child error\n"; + std::exit(50); + } else { + std::cout << "Parent output\n"; + std::cerr << "Parent error\n"; + atf::utils::wait(child, 50, "Child output\n", "Child error\n"); + std::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_TEST_CASE_WITHOUT_HEAD(wait__invalid_exitstatus); ATF_TEST_CASE_BODY(wait__invalid_exitstatus) { @@ -432,12 +462,6 @@ ATF_TEST_CASE_BODY(wait__save_stderr) } } -// ------------------------------------------------------------------------ -// Tests cases for the header file. -// ------------------------------------------------------------------------ - -HEADER_TC(include, "atf-c++/utils.hpp"); - // ------------------------------------------------------------------------ // Main. // ------------------------------------------------------------------------ @@ -476,12 +500,10 @@ ATF_INIT_TEST_CASES(tcs) ATF_ADD_TEST_CASE(tcs, redirect__other); ATF_ADD_TEST_CASE(tcs, wait__ok); + ATF_ADD_TEST_CASE(tcs, wait__ok_nested); ATF_ADD_TEST_CASE(tcs, wait__invalid_exitstatus); ATF_ADD_TEST_CASE(tcs, wait__invalid_stdout); ATF_ADD_TEST_CASE(tcs, wait__invalid_stderr); ATF_ADD_TEST_CASE(tcs, wait__save_stdout); ATF_ADD_TEST_CASE(tcs, wait__save_stderr); - - // Add the test cases for the header file. - ATF_ADD_TEST_CASE(tcs, include); } diff --git a/contrib/atf/atf-c.h b/contrib/atf/atf-c.h index 86606df3f9d2..701f7464f7ae 100644 --- a/contrib/atf/atf-c.h +++ b/contrib/atf/atf-c.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_H) #define ATF_C_H diff --git a/contrib/atf/atf-c/Kyuafile b/contrib/atf/atf-c/Kyuafile index 2f3b82e100f7..40fdb9215891 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 000000000000..edb7207d7cda --- /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_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_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 f44d87fb09c2..eda9596bd2b8 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 -#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 248330373b61..c119fc97a214 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 #include -#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 2e981cfdadba..a263f5063bd4 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 b08c9a54913c..c24b5737022f 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 #include @@ -33,20 +31,15 @@ #include -#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; @@ -241,12 +231,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 d7a908d3c56a..38afdf3743a6 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 @@ -37,18 +35,16 @@ #include #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 f36aa3eaef79..1eb2267d7e2d 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 a26e032e11c5..adaca649be25 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 #include @@ -36,13 +34,10 @@ #include -#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; @@ -509,12 +500,6 @@ ATF_TC_BODY(exec_unknown, tc) atf_check_result_fini(&result); } -/* --------------------------------------------------------------------- - * 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 3c2c8a9a61eb..000000000000 --- 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 -#include -#include -#include - -#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 19b86e2c2f65..000000000000 --- 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 - -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 aed181438b59..000000000000 --- 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 -#include - -#include - -#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 7925107cf83a..6059e7fdb0e6 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 e533a811ffc8..424a1c9dac73 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 #include @@ -34,12 +32,10 @@ #include #include +#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 c82209a48046..60b8e422ca9e 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 #include @@ -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 1b68d38b7722..25127529f81b 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 #include @@ -35,8 +33,7 @@ #include -#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 feb4ee53e763..8ee3d697c223 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 #include +#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 c0d07a3a337a..5d29440df468 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 #include 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 6ebf36c8bbef..3909c29fb991 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 #include #include -#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 22cbca439b36..5ff7648c3c7e 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 @@ -47,13 +45,11 @@ #include #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 ec77c3bb73d4..1c6c0eba64b2 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 #include @@ -36,10 +32,9 @@ #include #include +#include #include -#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 043304a0c7d3..3dbc4d3ba7ef 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 #include @@ -39,9 +37,8 @@ #include -#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 0d005ad05181..d14216eb409f 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 #include +#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 2c0fbcba1eda..b25006680641 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 #include @@ -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 3aa576cae6b3..82a715d28be8 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 #include #include +#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 7395adfebd97..34aaae25652b 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 #include #include +#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 a3ed7a22745e..7ca8e8ad6cd9 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 #include +#include #include -#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 644ab6926c15..0982e20f7dd5 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 #include #include +#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 bc36b570e7d3..8e08b6c57466 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 #include @@ -38,11 +36,9 @@ #include #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 b4aad3d93a18..81158d0a5a41 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 #include +#include +#include #include -#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 61f1b67c980e..47b90bccf85e 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 diff --git a/contrib/atf/atf-c/detail/process_test.c b/contrib/atf/atf-c/detail/process_test.c index 9e55f70e3214..5ae5565b6a2b 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 #include @@ -43,10 +41,8 @@ #include #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 d8a8905f2c17..cfc8676bebcb 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 @@ -36,8 +34,6 @@ #include #include -#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 0b4f3e4756ce..7f51fe03f74b 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 7c8285b5193c..a986c32ae3c8 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 @@ -42,10 +40,9 @@ #include -#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 aacbf32b3746..827d46eeb8b7 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 #include #include #include +#include + #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 3037ba4189c8..a601c293ffe4 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 -#include "atf-c/error_fwd.h" +#include + +#include +#include 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 d91e8d1dcf7e..3b1d7e7fe2a4 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 #include #include #include +#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 8f8ddf4ccbef..b2820b6b7cf8 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 #include +#include #include -#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 7bdf9c83129b..5d6c8e56f4f0 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 #include @@ -33,9 +31,8 @@ #include -#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 a62ae0ad615b..439384b4950e 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 @@ -38,17 +34,16 @@ #include #include +#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 5a89bf42b22a..bbb4ded5e8a8 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 #include #include #include -#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 d682bcfb4355..14a3e96cec7a 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 @@ -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 0bf37e7e3eb7..6a0f6e158de7 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 #include @@ -36,8 +34,7 @@ #include -#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 b75ff364b5a7..fd48466de06a 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 diff --git a/contrib/atf/atf-c/error.c b/contrib/atf/atf-c/error.c index aeb55a8ba47b..071daf6d2455 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 #include #include #include -#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 a8502801b063..260c0d07bf47 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 + #include #include -#include - /* --------------------------------------------------------------------- * 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 69d7e7dadbf5..d73e164b5cec 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 2c2a30789b2c..8bfa1249b391 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 #include @@ -35,9 +33,6 @@ #include #include "atf-c/defs.h" -#include "atf-c/error.h" - -#include "detail/test_helpers.h" /* --------------------------------------------------------------------- * Auxiliary functions. @@ -276,13 +271,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 9454fdfde807..c5ad1c75efbf 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 7c33ccbc1e10..485a159acecb 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 64c6786e477f..9525fcaae259 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 diff --git a/contrib/atf/atf-c/macros_test.c b/contrib/atf/atf-c/macros_test.c index adfc77c0ba0d..83578cda595f 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 #include @@ -41,10 +39,10 @@ #include -#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 d913ec91012d..ddffdb0ca1f7 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 cbdd00c4e0b0..92c3e12c99b1 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 #include @@ -41,14 +39,12 @@ #include #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 3f24186b0264..3fb695562ac8 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 4aaf9a54c242..616c37e94e68 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 #include #include -#include "detail/test_helpers.h" +#include "atf-c/detail/test_helpers.h" /* --------------------------------------------------------------------- * Auxiliary test cases. @@ -166,12 +164,6 @@ ATF_TC_BODY(config, tcin) * but good tests here could allow us to avoid much of the indirect * 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 7833498ac15e..f4f225772ca2 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 #include #include #include +#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 e4f9ba46e936..c176f7d96f5e 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 5da18b20bdac..de334a97483b 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 #include #include -#include "detail/test_helpers.h" - ATF_TC(getopt); ATF_TC_HEAD(getopt, tc) { @@ -80,12 +76,6 @@ ATF_TC_BODY(getopt, tc) "invalid"); } -/* --------------------------------------------------------------------- - * 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 e8de6823a374..1c5fda93230f 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 +#include 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 4409f7a4fb9e..1e2aac1ed3b6 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 -#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 666804d3a2c1..e4162b215fe5 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 57d6af8d2a25..fb81cd3a1d9e 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 #include @@ -39,9 +37,8 @@ #include -#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(); } diff --git a/contrib/atf/atf-sh/atf-check.1 b/contrib/atf/atf-sh/atf-check.1 index 66f931892501..a3bd379c7438 100644 --- a/contrib/atf/atf-sh/atf-check.1 +++ b/contrib/atf/atf-sh/atf-check.1 @@ -1,6 +1,3 @@ -.\" -.\" Automated Testing Framework (atf) -.\" .\" Copyright (c) 2008 The NetBSD Foundation, Inc. .\" All rights reserved. .\" @@ -25,8 +22,7 @@ .\" 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 March 2, 2014 +.Dd October 5, 2014 .Dt ATF-CHECK 1 .Os .Sh NAME @@ -39,13 +35,16 @@ .Op Fl e Ar action:arg ... .Op Fl x .Ar command -.Nm -.Fl h .Sh DESCRIPTION .Nm executes a given command and analyzes its results, including exit code, stdout and stderr. .Pp +.Em Test cases must use +.Em Xr atf-sh 3 Ns ' Ns s +.Em Nm atf_check +.Em builtin function instead of calling this utility directly. +.Pp In the first synopsis form, .Nm will execute the provided command and apply checks specified @@ -67,8 +66,6 @@ will print information about all supported options and their purpose. .Pp The following options are available: .Bl -tag -width XqualXvalueXX -.It Fl h -Shows a short summary of all available options and their purpose. .It Fl s Ar qual:value Analyzes termination status. Must be one of: @@ -133,21 +130,31 @@ Path to the system shell to be used when the is given to run commands. .El .Sh EXAMPLES +The following are sample invocations from within a test case. +Note that we use the +.Nm atf_check +function provided by +.Xr atf-sh 3 +instead of executing +.Nm +directly: .Bd -literal -offset indent # Exit code 0, nothing on stdout/stderr -atf-check 'true' +atf_check 'true' # Typical usage if failure is expected -atf-check -s not-exit:0 'false' +atf_check -s not-exit:0 'false' # Checking stdout/stderr echo foobar >expout -atf-check -o file:expout -e inline:"xx\etyy\en" \e +atf_check -o file:expout -e inline:"xx\etyy\en" \e 'echo foobar ; printf "xx\etyy\en" >&2' # Checking for a crash -atf-check -s signal:sigsegv my_program +atf_check -s signal:sigsegv my_program # Combined checks -atf-check -o match:foo -o not-match:bar echo foo baz +atf_check -o match:foo -o not-match:bar echo foo baz .Ed +.Sh SEE ALSO +.Xr atf-sh 1 diff --git a/contrib/atf/atf-sh/atf-check.cpp b/contrib/atf/atf-sh/atf-check.cpp index b08c020e95d5..866b7bb483a2 100644 --- a/contrib/atf/atf-sh/atf-check.cpp +++ b/contrib/atf/atf-sh/atf-check.cpp @@ -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. -// extern "C" { #include @@ -48,10 +44,9 @@ extern "C" { #include #include "atf-c++/check.hpp" -#include "atf-c++/config.hpp" - #include "atf-c++/detail/application.hpp" #include "atf-c++/detail/auto_array.hpp" +#include "atf-c++/detail/env.hpp" #include "atf-c++/detail/exceptions.hpp" #include "atf-c++/detail/fs.hpp" #include "atf-c++/detail/process.hpp" @@ -112,17 +107,20 @@ class temp_file : public std::ostream { int m_fd; public: - temp_file(const atf::fs::path& p) : + temp_file(const char* pattern) : std::ostream(NULL), m_fd(-1) { - atf::auto_array< char > buf(new char[p.str().length() + 1]); - std::strcpy(buf.get(), p.c_str()); + const atf::fs::path file = atf::fs::path( + atf::env::get("TMPDIR", "/tmp")) / pattern; + + atf::auto_array< char > buf(new char[file.str().length() + 1]); + std::strcpy(buf.get(), file.c_str()); m_fd = ::mkstemp(buf.get()); if (m_fd == -1) throw atf::system_error("atf_check::temp_file::temp_file(" + - p.str() + ")", "mkstemp(3) failed", + file.str() + ")", "mkstemp(3) failed", errno); m_path.reset(new atf::fs::path(buf.get())); @@ -350,7 +348,7 @@ execute_with_shell(char* const* argv) const std::string cmd = flatten_argv(argv); const char* sh_argv[4]; - sh_argv[0] = atf::config::get("atf_shell").c_str(); + sh_argv[0] = atf::env::get("ATF_SHELL", ATF_SHELL).c_str(); sh_argv[1] = "-c"; sh_argv[2] = cmd.c_str(); sh_argv[3] = NULL; @@ -623,9 +621,7 @@ run_output_check(const output_check oc, const atf::fs::path& path, } else if (oc.type == oc_ignore) { result = true; } else if (oc.type == oc_inline) { - atf::fs::path path2 = atf::fs::path(atf::config::get("atf_workdir")) - / "inline.XXXXXX"; - temp_file temp(path2); + temp_file temp("atf-check.XXXXXX"); temp.write(decode(oc.value)); temp.close(); diff --git a/contrib/atf/atf-sh/atf-check_test.sh b/contrib/atf/atf-sh/atf-check_test.sh index 7319a2b882ba..9542dfb0bd9f 100644 --- a/contrib/atf/atf-sh/atf-check_test.sh +++ b/contrib/atf/atf-sh/atf-check_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 Atf_Check and Atf-Shell variables are set by atf-sh. @@ -211,16 +207,7 @@ oflag_inline_body() h_pass "echo foo bar" -o inline:"foo bar\n" h_pass "printf 'foo bar'" -o inline:"foo bar" h_pass "printf '\t\n\t\n'" -o inline:"\t\n\t\n" - # XXX Ugly hack to workaround the lack of \e in FreeBSD. Also, \e doesn't - # seem to work as expected in Linux. Look for a nicer solution. - case $(uname) in - Darwin|FreeBSD|Linux) - h_pass "printf '\a\b\f\n\r\t\v'" -o inline:"\a\b\f\n\r\t\v" - ;; - *) - h_pass "printf '\a\b\e\f\n\r\t\v'" -o inline:"\a\b\e\f\n\r\t\v" - ;; - esac + h_pass "printf '\a\b\033\f\n\r\t\v'" -o inline:"\a\b\e\f\n\r\t\v" h_pass "printf '\011\022\033\012'" -o inline:"\011\022\033\012" h_fail "echo foo bar" -o inline:"foo bar" @@ -331,16 +318,7 @@ eflag_inline_body() h_pass "echo foo bar 1>&2" -e inline:"foo bar\n" h_pass "printf 'foo bar' 1>&2" -e inline:"foo bar" h_pass "printf '\t\n\t\n' 1>&2" -e inline:"\t\n\t\n" - # XXX Ugly hack to workaround the lack of \e in FreeBSD. Also, \e doesn't - # seem to work as expected in Linux. Look for a nicer solution. - case $(uname) in - Darwin|FreeBSD|Linux) - h_pass "printf '\a\b\f\n\r\t\v' 1>&2" -e inline:"\a\b\f\n\r\t\v" - ;; - *) - h_pass "printf '\a\b\e\f\n\r\t\v' 1>&2" -e inline:"\a\b\e\f\n\r\t\v" - ;; - esac + h_pass "printf '\a\b\033\f\n\r\t\v' 1>&2" -e inline:"\a\b\e\f\n\r\t\v" h_pass "printf '\011\022\033\012' 1>&2" -e inline:"\011\022\033\012" h_fail "echo foo bar 1>&2" -e inline:"foo bar" diff --git a/contrib/atf/atf-sh/atf-sh.1 b/contrib/atf/atf-sh/atf-sh.1 index ad77f04d3e22..ac4a135beb15 100644 --- a/contrib/atf/atf-sh/atf-sh.1 +++ b/contrib/atf/atf-sh/atf-sh.1 @@ -1,6 +1,3 @@ -.\" -.\" Automated Testing Framework (atf) -.\" .\" Copyright (c) 2010 The NetBSD Foundation, Inc. .\" All rights reserved. .\" @@ -25,24 +22,22 @@ .\" 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 March 2, 2014 +.Dd September 27, 2014 .Dt ATF-SH 1 .Os .Sh NAME .Nm atf-sh +.Op Fl s Ar shell .Nd interpreter for shell-based test programs .Sh SYNOPSIS .Nm .Ar script -.Nm -.Fl h .Sh DESCRIPTION .Nm is an interpreter that runs the test program given in .Ar script after loading the -.Xr atf-sh-api 3 +.Xr atf-sh 3 library. .Pp .Nm @@ -51,25 +46,62 @@ the system-wide shell defined by .Va ATF_SHELL . .Nm executes the interpreter, loads the -.Xr atf-sh-api 3 +.Xr atf-sh 3 library and then runs the script. +You must consider +.Nm atf-sh +to be a POSIX shell by default and thus should not use any non-standard +extensions. .Pp +The following options are available: +.Bl -tag -width XsXshellXXX +.It Fl s Ar shell +Specifies the shell to use instead of the value provided by +.Va ATF_SHELL . +.El +.Sh ENVIRONMENT +.Bl -tag -width ATFXLIBEXECDIRXX -compact +.It Va ATF_LIBEXECDIR +Overrides the builtin directory where +.Nm +is located. +Should not be overridden other than for testing purposes. +.It Va ATF_PKGDATADIR +Overrides the builtin directory where +.Pa libatf-sh.subr +is located. +Should not be overridden other than for testing purposes. +.It Va ATF_SHELL +Path to the system shell to be used in the generated scripts. +Scripts must not rely on this variable being set to select a specific +interpreter. +.El +.Sh EXAMPLES Scripts using -.Xr atf-sh-api 3 +.Xr atf-sh 3 should start with: .Bd -literal -offset indent #! /usr/bin/env atf-sh .Ed .Pp -The following options are available: -.Bl -tag -width XhXX -.It Fl h -Shows a short summary of all available options and their purpose. -.El +Alternatively, if you want to explicitly choose a shell interpreter, you cannot +rely on +.Xr env 1 +to find +.Nm . +Instead, you have to hardcode the path to +.Nm +in the script and then use the +.Fl s +option afterwards as a +.Em single parameter : +.Bd -literal -offset indent +#! /path/to/bin/atf-sh -s/bin/bash +.Ed .Sh ENVIRONMENT .Bl -tag -width ATFXSHELLXX -compact .It Va ATF_SHELL Path to the system shell to be used in the generated scripts. .El .Sh SEE ALSO -.Xr atf-sh-api 3 +.Xr atf-sh 3 diff --git a/contrib/atf/atf-sh/atf-sh.3 b/contrib/atf/atf-sh/atf-sh.3 new file mode 100644 index 000000000000..be56539d04ec --- /dev/null +++ b/contrib/atf/atf-sh/atf-sh.3 @@ -0,0 +1,372 @@ +.\" 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-SH 3 +.Os +.Sh NAME +.Nm atf_add_test_case , +.Nm atf_check , +.Nm atf_check_equal , +.Nm atf_config_get , +.Nm atf_config_has , +.Nm atf_expect_death , +.Nm atf_expect_exit , +.Nm atf_expect_fail , +.Nm atf_expect_pass , +.Nm atf_expect_signal , +.Nm atf_expect_timeout , +.Nm atf_fail , +.Nm atf_get , +.Nm atf_get_srcdir , +.Nm atf_pass , +.Nm atf_require_prog , +.Nm atf_set , +.Nm atf_skip , +.Nm atf_test_case +.Nd POSIX shell API to write ATF-based test programs +.Sh SYNOPSIS +.Nm atf_add_test_case +.Qq name +.Nm atf_check +.Qq command +.Nm atf_check_equal +.Qq expected_expression +.Qq actual_expression +.Nm atf_config_get +.Qq var_name +.Nm atf_config_has +.Qq var_name +.Nm atf_expect_death +.Qq reason +.Qq ... +.Nm atf_expect_exit +.Qq exitcode +.Qq reason +.Qq ... +.Nm atf_expect_fail +.Qq reason +.Qq ... +.Nm atf_expect_pass +.Qq +.Nm atf_expect_signal +.Qq signo +.Qq reason +.Qq ... +.Nm atf_expect_timeout +.Qq reason +.Qq ... +.Nm atf_fail +.Qq reason +.Nm atf_get +.Qq var_name +.Nm atf_get_srcdir +.Nm atf_pass +.Nm atf_require_prog +.Qq prog_name +.Nm atf_set +.Qq var_name +.Qq value +.Nm atf_skip +.Qq reason +.Nm atf_test_case +.Qq name +.Qq cleanup +.Sh DESCRIPTION +ATF +provides a simple but powerful interface to easily write test programs in +the POSIX shell language. +These are extremely helpful given that they are trivial to write due to the +language simplicity and the great deal of available external tools, so they +are often ideal to test other applications at the user level. +.Pp +Test programs written using this library must be run using the +.Xr atf-sh 1 +interpreter by putting the following on their very first line: +.Bd -literal -offset indent +#! /usr/bin/env atf-sh +.Ed +.Pp +Shell-based test programs always follow this template: +.Bd -literal -offset indent +atf_test_case tc1 +tc1_head() { + ... first test case's header ... +} +tc1_body() { + ... first test case's body ... +} + +atf_test_case tc2 cleanup +tc2_head() { + ... second test case's header ... +} +tc2_body() { + ... second test case's body ... +} +tc2_cleanup() { + ... second test case's cleanup ... +} + +.Ns ... additional test cases ... + +atf_init_test_cases() { + atf_add_test_case tc1 + atf_add_test_case tc2 + ... add additional test cases ... +} +.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 +.Nm atf_test_case +function, which takes a first parameter specifiying the test case's +name and instructs the library to set things up to accept it as a valid +test case. +The second parameter is optional and, if provided, must be +.Sq cleanup ; +providing this parameter allows defining a cleanup routine for the test +case. +It is important to note that this function +.Em does not +set the test case up for execution when the program is run. +In order to do so, a later registration is needed through the +.Nm atf_add_test_case +function detailed in +.Sx Program initialization . +.Pp +Later on, one must define the three parts of the body by providing two +or three functions (remember that the cleanup routine is optional). +These functions are named after the test case's identifier, and are +.Nm \*(Ltid\*(Gt_head , +.Nm \*(Ltid\*(Gt_body +and +.Nm \*(Ltid\*(Gt_cleanup . +None of these take parameters when executed. +.Ss Program initialization +The test program must define an +.Nm atf_init_test_cases +function, which is in charge of registering the test cases that will be +executed at run time by using the +.Nm atf_add_test_case +function, which takes the name of a test case as its single parameter. +This main function should not do anything else, except maybe sourcing +auxiliary source files that define extra variables and functions. +.Ss Configuration variables +The test case has read-only access to the current configuration variables +through the +.Nm atf_config_has +and +.Nm atf_config_get +methods. +The former takes a single parameter specifying a variable name and returns +a boolean indicating whether the variable is defined or not. +The latter can take one or two parameters. +If it takes only one, it specifies the variable from which to get the +value, and this variable must be defined. +If it takes two, the second one specifies a default value to be returned +if the variable is not available. +.Ss Access to the source directory +It is possible to get the path to the test case's source directory from +anywhere in the test program by using the +.Nm atf_get_srcdir +function. +It is interesting to note that this can be used inside +.Nm atf_init_test_cases +to silently include additional helper files from the source directory. +.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 +.Nm atf_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 , +or at any explicit call to +.Nm atf_pass , +.Nm atf_fail +or +.Nm atf_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 +.Nm atf_pass +does not take any parameters. +.Nm atf_fail +and +.Nm atf_skip +take a single string parameter that describes 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 Nm atf_expect_death Qo reason Qc Qo ... Qc +Expects the test case to exit prematurely regardless of the nature of the +exit. +.It Nm atf_expect_exit Qo exitcode Qc Qo reason Qc Qo ... Qc +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 Nm atf_expect_fail Qo reason Qc +Any failure raised in this mode is recorded, but 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 Nm atf_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 Nm atf_expect_signal Qo signo Qc Qo reason Qc Qo ... Qc +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 Nm atf_expect_timeout Qo reason Qc Qo ... Qc +Expects the test case to execute for longer than its timeout. +.El +.Ss Helper functions for common checks +.Bl -tag -width indent +.It Nm atf_check Qo [options] Qc Qo command Qc Qo [args] Qc +Executes a command, performs checks on its exit code and its output, and +fails the test case if any of the checks is not successful. +This function is particularly useful in integration tests that verify the +correct functioning of a binary. +.Pp +Internally, this function is just a wrapper over the +.Xr atf-check 1 +tool (whose manual page provides all details on the calling syntax). +You should always use the +.Nm atf_check +function instead of the +.Xr atf-check 1 +tool in your scripts; the latter is not even in the path. +.It Nm atf_check_equal Qo expected_expression Qc Qo actual_expression Qc +This function takes two expressions, evaluates them and, if their +results differ, aborts the test case with an appropriate failure message. +The common style is to put the expected value in the first parameter and the +actual value in the second parameter. +.El +.Sh EXAMPLES +The following shows a complete test program with a single test case that +validates the addition operator: +.Bd -literal -offset indent +atf_test_case addition +addition_head() { + atf_set "descr" "Sample tests for the addition operator" +} +addition_body() { + atf_check_equal 0 $((0 + 0)) + atf_check_equal 1 $((0 + 1)) + atf_check_equal 1 $((1 + 0)) + + atf_check_equal 2 $((1 + 1)) + + atf_check_equal 300 $((100 + 200)) +} + +atf_init_test_cases() { + atf_add_test_case addition +} +.Ed +.Pp +This other example shows how to include a file with extra helper functions +in the test program: +.Bd -literal -offset indent +.Ns ... definition of test cases ... + +atf_init_test_cases() { + . $(atf_get_srcdir)/helper_functions.sh + + atf_add_test_case foo1 + atf_add_test_case foo2 +} +.Ed +.Pp +This example demonstrates the use of the very useful +.Nm atf_check +function: +.Bd -literal -offset indent +# Check for silent output +atf_check -s exit:0 -o empty -e empty 'true' + +# Check for silent output and failure +atf_check -s exit:1 -o empty -e empty 'false' + +# Check for known stdout and silent stderr +echo foo >expout +atf_check -s exit:0 -o file:expout -e empty 'echo foo' + +# Generate a file for later inspection +atf_check -s exit:0 -o save:stdout -e empty 'ls' +grep foo ls || atf_fail "foo file not found in listing" + +# Or just do the match along the way +atf_check -s exit:0 -o match:"^foo$" -e empty 'ls' +.Ed +.Sh SEE ALSO +.Xr atf-check 1 , +.Xr atf-sh 1 , +.Xr atf-test-program 1 , +.Xr atf-test-case 4 diff --git a/contrib/atf/atf-sh/atf-sh.cpp b/contrib/atf/atf-sh/atf-sh.cpp index e985e79ab96f..997557322e45 100644 --- a/contrib/atf/atf-sh/atf-sh.cpp +++ b/contrib/atf/atf-sh/atf-sh.cpp @@ -1,6 +1,3 @@ -// -// Automated Testing Framework (atf) -// // Copyright (c) 2010 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. -// extern "C" { #include @@ -36,9 +32,8 @@ extern "C" { #include #include -#include "atf-c++/config.hpp" - #include "atf-c++/detail/application.hpp" +#include "atf-c++/detail/env.hpp" #include "atf-c++/detail/fs.hpp" #include "atf-c++/detail/sanity.hpp" @@ -63,9 +58,11 @@ static std::string* construct_script(const char* filename) { - const std::string libexecdir = atf::config::get("atf_libexecdir"); - const std::string pkgdatadir = atf::config::get("atf_pkgdatadir"); - const std::string shell = atf::config::get("atf_shell"); + const std::string libexecdir = atf::env::get( + "ATF_LIBEXECDIR", ATF_LIBEXECDIR); + const std::string pkgdatadir = atf::env::get( + "ATF_PKGDATADIR", ATF_PKGDATADIR); + const std::string shell = atf::env::get("ATF_SHELL", ATF_SHELL); std::string* command = new std::string(); command->reserve(512); @@ -111,6 +108,11 @@ construct_argv(const std::string& shell, const int interpreter_argc, class atf_sh : public atf::application::app { static const char* m_description; + atf::fs::path m_shell; + + options_set specific_options(void) const; + void process_option(int, const char*); + public: atf_sh(void); @@ -122,10 +124,38 @@ const char* atf_sh::m_description = "system sh(1) with the atf-sh library."; atf_sh::atf_sh(void) : - app(m_description, "atf-sh(1)") + app(m_description, "atf-sh(1)"), + m_shell(atf::fs::path(atf::env::get("ATF_SHELL", ATF_SHELL))) { } +atf_sh::options_set +atf_sh::specific_options(void) + const +{ + using atf::application::option; + options_set opts; + + INV(m_shell == atf::fs::path(atf::env::get("ATF_SHELL", ATF_SHELL))); + opts.insert(option('s', "shell", "Path to the shell interpreter to use; " + "default: " + m_shell.str())); + + return opts; +} + +void +atf_sh::process_option(int ch, const char* arg) +{ + switch (ch) { + case 's': + m_shell = atf::fs::path(arg); + break; + + default: + UNREACHABLE; + } +} + int atf_sh::main(void) { @@ -137,15 +167,14 @@ atf_sh::main(void) throw std::runtime_error("The test program '" + script.str() + "' " "does not exist"); - const std::string shell = atf::config::get("atf_shell"); - const char** argv = construct_argv(shell, m_argc, m_argv); + const char** argv = construct_argv(m_shell.str(), m_argc, m_argv); // Don't bother keeping track of the memory allocated by construct_argv: // we are going to exec or die immediately. - const int ret = execv(shell.c_str(), const_cast< char** >(argv)); + const int ret = execv(m_shell.c_str(), const_cast< char** >(argv)); INV(ret == -1); - std::cerr << "Failed to execute " << shell << ": " << std::strerror(errno) - << "\n"; + std::cerr << "Failed to execute " << m_shell.str() << ": " + << std::strerror(errno) << "\n"; return EXIT_FAILURE; } diff --git a/contrib/atf/atf-sh/atf_check_test.sh b/contrib/atf/atf-sh/atf_check_test.sh index a43a952817bb..163e905f1ab0 100644 --- a/contrib/atf/atf-sh/atf_check_test.sh +++ b/contrib/atf/atf-sh/atf_check_test.sh @@ -1,6 +1,3 @@ -# -# Automated Testing Framework (atf) -# # Copyright (c) 2007 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. -# # TODO: Bring in the checks in the bootstrap testsuite for atf_check. diff --git a/contrib/atf/atf-sh/config_test.sh b/contrib/atf/atf-sh/config_test.sh index f7f57f0199f6..048834c1c494 100644 --- a/contrib/atf/atf-sh/config_test.sh +++ b/contrib/atf/atf-sh/config_test.sh @@ -1,6 +1,3 @@ -# -# Automated Testing Framework (atf) -# # Copyright (c) 2007 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. -# atf_test_case has has_head() diff --git a/contrib/atf/atf-sh/integration_test.sh b/contrib/atf/atf-sh/integration_test.sh index 452c958ccc36..1150966f288f 100644 --- a/contrib/atf/atf-sh/integration_test.sh +++ b/contrib/atf/atf-sh/integration_test.sh @@ -1,6 +1,3 @@ -# -# Automated Testing Framework (atf) -# # Copyright (c) 2010 The NetBSD Foundation, Inc. # All rights reserved. # @@ -25,12 +22,14 @@ # 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. -# + +: ${ATF_SH:="__ATF_SH__"} create_test_program() { - echo '#! /usr/bin/env atf-sh' >"${1}" - cat >>"${1}" - chmod +x "${1}" + local output="${1}"; shift + echo "#! ${ATF_SH} ${*}" >"${output}" + cat >>"${output}" + chmod +x "${output}" } atf_test_case no_args @@ -40,7 +39,7 @@ no_args_body() atf-sh: ERROR: No test program provided atf-sh: See atf-sh(1) for usage details. EOF - atf_check -s eq:1 -o ignore -e file:experr atf-sh + atf_check -s eq:1 -o ignore -e file:experr "${ATF_SH}" } atf_test_case missing_script @@ -49,7 +48,7 @@ missing_script_body() cat >experr <>> hello bye <<< >>>foo bar<<< EOF - atf_check -s eq:0 -o file:expout -e empty atf-sh tp ' hello bye ' 'foo bar' + atf_check -s eq:0 -o file:expout -e empty "${ATF_SH}" tp \ + ' hello bye ' 'foo bar' +} + +atf_test_case custom_shell__command_line +custom_shell__command_line_body() +{ + cat >expout <custom-shell <expout <custom-shell <custom-shell <tp < #include @@ -39,12 +35,11 @@ #include -#include "atf-c/error.h" - #include "atf-c/detail/env.h" #include "atf-c/detail/fs.h" #include "atf-c/detail/test_helpers.h" #include "atf-c/detail/text.h" +#include "atf-c/error.h" /* --------------------------------------------------------------------- * Auxiliary functions. diff --git a/contrib/atf/test-programs/common.sh b/contrib/atf/test-programs/common.sh index ebeebdb2dfc6..91657523b732 100644 --- a/contrib/atf/test-programs/common.sh +++ b/contrib/atf/test-programs/common.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. -# get_helpers() { diff --git a/contrib/atf/test-programs/config_test.sh b/contrib/atf/test-programs/config_test.sh index a697bee2b6c1..510285215c2b 100644 --- a/contrib/atf/test-programs/config_test.sh +++ b/contrib/atf/test-programs/config_test.sh @@ -1,6 +1,3 @@ -# -# Automated Testing Framework (atf) -# # Copyright (c) 2007 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. -# atf_test_case vflag vflag_head() diff --git a/contrib/atf/test-programs/cpp_helpers.cpp b/contrib/atf/test-programs/cpp_helpers.cpp index d8a495e7c67e..ff9e54391936 100644 --- a/contrib/atf/test-programs/cpp_helpers.cpp +++ b/contrib/atf/test-programs/cpp_helpers.cpp @@ -1,6 +1,3 @@ -// -// Automated Testing Framework (atf) -// // Copyright (c) 2007 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. -// extern "C" { #include diff --git a/contrib/atf/test-programs/expect_test.sh b/contrib/atf/test-programs/expect_test.sh index 46293507db70..74e38e1d6abe 100644 --- a/contrib/atf/test-programs/expect_test.sh +++ b/contrib/atf/test-programs/expect_test.sh @@ -1,6 +1,3 @@ -# -# Automated Testing Framework (atf) -# # Copyright (c) 2007 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. -# check_result() { file="${1}"; shift diff --git a/contrib/atf/test-programs/meta_data_test.sh b/contrib/atf/test-programs/meta_data_test.sh index 35b008647390..150b9e2120d7 100644 --- a/contrib/atf/test-programs/meta_data_test.sh +++ b/contrib/atf/test-programs/meta_data_test.sh @@ -1,6 +1,3 @@ -# -# Automated Testing Framework (atf) -# # Copyright (c) 2010 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. -# atf_test_case no_descr no_descr_head() diff --git a/contrib/atf/test-programs/result_test.sh b/contrib/atf/test-programs/result_test.sh index b2b325c4daee..a87f08daaf5e 100644 --- a/contrib/atf/test-programs/result_test.sh +++ b/contrib/atf/test-programs/result_test.sh @@ -1,6 +1,3 @@ -# -# Automated Testing Framework (atf) -# # Copyright (c) 2007 The NetBSD Foundation, Inc. # All rights reserved. # @@ -25,21 +22,20 @@ # 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. -# -atf_test_case atf_run_warnings -atf_run_warnings_head() +atf_test_case runtime_warnings +runtime_warnings_head() { # The fact that this test case is in this test program is an abuse. atf_set "descr" "Tests that the test case prints a warning because" \ - "it is not being run by atf-run" + "it is being run outside of a runtime engine" } -atf_run_warnings_body() +runtime_warnings_body() { unset __RUNNING_INSIDE_ATF_RUN srcdir="$(atf_get_srcdir)" for h in $(get_helpers); do - atf_check -s eq:0 -o match:"passed" -e match:"WARNING.*atf-run" \ + atf_check -s eq:0 -o match:"passed" -e match:"WARNING.*kyua" \ "${h}" -s "${srcdir}" result_pass done } @@ -122,14 +118,14 @@ result_exception_head() result_exception_body() { for h in $(get_helpers cpp_helpers); do - atf_check -s exit:1 -o match:'failed: .*This is unhandled' \ - "${h}" -s "${srcdir}" result_exception + atf_check -s signal -o not-match:'failed: .*This is unhandled' \ + -e ignore "${h}" -s "${srcdir}" result_exception done } atf_init_test_cases() { - atf_add_test_case atf_run_warnings + atf_add_test_case runtime_warnings atf_add_test_case result_on_stdout atf_add_test_case result_to_file atf_add_test_case result_to_file_fail diff --git a/contrib/atf/test-programs/sh_helpers.sh b/contrib/atf/test-programs/sh_helpers.sh index eb55102dfeed..b27a541df547 100644 --- a/contrib/atf/test-programs/sh_helpers.sh +++ b/contrib/atf/test-programs/sh_helpers.sh @@ -1,6 +1,3 @@ -# -# Automated Testing Framework (atf) -# # Copyright (c) 2007 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. -# # ------------------------------------------------------------------------- # Helper tests for "t_cleanup". diff --git a/contrib/atf/test-programs/srcdir_test.sh b/contrib/atf/test-programs/srcdir_test.sh index 11d6831f8868..90a468a8f069 100644 --- a/contrib/atf/test-programs/srcdir_test.sh +++ b/contrib/atf/test-programs/srcdir_test.sh @@ -1,6 +1,3 @@ -# -# Automated Testing Framework (atf) -# # Copyright (c) 2007 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. -# create_files() { diff --git a/lib/atf/Makefile.inc b/lib/atf/Makefile.inc index 40da94673e12..392bbb23b236 100644 --- a/lib/atf/Makefile.inc +++ b/lib/atf/Makefile.inc @@ -25,29 +25,6 @@ # # $FreeBSD$ -_CFLAGS:= ${CFLAGS} -_CPPFLAGS:= ${CPPFLAGS} -_CXXFLAGS:= ${CXXFLAGS} - CFLAGS+= -DHAVE_CONFIG_H -CFLAGS+= -DATF_ARCH='"${MACHINE}"' -CFLAGS+= -DATF_BUILD_CC='"${CC}"' -CFLAGS+= -DATF_BUILD_CFLAGS='"${_CFLAGS}"' -CFLAGS+= -DATF_BUILD_CPP='"${CPP}"' -CFLAGS+= -DATF_BUILD_CPPFLAGS='"${_CPPFLAGS}"' -CFLAGS+= -DATF_BUILD_CXX='"${CXX}"' -CFLAGS+= -DATF_BUILD_CXXFLAGS='"${_CXXFLAGS}"' -CFLAGS+= -DATF_CONFDIR='"${CONFDIR}/atf"' -CFLAGS+= -DATF_C_TESTS_BASE='"${TESTSBASE}/lib/atf/libatf-c"' -CFLAGS+= -DATF_INCLUDEDIR='"${INCLUDEDIR}"' -CFLAGS+= -DATF_LIBDIR='"${LIBDIR}"' -CFLAGS+= -DATF_LIBEXECDIR='"${LIBEXECDIR}"' -CFLAGS+= -DATF_MACHINE='"${MACHINE_ARCH}"' -CFLAGS+= -DATF_M4='"/usr/bin/m4"' -CFLAGS+= -DATF_PKGDATADIR='"${SHAREDIR}/atf"' -CFLAGS+= -DATF_SHELL='"/bin/sh"' -CFLAGS+= -DATF_WORKDIR='"/tmp"' WARNS?= 3 - -# vim: syntax=make diff --git a/lib/atf/common.mk b/lib/atf/common.mk index 633820794799..581befba08fa 100644 --- a/lib/atf/common.mk +++ b/lib/atf/common.mk @@ -14,6 +14,6 @@ atf-version: atf-version-real @cmp -s atf-version atf-version-real \ || cp atf-version-real atf-version atf-version-real: .PHONY - @grep 'define VERSION' ${ATF}/bconfig.h \ + @grep 'define VERSION' ${ATF}/config.h \ | cut -d '"' -f 2 >atf-version-real CLEANFILES+= atf-version atf-version-real diff --git a/lib/atf/libatf-c++/Makefile b/lib/atf/libatf-c++/Makefile index a7a8d91de48d..352a8f4caa4d 100644 --- a/lib/atf/libatf-c++/Makefile +++ b/lib/atf/libatf-c++/Makefile @@ -30,7 +30,7 @@ LIB= atf-c++ PRIVATELIB= true -SHLIB_MAJOR= 1 +SHLIB_MAJOR= 2 # libatf-c++ depends on the C version of the ATF library to build. DPADD= ${LIBATF_C} @@ -52,7 +52,6 @@ CFLAGS+= -DHAVE_CONFIG_H SRCS= application.cpp \ build.cpp \ check.cpp \ - config.cpp \ env.cpp \ exceptions.cpp \ fs.cpp \ @@ -63,7 +62,6 @@ SRCS= application.cpp \ INCS= build.hpp \ check.hpp \ - config.hpp \ macros.hpp \ tests.hpp \ utils.hpp @@ -72,7 +70,8 @@ INCSDIR= ${INCLUDEDIR}/atf-c++ INCS+= atf-c++.hpp INCSDIR_atf-c++.hpp= ${INCLUDEDIR} -MAN= atf-c++-api.3 +MAN= atf-c++.3 +MLINKS+= atf-c++.3 atf-c-api++.3 # Backwards compatibility. .if ${MK_TESTS} != "no" SUBDIR= tests diff --git a/lib/atf/libatf-c++/tests/Makefile b/lib/atf/libatf-c++/tests/Makefile index 56355f295227..5f5a57515bb2 100644 --- a/lib/atf/libatf-c++/tests/Makefile +++ b/lib/atf/libatf-c++/tests/Makefile @@ -9,6 +9,8 @@ ATF= ${.CURDIR:H:H:H:H}/contrib/atf .PATH: ${ATF}/atf-c++ .PATH: ${ATF}/atf-c++/detail +CFLAGS+= -DATF_C_TESTS_BASE='"${TESTSBASE}/lib/atf/libatf-c"' +CFLAGS+= -DATF_INCLUDEDIR='"${INCLUDEDIR}"' CFLAGS+= -I${ATF} FILESDIR= ${TESTSDIR} @@ -18,7 +20,6 @@ FILES+= unused_test.cpp .for _T in atf_c++_test \ build_test \ check_test \ - config_test \ macros_test \ tests_test \ utils_test diff --git a/lib/atf/libatf-c++/tests/detail/Makefile b/lib/atf/libatf-c++/tests/detail/Makefile index b3fd4dcaf3b8..69c3e7bac0d0 100644 --- a/lib/atf/libatf-c++/tests/detail/Makefile +++ b/lib/atf/libatf-c++/tests/detail/Makefile @@ -7,6 +7,8 @@ TESTSDIR= ${TESTSBASE}/lib/atf/libatf-c++/detail ATF= ${.CURDIR:H:H:H:H:H}/contrib/atf .PATH: ${ATF}/atf-c++/detail +CFLAGS+= -DATF_C_TESTS_BASE='"${TESTSBASE}/lib/atf/libatf-c"' +CFLAGS+= -DATF_INCLUDEDIR='"${INCLUDEDIR}"' CFLAGS+= -I${ATF} .for _T in application_test \ @@ -14,7 +16,6 @@ CFLAGS+= -I${ATF} exceptions_test \ fs_test \ process_test \ - sanity_test \ text_test ATF_TESTS_CXX+= ${_T} SRCS.${_T}= ${_T}.cpp test_helpers.cpp diff --git a/lib/atf/libatf-c/Makefile b/lib/atf/libatf-c/Makefile index 4920eb5c78cd..0fbb4cad23b3 100644 --- a/lib/atf/libatf-c/Makefile +++ b/lib/atf/libatf-c/Makefile @@ -28,22 +28,31 @@ .include .include +_CFLAGS:= ${CFLAGS} +_CPPFLAGS:= ${CPPFLAGS} +_CXXFLAGS:= ${CXXFLAGS} + LIB= atf-c PRIVATELIB= true -SHLIB_MAJOR= 0 +SHLIB_MAJOR= 1 ATF= ${.CURDIR:H:H:H}/contrib/atf .PATH: ${ATF} .PATH: ${ATF}/atf-c .PATH: ${ATF}/atf-c/detail +CFLAGS+= -DATF_BUILD_CC='"${CC}"' +CFLAGS+= -DATF_BUILD_CFLAGS='"${_CFLAGS}"' +CFLAGS+= -DATF_BUILD_CPP='"${CPP}"' +CFLAGS+= -DATF_BUILD_CPPFLAGS='"${_CPPFLAGS}"' +CFLAGS+= -DATF_BUILD_CXX='"${CXX}"' +CFLAGS+= -DATF_BUILD_CXXFLAGS='"${_CXXFLAGS}"' CFLAGS+= -I${ATF} CFLAGS+= -I${.CURDIR} CFLAGS+= -I. SRCS= build.c \ check.c \ - config.c \ dynstr.c \ env.c \ error.c \ @@ -61,7 +70,6 @@ SRCS= build.c \ INCS= build.h \ check.h \ - config.h \ defs.h \ error.h \ error_fwd.h \ @@ -74,7 +82,8 @@ INCSDIR= ${INCLUDEDIR}/atf-c INCS+= atf-c.h INCSDIR_atf-c.h= ${INCLUDEDIR} -MAN= atf-c-api.3 +MAN= atf-c.3 +MLINKS+= atf-c.3 atf-c-api.3 # Backwards compatibility. .if ${MK_TESTS} != "no" SUBDIR= tests diff --git a/lib/atf/libatf-c/tests/Makefile b/lib/atf/libatf-c/tests/Makefile index 70ba1a5ca2ca..d5b6dc07520c 100644 --- a/lib/atf/libatf-c/tests/Makefile +++ b/lib/atf/libatf-c/tests/Makefile @@ -9,6 +9,7 @@ ATF= ${.CURDIR:H:H:H:H}/contrib/atf .PATH: ${ATF}/atf-c .PATH: ${ATF}/atf-c/detail +CFLAGS+= -DATF_INCLUDEDIR='"${INCLUDEDIR}"' CFLAGS+= -I${ATF} # macros_test.c contains a double 'const const' which will be gone with @@ -23,7 +24,6 @@ FILES+= unused_test.c .for _T in atf_c_test \ build_test \ check_test \ - config_test \ error_test \ macros_test \ tc_test \ diff --git a/lib/atf/libatf-c/tests/detail/Makefile b/lib/atf/libatf-c/tests/detail/Makefile index aa85aa311c50..02c1f2b444d3 100644 --- a/lib/atf/libatf-c/tests/detail/Makefile +++ b/lib/atf/libatf-c/tests/detail/Makefile @@ -7,6 +7,7 @@ TESTSDIR= ${TESTSBASE}/lib/atf/libatf-c/detail ATF= ${.CURDIR:H:H:H:H:H}/contrib/atf .PATH: ${ATF}/atf-c/detail +CFLAGS+= -DATF_INCLUDEDIR='"${INCLUDEDIR}"' CFLAGS+= -I${ATF} .for _T in dynstr_test \ diff --git a/libexec/atf/atf-check/Makefile b/libexec/atf/atf-check/Makefile index a36d94d30a20..2a9851eeea5a 100644 --- a/libexec/atf/atf-check/Makefile +++ b/libexec/atf/atf-check/Makefile @@ -36,6 +36,7 @@ SRCS= atf-check.cpp MAN= atf-check.1 CFLAGS+= -I${ATF} +CFLAGS+= -DATF_SHELL='"/bin/sh"' DPADD+= ${LIBATF_CXX} ${LIBATF_C} LDADD+= ${LDATF_CXX} ${LDATF_C} diff --git a/libexec/atf/atf-sh/Makefile b/libexec/atf/atf-sh/Makefile index 90a780cc7751..4e14643c0574 100644 --- a/libexec/atf/atf-sh/Makefile +++ b/libexec/atf/atf-sh/Makefile @@ -33,9 +33,13 @@ ATF= ${.CURDIR:H:H:H}/contrib/atf PROG_CXX= atf-sh SRCS= atf-sh.cpp -MAN= atf-sh.1 atf-sh-api.3 +MAN= atf-sh.1 atf-sh.3 +MLINKS+= atf-sh.3 atf-sh-api.3 # Backwards compatibility. CFLAGS+= -DHAVE_CONFIG_H +CFLAGS+= -DATF_LIBEXECDIR='"${LIBEXECDIR}"' +CFLAGS+= -DATF_PKGDATADIR='"${SHAREDIR}/atf"' +CFLAGS+= -DATF_SHELL='"/bin/sh"' CFLAGS+= -I${ATF} DPADD+= ${LIBATF_C} ${LIBATF_CXX} diff --git a/libexec/atf/atf-sh/tests/Makefile b/libexec/atf/atf-sh/tests/Makefile index e71b6b53a6b4..3360b974f9ee 100644 --- a/libexec/atf/atf-sh/tests/Makefile +++ b/libexec/atf/atf-sh/tests/Makefile @@ -16,8 +16,7 @@ ATF_TESTS_SH+= tp_test integration_test: Makefile ATF_TESTS_SH_SED_integration_test= \ - -e 's,atf_check,PATH=/usr/libexec:$${PATH} atf_check,g' \ - -e 's,/usr/bin/env *atf-sh,/usr/libexec/atf-sh,g' + -e 's,__ATF_SH__,/usr/libexec/atf-sh,g' SCRIPTS+= misc_helpers SCRIPTSDIR_misc_helpers=${TESTSDIR} diff --git a/share/man/man7/Makefile b/share/man/man7/Makefile index 9dcaad92bee8..78a4bbcae82a 100644 --- a/share/man/man7/Makefile +++ b/share/man/man7/Makefile @@ -1,7 +1,7 @@ # @(#)Makefile 8.1 (Berkeley) 6/5/93 # $FreeBSD$ -.include +.include #MISSING: eqnchar.7 ms.7 term.7 MAN= adding_user.7 \ @@ -37,4 +37,15 @@ MLINKS+= c99.7 c78.7 MLINKS+= c99.7 c89.7 MLINKS+= c99.7 c90.7 +.if ${MK_TESTS} != "no" +ATF= ${.CURDIR}/../../../contrib/atf +.PATH: ${ATF}/doc +MAN+= atf.7 + +CLEANFILES+= atf.7 +atf.7: atf.7.in + sed -e 's,__DOCDIR__,/usr/share/doc/atf,g' \ + <"${ATF}/doc/atf.7.in" >atf.7 +.endif + .include diff --git a/tools/build/mk/OptionalObsoleteFiles.inc b/tools/build/mk/OptionalObsoleteFiles.inc index 403d67ed78ec..09c52cbc6962 100644 --- a/tools/build/mk/OptionalObsoleteFiles.inc +++ b/tools/build/mk/OptionalObsoleteFiles.inc @@ -4145,6 +4145,8 @@ OLD_FILES+=usr/share/man/man8/telnetd.8.gz .if ${MK_TESTS} == yes OLD_FILES+=usr/bin/atf-sh +OLD_FILES+=usr/include/atf-c++/config.hpp +OLD_FILES+=usr/include/atf-c/config.h OLD_LIBS+=usr/lib/libatf-c++.a OLD_LIBS+=usr/lib/libatf-c++.so OLD_LIBS+=usr/lib/libatf-c++.so.1 @@ -4154,8 +4156,8 @@ OLD_LIBS+=usr/lib/libatf-c.a OLD_LIBS+=usr/lib/libatf-c.so OLD_LIBS+=usr/lib/libatf-c.so.1 OLD_LIBS+=usr/lib/libatf-c_p.a -OLD_LIBS+=usr/lib/private/libatf-c.so.1 -OLD_LIBS+=usr/lib/private/libatf-c++.so.2 +OLD_LIBS+=usr/lib/private/libatf-c.so.0 +OLD_LIBS+=usr/lib/private/libatf-c++.so.1 .if ${TARGET_ARCH} == "amd64" || ${TARGET_ARCH} == "powerpc64" OLD_LIBS+=usr/lib32/libatf-c++.a OLD_LIBS+=usr/lib32/libatf-c++.so @@ -4166,8 +4168,8 @@ OLD_LIBS+=usr/lib32/libatf-c.a OLD_LIBS+=usr/lib32/libatf-c.so OLD_LIBS+=usr/lib32/libatf-c.so.1 OLD_LIBS+=usr/lib32/libatf-c_p.a -OLD_LIBS+=usr/lib32/private/libatf-c.so.1 -OLD_LIBS+=usr/lib32/private/libatf-c++.so.2 +OLD_LIBS+=usr/lib32/private/libatf-c.so.0 +OLD_LIBS+=usr/lib32/private/libatf-c++.so.1 .endif OLD_FILES+=usr/libdata/pkgconfig/atf-c++.pc OLD_FILES+=usr/libdata/pkgconfig/atf-c.pc @@ -4194,8 +4196,10 @@ OLD_DIRS+=usr/tests/usr.bin/atf OLD_FILES+=usr/tests/lib/atf/libatf-c/test_helpers_test OLD_FILES+=usr/tests/lib/atf/test-programs/fork_test OLD_FILES+=usr/tests/lib/atf/libatf-c++/application_test +OLD_FILES+=usr/tests/lib/atf/libatf-c++/config_test OLD_FILES+=usr/tests/lib/atf/libatf-c++/detail/expand_test OLD_FILES+=usr/tests/lib/atf/libatf-c++/detail/parser_test +OLD_FILES+=usr/tests/lib/atf/libatf-c++/detail/sanity_test OLD_FILES+=usr/tests/lib/atf/libatf-c++/detail/ui_test OLD_FILES+=usr/tests/lib/atf/libatf-c++/env_test OLD_FILES+=usr/tests/lib/atf/libatf-c++/exceptions_test @@ -4207,6 +4211,7 @@ OLD_FILES+=usr/tests/lib/atf/libatf-c++/sanity_test OLD_FILES+=usr/tests/lib/atf/libatf-c++/pkg_config_test OLD_FILES+=usr/tests/lib/atf/libatf-c++/text_test OLD_FILES+=usr/tests/lib/atf/libatf-c++/ui_test +OLD_FILES+=usr/tests/lib/atf/libatf-c/config_test OLD_FILES+=usr/tests/lib/atf/libatf-c/dynstr_test OLD_FILES+=usr/tests/lib/atf/libatf-c/env_test OLD_FILES+=usr/tests/lib/atf/libatf-c/fs_test