Import atf-0.17:

Experimental version released on February 14th, 2013.

* Added the atf_utils_cat_file, atf_utils_compare_file,
  atf_utils_copy_file, atf_utils_create_file, atf_utils_file_exists,
  atf_utils_fork, atf_utils_grep_file, atf_utils_grep_string,
  atf_utils_readline, atf_utils_redirect and atf_utils_wait utility
  functions to atf-c-api.  Documented the already-public
  atf_utils_free_charpp function.

* Added the cat_file, compare_file, copy_file, create_file, file_exists,
  fork, grep_collection, grep_file, grep_string, redirect and wait
  functions to the atf::utils namespace of atf-c++-api.  These are
  wrappers around the same functions added to the atf-c-api library.

* Added the ATF_CHECK_MATCH, ATF_CHECK_MATCH_MSG, ATF_REQUIRE_MATCH and
  ATF_REQUIRE_MATCH_MSG macros to atf-c to simplify the validation of a
  string against a regular expression.

* Miscellaneous fixes for manpage typos and compilation problems with
  clang.

* Added caching of the results of those configure tests that rely on
  executing a test program.  This should help crossbuild systems by
  providing a mechanism to pre-specify what the results should be.

* X-NetBSD-PR bin/45690: Make atf-report convert any non-printable
  characters to a plain-text representation (matching their
  corresponding hexadecimal entities) in XML output files.  This is to
  prevent the output of test cases from breaking xsltproc later.

Note that this import, compared to the one for 0.16, brings in all the
files that are part of the release.  This is to follow the Subversion
Primer guidelines, which mention that all files should be imported first
and only dropped when merging into contrib/atf/.

Approved by:	rpaulo (mentor)
This commit is contained in:
Julio Merino 2013-11-15 21:28:06 +00:00
parent f1e38e2131
commit b2b6e97c46
111 changed files with 25191 additions and 7445 deletions

223
INSTALL Normal file
View file

@ -0,0 +1,223 @@
Installation instructions Automated Testing Framework
===========================================================================
Introduction
************
ATF uses the GNU Automake, GNU Autoconf and GNU Libtool utilities as its
build system. These are used only when compiling the application from the
source code package. If you want to install ATF from a binary package, you
do not need to read this document.
For the impatient:
$ ./configure
$ make
Gain root privileges
# make install
Drop root privileges
$ make installcheck
Or alternatively, install as a regular user into your home directory:
$ ./configure --prefix ~/local
$ make
$ make install
$ make installcheck
Dependencies
************
To build and use ATF successfully you need:
* A standards-compliant C/C++ complier. For example, GNU GCC 2.95 will not
work.
* A POSIX shell interpreter.
* A make(1) utility.
If you are building ATF from the code on the repository, you will also need
to have GNU autoconf, automake and libtool installed.
Regenerating the build system
*****************************
If you are building ATF from code extracted from the repository, you must
first regenerate the files used by the build system. You will also need to
do this if you modify configure.ac, Makefile.am or any of the other build
system files. To do this, simply run:
$ autoreconf -i -s
For formal releases, no extra steps are needed.
General build procedure
***********************
To build and install the source package, you must follow these steps:
1. Configure the sources to adapt to your operating system. This is done
using the 'configure' script located on the sources' top directory,
and it is usually invoked without arguments unless you want to change
the installation prefix. More details on this procedure are given on a
later section.
2. Build the sources to generate the binaries and scripts. Simply run
'make' on the sources' top directory after configuring them. No
problems should arise.
3. Install the program by running 'make install'. You may need to become
root to issue this step.
4. Issue any manual installation steps that may be required. These are
described later in their own section.
5. Check that the installed programs work by running 'make installcheck'.
You do not need to be root to do this, even though some checks will not
be run otherwise.
Configuration flags
*******************
The most common, standard flags given to 'configure' are:
* --prefix=directory
Possible values: Any path
Default: /usr/local
Specifies where the program (binaries and all associated files) will
be installed.
* --sysconfdir=directory
Possible values: Any path
Default: /usr/local/etc
Specifies where the installed programs will look for configuration files.
'/atf' will be appended to the given path unless ATF_CONFSUBDIR is
redefined as explained later on.
* --help
Shows information about all available flags and exits immediately,
without running any configuration tasks.
The following environment variables are specific to ATF's 'configure'
script:
* ATF_BUILD_CC
Possible values: empty, a absolute or relative path to a C compiler.
Default: the value of CC as detected by the configure script.
Specifies the C compiler that ATF will use at run time whenever the
build-time-specific checks are used.
* ATF_BUILD_CFLAGS
Possible values: empty, a list of valid C compiler flags.
Default: the value of CFLAGS as detected by the configure script.
Specifies the C compiler flags that ATF will use at run time whenever the
build-time-specific checks are used.
* ATF_BUILD_CPP
Possible values: empty, a absolute or relative path to a C/C++
preprocessor.
Default: the value of CPP as detected by the configure script.
Specifies the C/C++ preprocessor that ATF will use at run time whenever
the build-time-specific checks are used.
* ATF_BUILD_CPPFLAGS
Possible values: empty, a list of valid C/C++ preprocessor flags.
Default: the value of CPPFLAGS as detected by the configure script.
Specifies the C/C++ preprocessor flags that ATF will use at run time
whenever the build-time-specific checks are used.
* ATF_BUILD_CXX
Possible values: empty, a absolute or relative path to a C++ compiler.
Default: the value of CXX as detected by the configure script.
Specifies the C++ compiler that ATF will use at run time whenever the
build-time-specific checks are used.
* ATF_BUILD_CXXFLAGS
Possible values: empty, a list of valid C++ compiler flags.
Default: the value of CXXFLAGS as detected by the configure script.
Specifies the C++ compiler flags that ATF will use at run time whenever
the build-time-specific checks are used.
* ATF_CONFSUBDIR
Possible values: empty, a relative path.
Default: atf.
Specifies the subdirectory of the configuration directory (given by the
--sysconfdir argument) under which ATF will search for its configuration
files.
* ATF_SHELL
Possible values: empty, absolute path to a POSIX shell interpreter.
Default: empty.
Specifies the POSIX shell interpreter that ATF will use at run time to
execute its scripts and the test programs written using the atf-sh
library. If empty, the configure script will try to find a suitable
interpreter for you.
* ATF_WORKDIR
Possible values: empty, an absolute path.
Default: /tmp or /var/tmp, depending on availability.
Specifies the directory that ATF will use to place its temporary files
and work directories for test cases. This is just a default and can be
overriden at run time.
* GDB
Possible values: empty, absolute path to GNU GDB.
Default: empty.
Specifies the path to the GNU GDB binary that atf-run will use to gather
a stack trace of a crashing test program. If empty, the configure script
will try to find a suitable binary for you.
The following flags are specific to ATF's 'configure' script:
* --enable-developer
Possible values: yes, no
Default: 'yes' in Git HEAD builds; 'no' in formal releases.
Enables several features useful for development, such as the inclusion
of debugging symbols in all objects or the enforcement of compilation
warnings.
The compiler will be executed with an exhaustive collection of warning
detection features regardless of the value of this flag. However, such
warnings are only fatal when --enable-developer is 'yes'.
* --enable-tools
Possible values: yes, no
Default: no.
Enables the build of the deprecated atf-config, atf-report, atf-run
and atf-version tools. atf-report and atf-run have been superseded by
Kyua, and atf-config and atf-version are unnecessary.
Post-installation steps
***********************
After installing ATF, you have to register the DTDs it provides into the
system-wide XML catalog. See the comments at the top of the files in
${datadir}/share/xml/atf to see the correct public identifiers. This
directory will typically be /usr/local/share/xml/atf or /usr/share/xml/atf.
Failure to do so will lead to further errors when processing the XML files
generated by atf-report.
===========================================================================
vim: filetype=text:textwidth=75:expandtab:shiftwidth=2:softtabstop=2

View file

@ -101,11 +101,14 @@ endif
PHONY_TARGETS += installcheck-kyua
if HAVE_KYUA
if !ENABLE_TOOLS
INSTALLCHECK_TARGETS += installcheck-kyua
endif
installcheck-kyua:
cd $(pkgtestsdir) && $(TESTS_ENVIRONMENT) $(KYUA) test
endif
installcheck-targets: $(INSTALLCHECK_TARGETS)
installcheck-local: $(INSTALLCHECK_TARGETS)
pkgtests_DATA = Kyuafile
if ENABLE_TOOLS

File diff suppressed because it is too large Load diff

34
NEWS
View file

@ -2,6 +2,40 @@ Major changes between releases Automated Testing Framework
===========================================================================
Changes in version 0.17
***********************
Experimental version released on February 14th, 2013.
* Added the atf_utils_cat_file, atf_utils_compare_file,
atf_utils_copy_file, atf_utils_create_file, atf_utils_file_exists,
atf_utils_fork, atf_utils_grep_file, atf_utils_grep_string,
atf_utils_readline, atf_utils_redirect and atf_utils_wait utility
functions to atf-c-api. Documented the already-public
atf_utils_free_charpp function.
* Added the cat_file, compare_file, copy_file, create_file, file_exists,
fork, grep_collection, grep_file, grep_string, redirect and wait
functions to the atf::utils namespace of atf-c++-api. These are
wrappers around the same functions added to the atf-c-api library.
* Added the ATF_CHECK_MATCH, ATF_CHECK_MATCH_MSG, ATF_REQUIRE_MATCH and
ATF_REQUIRE_MATCH_MSG macros to atf-c to simplify the validation of a
string against a regular expression.
* Miscellaneous fixes for manpage typos and compilation problems with
clang.
* Added caching of the results of those configure tests that rely on
executing a test program. This should help crossbuild systems by
providing a mechanism to pre-specify what the results should be.
* PR bin/45690: Make atf-report convert any non-printable characters to
a plain-text representation (matching their corresponding hexadecimal
entities) in XML output files. This is to prevent the output of test
cases from breaking xsltproc later.
Changes in version 0.16
***********************

184
TODO Normal file
View file

@ -0,0 +1,184 @@
Things to do Automated Testing Framework
===========================================================================
Last revised: November 30th, 2010
This document includes the list of things that need to be done in ATF that
are most requested by the users. This information used to be available in
an ad-hoc bug tracker but that proved to be a bad idea. I have collected
all worthy comments in here.
Please note that most work these days is going into Kyua (see
http://code.google.com/p/kyua/). The ideas listed here apply to the
components of ATF that have *not* been migrated to the new codebase yet.
For bug reports or ideas that apply to the components that already have
been migrated, please use the bug tracker in the URL above. Similarly,
whenever a component is migrated, the ideas in this file should be revised
and migrated to the new bug tracker where appropriate.
---------------------------------------------------------------------------
Add build-time checks to atf-sh
The 0.7 release introduced build-time tests to atf-c and atf-c++, but not
to atf-sh. Expose the functionality to the shell interface.
This will probably require writing an atf-build utility that exposes the C
code and can be called from the shell.
---------------------------------------------------------------------------
Revisit what to do when an Atffile lists a non-existent file
---------------------------------------------------------------------------
Add ATF_CHECK* versions to atf-c++ to support non-fatal tests
---------------------------------------------------------------------------
Implement race-condition tests
gcooper:
I would think that stress/negative tests would be of more value than race
condition tests (they're similar, but not exactly the same in my mind).
In particular,
1. Feed through as much data as possible to determine where reporting
breaks down.
2. Feed through data quickly and terminate ASAP. The data should be
captured. Terminate child applications with unexpected exit codes and
signals (in particular, SIGCHLD, SIGPIPE, exit codes that terminate,
etc).
3. Open up a file descriptor in the test application, don't close the file
descriptor.
4. fork(2) a process; don't wait(2) for the application to complete.
There are other scenarios that could be exercised, but these are the ones
I could think of off the topic of my head.
--
jmmv:
1. The thing is: how do you express any of this in a portable/abstract
interface? How do you express that a test case "receives data"? What
does that exactly mean? I don't think the framework should care about
this: each test should be free to decide where its data is and how to
deal with it.
2. Ditto.
3. Not sure I understand your request, but testing for "unexpected exit
codes" is already supported. See wiki:DesignXFail for the feature
design details.
4. What's the problem with this case? The test case exits right away after
terminating the execution of its body; any open file descriptors,
leaked memory, etc. die with it.
5. forking and not waiting for a subprocess was a problem already
addressed.
I kinda have an idea of what Antti means with "race condition tests", but
every time I have tried to describe my understanding of matters I seem to
be wrong. Would be nice to have a clear description of what this involves;
in particular, what are the expectations from the framework and how should
the feature be exposed.
As of now, what I understand by "race condition test" is: a test case that
exercises a race condition. The test case may finish without triggering
the race, in which case it just exists with a successful status.
Otherwise, if the race triggers, the test case gets stuck and times out.
The result should be reported as an "expected failure" different from
timeout.
--
pooka:
Yup. Plus some atf-wide mechanism for the operator to supply some kind of
guideline if the test should try to trigger the race for a second or for
an hour.
--
jmmv:
Alright. While mocking up some code for this, I think that your two
requests are complementary.
On the one hand, when you are talking about a "race condition" test you
really mean an "expected race condition" test. Correct? If so, we need to
extend the xfail mechanism to add one more case, which is to report any
failures as a race condition error and, if there is no failure, report the
test as successful.
On the other hand, the atf-wide mechanism to support how long the test
should run for can be thought as a "stress test" mechanism. I.e. run this
test for X time / iterations and report its results regularly without
involving xfail at all.
So, with this in mind:
* For a test that triggers an unfixed race condition, you set xfail to
race mode and define the test as a stress test. Any failures are
reported as expected failures.
* For a test that verifies a supposedly-fixed race condition, you do *not*
set xfail to race mode, and only set the test to stress test. Any
failures are reported as real failures.
These stress test cases implement a single iteration of the test and
atf-run is in charge of running the test several times, stopping on the
first failure.
Does that make sense?
---------------------------------------------------------------------------
Implement ATF_REQUIRE_ERRNO
pooka:
Most of the lines in tests against system functionality are:
if (syscall(args) == -1)
atf_tc_fail_errno("flop")
Some shorthand would be helpful, like ATF_REQUIRE_ERRNO(syscall(args))
Also, a variant which allows arbitrary return value checks (e.g. "!= 0" or
"< 124" or "!= size") would be nice.
--
gcooper:
There's a problem with this request; not all functions fail in the same
way ... in particular compare the pthread family of functions (which
return errno) vs many native syscalls. Furthermore, compare some
fcntl-like syscalls vs other syscalls. One size fits all solutions may not
be a wise idea in this case, so I think that the problem statement needs
to be better defined, because the above request is too loose.
FWIW, there's also a TEST macro in LTP, which tests for non-zero status,
and sets an appropriate set of global variables for errnos and return
codes, respectively. It was a good idea, but has been mostly abandoned
because it's too difficult to define a success and failure in a universal
manner, so I think that we need to be careful with what's implemented in
ATF to not repeat the mistakes that others have made.
--
jmmv:
I think you've got a good point.
This was mostly intended to simplify the handling of the stupid errno
global variable. I think this is valuable to have, but maybe the
macro/function name should be different because _ERRNO can be confusing.
Probably something like an ATF_CHECK_LIBC / ATF_CHECK_PTHREAD approach
would be more flexible and simple.
===========================================================================
vim: filetype=text:textwidth=75:expandtab:shiftwidth=2:softtabstop=2

1022
aclocal.m4 vendored Normal file

File diff suppressed because it is too large Load diff

View file

@ -27,18 +27,12 @@
# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
dist-hook: check-install
PHONY_TARGETS += check-install
check-install: $(srcdir)/INSTALL
$(srcdir)/admin/check-install.sh $(srcdir)/INSTALL
dist-hook: check-style
PHONY_TARGETS += check-style
check-style:
$(srcdir)/admin/check-style.sh
EXTRA_DIST += admin/check-install.sh \
admin/check-style-common.awk \
EXTRA_DIST += admin/check-style-common.awk \
admin/check-style-c.awk \
admin/check-style-cpp.awk \
admin/check-style-man.awk \

View file

@ -1,10 +1,9 @@
#! /bin/sh
# Wrapper for compilers which do not understand '-c -o'.
scriptversion=2012-01-04.17; # UTC
scriptversion=2012-03-05.13; # UTC
# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2009, 2010, 2012 Free
# Software Foundation, Inc.
# Copyright (C) 1999-2012 Free Software Foundation, Inc.
# Written by Tom Tromey <tromey@cygnus.com>.
#
# This program is free software; you can redistribute it and/or modify
@ -79,6 +78,48 @@ func_file_conv ()
esac
}
# func_cl_dashL linkdir
# Make cl look for libraries in LINKDIR
func_cl_dashL ()
{
func_file_conv "$1"
if test -z "$lib_path"; then
lib_path=$file
else
lib_path="$lib_path;$file"
fi
linker_opts="$linker_opts -LIBPATH:$file"
}
# func_cl_dashl library
# Do a library search-path lookup for cl
func_cl_dashl ()
{
lib=$1
found=no
save_IFS=$IFS
IFS=';'
for dir in $lib_path $LIB
do
IFS=$save_IFS
if $shared && test -f "$dir/$lib.dll.lib"; then
found=yes
lib=$dir/$lib.dll.lib
break
fi
if test -f "$dir/$lib.lib"; then
found=yes
lib=$dir/$lib.lib
break
fi
done
IFS=$save_IFS
if test "$found" != yes; then
lib=$lib.lib
fi
}
# func_cl_wrapper cl arg...
# Adjust compile command to suit cl
func_cl_wrapper ()
@ -109,43 +150,34 @@ func_cl_wrapper ()
;;
esac
;;
-I)
eat=1
func_file_conv "$2" mingw
set x "$@" -I"$file"
shift
;;
-I*)
func_file_conv "${1#-I}" mingw
set x "$@" -I"$file"
shift
;;
-l*)
lib=${1#-l}
found=no
save_IFS=$IFS
IFS=';'
for dir in $lib_path $LIB
do
IFS=$save_IFS
if $shared && test -f "$dir/$lib.dll.lib"; then
found=yes
set x "$@" "$dir/$lib.dll.lib"
break
fi
if test -f "$dir/$lib.lib"; then
found=yes
set x "$@" "$dir/$lib.lib"
break
fi
done
IFS=$save_IFS
test "$found" != yes && set x "$@" "$lib.lib"
-l)
eat=1
func_cl_dashl "$2"
set x "$@" "$lib"
shift
;;
-l*)
func_cl_dashl "${1#-l}"
set x "$@" "$lib"
shift
;;
-L)
eat=1
func_cl_dashL "$2"
;;
-L*)
func_file_conv "${1#-L}"
if test -z "$lib_path"; then
lib_path=$file
else
lib_path="$lib_path;$file"
fi
linker_opts="$linker_opts -LIBPATH:$file"
func_cl_dashL "${1#-L}"
;;
-static)
shared=false

244
admin/config.guess vendored
View file

@ -1,10 +1,10 @@
#! /bin/sh
# Attempt to guess a canonical system name.
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
# 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
# 2011, 2012 Free Software Foundation, Inc.
# 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
# Free Software Foundation, Inc.
timestamp='2012-01-01'
timestamp='2009-12-30'
# This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
@ -57,8 +57,8 @@ GNU config.guess ($timestamp)
Originally written by Per Bothner.
Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
Free Software Foundation, Inc.
2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free
Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
@ -145,7 +145,7 @@ UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown
case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
*:NetBSD:*:*)
# NetBSD (nbsd) targets should (where applicable) match one or
# more of the tuples: *-*-netbsdelf*, *-*-netbsdaout*,
# more of the tupples: *-*-netbsdelf*, *-*-netbsdaout*,
# *-*-netbsdecoff* and *-*-netbsd*. For targets that recently
# switched to ELF, *-*-netbsd* would select the old
# object file format. This provides both forward
@ -181,7 +181,7 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
fi
;;
*)
os=netbsd
os=netbsd
;;
esac
# The OS release
@ -224,7 +224,7 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'`
;;
*5.*)
UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'`
UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'`
;;
esac
# According to Compaq, /usr/sbin/psrinfo has been available on
@ -270,10 +270,7 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
# A Xn.n version is an unreleased experimental baselevel.
# 1.2 uses "1.2" for uname -r.
echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
# Reset EXIT trap before exiting to avoid spurious non-zero exit code.
exitcode=$?
trap '' 0
exit $exitcode ;;
exit ;;
Alpha\ *:Windows_NT*:*)
# How do we know it's Interix rather than the generic POSIX subsystem?
# Should we change UNAME_MACHINE based on the output of uname instead
@ -299,7 +296,7 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
echo s390-ibm-zvmoe
exit ;;
*:OS400:*:*)
echo powerpc-ibm-os400
echo powerpc-ibm-os400
exit ;;
arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*)
echo arm-acorn-riscix${UNAME_RELEASE}
@ -398,23 +395,23 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
# MiNT. But MiNT is downward compatible to TOS, so this should
# be no problem.
atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*)
echo m68k-atari-mint${UNAME_RELEASE}
echo m68k-atari-mint${UNAME_RELEASE}
exit ;;
atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*)
echo m68k-atari-mint${UNAME_RELEASE}
exit ;;
exit ;;
*falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*)
echo m68k-atari-mint${UNAME_RELEASE}
echo m68k-atari-mint${UNAME_RELEASE}
exit ;;
milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*)
echo m68k-milan-mint${UNAME_RELEASE}
exit ;;
echo m68k-milan-mint${UNAME_RELEASE}
exit ;;
hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*)
echo m68k-hades-mint${UNAME_RELEASE}
exit ;;
echo m68k-hades-mint${UNAME_RELEASE}
exit ;;
*:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*)
echo m68k-unknown-mint${UNAME_RELEASE}
exit ;;
echo m68k-unknown-mint${UNAME_RELEASE}
exit ;;
m68k:machten:*:*)
echo m68k-apple-machten${UNAME_RELEASE}
exit ;;
@ -484,8 +481,8 @@ EOF
echo m88k-motorola-sysv3
exit ;;
AViiON:dgux:*:*)
# DG/UX returns AViiON for all architectures
UNAME_PROCESSOR=`/usr/bin/uname -p`
# DG/UX returns AViiON for all architectures
UNAME_PROCESSOR=`/usr/bin/uname -p`
if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ]
then
if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \
@ -498,7 +495,7 @@ EOF
else
echo i586-dg-dgux${UNAME_RELEASE}
fi
exit ;;
exit ;;
M88*:DolphinOS:*:*) # DolphinOS (SVR3)
echo m88k-dolphin-sysv3
exit ;;
@ -555,7 +552,7 @@ EOF
echo rs6000-ibm-aix3.2
fi
exit ;;
*:AIX:*:[4567])
*:AIX:*:[456])
IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'`
if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then
IBM_ARCH=rs6000
@ -598,52 +595,52 @@ EOF
9000/[678][0-9][0-9])
if [ -x /usr/bin/getconf ]; then
sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null`
sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null`
case "${sc_cpu_version}" in
523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0
528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1
532) # CPU_PA_RISC2_0
case "${sc_kernel_bits}" in
32) HP_ARCH="hppa2.0n" ;;
64) HP_ARCH="hppa2.0w" ;;
sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null`
case "${sc_cpu_version}" in
523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0
528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1
532) # CPU_PA_RISC2_0
case "${sc_kernel_bits}" in
32) HP_ARCH="hppa2.0n" ;;
64) HP_ARCH="hppa2.0w" ;;
'') HP_ARCH="hppa2.0" ;; # HP-UX 10.20
esac ;;
esac
esac ;;
esac
fi
if [ "${HP_ARCH}" = "" ]; then
eval $set_cc_for_build
sed 's/^ //' << EOF >$dummy.c
sed 's/^ //' << EOF >$dummy.c
#define _HPUX_SOURCE
#include <stdlib.h>
#include <unistd.h>
#define _HPUX_SOURCE
#include <stdlib.h>
#include <unistd.h>
int main ()
{
#if defined(_SC_KERNEL_BITS)
long bits = sysconf(_SC_KERNEL_BITS);
#endif
long cpu = sysconf (_SC_CPU_VERSION);
int main ()
{
#if defined(_SC_KERNEL_BITS)
long bits = sysconf(_SC_KERNEL_BITS);
#endif
long cpu = sysconf (_SC_CPU_VERSION);
switch (cpu)
{
case CPU_PA_RISC1_0: puts ("hppa1.0"); break;
case CPU_PA_RISC1_1: puts ("hppa1.1"); break;
case CPU_PA_RISC2_0:
#if defined(_SC_KERNEL_BITS)
switch (bits)
{
case 64: puts ("hppa2.0w"); break;
case 32: puts ("hppa2.0n"); break;
default: puts ("hppa2.0"); break;
} break;
#else /* !defined(_SC_KERNEL_BITS) */
puts ("hppa2.0"); break;
#endif
default: puts ("hppa1.0"); break;
}
exit (0);
}
switch (cpu)
{
case CPU_PA_RISC1_0: puts ("hppa1.0"); break;
case CPU_PA_RISC1_1: puts ("hppa1.1"); break;
case CPU_PA_RISC2_0:
#if defined(_SC_KERNEL_BITS)
switch (bits)
{
case 64: puts ("hppa2.0w"); break;
case 32: puts ("hppa2.0n"); break;
default: puts ("hppa2.0"); break;
} break;
#else /* !defined(_SC_KERNEL_BITS) */
puts ("hppa2.0"); break;
#endif
default: puts ("hppa1.0"); break;
}
exit (0);
}
EOF
(CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy`
test -z "$HP_ARCH" && HP_ARCH=hppa
@ -734,22 +731,22 @@ EOF
exit ;;
C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*)
echo c1-convex-bsd
exit ;;
exit ;;
C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*)
if getsysinfo -f scalar_acc
then echo c32-convex-bsd
else echo c2-convex-bsd
fi
exit ;;
exit ;;
C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*)
echo c34-convex-bsd
exit ;;
exit ;;
C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*)
echo c38-convex-bsd
exit ;;
exit ;;
C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*)
echo c4-convex-bsd
exit ;;
exit ;;
CRAY*Y-MP:*:*:*)
echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
exit ;;
@ -773,14 +770,14 @@ EOF
exit ;;
F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*)
FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'`
echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
exit ;;
FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'`
echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
exit ;;
5000:UNIX_System_V:4.*:*)
FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'`
echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'`
echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
exit ;;
i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*)
echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE}
@ -792,12 +789,13 @@ EOF
echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE}
exit ;;
*:FreeBSD:*:*)
UNAME_PROCESSOR=`/usr/bin/uname -p`
case ${UNAME_PROCESSOR} in
case ${UNAME_MACHINE} in
pc98)
echo i386-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
amd64)
echo x86_64-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
*)
echo ${UNAME_PROCESSOR}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
esac
exit ;;
i*:CYGWIN*:*)
@ -806,18 +804,15 @@ EOF
*:MINGW*:*)
echo ${UNAME_MACHINE}-pc-mingw32
exit ;;
i*:MSYS*:*)
echo ${UNAME_MACHINE}-pc-msys
exit ;;
i*:windows32*:*)
# uname -m includes "-pc" on this system.
echo ${UNAME_MACHINE}-mingw32
# uname -m includes "-pc" on this system.
echo ${UNAME_MACHINE}-mingw32
exit ;;
i*:PW*:*)
echo ${UNAME_MACHINE}-pc-pw32
exit ;;
*:Interix*:*)
case ${UNAME_MACHINE} in
case ${UNAME_MACHINE} in
x86)
echo i586-pc-interix${UNAME_RELEASE}
exit ;;
@ -872,7 +867,7 @@ EOF
EV6) UNAME_MACHINE=alphaev6 ;;
EV67) UNAME_MACHINE=alphaev67 ;;
EV68*) UNAME_MACHINE=alphaev68 ;;
esac
esac
objdump --private-headers /bin/sh | grep -q ld.so.1
if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi
echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC}
@ -884,29 +879,20 @@ EOF
then
echo ${UNAME_MACHINE}-unknown-linux-gnu
else
if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \
| grep -q __ARM_PCS_VFP
then
echo ${UNAME_MACHINE}-unknown-linux-gnueabi
else
echo ${UNAME_MACHINE}-unknown-linux-gnueabihf
fi
echo ${UNAME_MACHINE}-unknown-linux-gnueabi
fi
exit ;;
avr32*:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-gnu
exit ;;
cris:Linux:*:*)
echo ${UNAME_MACHINE}-axis-linux-gnu
echo cris-axis-linux-gnu
exit ;;
crisv32:Linux:*:*)
echo ${UNAME_MACHINE}-axis-linux-gnu
echo crisv32-axis-linux-gnu
exit ;;
frv:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-gnu
exit ;;
hexagon:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-gnu
echo frv-unknown-linux-gnu
exit ;;
i*86:Linux:*:*)
LIBC=gnu
@ -948,7 +934,7 @@ EOF
test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; }
;;
or32:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-gnu
echo or32-unknown-linux-gnu
exit ;;
padre:Linux:*:*)
echo sparc-unknown-linux-gnu
@ -974,7 +960,7 @@ EOF
echo ${UNAME_MACHINE}-ibm-linux
exit ;;
sh64*:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-gnu
echo ${UNAME_MACHINE}-unknown-linux-gnu
exit ;;
sh*:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-gnu
@ -982,17 +968,14 @@ EOF
sparc:Linux:*:* | sparc64:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-gnu
exit ;;
tile*:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-gnu
exit ;;
vax:Linux:*:*)
echo ${UNAME_MACHINE}-dec-linux-gnu
exit ;;
x86_64:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-gnu
echo x86_64-unknown-linux-gnu
exit ;;
xtensa*:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-gnu
echo ${UNAME_MACHINE}-unknown-linux-gnu
exit ;;
i*86:DYNIX/ptx:4*:*)
# ptx 4.0 does uname -s correctly, with DYNIX/ptx in there.
@ -1001,11 +984,11 @@ EOF
echo i386-sequent-sysv4
exit ;;
i*86:UNIX_SV:4.2MP:2.*)
# Unixware is an offshoot of SVR4, but it has its own version
# number series starting with 2...
# I am not positive that other SVR4 systems won't match this,
# Unixware is an offshoot of SVR4, but it has its own version
# number series starting with 2...
# I am not positive that other SVR4 systems won't match this,
# I just have to hope. -- rms.
# Use sysv4.2uw... so that sysv4* matches it.
# Use sysv4.2uw... so that sysv4* matches it.
echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION}
exit ;;
i*86:OS/2:*:*)
@ -1037,7 +1020,7 @@ EOF
fi
exit ;;
i*86:*:5:[678]*)
# UnixWare 7.x, OpenUNIX and OpenServer 6.
# UnixWare 7.x, OpenUNIX and OpenServer 6.
case `/bin/uname -X | grep "^Machine"` in
*486*) UNAME_MACHINE=i486 ;;
*Pentium) UNAME_MACHINE=i586 ;;
@ -1065,13 +1048,13 @@ EOF
exit ;;
pc:*:*:*)
# Left here for compatibility:
# uname -m prints for DJGPP always 'pc', but it prints nothing about
# the processor, so we play safe by assuming i586.
# uname -m prints for DJGPP always 'pc', but it prints nothing about
# the processor, so we play safe by assuming i586.
# Note: whatever this is, it MUST be the same as what config.sub
# prints for the "djgpp" host, or else GDB configury will decide that
# this is a cross-build.
echo i586-pc-msdosdjgpp
exit ;;
exit ;;
Intel:Mach:3*:*)
echo i386-pc-mach3
exit ;;
@ -1106,8 +1089,8 @@ EOF
/bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \
&& { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;;
3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*)
/bin/uname -p 2>/dev/null | grep 86 >/dev/null \
&& { echo i486-ncr-sysv4; exit; } ;;
/bin/uname -p 2>/dev/null | grep 86 >/dev/null \
&& { echo i486-ncr-sysv4; exit; } ;;
NCR*:*:4.2:* | MPRAS*:*:4.2:*)
OS_REL='.3'
test -r /etc/.relid \
@ -1150,10 +1133,10 @@ EOF
echo ns32k-sni-sysv
fi
exit ;;
PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort
# says <Richard.M.Bartel@ccMail.Census.GOV>
echo i586-unisys-sysv4
exit ;;
PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort
# says <Richard.M.Bartel@ccMail.Census.GOV>
echo i586-unisys-sysv4
exit ;;
*:UNIX_System_V:4*:FTX*)
# From Gerald Hewes <hewes@openmarket.com>.
# How about differentiating between stratus architectures? -djm
@ -1179,11 +1162,11 @@ EOF
exit ;;
R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*)
if [ -d /usr/nec ]; then
echo mips-nec-sysv${UNAME_RELEASE}
echo mips-nec-sysv${UNAME_RELEASE}
else
echo mips-unknown-sysv${UNAME_RELEASE}
echo mips-unknown-sysv${UNAME_RELEASE}
fi
exit ;;
exit ;;
BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only.
echo powerpc-be-beos
exit ;;
@ -1248,9 +1231,6 @@ EOF
*:QNX:*:4*)
echo i386-pc-qnx
exit ;;
NEO-?:NONSTOP_KERNEL:*:*)
echo neo-tandem-nsk${UNAME_RELEASE}
exit ;;
NSE-?:NONSTOP_KERNEL:*:*)
echo nse-tandem-nsk${UNAME_RELEASE}
exit ;;
@ -1296,13 +1276,13 @@ EOF
echo pdp10-unknown-its
exit ;;
SEI:*:*:SEIUX)
echo mips-sei-seiux${UNAME_RELEASE}
echo mips-sei-seiux${UNAME_RELEASE}
exit ;;
*:DragonFly:*:*)
echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`
exit ;;
*:*VMS:*:*)
UNAME_MACHINE=`(uname -p) 2>/dev/null`
UNAME_MACHINE=`(uname -p) 2>/dev/null`
case "${UNAME_MACHINE}" in
A*) echo alpha-dec-vms ; exit ;;
I*) echo ia64-dec-vms ; exit ;;
@ -1342,11 +1322,11 @@ main ()
#include <sys/param.h>
printf ("m68k-sony-newsos%s\n",
#ifdef NEWSOS4
"4"
"4"
#else
""
""
#endif
); exit (0);
); exit (0);
#endif
#endif

190
admin/config.sub vendored
View file

@ -1,10 +1,10 @@
#! /bin/sh
# Configuration validation subroutine script.
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
# 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
# 2011, 2012 Free Software Foundation, Inc.
# 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
# Free Software Foundation, Inc.
timestamp='2012-01-01'
timestamp='2009-12-31'
# This file is (in principle) common to ALL GNU software.
# The presence of a machine in this file suggests that SOME GNU software
@ -76,8 +76,8 @@ version="\
GNU config.sub ($timestamp)
Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
Free Software Foundation, Inc.
2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free
Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
@ -124,9 +124,8 @@ esac
# Here we must recognize all the valid KERNEL-OS combinations.
maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'`
case $maybe_os in
nto-qnx* | linux-gnu* | linux-android* | linux-dietlibc | linux-newlib* | \
linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | \
knetbsd*-gnu* | netbsd*-gnu* | \
nto-qnx* | linux-gnu* | linux-dietlibc | linux-newlib* | linux-uclibc* | \
uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* | \
kopensolaris*-gnu* | \
storm-chaos* | os2-emx* | rtmk-nova*)
os=-$maybe_os
@ -158,8 +157,8 @@ case $os in
os=
basic_machine=$1
;;
-bluegene*)
os=-cnk
-bluegene*)
os=-cnk
;;
-sim | -cisco | -oki | -wec | -winbond)
os=
@ -175,10 +174,10 @@ case $os in
os=-chorusos
basic_machine=$1
;;
-chorusrdb)
os=-chorusrdb
-chorusrdb)
os=-chorusrdb
basic_machine=$1
;;
;;
-hiux*)
os=-hiuxwe2
;;
@ -251,17 +250,13 @@ case $basic_machine in
| alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \
| am33_2.0 \
| arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr | avr32 \
| be32 | be64 \
| bfin \
| c4x | clipper \
| d10v | d30v | dlx | dsp16xx \
| epiphany \
| fido | fr30 | frv \
| h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \
| hexagon \
| i370 | i860 | i960 | ia64 \
| ip2k | iq2000 \
| le32 | le64 \
| lm32 \
| m32c | m32r | m32rle | m68000 | m68k | m88k \
| maxq | mb | microblaze | mcore | mep | metag \
@ -287,39 +282,29 @@ case $basic_machine in
| moxie \
| mt \
| msp430 \
| nds32 | nds32le | nds32be \
| nios | nios2 \
| ns16k | ns32k \
| open8 \
| or32 \
| pdp10 | pdp11 | pj | pjl \
| powerpc | powerpc64 | powerpc64le | powerpcle \
| powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \
| pyramid \
| rl78 | rx \
| rx \
| score \
| sh | sh[1234] | sh[24]a | sh[24]aeb | sh[23]e | sh[34]eb | sheb | shbe | shle | sh[1234]le | sh3ele \
| sh64 | sh64le \
| sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \
| sparcv8 | sparcv9 | sparcv9b | sparcv9v \
| spu \
| tahoe | tic4x | tic54x | tic55x | tic6x | tic80 | tron \
| spu | strongarm \
| tahoe | thumb | tic4x | tic80 | tron \
| ubicom32 \
| v850 | v850e | v850e1 | v850e2 | v850es | v850e2v3 \
| v850 | v850e \
| we32k \
| x86 | xc16x | xstormy16 | xtensa \
| x86 | xc16x | xscale | xscalee[bl] | xstormy16 | xtensa \
| z8k | z80)
basic_machine=$basic_machine-unknown
;;
c54x)
basic_machine=tic54x-unknown
;;
c55x)
basic_machine=tic55x-unknown
;;
c6x)
basic_machine=tic6x-unknown
;;
m6811 | m68hc11 | m6812 | m68hc12 | picochip)
# Motorola 68HC11/12.
basic_machine=$basic_machine-unknown
os=-none
;;
@ -329,18 +314,6 @@ case $basic_machine in
basic_machine=mt-unknown
;;
strongarm | thumb | xscale)
basic_machine=arm-unknown
;;
xscaleeb)
basic_machine=armeb-unknown
;;
xscaleel)
basic_machine=armel-unknown
;;
# We use `pc' rather than `unknown'
# because (1) that's what they normally are, and
# (2) the word "unknown" tends to confuse beginning users.
@ -360,19 +333,16 @@ case $basic_machine in
| alphapca5[67]-* | alpha64pca5[67]-* | arc-* \
| arm-* | armbe-* | armle-* | armeb-* | armv*-* \
| avr-* | avr32-* \
| be32-* | be64-* \
| bfin-* | bs2000-* \
| c[123]* | c30-* | [cjt]90-* | c4x-* \
| c[123]* | c30-* | [cjt]90-* | c4x-* | c54x-* | c55x-* | c6x-* \
| clipper-* | craynv-* | cydra-* \
| d10v-* | d30v-* | dlx-* \
| elxsi-* \
| f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \
| h8300-* | h8500-* \
| hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \
| hexagon-* \
| i*86-* | i860-* | i960-* | ia64-* \
| ip2k-* | iq2000-* \
| le32-* | le64-* \
| lm32-* \
| m32c-* | m32r-* | m32rle-* \
| m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \
@ -398,29 +368,25 @@ case $basic_machine in
| mmix-* \
| mt-* \
| msp430-* \
| nds32-* | nds32le-* | nds32be-* \
| nios-* | nios2-* \
| none-* | np1-* | ns16k-* | ns32k-* \
| open8-* \
| orion-* \
| pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \
| powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* \
| powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \
| pyramid-* \
| rl78-* | romp-* | rs6000-* | rx-* \
| romp-* | rs6000-* | rx-* \
| sh-* | sh[1234]-* | sh[24]a-* | sh[24]aeb-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \
| shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \
| sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \
| sparclite-* \
| sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | sv1-* | sx?-* \
| tahoe-* \
| tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \
| tile*-* \
| sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | strongarm-* | sv1-* | sx?-* \
| tahoe-* | thumb-* \
| tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* | tile-* \
| tron-* \
| ubicom32-* \
| v850-* | v850e-* | v850e1-* | v850es-* | v850e2-* | v850e2v3-* \
| vax-* \
| v850-* | v850e-* | vax-* \
| we32k-* \
| x86-* | x86_64-* | xc16x-* | xps100-* \
| x86-* | x86_64-* | xc16x-* | xps100-* | xscale-* | xscalee[bl]-* \
| xstormy16-* | xtensa*-* \
| ymp-* \
| z8k-* | z80-*)
@ -445,7 +411,7 @@ case $basic_machine in
basic_machine=a29k-amd
os=-udi
;;
abacus)
abacus)
basic_machine=abacus-unknown
;;
adobe68k)
@ -515,20 +481,11 @@ case $basic_machine in
basic_machine=powerpc-ibm
os=-cnk
;;
c54x-*)
basic_machine=tic54x-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
c55x-*)
basic_machine=tic55x-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
c6x-*)
basic_machine=tic6x-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
c90)
basic_machine=c90-cray
os=-unicos
;;
cegcc)
cegcc)
basic_machine=arm-unknown
os=-cegcc
;;
@ -560,7 +517,7 @@ case $basic_machine in
basic_machine=craynv-cray
os=-unicosmp
;;
cr16 | cr16-*)
cr16)
basic_machine=cr16-unknown
os=-elf
;;
@ -718,6 +675,7 @@ case $basic_machine in
i370-ibm* | ibm*)
basic_machine=i370-ibm
;;
# I'm not sure what "Sysv32" means. Should this be sysv3.2?
i*86v32)
basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
os=-sysv32
@ -775,7 +733,7 @@ case $basic_machine in
basic_machine=ns32k-utek
os=-sysv
;;
microblaze)
microblaze)
basic_machine=microblaze-xilinx
;;
mingw32)
@ -814,18 +772,10 @@ case $basic_machine in
ms1-*)
basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'`
;;
msys)
basic_machine=i386-pc
os=-msys
;;
mvs)
basic_machine=i370-ibm
os=-mvs
;;
nacl)
basic_machine=le32-unknown
os=-nacl
;;
ncr3000)
basic_machine=i486-ncr
os=-sysv4
@ -890,12 +840,6 @@ case $basic_machine in
np1)
basic_machine=np1-gould
;;
neo-tandem)
basic_machine=neo-tandem
;;
nse-tandem)
basic_machine=nse-tandem
;;
nsr-tandem)
basic_machine=nsr-tandem
;;
@ -978,10 +922,9 @@ case $basic_machine in
;;
power) basic_machine=power-ibm
;;
ppc | ppcbe) basic_machine=powerpc-unknown
ppc) basic_machine=powerpc-unknown
;;
ppc-* | ppcbe-*)
basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'`
ppc-*) basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
ppcle | powerpclittle | ppc-le | powerpc-little)
basic_machine=powerpcle-unknown
@ -1075,9 +1018,6 @@ case $basic_machine in
basic_machine=i860-stratus
os=-sysv4
;;
strongarm-* | thumb-*)
basic_machine=arm-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
sun2)
basic_machine=m68000-sun
;;
@ -1134,8 +1074,20 @@ case $basic_machine in
basic_machine=t90-cray
os=-unicos
;;
tic54x | c54x*)
basic_machine=tic54x-unknown
os=-coff
;;
tic55x | c55x*)
basic_machine=tic55x-unknown
os=-coff
;;
tic6x | c6x*)
basic_machine=tic6x-unknown
os=-coff
;;
tile*)
basic_machine=$basic_machine-unknown
basic_machine=tile-unknown
os=-linux-gnu
;;
tx39)
@ -1205,9 +1157,6 @@ case $basic_machine in
xps | xps100)
basic_machine=xps100-honeywell
;;
xscale-* | xscalee[bl]-*)
basic_machine=`echo $basic_machine | sed 's/^xscale/arm/'`
;;
ymp)
basic_machine=ymp-cray
os=-unicos
@ -1305,11 +1254,11 @@ esac
if [ x"$os" != x"" ]
then
case $os in
# First match some system type aliases
# that might get confused with valid system types.
# First match some system type aliases
# that might get confused with valid system types.
# -solaris* is a basic system type, with this one exception.
-auroraux)
os=-auroraux
-auroraux)
os=-auroraux
;;
-solaris1 | -solaris1.*)
os=`echo $os | sed -e 's|solaris1|sunos4|'`
@ -1345,9 +1294,8 @@ case $os in
| -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \
| -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
| -chorusos* | -chorusrdb* | -cegcc* \
| -cygwin* | -msys* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
| -mingw32* | -linux-gnu* | -linux-android* \
| -linux-newlib* | -linux-uclibc* \
| -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
| -mingw32* | -linux-gnu* | -linux-newlib* | -linux-uclibc* \
| -uxpv* | -beos* | -mpeix* | -udk* \
| -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \
| -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \
@ -1394,7 +1342,7 @@ case $os in
-opened*)
os=-openedition
;;
-os400*)
-os400*)
os=-os400
;;
-wince*)
@ -1443,7 +1391,7 @@ case $os in
-sinix*)
os=-sysv4
;;
-tpf*)
-tpf*)
os=-tpf
;;
-triton*)
@ -1488,8 +1436,8 @@ case $os in
-dicos*)
os=-dicos
;;
-nacl*)
;;
-nacl*)
;;
-none)
;;
*)
@ -1512,10 +1460,10 @@ else
# system, and we'll never get to this point.
case $basic_machine in
score-*)
score-*)
os=-elf
;;
spu-*)
spu-*)
os=-elf
;;
*-acorn)
@ -1527,17 +1475,8 @@ case $basic_machine in
arm*-semi)
os=-aout
;;
c4x-* | tic4x-*)
os=-coff
;;
tic54x-*)
os=-coff
;;
tic55x-*)
os=-coff
;;
tic6x-*)
os=-coff
c4x-* | tic4x-*)
os=-coff
;;
# This must come before the *-dec entry.
pdp10-*)
@ -1557,11 +1496,14 @@ case $basic_machine in
;;
m68000-sun)
os=-sunos3
# This also exists in the configure program, but was not the
# default.
# os=-sunos4
;;
m68*-cisco)
os=-aout
;;
mep-*)
mep-*)
os=-elf
;;
mips*-cisco)
@ -1588,7 +1530,7 @@ case $basic_machine in
*-ibm)
os=-aix
;;
*-knuth)
*-knuth)
os=-mmixware
;;
*-wec)

View file

@ -1,10 +1,9 @@
#! /bin/sh
# depcomp - compile a program generating dependencies as side-effects
scriptversion=2011-12-04.11; # UTC
scriptversion=2012-03-27.16; # UTC
# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2009, 2010,
# 2011 Free Software Foundation, Inc.
# Copyright (C) 1999-2012 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -28,7 +27,7 @@ scriptversion=2011-12-04.11; # UTC
case $1 in
'')
echo "$0: No command. Try \`$0 --help' for more information." 1>&2
echo "$0: No command. Try '$0 --help' for more information." 1>&2
exit 1;
;;
-h | --h*)
@ -40,8 +39,8 @@ as side-effects.
Environment variables:
depmode Dependency tracking mode.
source Source file read by `PROGRAMS ARGS'.
object Object file output by `PROGRAMS ARGS'.
source Source file read by 'PROGRAMS ARGS'.
object Object file output by 'PROGRAMS ARGS'.
DEPDIR directory where to store dependencies.
depfile Dependency file to output.
tmpdepfile Temporary file to use when outputting dependencies.
@ -57,6 +56,12 @@ EOF
;;
esac
# A tabulation character.
tab=' '
# A newline character.
nl='
'
if test -z "$depmode" || test -z "$source" || test -z "$object"; then
echo "depcomp: Variables source, object and depmode must be set" 1>&2
exit 1
@ -102,6 +107,12 @@ if test "$depmode" = msvc7msys; then
depmode=msvc7
fi
if test "$depmode" = xlc; then
# IBM C/C++ Compilers xlc/xlC can output gcc-like dependency informations.
gccflag=-qmakedep=gcc,-MF
depmode=gcc
fi
case "$depmode" in
gcc3)
## gcc 3 implements dependency tracking that does exactly what
@ -156,15 +167,14 @@ gcc)
## The second -e expression handles DOS-style file names with drive letters.
sed -e 's/^[^:]*: / /' \
-e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
## This next piece of magic avoids the `deleted header file' problem.
## This next piece of magic avoids the "deleted header file" problem.
## The problem is that when a header file which appears in a .P file
## is deleted, the dependency causes make to die (because there is
## typically no way to rebuild the header). We avoid this by adding
## dummy dependencies for each header file. Too bad gcc doesn't do
## this for us directly.
tr ' ' '
' < "$tmpdepfile" |
## Some versions of gcc put a space before the `:'. On the theory
tr ' ' "$nl" < "$tmpdepfile" |
## Some versions of gcc put a space before the ':'. On the theory
## that the space means something, we add a space to the output as
## well. hp depmode also adds that space, but also prefixes the VPATH
## to the object. Take care to not repeat it in the output.
@ -203,18 +213,15 @@ sgi)
# clever and replace this with sed code, as IRIX sed won't handle
# lines with more than a fixed number of characters (4096 in
# IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines;
# the IRIX cc adds comments like `#:fec' to the end of the
# the IRIX cc adds comments like '#:fec' to the end of the
# dependency line.
tr ' ' '
' < "$tmpdepfile" \
tr ' ' "$nl" < "$tmpdepfile" \
| sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
tr '
' ' ' >> "$depfile"
tr "$nl" ' ' >> "$depfile"
echo >> "$depfile"
# The second pass generates a dummy entry for each header file.
tr ' ' '
' < "$tmpdepfile" \
tr ' ' "$nl" < "$tmpdepfile" \
| sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
>> "$depfile"
else
@ -226,10 +233,17 @@ sgi)
rm -f "$tmpdepfile"
;;
xlc)
# This case exists only to let depend.m4 do its work. It works by
# looking at the text of this script. This case will never be run,
# since it is checked for above.
exit 1
;;
aix)
# The C for AIX Compiler uses -M and outputs the dependencies
# in a .u file. In older versions, this file always lives in the
# current directory. Also, the AIX compiler puts `$object:' at the
# current directory. Also, the AIX compiler puts '$object:' at the
# start of each line; $object doesn't have directory information.
# Version 6 uses the directory in both cases.
dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
@ -259,12 +273,11 @@ aix)
test -f "$tmpdepfile" && break
done
if test -f "$tmpdepfile"; then
# Each line is of the form `foo.o: dependent.h'.
# Each line is of the form 'foo.o: dependent.h'.
# Do two passes, one to just change these to
# `$object: dependent.h' and one to simply `dependent.h:'.
# '$object: dependent.h' and one to simply 'dependent.h:'.
sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
# That's a tab and a space in the [].
sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
sed -e 's,^.*\.[a-z]*:['"$tab"' ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
else
# The sourcefile does not contain any dependencies, so just
# store a dummy comment line, to avoid errors with the Makefile
@ -275,23 +288,26 @@ aix)
;;
icc)
# Intel's C compiler understands `-MD -MF file'. However on
# icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c
# Intel's C compiler anf tcc (Tiny C Compiler) understand '-MD -MF file'.
# However on
# $CC -MD -MF foo.d -c -o sub/foo.o sub/foo.c
# ICC 7.0 will fill foo.d with something like
# foo.o: sub/foo.c
# foo.o: sub/foo.h
# which is wrong. We want:
# which is wrong. We want
# sub/foo.o: sub/foo.c
# sub/foo.o: sub/foo.h
# sub/foo.c:
# sub/foo.h:
# ICC 7.1 will output
# foo.o: sub/foo.c sub/foo.h
# and will wrap long lines using \ :
# and will wrap long lines using '\':
# foo.o: sub/foo.c ... \
# sub/foo.h ... \
# ...
# tcc 0.9.26 (FIXME still under development at the moment of writing)
# will emit a similar output, but also prepend the continuation lines
# with horizontal tabulation characters.
"$@" -MD -MF "$tmpdepfile"
stat=$?
if test $stat -eq 0; then :
@ -300,15 +316,21 @@ icc)
exit $stat
fi
rm -f "$depfile"
# Each line is of the form `foo.o: dependent.h',
# or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
# Each line is of the form 'foo.o: dependent.h',
# or 'foo.o: dep1.h dep2.h \', or ' dep3.h dep4.h \'.
# Do two passes, one to just change these to
# `$object: dependent.h' and one to simply `dependent.h:'.
sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
# Some versions of the HPUX 10.20 sed can't process this invocation
# correctly. Breaking it into two sed invocations is a workaround.
sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
sed -e 's/$/ :/' >> "$depfile"
# '$object: dependent.h' and one to simply 'dependent.h:'.
sed -e "s/^[ $tab][ $tab]*/ /" -e "s,^[^:]*:,$object :," \
< "$tmpdepfile" > "$depfile"
sed '
s/[ '"$tab"'][ '"$tab"']*/ /g
s/^ *//
s/ *\\*$//
s/^[^:]*: *//
/^$/d
/:$/d
s/$/ :/
' < "$tmpdepfile" >> "$depfile"
rm -f "$tmpdepfile"
;;
@ -344,7 +366,7 @@ hp2)
done
if test -f "$tmpdepfile"; then
sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile"
# Add `dependent.h:' lines.
# Add 'dependent.h:' lines.
sed -ne '2,${
s/^ *//
s/ \\*$//
@ -359,9 +381,9 @@ hp2)
tru64)
# The Tru64 compiler uses -MD to generate dependencies as a side
# effect. `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
# effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
# At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
# dependencies in `foo.d' instead, so we check for that too.
# dependencies in 'foo.d' instead, so we check for that too.
# Subdirectories are respected.
dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
test "x$dir" = "x$object" && dir=
@ -407,8 +429,7 @@ tru64)
done
if test -f "$tmpdepfile"; then
sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
# That's a tab and a space in the [].
sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
sed -e 's,^.*\.[a-z]*:['"$tab"' ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
else
echo "#dummy" > "$depfile"
fi
@ -443,11 +464,11 @@ msvc7)
p
}' | $cygpath_u | sort -u | sed -n '
s/ /\\ /g
s/\(.*\)/ \1 \\/p
s/\(.*\)/'"$tab"'\1 \\/p
s/.\(.*\) \\/\1:/
H
$ {
s/.*/ /
s/.*/'"$tab"'/
G
p
}' >> "$depfile"
@ -478,7 +499,7 @@ dashmstdout)
shift
fi
# Remove `-o $object'.
# Remove '-o $object'.
IFS=" "
for arg
do
@ -498,15 +519,14 @@ dashmstdout)
done
test -z "$dashmflag" && dashmflag=-M
# Require at least two characters before searching for `:'
# Require at least two characters before searching for ':'
# in the target name. This is to cope with DOS-style filenames:
# a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.
# a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
"$@" $dashmflag |
sed 's:^[ ]*[^: ][^:][^:]*\:[ ]*:'"$object"'\: :' > "$tmpdepfile"
sed 's:^['"$tab"' ]*[^:'"$tab"' ][^:][^:]*\:['"$tab"' ]*:'"$object"'\: :' > "$tmpdepfile"
rm -f "$depfile"
cat < "$tmpdepfile" > "$depfile"
tr ' ' '
' < "$tmpdepfile" | \
tr ' ' "$nl" < "$tmpdepfile" | \
## Some versions of the HPUX 10.20 sed can't process this invocation
## correctly. Breaking it into two sed invocations is a workaround.
sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
@ -562,8 +582,7 @@ makedepend)
# makedepend may prepend the VPATH from the source file name to the object.
# No need to regex-escape $object, excess matching of '.' is harmless.
sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
sed '1,2d' "$tmpdepfile" | tr ' ' '
' | \
sed '1,2d' "$tmpdepfile" | tr ' ' "$nl" | \
## Some versions of the HPUX 10.20 sed can't process this invocation
## correctly. Breaking it into two sed invocations is a workaround.
sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
@ -583,7 +602,7 @@ cpp)
shift
fi
# Remove `-o $object'.
# Remove '-o $object'.
IFS=" "
for arg
do
@ -652,8 +671,8 @@ msvisualcpp)
sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
rm -f "$depfile"
echo "$object : \\" > "$depfile"
sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s:: \1 \\:p' >> "$depfile"
echo " " >> "$depfile"
sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
echo "$tab" >> "$depfile"
sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
rm -f "$tmpdepfile"
;;

View file

@ -1,38 +1,23 @@
#!/bin/sh
#
# $NetBSD: install-sh.in,v 1.6 2012/01/11 13:07:31 hans Exp $
# This script now also installs multiple files, but might choke on installing
# multiple files with spaces in the file names.
#
# install - install a program, script, or datafile
scriptversion=2011-01-19.21; # UTC
# This originates from X11R5 (mit/util/scripts/install.sh), which was
# later released in X11R6 (xc/config/util/install.sh) with the
# following copyright and license.
# This comes from X11R5 (mit/util/scripts/install.sh).
#
# Copyright (C) 1994 X Consortium
# Copyright 1991 by the Massachusetts Institute of Technology
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
# Except as contained in this notice, the name of the X Consortium shall not
# be used in advertising or otherwise to promote the sale, use or other deal-
# ings in this Software without prior written authorization from the X Consor-
# tium.
#
#
# FSF changes to this file are in the public domain.
# Permission to use, copy, modify, distribute, and sell this software and its
# documentation for any purpose is hereby granted without fee, provided that
# the above copyright notice appear in all copies and that both that
# copyright notice and this permission notice appear in supporting
# documentation, and that the name of M.I.T. not be used in advertising or
# publicity pertaining to distribution of the software without specific,
# written prior permission. M.I.T. makes no representations about the
# suitability of this software for any purpose. It is provided "as is"
# without express or implied warranty.
#
# Calling this script install-sh is preferred over install.sh, to prevent
# `make' implicit rules from creating a file called install from it
@ -41,487 +26,276 @@ scriptversion=2011-01-19.21; # UTC
# This script is compatible with the BSD install script, but was written
# from scratch.
nl='
'
IFS=" "" $nl"
# set DOITPROG to echo to test this script
# Don't use :- since 4.3BSD and earlier shells don't like it.
doit=${DOITPROG-}
if test -z "$doit"; then
doit_exec=exec
else
doit_exec=$doit
fi
doit="${DOITPROG-}"
# Put in absolute file names if you don't have them in your path;
# or use environment vars.
chgrpprog=${CHGRPPROG-chgrp}
chmodprog=${CHMODPROG-chmod}
chownprog=${CHOWNPROG-chown}
cmpprog=${CMPPROG-cmp}
cpprog=${CPPROG-cp}
mkdirprog=${MKDIRPROG-mkdir}
mvprog=${MVPROG-mv}
rmprog=${RMPROG-rm}
stripprog=${STRIPPROG-strip}
# put in absolute paths if you don't have them in your path; or use env. vars.
posix_glob='?'
initialize_posix_glob='
test "$posix_glob" != "?" || {
if (set -f) 2>/dev/null; then
posix_glob=
else
posix_glob=:
fi
}
'
awkprog="${AWKPROG-awk}"
mvprog="${MVPROG-mv}"
cpprog="${CPPROG-cp}"
chmodprog="${CHMODPROG-chmod}"
chownprog="${CHOWNPROG-chown}"
chgrpprog="${CHGRPPROG-chgrp}"
stripprog="${STRIPPROG-strip}"
rmprog="${RMPROG-rm}"
mkdirprog="${MKDIRPROG-mkdir}"
posix_mkdir=
# Desired mode of installed file.
mode=0755
chgrpcmd=
chmodcmd=$chmodprog
chowncmd=
mvcmd=$mvprog
instcmd="$cpprog"
instflags=""
pathcompchmodcmd="$chmodprog 755"
chmodcmd="$chmodprog 755"
chowncmd=""
chgrpcmd=""
stripcmd=""
stripflags=""
rmcmd="$rmprog -f"
stripcmd=
mvcmd="$mvprog"
src=""
msrc=""
dst=""
dir_arg=""
suffix=""
suffixfmt=""
src=
dst=
dir_arg=
dst_arg=
while [ x"$1" != x ]; do
case $1 in
-b) suffix=".old"
shift
continue;;
copy_on_change=false
no_target_directory=
-B) suffixfmt="$2"
shift
shift
continue;;
usage="\
Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
or: $0 [OPTION]... SRCFILES... DIRECTORY
or: $0 [OPTION]... -t DIRECTORY SRCFILES...
or: $0 [OPTION]... -d DIRECTORIES...
-c) instcmd="$cpprog"
shift
continue;;
In the 1st form, copy SRCFILE to DSTFILE.
In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
In the 4th, create DIRECTORIES.
-d) dir_arg=true
shift
continue;;
Options:
--help display this help and exit.
--version display version info and exit.
-m) chmodcmd="$chmodprog $2"
shift
shift
continue;;
-c (ignored)
-C install only if different (preserve the last data modification time)
-d create directories instead of installing files.
-g GROUP $chgrpprog installed files to GROUP.
-m MODE $chmodprog installed files to MODE.
-o USER $chownprog installed files to USER.
-s $stripprog installed files.
-t DIRECTORY install into DIRECTORY.
-T report an error if DSTFILE is a directory.
-m*)
chmodcmd="$chmodprog ${1#-m}"
shift
continue;;
Environment variables override the default commands:
CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG
RMPROG STRIPPROG
"
-o) chowncmd="$chownprog $2"
shift
shift
continue;;
while test $# -ne 0; do
case $1 in
-c) ;;
-g) chgrpcmd="$chgrpprog $2"
shift
shift
continue;;
-C) copy_on_change=true;;
-s) stripcmd="$stripprog"
shift
continue;;
-d) dir_arg=true;;
-S) stripcmd="$stripprog"
stripflags="-S $2 $stripflags"
shift
shift
continue;;
-g) chgrpcmd="$chgrpprog $2"
shift;;
-p) instflags="-p"
shift
continue;;
--help) echo "$usage"; exit $?;;
-m) mode=$2
case $mode in
*' '* | *' '* | *'
'* | *'*'* | *'?'* | *'['*)
echo "$0: invalid mode: $mode" >&2
exit 1;;
esac
shift;;
-o) chowncmd="$chownprog $2"
shift;;
-s) stripcmd=$stripprog;;
-t) dst_arg=$2
# Protect names problematic for `test' and other utilities.
case $dst_arg in
-* | [=\(\)!]) dst_arg=./$dst_arg;;
esac
shift;;
-T) no_target_directory=true;;
--version) echo "$0 $scriptversion"; exit $?;;
--) shift
break;;
-*) echo "$0: invalid option: $1" >&2
exit 1;;
*) break;;
esac
shift
done
if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then
# When -d is used, all remaining arguments are directories to create.
# When -t is used, the destination is already specified.
# Otherwise, the last argument is the destination. Remove it from $@.
for arg
do
if test -n "$dst_arg"; then
# $@ is not empty: it contains at least $arg.
set fnord "$@" "$dst_arg"
shift # fnord
fi
shift # arg
dst_arg=$arg
# Protect names problematic for `test' and other utilities.
case $dst_arg in
-* | [=\(\)!]) dst_arg=./$dst_arg;;
esac
done
fi
if test $# -eq 0; then
if test -z "$dir_arg"; then
echo "$0: no input file specified." >&2
exit 1
fi
# It's OK to call `install-sh -d' without argument.
# This can happen when creating conditional directories.
exit 0
fi
if test -z "$dir_arg"; then
do_exit='(exit $ret); exit $ret'
trap "ret=129; $do_exit" 1
trap "ret=130; $do_exit" 2
trap "ret=141; $do_exit" 13
trap "ret=143; $do_exit" 15
# Set umask so as not to create temps with too-generous modes.
# However, 'strip' requires both read and write access to temps.
case $mode in
# Optimize common cases.
*644) cp_umask=133;;
*755) cp_umask=22;;
*[0-7])
if test -z "$stripcmd"; then
u_plus_rw=
else
u_plus_rw='% 200'
fi
cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;;
*)
if test -z "$stripcmd"; then
u_plus_rw=
else
u_plus_rw=,u+rw
fi
cp_umask=$mode$u_plus_rw;;
esac
fi
for src
do
# Protect names problematic for `test' and other utilities.
case $src in
-* | [=\(\)!]) src=./$src;;
esac
if test -n "$dir_arg"; then
dst=$src
dstdir=$dst
test -d "$dstdir"
dstdir_status=$?
else
# Waiting for this to be detected by the "$cpprog $src $dsttmp" command
# might cause directories to be created, which would be especially bad
# if $src (and thus $dsttmp) contains '*'.
if test ! -f "$src" && test ! -d "$src"; then
echo "$0: $src does not exist." >&2
exit 1
fi
if test -z "$dst_arg"; then
echo "$0: no destination specified." >&2
exit 1
fi
dst=$dst_arg
# If destination is a directory, append the input filename; won't work
# if double slashes aren't ignored.
if test -d "$dst"; then
if test -n "$no_target_directory"; then
echo "$0: $dst_arg: Is a directory" >&2
exit 1
fi
dstdir=$dst
dst=$dstdir/`basename "$src"`
dstdir_status=0
else
# Prefer dirname, but fall back on a substitute if dirname fails.
dstdir=`
(dirname "$dst") 2>/dev/null ||
expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
X"$dst" : 'X\(//\)[^/]' \| \
X"$dst" : 'X\(//\)$' \| \
X"$dst" : 'X\(/\)' \| . 2>/dev/null ||
echo X"$dst" |
sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
s//\1/
q
}
/^X\(\/\/\)[^/].*/{
s//\1/
q
}
/^X\(\/\/\)$/{
s//\1/
q
}
/^X\(\/\).*/{
s//\1/
q
}
s/.*/./; q'
`
test -d "$dstdir"
dstdir_status=$?
fi
fi
obsolete_mkdir_used=false
if test $dstdir_status != 0; then
case $posix_mkdir in
'')
# Create intermediate dirs using mode 755 as modified by the umask.
# This is like FreeBSD 'install' as of 1997-10-28.
umask=`umask`
case $stripcmd.$umask in
# Optimize common cases.
*[2367][2367]) mkdir_umask=$umask;;
.*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;;
*[0-7])
mkdir_umask=`expr $umask + 22 \
- $umask % 100 % 40 + $umask % 20 \
- $umask % 10 % 4 + $umask % 2
`;;
*) mkdir_umask=$umask,go-w;;
esac
# With -d, create the new directory with the user-specified mode.
# Otherwise, rely on $mkdir_umask.
if test -n "$dir_arg"; then
mkdir_mode=-m$mode
else
mkdir_mode=
fi
posix_mkdir=false
case $umask in
*[123567][0-7][0-7])
# POSIX mkdir -p sets u+wx bits regardless of umask, which
# is incompatible with FreeBSD 'install' when (umask & 300) != 0.
;;
*)
tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0
if (umask $mkdir_umask &&
exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1
*) if [ x"$msrc" = x ]
then
if test -z "$dir_arg" || {
# Check for POSIX incompatibilities with -m.
# HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
# other-writeable bit of parent directory when it shouldn't.
# FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
ls_ld_tmpdir=`ls -ld "$tmpdir"`
case $ls_ld_tmpdir in
d????-?r-*) different_mode=700;;
d????-?--*) different_mode=755;;
*) false;;
esac &&
$mkdirprog -m$different_mode -p -- "$tmpdir" && {
ls_ld_tmpdir_1=`ls -ld "$tmpdir"`
test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
}
}
then posix_mkdir=:
fi
rmdir "$tmpdir/d" "$tmpdir"
msrc="$dst"
else
# Remove any dirs left behind by ancient mkdir implementations.
rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null
msrc="$msrc $dst"
fi
trap '' 0;;
esac;;
src="$dst"
dst="$1"
shift
continue;;
esac
if
$posix_mkdir && (
umask $mkdir_umask &&
$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
)
then :
else
# The umask is ridiculous, or mkdir does not conform to POSIX,
# or it failed possibly due to a race condition. Create the
# directory the slow way, step by step, checking for races as we go.
case $dstdir in
/*) prefix='/';;
[-=\(\)!]*) prefix='./';;
*) prefix='';;
esac
eval "$initialize_posix_glob"
oIFS=$IFS
IFS=/
$posix_glob set -f
set fnord $dstdir
shift
$posix_glob set +f
IFS=$oIFS
prefixes=
for d
do
test X"$d" = X && continue
prefix=$prefix$d
if test -d "$prefix"; then
prefixes=
else
if $posix_mkdir; then
(umask=$mkdir_umask &&
$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
# Don't fail if two instances are running concurrently.
test -d "$prefix" || exit 1
else
case $prefix in
*\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
*) qprefix=$prefix;;
esac
prefixes="$prefixes '$qprefix'"
fi
fi
prefix=$prefix/
done
if test -n "$prefixes"; then
# Don't fail if two instances are running concurrently.
(umask $mkdir_umask &&
eval "\$doit_exec \$mkdirprog $prefixes") ||
test -d "$dstdir" || exit 1
obsolete_mkdir_used=true
fi
fi
fi
if test -n "$dir_arg"; then
{ test -z "$chowncmd" || $doit $chowncmd "$dst"; } &&
{ test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } &&
{ test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false ||
test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1
else
# Make a couple of temp file names in the proper directory.
dsttmp=$dstdir/_inst.$$_
rmtmp=$dstdir/_rm.$$_
# Trap to clean up those temp files at exit.
trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
# Copy the file name to the temp name.
(umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") &&
# and set any options; do chmod last to preserve setuid bits.
#
# If any of these fail, we abort the whole thing. If we want to
# ignore errors from any of these, just make sure not to ignore
# errors from the above "$doit $cpprog $src $dsttmp" command.
#
{ test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } &&
{ test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } &&
{ test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } &&
{ test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } &&
# If -C, don't bother to copy if it wouldn't change the file.
if $copy_on_change &&
old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` &&
new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` &&
eval "$initialize_posix_glob" &&
$posix_glob set -f &&
set X $old && old=:$2:$4:$5:$6 &&
set X $new && new=:$2:$4:$5:$6 &&
$posix_glob set +f &&
test "$old" = "$new" &&
$cmpprog "$dst" "$dsttmp" >/dev/null 2>&1
then
rm -f "$dsttmp"
else
# Rename the file to the real destination.
$doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null ||
# The rename failed, perhaps because mv can't rename something else
# to itself, or perhaps because mv is so ancient that it does not
# support -f.
{
# Now remove or move aside any old file at destination location.
# We try this two ways since rm can't unlink itself on some
# systems and the destination file might be busy for other
# reasons. In this case, the final cleanup might fail but the new
# file should still install successfully.
{
test ! -f "$dst" ||
$doit $rmcmd -f "$dst" 2>/dev/null ||
{ $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null &&
{ $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }
} ||
{ echo "$0: cannot unlink or rename $dst" >&2
(exit 1); exit 1
}
} &&
# Now rename the file to the real destination.
$doit $mvcmd "$dsttmp" "$dst"
}
fi || exit 1
trap '' 0
fi
done
# Local variables:
# eval: (add-hook 'write-file-hooks 'time-stamp)
# time-stamp-start: "scriptversion="
# time-stamp-format: "%:y-%02m-%02d.%02H"
# time-stamp-time-zone: "UTC"
# time-stamp-end: "; # UTC"
# End:
if [ x"$dir_arg" = x ]
then
dstisfile=""
if [ ! -d "$dst" ]
then
if [ x"$msrc" = x"$src" ]
then
dstisfile=true
else
echo "install: destination is not a directory"
exit 1
fi
fi
else
msrc="$msrc $dst"
fi
if [ x"$msrc" = x ]
then
echo "install: no destination specified"
exit 1
fi
for srcarg in $msrc; do
if [ x"$dir_arg" != x ]; then
dstarg="$srcarg"
else
dstarg="$dst"
# Waiting for this to be detected by the "$instcmd $srcarg $dsttmp" command
# might cause directories to be created, which would be especially bad
# if $src (and thus $dsttmp) contains '*'.
if [ -f "$srcarg" ]
then
doinst="$instcmd $instflags"
elif [ -d "$srcarg" ]
then
echo "install: $srcarg: not a regular file"
exit 1
elif [ "$srcarg" = "/dev/null" ]
then
doinst="$cpprog"
else
echo "install: $srcarg does not exist"
exit 1
fi
# If destination is a directory, append the input filename; if your system
# does not like double slashes in filenames, you may need to add some logic
if [ -d "$dstarg" ]
then
dstarg="$dstarg"/`basename "$srcarg"`
fi
fi
## this sed command emulates the dirname command
dstdir=`echo "$dstarg" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
# Make sure that the destination directory exists.
# this part is taken from Noah Friedman's mkinstalldirs script
# Skip lots of stat calls in the usual case.
if [ ! -d "$dstdir" ]; then
defaultIFS='
'
IFS="${IFS-${defaultIFS}}"
oIFS="${IFS}"
# Some sh's can't handle IFS=/ for some reason.
IFS='%'
set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
IFS="${oIFS}"
pathcomp=''
while [ $# -ne 0 ] ; do
pathcomp="${pathcomp}${1}"
shift
if [ ! -d "${pathcomp}" ] ;
then
$doit $mkdirprog "${pathcomp}"
if [ x"$chowncmd" != x ]; then $doit $chowncmd "${pathcomp}"; else true ; fi &&
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "${pathcomp}"; else true ; fi &&
if [ x"$pathcompchmodcmd" != x ]; then $doit $pathcompchmodcmd "${pathcomp}"; else true ; fi
else
true
fi
pathcomp="${pathcomp}/"
done
fi
if [ x"$dir_arg" != x ]
then
if [ -d "$dstarg" ]; then
true
else
$doit $mkdirprog "$dstarg" &&
if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dstarg"; else true ; fi &&
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dstarg"; else true ; fi &&
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dstarg"; else true ; fi
fi
else
if [ x"$dstisfile" = x ]
then
file=$srcarg
else
file=$dst
fi
dstfile=`basename "$file"`
dstfinal="$dstdir/$dstfile"
# Make a temp file name in the proper directory.
dsttmp=$dstdir/#inst.$$#
# Make a backup file name in the proper directory.
case x$suffixfmt in
*%*) suffix=`echo x |
$awkprog -v bname="$dstfinal" -v fmt="$suffixfmt" '
{ cnt = 0;
do {
sfx = sprintf(fmt, cnt++);
name = bname sfx;
} while (system("test -f " name) == 0);
print sfx; }' -`;;
x) ;;
*) suffix="$suffixfmt";;
esac
dstbackup="$dstfinal$suffix"
# Move or copy the file name to the temp name
$doit $doinst $srcarg "$dsttmp" &&
trap "rm -f ${dsttmp}" 0 &&
# and set any options; do chmod last to preserve setuid bits
# If any of these fail, we abort the whole thing. If we want to
# ignore errors from any of these, just make sure not to ignore
# errors from the above "$doit $instcmd $src $dsttmp" command.
if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dsttmp"; else true;fi &&
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dsttmp"; else true;fi &&
if [ x"$stripcmd" != x ]; then $doit $stripcmd $stripflags "$dsttmp"; else true;fi &&
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dsttmp"; else true;fi &&
# Now rename the file to the real destination.
if [ x"$suffix" != x ] && [ -f "$dstfinal" ]
then
$doit $mvcmd "$dstfinal" "$dstbackup"
else
$doit $rmcmd -f "$dstfinal"
fi &&
$doit $mvcmd "$dsttmp" "$dstfinal"
fi
done &&
exit 0

File diff suppressed because it is too large Load diff

View file

@ -1,10 +1,9 @@
#! /bin/sh
# Common stub for a few missing GNU programs while installing.
scriptversion=2012-01-06.13; # UTC
scriptversion=2012-01-06.18; # UTC
# Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003, 2004, 2005, 2006,
# 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
# Copyright (C) 1996-2012 Free Software Foundation, Inc.
# Originally by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
# This program is free software; you can redistribute it and/or modify
@ -26,7 +25,7 @@ scriptversion=2012-01-06.13; # UTC
# the same distribution terms that you use for the rest of that program.
if test $# -eq 0; then
echo 1>&2 "Try \`$0 --help' for more information"
echo 1>&2 "Try '$0 --help' for more information"
exit 1
fi
@ -34,7 +33,7 @@ run=:
sed_output='s/.* --output[ =]\([^ ]*\).*/\1/p'
sed_minuso='s/.* -o \([^ ]*\).*/\1/p'
# In the cases where this matters, `missing' is being run in the
# In the cases where this matters, 'missing' is being run in the
# srcdir already.
if test -f configure.ac; then
configure_ac=configure.ac
@ -65,7 +64,7 @@ case $1 in
echo "\
$0 [OPTION]... PROGRAM [ARGUMENT]...
Handle \`PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an
Handle 'PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an
error status if there is no known handling for PROGRAM.
Options:
@ -74,20 +73,20 @@ Options:
--run try to run the given command, and emulate it if it fails
Supported PROGRAM values:
aclocal touch file \`aclocal.m4'
autoconf touch file \`configure'
autoheader touch file \`config.h.in'
aclocal touch file 'aclocal.m4'
autoconf touch file 'configure'
autoheader touch file 'config.h.in'
autom4te touch the output file, or create a stub one
automake touch all \`Makefile.in' files
bison create \`y.tab.[ch]', if possible, from existing .[ch]
flex create \`lex.yy.c', if possible, from existing .c
automake touch all 'Makefile.in' files
bison create 'y.tab.[ch]', if possible, from existing .[ch]
flex create 'lex.yy.c', if possible, from existing .c
help2man touch the output file
lex create \`lex.yy.c', if possible, from existing .c
lex create 'lex.yy.c', if possible, from existing .c
makeinfo touch the output file
yacc create \`y.tab.[ch]', if possible, from existing .[ch]
yacc create 'y.tab.[ch]', if possible, from existing .[ch]
Version suffixes to PROGRAM as well as the prefixes \`gnu-', \`gnu', and
\`g' are ignored when checking the name.
Version suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
'g' are ignored when checking the name.
Send bug reports to <bug-automake@gnu.org>."
exit $?
@ -99,8 +98,8 @@ Send bug reports to <bug-automake@gnu.org>."
;;
-*)
echo 1>&2 "$0: Unknown \`$1' option"
echo 1>&2 "Try \`$0 --help' for more information"
echo 1>&2 "$0: Unknown '$1' option"
echo 1>&2 "Try '$0 --help' for more information"
exit 1
;;
@ -127,7 +126,7 @@ case $1 in
exit 1
elif test "x$2" = "x--version" || test "x$2" = "x--help"; then
# Could not run --version or --help. This is probably someone
# running `$TOOL --version' or `$TOOL --help' to check whether
# running '$TOOL --version' or '$TOOL --help' to check whether
# $TOOL exists and not knowing $TOOL uses missing.
exit 1
fi
@ -139,27 +138,27 @@ esac
case $program in
aclocal*)
echo 1>&2 "\
WARNING: \`$1' is $msg. You should only need it if
you modified \`acinclude.m4' or \`${configure_ac}'. You might want
to install the \`Automake' and \`Perl' packages. Grab them from
WARNING: '$1' is $msg. You should only need it if
you modified 'acinclude.m4' or '${configure_ac}'. You might want
to install the Automake and Perl packages. Grab them from
any GNU archive site."
touch aclocal.m4
;;
autoconf*)
echo 1>&2 "\
WARNING: \`$1' is $msg. You should only need it if
you modified \`${configure_ac}'. You might want to install the
\`Autoconf' and \`GNU m4' packages. Grab them from any GNU
WARNING: '$1' is $msg. You should only need it if
you modified '${configure_ac}'. You might want to install the
Autoconf and GNU m4 packages. Grab them from any GNU
archive site."
touch configure
;;
autoheader*)
echo 1>&2 "\
WARNING: \`$1' is $msg. You should only need it if
you modified \`acconfig.h' or \`${configure_ac}'. You might want
to install the \`Autoconf' and \`GNU m4' packages. Grab them
WARNING: '$1' is $msg. You should only need it if
you modified 'acconfig.h' or '${configure_ac}'. You might want
to install the Autoconf and GNU m4 packages. Grab them
from any GNU archive site."
files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' ${configure_ac}`
test -z "$files" && files="config.h"
@ -176,9 +175,9 @@ WARNING: \`$1' is $msg. You should only need it if
automake*)
echo 1>&2 "\
WARNING: \`$1' is $msg. You should only need it if
you modified \`Makefile.am', \`acinclude.m4' or \`${configure_ac}'.
You might want to install the \`Automake' and \`Perl' packages.
WARNING: '$1' is $msg. You should only need it if
you modified 'Makefile.am', 'acinclude.m4' or '${configure_ac}'.
You might want to install the Automake and Perl packages.
Grab them from any GNU archive site."
find . -type f -name Makefile.am -print |
sed 's/\.am$/.in/' |
@ -187,10 +186,10 @@ WARNING: \`$1' is $msg. You should only need it if
autom4te*)
echo 1>&2 "\
WARNING: \`$1' is needed, but is $msg.
WARNING: '$1' is needed, but is $msg.
You might have modified some files without having the
proper tools for further handling them.
You can get \`$1' as part of \`Autoconf' from any GNU
You can get '$1' as part of Autoconf from any GNU
archive site."
file=`echo "$*" | sed -n "$sed_output"`
@ -210,10 +209,10 @@ WARNING: \`$1' is needed, but is $msg.
bison*|yacc*)
echo 1>&2 "\
WARNING: \`$1' $msg. You should only need it if
you modified a \`.y' file. You may need the \`Bison' package
WARNING: '$1' $msg. You should only need it if
you modified a '.y' file. You may need the Bison package
in order for those modifications to take effect. You can get
\`Bison' from any GNU archive site."
Bison from any GNU archive site."
rm -f y.tab.c y.tab.h
if test $# -ne 1; then
eval LASTARG=\${$#}
@ -240,10 +239,10 @@ WARNING: \`$1' $msg. You should only need it if
lex*|flex*)
echo 1>&2 "\
WARNING: \`$1' is $msg. You should only need it if
you modified a \`.l' file. You may need the \`Flex' package
WARNING: '$1' is $msg. You should only need it if
you modified a '.l' file. You may need the Flex package
in order for those modifications to take effect. You can get
\`Flex' from any GNU archive site."
Flex from any GNU archive site."
rm -f lex.yy.c
if test $# -ne 1; then
eval LASTARG=\${$#}
@ -263,10 +262,10 @@ WARNING: \`$1' is $msg. You should only need it if
help2man*)
echo 1>&2 "\
WARNING: \`$1' is $msg. You should only need it if
WARNING: '$1' is $msg. You should only need it if
you modified a dependency of a manual page. You may need the
\`Help2man' package in order for those modifications to take
effect. You can get \`Help2man' from any GNU archive site."
Help2man package in order for those modifications to take
effect. You can get Help2man from any GNU archive site."
file=`echo "$*" | sed -n "$sed_output"`
test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
@ -281,12 +280,12 @@ WARNING: \`$1' is $msg. You should only need it if
makeinfo*)
echo 1>&2 "\
WARNING: \`$1' is $msg. You should only need it if
you modified a \`.texi' or \`.texinfo' file, or any other file
WARNING: '$1' is $msg. You should only need it if
you modified a '.texi' or '.texinfo' file, or any other file
indirectly affecting the aspect of the manual. The spurious
call might also be the consequence of using a buggy \`make' (AIX,
DU, IRIX). You might want to install the \`Texinfo' package or
the \`GNU make' package. Grab either from any GNU archive site."
call might also be the consequence of using a buggy 'make' (AIX,
DU, IRIX). You might want to install the Texinfo package or
the GNU make package. Grab either from any GNU archive site."
# The file to touch is that specified with -o ...
file=`echo "$*" | sed -n "$sed_output"`
test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
@ -310,12 +309,12 @@ WARNING: \`$1' is $msg. You should only need it if
*)
echo 1>&2 "\
WARNING: \`$1' is needed, and is $msg.
WARNING: '$1' is needed, and is $msg.
You might have modified some files without having the
proper tools for further handling them. Check the \`README' file,
proper tools for further handling them. Check the 'README' file,
it often tells you about the needed prerequisites for installing
this package. You may also peek at any GNU archive site, in case
some other package would contain this missing \`$1' program."
some other package would contain this missing '$1' program."
exit 1
;;
esac

View file

@ -31,5 +31,6 @@
#define _ATF_CXX_HPP_
#include <atf-c++/macros.hpp>
#include <atf-c++/utils.hpp>
#endif // !defined(_ATF_CXX_HPP_)

View file

@ -38,8 +38,10 @@ libatf_c___la_SOURCES = atf-c++/build.cpp \
atf-c++/config.cpp \
atf-c++/config.hpp \
atf-c++/macros.hpp \
atf-c++/noncopyable.hpp \
atf-c++/tests.cpp \
atf-c++/tests.hpp \
atf-c++/utils.cpp \
atf-c++/utils.hpp
libatf_c___la_LDFLAGS = -version-info 0:0:0
@ -48,6 +50,7 @@ atf_c___HEADERS = atf-c++/build.hpp \
atf-c++/check.hpp \
atf-c++/config.hpp \
atf-c++/macros.hpp \
atf-c++/noncopyable.hpp \
atf-c++/tests.hpp \
atf-c++/utils.hpp
atf_c__dir = $(includedir)/atf-c++

View file

@ -26,10 +26,11 @@
.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd January 21, 2012
.Dd November 30, 2012
.Dt ATF-C++-API 3
.Os
.Sh NAME
.Nm atf-c++-api ,
.Nm ATF_ADD_TEST_CASE ,
.Nm ATF_CHECK_ERRNO ,
.Nm ATF_FAIL ,
@ -52,6 +53,17 @@
.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
@ -77,6 +89,61 @@
.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 mostly-macro-based programming interface to implement test
programs in C or C++.
@ -205,7 +272,7 @@ 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
.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.
@ -348,7 +415,7 @@ in the collection.
.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_EQ
.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.
@ -362,6 +429,163 @@ 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 -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 -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 -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 -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 -offset indent
Checks if
.Fa path
exists.
.Ed
.Pp
.Ft pid_t
.Fo atf::utils::fork
.Fa "void"
.Fc
.Bd -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 -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 -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 -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 -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 -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 EXAMPLES
The following shows a complete test program with a single test case that
validates the addition operator:
@ -371,7 +595,7 @@ validates the addition operator:
ATF_TEST_CASE(addition);
ATF_TEST_CASE_HEAD(addition)
{
set("descr", "Sample tests for the addition operator");
set_md_var("descr", "Sample tests for the addition operator");
}
ATF_TEST_CASE_BODY(addition)
{
@ -387,7 +611,7 @@ ATF_TEST_CASE_BODY(addition)
ATF_TEST_CASE(open_failure);
ATF_TEST_CASE_HEAD(open_failure)
{
set("descr", "Sample tests for the open function");
set_md_var("descr", "Sample tests for the open function");
}
ATF_TEST_CASE_BODY(open_failure)
{
@ -397,7 +621,7 @@ ATF_TEST_CASE_BODY(open_failure)
ATF_TEST_CASE(known_bug);
ATF_TEST_CASE_HEAD(known_bug)
{
set("descr", "Reproduces a known bug");
set_md_var("descr", "Reproduces a known bug");
}
ATF_TEST_CASE_BODY(known_bug)
{

48
atf-c++/atf-c++.m4 Normal file
View file

@ -0,0 +1,48 @@
dnl
dnl Automated Testing Framework (atf)
dnl
dnl Copyright 2011 Google Inc.
dnl All rights reserved.
dnl
dnl Redistribution and use in source and binary forms, with or without
dnl modification, are permitted provided that the following conditions are
dnl met:
dnl
dnl * Redistributions of source code must retain the above copyright
dnl notice, this list of conditions and the following disclaimer.
dnl * Redistributions in binary form must reproduce the above copyright
dnl notice, this list of conditions and the following disclaimer in the
dnl documentation and/or other materials provided with the distribution.
dnl * Neither the name of Google Inc. nor the names of its contributors
dnl may be used to endorse or promote products derived from this software
dnl without specific prior written permission.
dnl
dnl THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
dnl "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
dnl LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
dnl A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
dnl OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
dnl SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
dnl LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
dnl DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
dnl THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
dnl (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
dnl OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dnl
dnl ATF_CHECK_CXX([version-spec])
dnl
dnl Checks if atf-c++ is present. If version-spec is provided, ensures that
dnl the installed version of atf-sh matches the required version. This
dnl argument must be something like '>= 0.14' and accepts any version
dnl specification supported by pkg-config.
dnl
dnl Defines and substitutes ATF_CXX_CFLAGS and ATF_CXX_LIBS with the compiler
dnl and linker flags need to build against atf-c++.
AC_DEFUN([ATF_CHECK_CXX], [
spec="atf-c++[]m4_default_nblank([ $1], [])"
_ATF_CHECK_ARG_WITH(
[PKG_CHECK_MODULES([ATF_CXX], [${spec}],
[found=yes found_atf_cxx=yes], [found=no])],
[required ${spec} not found])
])

11
atf-c++/atf-c++.pc.in Normal file
View file

@ -0,0 +1,11 @@
# ATF pkg-config file
cxx=__CXX__
includedir=__INCLUDEDIR__
libdir=__LIBDIR__
Name: atf-c++
Description: Automated Testing Framework (C++ binding)
Version: __ATF_VERSION__
Cflags: -I${includedir}
Libs: -L${libdir} -latf-c++ -latf-c

View file

@ -39,7 +39,7 @@ extern "C" {
#include <string>
#include <vector>
#include <atf-c++/utils.hpp>
#include <atf-c++/noncopyable.hpp>
namespace atf {
@ -60,7 +60,7 @@ namespace check {
//! of executing arbitrary command and manages files containing
//! its output.
//!
class check_result : utils::noncopyable {
class check_result : noncopyable {
//!
//! \brief Internal representation of a result.
//!

View file

@ -193,15 +193,15 @@ ATF_TEST_CASE_BODY(build_c_o)
{
ATF_TEST_CASE_USE(h_build_c_o_ok);
run_h_tc< ATF_TEST_CASE_NAME(h_build_c_o_ok) >();
ATF_REQUIRE(grep_file("stdout", "-o test.o"));
ATF_REQUIRE(grep_file("stdout", "-c test.c"));
ATF_REQUIRE(atf::utils::grep_file("-o test.o", "stdout"));
ATF_REQUIRE(atf::utils::grep_file("-c test.c", "stdout"));
ATF_TEST_CASE_USE(h_build_c_o_fail);
run_h_tc< ATF_TEST_CASE_NAME(h_build_c_o_fail) >();
ATF_REQUIRE(grep_file("stdout", "-o test.o"));
ATF_REQUIRE(grep_file("stdout", "-c test.c"));
ATF_REQUIRE(grep_file("stderr", "test.c"));
ATF_REQUIRE(grep_file("stderr", "UNDEFINED_SYMBOL"));
ATF_REQUIRE(atf::utils::grep_file("-o test.o", "stdout"));
ATF_REQUIRE(atf::utils::grep_file("-c test.c", "stdout"));
ATF_REQUIRE(atf::utils::grep_file("test.c", "stderr"));
ATF_REQUIRE(atf::utils::grep_file("UNDEFINED_SYMBOL", "stderr"));
}
ATF_TEST_CASE(build_cpp);
@ -213,16 +213,16 @@ ATF_TEST_CASE_BODY(build_cpp)
{
ATF_TEST_CASE_USE(h_build_cpp_ok);
run_h_tc< ATF_TEST_CASE_NAME(h_build_cpp_ok) >();
ATF_REQUIRE(grep_file("stdout", "-o.*test.p"));
ATF_REQUIRE(grep_file("stdout", "test.c"));
ATF_REQUIRE(grep_file("test.p", "foo bar"));
ATF_REQUIRE(atf::utils::grep_file("-o.*test.p", "stdout"));
ATF_REQUIRE(atf::utils::grep_file("test.c", "stdout"));
ATF_REQUIRE(atf::utils::grep_file("foo bar", "test.p"));
ATF_TEST_CASE_USE(h_build_cpp_fail);
run_h_tc< ATF_TEST_CASE_NAME(h_build_cpp_fail) >();
ATF_REQUIRE(grep_file("stdout", "-o test.p"));
ATF_REQUIRE(grep_file("stdout", "test.c"));
ATF_REQUIRE(grep_file("stderr", "test.c"));
ATF_REQUIRE(grep_file("stderr", "non-existent.h"));
ATF_REQUIRE(atf::utils::grep_file("-o test.p", "stdout"));
ATF_REQUIRE(atf::utils::grep_file("test.c", "stdout"));
ATF_REQUIRE(atf::utils::grep_file("test.c", "stderr"));
ATF_REQUIRE(atf::utils::grep_file("non-existent.h", "stderr"));
}
ATF_TEST_CASE(build_cxx_o);
@ -234,15 +234,15 @@ ATF_TEST_CASE_BODY(build_cxx_o)
{
ATF_TEST_CASE_USE(h_build_cxx_o_ok);
run_h_tc< ATF_TEST_CASE_NAME(h_build_cxx_o_ok) >();
ATF_REQUIRE(grep_file("stdout", "-o test.o"));
ATF_REQUIRE(grep_file("stdout", "-c test.cpp"));
ATF_REQUIRE(atf::utils::grep_file("-o test.o", "stdout"));
ATF_REQUIRE(atf::utils::grep_file("-c test.cpp", "stdout"));
ATF_TEST_CASE_USE(h_build_cxx_o_fail);
run_h_tc< ATF_TEST_CASE_NAME(h_build_cxx_o_fail) >();
ATF_REQUIRE(grep_file("stdout", "-o test.o"));
ATF_REQUIRE(grep_file("stdout", "-c test.cpp"));
ATF_REQUIRE(grep_file("stderr", "test.cpp"));
ATF_REQUIRE(grep_file("stderr", "UNDEFINED_SYMBOL"));
ATF_REQUIRE(atf::utils::grep_file("-o test.o", "stdout"));
ATF_REQUIRE(atf::utils::grep_file("-c test.cpp", "stdout"));
ATF_REQUIRE(atf::utils::grep_file("test.cpp", "stderr"));
ATF_REQUIRE(atf::utils::grep_file("UNDEFINED_SYMBOL", "stderr"));
}
ATF_TEST_CASE(exec_cleanup);

View file

@ -3,6 +3,7 @@ Content-Type: application/X-atf-atffile; version="1"
prop: test-suite = atf
tp: application_test
tp: auto_array_test
tp: env_test
tp: exceptions_test
tp: expand_test

View file

@ -3,6 +3,7 @@ syntax("kyuafile", 1)
test_suite("atf")
atf_test_program{name="application_test"}
atf_test_program{name="auto_array_test"}
atf_test_program{name="env_test"}
atf_test_program{name="exceptions_test"}
atf_test_program{name="expand_test"}

View file

@ -29,6 +29,7 @@
libatf_c___la_SOURCES += atf-c++/detail/application.cpp \
atf-c++/detail/application.hpp \
atf-c++/detail/auto_array.hpp \
atf-c++/detail/env.cpp \
atf-c++/detail/env.hpp \
atf-c++/detail/exceptions.cpp \
@ -60,6 +61,10 @@ tests_atf_c___detail_PROGRAMS = atf-c++/detail/application_test
atf_c___detail_application_test_SOURCES = atf-c++/detail/application_test.cpp
atf_c___detail_application_test_LDADD = atf-c++/detail/libtest_helpers.la $(ATF_CXX_LIBS)
tests_atf_c___detail_PROGRAMS += atf-c++/detail/auto_array_test
atf_c___detail_auto_array_test_SOURCES = atf-c++/detail/auto_array_test.cpp
atf_c___detail_auto_array_test_LDADD = atf-c++/detail/libtest_helpers.la $(ATF_CXX_LIBS)
tests_atf_c___detail_PROGRAMS += atf-c++/detail/env_test
atf_c___detail_env_test_SOURCES = atf-c++/detail/env_test.cpp
atf_c___detail_env_test_LDADD = atf-c++/detail/libtest_helpers.la $(ATF_CXX_LIBS)

View file

@ -0,0 +1,179 @@
//
// 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_AUTO_ARRAY_HPP_)
#define _ATF_CXX_AUTO_ARRAY_HPP_
#include <cstddef>
namespace atf {
// ------------------------------------------------------------------------
// The "auto_array" class.
// ------------------------------------------------------------------------
template< class T >
struct auto_array_ref {
T* m_ptr;
explicit auto_array_ref(T*);
};
template< class T >
auto_array_ref< T >::auto_array_ref(T* ptr) :
m_ptr(ptr)
{
}
template< class T >
class auto_array {
T* m_ptr;
public:
auto_array(T* = NULL) throw();
auto_array(auto_array< T >&) throw();
auto_array(auto_array_ref< T >) throw();
~auto_array(void) throw();
T* get(void) throw();
const T* get(void) const throw();
T* release(void) throw();
void reset(T* = NULL) throw();
auto_array< T >& operator=(auto_array< T >&) throw();
auto_array< T >& operator=(auto_array_ref< T >) throw();
T& operator[](int) throw();
operator auto_array_ref< T >(void) throw();
};
template< class T >
auto_array< T >::auto_array(T* ptr)
throw() :
m_ptr(ptr)
{
}
template< class T >
auto_array< T >::auto_array(auto_array< T >& ptr)
throw() :
m_ptr(ptr.release())
{
}
template< class T >
auto_array< T >::auto_array(auto_array_ref< T > ref)
throw() :
m_ptr(ref.m_ptr)
{
}
template< class T >
auto_array< T >::~auto_array(void)
throw()
{
if (m_ptr != NULL)
delete [] m_ptr;
}
template< class T >
T*
auto_array< T >::get(void)
throw()
{
return m_ptr;
}
template< class T >
const T*
auto_array< T >::get(void)
const throw()
{
return m_ptr;
}
template< class T >
T*
auto_array< T >::release(void)
throw()
{
T* ptr = m_ptr;
m_ptr = NULL;
return ptr;
}
template< class T >
void
auto_array< T >::reset(T* ptr)
throw()
{
if (m_ptr != NULL)
delete [] m_ptr;
m_ptr = ptr;
}
template< class T >
auto_array< T >&
auto_array< T >::operator=(auto_array< T >& ptr)
throw()
{
reset(ptr.release());
return *this;
}
template< class T >
auto_array< T >&
auto_array< T >::operator=(auto_array_ref< T > ref)
throw()
{
if (m_ptr != ref.m_ptr) {
delete [] m_ptr;
m_ptr = ref.m_ptr;
}
return *this;
}
template< class T >
T&
auto_array< T >::operator[](int pos)
throw()
{
return m_ptr[pos];
}
template< class T >
auto_array< T >::operator auto_array_ref< T >(void)
throw()
{
return auto_array_ref< T >(release());
}
} // namespace atf
#endif // !defined(_ATF_CXX_AUTO_ARRAY_HPP_)

View file

@ -0,0 +1,304 @@
//
// 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.
//
extern "C" {
#include <sys/types.h>
}
#include <iostream>
#include "atf-c/defs.h"
#include "../macros.hpp"
#include "auto_array.hpp"
// ------------------------------------------------------------------------
// Tests for the "auto_array" class.
// ------------------------------------------------------------------------
class test_array {
public:
int m_value;
static ssize_t m_nblocks;
static
atf::auto_array< test_array >
do_copy(atf::auto_array< test_array >& ta)
{
return atf::auto_array< test_array >(ta);
}
void* operator new(size_t size ATF_DEFS_ATTRIBUTE_UNUSED)
{
ATF_FAIL("New called but should have been new[]");
return new int(5);
}
void* operator new[](size_t size)
{
m_nblocks++;
void* mem = ::operator new(size);
std::cout << "Allocated 'test_array' object " << mem << "\n";
return mem;
}
void operator delete(void* mem ATF_DEFS_ATTRIBUTE_UNUSED)
{
ATF_FAIL("Delete called but should have been delete[]");
}
void operator delete[](void* mem)
{
std::cout << "Releasing 'test_array' object " << mem << "\n";
if (m_nblocks == 0)
ATF_FAIL("Unbalanced delete[]");
m_nblocks--;
::operator delete(mem);
}
};
ssize_t test_array::m_nblocks = 0;
ATF_TEST_CASE(auto_array_scope);
ATF_TEST_CASE_HEAD(auto_array_scope)
{
set_md_var("descr", "Tests the automatic scope handling in the "
"auto_array smart pointer class");
}
ATF_TEST_CASE_BODY(auto_array_scope)
{
using atf::auto_array;
ATF_REQUIRE_EQ(test_array::m_nblocks, 0);
{
auto_array< test_array > t(new test_array[10]);
ATF_REQUIRE_EQ(test_array::m_nblocks, 1);
}
ATF_REQUIRE_EQ(test_array::m_nblocks, 0);
}
ATF_TEST_CASE(auto_array_copy);
ATF_TEST_CASE_HEAD(auto_array_copy)
{
set_md_var("descr", "Tests the auto_array smart pointer class' copy "
"constructor");
}
ATF_TEST_CASE_BODY(auto_array_copy)
{
using atf::auto_array;
ATF_REQUIRE_EQ(test_array::m_nblocks, 0);
{
auto_array< test_array > t1(new test_array[10]);
ATF_REQUIRE_EQ(test_array::m_nblocks, 1);
{
auto_array< test_array > t2(t1);
ATF_REQUIRE_EQ(test_array::m_nblocks, 1);
}
ATF_REQUIRE_EQ(test_array::m_nblocks, 0);
}
ATF_REQUIRE_EQ(test_array::m_nblocks, 0);
}
ATF_TEST_CASE(auto_array_copy_ref);
ATF_TEST_CASE_HEAD(auto_array_copy_ref)
{
set_md_var("descr", "Tests the auto_array smart pointer class' copy "
"constructor through the auxiliary auto_array_ref object");
}
ATF_TEST_CASE_BODY(auto_array_copy_ref)
{
using atf::auto_array;
ATF_REQUIRE_EQ(test_array::m_nblocks, 0);
{
auto_array< test_array > t1(new test_array[10]);
ATF_REQUIRE_EQ(test_array::m_nblocks, 1);
{
auto_array< test_array > t2 = test_array::do_copy(t1);
ATF_REQUIRE_EQ(test_array::m_nblocks, 1);
}
ATF_REQUIRE_EQ(test_array::m_nblocks, 0);
}
ATF_REQUIRE_EQ(test_array::m_nblocks, 0);
}
ATF_TEST_CASE(auto_array_get);
ATF_TEST_CASE_HEAD(auto_array_get)
{
set_md_var("descr", "Tests the auto_array smart pointer class' get "
"method");
}
ATF_TEST_CASE_BODY(auto_array_get)
{
using atf::auto_array;
test_array* ta = new test_array[10];
auto_array< test_array > t(ta);
ATF_REQUIRE_EQ(t.get(), ta);
}
ATF_TEST_CASE(auto_array_release);
ATF_TEST_CASE_HEAD(auto_array_release)
{
set_md_var("descr", "Tests the auto_array smart pointer class' release "
"method");
}
ATF_TEST_CASE_BODY(auto_array_release)
{
using atf::auto_array;
test_array* ta1 = new test_array[10];
{
auto_array< test_array > t(ta1);
ATF_REQUIRE_EQ(test_array::m_nblocks, 1);
test_array* ta2 = t.release();
ATF_REQUIRE_EQ(ta2, ta1);
ATF_REQUIRE_EQ(test_array::m_nblocks, 1);
}
ATF_REQUIRE_EQ(test_array::m_nblocks, 1);
delete [] ta1;
}
ATF_TEST_CASE(auto_array_reset);
ATF_TEST_CASE_HEAD(auto_array_reset)
{
set_md_var("descr", "Tests the auto_array smart pointer class' reset "
"method");
}
ATF_TEST_CASE_BODY(auto_array_reset)
{
using atf::auto_array;
test_array* ta1 = new test_array[10];
test_array* ta2 = new test_array[10];
ATF_REQUIRE_EQ(test_array::m_nblocks, 2);
{
auto_array< test_array > t(ta1);
ATF_REQUIRE_EQ(test_array::m_nblocks, 2);
t.reset(ta2);
ATF_REQUIRE_EQ(test_array::m_nblocks, 1);
t.reset();
ATF_REQUIRE_EQ(test_array::m_nblocks, 0);
}
ATF_REQUIRE_EQ(test_array::m_nblocks, 0);
}
ATF_TEST_CASE(auto_array_assign);
ATF_TEST_CASE_HEAD(auto_array_assign)
{
set_md_var("descr", "Tests the auto_array smart pointer class' "
"assignment operator");
}
ATF_TEST_CASE_BODY(auto_array_assign)
{
using atf::auto_array;
ATF_REQUIRE_EQ(test_array::m_nblocks, 0);
{
auto_array< test_array > t1(new test_array[10]);
ATF_REQUIRE_EQ(test_array::m_nblocks, 1);
{
auto_array< test_array > t2;
t2 = t1;
ATF_REQUIRE_EQ(test_array::m_nblocks, 1);
}
ATF_REQUIRE_EQ(test_array::m_nblocks, 0);
}
ATF_REQUIRE_EQ(test_array::m_nblocks, 0);
}
ATF_TEST_CASE(auto_array_assign_ref);
ATF_TEST_CASE_HEAD(auto_array_assign_ref)
{
set_md_var("descr", "Tests the auto_array smart pointer class' "
"assignment operator through the auxiliary auto_array_ref "
"object");
}
ATF_TEST_CASE_BODY(auto_array_assign_ref)
{
using atf::auto_array;
ATF_REQUIRE_EQ(test_array::m_nblocks, 0);
{
auto_array< test_array > t1(new test_array[10]);
ATF_REQUIRE_EQ(test_array::m_nblocks, 1);
{
auto_array< test_array > t2;
t2 = test_array::do_copy(t1);
ATF_REQUIRE_EQ(test_array::m_nblocks, 1);
}
ATF_REQUIRE_EQ(test_array::m_nblocks, 0);
}
ATF_REQUIRE_EQ(test_array::m_nblocks, 0);
}
ATF_TEST_CASE(auto_array_access);
ATF_TEST_CASE_HEAD(auto_array_access)
{
set_md_var("descr", "Tests the auto_array smart pointer class' access "
"operator");
}
ATF_TEST_CASE_BODY(auto_array_access)
{
using atf::auto_array;
auto_array< test_array > t(new test_array[10]);
for (int i = 0; i < 10; i++)
t[i].m_value = i * 2;
for (int i = 0; i < 10; i++)
ATF_REQUIRE_EQ(t[i].m_value, i * 2);
}
// ------------------------------------------------------------------------
// Main.
// ------------------------------------------------------------------------
ATF_INIT_TEST_CASES(tcs)
{
// Add the test for the "auto_array" class.
ATF_ADD_TEST_CASE(tcs, auto_array_scope);
ATF_ADD_TEST_CASE(tcs, auto_array_copy);
ATF_ADD_TEST_CASE(tcs, auto_array_copy_ref);
ATF_ADD_TEST_CASE(tcs, auto_array_get);
ATF_ADD_TEST_CASE(tcs, auto_array_release);
ATF_ADD_TEST_CASE(tcs, auto_array_reset);
ATF_ADD_TEST_CASE(tcs, auto_array_assign);
ATF_ADD_TEST_CASE(tcs, auto_array_assign_ref);
ATF_ADD_TEST_CASE(tcs, auto_array_access);
}

View file

@ -50,10 +50,10 @@ namespace impl = atf::process;
// ------------------------------------------------------------------------
template< class C >
atf::utils::auto_array< const char* >
atf::auto_array< const char* >
collection_to_argv(const C& c)
{
atf::utils::auto_array< const char* > argv(new const char*[c.size() + 1]);
atf::auto_array< const char* > argv(new const char*[c.size() + 1]);
std::size_t pos = 0;
for (typename C::const_iterator iter = c.begin(); iter != c.end();

View file

@ -41,11 +41,10 @@ extern "C" {
#include <string>
#include <vector>
#include "auto_array.hpp"
#include "exceptions.hpp"
#include "fs.hpp"
#include "../utils.hpp"
namespace atf {
namespace process {
@ -64,7 +63,7 @@ class argv_array {
// std::tr1::shared_array instead when it becomes widely available.
// The reason would be to remove all copy constructors and assignment
// operators from this class.
utils::auto_array< const char* > m_exec_argv;
auto_array< const char* > m_exec_argv;
void ctor_init_exec_argv(void);
public:

View file

@ -27,10 +27,6 @@
// IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
extern "C" {
#include <regex.h>
}
#include <fstream>
#include <iostream>
#include <string>
@ -88,43 +84,6 @@ get_process_helpers_path(const atf::tests::tc& tc)
".." / "atf-c" / "detail" / "process_helpers";
}
bool
grep_file(const char* name, const char* regex)
{
std::ifstream is(name);
ATF_REQUIRE(is);
bool found = false;
std::string line;
std::getline(is, line);
while (!found && is.good()) {
if (grep_string(line, regex))
found = true;
else
std::getline(is, line);
}
return found;
}
bool
grep_string(const std::string& str, const char* regex)
{
int res;
regex_t preg;
std::cout << "Looking for '" << regex << "' in '" << str << "'\n";
ATF_REQUIRE(::regcomp(&preg, regex, REG_EXTENDED) == 0);
res = ::regexec(&preg, str.c_str(), 0, NULL, 0);
ATF_REQUIRE(res == 0 || res == REG_NOMATCH);
::regfree(&preg);
return res == 0;
}
void
test_helpers_detail::check_equal(const char* expected[],
const string_vector& actual)

View file

@ -87,8 +87,6 @@ class tc;
void header_check(const char*);
void build_check_cxx_o(const atf::tests::tc&, const char*, const char*, bool);
atf::fs::path get_process_helpers_path(const atf::tests::tc&);
bool grep_file(const char*, const char*);
bool grep_string(const std::string&, const char*);
struct run_h_tc_data {
const atf::tests::vars_map& m_config;

View file

@ -38,6 +38,7 @@ extern "C" {
#include <stdexcept>
#include "macros.hpp"
#include "utils.hpp"
#include "detail/fs.hpp"
#include "detail/process.hpp"
@ -291,7 +292,7 @@ ATF_TEST_CASE_BODY(pass)
{
ATF_TEST_CASE_USE(h_pass);
run_h_tc< ATF_TEST_CASE_NAME(h_pass) >();
ATF_REQUIRE(grep_file("result", "^passed"));
ATF_REQUIRE(atf::utils::grep_file("^passed", "result"));
ATF_REQUIRE(atf::fs::exists(atf::fs::path("before")));
ATF_REQUIRE(!atf::fs::exists(atf::fs::path("after")));
}
@ -305,7 +306,7 @@ ATF_TEST_CASE_BODY(fail)
{
ATF_TEST_CASE_USE(h_fail);
run_h_tc< ATF_TEST_CASE_NAME(h_fail) >();
ATF_REQUIRE(grep_file("result", "^failed: Failed on purpose"));
ATF_REQUIRE(atf::utils::grep_file("^failed: Failed on purpose", "result"));
ATF_REQUIRE(atf::fs::exists(atf::fs::path("before")));
ATF_REQUIRE(!atf::fs::exists(atf::fs::path("after")));
}
@ -319,7 +320,8 @@ ATF_TEST_CASE_BODY(skip)
{
ATF_TEST_CASE_USE(h_skip);
run_h_tc< ATF_TEST_CASE_NAME(h_skip) >();
ATF_REQUIRE(grep_file("result", "^skipped: Skipped on purpose"));
ATF_REQUIRE(atf::utils::grep_file("^skipped: Skipped on purpose",
"result"));
ATF_REQUIRE(atf::fs::exists(atf::fs::path("before")));
ATF_REQUIRE(!atf::fs::exists(atf::fs::path("after")));
}
@ -354,10 +356,11 @@ ATF_TEST_CASE_BODY(require)
ATF_REQUIRE(atf::fs::exists(before));
if (t->ok) {
ATF_REQUIRE(grep_file("result", "^passed"));
ATF_REQUIRE(atf::utils::grep_file("^passed", "result"));
ATF_REQUIRE(atf::fs::exists(after));
} else {
ATF_REQUIRE(grep_file("result", "^failed: .*condition not met"));
ATF_REQUIRE(atf::utils::grep_file(
"^failed: .*condition not met", "result"));
ATF_REQUIRE(!atf::fs::exists(after));
}
@ -403,10 +406,10 @@ ATF_TEST_CASE_BODY(require_eq)
ATF_REQUIRE(atf::fs::exists(before));
if (t->ok) {
ATF_REQUIRE(grep_file("result", "^passed"));
ATF_REQUIRE(atf::utils::grep_file("^passed", "result"));
ATF_REQUIRE(atf::fs::exists(after));
} else {
ATF_REQUIRE(grep_file("result", "^failed: .*v1 != v2"));
ATF_REQUIRE(atf::utils::grep_file("^failed: .*v1 != v2", "result"));
ATF_REQUIRE(!atf::fs::exists(after));
}
@ -448,10 +451,10 @@ ATF_TEST_CASE_BODY(require_in)
ATF_REQUIRE(atf::fs::exists(before));
if (t->ok) {
ATF_REQUIRE(grep_file("result", "^passed"));
ATF_REQUIRE(atf::utils::grep_file("^passed", "result"));
ATF_REQUIRE(atf::fs::exists(after));
} else {
ATF_REQUIRE(grep_file("result", "^failed: "));
ATF_REQUIRE(atf::utils::grep_file("^failed: ", "result"));
ATF_REQUIRE(!atf::fs::exists(after));
}
@ -495,10 +498,10 @@ ATF_TEST_CASE_BODY(require_match)
ATF_REQUIRE(atf::fs::exists(before));
if (t->ok) {
ATF_REQUIRE(grep_file("result", "^passed"));
ATF_REQUIRE(atf::utils::grep_file("^passed", "result"));
ATF_REQUIRE(atf::fs::exists(after));
} else {
ATF_REQUIRE(grep_file("result", "^failed: "));
ATF_REQUIRE(atf::utils::grep_file("^failed: ", "result"));
ATF_REQUIRE(!atf::fs::exists(after));
}
@ -540,10 +543,10 @@ ATF_TEST_CASE_BODY(require_not_in)
ATF_REQUIRE(atf::fs::exists(before));
if (t->ok) {
ATF_REQUIRE(grep_file("result", "^passed"));
ATF_REQUIRE(atf::utils::grep_file("^passed", "result"));
ATF_REQUIRE(atf::fs::exists(after));
} else {
ATF_REQUIRE(grep_file("result", "^failed: "));
ATF_REQUIRE(atf::utils::grep_file("^failed: ", "result"));
ATF_REQUIRE(!atf::fs::exists(after));
}
@ -586,13 +589,13 @@ ATF_TEST_CASE_BODY(require_throw)
ATF_REQUIRE(atf::fs::exists(before));
if (t->ok) {
ATF_REQUIRE(grep_file("result", "^passed"));
ATF_REQUIRE(atf::utils::grep_file("^passed", "result"));
ATF_REQUIRE(atf::fs::exists(after));
} else {
std::cout << "Checking that message contains '" << t->msg
<< "'\n";
std::string exp_result = std::string("^failed: .*") + t->msg;
ATF_REQUIRE(grep_file("result", exp_result.c_str()));
ATF_REQUIRE(atf::utils::grep_file(exp_result.c_str(), "result"));
ATF_REQUIRE(!atf::fs::exists(after));
}
@ -638,13 +641,13 @@ ATF_TEST_CASE_BODY(require_throw_re)
ATF_REQUIRE(atf::fs::exists(before));
if (t->ok) {
ATF_REQUIRE(grep_file("result", "^passed"));
ATF_REQUIRE(atf::utils::grep_file("^passed", "result"));
ATF_REQUIRE(atf::fs::exists(after));
} else {
std::cout << "Checking that message contains '" << t->msg
<< "'\n";
std::string exp_result = std::string("^failed: .*") + t->msg;
ATF_REQUIRE(grep_file("result", exp_result.c_str()));
ATF_REQUIRE(atf::utils::grep_file(exp_result.c_str(), "result"));
ATF_REQUIRE(!atf::fs::exists(after));
}
@ -688,13 +691,13 @@ ATF_TEST_CASE_BODY(check_errno)
ATF_REQUIRE(atf::fs::exists(after));
if (t->ok) {
ATF_REQUIRE(grep_file("result", "^passed"));
ATF_REQUIRE(atf::utils::grep_file("^passed", "result"));
} else {
ATF_REQUIRE(grep_file("result", "^failed"));
ATF_REQUIRE(atf::utils::grep_file("^failed", "result"));
std::string exp_result = "macros_test.cpp:[0-9]+: " +
std::string(t->msg) + "$";
ATF_REQUIRE(grep_file("stderr", exp_result.c_str()));
ATF_REQUIRE(atf::utils::grep_file(exp_result.c_str(), "stderr"));
}
atf::fs::remove(before);
@ -734,12 +737,12 @@ ATF_TEST_CASE_BODY(require_errno)
ATF_REQUIRE(atf::fs::exists(before));
if (t->ok) {
ATF_REQUIRE(grep_file("result", "^passed"));
ATF_REQUIRE(atf::utils::grep_file("^passed", "result"));
ATF_REQUIRE(atf::fs::exists(after));
} else {
std::string exp_result = "^failed: .*macros_test.cpp:[0-9]+: " +
std::string(t->msg) + "$";
ATF_REQUIRE(grep_file("result", exp_result.c_str()));
ATF_REQUIRE(atf::utils::grep_file(exp_result.c_str(), "result"));
ATF_REQUIRE(!atf::fs::exists(after));
}

56
atf-c++/noncopyable.hpp Normal file
View file

@ -0,0 +1,56 @@
//
// 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_NONCOPYABLE_HPP_)
#define _ATF_CXX_NONCOPYABLE_HPP_
namespace atf {
// ------------------------------------------------------------------------
// The "noncopyable" class.
// ------------------------------------------------------------------------
class noncopyable {
// The class cannot be empty; otherwise we get ABI-stability warnings
// during the build, which will break it due to strict checking.
int m_noncopyable_dummy;
noncopyable(const noncopyable& nc);
noncopyable& operator=(const noncopyable& nc);
protected:
// Explicitly needed to provide some non-private functions. Otherwise
// we also get some warnings during the build.
noncopyable(void) {}
~noncopyable(void) {}
};
} // namespace atf
#endif // !defined(_ATF_CXX_NONCOPYABLE_HPP_)

View file

@ -55,9 +55,11 @@ extern "C" {
#include "atf-c/utils.h"
}
#include "noncopyable.hpp"
#include "tests.hpp"
#include "detail/application.hpp"
#include "detail/auto_array.hpp"
#include "detail/env.hpp"
#include "detail/exceptions.hpp"
#include "detail/fs.hpp"
@ -127,7 +129,7 @@ detail::match(const std::string& regexp, const std::string& str)
static std::map< atf_tc_t*, impl::tc* > wraps;
static std::map< const atf_tc_t*, const impl::tc* > cwraps;
struct impl::tc_impl : atf::utils::noncopyable {
struct impl::tc_impl : atf::noncopyable {
std::string m_ident;
atf_tc_t m_tc;
bool m_has_cleanup;
@ -190,8 +192,7 @@ impl::tc::init(const vars_map& config)
{
atf_error_t err;
utils::auto_array< const char * > array(
new const char*[(config.size() * 2) + 1]);
auto_array< const char * > array(new const char*[(config.size() * 2) + 1]);
const char **ptr = array.get();
for (vars_map::const_iterator iter = config.begin();
iter != config.end(); iter++) {

View file

@ -38,7 +38,7 @@ extern "C" {
#include <atf-c/defs.h>
}
#include <atf-c++/utils.hpp>
#include <atf-c++/noncopyable.hpp>
namespace atf {
namespace tests {
@ -74,7 +74,7 @@ typedef std::map< std::string, std::string > vars_map;
struct tc_impl;
class tc : utils::noncopyable {
class tc : noncopyable {
std::auto_ptr< tc_impl > pimpl;
protected:

104
atf-c++/utils.cpp Normal file
View file

@ -0,0 +1,104 @@
//
// 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.
//
extern "C" {
#include "atf-c/utils.h"
}
#include <cstdlib>
#include <iostream>
#include "utils.hpp"
void
atf::utils::cat_file(const std::string& path, const std::string& prefix)
{
atf_utils_cat_file(path.c_str(), prefix.c_str());
}
void
atf::utils::copy_file(const std::string& source, const std::string& destination)
{
atf_utils_copy_file(source.c_str(), destination.c_str());
}
bool
atf::utils::compare_file(const std::string& path, const std::string& contents)
{
return atf_utils_compare_file(path.c_str(), contents.c_str());
}
void
atf::utils::create_file(const std::string& path, const std::string& contents)
{
atf_utils_create_file(path.c_str(), "%s", contents.c_str());
}
bool
atf::utils::file_exists(const std::string& path)
{
return atf_utils_file_exists(path.c_str());
}
pid_t
atf::utils::fork(void)
{
std::cout.flush();
std::cerr.flush();
return atf_utils_fork();
}
bool
atf::utils::grep_file(const std::string& regex, const std::string& path)
{
return atf_utils_grep_file("%s", path.c_str(), regex.c_str());
}
bool
atf::utils::grep_string(const std::string& regex, const std::string& str)
{
return atf_utils_grep_string("%s", str.c_str(), regex.c_str());
}
void
atf::utils::redirect(const int fd, const std::string& path)
{
if (fd == STDOUT_FILENO)
std::cout.flush();
else if (fd == STDERR_FILENO)
std::cerr.flush();
atf_utils_redirect(fd, path.c_str());
}
void
atf::utils::wait(const pid_t pid, const int exitstatus,
const std::string& expout, const std::string& experr)
{
atf_utils_wait(pid, exitstatus, expout.c_str(), experr.c_str());
}

View file

@ -30,170 +30,38 @@
#if !defined(_ATF_CXX_UTILS_HPP_)
#define _ATF_CXX_UTILS_HPP_
#include <cstddef>
extern "C" {
#include <unistd.h>
}
#include <string>
namespace atf {
namespace utils {
// ------------------------------------------------------------------------
// The "auto_array" class.
// ------------------------------------------------------------------------
void cat_file(const std::string&, const std::string&);
bool compare_file(const std::string&, const std::string&);
void copy_file(const std::string&, const std::string&);
void create_file(const std::string&, const std::string&);
bool file_exists(const std::string&);
pid_t fork(void);
bool grep_file(const std::string&, const std::string&);
bool grep_string(const std::string&, const std::string&);
void redirect(const int, const std::string&);
void wait(const pid_t, const int, const std::string&, const std::string&);
template< class T >
struct auto_array_ref {
T* m_ptr;
explicit auto_array_ref(T*);
};
template< class T >
auto_array_ref< T >::auto_array_ref(T* ptr) :
m_ptr(ptr)
template< typename Collection >
bool
grep_collection(const std::string& regexp, const Collection& collection)
{
}
template< class T >
class auto_array {
T* m_ptr;
public:
auto_array(T* = NULL) throw();
auto_array(auto_array< T >&) throw();
auto_array(auto_array_ref< T >) throw();
~auto_array(void) throw();
T* get(void) throw();
const T* get(void) const throw();
T* release(void) throw();
void reset(T* = NULL) throw();
auto_array< T >& operator=(auto_array< T >&) throw();
auto_array< T >& operator=(auto_array_ref< T >) throw();
T& operator[](int) throw();
operator auto_array_ref< T >(void) throw();
};
template< class T >
auto_array< T >::auto_array(T* ptr)
throw() :
m_ptr(ptr)
{
}
template< class T >
auto_array< T >::auto_array(auto_array< T >& ptr)
throw() :
m_ptr(ptr.release())
{
}
template< class T >
auto_array< T >::auto_array(auto_array_ref< T > ref)
throw() :
m_ptr(ref.m_ptr)
{
}
template< class T >
auto_array< T >::~auto_array(void)
throw()
{
if (m_ptr != NULL)
delete [] m_ptr;
}
template< class T >
T*
auto_array< T >::get(void)
throw()
{
return m_ptr;
}
template< class T >
const T*
auto_array< T >::get(void)
const throw()
{
return m_ptr;
}
template< class T >
T*
auto_array< T >::release(void)
throw()
{
T* ptr = m_ptr;
m_ptr = NULL;
return ptr;
}
template< class T >
void
auto_array< T >::reset(T* ptr)
throw()
{
if (m_ptr != NULL)
delete [] m_ptr;
m_ptr = ptr;
}
template< class T >
auto_array< T >&
auto_array< T >::operator=(auto_array< T >& ptr)
throw()
{
reset(ptr.release());
return *this;
}
template< class T >
auto_array< T >&
auto_array< T >::operator=(auto_array_ref< T > ref)
throw()
{
if (m_ptr != ref.m_ptr) {
delete [] m_ptr;
m_ptr = ref.m_ptr;
for (typename Collection::const_iterator iter = collection.begin();
iter != collection.end(); ++iter) {
if (grep_string(regexp, *iter))
return true;
}
return *this;
return false;
}
template< class T >
T&
auto_array< T >::operator[](int pos)
throw()
{
return m_ptr[pos];
}
template< class T >
auto_array< T >::operator auto_array_ref< T >(void)
throw()
{
return auto_array_ref< T >(release());
}
// ------------------------------------------------------------------------
// The "noncopyable" class.
// ------------------------------------------------------------------------
class noncopyable {
// The class cannot be empty; otherwise we get ABI-stability warnings
// during the build, which will break it due to strict checking.
int m_noncopyable_dummy;
noncopyable(const noncopyable& nc);
noncopyable& operator=(const noncopyable& nc);
protected:
// Explicitly needed to provide some non-private functions. Otherwise
// we also get some warnings during the build.
noncopyable(void) {}
~noncopyable(void) {}
};
} // namespace utils
} // namespace atf

View file

@ -27,259 +27,409 @@
// IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
#include <iostream>
extern "C" {
#include <sys/stat.h>
#include <sys/wait.h>
#include "atf-c/defs.h"
#include <fcntl.h>
#include <unistd.h>
}
#include <cstdlib>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#include "macros.hpp"
#include "utils.hpp"
#include "detail/test_helpers.hpp"
static std::string
read_file(const char *path)
{
char buffer[1024];
const int fd = open(path, O_RDONLY);
if (fd == -1)
ATF_FAIL("Cannot open " + std::string(path));
const ssize_t length = read(fd, buffer, sizeof(buffer) - 1);
close(fd);
ATF_REQUIRE(length != -1);
if (length == sizeof(buffer) - 1)
ATF_FAIL("Internal buffer not long enough to read temporary file");
((char *)buffer)[length] = '\0';
return buffer;
}
// ------------------------------------------------------------------------
// Tests for the "auto_array" class.
// Tests cases for the free functions.
// ------------------------------------------------------------------------
class test_array {
public:
int m_value;
ATF_TEST_CASE_WITHOUT_HEAD(cat_file__empty);
ATF_TEST_CASE_BODY(cat_file__empty)
{
atf::utils::create_file("file.txt", "");
atf::utils::redirect(STDOUT_FILENO, "captured.txt");
atf::utils::cat_file("file.txt", "PREFIX");
std::cout.flush();
close(STDOUT_FILENO);
static ssize_t m_nblocks;
ATF_REQUIRE_EQ("", read_file("captured.txt"));
}
static
atf::utils::auto_array< test_array >
do_copy(atf::utils::auto_array< test_array >& ta)
{
return atf::utils::auto_array< test_array >(ta);
ATF_TEST_CASE_WITHOUT_HEAD(cat_file__one_line);
ATF_TEST_CASE_BODY(cat_file__one_line)
{
atf::utils::create_file("file.txt", "This is a single line\n");
atf::utils::redirect(STDOUT_FILENO, "captured.txt");
atf::utils::cat_file("file.txt", "PREFIX");
std::cout.flush();
close(STDOUT_FILENO);
ATF_REQUIRE_EQ("PREFIXThis is a single line\n", read_file("captured.txt"));
}
ATF_TEST_CASE_WITHOUT_HEAD(cat_file__several_lines);
ATF_TEST_CASE_BODY(cat_file__several_lines)
{
atf::utils::create_file("file.txt", "First\nSecond line\nAnd third\n");
atf::utils::redirect(STDOUT_FILENO, "captured.txt");
atf::utils::cat_file("file.txt", ">");
std::cout.flush();
close(STDOUT_FILENO);
ATF_REQUIRE_EQ(">First\n>Second line\n>And third\n",
read_file("captured.txt"));
}
ATF_TEST_CASE_WITHOUT_HEAD(cat_file__no_newline_eof);
ATF_TEST_CASE_BODY(cat_file__no_newline_eof)
{
atf::utils::create_file("file.txt", "Foo\n bar baz");
atf::utils::redirect(STDOUT_FILENO, "captured.txt");
atf::utils::cat_file("file.txt", "PREFIX");
std::cout.flush();
close(STDOUT_FILENO);
ATF_REQUIRE_EQ("PREFIXFoo\nPREFIX bar baz", read_file("captured.txt"));
}
ATF_TEST_CASE_WITHOUT_HEAD(compare_file__empty__match);
ATF_TEST_CASE_BODY(compare_file__empty__match)
{
atf::utils::create_file("test.txt", "");
ATF_REQUIRE(atf::utils::compare_file("test.txt", ""));
}
ATF_TEST_CASE_WITHOUT_HEAD(compare_file__empty__not_match);
ATF_TEST_CASE_BODY(compare_file__empty__not_match)
{
atf::utils::create_file("test.txt", "");
ATF_REQUIRE(!atf::utils::compare_file("test.txt", "\n"));
ATF_REQUIRE(!atf::utils::compare_file("test.txt", "foo"));
ATF_REQUIRE(!atf::utils::compare_file("test.txt", " "));
}
ATF_TEST_CASE_WITHOUT_HEAD(compare_file__short__match);
ATF_TEST_CASE_BODY(compare_file__short__match)
{
atf::utils::create_file("test.txt", "this is a short file");
ATF_REQUIRE(atf::utils::compare_file("test.txt", "this is a short file"));
}
ATF_TEST_CASE_WITHOUT_HEAD(compare_file__short__not_match);
ATF_TEST_CASE_BODY(compare_file__short__not_match)
{
atf::utils::create_file("test.txt", "this is a short file");
ATF_REQUIRE(!atf::utils::compare_file("test.txt", ""));
ATF_REQUIRE(!atf::utils::compare_file("test.txt", "\n"));
ATF_REQUIRE(!atf::utils::compare_file("test.txt", "this is a Short file"));
ATF_REQUIRE(!atf::utils::compare_file("test.txt", "this is a short fil"));
ATF_REQUIRE(!atf::utils::compare_file("test.txt", "this is a short file "));
}
ATF_TEST_CASE_WITHOUT_HEAD(compare_file__long__match);
ATF_TEST_CASE_BODY(compare_file__long__match)
{
char long_contents[3456];
size_t i = 0;
for (; i < sizeof(long_contents) - 1; i++)
long_contents[i] = '0' + (i % 10);
long_contents[i] = '\0';
atf::utils::create_file("test.txt", long_contents);
ATF_REQUIRE(atf::utils::compare_file("test.txt", long_contents));
}
ATF_TEST_CASE_WITHOUT_HEAD(compare_file__long__not_match);
ATF_TEST_CASE_BODY(compare_file__long__not_match)
{
char long_contents[3456];
size_t i = 0;
for (; i < sizeof(long_contents) - 1; i++)
long_contents[i] = '0' + (i % 10);
long_contents[i] = '\0';
atf::utils::create_file("test.txt", long_contents);
ATF_REQUIRE(!atf::utils::compare_file("test.txt", ""));
ATF_REQUIRE(!atf::utils::compare_file("test.txt", "\n"));
ATF_REQUIRE(!atf::utils::compare_file("test.txt", "0123456789"));
long_contents[i - 1] = 'Z';
ATF_REQUIRE(!atf::utils::compare_file("test.txt", long_contents));
}
ATF_TEST_CASE_WITHOUT_HEAD(copy_file__empty);
ATF_TEST_CASE_BODY(copy_file__empty)
{
atf::utils::create_file("src.txt", "");
ATF_REQUIRE(chmod("src.txt", 0520) != -1);
atf::utils::copy_file("src.txt", "dest.txt");
ATF_REQUIRE(atf::utils::compare_file("dest.txt", ""));
struct stat sb;
ATF_REQUIRE(stat("dest.txt", &sb) != -1);
ATF_REQUIRE_EQ(0520, sb.st_mode & 0xfff);
}
ATF_TEST_CASE_WITHOUT_HEAD(copy_file__some_contents);
ATF_TEST_CASE_BODY(copy_file__some_contents)
{
atf::utils::create_file("src.txt", "This is a\ntest file\n");
atf::utils::copy_file("src.txt", "dest.txt");
ATF_REQUIRE(atf::utils::compare_file("dest.txt", "This is a\ntest file\n"));
}
ATF_TEST_CASE_WITHOUT_HEAD(create_file);
ATF_TEST_CASE_BODY(create_file)
{
atf::utils::create_file("test.txt", "This is a %d test");
ATF_REQUIRE_EQ("This is a %d test", read_file("test.txt"));
}
ATF_TEST_CASE_WITHOUT_HEAD(file_exists);
ATF_TEST_CASE_BODY(file_exists)
{
atf::utils::create_file("test.txt", "foo");
ATF_REQUIRE( atf::utils::file_exists("test.txt"));
ATF_REQUIRE( atf::utils::file_exists("./test.txt"));
ATF_REQUIRE(!atf::utils::file_exists("./test.tx"));
ATF_REQUIRE(!atf::utils::file_exists("test.txt2"));
}
ATF_TEST_CASE_WITHOUT_HEAD(fork);
ATF_TEST_CASE_BODY(fork)
{
std::cout << "Should not get into child\n";
std::cerr << "Should not get into child\n";
pid_t pid = atf::utils::fork();
if (pid == 0) {
std::cout << "Child stdout\n";
std::cerr << "Child stderr\n";
exit(EXIT_SUCCESS);
}
void* operator new(size_t size ATF_DEFS_ATTRIBUTE_UNUSED)
{
ATF_FAIL("New called but should have been new[]");
return new int(5);
int status;
ATF_REQUIRE(waitpid(pid, &status, 0) != -1);
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"));
}
ATF_TEST_CASE_WITHOUT_HEAD(grep_collection__set);
ATF_TEST_CASE_BODY(grep_collection__set)
{
std::set< std::string > strings;
strings.insert("First");
strings.insert("Second");
ATF_REQUIRE( atf::utils::grep_collection("irs", strings));
ATF_REQUIRE( atf::utils::grep_collection("cond", strings));
ATF_REQUIRE(!atf::utils::grep_collection("Third", strings));
}
ATF_TEST_CASE_WITHOUT_HEAD(grep_collection__vector);
ATF_TEST_CASE_BODY(grep_collection__vector)
{
std::vector< std::string > strings;
strings.push_back("First");
strings.push_back("Second");
ATF_REQUIRE( atf::utils::grep_collection("irs", strings));
ATF_REQUIRE( atf::utils::grep_collection("cond", strings));
ATF_REQUIRE(!atf::utils::grep_collection("Third", strings));
}
ATF_TEST_CASE_WITHOUT_HEAD(grep_file);
ATF_TEST_CASE_BODY(grep_file)
{
atf::utils::create_file("test.txt", "line1\nthe second line\naaaabbbb\n");
ATF_REQUIRE(atf::utils::grep_file("line1", "test.txt"));
ATF_REQUIRE(atf::utils::grep_file("second line", "test.txt"));
ATF_REQUIRE(atf::utils::grep_file("aa.*bb", "test.txt"));
ATF_REQUIRE(!atf::utils::grep_file("foo", "test.txt"));
ATF_REQUIRE(!atf::utils::grep_file("bar", "test.txt"));
ATF_REQUIRE(!atf::utils::grep_file("aaaaa", "test.txt"));
}
ATF_TEST_CASE_WITHOUT_HEAD(grep_string);
ATF_TEST_CASE_BODY(grep_string)
{
const char *str = "a string - aaaabbbb";
ATF_REQUIRE(atf::utils::grep_string("a string", str));
ATF_REQUIRE(atf::utils::grep_string("^a string", str));
ATF_REQUIRE(atf::utils::grep_string("aaaabbbb$", str));
ATF_REQUIRE(atf::utils::grep_string("aa.*bb", str));
ATF_REQUIRE(!atf::utils::grep_string("foo", str));
ATF_REQUIRE(!atf::utils::grep_string("bar", str));
ATF_REQUIRE(!atf::utils::grep_string("aaaaa", str));
}
ATF_TEST_CASE_WITHOUT_HEAD(redirect__stdout);
ATF_TEST_CASE_BODY(redirect__stdout)
{
std::cout << "Buffer this";
atf::utils::redirect(STDOUT_FILENO, "captured.txt");
std::cout << "The printed message";
std::cout.flush();
ATF_REQUIRE_EQ("The printed message", read_file("captured.txt"));
}
ATF_TEST_CASE_WITHOUT_HEAD(redirect__stderr);
ATF_TEST_CASE_BODY(redirect__stderr)
{
std::cerr << "Buffer this";
atf::utils::redirect(STDERR_FILENO, "captured.txt");
std::cerr << "The printed message";
std::cerr.flush();
ATF_REQUIRE_EQ("The printed message", read_file("captured.txt"));
}
ATF_TEST_CASE_WITHOUT_HEAD(redirect__other);
ATF_TEST_CASE_BODY(redirect__other)
{
const std::string message = "Foo bar\nbaz\n";
atf::utils::redirect(15, "captured.txt");
ATF_REQUIRE(write(15, message.c_str(), message.length()) != -1);
close(15);
ATF_REQUIRE_EQ(message, read_file("captured.txt"));
}
static void
fork_and_wait(const int exitstatus, const char* expout, const char* experr)
{
const pid_t pid = atf::utils::fork();
if (pid == 0) {
std::cout << "Some output\n";
std::cerr << "Some error\n";
exit(123);
}
atf::utils::wait(pid, exitstatus, expout, experr);
exit(EXIT_SUCCESS);
}
void* operator new[](size_t size)
{
m_nblocks++;
void* mem = ::operator new(size);
std::cout << "Allocated 'test_array' object " << mem << "\n";
return mem;
ATF_TEST_CASE_WITHOUT_HEAD(wait__ok);
ATF_TEST_CASE_BODY(wait__ok)
{
const pid_t control = fork();
ATF_REQUIRE(control != -1);
if (control == 0)
fork_and_wait(123, "Some output\n", "Some error\n");
else {
int status;
ATF_REQUIRE(waitpid(control, &status, 0) != -1);
ATF_REQUIRE(WIFEXITED(status));
ATF_REQUIRE_EQ(EXIT_SUCCESS, WEXITSTATUS(status));
}
}
void operator delete(void* mem ATF_DEFS_ATTRIBUTE_UNUSED)
{
ATF_FAIL("Delete called but should have been delete[]");
ATF_TEST_CASE_WITHOUT_HEAD(wait__invalid_exitstatus);
ATF_TEST_CASE_BODY(wait__invalid_exitstatus)
{
const pid_t control = fork();
ATF_REQUIRE(control != -1);
if (control == 0)
fork_and_wait(120, "Some output\n", "Some error\n");
else {
int status;
ATF_REQUIRE(waitpid(control, &status, 0) != -1);
ATF_REQUIRE(WIFEXITED(status));
ATF_REQUIRE_EQ(EXIT_FAILURE, WEXITSTATUS(status));
}
}
void operator delete[](void* mem)
{
std::cout << "Releasing 'test_array' object " << mem << "\n";
if (m_nblocks == 0)
ATF_FAIL("Unbalanced delete[]");
m_nblocks--;
::operator delete(mem);
ATF_TEST_CASE_WITHOUT_HEAD(wait__invalid_stdout);
ATF_TEST_CASE_BODY(wait__invalid_stdout)
{
const pid_t control = fork();
ATF_REQUIRE(control != -1);
if (control == 0)
fork_and_wait(123, "Some output foo\n", "Some error\n");
else {
int status;
ATF_REQUIRE(waitpid(control, &status, 0) != -1);
ATF_REQUIRE(WIFEXITED(status));
ATF_REQUIRE_EQ(EXIT_FAILURE, WEXITSTATUS(status));
}
};
ssize_t test_array::m_nblocks = 0;
ATF_TEST_CASE(auto_array_scope);
ATF_TEST_CASE_HEAD(auto_array_scope)
{
set_md_var("descr", "Tests the automatic scope handling in the "
"auto_array smart pointer class");
}
ATF_TEST_CASE_BODY(auto_array_scope)
{
using atf::utils::auto_array;
ATF_REQUIRE_EQ(test_array::m_nblocks, 0);
{
auto_array< test_array > t(new test_array[10]);
ATF_REQUIRE_EQ(test_array::m_nblocks, 1);
ATF_TEST_CASE_WITHOUT_HEAD(wait__invalid_stderr);
ATF_TEST_CASE_BODY(wait__invalid_stderr)
{
const pid_t control = fork();
ATF_REQUIRE(control != -1);
if (control == 0)
fork_and_wait(123, "Some output\n", "Some error foo\n");
else {
int status;
ATF_REQUIRE(waitpid(control, &status, 0) != -1);
ATF_REQUIRE(WIFEXITED(status));
ATF_REQUIRE_EQ(EXIT_FAILURE, WEXITSTATUS(status));
}
ATF_REQUIRE_EQ(test_array::m_nblocks, 0);
}
ATF_TEST_CASE(auto_array_copy);
ATF_TEST_CASE_HEAD(auto_array_copy)
ATF_TEST_CASE_WITHOUT_HEAD(wait__save_stdout);
ATF_TEST_CASE_BODY(wait__save_stdout)
{
set_md_var("descr", "Tests the auto_array smart pointer class' copy "
"constructor");
}
ATF_TEST_CASE_BODY(auto_array_copy)
{
using atf::utils::auto_array;
const pid_t control = fork();
ATF_REQUIRE(control != -1);
if (control == 0)
fork_and_wait(123, "save:my-output.txt", "Some error\n");
else {
int status;
ATF_REQUIRE(waitpid(control, &status, 0) != -1);
ATF_REQUIRE(WIFEXITED(status));
ATF_REQUIRE_EQ(EXIT_SUCCESS, WEXITSTATUS(status));
ATF_REQUIRE_EQ(test_array::m_nblocks, 0);
{
auto_array< test_array > t1(new test_array[10]);
ATF_REQUIRE_EQ(test_array::m_nblocks, 1);
{
auto_array< test_array > t2(t1);
ATF_REQUIRE_EQ(test_array::m_nblocks, 1);
}
ATF_REQUIRE_EQ(test_array::m_nblocks, 0);
ATF_REQUIRE(atf::utils::compare_file("my-output.txt", "Some output\n"));
}
ATF_REQUIRE_EQ(test_array::m_nblocks, 0);
}
ATF_TEST_CASE(auto_array_copy_ref);
ATF_TEST_CASE_HEAD(auto_array_copy_ref)
ATF_TEST_CASE_WITHOUT_HEAD(wait__save_stderr);
ATF_TEST_CASE_BODY(wait__save_stderr)
{
set_md_var("descr", "Tests the auto_array smart pointer class' copy "
"constructor through the auxiliary auto_array_ref object");
}
ATF_TEST_CASE_BODY(auto_array_copy_ref)
{
using atf::utils::auto_array;
const pid_t control = fork();
ATF_REQUIRE(control != -1);
if (control == 0)
fork_and_wait(123, "Some output\n", "save:my-output.txt");
else {
int status;
ATF_REQUIRE(waitpid(control, &status, 0) != -1);
ATF_REQUIRE(WIFEXITED(status));
ATF_REQUIRE_EQ(EXIT_SUCCESS, WEXITSTATUS(status));
ATF_REQUIRE_EQ(test_array::m_nblocks, 0);
{
auto_array< test_array > t1(new test_array[10]);
ATF_REQUIRE_EQ(test_array::m_nblocks, 1);
{
auto_array< test_array > t2 = test_array::do_copy(t1);
ATF_REQUIRE_EQ(test_array::m_nblocks, 1);
}
ATF_REQUIRE_EQ(test_array::m_nblocks, 0);
ATF_REQUIRE(atf::utils::compare_file("my-output.txt", "Some error\n"));
}
ATF_REQUIRE_EQ(test_array::m_nblocks, 0);
}
ATF_TEST_CASE(auto_array_get);
ATF_TEST_CASE_HEAD(auto_array_get)
{
set_md_var("descr", "Tests the auto_array smart pointer class' get "
"method");
}
ATF_TEST_CASE_BODY(auto_array_get)
{
using atf::utils::auto_array;
test_array* ta = new test_array[10];
auto_array< test_array > t(ta);
ATF_REQUIRE_EQ(t.get(), ta);
}
ATF_TEST_CASE(auto_array_release);
ATF_TEST_CASE_HEAD(auto_array_release)
{
set_md_var("descr", "Tests the auto_array smart pointer class' release "
"method");
}
ATF_TEST_CASE_BODY(auto_array_release)
{
using atf::utils::auto_array;
test_array* ta1 = new test_array[10];
{
auto_array< test_array > t(ta1);
ATF_REQUIRE_EQ(test_array::m_nblocks, 1);
test_array* ta2 = t.release();
ATF_REQUIRE_EQ(ta2, ta1);
ATF_REQUIRE_EQ(test_array::m_nblocks, 1);
}
ATF_REQUIRE_EQ(test_array::m_nblocks, 1);
delete [] ta1;
}
ATF_TEST_CASE(auto_array_reset);
ATF_TEST_CASE_HEAD(auto_array_reset)
{
set_md_var("descr", "Tests the auto_array smart pointer class' reset "
"method");
}
ATF_TEST_CASE_BODY(auto_array_reset)
{
using atf::utils::auto_array;
test_array* ta1 = new test_array[10];
test_array* ta2 = new test_array[10];
ATF_REQUIRE_EQ(test_array::m_nblocks, 2);
{
auto_array< test_array > t(ta1);
ATF_REQUIRE_EQ(test_array::m_nblocks, 2);
t.reset(ta2);
ATF_REQUIRE_EQ(test_array::m_nblocks, 1);
t.reset();
ATF_REQUIRE_EQ(test_array::m_nblocks, 0);
}
ATF_REQUIRE_EQ(test_array::m_nblocks, 0);
}
ATF_TEST_CASE(auto_array_assign);
ATF_TEST_CASE_HEAD(auto_array_assign)
{
set_md_var("descr", "Tests the auto_array smart pointer class' "
"assignment operator");
}
ATF_TEST_CASE_BODY(auto_array_assign)
{
using atf::utils::auto_array;
ATF_REQUIRE_EQ(test_array::m_nblocks, 0);
{
auto_array< test_array > t1(new test_array[10]);
ATF_REQUIRE_EQ(test_array::m_nblocks, 1);
{
auto_array< test_array > t2;
t2 = t1;
ATF_REQUIRE_EQ(test_array::m_nblocks, 1);
}
ATF_REQUIRE_EQ(test_array::m_nblocks, 0);
}
ATF_REQUIRE_EQ(test_array::m_nblocks, 0);
}
ATF_TEST_CASE(auto_array_assign_ref);
ATF_TEST_CASE_HEAD(auto_array_assign_ref)
{
set_md_var("descr", "Tests the auto_array smart pointer class' "
"assignment operator through the auxiliary auto_array_ref "
"object");
}
ATF_TEST_CASE_BODY(auto_array_assign_ref)
{
using atf::utils::auto_array;
ATF_REQUIRE_EQ(test_array::m_nblocks, 0);
{
auto_array< test_array > t1(new test_array[10]);
ATF_REQUIRE_EQ(test_array::m_nblocks, 1);
{
auto_array< test_array > t2;
t2 = test_array::do_copy(t1);
ATF_REQUIRE_EQ(test_array::m_nblocks, 1);
}
ATF_REQUIRE_EQ(test_array::m_nblocks, 0);
}
ATF_REQUIRE_EQ(test_array::m_nblocks, 0);
}
ATF_TEST_CASE(auto_array_access);
ATF_TEST_CASE_HEAD(auto_array_access)
{
set_md_var("descr", "Tests the auto_array smart pointer class' access "
"operator");
}
ATF_TEST_CASE_BODY(auto_array_access)
{
using atf::utils::auto_array;
auto_array< test_array > t(new test_array[10]);
for (int i = 0; i < 10; i++)
t[i].m_value = i * 2;
for (int i = 0; i < 10; i++)
ATF_REQUIRE_EQ(t[i].m_value, i * 2);
}
// ------------------------------------------------------------------------
@ -294,16 +444,43 @@ HEADER_TC(include, "atf-c++/utils.hpp");
ATF_INIT_TEST_CASES(tcs)
{
// Add the test for the "auto_array" class.
ATF_ADD_TEST_CASE(tcs, auto_array_scope);
ATF_ADD_TEST_CASE(tcs, auto_array_copy);
ATF_ADD_TEST_CASE(tcs, auto_array_copy_ref);
ATF_ADD_TEST_CASE(tcs, auto_array_get);
ATF_ADD_TEST_CASE(tcs, auto_array_release);
ATF_ADD_TEST_CASE(tcs, auto_array_reset);
ATF_ADD_TEST_CASE(tcs, auto_array_assign);
ATF_ADD_TEST_CASE(tcs, auto_array_assign_ref);
ATF_ADD_TEST_CASE(tcs, auto_array_access);
// Add the test for the free functions.
ATF_ADD_TEST_CASE(tcs, cat_file__empty);
ATF_ADD_TEST_CASE(tcs, cat_file__one_line);
ATF_ADD_TEST_CASE(tcs, cat_file__several_lines);
ATF_ADD_TEST_CASE(tcs, cat_file__no_newline_eof);
ATF_ADD_TEST_CASE(tcs, compare_file__empty__match);
ATF_ADD_TEST_CASE(tcs, compare_file__empty__not_match);
ATF_ADD_TEST_CASE(tcs, compare_file__short__match);
ATF_ADD_TEST_CASE(tcs, compare_file__short__not_match);
ATF_ADD_TEST_CASE(tcs, compare_file__long__match);
ATF_ADD_TEST_CASE(tcs, compare_file__long__not_match);
ATF_ADD_TEST_CASE(tcs, copy_file__empty);
ATF_ADD_TEST_CASE(tcs, copy_file__some_contents);
ATF_ADD_TEST_CASE(tcs, create_file);
ATF_ADD_TEST_CASE(tcs, file_exists);
ATF_ADD_TEST_CASE(tcs, fork);
ATF_ADD_TEST_CASE(tcs, grep_collection__set);
ATF_ADD_TEST_CASE(tcs, grep_collection__vector);
ATF_ADD_TEST_CASE(tcs, grep_file);
ATF_ADD_TEST_CASE(tcs, grep_string);
ATF_ADD_TEST_CASE(tcs, redirect__stdout);
ATF_ADD_TEST_CASE(tcs, redirect__stderr);
ATF_ADD_TEST_CASE(tcs, redirect__other);
ATF_ADD_TEST_CASE(tcs, wait__ok);
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);

View file

@ -32,5 +32,6 @@
#include <atf-c/error.h>
#include <atf-c/macros.h>
#include <atf-c/utils.h>
#endif /* !defined(ATF_C_H) */

View file

@ -26,14 +26,17 @@
.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd December 26, 2010
.Dd November 30, 2012
.Dt ATF-C-API 3
.Os
.Sh NAME
.Nm atf-c-api ,
.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 ,
@ -41,6 +44,8 @@
.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 ,
@ -72,7 +77,19 @@
.Nm atf_tc_fail ,
.Nm atf_tc_fail_nonfatal ,
.Nm atf_tc_pass ,
.Nm atf_tc_skip
.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
@ -80,6 +97,8 @@
.Fn ATF_CHECK_MSG "expression" "fail_msg_fmt" ...
.Fn ATF_CHECK_EQ "expression_1" "expression_2"
.Fn ATF_CHECK_EQ_MSG "expression_1" "expression_2" "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 "exp_errno" "bool_expression"
@ -87,6 +106,8 @@
.Fn ATF_REQUIRE_MSG "expression" "fail_msg_fmt" ...
.Fn ATF_REQUIRE_EQ "expression_1" "expression_2"
.Fn ATF_REQUIRE_EQ_MSG "expression_1" "expression_2" "fail_msg_fmt" ...
.Fn ATF_REQUIRE_MATCH "regexp" "string"
.Fn ATF_REQUIRE_MATCH_MSG "regexp" "string" "fail_msg_fmt" ...
.Fn ATF_REQUIRE_STREQ "string_1" "string_2"
.Fn ATF_REQUIRE_STREQ_MSG "string_1" "string_2" "fail_msg_fmt" ...
.Fn ATF_REQUIRE_ERRNO "exp_errno" "bool_expression"
@ -119,6 +140,67 @@
.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
The ATF
.Pp
@ -382,7 +464,7 @@ 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 now sense to continue the execution of a
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
@ -417,6 +499,16 @@ and
.Fn ATF_REQUIRE_EQ_MSG
take two expressions and fail if the two evaluated values are not equal.
.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
@ -433,6 +525,180 @@ 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 -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 -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 -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 -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 -offset indent
Checks if
.Fa file
exists.
.Ed
.Pp
.Ft pid_t
.Fo atf_utils_fork
.Fa "void"
.Fc
.Bd -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 -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 -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 -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 -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 -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 -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 EXAMPLES
The following shows a complete test program with a single test case that
validates the addition operator:

48
atf-c/atf-c.m4 Normal file
View file

@ -0,0 +1,48 @@
dnl
dnl Automated Testing Framework (atf)
dnl
dnl Copyright 2011 Google Inc.
dnl All rights reserved.
dnl
dnl Redistribution and use in source and binary forms, with or without
dnl modification, are permitted provided that the following conditions are
dnl met:
dnl
dnl * Redistributions of source code must retain the above copyright
dnl notice, this list of conditions and the following disclaimer.
dnl * Redistributions in binary form must reproduce the above copyright
dnl notice, this list of conditions and the following disclaimer in the
dnl documentation and/or other materials provided with the distribution.
dnl * Neither the name of Google Inc. nor the names of its contributors
dnl may be used to endorse or promote products derived from this software
dnl without specific prior written permission.
dnl
dnl THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
dnl "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
dnl LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
dnl A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
dnl OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
dnl SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
dnl LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
dnl DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
dnl THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
dnl (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
dnl OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dnl
dnl ATF_CHECK_C([version-spec])
dnl
dnl Checks if atf-c is present. If version-spec is provided, ensures that
dnl the installed version of atf-sh matches the required version. This
dnl argument must be something like '>= 0.14' and accepts any version
dnl specification supported by pkg-config.
dnl
dnl Defines and substitutes ATF_C_CFLAGS and ATF_C_LIBS with the compiler
dnl and linker flags need to build against atf-c.
AC_DEFUN([ATF_CHECK_C], [
spec="atf-c[]m4_default_nblank([ $1], [])"
_ATF_CHECK_ARG_WITH(
[PKG_CHECK_MODULES([ATF_C], [${spec}],
[found=yes found_atf_c=yes], [found=no])],
[required ${spec} not found])
])

11
atf-c/atf-c.pc.in Normal file
View file

@ -0,0 +1,11 @@
# ATF pkg-config file
cc=__CC__
includedir=__INCLUDEDIR__
libdir=__LIBDIR__
Name: atf-c
Description: Automated Testing Framework (C binding)
Version: __ATF_VERSION__
Cflags: -I${includedir}
Libs: -L${libdir} -latf-c

92
atf-c/atf-common.m4 Normal file
View file

@ -0,0 +1,92 @@
dnl
dnl Automated Testing Framework (atf)
dnl
dnl Copyright 2011 Google Inc.
dnl All rights reserved.
dnl
dnl Redistribution and use in source and binary forms, with or without
dnl modification, are permitted provided that the following conditions are
dnl met:
dnl
dnl * Redistributions of source code must retain the above copyright
dnl notice, this list of conditions and the following disclaimer.
dnl * Redistributions in binary form must reproduce the above copyright
dnl notice, this list of conditions and the following disclaimer in the
dnl documentation and/or other materials provided with the distribution.
dnl * Neither the name of Google Inc. nor the names of its contributors
dnl may be used to endorse or promote products derived from this software
dnl without specific prior written permission.
dnl
dnl THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
dnl "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
dnl LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
dnl A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
dnl OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
dnl SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
dnl LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
dnl DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
dnl THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
dnl (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
dnl OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dnl
dnl ATF_ARG_WITH
dnl
dnl Adds a --with-atf flag to the configure script that allows the user to
dnl enable or disable atf support.
dnl
dnl The ATF_CHECK_{C,CXX,SH} macros honor the flag defined herein if
dnl instantiated. If not instantiated, they will request the presence of
dnl the libraries unconditionally.
dnl
dnl Defines the WITH_ATF Automake conditional if ATF has been found by any
dnl of the ATF_CHECK_{C,CXX,SH} macros.
AC_DEFUN([ATF_ARG_WITH], [
m4_define([atf_arg_with_called], [yes])
m4_divert_text([DEFAULTS], [with_atf=auto])
AC_ARG_WITH([atf],
[AS_HELP_STRING([--with-atf=<yes|no|auto>],
[build atf-based test programs])],
[with_atf=${withval}], [with_atf=auto])
m4_divert_text([DEFAULTS], [
found_atf_c=no
found_atf_cxx=no
found_atf_sh=no
])
AM_CONDITIONAL([WITH_ATF], [test x"${found_atf_c}" = x"yes" -o \
x"${found_atf_cxx}" = x"yes" -o \
x"${found_atf_sh}" = x"yes"])
])
dnl _ATF_CHECK_ARG_WITH(check, error_message)
dnl
dnl Internal macro to execute a check conditional on the --with-atf flag
dnl and handle the result accordingly.
dnl
dnl 'check' specifies the piece of code to be run to detect the feature.
dnl This code must set the 'found' shell variable to yes or no depending
dnl on the raw result of the check.
AC_DEFUN([_ATF_CHECK_ARG_WITH], [
m4_ifdef([atf_arg_with_called], [
m4_fatal([ATF_ARG_WITH must be called after the ATF_CHECK_* checks])
])
m4_divert_text([DEFAULTS], [with_atf=yes])
if test x"${with_atf}" = x"no"; then
_found=no
else
$1
if test x"${with_atf}" = x"auto"; then
_found="${found}"
else
if test x"${found}" = x"yes"; then
_found=yes
else
AC_MSG_ERROR([$2])
fi
fi
fi
])

View file

@ -90,14 +90,10 @@ static
void
check_line(int fd, const char *exp)
{
atf_dynstr_t line;
atf_dynstr_init(&line);
ATF_CHECK(!read_line(fd, &line));
ATF_CHECK_MSG(atf_equal_dynstr_cstring(&line, exp),
"read: '%s', expected: '%s'",
atf_dynstr_cstring(&line), exp);
atf_dynstr_fini(&line);
char *line = atf_utils_readline(fd);
ATF_CHECK(line != NULL);
ATF_CHECK_STREQ_MSG(exp, line, "read: '%s', expected: '%s'", line, exp);
free(line);
}
/* ---------------------------------------------------------------------
@ -246,15 +242,15 @@ ATF_TC_BODY(build_c_o, tc)
{
init_and_run_h_tc(&ATF_TC_NAME(h_build_c_o_ok),
&ATF_TC_PACK_NAME(h_build_c_o_ok), "stdout", "stderr");
ATF_CHECK(grep_file("stdout", "-o test.o"));
ATF_CHECK(grep_file("stdout", "-c test.c"));
ATF_CHECK(atf_utils_grep_file("-o test.o", "stdout"));
ATF_CHECK(atf_utils_grep_file("-c test.c", "stdout"));
init_and_run_h_tc(&ATF_TC_NAME(h_build_c_o_fail),
&ATF_TC_PACK_NAME(h_build_c_o_fail), "stdout", "stderr");
ATF_CHECK(grep_file("stdout", "-o test.o"));
ATF_CHECK(grep_file("stdout", "-c test.c"));
ATF_CHECK(grep_file("stderr", "test.c"));
ATF_CHECK(grep_file("stderr", "UNDEFINED_SYMBOL"));
ATF_CHECK(atf_utils_grep_file("-o test.o", "stdout"));
ATF_CHECK(atf_utils_grep_file("-c test.c", "stdout"));
ATF_CHECK(atf_utils_grep_file("test.c", "stderr"));
ATF_CHECK(atf_utils_grep_file("UNDEFINED_SYMBOL", "stderr"));
}
ATF_TC(build_cpp);
@ -267,16 +263,16 @@ ATF_TC_BODY(build_cpp, tc)
{
init_and_run_h_tc(&ATF_TC_NAME(h_build_cpp_ok),
&ATF_TC_PACK_NAME(h_build_cpp_ok), "stdout", "stderr");
ATF_CHECK(grep_file("stdout", "-o.*test.p"));
ATF_CHECK(grep_file("stdout", "test.c"));
ATF_CHECK(grep_file("test.p", "foo bar"));
ATF_CHECK(atf_utils_grep_file("-o.*test.p", "stdout"));
ATF_CHECK(atf_utils_grep_file("test.c", "stdout"));
ATF_CHECK(atf_utils_grep_file("foo bar", "test.p"));
init_and_run_h_tc(&ATF_TC_NAME(h_build_cpp_fail),
&ATF_TC_PACK_NAME(h_build_cpp_fail), "stdout", "stderr");
ATF_CHECK(grep_file("stdout", "-o test.p"));
ATF_CHECK(grep_file("stdout", "test.c"));
ATF_CHECK(grep_file("stderr", "test.c"));
ATF_CHECK(grep_file("stderr", "non-existent.h"));
ATF_CHECK(atf_utils_grep_file("-o test.p", "stdout"));
ATF_CHECK(atf_utils_grep_file("test.c", "stdout"));
ATF_CHECK(atf_utils_grep_file("test.c", "stderr"));
ATF_CHECK(atf_utils_grep_file("non-existent.h", "stderr"));
}
ATF_TC(build_cxx_o);
@ -289,15 +285,15 @@ ATF_TC_BODY(build_cxx_o, tc)
{
init_and_run_h_tc(&ATF_TC_NAME(h_build_cxx_o_ok),
&ATF_TC_PACK_NAME(h_build_cxx_o_ok), "stdout", "stderr");
ATF_CHECK(grep_file("stdout", "-o test.o"));
ATF_CHECK(grep_file("stdout", "-c test.cpp"));
ATF_CHECK(atf_utils_grep_file("-o test.o", "stdout"));
ATF_CHECK(atf_utils_grep_file("-c test.cpp", "stdout"));
init_and_run_h_tc(&ATF_TC_NAME(h_build_cxx_o_fail),
&ATF_TC_PACK_NAME(h_build_cxx_o_fail), "stdout", "stderr");
ATF_CHECK(grep_file("stdout", "-o test.o"));
ATF_CHECK(grep_file("stdout", "-c test.cpp"));
ATF_CHECK(grep_file("stderr", "test.cpp"));
ATF_CHECK(grep_file("stderr", "UNDEFINED_SYMBOL"));
ATF_CHECK(atf_utils_grep_file("-o test.o", "stdout"));
ATF_CHECK(atf_utils_grep_file("-c test.cpp", "stdout"));
ATF_CHECK(atf_utils_grep_file("test.cpp", "stderr"));
ATF_CHECK(atf_utils_grep_file("UNDEFINED_SYMBOL", "stderr"));
}
ATF_TC(exec_array);

View file

@ -9,6 +9,5 @@ tp: list_test
tp: map_test
tp: process_test
tp: sanity_test
tp: test_helpers_test
tp: text_test
tp: user_test

View file

@ -9,6 +9,5 @@ atf_test_program{name="list_test"}
atf_test_program{name="map_test"}
atf_test_program{name="process_test"}
atf_test_program{name="sanity_test"}
atf_test_program{name="test_helpers_test"}
atf_test_program{name="text_test"}
atf_test_program{name="user_test"}

View file

@ -69,11 +69,6 @@ tests_atf_c_detail_PROGRAMS += atf-c/detail/fs_test
atf_c_detail_fs_test_SOURCES = atf-c/detail/fs_test.c
atf_c_detail_fs_test_LDADD = atf-c/detail/libtest_helpers.la libatf-c.la
tests_atf_c_detail_PROGRAMS += atf-c/detail/test_helpers_test
atf_c_detail_test_helpers_test_SOURCES = atf-c/detail/test_helpers_test.c
atf_c_detail_test_helpers_test_LDADD = atf-c/detail/libtest_helpers.la \
libatf-c.la
tests_atf_c_detail_PROGRAMS += atf-c/detail/list_test
atf_c_detail_list_test_SOURCES = atf-c/detail/list_test.c
atf_c_detail_list_test_LDADD = atf-c/detail/libtest_helpers.la libatf-c.la

View file

@ -95,12 +95,12 @@ check_file(const enum out_type type)
{
switch (type) {
case stdout_type:
ATF_CHECK(grep_file("stdout", "stdout: msg"));
ATF_CHECK(!grep_file("stdout", "stderr: msg"));
ATF_CHECK(atf_utils_grep_file("stdout: msg", "stdout"));
ATF_CHECK(!atf_utils_grep_file("stderr: msg", "stdout"));
break;
case stderr_type:
ATF_CHECK(grep_file("stderr", "stderr: msg"));
ATF_CHECK(!grep_file("stderr", "stdout: msg"));
ATF_CHECK(atf_utils_grep_file("stderr: msg", "stderr"));
ATF_CHECK(!atf_utils_grep_file("stdout: msg", "stderr"));
break;
default:
UNREACHABLE;
@ -110,7 +110,7 @@ check_file(const enum out_type type)
struct capture_stream {
struct base_stream m_base;
atf_dynstr_t m_msg;
char *m_msg;
};
#define CAPTURE_STREAM(type) \
{ .m_base = BASE_STREAM(capture_stream_init, \
@ -126,7 +126,7 @@ capture_stream_init(void *v)
s->m_base.m_sb_ptr = &s->m_base.m_sb;
RE(atf_process_stream_init_capture(&s->m_base.m_sb));
RE(atf_dynstr_init(&s->m_msg));
s->m_msg = NULL;
}
static
@ -137,10 +137,10 @@ capture_stream_process(void *v, atf_process_child_t *c)
switch (s->m_base.m_type) {
case stdout_type:
(void)read_line(atf_process_child_stdout(c), &s->m_msg);
s->m_msg = atf_utils_readline(atf_process_child_stdout(c));
break;
case stderr_type:
(void)read_line(atf_process_child_stderr(c), &s->m_msg);
s->m_msg = atf_utils_readline(atf_process_child_stderr(c));
break;
default:
UNREACHABLE;
@ -155,18 +155,18 @@ capture_stream_fini(void *v)
switch (s->m_base.m_type) {
case stdout_type:
ATF_CHECK(grep_string(&s->m_msg, "stdout: msg"));
ATF_CHECK(!grep_string(&s->m_msg, "stderr: msg"));
ATF_CHECK(atf_utils_grep_string("stdout: msg", s->m_msg));
ATF_CHECK(!atf_utils_grep_string("stderr: msg", s->m_msg));
break;
case stderr_type:
ATF_CHECK(!grep_string(&s->m_msg, "stdout: msg"));
ATF_CHECK(grep_string(&s->m_msg, "stderr: msg"));
ATF_CHECK(!atf_utils_grep_string("stdout: msg", s->m_msg));
ATF_CHECK(atf_utils_grep_string("stderr: msg", s->m_msg));
break;
default:
UNREACHABLE;
}
atf_dynstr_fini(&s->m_msg);
free(s->m_msg);
atf_process_stream_fini(&s->m_base.m_sb);
}
@ -881,16 +881,10 @@ static
void
check_line(int fd, const char *exp)
{
atf_dynstr_t line;
bool eof;
atf_dynstr_init(&line);
eof = read_line(fd, &line);
ATF_CHECK(!eof);
ATF_CHECK_MSG(atf_equal_dynstr_cstring(&line, exp),
"read: '%s', expected: '%s'",
atf_dynstr_cstring(&line), exp);
atf_dynstr_fini(&line);
char *line = atf_utils_readline(fd);
ATF_CHECK(line != NULL);
ATF_CHECK_STREQ_MSG(exp, line, "read: '%s', expected: '%s'", line, exp);
free(line);
}
ATF_TC(exec_failure);

View file

@ -53,21 +53,6 @@
enum type { inv, pre, post, unreachable };
static
bool
grep(const atf_dynstr_t *line, const char *text)
{
const char *l = atf_dynstr_cstring(line);
bool found;
found = false;
if (strstr(l, text) != NULL)
found = true;
return found;
}
struct test_data {
enum type m_type;
bool m_cond;
@ -109,9 +94,8 @@ do_test(enum type t, bool cond)
{
atf_process_child_t child;
atf_process_status_t status;
bool eof;
int nlines;
atf_dynstr_t lines[3];
char *lines[3];
{
atf_process_stream_t outsb, errsb;
@ -125,13 +109,9 @@ do_test(enum type t, bool cond)
}
nlines = 0;
eof = false;
do {
RE(atf_dynstr_init(&lines[nlines]));
if (!eof)
eof = read_line(atf_process_child_stderr(&child), &lines[nlines]);
while (nlines < 3 && (lines[nlines] =
atf_utils_readline(atf_process_child_stderr(&child))) != NULL)
nlines++;
} while (nlines < 3);
ATF_REQUIRE(nlines == 0 || nlines == 3);
RE(atf_process_child_wait(&child, &status));
@ -147,29 +127,29 @@ do_test(enum type t, bool cond)
if (!cond) {
switch (t) {
case inv:
ATF_REQUIRE(grep(&lines[0], "Invariant"));
ATF_REQUIRE(atf_utils_grep_string("Invariant", lines[0]));
break;
case pre:
ATF_REQUIRE(grep(&lines[0], "Precondition"));
ATF_REQUIRE(atf_utils_grep_string("Precondition", lines[0]));
break;
case post:
ATF_REQUIRE(grep(&lines[0], "Postcondition"));
ATF_REQUIRE(atf_utils_grep_string("Postcondition", lines[0]));
break;
case unreachable:
ATF_REQUIRE(grep(&lines[0], "Invariant"));
ATF_REQUIRE(atf_utils_grep_string("Invariant", lines[0]));
break;
}
ATF_REQUIRE(grep(&lines[0], __FILE__));
ATF_REQUIRE(grep(&lines[2], PACKAGE_BUGREPORT));
ATF_REQUIRE(atf_utils_grep_string(__FILE__, lines[0]));
ATF_REQUIRE(atf_utils_grep_string(PACKAGE_BUGREPORT, lines[2]));
}
while (nlines > 0) {
nlines--;
atf_dynstr_fini(&lines[nlines]);
free(lines[nlines]);
}
}

View file

@ -30,7 +30,6 @@
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <regex.h>
#include <unistd.h>
#include "atf-c/build.h"
@ -106,72 +105,6 @@ get_process_helpers_path(const atf_tc_t *tc, const bool is_detail,
is_detail ? "" : "detail/"));
}
bool
grep_string(const atf_dynstr_t *str, const char *regex)
{
int res;
regex_t preg;
printf("Looking for '%s' in '%s'\n", regex, atf_dynstr_cstring(str));
ATF_REQUIRE(regcomp(&preg, regex, REG_EXTENDED) == 0);
res = regexec(&preg, atf_dynstr_cstring(str), 0, NULL, 0);
ATF_REQUIRE(res == 0 || res == REG_NOMATCH);
regfree(&preg);
return res == 0;
}
bool
grep_file(const char *file, const char *regex, ...)
{
bool done, found;
int fd;
va_list ap;
atf_dynstr_t formatted;
va_start(ap, regex);
RE(atf_dynstr_init_ap(&formatted, regex, ap));
va_end(ap);
done = false;
found = false;
ATF_REQUIRE((fd = open(file, O_RDONLY)) != -1);
do {
atf_dynstr_t line;
RE(atf_dynstr_init(&line));
done = read_line(fd, &line);
if (!done)
found = grep_string(&line, atf_dynstr_cstring(&formatted));
atf_dynstr_fini(&line);
} while (!found && !done);
close(fd);
atf_dynstr_fini(&formatted);
return found;
}
bool
read_line(int fd, atf_dynstr_t *dest)
{
char ch;
ssize_t cnt;
while ((cnt = read(fd, &ch, sizeof(ch))) == sizeof(ch) &&
ch != '\n') {
const atf_error_t err = atf_dynstr_append_fmt(dest, "%c", ch);
ATF_REQUIRE(!atf_is_error(err));
}
ATF_REQUIRE(cnt != -1);
return cnt == 0;
}
struct run_h_tc_data {
atf_tc_t *m_tc;
const char *m_resname;

View file

@ -81,7 +81,5 @@ void build_check_c_o(const atf_tc_t *, const char *, const char *, const bool);
void header_check(const char *);
void get_process_helpers_path(const atf_tc_t *, const bool,
struct atf_fs_path *);
bool grep_string(const struct atf_dynstr *, const char *);
bool grep_file(const char *, const char *, ...);
bool read_line(int, struct atf_dynstr *);
void run_h_tc(atf_tc_t *, const char *, const char *, const char *);

View file

@ -1,185 +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 <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <atf-c.h>
#include "dynstr.h"
#include "test_helpers.h"
/* ---------------------------------------------------------------------
* Test cases for the free functions.
* --------------------------------------------------------------------- */
/* TODO: Add checks for build_check_c_o and the macros defined in the
* header file. */
ATF_TC(grep_string);
ATF_TC_HEAD(grep_string, tc)
{
atf_tc_set_md_var(tc, "descr", "Tests the grep_string helper "
"function");
}
ATF_TC_BODY(grep_string, tc)
{
atf_dynstr_t str;
atf_dynstr_init_fmt(&str, "a string - aaaabbbb");
ATF_CHECK(grep_string(&str, "a string"));
ATF_CHECK(grep_string(&str, "^a string"));
ATF_CHECK(grep_string(&str, "aaaabbbb$"));
ATF_CHECK(grep_string(&str, "aa.*bb"));
ATF_CHECK(!grep_string(&str, "foo"));
ATF_CHECK(!grep_string(&str, "bar"));
ATF_CHECK(!grep_string(&str, "aaaaa"));
atf_dynstr_fini(&str);
}
ATF_TC(grep_file);
ATF_TC_HEAD(grep_file, tc)
{
atf_tc_set_md_var(tc, "descr", "Tests the grep_file helper function");
}
ATF_TC_BODY(grep_file, tc)
{
FILE *f;
f = fopen("test.txt", "w");
ATF_CHECK(f != NULL);
fprintf(f, "line1\n");
fprintf(f, "the second line\n");
fprintf(f, "aaaabbbb\n");
fclose(f);
ATF_CHECK(grep_file("test.txt", "line1"));
ATF_CHECK(grep_file("test.txt", "line%d", 1));
ATF_CHECK(grep_file("test.txt", "second line"));
ATF_CHECK(grep_file("test.txt", "aa.*bb"));
ATF_CHECK(!grep_file("test.txt", "foo"));
ATF_CHECK(!grep_file("test.txt", "bar"));
ATF_CHECK(!grep_file("test.txt", "aaaaa"));
}
ATF_TC(read_line);
ATF_TC_HEAD(read_line, tc)
{
atf_tc_set_md_var(tc, "descr", "Tests the read_line function");
}
ATF_TC_BODY(read_line, tc)
{
const char *l1 = "First line with % formatting % characters %";
const char *l2 = "Second line; much longer than the first one";
const char *l3 = "Last line, without terminator";
{
FILE *f;
f = fopen("test", "w");
ATF_REQUIRE(f != NULL);
fclose(f);
}
{
int fd;
atf_dynstr_t dest;
bool eof;
fd = open("test", O_RDONLY);
ATF_REQUIRE(fd != -1);
RE(atf_dynstr_init(&dest));
eof = read_line(fd, &dest);
ATF_REQUIRE(eof);
atf_dynstr_fini(&dest);
}
{
FILE *f;
f = fopen("test", "w");
ATF_REQUIRE(f != NULL);
fprintf(f, "%s\n", l1);
fprintf(f, "%s\n", l2);
fprintf(f, "%s", l3);
fclose(f);
}
{
int fd;
atf_dynstr_t dest;
bool eof;
fd = open("test", O_RDONLY);
ATF_REQUIRE(fd != -1);
RE(atf_dynstr_init(&dest));
eof = read_line(fd, &dest);
ATF_REQUIRE(!eof);
printf("1st line: >%s<\n", atf_dynstr_cstring(&dest));
ATF_REQUIRE(atf_equal_dynstr_cstring(&dest, l1));
atf_dynstr_fini(&dest);
RE(atf_dynstr_init(&dest));
eof = read_line(fd, &dest);
ATF_REQUIRE(!eof);
printf("2nd line: >%s<\n", atf_dynstr_cstring(&dest));
ATF_REQUIRE(atf_equal_dynstr_cstring(&dest, l2));
atf_dynstr_fini(&dest);
RE(atf_dynstr_init(&dest));
eof = read_line(fd, &dest);
ATF_REQUIRE(eof);
printf("3rd line: >%s<\n", atf_dynstr_cstring(&dest));
ATF_REQUIRE(atf_equal_dynstr_cstring(&dest, l3));
atf_dynstr_fini(&dest);
close(fd);
}
}
/* ---------------------------------------------------------------------
* Main.
* --------------------------------------------------------------------- */
ATF_TP_ADD_TCS(tp)
{
/* Add the tests for the free functions. */
ATF_TP_ADD_TC(tp, grep_string);
ATF_TP_ADD_TC(tp, grep_file);
ATF_TP_ADD_TC(tp, read_line);
return atf_no_error();
}

View file

@ -30,6 +30,8 @@
#if !defined(ATF_C_MACROS_H)
#define ATF_C_MACROS_H
#include <string.h>
#include <atf-c/defs.h>
#include <atf-c/error.h>
#include <atf-c/tc.h>
@ -78,7 +80,7 @@
#define ATF_TC_HEAD(tc, tcptr) \
static \
void \
atfu_ ## tc ## _head(atf_tc_t *tcptr)
atfu_ ## tc ## _head(atf_tc_t *tcptr ATF_DEFS_ATTRIBUTE_UNUSED)
#define ATF_TC_HEAD_NAME(tc) \
(atfu_ ## tc ## _head)
@ -179,6 +181,24 @@
ATF_CHECK_MSG(strcmp(x, y) == 0, "%s != %s (%s != %s): " fmt, \
#x, #y, x, y, ##__VA_ARGS__)
#define ATF_REQUIRE_MATCH(regexp, string) \
ATF_REQUIRE_MSG(atf_utils_grep_string("%s", string, regexp), \
"'%s' not matched in '%s'", regexp, string);
#define ATF_CHECK_MATCH(regexp, string) \
ATF_CHECK_MSG(atf_utils_grep_string("%s", string, regexp), \
"'%s' not matched in '%s'", regexp, string);
#define ATF_REQUIRE_MATCH_MSG(regexp, string, fmt, ...) \
ATF_REQUIRE_MSG(atf_utils_grep_string("%s", string, regexp), \
"'%s' not matched in '%s': " fmt, regexp, string, \
##__VA_ARGS__);
#define ATF_CHECK_MATCH_MSG(regexp, string, fmt, ...) \
ATF_CHECK_MSG(atf_utils_grep_string("%s", string, regexp), \
"'%s' not matched in '%s': " fmt, regexp, string, \
##__VA_ARGS__);
#define ATF_CHECK_ERRNO(exp_errno, bool_expr) \
atf_tc_check_errno(__FILE__, __LINE__, exp_errno, #bool_expr, bool_expr)

View file

@ -125,6 +125,11 @@ init_and_run_h_tc(const char *name, void (*head)(atf_tc_t *),
#define H_CHECK_STREQ(id, v1, v2) \
H_DEF(check_streq_ ## id, ATF_CHECK_STREQ(v1, v2))
#define H_CHECK_MATCH_HEAD_NAME(id) ATF_TC_HEAD_NAME(h_check_match_ ## id)
#define H_CHECK_MATCH_BODY_NAME(id) ATF_TC_BODY_NAME(h_check_match_ ## id)
#define H_CHECK_MATCH(id, v1, v2) \
H_DEF(check_match_ ## id, ATF_CHECK_MATCH(v1, v2))
#define H_CHECK_EQ_MSG_HEAD_NAME(id) \
ATF_TC_HEAD_NAME(h_check_eq_msg_ ## id)
#define H_CHECK_EQ_MSG_BODY_NAME(id) \
@ -139,6 +144,13 @@ init_and_run_h_tc(const char *name, void (*head)(atf_tc_t *),
#define H_CHECK_STREQ_MSG(id, v1, v2, msg) \
H_DEF(check_streq_msg_ ## id, ATF_CHECK_STREQ_MSG(v1, v2, msg))
#define H_CHECK_MATCH_MSG_HEAD_NAME(id) \
ATF_TC_HEAD_NAME(h_check_match_msg_ ## id)
#define H_CHECK_MATCH_MSG_BODY_NAME(id) \
ATF_TC_BODY_NAME(h_check_match_msg_ ## id)
#define H_CHECK_MATCH_MSG(id, v1, v2, msg) \
H_DEF(check_match_msg_ ## id, ATF_CHECK_MATCH_MSG(v1, v2, msg))
#define H_CHECK_ERRNO_HEAD_NAME(id) ATF_TC_HEAD_NAME(h_check_errno_ ## id)
#define H_CHECK_ERRNO_BODY_NAME(id) ATF_TC_BODY_NAME(h_check_errno_ ## id)
#define H_CHECK_ERRNO(id, exp_errno, bool_expr) \
@ -164,6 +176,11 @@ init_and_run_h_tc(const char *name, void (*head)(atf_tc_t *),
#define H_REQUIRE_STREQ(id, v1, v2) \
H_DEF(require_streq_ ## id, ATF_REQUIRE_STREQ(v1, v2))
#define H_REQUIRE_MATCH_HEAD_NAME(id) ATF_TC_HEAD_NAME(h_require_match_ ## id)
#define H_REQUIRE_MATCH_BODY_NAME(id) ATF_TC_BODY_NAME(h_require_match_ ## id)
#define H_REQUIRE_MATCH(id, v1, v2) \
H_DEF(require_match_ ## id, ATF_REQUIRE_MATCH(v1, v2))
#define H_REQUIRE_EQ_MSG_HEAD_NAME(id) \
ATF_TC_HEAD_NAME(h_require_eq_msg_ ## id)
#define H_REQUIRE_EQ_MSG_BODY_NAME(id) \
@ -178,6 +195,13 @@ init_and_run_h_tc(const char *name, void (*head)(atf_tc_t *),
#define H_REQUIRE_STREQ_MSG(id, v1, v2, msg) \
H_DEF(require_streq_msg_ ## id, ATF_REQUIRE_STREQ_MSG(v1, v2, msg))
#define H_REQUIRE_MATCH_MSG_HEAD_NAME(id) \
ATF_TC_HEAD_NAME(h_require_match_msg_ ## id)
#define H_REQUIRE_MATCH_MSG_BODY_NAME(id) \
ATF_TC_BODY_NAME(h_require_match_msg_ ## id)
#define H_REQUIRE_MATCH_MSG(id, v1, v2, msg) \
H_DEF(require_match_msg_ ## id, ATF_REQUIRE_MATCH_MSG(v1, v2, msg))
#define H_REQUIRE_ERRNO_HEAD_NAME(id) ATF_TC_HEAD_NAME(h_require_errno_ ## id)
#define H_REQUIRE_ERRNO_BODY_NAME(id) ATF_TC_BODY_NAME(h_require_errno_ ## id)
#define H_REQUIRE_ERRNO(id, exp_errno, bool_expr) \
@ -240,11 +264,11 @@ ATF_TC_BODY(check_errno, tc)
ATF_REQUIRE(exists("after"));
if (t->ok) {
ATF_REQUIRE(grep_file("result", "^passed"));
ATF_REQUIRE(atf_utils_grep_file("^passed", "result"));
} else {
ATF_REQUIRE(grep_file("result", "^failed"));
ATF_REQUIRE(grep_file("error", "macros_test.c:[0-9]+: %s$",
t->exp_regex));
ATF_REQUIRE(atf_utils_grep_file("^failed", "result"));
ATF_REQUIRE(atf_utils_grep_file(
"macros_test.c:[0-9]+: %s$", "error", t->exp_regex));
}
ATF_REQUIRE(unlink("before") != -1);
@ -282,11 +306,12 @@ ATF_TC_BODY(require_errno, tc)
ATF_REQUIRE(exists("before"));
if (t->ok) {
ATF_REQUIRE(grep_file("result", "^passed"));
ATF_REQUIRE(atf_utils_grep_file("^passed", "result"));
ATF_REQUIRE(exists("after"));
} else {
ATF_REQUIRE(grep_file("result", "^failed: .*macros_test.c:[0-9]+: "
"%s$", t->exp_regex));
ATF_REQUIRE(atf_utils_grep_file(
"^failed: .*macros_test.c:[0-9]+: %s$", "result",
t->exp_regex));
ATF_REQUIRE(!exists("after"));
}
@ -340,11 +365,11 @@ ATF_TC_BODY(check, tc)
ATF_REQUIRE(exists("after"));
if (t->ok) {
ATF_REQUIRE(grep_file("result", "^passed"));
ATF_REQUIRE(atf_utils_grep_file("^passed", "result"));
} else {
ATF_REQUIRE(grep_file("result", "^failed"));
ATF_REQUIRE(grep_file("error", "Check failed: .*"
"macros_test.c:[0-9]+: %s$", t->msg));
ATF_REQUIRE(atf_utils_grep_file("^failed", "result"));
ATF_REQUIRE(atf_utils_grep_file("Check failed: .*"
"macros_test.c:[0-9]+: %s$", "error", t->msg));
}
ATF_REQUIRE(unlink("before") != -1);
@ -381,11 +406,11 @@ do_check_eq_tests(const struct check_eq_test *tests)
ATF_CHECK(exists("after"));
if (t->ok) {
ATF_REQUIRE(grep_file("result", "^passed"));
ATF_REQUIRE(atf_utils_grep_file("^passed", "result"));
} else {
ATF_REQUIRE(grep_file("result", "^failed"));
ATF_CHECK(grep_file("error", "Check failed: .*"
"macros_test.c:[0-9]+: %s$", t->msg));
ATF_REQUIRE(atf_utils_grep_file("^failed", "result"));
ATF_CHECK(atf_utils_grep_file("Check failed: .*"
"macros_test.c:[0-9]+: %s$", "error", t->msg));
}
ATF_CHECK(unlink("before") != -1);
@ -442,8 +467,8 @@ H_CHECK_STREQ_MSG(2_1, "2", "1", "2 does not match 1");
H_CHECK_STREQ_MSG(2_2, "2", "2", "2 does not match 2");
#define CHECK_STREQ_VAR1 "5"
#define CHECK_STREQ_VAR2 "9"
const const char *check_streq_var1 = CHECK_STREQ_VAR1;
const const char *check_streq_var2 = CHECK_STREQ_VAR2;
const char *check_streq_var1 = CHECK_STREQ_VAR1;
const char *check_streq_var2 = CHECK_STREQ_VAR2;
H_CHECK_STREQ(vars, check_streq_var1, check_streq_var2);
ATF_TC(check_streq);
@ -484,6 +509,40 @@ ATF_TC_BODY(check_streq, tc)
do_check_eq_tests(tests);
}
/* ---------------------------------------------------------------------
* Test cases for the ATF_CHECK_MATCH and ATF_CHECK_MATCH_MSG macros.
* --------------------------------------------------------------------- */
H_CHECK_MATCH(yes, "hello [a-z]+", "abc hello world");
H_CHECK_MATCH(no, "hello [a-z]+", "abc hello WORLD");
H_CHECK_MATCH_MSG(yes, "hello [a-z]+", "abc hello world", "lowercase");
H_CHECK_MATCH_MSG(no, "hello [a-z]+", "abc hello WORLD", "uppercase");
ATF_TC(check_match);
ATF_TC_HEAD(check_match, tc)
{
atf_tc_set_md_var(tc, "descr", "Tests the ATF_CHECK_MATCH and "
"ATF_CHECK_MATCH_MSG macros");
}
ATF_TC_BODY(check_match, tc)
{
struct check_eq_test tests[] = {
{ H_CHECK_MATCH_HEAD_NAME(yes), H_CHECK_MATCH_BODY_NAME(yes),
"hello [a-z]+", "abc hello world", "", true },
{ H_CHECK_MATCH_HEAD_NAME(no), H_CHECK_MATCH_BODY_NAME(no),
"hello [a-z]+", "abc hello WORLD",
"'hello \\[a-z\\]\\+' not matched in 'abc hello WORLD'", false },
{ H_CHECK_MATCH_MSG_HEAD_NAME(yes), H_CHECK_MATCH_MSG_BODY_NAME(yes),
"hello [a-z]+", "abc hello world", "", true },
{ H_CHECK_MATCH_MSG_HEAD_NAME(no), H_CHECK_MATCH_MSG_BODY_NAME(no),
"hello [a-z]+", "abc hello WORLD",
"'hello \\[a-z\\]\\+' not matched in 'abc hello WORLD': uppercase",
false },
{ NULL, NULL, 0, 0, "", false }
};
do_check_eq_tests(tests);
}
/* ---------------------------------------------------------------------
* Test cases for the ATF_REQUIRE and ATF_REQUIRE_MSG macros.
* --------------------------------------------------------------------- */
@ -526,11 +585,11 @@ ATF_TC_BODY(require, tc)
ATF_REQUIRE(exists("before"));
if (t->ok) {
ATF_REQUIRE(grep_file("result", "^passed"));
ATF_REQUIRE(atf_utils_grep_file("^passed", "result"));
ATF_REQUIRE(exists("after"));
} else {
ATF_REQUIRE(grep_file("result", "^failed: .*macros_test.c:[0-9]+: "
"%s$", t->msg));
ATF_REQUIRE(atf_utils_grep_file(
"^failed: .*macros_test.c:[0-9]+: %s$", "result", t->msg));
ATF_REQUIRE(!exists("after"));
}
@ -567,11 +626,11 @@ do_require_eq_tests(const struct require_eq_test *tests)
ATF_REQUIRE(exists("before"));
if (t->ok) {
ATF_REQUIRE(grep_file("result", "^passed"));
ATF_REQUIRE(atf_utils_grep_file("^passed", "result"));
ATF_REQUIRE(exists("after"));
} else {
ATF_REQUIRE(grep_file("result", "^failed: .*macros_test.c"
":[0-9]+: %s$", t->msg));
ATF_REQUIRE(atf_utils_grep_file("^failed: .*macros_test.c"
":[0-9]+: %s$", "result", t->msg));
ATF_REQUIRE(!exists("after"));
}
@ -630,8 +689,8 @@ H_REQUIRE_STREQ_MSG(2_1, "2", "1", "2 does not match 1");
H_REQUIRE_STREQ_MSG(2_2, "2", "2", "2 does not match 2");
#define REQUIRE_STREQ_VAR1 "5"
#define REQUIRE_STREQ_VAR2 "9"
const const char *require_streq_var1 = REQUIRE_STREQ_VAR1;
const const char *require_streq_var2 = REQUIRE_STREQ_VAR2;
const char *require_streq_var1 = REQUIRE_STREQ_VAR1;
const char *require_streq_var2 = REQUIRE_STREQ_VAR2;
H_REQUIRE_STREQ(vars, require_streq_var1, require_streq_var2);
ATF_TC(require_streq);
@ -672,6 +731,41 @@ ATF_TC_BODY(require_streq, tc)
do_require_eq_tests(tests);
}
/* ---------------------------------------------------------------------
* Test cases for the ATF_REQUIRE_MATCH and ATF_REQUIRE_MATCH_MSG macros.
* --------------------------------------------------------------------- */
H_REQUIRE_MATCH(yes, "hello [a-z]+", "abc hello world");
H_REQUIRE_MATCH(no, "hello [a-z]+", "abc hello WORLD");
H_REQUIRE_MATCH_MSG(yes, "hello [a-z]+", "abc hello world", "lowercase");
H_REQUIRE_MATCH_MSG(no, "hello [a-z]+", "abc hello WORLD", "uppercase");
ATF_TC(require_match);
ATF_TC_HEAD(require_match, tc)
{
atf_tc_set_md_var(tc, "descr", "Tests the ATF_REQUIRE_MATCH and "
"ATF_REQUIRE_MATCH_MSG macros");
}
ATF_TC_BODY(require_match, tc)
{
struct require_eq_test tests[] = {
{ H_REQUIRE_MATCH_HEAD_NAME(yes), H_REQUIRE_MATCH_BODY_NAME(yes),
"hello [a-z]+", "abc hello world", "", true },
{ H_REQUIRE_MATCH_HEAD_NAME(no), H_REQUIRE_MATCH_BODY_NAME(no),
"hello [a-z]+", "abc hello WORLD",
"'hello \\[a-z\\]\\+' not matched in 'abc hello WORLD'", false },
{ H_REQUIRE_MATCH_MSG_HEAD_NAME(yes),
H_REQUIRE_MATCH_MSG_BODY_NAME(yes),
"hello [a-z]+", "abc hello world", "", true },
{ H_REQUIRE_MATCH_MSG_HEAD_NAME(no), H_REQUIRE_MATCH_MSG_BODY_NAME(no),
"hello [a-z]+", "abc hello WORLD",
"'hello \\[a-z\\]\\+' not matched in 'abc hello WORLD': uppercase",
false },
{ NULL, NULL, 0, 0, "", false }
};
do_require_eq_tests(tests);
}
/* ---------------------------------------------------------------------
* Miscellaneous test cases covering several macros.
* --------------------------------------------------------------------- */
@ -728,12 +822,12 @@ ATF_TC_BODY(msg_embedded_fmt, tc)
if (t->fatal) {
bool matched =
grep_file("result", "^failed: .*macros_test.c:[0-9]+: "
"%s$", t->msg);
atf_utils_grep_file(
"^failed: .*macros_test.c:[0-9]+: %s$", "result", t->msg);
ATF_CHECK_MSG(matched, "couldn't find error string in result");
} else {
bool matched = grep_file("error", "Check failed: .*"
"macros_test.c:[0-9]+: %s$", t->msg);
bool matched = atf_utils_grep_file("Check failed: .*"
"macros_test.c:[0-9]+: %s$", "error", t->msg);
ATF_CHECK_MSG(matched, "couldn't find error string in output");
}
}
@ -765,11 +859,13 @@ ATF_TP_ADD_TCS(tp)
ATF_TP_ADD_TC(tp, check_eq);
ATF_TP_ADD_TC(tp, check_streq);
ATF_TP_ADD_TC(tp, check_errno);
ATF_TP_ADD_TC(tp, check_match);
ATF_TP_ADD_TC(tp, require);
ATF_TP_ADD_TC(tp, require_eq);
ATF_TP_ADD_TC(tp, require_streq);
ATF_TP_ADD_TC(tp, require_errno);
ATF_TP_ADD_TC(tp, require_match);
ATF_TP_ADD_TC(tp, msg_embedded_fmt);

View file

@ -27,10 +27,221 @@
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdlib.h>
#include "atf-c/utils.h"
#include <sys/stat.h>
#include <sys/wait.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <regex.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <atf-c.h>
#include "detail/dynstr.h"
/** Searches for a regexp in a string.
*
* \param regex The regexp to look for.
* \param str The string in which to look for the expression.
*
* \return True if there is a match; false otherwise. */
static
bool
grep_string(const char *regex, const char *str)
{
int res;
regex_t preg;
printf("Looking for '%s' in '%s'\n", regex, str);
ATF_REQUIRE(regcomp(&preg, regex, REG_EXTENDED) == 0);
res = regexec(&preg, str, 0, NULL, 0);
ATF_REQUIRE(res == 0 || res == REG_NOMATCH);
regfree(&preg);
return res == 0;
}
/** Prints the contents of a file to stdout.
*
* \param name The name of the file to be printed.
* \param prefix An string to be prepended to every line of the printed
* file. */
void
atf_utils_cat_file(const char *name, const char *prefix)
{
const int fd = open(name, O_RDONLY);
ATF_REQUIRE_MSG(fd != -1, "Cannot open %s", name);
char buffer[1024];
ssize_t count;
bool continued = false;
while ((count = read(fd, buffer, sizeof(buffer) - 1)) > 0) {
buffer[count] = '\0';
if (!continued)
printf("%s", prefix);
char *iter = buffer;
char *end;
while ((end = strchr(iter, '\n')) != NULL) {
*end = '\0';
printf("%s\n", iter);
iter = end + 1;
if (iter != buffer + count)
printf("%s", prefix);
else
continued = false;
}
if (iter < buffer + count) {
printf("%s", iter);
continued = true;
}
}
ATF_REQUIRE(count == 0);
}
/** Compares a file against the given golden contents.
*
* \param name Name of the file to be compared.
* \param contents Expected contents of the file.
*
* \return True if the file matches the contents; false otherwise. */
bool
atf_utils_compare_file(const char *name, const char *contents)
{
const int fd = open(name, O_RDONLY);
ATF_REQUIRE_MSG(fd != -1, "Cannot open %s", name);
const char *pos = contents;
ssize_t remaining = strlen(contents);
char buffer[1024];
ssize_t count;
while ((count = read(fd, buffer, sizeof(buffer))) > 0 &&
count <= remaining) {
if (memcmp(pos, buffer, count) != 0) {
close(fd);
return false;
}
remaining -= count;
pos += count;
}
close(fd);
return count == 0 && remaining == 0;
}
/** Copies a file.
*
* \param source Path to the source file.
* \param destination Path to the destination file. */
void
atf_utils_copy_file(const char *source, const char *destination)
{
const int input = open(source, O_RDONLY);
ATF_REQUIRE_MSG(input != -1, "Failed to open source file during "
"copy (%s)", source);
const int output = open(destination, O_WRONLY | O_CREAT | O_TRUNC, 0777);
ATF_REQUIRE_MSG(output != -1, "Failed to open destination file during "
"copy (%s)", destination);
char buffer[1024];
ssize_t length;
while ((length = read(input, buffer, sizeof(buffer))) > 0)
ATF_REQUIRE_MSG(write(output, buffer, length) == length,
"Failed to write to %s during copy", destination);
ATF_REQUIRE_MSG(length != -1, "Failed to read from %s during copy", source);
struct stat sb;
ATF_REQUIRE_MSG(fstat(input, &sb) != -1,
"Failed to stat source file %s during copy", source);
ATF_REQUIRE_MSG(fchmod(output, sb.st_mode) != -1,
"Failed to chmod destination file %s during copy",
destination);
close(output);
close(input);
}
/** Creates a file.
*
* \param name Name of the file to create.
* \param contents Text to write into the created file.
* \param ... Positional parameters to the contents. */
void
atf_utils_create_file(const char *name, const char *contents, ...)
{
va_list ap;
atf_dynstr_t formatted;
atf_error_t error;
va_start(ap, contents);
error = atf_dynstr_init_ap(&formatted, contents, ap);
va_end(ap);
ATF_REQUIRE(!atf_is_error(error));
const int fd = open(name, O_WRONLY | O_CREAT | O_TRUNC, 0644);
ATF_REQUIRE_MSG(fd != -1, "Cannot create file %s", name);
ATF_REQUIRE(write(fd, atf_dynstr_cstring(&formatted),
atf_dynstr_length(&formatted)) != -1);
close(fd);
atf_dynstr_fini(&formatted);
}
/** Checks if a file exists.
*
* \param path Location of the file to check for.
*
* \return True if the file exists, false otherwise. */
bool
atf_utils_file_exists(const char *path)
{
const int ret = access(path, F_OK);
if (ret == -1) {
if (errno != ENOENT)
atf_tc_fail("Failed to check the existence of %s: %s", path,
strerror(errno));
else
return false;
} else
return true;
}
/** Spawns a subprocess and redirects its output to files.
*
* Use the atf_utils_wait() function to wait for the completion of the spawned
* subprocess and validate its exit conditions.
*
* \return 0 in the new child; the PID of the new child in the parent. Does
* not return in error conditions. */
pid_t
atf_utils_fork(void)
{
const pid_t pid = fork();
if (pid == -1)
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");
}
return pid;
}
/** Frees an dynamically-allocated "argv" array.
*
* \param argv A dynamically-allocated array of dynamically-allocated
* strings. */
void
atf_utils_free_charpp(char **argv)
{
@ -41,3 +252,164 @@ atf_utils_free_charpp(char **argv)
free(argv);
}
/** Searches for a regexp in a file.
*
* \param regex The regexp to look for.
* \param file The file in which to look for the expression.
* \param ... Positional parameters to the regex.
*
* \return True if there is a match; false otherwise. */
bool
atf_utils_grep_file(const char *regex, const char *file, ...)
{
int fd;
va_list ap;
atf_dynstr_t formatted;
atf_error_t error;
va_start(ap, file);
error = atf_dynstr_init_ap(&formatted, regex, ap);
va_end(ap);
ATF_REQUIRE(!atf_is_error(error));
ATF_REQUIRE((fd = open(file, O_RDONLY)) != -1);
bool found = false;
char *line = NULL;
while (!found && (line = atf_utils_readline(fd)) != NULL) {
found = grep_string(atf_dynstr_cstring(&formatted), line);
free(line);
}
close(fd);
atf_dynstr_fini(&formatted);
return found;
}
/** Searches for a regexp in a string.
*
* \param regex The regexp to look for.
* \param str The string in which to look for the expression.
* \param ... Positional parameters to the regex.
*
* \return True if there is a match; false otherwise. */
bool
atf_utils_grep_string(const char *regex, const char *str, ...)
{
bool res;
va_list ap;
atf_dynstr_t formatted;
atf_error_t error;
va_start(ap, str);
error = atf_dynstr_init_ap(&formatted, regex, ap);
va_end(ap);
ATF_REQUIRE(!atf_is_error(error));
res = grep_string(atf_dynstr_cstring(&formatted), str);
atf_dynstr_fini(&formatted);
return res;
}
/** Reads a line of arbitrary length.
*
* \param fd The descriptor from which to read the line.
*
* \return A pointer to the read line, which must be released with free(), or
* NULL if there was nothing to read from the file. */
char *
atf_utils_readline(const int fd)
{
char ch;
ssize_t cnt;
atf_dynstr_t temp;
atf_error_t error;
error = atf_dynstr_init(&temp);
ATF_REQUIRE(!atf_is_error(error));
while ((cnt = read(fd, &ch, sizeof(ch))) == sizeof(ch) &&
ch != '\n') {
error = atf_dynstr_append_fmt(&temp, "%c", ch);
ATF_REQUIRE(!atf_is_error(error));
}
ATF_REQUIRE(cnt != -1);
if (cnt == 0 && atf_dynstr_length(&temp) == 0) {
atf_dynstr_fini(&temp);
return NULL;
} else
return atf_dynstr_fini_disown(&temp);
}
/** Redirects a file descriptor to a file.
*
* \param target_fd The file descriptor to be replaced.
* \param name The name of the file to direct the descriptor to.
*
* \pre Should only be called from the process spawned by fork_for_testing
* because this exits uncontrolledly.
* \post Terminates execution if the redirection fails. */
void
atf_utils_redirect(const int target_fd, const char *name)
{
if (target_fd == STDOUT_FILENO)
fflush(stdout);
else if (target_fd == STDERR_FILENO)
fflush(stderr);
const int new_fd = open(name, O_WRONLY | O_CREAT | O_TRUNC, 0644);
if (new_fd == -1)
err(EXIT_FAILURE, "Cannot create %s", name);
if (new_fd != target_fd) {
if (dup2(new_fd, target_fd) == -1)
err(EXIT_FAILURE, "Cannot redirect to fd %d", target_fd);
}
close(new_fd);
}
/** Waits for a subprocess and validates its exit condition.
*
* \param pid The process to be waited for. Must have been started by
* testutils_fork().
* \param exitstatus Expected exit status.
* \param expout Expected contents of stdout.
* \param experr Expected contents of stderr. */
void
atf_utils_wait(const pid_t pid, const int exitstatus, const char *expout,
const char *experr)
{
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_REQUIRE(WIFEXITED(status));
ATF_REQUIRE_EQ(exitstatus, WEXITSTATUS(status));
const char *save_prefix = "save:";
const size_t save_prefix_length = strlen(save_prefix);
if (strlen(expout) > save_prefix_length &&
strncmp(expout, save_prefix, save_prefix_length) == 0) {
atf_utils_copy_file("atf_utils_fork_out.txt",
expout + save_prefix_length);
} else {
ATF_REQUIRE(atf_utils_compare_file("atf_utils_fork_out.txt", expout));
}
if (strlen(experr) > save_prefix_length &&
strncmp(experr, save_prefix, save_prefix_length) == 0) {
atf_utils_copy_file("atf_utils_fork_err.txt",
experr + save_prefix_length);
} else {
ATF_REQUIRE(atf_utils_compare_file("atf_utils_fork_err.txt", experr));
}
ATF_REQUIRE(unlink("atf_utils_fork_out.txt") != -1);
ATF_REQUIRE(unlink("atf_utils_fork_err.txt") != -1);
}

View file

@ -30,6 +30,25 @@
#if !defined(ATF_C_UTILS_H)
#define ATF_C_UTILS_H
#include <stdbool.h>
#include <unistd.h>
#include <atf-c/defs.h>
void atf_utils_cat_file(const char *, const char *);
bool atf_utils_compare_file(const char *, const char *);
void atf_utils_copy_file(const char *, const char *);
void atf_utils_create_file(const char *, const char *, ...)
ATF_DEFS_ATTRIBUTE_FORMAT_PRINTF(2, 3);
bool atf_utils_file_exists(const char *);
pid_t atf_utils_fork(void);
void atf_utils_free_charpp(char **);
bool atf_utils_grep_file(const char *, const char *, ...)
ATF_DEFS_ATTRIBUTE_FORMAT_PRINTF(1, 3);
bool atf_utils_grep_string(const char *, const char *, ...)
ATF_DEFS_ATTRIBUTE_FORMAT_PRINTF(1, 3);
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 */

View file

@ -27,8 +27,15 @@
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/stat.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <atf-c.h>
@ -36,8 +43,218 @@
#include "detail/test_helpers.h"
ATF_TC_WITHOUT_HEAD(free_charpp_empty);
ATF_TC_BODY(free_charpp_empty, tc)
/** Reads the contents of a file into a buffer.
*
* Up to buflen-1 characters are read into buffer. If this function returns,
* the contents read into the buffer are guaranteed to be nul-terminated.
* Note, however, that if the file contains any nul characters itself,
* comparing it "as a string" will not work.
*
* \param path The file to be read, which must exist.
* \param buffer Buffer into which to store the file contents.
* \param buflen Size of the target buffer.
*
* \return The count of bytes read. */
static ssize_t
read_file(const char *path, void *const buffer, const size_t buflen)
{
const int fd = open(path, O_RDONLY);
ATF_REQUIRE_MSG(fd != -1, "Cannot open %s", path);
const ssize_t length = read(fd, buffer, buflen - 1);
close(fd);
ATF_REQUIRE(length != -1);
((char *)buffer)[length] = '\0';
return length;
}
ATF_TC_WITHOUT_HEAD(cat_file__empty);
ATF_TC_BODY(cat_file__empty, tc)
{
atf_utils_create_file("file.txt", "%s", "");
atf_utils_redirect(STDOUT_FILENO, "captured.txt");
atf_utils_cat_file("file.txt", "PREFIX");
fflush(stdout);
close(STDOUT_FILENO);
char buffer[1024];
read_file("captured.txt", buffer, sizeof(buffer));
ATF_REQUIRE_STREQ("", buffer);
}
ATF_TC_WITHOUT_HEAD(cat_file__one_line);
ATF_TC_BODY(cat_file__one_line, tc)
{
atf_utils_create_file("file.txt", "This is a single line\n");
atf_utils_redirect(STDOUT_FILENO, "captured.txt");
atf_utils_cat_file("file.txt", "PREFIX");
fflush(stdout);
close(STDOUT_FILENO);
char buffer[1024];
read_file("captured.txt", buffer, sizeof(buffer));
ATF_REQUIRE_STREQ("PREFIXThis is a single line\n", buffer);
}
ATF_TC_WITHOUT_HEAD(cat_file__several_lines);
ATF_TC_BODY(cat_file__several_lines, tc)
{
atf_utils_create_file("file.txt", "First\nSecond line\nAnd third\n");
atf_utils_redirect(STDOUT_FILENO, "captured.txt");
atf_utils_cat_file("file.txt", ">");
fflush(stdout);
close(STDOUT_FILENO);
char buffer[1024];
read_file("captured.txt", buffer, sizeof(buffer));
ATF_REQUIRE_STREQ(">First\n>Second line\n>And third\n", buffer);
}
ATF_TC_WITHOUT_HEAD(cat_file__no_newline_eof);
ATF_TC_BODY(cat_file__no_newline_eof, tc)
{
atf_utils_create_file("file.txt", "Foo\n bar baz");
atf_utils_redirect(STDOUT_FILENO, "captured.txt");
atf_utils_cat_file("file.txt", "PREFIX");
fflush(stdout);
close(STDOUT_FILENO);
char buffer[1024];
read_file("captured.txt", buffer, sizeof(buffer));
ATF_REQUIRE_STREQ("PREFIXFoo\nPREFIX bar baz", buffer);
}
ATF_TC_WITHOUT_HEAD(compare_file__empty__match);
ATF_TC_BODY(compare_file__empty__match, tc)
{
atf_utils_create_file("test.txt", "%s", "");
ATF_REQUIRE(atf_utils_compare_file("test.txt", ""));
}
ATF_TC_WITHOUT_HEAD(compare_file__empty__not_match);
ATF_TC_BODY(compare_file__empty__not_match, tc)
{
atf_utils_create_file("test.txt", "%s", "");
ATF_REQUIRE(!atf_utils_compare_file("test.txt", "\n"));
ATF_REQUIRE(!atf_utils_compare_file("test.txt", "foo"));
ATF_REQUIRE(!atf_utils_compare_file("test.txt", " "));
}
ATF_TC_WITHOUT_HEAD(compare_file__short__match);
ATF_TC_BODY(compare_file__short__match, tc)
{
atf_utils_create_file("test.txt", "this is a short file");
ATF_REQUIRE(atf_utils_compare_file("test.txt", "this is a short file"));
}
ATF_TC_WITHOUT_HEAD(compare_file__short__not_match);
ATF_TC_BODY(compare_file__short__not_match, tc)
{
atf_utils_create_file("test.txt", "this is a short file");
ATF_REQUIRE(!atf_utils_compare_file("test.txt", ""));
ATF_REQUIRE(!atf_utils_compare_file("test.txt", "\n"));
ATF_REQUIRE(!atf_utils_compare_file("test.txt", "this is a Short file"));
ATF_REQUIRE(!atf_utils_compare_file("test.txt", "this is a short fil"));
ATF_REQUIRE(!atf_utils_compare_file("test.txt", "this is a short file "));
}
ATF_TC_WITHOUT_HEAD(compare_file__long__match);
ATF_TC_BODY(compare_file__long__match, tc)
{
char long_contents[3456];
size_t i = 0;
for (; i < sizeof(long_contents) - 1; i++)
long_contents[i] = '0' + (i % 10);
long_contents[i] = '\0';
atf_utils_create_file("test.txt", "%s", long_contents);
ATF_REQUIRE(atf_utils_compare_file("test.txt", long_contents));
}
ATF_TC_WITHOUT_HEAD(compare_file__long__not_match);
ATF_TC_BODY(compare_file__long__not_match, tc)
{
char long_contents[3456];
size_t i = 0;
for (; i < sizeof(long_contents) - 1; i++)
long_contents[i] = '0' + (i % 10);
long_contents[i] = '\0';
atf_utils_create_file("test.txt", "%s", long_contents);
ATF_REQUIRE(!atf_utils_compare_file("test.txt", ""));
ATF_REQUIRE(!atf_utils_compare_file("test.txt", "\n"));
ATF_REQUIRE(!atf_utils_compare_file("test.txt", "0123456789"));
long_contents[i - 1] = 'Z';
ATF_REQUIRE(!atf_utils_compare_file("test.txt", long_contents));
}
ATF_TC_WITHOUT_HEAD(copy_file__empty);
ATF_TC_BODY(copy_file__empty, tc)
{
atf_utils_create_file("src.txt", "%s", "");
ATF_REQUIRE(chmod("src.txt", 0520) != -1);
atf_utils_copy_file("src.txt", "dest.txt");
ATF_REQUIRE(atf_utils_compare_file("dest.txt", ""));
struct stat sb;
ATF_REQUIRE(stat("dest.txt", &sb) != -1);
ATF_REQUIRE_EQ(0520, sb.st_mode & 0xfff);
}
ATF_TC_WITHOUT_HEAD(copy_file__some_contents);
ATF_TC_BODY(copy_file__some_contents, tc)
{
atf_utils_create_file("src.txt", "This is a\ntest file\n");
atf_utils_copy_file("src.txt", "dest.txt");
ATF_REQUIRE(atf_utils_compare_file("dest.txt", "This is a\ntest file\n"));
}
ATF_TC_WITHOUT_HEAD(create_file);
ATF_TC_BODY(create_file, tc)
{
atf_utils_create_file("test.txt", "This is a test with %d", 12345);
char buffer[128];
read_file("test.txt", buffer, sizeof(buffer));
ATF_REQUIRE_STREQ("This is a test with 12345", buffer);
}
ATF_TC_WITHOUT_HEAD(file_exists);
ATF_TC_BODY(file_exists, tc)
{
atf_utils_create_file("test.txt", "foo");
ATF_REQUIRE( atf_utils_file_exists("test.txt"));
ATF_REQUIRE( atf_utils_file_exists("./test.txt"));
ATF_REQUIRE(!atf_utils_file_exists("./test.tx"));
ATF_REQUIRE(!atf_utils_file_exists("test.txt2"));
}
ATF_TC_WITHOUT_HEAD(fork);
ATF_TC_BODY(fork, tc)
{
fprintf(stdout, "Should not get into child\n");
fprintf(stderr, "Should not get into child\n");
pid_t pid = atf_utils_fork();
if (pid == 0) {
fprintf(stdout, "Child stdout\n");
fprintf(stderr, "Child stderr\n");
exit(EXIT_SUCCESS);
}
int status;
ATF_REQUIRE(waitpid(pid, &status, 0) != -1);
ATF_REQUIRE(WIFEXITED(status));
ATF_REQUIRE_EQ(EXIT_SUCCESS, WEXITSTATUS(status));
char buffer[1024];
read_file("atf_utils_fork_out.txt", buffer, sizeof(buffer));
ATF_REQUIRE_STREQ("Child stdout\n", buffer);
read_file("atf_utils_fork_err.txt", buffer, sizeof(buffer));
ATF_REQUIRE_STREQ("Child stderr\n", buffer);
}
ATF_TC_WITHOUT_HEAD(free_charpp__empty);
ATF_TC_BODY(free_charpp__empty, tc)
{
char **array = malloc(sizeof(char *) * 1);
array[0] = NULL;
@ -45,8 +262,8 @@ ATF_TC_BODY(free_charpp_empty, tc)
atf_utils_free_charpp(array);
}
ATF_TC_WITHOUT_HEAD(free_charpp_some);
ATF_TC_BODY(free_charpp_some, tc)
ATF_TC_WITHOUT_HEAD(free_charpp__some);
ATF_TC_BODY(free_charpp__some, tc)
{
char **array = malloc(sizeof(char *) * 4);
array[0] = strdup("first");
@ -57,12 +274,263 @@ ATF_TC_BODY(free_charpp_some, tc)
atf_utils_free_charpp(array);
}
ATF_TC_WITHOUT_HEAD(grep_file);
ATF_TC_BODY(grep_file, tc)
{
atf_utils_create_file("test.txt", "line1\nthe second line\naaaabbbb\n");
ATF_CHECK(atf_utils_grep_file("line1", "test.txt"));
ATF_CHECK(atf_utils_grep_file("line%d", "test.txt", 1));
ATF_CHECK(atf_utils_grep_file("second line", "test.txt"));
ATF_CHECK(atf_utils_grep_file("aa.*bb", "test.txt"));
ATF_CHECK(!atf_utils_grep_file("foo", "test.txt"));
ATF_CHECK(!atf_utils_grep_file("bar", "test.txt"));
ATF_CHECK(!atf_utils_grep_file("aaaaa", "test.txt"));
}
ATF_TC_WITHOUT_HEAD(grep_string);
ATF_TC_BODY(grep_string, tc)
{
const char *str = "a string - aaaabbbb";
ATF_CHECK(atf_utils_grep_string("a string", str));
ATF_CHECK(atf_utils_grep_string("^a string", str));
ATF_CHECK(atf_utils_grep_string("aaaabbbb$", str));
ATF_CHECK(atf_utils_grep_string("a%s*bb", str, "a."));
ATF_CHECK(!atf_utils_grep_string("foo", str));
ATF_CHECK(!atf_utils_grep_string("bar", str));
ATF_CHECK(!atf_utils_grep_string("aaaaa", str));
}
ATF_TC_WITHOUT_HEAD(readline__none);
ATF_TC_BODY(readline__none, tc)
{
atf_utils_create_file("empty.txt", "%s", "");
const int fd = open("empty.txt", O_RDONLY);
ATF_REQUIRE(fd != -1);
ATF_REQUIRE(atf_utils_readline(fd) == NULL);
close(fd);
}
ATF_TC_WITHOUT_HEAD(readline__some);
ATF_TC_BODY(readline__some, tc)
{
const char *l1 = "First line with % formatting % characters %";
const char *l2 = "Second line; much longer than the first one";
const char *l3 = "Last line, without terminator";
atf_utils_create_file("test.txt", "%s\n%s\n%s", l1, l2, l3);
const int fd = open("test.txt", O_RDONLY);
ATF_REQUIRE(fd != -1);
char *line;
line = atf_utils_readline(fd);
ATF_REQUIRE_STREQ(l1, line);
free(line);
line = atf_utils_readline(fd);
ATF_REQUIRE_STREQ(l2, line);
free(line);
line = atf_utils_readline(fd);
ATF_REQUIRE_STREQ(l3, line);
free(line);
close(fd);
}
ATF_TC_WITHOUT_HEAD(redirect__stdout);
ATF_TC_BODY(redirect__stdout, tc)
{
printf("Buffer this");
atf_utils_redirect(STDOUT_FILENO, "captured.txt");
printf("The printed message");
fflush(stdout);
char buffer[1024];
read_file("captured.txt", buffer, sizeof(buffer));
ATF_REQUIRE_STREQ("The printed message", buffer);
}
ATF_TC_WITHOUT_HEAD(redirect__stderr);
ATF_TC_BODY(redirect__stderr, tc)
{
fprintf(stderr, "Buffer this");
atf_utils_redirect(STDERR_FILENO, "captured.txt");
fprintf(stderr, "The printed message");
fflush(stderr);
char buffer[1024];
read_file("captured.txt", buffer, sizeof(buffer));
ATF_REQUIRE_STREQ("The printed message", buffer);
}
ATF_TC_WITHOUT_HEAD(redirect__other);
ATF_TC_BODY(redirect__other, tc)
{
const char *message = "Foo bar\nbaz\n";
atf_utils_redirect(15, "captured.txt");
ATF_REQUIRE(write(15, message, strlen(message)) != -1);
close(15);
char buffer[1024];
read_file("captured.txt", buffer, sizeof(buffer));
ATF_REQUIRE_STREQ(message, buffer);
}
static void
fork_and_wait(const int exitstatus, const char* expout, const char* experr)
{
const pid_t pid = atf_utils_fork();
if (pid == 0) {
fprintf(stdout, "Some output\n");
fprintf(stderr, "Some error\n");
exit(123);
}
atf_utils_wait(pid, exitstatus, expout, experr);
exit(EXIT_SUCCESS);
}
ATF_TC_WITHOUT_HEAD(wait__ok);
ATF_TC_BODY(wait__ok, tc)
{
const pid_t control = fork();
ATF_REQUIRE(control != -1);
if (control == 0)
fork_and_wait(123, "Some output\n", "Some error\n");
else {
int status;
ATF_REQUIRE(waitpid(control, &status, 0) != -1);
ATF_REQUIRE(WIFEXITED(status));
ATF_REQUIRE_EQ(EXIT_SUCCESS, WEXITSTATUS(status));
}
}
ATF_TC_WITHOUT_HEAD(wait__invalid_exitstatus);
ATF_TC_BODY(wait__invalid_exitstatus, tc)
{
const pid_t control = fork();
ATF_REQUIRE(control != -1);
if (control == 0)
fork_and_wait(120, "Some output\n", "Some error\n");
else {
int status;
ATF_REQUIRE(waitpid(control, &status, 0) != -1);
ATF_REQUIRE(WIFEXITED(status));
ATF_REQUIRE_EQ(EXIT_FAILURE, WEXITSTATUS(status));
}
}
ATF_TC_WITHOUT_HEAD(wait__invalid_stdout);
ATF_TC_BODY(wait__invalid_stdout, tc)
{
const pid_t control = fork();
ATF_REQUIRE(control != -1);
if (control == 0)
fork_and_wait(123, "Some output foo\n", "Some error\n");
else {
int status;
ATF_REQUIRE(waitpid(control, &status, 0) != -1);
ATF_REQUIRE(WIFEXITED(status));
ATF_REQUIRE_EQ(EXIT_FAILURE, WEXITSTATUS(status));
}
}
ATF_TC_WITHOUT_HEAD(wait__invalid_stderr);
ATF_TC_BODY(wait__invalid_stderr, tc)
{
const pid_t control = fork();
ATF_REQUIRE(control != -1);
if (control == 0)
fork_and_wait(123, "Some output\n", "Some error foo\n");
else {
int status;
ATF_REQUIRE(waitpid(control, &status, 0) != -1);
ATF_REQUIRE(WIFEXITED(status));
ATF_REQUIRE_EQ(EXIT_FAILURE, WEXITSTATUS(status));
}
}
ATF_TC_WITHOUT_HEAD(wait__save_stdout);
ATF_TC_BODY(wait__save_stdout, tc)
{
const pid_t control = fork();
ATF_REQUIRE(control != -1);
if (control == 0)
fork_and_wait(123, "save:my-output.txt", "Some error\n");
else {
int status;
ATF_REQUIRE(waitpid(control, &status, 0) != -1);
ATF_REQUIRE(WIFEXITED(status));
ATF_REQUIRE_EQ(EXIT_SUCCESS, WEXITSTATUS(status));
ATF_REQUIRE(atf_utils_compare_file("my-output.txt", "Some output\n"));
}
}
ATF_TC_WITHOUT_HEAD(wait__save_stderr);
ATF_TC_BODY(wait__save_stderr, tc)
{
const pid_t control = fork();
ATF_REQUIRE(control != -1);
if (control == 0)
fork_and_wait(123, "Some output\n", "save:my-output.txt");
else {
int status;
ATF_REQUIRE(waitpid(control, &status, 0) != -1);
ATF_REQUIRE(WIFEXITED(status));
ATF_REQUIRE_EQ(EXIT_SUCCESS, WEXITSTATUS(status));
ATF_REQUIRE(atf_utils_compare_file("my-output.txt", "Some error\n"));
}
}
HEADER_TC(include, "atf-c/utils.h");
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, free_charpp_empty);
ATF_TP_ADD_TC(tp, free_charpp_some);
ATF_TP_ADD_TC(tp, cat_file__empty);
ATF_TP_ADD_TC(tp, cat_file__one_line);
ATF_TP_ADD_TC(tp, cat_file__several_lines);
ATF_TP_ADD_TC(tp, cat_file__no_newline_eof);
ATF_TP_ADD_TC(tp, compare_file__empty__match);
ATF_TP_ADD_TC(tp, compare_file__empty__not_match);
ATF_TP_ADD_TC(tp, compare_file__short__match);
ATF_TP_ADD_TC(tp, compare_file__short__not_match);
ATF_TP_ADD_TC(tp, compare_file__long__match);
ATF_TP_ADD_TC(tp, compare_file__long__not_match);
ATF_TP_ADD_TC(tp, copy_file__empty);
ATF_TP_ADD_TC(tp, copy_file__some_contents);
ATF_TP_ADD_TC(tp, create_file);
ATF_TP_ADD_TC(tp, file_exists);
ATF_TP_ADD_TC(tp, fork);
ATF_TP_ADD_TC(tp, free_charpp__empty);
ATF_TP_ADD_TC(tp, free_charpp__some);
ATF_TP_ADD_TC(tp, grep_file);
ATF_TP_ADD_TC(tp, grep_string);
ATF_TP_ADD_TC(tp, readline__none);
ATF_TP_ADD_TC(tp, readline__some);
ATF_TP_ADD_TC(tp, redirect__stdout);
ATF_TP_ADD_TC(tp, redirect__stderr);
ATF_TP_ADD_TC(tp, redirect__other);
ATF_TP_ADD_TC(tp, wait__ok);
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);

View file

@ -31,6 +31,7 @@ extern "C" {
#include <sys/time.h>
}
#include <cctype>
#include <cstdlib>
#include <fstream>
#include <iomanip>
@ -381,7 +382,6 @@ public:
class xml_writer : public writer {
ostream_ptr m_os;
size_t m_curtp, m_ntps;
std::string m_tcname, m_tpname;
static
@ -395,17 +395,24 @@ class xml_writer : public writer {
std::string
elemval(const std::string& str)
{
std::string ostr;
std::ostringstream buf;
for (std::string::const_iterator iter = str.begin();
iter != str.end(); iter++) {
switch (*iter) {
case '&': ostr += "&amp;"; break;
case '<': ostr += "&lt;"; break;
case '>': ostr += "&gt;"; break;
default: ostr += *iter;
const int character = static_cast< unsigned char >(*iter);
if (character == '&') {
buf << "&amp;";
} else if (character == '<') {
buf << "&lt;";
} else if (character == '>') {
buf << "&gt;";
} else if (std::isalnum(character) || std::ispunct(character) ||
std::isspace(character)) {
buf << static_cast< char >(character);
} else {
buf << "&amp;#" << character << ";";
}
}
return ostr;
return buf.str();
}
void

View file

@ -44,6 +44,7 @@ extern "C" {
#include <cstdlib>
#include <cstring>
#include "atf-c++/detail/auto_array.hpp"
#include "atf-c++/detail/process.hpp"
#include "atf-c++/detail/sanity.hpp"
@ -200,7 +201,7 @@ retry_unmount:
impl::temp_dir::temp_dir(const atf::fs::path& p)
{
atf::utils::auto_array< char > buf(new char[p.str().length() + 1]);
atf::auto_array< char > buf(new char[p.str().length() + 1]);
std::strcpy(buf.get(), p.c_str());
if (::mkdtemp(buf.get()) == NULL)
throw system_error(IMPL_NAME "::temp_dir::temp_dir(" +

View file

@ -41,9 +41,9 @@ extern "C" {
#include "../atf-c/error.h"
}
#include "../atf-c++/detail/auto_array.hpp"
#include "../atf-c++/detail/exceptions.hpp"
#include "../atf-c++/detail/sanity.hpp"
#include "../atf-c++/utils.hpp"
#include "io.hpp"
@ -290,7 +290,7 @@ size_t
impl::muxer::read_one(const size_t index, const int fd, std::string& accum,
const bool report_errors)
{
atf::utils::auto_array< char > buffer(new char[m_bufsize]);
atf::auto_array< char > buffer(new char[m_bufsize]);
const size_t nbytes = safe_read(fd, buffer.get(), m_bufsize - 1,
report_errors);
INV(nbytes < m_bufsize);
@ -319,7 +319,7 @@ impl::muxer::read_one(const size_t index, const int fd, std::string& accum,
void
impl::muxer::mux(volatile const bool& terminate)
{
atf::utils::auto_array< struct pollfd > poll_fds(new struct pollfd[m_nfds]);
atf::auto_array< struct pollfd > poll_fds(new struct pollfd[m_nfds]);
for (size_t i = 0; i < m_nfds; i++) {
poll_fds[i].fd = m_fds[i];
poll_fds[i].events = POLLIN;

View file

@ -36,7 +36,8 @@
#include "fs.hpp"
#include "../atf-c++/utils.hpp"
#include "../atf-c++/detail/auto_array.hpp"
#include "../atf-c++/noncopyable.hpp"
namespace atf {
namespace atf_run {
@ -253,8 +254,7 @@ private:
//! However, it is not copyable to avoid introducing inconsistences with
//! the on-disk file and the in-memory buffers.
//!
class systembuf :
public std::streambuf, atf::utils::noncopyable
class systembuf : public std::streambuf, atf::noncopyable
{
public:
typedef int handle_type;
@ -374,14 +374,8 @@ protected:
//! this happens, the buffer eventually empties and the system blocks
//! until the writer generates some data.
//!
class pistream :
public std::istream, utils::noncopyable
class pistream : public std::istream, noncopyable
{
//!
//! \brief The file handle managed by this stream.
//!
int m_fd;
//!
//! \brief The systembuf object used to manage this stream's data.
//!
@ -406,12 +400,12 @@ public:
// The "muxer" class.
// ------------------------------------------------------------------------
class muxer : utils::noncopyable {
class muxer : noncopyable {
const int* m_fds;
const size_t m_nfds;
const size_t m_bufsize;
atf::utils::auto_array< std::string > m_buffers;
atf::auto_array< std::string > m_buffers;
protected:
virtual void line_callback(const size_t, const std::string&) = 0;

View file

@ -36,7 +36,7 @@ extern "C" {
#include <memory>
#include "atf-c++/utils.hpp"
#include "atf-c++/noncopyable.hpp"
namespace atf {
namespace atf_run {
@ -47,7 +47,7 @@ class signal_programmer;
// The "timer" class.
// ------------------------------------------------------------------------
class timer : utils::noncopyable {
class timer : noncopyable {
struct impl;
std::auto_ptr< impl > m_pimpl;

View file

@ -49,9 +49,9 @@ extern "C" {
#include "atf-c++/check.hpp"
#include "atf-c++/config.hpp"
#include "atf-c++/utils.hpp"
#include "atf-c++/detail/application.hpp"
#include "atf-c++/detail/auto_array.hpp"
#include "atf-c++/detail/exceptions.hpp"
#include "atf-c++/detail/fs.hpp"
#include "atf-c++/detail/process.hpp"
@ -116,7 +116,7 @@ public:
std::ostream(NULL),
m_fd(-1)
{
atf::utils::auto_array< char > buf(new char[p.str().length() + 1]);
atf::auto_array< char > buf(new char[p.str().length() + 1]);
std::strcpy(buf.get(), p.c_str());
m_fd = ::mkstemp(buf.get());

View file

@ -211,10 +211,10 @@ 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. Look for a
# nicer solution...
# 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)
Darwin|FreeBSD|Linux)
h_pass "printf '\a\b\f\n\r\t\v'" -o inline:"\a\b\f\n\r\t\v"
;;
*)
@ -331,10 +331,10 @@ 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. Look for a
# nicer solution...
# 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)
Darwin|FreeBSD|Linux)
h_pass "printf '\a\b\f\n\r\t\v' 1>&2" -e inline:"\a\b\f\n\r\t\v"
;;
*)

53
atf-sh/atf-sh.m4 Normal file
View file

@ -0,0 +1,53 @@
dnl
dnl Automated Testing Framework (atf)
dnl
dnl Copyright 2011 Google Inc.
dnl All rights reserved.
dnl
dnl Redistribution and use in source and binary forms, with or without
dnl modification, are permitted provided that the following conditions are
dnl met:
dnl
dnl * Redistributions of source code must retain the above copyright
dnl notice, this list of conditions and the following disclaimer.
dnl * Redistributions in binary form must reproduce the above copyright
dnl notice, this list of conditions and the following disclaimer in the
dnl documentation and/or other materials provided with the distribution.
dnl * Neither the name of Google Inc. nor the names of its contributors
dnl may be used to endorse or promote products derived from this software
dnl without specific prior written permission.
dnl
dnl THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
dnl "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
dnl LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
dnl A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
dnl OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
dnl SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
dnl LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
dnl DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
dnl THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
dnl (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
dnl OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dnl
dnl ATF_CHECK_SH([version-spec])
dnl
dnl Checks if atf-sh is present. If version-spec is provided, ensures that
dnl the installed version of atf-sh matches the required version. This
dnl argument must be something like '>= 0.14' and accepts any version
dnl specification supported by pkg-config.
dnl
dnl Defines and substitutes ATF_SH with the full path to the atf-sh interpreter.
AC_DEFUN([ATF_CHECK_SH], [
spec="atf-sh[]m4_default_nblank([ $1], [])"
_ATF_CHECK_ARG_WITH(
[AC_MSG_CHECKING([for ${spec}])
PKG_CHECK_EXISTS([${spec}], [found=yes], [found=no])
if test "${found}" = yes; then
ATF_SH="$(${PKG_CONFIG} --variable=interpreter atf-sh)"
AC_SUBST([ATF_SH], [${ATF_SH}])
found_atf_sh=yes
fi
AC_MSG_RESULT([${ATF_SH}])],
[required ${spec} not found])
])

8
atf-sh/atf-sh.pc.in Normal file
View file

@ -0,0 +1,8 @@
# ATF pkg-config file
exec_prefix=__EXEC_PREFIX__
interpreter=${exec_prefix}/bin/atf-sh
Name: atf-sh
Description: Automated Testing Framework (POSIX shell binding)
Version: __ATF_VERSION__

View file

@ -54,7 +54,7 @@ atf_test_case expout_mismatch
expout_mismatch_head()
{
atf_set "descr" "Verifies that atf_check prints a diff of the" \
"stdout and the expected stdout if the two do no" \
"stdout and the expected stdout if the two do not" \
"match"
}
expout_mismatch_body()
@ -79,7 +79,7 @@ atf_test_case experr_mismatch
experr_mismatch_head()
{
atf_set "descr" "Verifies that atf_check prints a diff of the" \
"stderr and the expected stderr if the two do no" \
"stderr and the expected stderr if the two do not" \
"match"
}
experr_mismatch_body()

122
bootstrap/Makefile.am.inc Normal file
View file

@ -0,0 +1,122 @@
#
# 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.
#
check_PROGRAMS = bootstrap/h_app_empty
bootstrap_h_app_empty_SOURCES = bootstrap/h_app_empty.cpp
bootstrap_h_app_empty_LDADD = $(ATF_CXX_LIBS)
check_PROGRAMS += bootstrap/h_app_opts_args
bootstrap_h_app_opts_args_SOURCES = bootstrap/h_app_opts_args.cpp
bootstrap_h_app_opts_args_LDADD = $(ATF_CXX_LIBS)
check_PROGRAMS += bootstrap/h_tp_basic_c
bootstrap_h_tp_basic_c_SOURCES = bootstrap/h_tp_basic_c.c
bootstrap_h_tp_basic_c_LDADD = libatf-c.la
check_PROGRAMS += bootstrap/h_tp_basic_cpp
bootstrap_h_tp_basic_cpp_SOURCES = bootstrap/h_tp_basic_cpp.cpp
bootstrap_h_tp_basic_cpp_LDADD = $(ATF_CXX_LIBS)
check_SCRIPTS = bootstrap/h_tp_basic_sh
CLEANFILES += bootstrap/h_tp_basic_sh
EXTRA_DIST += bootstrap/h_tp_basic_sh.sh
bootstrap/h_tp_basic_sh: $(srcdir)/bootstrap/h_tp_basic_sh.sh
test -d bootstrap || mkdir -p bootstrap
@src=$(srcdir)/bootstrap/h_tp_basic_sh.sh; dst=$@; $(BUILD_SH_TP)
check_SCRIPTS += bootstrap/h_tp_atf_check_sh
CLEANFILES += bootstrap/h_tp_atf_check_sh
EXTRA_DIST += bootstrap/h_tp_atf_check_sh.sh
bootstrap/h_tp_atf_check_sh: \
$(srcdir)/bootstrap/h_tp_atf_check_sh.sh
test -d bootstrap || mkdir -p bootstrap
@src=$(srcdir)/bootstrap/h_tp_atf_check_sh.sh; dst=$@; $(BUILD_SH_TP)
check_SCRIPTS += bootstrap/h_tp_fail
CLEANFILES += bootstrap/h_tp_fail
EXTRA_DIST += bootstrap/h_tp_fail.sh
bootstrap/h_tp_fail: $(srcdir)/bootstrap/h_tp_fail.sh
test -d bootstrap || mkdir -p bootstrap
@src=$(srcdir)/bootstrap/h_tp_fail.sh; dst=$@; $(BUILD_SH_TP)
check_SCRIPTS += bootstrap/h_tp_pass
CLEANFILES += bootstrap/h_tp_pass
EXTRA_DIST += bootstrap/h_tp_pass.sh
bootstrap/h_tp_pass: $(srcdir)/bootstrap/h_tp_pass.sh
test -d bootstrap || mkdir -p bootstrap
@src=$(srcdir)/bootstrap/h_tp_pass.sh; dst=$@; $(BUILD_SH_TP)
DISTCLEANFILES = \
bootstrap/atconfig \
testsuite.lineno \
testsuite.log
distclean-local:
-rm -rf testsuite.dir
EXTRA_DIST += bootstrap/testsuite \
bootstrap/package.m4 \
bootstrap/testsuite.at \
$(testsuite_incs)
testsuite_incs= $(srcdir)/bootstrap/t_application_help.at \
$(srcdir)/bootstrap/t_application_opts_args.at \
$(srcdir)/bootstrap/t_atf_config.at \
$(srcdir)/bootstrap/t_atf_run.at \
$(srcdir)/bootstrap/t_subr_atf_check.at \
$(srcdir)/bootstrap/t_test_program_compare.at \
$(srcdir)/bootstrap/t_test_program_filter.at \
$(srcdir)/bootstrap/t_test_program_list.at \
$(srcdir)/bootstrap/t_test_program_run.at
@target_srcdir@bootstrap/package.m4: $(top_srcdir)/configure.ac
{ \
echo '# Signature of the current package.'; \
echo 'm4_define(AT_PACKAGE_NAME, @PACKAGE_NAME@)'; \
echo 'm4_define(AT_PACKAGE_TARNAME, @PACKAGE_TARNAME@)'; \
echo 'm4_define(AT_PACKAGE_VERSION, @PACKAGE_VERSION@)'; \
echo 'm4_define(AT_PACKAGE_STRING, @PACKAGE_STRING@)'; \
echo 'm4_define(AT_PACKAGE_BUGREPORT, @PACKAGE_BUGREPORT@)'; \
echo 'm4_define(ENABLE_TOOLS, @ENABLE_TOOLS@)'; \
} >$(srcdir)/bootstrap/package.m4
@target_srcdir@bootstrap/testsuite: $(srcdir)/bootstrap/testsuite.at \
$(testsuite_incs) \
@target_srcdir@bootstrap/package.m4
autom4te --language=Autotest -I $(srcdir) \
-I $(srcdir)/bootstrap \
$(srcdir)/bootstrap/testsuite.at -o $@.tmp
mv $@.tmp $@
INSTALLCHECK_TARGETS += installcheck-bootstrap
PHONY_TARGETS += installcheck-bootstrap
installcheck-bootstrap: @target_srcdir@bootstrap/testsuite check
$(TESTS_ENVIRONMENT) $(srcdir)/bootstrap/testsuite
# vim: syntax=make:noexpandtab:shiftwidth=8:softtabstop=8

62
bootstrap/h_app_empty.cpp Normal file
View file

@ -0,0 +1,62 @@
//
// 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 <cstdlib>
#include "atf-c++/detail/application.hpp"
class h_app_empty : public atf::application::app {
static const char* m_description;
public:
h_app_empty(void);
int main(void);
};
const char* h_app_empty::m_description =
"A helper application for the bootstrap test suite that does nothing "
"on its own and redefines no methods.";
h_app_empty::h_app_empty(void) :
app(m_description, "h_app_empty(1)", "atf(7)")
{
}
int
h_app_empty::main(void)
{
return EXIT_SUCCESS;
}
int
main(int argc, char* const* argv)
{
return h_app_empty().run(argc, argv);
}

View file

@ -0,0 +1,103 @@
//
// 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 <cstdlib>
#include <iostream>
#include "atf-c++/detail/application.hpp"
#include "atf-c++/detail/sanity.hpp"
class h_app_opts_args : public atf::application::app {
static const char* m_description;
std::string specific_args(void) const;
options_set specific_options(void) const;
void process_option(int, const char*);
public:
h_app_opts_args(void);
int main(void);
};
const char* h_app_opts_args::m_description =
"A helper application for the bootstrap test suite that redefines the "
"methods to specify custom options and arguments.";
h_app_opts_args::h_app_opts_args(void) :
app(m_description, "h_app_opts_args(1)", "atf(7)")
{
}
std::string
h_app_opts_args::specific_args(void)
const
{
return "<arg1> <arg2>";
}
h_app_opts_args::options_set
h_app_opts_args::specific_options(void)
const
{
using atf::application::option;
options_set opts;
opts.insert(option('d', "", "Debug mode"));
opts.insert(option('v', "level", "Verbosity level"));
return opts;
}
void
h_app_opts_args::process_option(int ch, const char* arg)
{
switch (ch) {
case 'd':
std::cout << "-d given\n";
break;
case 'v':
std::cout << "-v given with argument " << arg << "\n";
break;
default:
UNREACHABLE;
}
}
int
h_app_opts_args::main(void)
{
return EXIT_SUCCESS;
}
int
main(int argc, char* const* argv)
{
return h_app_opts_args().run(argc, argv);
}

304
bootstrap/h_tp_atf_check_sh.sh Executable file
View file

@ -0,0 +1,304 @@
#
# 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.
#
atf_test_case exitcode_0_0
exitcode_0_0_head()
{
atf_set "descr" "Runs a program that returns true and expects true"
}
exitcode_0_0_body()
{
atf_check -s eq:0 -o empty -e empty true
}
atf_test_case exitcode_0_1
exitcode_0_1_head()
{
atf_set "descr" "Runs a program that returns true and expects false"
}
exitcode_0_1_body()
{
atf_check -s eq:1 -o empty -e empty true
}
atf_test_case exitcode_1_0
exitcode_1_0_head()
{
atf_set "descr" "Runs a program that returns false and expects true"
}
exitcode_1_0_body()
{
atf_check -s eq:0 -o empty -e empty false
}
atf_test_case exitcode_1_1
exitcode_1_1_head()
{
atf_set "descr" "Runs a program that returns false and expects false"
}
exitcode_1_1_body()
{
# In Solaris, /usr/bin/false returns 255 rather than 1. Use the
# built-in version for the check.
atf_check -s eq:1 -o empty -e empty sh -c "false"
}
atf_test_case stdout_expout_pass
stdout_expout_pass_head()
{
atf_set "descr" "Runs a program with stdout set to expout and passes"
}
stdout_expout_pass_body()
{
echo foo >expout
atf_check -s eq:0 -o file:expout -e empty echo foo
}
atf_test_case stdout_expout_fail
stdout_expout_fail_head()
{
atf_set "descr" "Runs a program with stdout set to expout and fails"
}
stdout_expout_fail_body()
{
echo foo >expout
atf_check -s eq:0 -o file:expout -e empty echo bar
}
atf_test_case stdout_ignore_empty
stdout_ignore_empty_head()
{
atf_set "descr" "Runs a program with stdout set to ignore and" \
"writes nothing"
}
stdout_ignore_empty_body()
{
atf_check -s eq:0 -o ignore -e empty true
}
atf_test_case stdout_ignore_sth
stdout_ignore_sth_head()
{
atf_set "descr" "Runs a program with stdout set to ignore and" \
"writes something"
}
stdout_ignore_sth_body()
{
atf_check -s eq:0 -o ignore -e empty echo foo
}
atf_test_case stdout_null_empty
stdout_null_empty_head()
{
atf_set "descr" "Runs a program with stdout set to null and" \
"writes nothing"
}
stdout_null_empty_body()
{
atf_check -s eq:0 -o empty -e empty true
}
atf_test_case stdout_null_sth
stdout_null_sth_head()
{
atf_set "descr" "Runs a program with stdout set to null and" \
"writes something"
}
stdout_null_sth_body()
{
atf_check -s eq:0 -o empty -e empty echo foo
}
atf_test_case stdout_stdout_written
stdout_stdout_written_head()
{
atf_set "descr" "Runs a program with stdout set to stdout and" \
"writes something"
}
stdout_stdout_written_body()
{
atf_check -s eq:0 -o save:stdout -e empty echo foo
echo foo >aux
cmp -s stdout aux || atf_fail "Test failed"
}
atf_test_case stdout_match_ok
stdout_match_ok_head()
{
atf_set "descr" "Runs a program with stdout set to match and" \
"matches the regular expression"
}
stdout_match_ok_body()
{
atf_check -s eq:0 -o 'match:bar$' -e empty -x "echo line; echo foo bar"
}
atf_test_case stdout_match_fail
stdout_match_fail_head()
{
atf_set "descr" "Runs a program with stdout set to match and" \
"does not match the regular expression"
}
stdout_match_fail_body()
{
atf_check -s eq:0 -o 'match:bar$' -e empty -x "echo line; echo foo bar baz"
}
atf_test_case stderr_experr_pass
stderr_experr_pass_head()
{
atf_set "descr" "Runs a program with stderr set to experr and passes"
}
stderr_experr_pass_body()
{
echo foo >experr
atf_check -s eq:0 -o empty -e file:experr -x 'echo foo 1>&2'
}
atf_test_case stderr_experr_fail
stderr_experr_fail_head()
{
atf_set "descr" "Runs a program with stderr set to experr and fails"
}
stderr_experr_fail_body()
{
echo foo >experr
atf_check -s eq:0 -o empty -e file:stderr -x 'echo bar 1>&2'
}
atf_test_case stderr_ignore_empty
stderr_ignore_empty_head()
{
atf_set "descr" "Runs a program with stderr set to ignore and" \
"writes nothing"
}
stderr_ignore_empty_body()
{
atf_check -s eq:0 -o empty -e ignore -x 'true 1>&2'
}
atf_test_case stderr_ignore_sth
stderr_ignore_sth_head()
{
atf_set "descr" "Runs a program with stderr set to ignore and" \
"writes something"
}
stderr_ignore_sth_body()
{
atf_check -s eq:0 -o empty -e ignore -x 'echo foo 1>&2'
}
atf_test_case stderr_null_empty
stderr_null_empty_head()
{
atf_set "descr" "Runs a program with stderr set to null and" \
"writes nothing"
}
stderr_null_empty_body()
{
atf_check -s eq:0 -o empty -e empty -x 'true 1>&2'
}
atf_test_case stderr_null_sth
stderr_null_sth_head()
{
atf_set "descr" "Runs a program with stderr set to null and" \
"writes something"
}
stderr_null_sth_body()
{
atf_check -s eq:0 -o empty -e empty -x 'echo foo 1>&2'
}
atf_test_case stderr_stderr_written
stderr_stderr_written_head()
{
atf_set "descr" "Runs a program with stderr set to stderr and" \
"writes something"
}
stderr_stderr_written_body()
{
atf_check -s eq:0 -o empty -e save:stderr -x 'echo foo 1>&2'
echo foo >aux
cmp -s stderr aux || atf_fail "Test failed"
}
atf_test_case stderr_match_ok
stderr_match_ok_head()
{
atf_set "descr" "Runs a program with stderr set to match and" \
"matches the regular expression"
}
stderr_match_ok_body()
{
atf_check -s eq:0 -o empty -e 'match:bar$' -x \
"echo line 1>&2; echo foo bar 1>&2"
}
atf_test_case stderr_match_fail
stderr_match_fail_head()
{
atf_set "descr" "Runs a program with stderr set to match and" \
"does not match the regular expression"
}
stderr_match_fail_body()
{
atf_check -s eq:0 -o empty -e 'match:bar$' -x \
"echo line 1>&2; echo foo bar baz 1>&2"
}
atf_init_test_cases()
{
atf_add_test_case exitcode_0_0
atf_add_test_case exitcode_0_1
atf_add_test_case exitcode_1_0
atf_add_test_case exitcode_1_1
atf_add_test_case stdout_expout_pass
atf_add_test_case stdout_expout_fail
atf_add_test_case stdout_ignore_empty
atf_add_test_case stdout_ignore_sth
atf_add_test_case stdout_null_empty
atf_add_test_case stdout_null_sth
atf_add_test_case stdout_stdout_written
atf_add_test_case stdout_match_ok
atf_add_test_case stdout_match_fail
atf_add_test_case stderr_experr_pass
atf_add_test_case stderr_experr_fail
atf_add_test_case stderr_ignore_empty
atf_add_test_case stderr_ignore_sth
atf_add_test_case stderr_null_empty
atf_add_test_case stderr_null_sth
atf_add_test_case stderr_stderr_written
atf_add_test_case stderr_match_ok
atf_add_test_case stderr_match_fail
}
# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4

83
bootstrap/h_tp_basic_c.c Normal file
View file

@ -0,0 +1,83 @@
/*
* 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 <atf-c.h>
#include "atf-c/error.h"
ATF_TC(pass);
ATF_TC_HEAD(pass, tc)
{
atf_tc_set_md_var(tc, "descr", "An empty test case that always passes");
}
ATF_TC_BODY(pass, tc)
{
atf_tc_pass();
}
ATF_TC(fail);
ATF_TC_HEAD(fail, tc)
{
atf_tc_set_md_var(tc, "descr", "An empty test case that always fails");
}
ATF_TC_BODY(fail, tc)
{
atf_tc_fail("On purpose");
}
ATF_TC(skip);
ATF_TC_HEAD(skip, tc)
{
atf_tc_set_md_var(tc, "descr", "An empty test case that is always "
"skipped");
}
ATF_TC_BODY(skip, tc)
{
atf_tc_skip("By design");
}
ATF_TC(default);
ATF_TC_HEAD(default, tc)
{
atf_tc_set_md_var(tc, "descr", "A test case that passes without "
"explicitly stating it");
}
ATF_TC_BODY(default, tc)
{
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, pass);
ATF_TP_ADD_TC(tp, fail);
ATF_TP_ADD_TC(tp, skip);
ATF_TP_ADD_TC(tp, default);
return atf_no_error();
}

View file

@ -0,0 +1,86 @@
//
// 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 <atf-c++.hpp>
ATF_TEST_CASE(pass);
ATF_TEST_CASE_HEAD(pass)
{
set_md_var("descr", "An empty test case that always passes");
}
ATF_TEST_CASE_BODY(pass)
{
ATF_PASS();
}
ATF_TEST_CASE(fail);
ATF_TEST_CASE_HEAD(fail)
{
set_md_var("descr", "An empty test case that always fails");
}
ATF_TEST_CASE_BODY(fail)
{
ATF_FAIL("On purpose");
}
ATF_TEST_CASE(skip);
ATF_TEST_CASE_HEAD(skip)
{
set_md_var("descr", "An empty test case that is always skipped");
}
ATF_TEST_CASE_BODY(skip)
{
ATF_SKIP("By design");
}
ATF_TEST_CASE(default);
ATF_TEST_CASE_HEAD(default)
{
set_md_var("descr", "A test case that passes without explicitly "
"stating it");
}
ATF_TEST_CASE_BODY(default)
{
}
ATF_INIT_TEST_CASES(tcs)
{
ATF_ADD_TEST_CASE(tcs, pass);
ATF_ADD_TEST_CASE(tcs, fail);
ATF_ADD_TEST_CASE(tcs, skip);
ATF_ADD_TEST_CASE(tcs, default);
}

View file

@ -27,38 +27,53 @@
# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# TODO: This test program is about checking the test case's "environment"
# (not the variables). Should be named something else than t_fork.
atf_test_case stop
stop_head()
atf_test_case pass
pass_head()
{
atf_set "descr" "Tests that sending a stop signal to a test case does" \
"not report it as failed"
atf_set "descr" "An empty test case that always passes"
}
stop_body()
pass_body()
{
for h in $(get_helpers); do
${h} -s $(atf_get_srcdir) -v pidfile=$(pwd)/pid \
-v donefile=$(pwd)/done -r resfile fork_stop &
ppid=${!}
echo "Waiting for pid file for test program ${ppid}"
while test ! -f pid; do sleep 1; done
pid=$(cat pid)
echo "Test case's pid is ${pid}"
kill -STOP ${pid}
touch done
echo "Wrote done file"
kill -CONT ${pid}
wait ${ppid}
atf_check -s eq:0 -o ignore -e empty grep '^passed$' resfile
rm -f pid done
done
atf_pass
}
atf_test_case fail
fail_head()
{
atf_set "descr" "An empty test case that always fails"
}
fail_body()
{
atf_fail "On purpose"
}
atf_test_case skip
skip_head()
{
atf_set "descr" "An empty test case that is always skipped"
}
skip_body()
{
atf_skip "By design"
}
atf_test_case default
default_head()
{
atf_set "descr" "A test case that passes without explicitly" \
"stating it"
}
default_body()
{
:
}
atf_init_test_cases()
{
atf_add_test_case stop
atf_add_test_case pass
atf_add_test_case fail
atf_add_test_case skip
atf_add_test_case default
}
# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4

View file

@ -1,8 +1,7 @@
#! /bin/sh
#
# Automated Testing Framework (atf)
#
# Copyright (c) 2007 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
@ -28,65 +27,21 @@
# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#
# A utility to ensure that INSTALL lists the correct versions of the
# tools used to generate the distfile.
#
Prog_Name=${0##*/}
#
# err message
#
err() {
echo "${Prog_Name}: ${@}" 1>&2
exit 1
atf_test_case @TC_NAME@
@TC_NAME@_head()
{
atf_set "descr" "An empty test case that always fails"
}
@TC_NAME@_body()
{
echo "ignore-me"
echo "ignore-me" 1>&2
atf_fail "No reason"
}
#
# warn message
#
warn() {
echo "${Prog_Name}: ${@}" 1>&2
atf_init_test_cases()
{
atf_add_test_case @TC_NAME@
}
#
# check_tool readme_file prog_name verbose_name
#
# Executes 'prog_name' to determine its version and checks if the
# given 'readme_file' contains 'verbose_name <version>' in it.
#
check_tool() {
readme=${1}
prog=${2}
name=${3}
ver=$(${prog} --version | head -n 1 | cut -d ' ' -f 4)
if grep "\\* ${name} ${ver}" ${readme} >/dev/null; then
true
else
warn "Incorrect version of ${name}"
false
fi
}
#
# main readme_file
#
# Entry point.
#
main() {
readme=${1}
ret=0
check_tool ${readme} autoconf "GNU autoconf" || ret=1
check_tool ${readme} automake "GNU automake" || ret=1
check_tool ${readme} libtool "GNU libtool" || ret=1
return ${ret}
}
main "${@}"
# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4

47
bootstrap/h_tp_pass.sh Executable file
View file

@ -0,0 +1,47 @@
#
# 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.
#
atf_test_case @TC_NAME@
@TC_NAME@_head()
{
atf_set "descr" "An empty test case that always passes"
}
@TC_NAME@_body()
{
echo "ignore-me"
echo "ignore-me" 1>&2
atf_pass
}
atf_init_test_cases()
{
atf_add_test_case @TC_NAME@
}
# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4

7
bootstrap/package.m4 Normal file
View file

@ -0,0 +1,7 @@
# Signature of the current package.
m4_define(AT_PACKAGE_NAME, Automated Testing Framework)
m4_define(AT_PACKAGE_TARNAME, atf)
m4_define(AT_PACKAGE_VERSION, 0.17)
m4_define(AT_PACKAGE_STRING, Automated Testing Framework 0.17)
m4_define(AT_PACKAGE_BUGREPORT, atf-devel@NetBSD.org)
m4_define(ENABLE_TOOLS, yes)

View file

@ -0,0 +1,40 @@
dnl
dnl Automated Testing Framework (atf)
dnl
dnl Copyright (c) 2007 The NetBSD Foundation, Inc.
dnl All rights reserved.
dnl
dnl Redistribution and use in source and binary forms, with or without
dnl modification, are permitted provided that the following conditions
dnl are met:
dnl 1. Redistributions of source code must retain the above copyright
dnl notice, this list of conditions and the following disclaimer.
dnl 2. Redistributions in binary form must reproduce the above copyright
dnl notice, this list of conditions and the following disclaimer in the
dnl documentation and/or other materials provided with the distribution.
dnl
dnl THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
dnl CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
dnl INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
dnl MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
dnl IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
dnl DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
dnl DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
dnl GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
dnl INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
dnl IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
dnl OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
dnl IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dnl
AT_SETUP([application: online help option])
AT_CHECK([APP_HELPER(app_empty)], 0, [stdout], [])
AT_CHECK([grep 'Available options' stdout], 1, [ignore], [])
AT_CHECK([APP_HELPER(app_empty) -h], 0, [stdout], [])
AT_CHECK([grep 'Available options' stdout], 0, [ignore], [])
AT_CLEANUP()
dnl vim: syntax=m4:expandtab:shiftwidth=4:softtabstop=4

View file

@ -0,0 +1,86 @@
dnl
dnl Automated Testing Framework (atf)
dnl
dnl Copyright (c) 2007 The NetBSD Foundation, Inc.
dnl All rights reserved.
dnl
dnl Redistribution and use in source and binary forms, with or without
dnl modification, are permitted provided that the following conditions
dnl are met:
dnl 1. Redistributions of source code must retain the above copyright
dnl notice, this list of conditions and the following disclaimer.
dnl 2. Redistributions in binary form must reproduce the above copyright
dnl notice, this list of conditions and the following disclaimer in the
dnl documentation and/or other materials provided with the distribution.
dnl
dnl THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
dnl CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
dnl INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
dnl MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
dnl IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
dnl DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
dnl DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
dnl GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
dnl INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
dnl IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
dnl OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
dnl IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dnl
AT_SETUP([application: arguments and options handling])
dnl Check that an application that does not redefine any method does
dnl not show strange flags in the usage message.
AT_CHECK([APP_HELPER(app_empty) -h], 0, [stdout], [])
AT_CHECK([grep ' -d ' stdout], 1, [ignore], [])
AT_CHECK([grep ' -h ' stdout], 0, [ignore], [])
AT_CHECK([grep ' -v ' stdout], 1, [ignore], [])
AT_CHECK([grep ' -z ' stdout], 1, [ignore], [])
dnl Check that an application that adds its own options shows them in
dnl the usage message.
AT_CHECK([APP_HELPER(app_opts_args) -h], 0, [stdout], [])
AT_CHECK([grep ' -d ' stdout], 0, [ignore], [])
AT_CHECK([grep ' -h ' stdout], 0, [ignore], [])
AT_CHECK([grep ' -v ' stdout], 0, [ignore], [])
AT_CHECK([grep ' -z ' stdout], 1, [ignore], [])
dnl Check that an application that does not redefine any method does
dnl not recognize strange flags.
AT_CHECK([APP_HELPER(app_empty) -d], 1, [], [stderr])
AT_CHECK([grep 'Unknown option.*-d' stderr], 0, [ignore], [])
AT_CHECK([APP_HELPER(app_empty) -v], 1, [], [stderr])
AT_CHECK([grep 'Unknown option.*-v' stderr], 0, [ignore], [])
AT_CHECK([APP_HELPER(app_empty) -z], 1, [], [stderr])
AT_CHECK([grep 'Unknown option.*-z' stderr], 0, [ignore], [])
dnl Check that an application that adds its own options is able to
dnl properly handle them.
AT_CHECK([APP_HELPER(app_opts_args) -d], 0, [stdout], [])
AT_CHECK([grep -- '-d given' stdout], 0, [ignore], [])
AT_CHECK([APP_HELPER(app_opts_args) -v], 1, [], [stderr])
AT_CHECK([grep 'Option.*-v.*requires an argument' stderr], 0, [ignore], [])
AT_CHECK([APP_HELPER(app_opts_args) -v foo], 0, [stdout], [])
AT_CHECK([grep -- '-v given with argument foo' stdout], 0, [ignore], [])
AT_CHECK([APP_HELPER(app_opts_args) -z], 1, [], [stderr])
AT_CHECK([grep 'Unknown option.*-z' stderr], 0, [ignore], [])
dnl Check that option processing stops after an argument.
AT_CHECK([APP_HELPER(app_opts_args) -- -d], 0, [stdout], [])
AT_CHECK([grep -- '-d given' stdout], 1, [], [])
AT_CHECK([APP_HELPER(app_opts_args) arg -d], 0, [stdout], [])
AT_CHECK([grep -- '-d given' stdout], 1, [], [])
dnl Check that an application that does not redefine any method does
dnl not show unexpected arguments in the usage message.
AT_CHECK([APP_HELPER(app_empty) -h], 0, [stdout], [])
AT_CHECK([grep '\@<:@options\@:>@$' stdout], 0, [ignore], [])
dnl Check that an application that defines the arguments it takes
dnl shows them in the usage message.
AT_CHECK([APP_HELPER(app_opts_args) -h], 0, [stdout], [])
AT_CHECK([grep '\@<:@options\@:>@ <arg1> <arg2>' stdout], 0, [ignore], [])
AT_CLEANUP()
dnl vim: syntax=m4:expandtab:shiftwidth=4:softtabstop=4

108
bootstrap/t_atf_config.at Normal file
View file

@ -0,0 +1,108 @@
dnl
dnl Automated Testing Framework (atf)
dnl
dnl Copyright (c) 2007 The NetBSD Foundation, Inc.
dnl All rights reserved.
dnl
dnl Redistribution and use in source and binary forms, with or without
dnl modification, are permitted provided that the following conditions
dnl are met:
dnl 1. Redistributions of source code must retain the above copyright
dnl notice, this list of conditions and the following disclaimer.
dnl 2. Redistributions in binary form must reproduce the above copyright
dnl notice, this list of conditions and the following disclaimer in the
dnl documentation and/or other materials provided with the distribution.
dnl
dnl THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
dnl CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
dnl INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
dnl MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
dnl IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
dnl DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
dnl DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
dnl GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
dnl INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
dnl IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
dnl OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
dnl IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dnl
AT_SETUP([atf-config: querying of build-time variables])
AT_TESTED(atf-config)
all_vars="atf_arch \
atf_build_cc \
atf_build_cflags \
atf_build_cpp \
atf_build_cppflags \
atf_build_cxx \
atf_build_cxxflags \
atf_confdir \
atf_includedir \
atf_libdir \
atf_libexecdir \
atf_machine \
atf_pkgdatadir \
atf_shell \
atf_workdir"
all_vars_no=15
dnl List all variables.
AT_CHECK([atf-config], [0], [stdout], [])
AT_CHECK([COUNT_LINES(stdout, ${all_vars_no})], [0], [], [])
for v in ${all_vars}; do
AT_CHECK([grep "${v}" stdout], [0], [ignore], [])
done
dnl Query a single variable and test terse mode.
for v in ${all_vars}; do
AT_CHECK([atf-config ${v}], [0], [stdout], [])
AT_CHECK([COUNT_LINES(stdout, 1)], [0], [], [])
AT_CHECK([grep "${v}" stdout], [0], [ignore], [])
AT_CHECK([cut -d ' ' -f 3- stdout], [0], [stdout], [])
AT_CHECK([mv stdout expout], [0], [], [])
AT_CHECK([atf-config -t ${v}], [0], [expout], [])
done
dnl Query several variables.
AT_CHECK([atf-config atf_libexecdir atf_pkgdatadir], [0], [stdout], [])
AT_CHECK([grep 'atf_libexecdir' stdout], [0], [ignore], [])
AT_CHECK([grep 'atf_pkgdatadir' stdout], [0], [ignore], [])
AT_CHECK([COUNT_LINES(stdout, 2)], [0], [ignore], [])
dnl Query a non-existent variable.
AT_CHECK([atf-config non_existent], [1], [], [stderr])
AT_CHECK([grep 'Unknown variable.*non_existent' stderr], [0], [ignore], [])
dnl Query an existent and non-existent variable.
for v in ${all_vars}; do
AT_CHECK([atf-config ${v} non_existent], [1], [], [stderr])
AT_CHECK([grep 'Unknown variable.*non_existent' stderr],
[0], [ignore], [])
AT_CHECK([atf-config non_existent ${v}], [1], [], [stderr])
AT_CHECK([grep 'Unknown variable.*non_existent' stderr],
[0], [ignore], [])
done
dnl Override every variable through the environment.
for v in ${all_vars}; do
V=$(echo ${v} | tr '@<:@a-z@:>@' '@<:@A-Z@:>@')
AT_CHECK([env ${V}=testval atf-config], [0], [stdout], [])
AT_CHECK([mv stdout all], [0], [], [])
AT_CHECK([grep "^${v} : " all], [0], [stdout], [])
AT_CHECK([mv stdout affected], [0], [], [])
AT_CHECK([grep -v "^${v} : " all], [0], [stdout], [])
AT_CHECK([mv stdout unaffected], [0], [], [])
AT_CHECK([COUNT_LINES(affected, 1)], [0], [ignore], [])
AT_CHECK([COUNT_LINES(unaffected, $((${all_vars_no} - 1)))],
[0], [ignore], [])
AT_CHECK([grep "^${v} : testval$" affected], [0], [ignore], [])
AT_CHECK([grep ' : testval$' unaffected], [1], [], [])
done
AT_CLEANUP()
dnl vim: syntax=m4:expandtab:shiftwidth=4:softtabstop=4

178
bootstrap/t_atf_run.at Normal file
View file

@ -0,0 +1,178 @@
dnl
dnl Automated Testing Framework (atf)
dnl
dnl Copyright (c) 2007 The NetBSD Foundation, Inc.
dnl All rights reserved.
dnl
dnl Redistribution and use in source and binary forms, with or without
dnl modification, are permitted provided that the following conditions
dnl are met:
dnl 1. Redistributions of source code must retain the above copyright
dnl notice, this list of conditions and the following disclaimer.
dnl 2. Redistributions in binary form must reproduce the above copyright
dnl notice, this list of conditions and the following disclaimer in the
dnl documentation and/or other materials provided with the distribution.
dnl
dnl THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
dnl CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
dnl INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
dnl MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
dnl IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
dnl DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
dnl DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
dnl GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
dnl INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
dnl IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
dnl OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
dnl IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dnl
AT_SETUP([atf-run: execution of tests])
AT_TESTED(atf-run)
m4_define([CREATE_PASS_TEST],
[AT_CHECK([sed -e 's,@TC_NAME@,$2,g' <TEST_HELPER_NO_S(tp_pass)],
[0], [stdout], [])
AT_CHECK([mv stdout $1], [0], [], [])
AT_CHECK([chmod +x $1], [0], [], [])
])
m4_define([CREATE_FAIL_TEST],
[AT_CHECK([sed -e 's,@TC_NAME@,$2,g' <TEST_HELPER_NO_S(tp_fail)],
[0], [stdout], [])
AT_CHECK([mv stdout $1], [0], [], [])
AT_CHECK([chmod +x $1], [0], [], [])
])
AT_CHECK([mkdir top], [0], [], [])
AT_CHECK([mkdir top/dir1], [0], [], [])
AT_CHECK([mkdir top/dir2], [0], [], [])
AT_DATA([top/Atffile],
[Content-Type: application/X-atf-atffile; version="1"
prop: test-suite = atf
tp: dir1
tp: dir2
tp: test1
tp: test2
])
AT_DATA([top/dir1/Atffile],
[Content-Type: application/X-atf-atffile; version="1"
prop: test-suite = atf
tp: test3
])
AT_DATA([top/dir2/Atffile],
[Content-Type: application/X-atf-atffile; version="1"
prop: test-suite = atf
tp: test4
tp: test5
])
CREATE_PASS_TEST([top/test1], [tc_1])
CREATE_FAIL_TEST([top/test2], [tc_2])
CREATE_PASS_TEST([top/dir1/test3], [tc_3])
CREATE_FAIL_TEST([top/dir2/test4], [tc_4])
CREATE_PASS_TEST([top/dir2/test5], [tc_5])
AT_CHECK([cd top/dir1 && atf-run], [0], [stdout], [])
CHECK_TPS_TCR(tc_3, passed, stdout)
AT_CHECK([grep -i 'tc_@<:@1245@:>@' stdout], [1], [], [])
AT_CHECK([grep 'tc-so:ignore-me' stdout], [0], [ignore], [])
AT_CHECK([grep 'tc-se:ignore-me' stdout], [0], [ignore], [])
AT_CHECK([cd top/dir2 && atf-run], [1], [stdout], [stderr])
CHECK_TPS_TCR(tc_4, failed, stdout)
CHECK_TPS_TCR(tc_5, passed, stdout)
AT_CHECK([grep -i 'tc_@<:@123@:>@' stdout], [1], [], [])
AT_CHECK([grep 'tc-so:ignore-me' stdout], [0], [ignore], [])
AT_CHECK([grep 'tc-se:ignore-me' stdout], [0], [ignore], [])
AT_CHECK([cd top && atf-run], [1], [stdout], [stderr])
CHECK_TPS_TCR(tc_1, passed, stdout)
CHECK_TPS_TCR(tc_2, failed, stdout)
CHECK_TPS_TCR(tc_3, passed, stdout)
CHECK_TPS_TCR(tc_4, failed, stdout)
CHECK_TPS_TCR(tc_5, passed, stdout)
AT_CHECK([grep 'tc-so:ignore-me' stdout], [0], [ignore], [])
AT_CHECK([grep 'tc-se:ignore-me' stdout], [0], [ignore], [])
dnl Repeat previous but using a glob that matches everything.
AT_DATA([top/Atffile],
[Content-Type: application/X-atf-atffile; version="1"
prop: test-suite = atf
tp-glob: *
])
AT_CHECK([cd top && atf-run], [1], [stdout], [stderr])
CHECK_TPS_TCR(tc_1, passed, stdout)
CHECK_TPS_TCR(tc_2, failed, stdout)
CHECK_TPS_TCR(tc_3, passed, stdout)
CHECK_TPS_TCR(tc_4, failed, stdout)
CHECK_TPS_TCR(tc_5, passed, stdout)
AT_CHECK([grep 'tc-so:ignore-me' stdout], [0], [ignore], [])
AT_CHECK([grep 'tc-se:ignore-me' stdout], [0], [ignore], [])
dnl Repeat previous but using a glob that matches directories only.
AT_DATA([top/Atffile],
[Content-Type: application/X-atf-atffile; version="1"
prop: test-suite = atf
tp-glob: d*
])
AT_CHECK([cd top && atf-run], [1], [stdout], [stderr])
CHECK_TPS_TCR(tc_3, passed, stdout)
CHECK_TPS_TCR(tc_4, failed, stdout)
CHECK_TPS_TCR(tc_5, passed, stdout)
AT_CHECK([grep 'tc-so:ignore-me' stdout], [0], [ignore], [])
AT_CHECK([grep 'tc-se:ignore-me' stdout], [0], [ignore], [])
dnl Make sure globs do not match non-executable nor hidden files.
dnl XXX This is not really part of the bootstrap test suite. Move to
dnl tests/atf/tools/t_atf_run.sh when it exists.
AT_CHECK([rm -rf top], [0], [], [])
AT_CHECK([mkdir top], [0], [], [])
CREATE_PASS_TEST([top/test1], [tc_1])
CREATE_PASS_TEST([top/test2], [tc_2])
CREATE_PASS_TEST([top/test3], [tc_3])
AT_CHECK([chmod -x top/test3], [0], [], [])
CREATE_PASS_TEST([top/.test4], [tc_4])
AT_CHECK([chmod -x top/.test4], [0], [], [])
AT_DATA([top/Atffile],
[Content-Type: application/X-atf-atffile; version="1"
prop: test-suite = atf
tp-glob: *
])
AT_CHECK([cd top && atf-run], [0], [stdout], [stderr])
CHECK_TPS_TCR(tc_1, passed, stdout)
CHECK_TPS_TCR(tc_2, passed, stdout)
AT_CHECK([grep -i 'tc_3' stdout], [1], [ignore], [])
AT_CHECK([grep -i 'tc_4' stdout], [1], [ignore], [])
dnl Run all test cases from a test program.
AT_CHECK([rm -rf top], [0], [], [])
AT_CHECK([mkdir top], [0], [], [])
AT_CHECK([cp TEST_HELPER_NO_S(tp_basic_sh) top])
AT_DATA([top/Atffile],
[Content-Type: application/X-atf-atffile; version="1"
prop: test-suite = atf
tp: h_tp_basic_sh
])
AT_CHECK([cd top && atf-run], [1], [stdout], [stderr])
CHECK_TPS_TCR(pass, passed, stdout)
CHECK_TPS_TCR(fail, failed, stdout)
CHECK_TPS_TCR(skip, skipped, stdout)
CHECK_TPS_TCR(default, passed, stdout)
AT_CLEANUP()
dnl vim: syntax=m4:expandtab:shiftwidth=4:softtabstop=4

View file

@ -0,0 +1,81 @@
dnl
dnl Automated Testing Framework (atf)
dnl
dnl Copyright (c) 2007 The NetBSD Foundation, Inc.
dnl All rights reserved.
dnl
dnl Redistribution and use in source and binary forms, with or without
dnl modification, are permitted provided that the following conditions
dnl are met:
dnl 1. Redistributions of source code must retain the above copyright
dnl notice, this list of conditions and the following disclaimer.
dnl 2. Redistributions in binary form must reproduce the above copyright
dnl notice, this list of conditions and the following disclaimer in the
dnl documentation and/or other materials provided with the distribution.
dnl
dnl THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
dnl CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
dnl INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
dnl MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
dnl IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
dnl DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
dnl DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
dnl GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
dnl INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
dnl IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
dnl OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
dnl IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dnl
AT_SETUP([subr: atf_check function])
AT_CHECK([TEST_HELPER(tp_atf_check_sh) exitcode_0_0],
[0], [ignore], [ignore])
AT_CHECK([TEST_HELPER(tp_atf_check_sh) exitcode_0_1],
[1], [ignore], [ignore])
AT_CHECK([TEST_HELPER(tp_atf_check_sh) exitcode_1_0],
[1], [ignore], [ignore])
AT_CHECK([TEST_HELPER(tp_atf_check_sh) exitcode_1_1],
[0], [ignore], [ignore])
AT_CHECK([TEST_HELPER(tp_atf_check_sh) stdout_expout_pass],
[0], [ignore], [ignore])
AT_CHECK([TEST_HELPER(tp_atf_check_sh) stdout_expout_fail],
[1], [ignore], [ignore])
AT_CHECK([TEST_HELPER(tp_atf_check_sh) stdout_ignore_empty],
[0], [ignore], [ignore])
AT_CHECK([TEST_HELPER(tp_atf_check_sh) stdout_ignore_sth],
[0], [ignore], [ignore])
AT_CHECK([TEST_HELPER(tp_atf_check_sh) stdout_null_empty],
[0], [ignore], [ignore])
AT_CHECK([TEST_HELPER(tp_atf_check_sh) stdout_null_sth],
[1], [ignore], [ignore])
AT_CHECK([TEST_HELPER(tp_atf_check_sh) stdout_stdout_written],
[0], [ignore], [ignore])
AT_CHECK([TEST_HELPER(tp_atf_check_sh) stdout_match_ok],
[0], [ignore], [ignore])
AT_CHECK([TEST_HELPER(tp_atf_check_sh) stdout_match_fail],
[1], [ignore], [ignore])
AT_CHECK([TEST_HELPER(tp_atf_check_sh) stderr_experr_pass],
[0], [ignore], [ignore])
AT_CHECK([TEST_HELPER(tp_atf_check_sh) stderr_experr_fail],
[1], [ignore], [ignore])
AT_CHECK([TEST_HELPER(tp_atf_check_sh) stderr_ignore_empty],
[0], [ignore], [ignore])
AT_CHECK([TEST_HELPER(tp_atf_check_sh) stderr_ignore_sth],
[0], [ignore], [ignore])
AT_CHECK([TEST_HELPER(tp_atf_check_sh) stderr_null_empty],
[0], [ignore], [ignore])
AT_CHECK([TEST_HELPER(tp_atf_check_sh) stderr_null_sth],
[1], [ignore], [ignore])
AT_CHECK([TEST_HELPER(tp_atf_check_sh) stderr_stderr_written],
[0], [ignore], [ignore])
AT_CHECK([TEST_HELPER(tp_atf_check_sh) stderr_match_ok],
[0], [ignore], [ignore])
AT_CHECK([TEST_HELPER(tp_atf_check_sh) stderr_match_fail],
[1], [ignore], [ignore])
AT_CLEANUP()
dnl vim: syntax=m4:expandtab:shiftwidth=4:softtabstop=4

View file

@ -0,0 +1,186 @@
dnl
dnl Automated Testing Framework (atf)
dnl
dnl Copyright (c) 2007 The NetBSD Foundation, Inc.
dnl All rights reserved.
dnl
dnl Redistribution and use in source and binary forms, with or without
dnl modification, are permitted provided that the following conditions
dnl are met:
dnl 1. Redistributions of source code must retain the above copyright
dnl notice, this list of conditions and the following disclaimer.
dnl 2. Redistributions in binary form must reproduce the above copyright
dnl notice, this list of conditions and the following disclaimer in the
dnl documentation and/or other materials provided with the distribution.
dnl
dnl THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
dnl CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
dnl INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
dnl MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
dnl IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
dnl DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
dnl DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
dnl GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
dnl INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
dnl IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
dnl OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
dnl IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dnl
AT_SETUP([test_program: compare the user-visible interfaces])
dnl No arguments.
AT_CHECK([TEST_HELPER(tp_basic_c)], [1], [], [stderr])
sed 's,tp_basic_c,tp_basic_cpp,g' <stderr >experr
AT_CHECK([TEST_HELPER(tp_basic_cpp)], [1], [], [experr])
sed 's,tp_basic_c,tp_basic_sh,g' <stderr >experr
AT_CHECK([TEST_HELPER(tp_basic_sh)], [1], [], [experr])
dnl Try to ask for help, which is not bundled in.
AT_CHECK([TEST_HELPER(tp_basic_c) -h], [1], [], [stderr])
sed 's,tp_basic_c,tp_basic_cpp,g' <stderr >experr
AT_CHECK([TEST_HELPER(tp_basic_cpp) -h], [1], [], [experr])
sed 's,tp_basic_c,tp_basic_sh,g' <stderr >experr
AT_CHECK([TEST_HELPER(tp_basic_sh) -h], [1], [], [experr])
dnl Give an invalid option.
AT_CHECK([TEST_HELPER(tp_basic_c) -Z], [1], [], [stderr])
sed 's,tp_basic_c,tp_basic_cpp,g' <stderr >experr
AT_CHECK([TEST_HELPER(tp_basic_cpp) -Z], [1], [], [experr])
sed 's,tp_basic_c,tp_basic_sh,g' <stderr >experr
AT_CHECK([TEST_HELPER(tp_basic_sh) -Z], [1], [], [experr])
dnl List all tests.
AT_CHECK([TEST_HELPER(tp_basic_c) -l], [0], [stdout], [])
sed 's,tp_basic_c,tp_basic_cpp,g' <stdout >expout
AT_CHECK([TEST_HELPER(tp_basic_cpp) -l], [0], [expout], [])
sed 's,tp_basic_c,tp_basic_sh,g' <stdout >expout
AT_CHECK([TEST_HELPER(tp_basic_sh) -l], [0], [expout], [])
dnl Run no tests.
AT_CHECK([TEST_HELPER(tp_basic_c)],
[1], [stdout], [stderr])
sed 's,tp_basic_c,tp_basic_cpp,g' <stdout >expout
sed 's,tp_basic_c,tp_basic_cpp,g' <stderr >experr
AT_CHECK([TEST_HELPER(tp_basic_cpp)],
[1], [expout], [experr])
sed 's,tp_basic_c,tp_basic_sh,g' <stdout >expout
sed 's,tp_basic_c,tp_basic_sh,g' <stderr >experr
AT_CHECK([TEST_HELPER(tp_basic_sh)],
[1], [expout], [experr])
dnl Run the pass test case.
AT_CHECK([TEST_HELPER(tp_basic_c) -r resout pass],
[0], [stdout], [stderr])
sed 's,tp_basic_c,tp_basic_cpp,g' <stdout >expout
sed 's,tp_basic_c,tp_basic_cpp,g' <stderr >experr
sed 's,tp_basic_c,tp_basic_cpp,g' <resout >resexp
AT_CHECK([TEST_HELPER(tp_basic_cpp) -r resout pass],
[0], [expout], [experr])
AT_CHECK([cmp -s resout resexp], [0], [], [])
sed 's,tp_basic_c,tp_basic_sh,g' <stdout >expout
sed 's,tp_basic_c,tp_basic_sh,g' <stderr >experr
sed 's,tp_basic_c,tp_basic_sh,g' <resout >resexp
AT_CHECK([TEST_HELPER(tp_basic_sh) -r resout pass],
[0], [expout], [experr])
AT_CHECK([cmp -s resout resexp], [0], [], [])
dnl Run the fail test case.
AT_CHECK([TEST_HELPER(tp_basic_c) -r resout fail],
[1], [stdout], [stderr])
sed 's,tp_basic_c,tp_basic_cpp,g' <stdout >expout
sed 's,tp_basic_c,tp_basic_cpp,g' <stderr >experr
sed 's,tp_basic_c,tp_basic_cpp,g' <resout >resexp
AT_CHECK([TEST_HELPER(tp_basic_cpp) -r resout fail],
[1], [expout], [experr])
AT_CHECK([cmp -s resout resexp], [0], [], [])
sed 's,tp_basic_c,tp_basic_sh,g' <stdout >expout
sed 's,tp_basic_c,tp_basic_sh,g' <stderr >experr
sed 's,tp_basic_c,tp_basic_sh,g' <resout >resexp
AT_CHECK([TEST_HELPER(tp_basic_sh) -r resout fail],
[1], [expout], [experr])
AT_CHECK([cmp -s resout resexp], [0], [], [])
dnl Run the skip test case.
AT_CHECK([TEST_HELPER(tp_basic_c) -r resout skip],
[0], [stdout], [stderr])
sed 's,tp_basic_c,tp_basic_cpp,g' <stdout >expout
sed 's,tp_basic_c,tp_basic_cpp,g' <stderr >experr
sed 's,tp_basic_c,tp_basic_cpp,g' <resout >resexp
AT_CHECK([TEST_HELPER(tp_basic_cpp) -r resout skip],
[0], [expout], [experr])
AT_CHECK([cmp -s resout resexp], [0], [], [])
sed 's,tp_basic_c,tp_basic_sh,g' <stdout >expout
sed 's,tp_basic_c,tp_basic_sh,g' <stderr >experr
sed 's,tp_basic_c,tp_basic_sh,g' <resout >resexp
AT_CHECK([TEST_HELPER(tp_basic_sh) -r resout skip],
[0], [expout], [experr])
AT_CHECK([cmp -s resout resexp], [0], [], [])
dnl Run the default test case.
AT_CHECK([TEST_HELPER(tp_basic_c) -r resout default],
[0], [stdout], [stderr])
sed 's,tp_basic_c,tp_basic_cpp,g' <stdout >expout
sed 's,tp_basic_c,tp_basic_cpp,g' <stderr >experr
sed 's,tp_basic_c,tp_basic_cpp,g' <resout >resexp
AT_CHECK([TEST_HELPER(tp_basic_cpp) -r resout default],
[0], [expout], [experr])
AT_CHECK([cmp -s resout resexp], [0], [], [])
sed 's,tp_basic_c,tp_basic_sh,g' <stdout >expout
sed 's,tp_basic_c,tp_basic_sh,g' <stderr >experr
sed 's,tp_basic_c,tp_basic_sh,g' <resout >resexp
AT_CHECK([TEST_HELPER(tp_basic_sh) -r resout default],
[0], [expout], [experr])
AT_CHECK([cmp -s resout resexp], [0], [], [])
dnl Try running multiple tests.
AT_CHECK([TEST_HELPER(tp_basic_c) pass fail],
[1], [stdout], [stderr])
sed 's,tp_basic_c,tp_basic_cpp,g' <stdout >expout
sed 's,tp_basic_c,tp_basic_cpp,g' <stderr >experr
AT_CHECK([TEST_HELPER(tp_basic_cpp) pass fail],
[1], [expout], [experr])
sed 's,tp_basic_c,tp_basic_sh,g' <stdout >expout
sed 's,tp_basic_c,tp_basic_sh,g' <stderr >experr
AT_CHECK([TEST_HELPER(tp_basic_sh) pass fail],
[1], [expout], [experr])
dnl Run an unknown test case.
AT_CHECK([TEST_HELPER(tp_basic_c) unknown],
[1], [stdout], [stderr])
sed 's,tp_basic_c,tp_basic_cpp,g' <stdout >expout
sed 's,tp_basic_c,tp_basic_cpp,g' <stderr >experr
AT_CHECK([TEST_HELPER(tp_basic_cpp) unknown],
[1], [expout], [experr])
sed 's,tp_basic_c,tp_basic_sh,g' <stdout >expout
sed 's,tp_basic_c,tp_basic_sh,g' <stderr >experr
AT_CHECK([TEST_HELPER(tp_basic_sh) unknown],
[1], [expout], [experr])
dnl Try running a non-existent cleanup routine.
AT_CHECK([TEST_HELPER(tp_basic_c) pass:cleanup],
[0], [stdout], [stderr])
sed 's,tp_basic_c,tp_basic_cpp,g' <stdout >expout
sed 's,tp_basic_c,tp_basic_cpp,g' <stderr >experr
AT_CHECK([TEST_HELPER(tp_basic_cpp) pass:cleanup],
[0], [expout], [experr])
sed 's,tp_basic_c,tp_basic_sh,g' <stdout >expout
sed 's,tp_basic_c,tp_basic_sh,g' <stderr >experr
AT_CHECK([TEST_HELPER(tp_basic_sh) pass:cleanup],
[0], [expout], [experr])
dnl Run a test and dump the results on stdout.
AT_CHECK([TEST_HELPER(tp_basic_c) skip],
[0], [stdout], [stderr])
sed 's,tp_basic_c,tp_basic_cpp,g' <stdout >expout
sed 's,tp_basic_c,tp_basic_cpp,g' <stderr >experr
AT_CHECK([TEST_HELPER(tp_basic_cpp) skip],
[0], [expout], [experr])
sed 's,tp_basic_c,tp_basic_sh,g' <stdout >expout
sed 's,tp_basic_c,tp_basic_sh,g' <stderr >experr
AT_CHECK([TEST_HELPER(tp_basic_sh) skip],
[0], [expout], [experr])
AT_CLEANUP()
dnl vim: syntax=m4:expandtab:shiftwidth=4:softtabstop=4

View file

@ -0,0 +1,63 @@
dnl
dnl Automated Testing Framework (atf)
dnl
dnl Copyright (c) 2007 The NetBSD Foundation, Inc.
dnl All rights reserved.
dnl
dnl Redistribution and use in source and binary forms, with or without
dnl modification, are permitted provided that the following conditions
dnl are met:
dnl 1. Redistributions of source code must retain the above copyright
dnl notice, this list of conditions and the following disclaimer.
dnl 2. Redistributions in binary form must reproduce the above copyright
dnl notice, this list of conditions and the following disclaimer in the
dnl documentation and/or other materials provided with the distribution.
dnl
dnl THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
dnl CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
dnl INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
dnl MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
dnl IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
dnl DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
dnl DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
dnl GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
dnl INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
dnl IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
dnl OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
dnl IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dnl
AT_SETUP([test_program: filter test cases by name])
for h in tp_basic_c tp_basic_cpp tp_basic_sh; do
dnl Try an invalid test case name.
AT_CHECK([TEST_HELPER(${h}) invalid], 1, [], [stderr])
AT_CHECK([grep "Unknown test case .invalid'" stderr],
[0], [ignore], [])
dnl Try a glob as a test case name.
AT_CHECK([TEST_HELPER(${h}) "*p*"], 1, [], [stderr])
AT_CHECK([grep "Unknown test case .\\*p\\*'" stderr],
[0], [ignore], [])
AT_DATA([expres], [passed
])
AT_CHECK([TEST_HELPER(${h}) -r resout pass], 0, [ignore], [ignore])
AT_CHECK([cmp -s resout expres], [0], [], [])
AT_DATA([expres], [skipped: By design
])
AT_CHECK([TEST_HELPER(${h}) -r resout skip], 0, [ignore], [ignore])
AT_CHECK([cmp -s resout expres], [0], [], [])
AT_DATA([expres], [failed: On purpose
])
AT_CHECK([TEST_HELPER(${h}) -r resout fail], 1, [ignore], [ignore])
AT_CHECK([cmp -s resout expres], [0], [], [])
done
AT_CLEANUP()
dnl vim: syntax=m4:expandtab:shiftwidth=4:softtabstop=4

View file

@ -0,0 +1,63 @@
dnl
dnl Automated Testing Framework (atf)
dnl
dnl Copyright (c) 2007 The NetBSD Foundation, Inc.
dnl All rights reserved.
dnl
dnl Redistribution and use in source and binary forms, with or without
dnl modification, are permitted provided that the following conditions
dnl are met:
dnl 1. Redistributions of source code must retain the above copyright
dnl notice, this list of conditions and the following disclaimer.
dnl 2. Redistributions in binary form must reproduce the above copyright
dnl notice, this list of conditions and the following disclaimer in the
dnl documentation and/or other materials provided with the distribution.
dnl
dnl THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
dnl CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
dnl INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
dnl MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
dnl IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
dnl DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
dnl DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
dnl GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
dnl INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
dnl IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
dnl OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
dnl IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dnl
AT_SETUP([test_program: list test cases])
for h in tp_basic_c tp_basic_cpp tp_basic_sh; do
AT_DATA([expout], [Content-Type: application/X-atf-tp; version="1"
ident: pass
descr: An empty test case that always passes
ident: fail
descr: An empty test case that always fails
ident: skip
descr: An empty test case that is always skipped
ident: default
descr: A test case that passes without explicitly stating it
])
AT_CHECK([TEST_HELPER(${h}) -l], [0], [expout], [])
AT_CHECK([TEST_HELPER(${h}) -l pass], [1], [], [stderr])
AT_CHECK([grep 'Cannot provide test case names with -l' stderr],
[0], [ignore], [])
AT_CHECK([TEST_HELPER(${h}) -l pass fail], [1], [], [stderr])
AT_CHECK([grep 'Cannot provide test case names with -l' stderr],
[0], [ignore], [])
done
AT_CLEANUP()
dnl vim: syntax=m4:expandtab:shiftwidth=4:softtabstop=4

View file

@ -0,0 +1,51 @@
dnl
dnl Automated Testing Framework (atf)
dnl
dnl Copyright (c) 2007 The NetBSD Foundation, Inc.
dnl All rights reserved.
dnl
dnl Redistribution and use in source and binary forms, with or without
dnl modification, are permitted provided that the following conditions
dnl are met:
dnl 1. Redistributions of source code must retain the above copyright
dnl notice, this list of conditions and the following disclaimer.
dnl 2. Redistributions in binary form must reproduce the above copyright
dnl notice, this list of conditions and the following disclaimer in the
dnl documentation and/or other materials provided with the distribution.
dnl
dnl THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
dnl CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
dnl INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
dnl MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
dnl IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
dnl DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
dnl DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
dnl GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
dnl INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
dnl IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
dnl OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
dnl IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dnl
AT_SETUP([test_program: output format and exit codes])
for h in tp_basic_c tp_basic_cpp tp_basic_sh; do
dnl Check the -r flag to redirect the results output.
AT_CHECK([TEST_HELPER(${h}) -r resout pass], 0, [stdout], [stderr])
CHECK_TCR([resout], [passed])
AT_CHECK([TEST_HELPER(${h}) -r resout fail], 1, [stdout], [stderr])
CHECK_TCR([resout], [failed], [On purpose])
AT_CHECK([TEST_HELPER(${h}) -r resout skip], 0, [stdout], [stderr])
CHECK_TCR([resout], [skipped], [By design])
AT_CHECK([TEST_HELPER(${h}) -r resout default], 0, [stdout], [stderr])
CHECK_TCR([resout], [passed])
done
AT_CLEANUP()
dnl vim: syntax=m4:expandtab:shiftwidth=4:softtabstop=4

5873
bootstrap/testsuite Executable file

File diff suppressed because it is too large Load diff

84
bootstrap/testsuite.at Normal file
View file

@ -0,0 +1,84 @@
dnl
dnl Automated Testing Framework (atf)
dnl
dnl Copyright (c) 2007 The NetBSD Foundation, Inc.
dnl All rights reserved.
dnl
dnl Redistribution and use in source and binary forms, with or without
dnl modification, are permitted provided that the following conditions
dnl are met:
dnl 1. Redistributions of source code must retain the above copyright
dnl notice, this list of conditions and the following disclaimer.
dnl 2. Redistributions in binary form must reproduce the above copyright
dnl notice, this list of conditions and the following disclaimer in the
dnl documentation and/or other materials provided with the distribution.
dnl
dnl THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
dnl CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
dnl INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
dnl MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
dnl IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
dnl DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
dnl DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
dnl GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
dnl INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
dnl IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
dnl OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
dnl IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dnl
AT_INIT([bootstrap tests])
m4_define([GUESS_TOPDIR], {
old=$(pwd)
while test $(pwd) != '/' -a ! -e ./Makefile; do
cd ..
done
topdir=$(pwd)
cd ${old}
echo ${topdir}
})
m4_define([APP_HELPER], [$(GUESS_TOPDIR)/bootstrap/h_$1])
m4_define([TEST_HELPER_NO_S], [$(GUESS_TOPDIR)/bootstrap/h_$1])
m4_define([TEST_HELPER], [$(GUESS_TOPDIR)/bootstrap/h_$1 \
-s $(GUESS_TOPDIR)/bootstrap])
m4_define(COUNT_IN_LINES,
[test @S|@[($1 | wc -l | awk '{ print @S|@1 }')] = $2])
m4_define(COUNT_LINES, [test @S|@[(wc -l $1 | awk '{ print @S|@1 }')] = $2])
m4_define(TCR_DATA, [echo '$2' >$1 <<EOF
$2
EOF
m4_ifnblank([$3], [echo "$2: $3" >$1])])
m4_define(CHECK_TCR, [TCR_DATA([expres], $2, $3)
AT_CHECK([diff -u expres $1], [0], [], [])])
m4_define(CHECK_TCS_TCR,
[AT_CHECK([grep '^tc-end: @<:@0-9. @:>@*, $1, $2' $3], [0],
[ignore], [])])
m4_define(CHECK_TPS_TCR,
[AT_CHECK([grep '^tc-end: @<:@0-9. @:>@*, $1, $2' $3], [0],
[ignore], [])])
dnl The tests below are sorted depending on how important they are.
m4_include(bootstrap/t_test_program_filter.at)
m4_include(bootstrap/t_test_program_run.at)
m4_include(bootstrap/t_test_program_list.at)
m4_include(bootstrap/t_test_program_compare.at)
m4_include(bootstrap/t_subr_atf_check.at)
m4_if([ENABLE_TOOLS], yes, [
m4_include(bootstrap/t_application_opts_args.at)
m4_include(bootstrap/t_application_help.at)
m4_include(bootstrap/t_atf_config.at)
m4_include(bootstrap/t_atf_run.at)
])
dnl vim: syntax=m4:expandtab:shiftwidth=4:softtabstop=4

4271
configure vendored

File diff suppressed because it is too large Load diff

View file

@ -31,7 +31,7 @@ dnl -----------------------------------------------------------------------
dnl Initialize the GNU build system.
dnl -----------------------------------------------------------------------
AC_INIT([Automated Testing Framework], [0.16], [atf-devel@NetBSD.org], [atf],
AC_INIT([Automated Testing Framework], [0.17], [atf-devel@NetBSD.org], [atf],
[http://code.google.com/p/kyua/wiki/ATF])
AC_PREREQ([2.65])
AC_COPYRIGHT([Copyright (c) 2007-2012 The NetBSD Foundation, Inc.])

View file

@ -61,7 +61,7 @@ failures.
This body is only executed if the abstract conditions specified by the
header are met.
The
.Em cleanup routine
.Em cleanup
routine is a piece of code always executed after the body, regardless of
the exit status of the test case.
It can be used to undo side-effects of the test case.

159
m4/compiler-flags.m4 Normal file
View file

@ -0,0 +1,159 @@
dnl Copyright 2010 Google Inc.
dnl All rights reserved.
dnl
dnl Redistribution and use in source and binary forms, with or without
dnl modification, are permitted provided that the following conditions are
dnl met:
dnl
dnl * Redistributions of source code must retain the above copyright
dnl notice, this list of conditions and the following disclaimer.
dnl * Redistributions in binary form must reproduce the above copyright
dnl notice, this list of conditions and the following disclaimer in the
dnl documentation and/or other materials provided with the distribution.
dnl * Neither the name of Google Inc. nor the names of its contributors
dnl may be used to endorse or promote products derived from this software
dnl without specific prior written permission.
dnl
dnl THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
dnl "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
dnl LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
dnl A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
dnl OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
dnl SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
dnl LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
dnl DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
dnl THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
dnl (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
dnl OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dnl \file compiler-flags.m4
dnl
dnl Macros to check for the existence of compiler flags. The macros in this
dnl file support both C and C++.
dnl
dnl Be aware that, in order to detect a flag accurately, we may need to enable
dnl strict warning checking in the compiler (i.e. enable -Werror). Some
dnl compilers, e.g. Clang, report unknown -W flags as warnings unless -Werror is
dnl selected. This fact would confuse the flag checks below because we would
dnl conclude that a flag is valid while in reality it is not. To resolve this,
dnl the macros below will pass -Werror to the compiler along with any other flag
dnl being checked.
dnl Checks for a compiler flag and sets a result variable.
dnl
dnl This is an auxiliary macro for the implementation of _KYUA_FLAG.
dnl
dnl \param 1 The shell variable containing the compiler name. Used for
dnl reporting purposes only. C or CXX.
dnl \param 2 The shell variable containing the flags for the compiler.
dnl CFLAGS or CXXFLAGS.
dnl \param 3 The name of the compiler flag to check for.
dnl \param 4 The shell variable to set with the result of the test. Will
dnl be set to 'yes' if the flag is valid, 'no' otherwise.
dnl \param 5 Additional, optional flags to pass to the C compiler while
dnl looking for the flag in $3. We use this here to pass -Werror to the
dnl flag checks (unless we are checking for -Werror already).
AC_DEFUN([_KYUA_FLAG_AUX], [
if test x"${$4-unset}" = xunset; then
AC_MSG_CHECKING(whether ${$1} supports $3)
saved_flags="${$2}"
$4=no
$2="${$2} $5 $3"
AC_LINK_IFELSE([AC_LANG_PROGRAM([], [return 0;])],
AC_MSG_RESULT(yes)
$4=yes,
AC_MSG_RESULT(no))
$2="${saved_flags}"
fi
])
dnl Checks for a compiler flag and appends it to a result variable.
dnl
dnl \param 1 The shell variable containing the compiler name. Used for
dnl reporting purposes only. CC or CXX.
dnl \param 2 The shell variable containing the flags for the compiler.
dnl CFLAGS or CXXFLAGS.
dnl \param 3 The name of the compiler flag to check for.
dnl \param 4 The shell variable to which to append $3 if the flag is valid.
AC_DEFUN([_KYUA_FLAG], [
_KYUA_FLAG_AUX([$1], [$2], [-Werror], [kyua_$1_has_werror])
if test "$3" = "-Werror"; then
found=${kyua_$1_has_werror}
else
found=unset
if test ${kyua_$1_has_werror} = yes; then
_KYUA_FLAG_AUX([$1], [$2], [$3], [found], [-Werror])
else
_KYUA_FLAG_AUX([$1], [$2], [$3], [found], [])
fi
fi
if test ${found} = yes; then
$4="${$4} $3"
fi
])
dnl Checks for a C compiler flag and appends it to a variable.
dnl
dnl \pre The current language is C.
dnl
dnl \param 1 The name of the compiler flag to check for.
dnl \param 2 The shell variable to which to append $1 if the flag is valid.
AC_DEFUN([KYUA_CC_FLAG], [
AC_LANG_ASSERT([C])
_KYUA_FLAG([CC], [CFLAGS], [$1], [$2])
])
dnl Checks for a C++ compiler flag and appends it to a variable.
dnl
dnl \pre The current language is C++.
dnl
dnl \param 1 The name of the compiler flag to check for.
dnl \param 2 The shell variable to which to append $1 if the flag is valid.
AC_DEFUN([KYUA_CXX_FLAG], [
AC_LANG_ASSERT([C++])
_KYUA_FLAG([CXX], [CXXFLAGS], [$1], [$2])
])
dnl Checks for a set of C compiler flags and appends them to CFLAGS.
dnl
dnl The checks are performed independently and only when all the checks are
dnl done, the output variable is modified.
dnl
dnl \param 1 Whitespace-separated list of C flags to check.
AC_DEFUN([KYUA_CC_FLAGS], [
AC_LANG_PUSH([C])
valid_cflags=
for f in $1; do
KYUA_CC_FLAG(${f}, valid_cflags)
done
if test -n "${valid_cflags}"; then
CFLAGS="${CFLAGS} ${valid_cflags}"
fi
AC_LANG_POP([C])
])
dnl Checks for a set of C++ compiler flags and appends them to CXXFLAGS.
dnl
dnl The checks are performed independently and only when all the checks are
dnl done, the output variable is modified.
dnl
dnl \pre The current language is C++.
dnl
dnl \param 1 Whitespace-separated list of C flags to check.
AC_DEFUN([KYUA_CXX_FLAGS], [
AC_LANG_PUSH([C++])
valid_cxxflags=
for f in $1; do
KYUA_CXX_FLAG(${f}, valid_cxxflags)
done
if test -n "${valid_cxxflags}"; then
CXXFLAGS="${CXXFLAGS} ${valid_cxxflags}"
fi
AC_LANG_POP([C++])
])

79
m4/cxx-std-funcs.m4 Normal file
View file

@ -0,0 +1,79 @@
dnl
dnl Automated Testing Framework (atf)
dnl
dnl Copyright (c) 2007 The NetBSD Foundation, Inc.
dnl All rights reserved.
dnl
dnl Redistribution and use in source and binary forms, with or without
dnl modification, are permitted provided that the following conditions
dnl are met:
dnl 1. Redistributions of source code must retain the above copyright
dnl notice, this list of conditions and the following disclaimer.
dnl 2. Redistributions in binary form must reproduce the above copyright
dnl notice, this list of conditions and the following disclaimer in the
dnl documentation and/or other materials provided with the distribution.
dnl
dnl THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
dnl CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
dnl INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
dnl MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
dnl IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
dnl DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
dnl DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
dnl GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
dnl INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
dnl IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
dnl OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
dnl IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dnl
AC_DEFUN([ATF_CHECK_IN_STD], [
AC_MSG_CHECKING(whether $1 is in std)
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([$2], [$3 return 0;])],
AC_MSG_RESULT(yes)
AC_DEFINE([HAVE_]translit($1, [a-z], [A-Z])[_IN_STD], [1],
[Define to 1 if $1 is in std]),
AC_MSG_RESULT(no)
)
])
AC_DEFUN([ATF_CHECK_STD_PUTENV], [
ATF_CHECK_IN_STD([putenv],
[#include <cstdio>],
[std::putenv("a=b");]
)
])
AC_DEFUN([ATF_CHECK_STD_SETENV], [
ATF_CHECK_IN_STD([setenv],
[#include <cstdio>],
[std::setenv("a", "b");]
)
])
AC_DEFUN([ATF_CHECK_STD_SNPRINTF], [
ATF_CHECK_IN_STD([snprintf],
[#include <cstdio>],
[char buf;
std::snprintf(&buf, 1, "");]
)
])
AC_DEFUN([ATF_CHECK_STD_UNSETENV], [
ATF_CHECK_IN_STD([unsetenv],
[#include <cstdio>],
[std::unsetenv("a");]
)
])
AC_DEFUN([ATF_CHECK_STD_VSNPRINTF], [
ATF_CHECK_IN_STD([vsnprintf],
[#include <cstdarg>
#include <cstdio>],
[va_list ap;
char* buf = NULL;
const char* fmt = NULL;
std::vsnprintf(buf, 0, fmt, ap);]
)
])

112
m4/developer-mode.m4 Normal file
View file

@ -0,0 +1,112 @@
dnl Copyright 2010 Google Inc.
dnl All rights reserved.
dnl
dnl Redistribution and use in source and binary forms, with or without
dnl modification, are permitted provided that the following conditions are
dnl met:
dnl
dnl * Redistributions of source code must retain the above copyright
dnl notice, this list of conditions and the following disclaimer.
dnl * Redistributions in binary form must reproduce the above copyright
dnl notice, this list of conditions and the following disclaimer in the
dnl documentation and/or other materials provided with the distribution.
dnl * Neither the name of Google Inc. nor the names of its contributors
dnl may be used to endorse or promote products derived from this software
dnl without specific prior written permission.
dnl
dnl THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
dnl "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
dnl LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
dnl A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
dnl OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
dnl SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
dnl LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
dnl DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
dnl THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
dnl (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
dnl OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dnl \file developer-mode.m4
dnl
dnl "Developer mode" is a mode in which the build system reports any
dnl build-time warnings as fatal errors. This helps in minimizing the
dnl amount of trivial coding problems introduced in the code.
dnl Unfortunately, this is not bullet-proof due to the wide variety of
dnl compilers available and their different warning diagnostics.
dnl
dnl When developer mode support is added to a package, the compilation will
dnl gain a bunch of extra warning diagnostics. These will NOT be enforced
dnl unless developer mode is enabled.
dnl
dnl Developer mode is enabled when the user requests it through the
dnl configure command line, or when building from the repository. The
dnl latter is to minimize the risk of committing new code with warnings
dnl into the tree.
dnl Adds "developer mode" support to the package.
dnl
dnl This macro performs the actual definition of the --enable-developer
dnl flag and implements all of its logic. See the file-level comment for
dnl details as to what this implies.
AC_DEFUN([KYUA_DEVELOPER_MODE], [
m4_foreach([language], [$1], [m4_set_add([languages], language)])
AC_ARG_ENABLE(
[developer],
AS_HELP_STRING([--enable-developer], [enable developer features]),,
[if test -d ${srcdir}/.git; then
AC_MSG_NOTICE([building from HEAD; developer mode autoenabled])
enable_developer=yes
else
enable_developer=no
fi])
#
# The following warning flags should also be enabled but cannot be.
# Reasons given below.
#
# -Wold-style-cast: Raises errors when using TIOCGWINSZ, at least under
# Mac OS X. This is due to the way _IOR is defined.
#
try_c_cxx_flags="-D_FORTIFY_SOURCE=2 \
-Wall \
-Wcast-qual \
-Wextra \
-Wpointer-arith \
-Wredundant-decls \
-Wreturn-type \
-Wshadow \
-Wsign-compare \
-Wswitch \
-Wwrite-strings"
try_c_flags="-Wmissing-prototypes \
-Wno-traditional \
-Wstrict-prototypes"
try_cxx_flags="-Wabi \
-Wctor-dtor-privacy \
-Wno-deprecated \
-Wno-non-template-friend \
-Wno-pmf-conversions \
-Wnon-virtual-dtor \
-Woverloaded-virtual \
-Wreorder \
-Wsign-promo \
-Wsynth"
if test ${enable_developer} = yes; then
try_werror=yes
try_c_cxx_flags="${try_c_cxx_flags} -g -Werror"
else
try_werror=no
try_c_cxx_flags="${try_c_cxx_flags} -DNDEBUG"
fi
m4_set_contains([languages], [C],
[KYUA_CC_FLAGS(${try_c_cxx_flags} ${try_c_flags})])
m4_set_contains([languages], [C++],
[KYUA_CXX_FLAGS(${try_c_cxx_flags} ${try_cxx_flags})])
])

7357
m4/libtool.m4 vendored Normal file

File diff suppressed because it is too large Load diff

368
m4/ltoptions.m4 vendored Normal file
View file

@ -0,0 +1,368 @@
# Helper functions for option handling. -*- Autoconf -*-
#
# Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc.
# Written by Gary V. Vaughan, 2004
#
# This file is free software; the Free Software Foundation gives
# unlimited permission to copy and/or distribute it, with or without
# modifications, as long as this notice is preserved.
# serial 6 ltoptions.m4
# This is to help aclocal find these macros, as it can't see m4_define.
AC_DEFUN([LTOPTIONS_VERSION], [m4_if([1])])
# _LT_MANGLE_OPTION(MACRO-NAME, OPTION-NAME)
# ------------------------------------------
m4_define([_LT_MANGLE_OPTION],
[[_LT_OPTION_]m4_bpatsubst($1__$2, [[^a-zA-Z0-9_]], [_])])
# _LT_SET_OPTION(MACRO-NAME, OPTION-NAME)
# ---------------------------------------
# Set option OPTION-NAME for macro MACRO-NAME, and if there is a
# matching handler defined, dispatch to it. Other OPTION-NAMEs are
# saved as a flag.
m4_define([_LT_SET_OPTION],
[m4_define(_LT_MANGLE_OPTION([$1], [$2]))dnl
m4_ifdef(_LT_MANGLE_DEFUN([$1], [$2]),
_LT_MANGLE_DEFUN([$1], [$2]),
[m4_warning([Unknown $1 option `$2'])])[]dnl
])
# _LT_IF_OPTION(MACRO-NAME, OPTION-NAME, IF-SET, [IF-NOT-SET])
# ------------------------------------------------------------
# Execute IF-SET if OPTION is set, IF-NOT-SET otherwise.
m4_define([_LT_IF_OPTION],
[m4_ifdef(_LT_MANGLE_OPTION([$1], [$2]), [$3], [$4])])
# _LT_UNLESS_OPTIONS(MACRO-NAME, OPTION-LIST, IF-NOT-SET)
# -------------------------------------------------------
# Execute IF-NOT-SET unless all options in OPTION-LIST for MACRO-NAME
# are set.
m4_define([_LT_UNLESS_OPTIONS],
[m4_foreach([_LT_Option], m4_split(m4_normalize([$2])),
[m4_ifdef(_LT_MANGLE_OPTION([$1], _LT_Option),
[m4_define([$0_found])])])[]dnl
m4_ifdef([$0_found], [m4_undefine([$0_found])], [$3
])[]dnl
])
# _LT_SET_OPTIONS(MACRO-NAME, OPTION-LIST)
# ----------------------------------------
# OPTION-LIST is a space-separated list of Libtool options associated
# with MACRO-NAME. If any OPTION has a matching handler declared with
# LT_OPTION_DEFINE, dispatch to that macro; otherwise complain about
# the unknown option and exit.
m4_defun([_LT_SET_OPTIONS],
[# Set options
m4_foreach([_LT_Option], m4_split(m4_normalize([$2])),
[_LT_SET_OPTION([$1], _LT_Option)])
m4_if([$1],[LT_INIT],[
dnl
dnl Simply set some default values (i.e off) if boolean options were not
dnl specified:
_LT_UNLESS_OPTIONS([LT_INIT], [dlopen], [enable_dlopen=no
])
_LT_UNLESS_OPTIONS([LT_INIT], [win32-dll], [enable_win32_dll=no
])
dnl
dnl If no reference was made to various pairs of opposing options, then
dnl we run the default mode handler for the pair. For example, if neither
dnl `shared' nor `disable-shared' was passed, we enable building of shared
dnl archives by default:
_LT_UNLESS_OPTIONS([LT_INIT], [shared disable-shared], [_LT_ENABLE_SHARED])
_LT_UNLESS_OPTIONS([LT_INIT], [static disable-static], [_LT_ENABLE_STATIC])
_LT_UNLESS_OPTIONS([LT_INIT], [pic-only no-pic], [_LT_WITH_PIC])
_LT_UNLESS_OPTIONS([LT_INIT], [fast-install disable-fast-install],
[_LT_ENABLE_FAST_INSTALL])
])
])# _LT_SET_OPTIONS
## --------------------------------- ##
## Macros to handle LT_INIT options. ##
## --------------------------------- ##
# _LT_MANGLE_DEFUN(MACRO-NAME, OPTION-NAME)
# -----------------------------------------
m4_define([_LT_MANGLE_DEFUN],
[[_LT_OPTION_DEFUN_]m4_bpatsubst(m4_toupper([$1__$2]), [[^A-Z0-9_]], [_])])
# LT_OPTION_DEFINE(MACRO-NAME, OPTION-NAME, CODE)
# -----------------------------------------------
m4_define([LT_OPTION_DEFINE],
[m4_define(_LT_MANGLE_DEFUN([$1], [$2]), [$3])[]dnl
])# LT_OPTION_DEFINE
# dlopen
# ------
LT_OPTION_DEFINE([LT_INIT], [dlopen], [enable_dlopen=yes
])
AU_DEFUN([AC_LIBTOOL_DLOPEN],
[_LT_SET_OPTION([LT_INIT], [dlopen])
AC_DIAGNOSE([obsolete],
[$0: Remove this warning and the call to _LT_SET_OPTION when you
put the `dlopen' option into LT_INIT's first parameter.])
])
dnl aclocal-1.4 backwards compatibility:
dnl AC_DEFUN([AC_LIBTOOL_DLOPEN], [])
# win32-dll
# ---------
# Declare package support for building win32 dll's.
LT_OPTION_DEFINE([LT_INIT], [win32-dll],
[enable_win32_dll=yes
case $host in
*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-cegcc*)
AC_CHECK_TOOL(AS, as, false)
AC_CHECK_TOOL(DLLTOOL, dlltool, false)
AC_CHECK_TOOL(OBJDUMP, objdump, false)
;;
esac
test -z "$AS" && AS=as
_LT_DECL([], [AS], [0], [Assembler program])dnl
test -z "$DLLTOOL" && DLLTOOL=dlltool
_LT_DECL([], [DLLTOOL], [0], [DLL creation program])dnl
test -z "$OBJDUMP" && OBJDUMP=objdump
_LT_DECL([], [OBJDUMP], [0], [Object dumper program])dnl
])# win32-dll
AU_DEFUN([AC_LIBTOOL_WIN32_DLL],
[AC_REQUIRE([AC_CANONICAL_HOST])dnl
_LT_SET_OPTION([LT_INIT], [win32-dll])
AC_DIAGNOSE([obsolete],
[$0: Remove this warning and the call to _LT_SET_OPTION when you
put the `win32-dll' option into LT_INIT's first parameter.])
])
dnl aclocal-1.4 backwards compatibility:
dnl AC_DEFUN([AC_LIBTOOL_WIN32_DLL], [])
# _LT_ENABLE_SHARED([DEFAULT])
# ----------------------------
# implement the --enable-shared flag, and supports the `shared' and
# `disable-shared' LT_INIT options.
# DEFAULT is either `yes' or `no'. If omitted, it defaults to `yes'.
m4_define([_LT_ENABLE_SHARED],
[m4_define([_LT_ENABLE_SHARED_DEFAULT], [m4_if($1, no, no, yes)])dnl
AC_ARG_ENABLE([shared],
[AS_HELP_STRING([--enable-shared@<:@=PKGS@:>@],
[build shared libraries @<:@default=]_LT_ENABLE_SHARED_DEFAULT[@:>@])],
[p=${PACKAGE-default}
case $enableval in
yes) enable_shared=yes ;;
no) enable_shared=no ;;
*)
enable_shared=no
# Look at the argument we got. We use all the common list separators.
lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
for pkg in $enableval; do
IFS="$lt_save_ifs"
if test "X$pkg" = "X$p"; then
enable_shared=yes
fi
done
IFS="$lt_save_ifs"
;;
esac],
[enable_shared=]_LT_ENABLE_SHARED_DEFAULT)
_LT_DECL([build_libtool_libs], [enable_shared], [0],
[Whether or not to build shared libraries])
])# _LT_ENABLE_SHARED
LT_OPTION_DEFINE([LT_INIT], [shared], [_LT_ENABLE_SHARED([yes])])
LT_OPTION_DEFINE([LT_INIT], [disable-shared], [_LT_ENABLE_SHARED([no])])
# Old names:
AC_DEFUN([AC_ENABLE_SHARED],
[_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[shared])
])
AC_DEFUN([AC_DISABLE_SHARED],
[_LT_SET_OPTION([LT_INIT], [disable-shared])
])
AU_DEFUN([AM_ENABLE_SHARED], [AC_ENABLE_SHARED($@)])
AU_DEFUN([AM_DISABLE_SHARED], [AC_DISABLE_SHARED($@)])
dnl aclocal-1.4 backwards compatibility:
dnl AC_DEFUN([AM_ENABLE_SHARED], [])
dnl AC_DEFUN([AM_DISABLE_SHARED], [])
# _LT_ENABLE_STATIC([DEFAULT])
# ----------------------------
# implement the --enable-static flag, and support the `static' and
# `disable-static' LT_INIT options.
# DEFAULT is either `yes' or `no'. If omitted, it defaults to `yes'.
m4_define([_LT_ENABLE_STATIC],
[m4_define([_LT_ENABLE_STATIC_DEFAULT], [m4_if($1, no, no, yes)])dnl
AC_ARG_ENABLE([static],
[AS_HELP_STRING([--enable-static@<:@=PKGS@:>@],
[build static libraries @<:@default=]_LT_ENABLE_STATIC_DEFAULT[@:>@])],
[p=${PACKAGE-default}
case $enableval in
yes) enable_static=yes ;;
no) enable_static=no ;;
*)
enable_static=no
# Look at the argument we got. We use all the common list separators.
lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
for pkg in $enableval; do
IFS="$lt_save_ifs"
if test "X$pkg" = "X$p"; then
enable_static=yes
fi
done
IFS="$lt_save_ifs"
;;
esac],
[enable_static=]_LT_ENABLE_STATIC_DEFAULT)
_LT_DECL([build_old_libs], [enable_static], [0],
[Whether or not to build static libraries])
])# _LT_ENABLE_STATIC
LT_OPTION_DEFINE([LT_INIT], [static], [_LT_ENABLE_STATIC([yes])])
LT_OPTION_DEFINE([LT_INIT], [disable-static], [_LT_ENABLE_STATIC([no])])
# Old names:
AC_DEFUN([AC_ENABLE_STATIC],
[_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[static])
])
AC_DEFUN([AC_DISABLE_STATIC],
[_LT_SET_OPTION([LT_INIT], [disable-static])
])
AU_DEFUN([AM_ENABLE_STATIC], [AC_ENABLE_STATIC($@)])
AU_DEFUN([AM_DISABLE_STATIC], [AC_DISABLE_STATIC($@)])
dnl aclocal-1.4 backwards compatibility:
dnl AC_DEFUN([AM_ENABLE_STATIC], [])
dnl AC_DEFUN([AM_DISABLE_STATIC], [])
# _LT_ENABLE_FAST_INSTALL([DEFAULT])
# ----------------------------------
# implement the --enable-fast-install flag, and support the `fast-install'
# and `disable-fast-install' LT_INIT options.
# DEFAULT is either `yes' or `no'. If omitted, it defaults to `yes'.
m4_define([_LT_ENABLE_FAST_INSTALL],
[m4_define([_LT_ENABLE_FAST_INSTALL_DEFAULT], [m4_if($1, no, no, yes)])dnl
AC_ARG_ENABLE([fast-install],
[AS_HELP_STRING([--enable-fast-install@<:@=PKGS@:>@],
[optimize for fast installation @<:@default=]_LT_ENABLE_FAST_INSTALL_DEFAULT[@:>@])],
[p=${PACKAGE-default}
case $enableval in
yes) enable_fast_install=yes ;;
no) enable_fast_install=no ;;
*)
enable_fast_install=no
# Look at the argument we got. We use all the common list separators.
lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
for pkg in $enableval; do
IFS="$lt_save_ifs"
if test "X$pkg" = "X$p"; then
enable_fast_install=yes
fi
done
IFS="$lt_save_ifs"
;;
esac],
[enable_fast_install=]_LT_ENABLE_FAST_INSTALL_DEFAULT)
_LT_DECL([fast_install], [enable_fast_install], [0],
[Whether or not to optimize for fast installation])dnl
])# _LT_ENABLE_FAST_INSTALL
LT_OPTION_DEFINE([LT_INIT], [fast-install], [_LT_ENABLE_FAST_INSTALL([yes])])
LT_OPTION_DEFINE([LT_INIT], [disable-fast-install], [_LT_ENABLE_FAST_INSTALL([no])])
# Old names:
AU_DEFUN([AC_ENABLE_FAST_INSTALL],
[_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[fast-install])
AC_DIAGNOSE([obsolete],
[$0: Remove this warning and the call to _LT_SET_OPTION when you put
the `fast-install' option into LT_INIT's first parameter.])
])
AU_DEFUN([AC_DISABLE_FAST_INSTALL],
[_LT_SET_OPTION([LT_INIT], [disable-fast-install])
AC_DIAGNOSE([obsolete],
[$0: Remove this warning and the call to _LT_SET_OPTION when you put
the `disable-fast-install' option into LT_INIT's first parameter.])
])
dnl aclocal-1.4 backwards compatibility:
dnl AC_DEFUN([AC_ENABLE_FAST_INSTALL], [])
dnl AC_DEFUN([AM_DISABLE_FAST_INSTALL], [])
# _LT_WITH_PIC([MODE])
# --------------------
# implement the --with-pic flag, and support the `pic-only' and `no-pic'
# LT_INIT options.
# MODE is either `yes' or `no'. If omitted, it defaults to `both'.
m4_define([_LT_WITH_PIC],
[AC_ARG_WITH([pic],
[AS_HELP_STRING([--with-pic],
[try to use only PIC/non-PIC objects @<:@default=use both@:>@])],
[pic_mode="$withval"],
[pic_mode=default])
test -z "$pic_mode" && pic_mode=m4_default([$1], [default])
_LT_DECL([], [pic_mode], [0], [What type of objects to build])dnl
])# _LT_WITH_PIC
LT_OPTION_DEFINE([LT_INIT], [pic-only], [_LT_WITH_PIC([yes])])
LT_OPTION_DEFINE([LT_INIT], [no-pic], [_LT_WITH_PIC([no])])
# Old name:
AU_DEFUN([AC_LIBTOOL_PICMODE],
[_LT_SET_OPTION([LT_INIT], [pic-only])
AC_DIAGNOSE([obsolete],
[$0: Remove this warning and the call to _LT_SET_OPTION when you
put the `pic-only' option into LT_INIT's first parameter.])
])
dnl aclocal-1.4 backwards compatibility:
dnl AC_DEFUN([AC_LIBTOOL_PICMODE], [])
## ----------------- ##
## LTDL_INIT Options ##
## ----------------- ##
m4_define([_LTDL_MODE], [])
LT_OPTION_DEFINE([LTDL_INIT], [nonrecursive],
[m4_define([_LTDL_MODE], [nonrecursive])])
LT_OPTION_DEFINE([LTDL_INIT], [recursive],
[m4_define([_LTDL_MODE], [recursive])])
LT_OPTION_DEFINE([LTDL_INIT], [subproject],
[m4_define([_LTDL_MODE], [subproject])])
m4_define([_LTDL_TYPE], [])
LT_OPTION_DEFINE([LTDL_INIT], [installable],
[m4_define([_LTDL_TYPE], [installable])])
LT_OPTION_DEFINE([LTDL_INIT], [convenience],
[m4_define([_LTDL_TYPE], [convenience])])

123
m4/ltsugar.m4 vendored Normal file
View file

@ -0,0 +1,123 @@
# ltsugar.m4 -- libtool m4 base layer. -*-Autoconf-*-
#
# Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc.
# Written by Gary V. Vaughan, 2004
#
# This file is free software; the Free Software Foundation gives
# unlimited permission to copy and/or distribute it, with or without
# modifications, as long as this notice is preserved.
# serial 6 ltsugar.m4
# This is to help aclocal find these macros, as it can't see m4_define.
AC_DEFUN([LTSUGAR_VERSION], [m4_if([0.1])])
# lt_join(SEP, ARG1, [ARG2...])
# -----------------------------
# Produce ARG1SEPARG2...SEPARGn, omitting [] arguments and their
# associated separator.
# Needed until we can rely on m4_join from Autoconf 2.62, since all earlier
# versions in m4sugar had bugs.
m4_define([lt_join],
[m4_if([$#], [1], [],
[$#], [2], [[$2]],
[m4_if([$2], [], [], [[$2]_])$0([$1], m4_shift(m4_shift($@)))])])
m4_define([_lt_join],
[m4_if([$#$2], [2], [],
[m4_if([$2], [], [], [[$1$2]])$0([$1], m4_shift(m4_shift($@)))])])
# lt_car(LIST)
# lt_cdr(LIST)
# ------------
# Manipulate m4 lists.
# These macros are necessary as long as will still need to support
# Autoconf-2.59 which quotes differently.
m4_define([lt_car], [[$1]])
m4_define([lt_cdr],
[m4_if([$#], 0, [m4_fatal([$0: cannot be called without arguments])],
[$#], 1, [],
[m4_dquote(m4_shift($@))])])
m4_define([lt_unquote], $1)
# lt_append(MACRO-NAME, STRING, [SEPARATOR])
# ------------------------------------------
# Redefine MACRO-NAME to hold its former content plus `SEPARATOR'`STRING'.
# Note that neither SEPARATOR nor STRING are expanded; they are appended
# to MACRO-NAME as is (leaving the expansion for when MACRO-NAME is invoked).
# No SEPARATOR is output if MACRO-NAME was previously undefined (different
# than defined and empty).
#
# This macro is needed until we can rely on Autoconf 2.62, since earlier
# versions of m4sugar mistakenly expanded SEPARATOR but not STRING.
m4_define([lt_append],
[m4_define([$1],
m4_ifdef([$1], [m4_defn([$1])[$3]])[$2])])
# lt_combine(SEP, PREFIX-LIST, INFIX, SUFFIX1, [SUFFIX2...])
# ----------------------------------------------------------
# Produce a SEP delimited list of all paired combinations of elements of
# PREFIX-LIST with SUFFIX1 through SUFFIXn. Each element of the list
# has the form PREFIXmINFIXSUFFIXn.
# Needed until we can rely on m4_combine added in Autoconf 2.62.
m4_define([lt_combine],
[m4_if(m4_eval([$# > 3]), [1],
[m4_pushdef([_Lt_sep], [m4_define([_Lt_sep], m4_defn([lt_car]))])]]dnl
[[m4_foreach([_Lt_prefix], [$2],
[m4_foreach([_Lt_suffix],
]m4_dquote(m4_dquote(m4_shift(m4_shift(m4_shift($@)))))[,
[_Lt_sep([$1])[]m4_defn([_Lt_prefix])[$3]m4_defn([_Lt_suffix])])])])])
# lt_if_append_uniq(MACRO-NAME, VARNAME, [SEPARATOR], [UNIQ], [NOT-UNIQ])
# -----------------------------------------------------------------------
# Iff MACRO-NAME does not yet contain VARNAME, then append it (delimited
# by SEPARATOR if supplied) and expand UNIQ, else NOT-UNIQ.
m4_define([lt_if_append_uniq],
[m4_ifdef([$1],
[m4_if(m4_index([$3]m4_defn([$1])[$3], [$3$2$3]), [-1],
[lt_append([$1], [$2], [$3])$4],
[$5])],
[lt_append([$1], [$2], [$3])$4])])
# lt_dict_add(DICT, KEY, VALUE)
# -----------------------------
m4_define([lt_dict_add],
[m4_define([$1($2)], [$3])])
# lt_dict_add_subkey(DICT, KEY, SUBKEY, VALUE)
# --------------------------------------------
m4_define([lt_dict_add_subkey],
[m4_define([$1($2:$3)], [$4])])
# lt_dict_fetch(DICT, KEY, [SUBKEY])
# ----------------------------------
m4_define([lt_dict_fetch],
[m4_ifval([$3],
m4_ifdef([$1($2:$3)], [m4_defn([$1($2:$3)])]),
m4_ifdef([$1($2)], [m4_defn([$1($2)])]))])
# lt_if_dict_fetch(DICT, KEY, [SUBKEY], VALUE, IF-TRUE, [IF-FALSE])
# -----------------------------------------------------------------
m4_define([lt_if_dict_fetch],
[m4_if(lt_dict_fetch([$1], [$2], [$3]), [$4],
[$5],
[$6])])
# lt_dict_filter(DICT, [SUBKEY], VALUE, [SEPARATOR], KEY, [...])
# --------------------------------------------------------------
m4_define([lt_dict_filter],
[m4_if([$5], [], [],
[lt_join(m4_quote(m4_default([$4], [[, ]])),
lt_unquote(m4_split(m4_normalize(m4_foreach(_Lt_key, lt_car([m4_shiftn(4, $@)]),
[lt_if_dict_fetch([$1], _Lt_key, [$2], [$3], [_Lt_key ])])))))])[]dnl
])

23
m4/ltversion.m4 vendored Normal file
View file

@ -0,0 +1,23 @@
# ltversion.m4 -- version numbers -*- Autoconf -*-
#
# Copyright (C) 2004 Free Software Foundation, Inc.
# Written by Scott James Remnant, 2004
#
# This file is free software; the Free Software Foundation gives
# unlimited permission to copy and/or distribute it, with or without
# modifications, as long as this notice is preserved.
# Generated from ltversion.in.
# serial 3017 ltversion.m4
# This file is part of GNU Libtool
m4_define([LT_PACKAGE_VERSION], [2.2.6b])
m4_define([LT_PACKAGE_REVISION], [1.3017])
AC_DEFUN([LTVERSION_VERSION],
[macro_version='2.2.6b'
macro_revision='1.3017'
_LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?])
_LT_DECL(, macro_revision, 0)
])

92
m4/lt~obsolete.m4 vendored Normal file
View file

@ -0,0 +1,92 @@
# lt~obsolete.m4 -- aclocal satisfying obsolete definitions. -*-Autoconf-*-
#
# Copyright (C) 2004, 2005, 2007 Free Software Foundation, Inc.
# Written by Scott James Remnant, 2004.
#
# This file is free software; the Free Software Foundation gives
# unlimited permission to copy and/or distribute it, with or without
# modifications, as long as this notice is preserved.
# serial 4 lt~obsolete.m4
# These exist entirely to fool aclocal when bootstrapping libtool.
#
# In the past libtool.m4 has provided macros via AC_DEFUN (or AU_DEFUN)
# which have later been changed to m4_define as they aren't part of the
# exported API, or moved to Autoconf or Automake where they belong.
#
# The trouble is, aclocal is a bit thick. It'll see the old AC_DEFUN
# in /usr/share/aclocal/libtool.m4 and remember it, then when it sees us
# using a macro with the same name in our local m4/libtool.m4 it'll
# pull the old libtool.m4 in (it doesn't see our shiny new m4_define
# and doesn't know about Autoconf macros at all.)
#
# So we provide this file, which has a silly filename so it's always
# included after everything else. This provides aclocal with the
# AC_DEFUNs it wants, but when m4 processes it, it doesn't do anything
# because those macros already exist, or will be overwritten later.
# We use AC_DEFUN over AU_DEFUN for compatibility with aclocal-1.6.
#
# Anytime we withdraw an AC_DEFUN or AU_DEFUN, remember to add it here.
# Yes, that means every name once taken will need to remain here until
# we give up compatibility with versions before 1.7, at which point
# we need to keep only those names which we still refer to.
# This is to help aclocal find these macros, as it can't see m4_define.
AC_DEFUN([LTOBSOLETE_VERSION], [m4_if([1])])
m4_ifndef([AC_LIBTOOL_LINKER_OPTION], [AC_DEFUN([AC_LIBTOOL_LINKER_OPTION])])
m4_ifndef([AC_PROG_EGREP], [AC_DEFUN([AC_PROG_EGREP])])
m4_ifndef([_LT_AC_PROG_ECHO_BACKSLASH], [AC_DEFUN([_LT_AC_PROG_ECHO_BACKSLASH])])
m4_ifndef([_LT_AC_SHELL_INIT], [AC_DEFUN([_LT_AC_SHELL_INIT])])
m4_ifndef([_LT_AC_SYS_LIBPATH_AIX], [AC_DEFUN([_LT_AC_SYS_LIBPATH_AIX])])
m4_ifndef([_LT_PROG_LTMAIN], [AC_DEFUN([_LT_PROG_LTMAIN])])
m4_ifndef([_LT_AC_TAGVAR], [AC_DEFUN([_LT_AC_TAGVAR])])
m4_ifndef([AC_LTDL_ENABLE_INSTALL], [AC_DEFUN([AC_LTDL_ENABLE_INSTALL])])
m4_ifndef([AC_LTDL_PREOPEN], [AC_DEFUN([AC_LTDL_PREOPEN])])
m4_ifndef([_LT_AC_SYS_COMPILER], [AC_DEFUN([_LT_AC_SYS_COMPILER])])
m4_ifndef([_LT_AC_LOCK], [AC_DEFUN([_LT_AC_LOCK])])
m4_ifndef([AC_LIBTOOL_SYS_OLD_ARCHIVE], [AC_DEFUN([AC_LIBTOOL_SYS_OLD_ARCHIVE])])
m4_ifndef([_LT_AC_TRY_DLOPEN_SELF], [AC_DEFUN([_LT_AC_TRY_DLOPEN_SELF])])
m4_ifndef([AC_LIBTOOL_PROG_CC_C_O], [AC_DEFUN([AC_LIBTOOL_PROG_CC_C_O])])
m4_ifndef([AC_LIBTOOL_SYS_HARD_LINK_LOCKS], [AC_DEFUN([AC_LIBTOOL_SYS_HARD_LINK_LOCKS])])
m4_ifndef([AC_LIBTOOL_OBJDIR], [AC_DEFUN([AC_LIBTOOL_OBJDIR])])
m4_ifndef([AC_LTDL_OBJDIR], [AC_DEFUN([AC_LTDL_OBJDIR])])
m4_ifndef([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH], [AC_DEFUN([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH])])
m4_ifndef([AC_LIBTOOL_SYS_LIB_STRIP], [AC_DEFUN([AC_LIBTOOL_SYS_LIB_STRIP])])
m4_ifndef([AC_PATH_MAGIC], [AC_DEFUN([AC_PATH_MAGIC])])
m4_ifndef([AC_PROG_LD_GNU], [AC_DEFUN([AC_PROG_LD_GNU])])
m4_ifndef([AC_PROG_LD_RELOAD_FLAG], [AC_DEFUN([AC_PROG_LD_RELOAD_FLAG])])
m4_ifndef([AC_DEPLIBS_CHECK_METHOD], [AC_DEFUN([AC_DEPLIBS_CHECK_METHOD])])
m4_ifndef([AC_LIBTOOL_PROG_COMPILER_NO_RTTI], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_NO_RTTI])])
m4_ifndef([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE], [AC_DEFUN([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE])])
m4_ifndef([AC_LIBTOOL_PROG_COMPILER_PIC], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_PIC])])
m4_ifndef([AC_LIBTOOL_PROG_LD_SHLIBS], [AC_DEFUN([AC_LIBTOOL_PROG_LD_SHLIBS])])
m4_ifndef([AC_LIBTOOL_POSTDEP_PREDEP], [AC_DEFUN([AC_LIBTOOL_POSTDEP_PREDEP])])
m4_ifndef([LT_AC_PROG_EGREP], [AC_DEFUN([LT_AC_PROG_EGREP])])
m4_ifndef([LT_AC_PROG_SED], [AC_DEFUN([LT_AC_PROG_SED])])
m4_ifndef([_LT_CC_BASENAME], [AC_DEFUN([_LT_CC_BASENAME])])
m4_ifndef([_LT_COMPILER_BOILERPLATE], [AC_DEFUN([_LT_COMPILER_BOILERPLATE])])
m4_ifndef([_LT_LINKER_BOILERPLATE], [AC_DEFUN([_LT_LINKER_BOILERPLATE])])
m4_ifndef([_AC_PROG_LIBTOOL], [AC_DEFUN([_AC_PROG_LIBTOOL])])
m4_ifndef([AC_LIBTOOL_SETUP], [AC_DEFUN([AC_LIBTOOL_SETUP])])
m4_ifndef([_LT_AC_CHECK_DLFCN], [AC_DEFUN([_LT_AC_CHECK_DLFCN])])
m4_ifndef([AC_LIBTOOL_SYS_DYNAMIC_LINKER], [AC_DEFUN([AC_LIBTOOL_SYS_DYNAMIC_LINKER])])
m4_ifndef([_LT_AC_TAGCONFIG], [AC_DEFUN([_LT_AC_TAGCONFIG])])
m4_ifndef([AC_DISABLE_FAST_INSTALL], [AC_DEFUN([AC_DISABLE_FAST_INSTALL])])
m4_ifndef([_LT_AC_LANG_CXX], [AC_DEFUN([_LT_AC_LANG_CXX])])
m4_ifndef([_LT_AC_LANG_F77], [AC_DEFUN([_LT_AC_LANG_F77])])
m4_ifndef([_LT_AC_LANG_GCJ], [AC_DEFUN([_LT_AC_LANG_GCJ])])
m4_ifndef([AC_LIBTOOL_RC], [AC_DEFUN([AC_LIBTOOL_RC])])
m4_ifndef([AC_LIBTOOL_LANG_C_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_C_CONFIG])])
m4_ifndef([_LT_AC_LANG_C_CONFIG], [AC_DEFUN([_LT_AC_LANG_C_CONFIG])])
m4_ifndef([AC_LIBTOOL_LANG_CXX_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_CXX_CONFIG])])
m4_ifndef([_LT_AC_LANG_CXX_CONFIG], [AC_DEFUN([_LT_AC_LANG_CXX_CONFIG])])
m4_ifndef([AC_LIBTOOL_LANG_F77_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_F77_CONFIG])])
m4_ifndef([_LT_AC_LANG_F77_CONFIG], [AC_DEFUN([_LT_AC_LANG_F77_CONFIG])])
m4_ifndef([AC_LIBTOOL_LANG_GCJ_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_GCJ_CONFIG])])
m4_ifndef([_LT_AC_LANG_GCJ_CONFIG], [AC_DEFUN([_LT_AC_LANG_GCJ_CONFIG])])
m4_ifndef([AC_LIBTOOL_LANG_RC_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_RC_CONFIG])])
m4_ifndef([_LT_AC_LANG_RC_CONFIG], [AC_DEFUN([_LT_AC_LANG_RC_CONFIG])])
m4_ifndef([AC_LIBTOOL_CONFIG], [AC_DEFUN([AC_LIBTOOL_CONFIG])])
m4_ifndef([_LT_AC_FILE_LTDLL_C], [AC_DEFUN([_LT_AC_FILE_LTDLL_C])])

94
m4/module-application.m4 Normal file
View file

@ -0,0 +1,94 @@
dnl
dnl Automated Testing Framework (atf)
dnl
dnl Copyright (c) 2007 The NetBSD Foundation, Inc.
dnl All rights reserved.
dnl
dnl Redistribution and use in source and binary forms, with or without
dnl modification, are permitted provided that the following conditions
dnl are met:
dnl 1. Redistributions of source code must retain the above copyright
dnl notice, this list of conditions and the following disclaimer.
dnl 2. Redistributions in binary form must reproduce the above copyright
dnl notice, this list of conditions and the following disclaimer in the
dnl documentation and/or other materials provided with the distribution.
dnl
dnl THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
dnl CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
dnl INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
dnl MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
dnl IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
dnl DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
dnl DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
dnl GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
dnl INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
dnl IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
dnl OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
dnl IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dnl
AC_DEFUN([ATF_MODULE_APPLICATION], [
ATF_CHECK_STD_VSNPRINTF
AC_CACHE_CHECK(
[whether getopt allows a + sign for POSIX behavior],
[kyua_cv_getopt_plus], [
AC_LANG_PUSH([C])
AC_RUN_IFELSE([AC_LANG_PROGRAM([#include <stdlib.h>
#include <string.h>
#include <unistd.h>], [
int argc = 4;
char* argv@<:@5@:>@ = {
strdup("conftest"),
strdup("-+"),
strdup("-a"),
strdup("bar"),
NULL
};
int ch;
int seen_a = 0, seen_plus = 0;
while ((ch = getopt(argc, argv, "+a:")) != -1) {
switch (ch) {
case 'a':
seen_a = 1;
break;
case '+':
seen_plus = 1;
break;
case '?':
default:
;
}
}
return (seen_a && !seen_plus) ? EXIT_SUCCESS : EXIT_FAILURE;
])],
[kyua_cv_getopt_plus=yes],
[kyua_cv_getopt_plus=no])
AC_LANG_POP([C])
])
if test x"${kyua_cv_getopt_plus}" = xyes; then
AC_DEFINE([HAVE_GNU_GETOPT], [1],
[Define to 1 if getopt allows a + sign for POSIX behavior])
fi
AC_CACHE_CHECK(
[whether getopt has optreset],
[kyua_cv_getopt_optreset], [
AC_LANG_PUSH([C])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <stdlib.h>
#include <unistd.h>], [
optreset = 1;
return EXIT_SUCCESS;
])],
[kyua_cv_getopt_optreset=yes],
[kyua_cv_getopt_optreset=no])
AC_LANG_POP([C])
])
if test x"${kyua_cv_getopt_optreset}" = xyes; then
AC_DEFINE([HAVE_OPTRESET], [1], [Define to 1 if getopt has optreset])
fi
])

112
m4/module-defs.m4 Normal file
View file

@ -0,0 +1,112 @@
dnl
dnl Automated Testing Framework (atf)
dnl
dnl Copyright (c) 2008 The NetBSD Foundation, Inc.
dnl All rights reserved.
dnl
dnl Redistribution and use in source and binary forms, with or without
dnl modification, are permitted provided that the following conditions
dnl are met:
dnl 1. Redistributions of source code must retain the above copyright
dnl notice, this list of conditions and the following disclaimer.
dnl 2. Redistributions in binary form must reproduce the above copyright
dnl notice, this list of conditions and the following disclaimer in the
dnl documentation and/or other materials provided with the distribution.
dnl
dnl THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
dnl CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
dnl INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
dnl MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
dnl IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
dnl DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
dnl DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
dnl GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
dnl INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
dnl IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
dnl OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
dnl IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dnl
AC_DEFUN([ATF_ATTRIBUTE_FORMAT_PRINTF], [
AC_MSG_CHECKING(
[whether __attribute__((__format__(__printf__, a, b))) is supported])
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([
#include <stdarg.h>
#include <stdio.h>
static void test_printf(const char *, ...)
__attribute__((__format__(__printf__, 1, 2)));
static void
test_printf(const char *format, ...)
{
va_list ap;
va_start(ap, format);
vprintf(format, ap);
va_end(ap);
}], [
test_printf("foo %s", "bar");
return 0;
])],
[AC_MSG_RESULT(yes)
value="__attribute__((__format__(__printf__, a, b)))"],
[AC_MSG_RESULT(no)
value=""]
)
AC_SUBST([ATTRIBUTE_FORMAT_PRINTF], [${value}])
])
AC_DEFUN([ATF_ATTRIBUTE_NORETURN], [
dnl XXX This check is overly simple and should be fixed. For example,
dnl Sun's cc does support the noreturn attribute but CC (the C++
dnl compiler) does not. And in that case, CC just raises a warning
dnl during compilation, not an error, which later breaks the
dnl atf-c++/t_pkg_config:cxx_build check.
AC_CACHE_CHECK(
[whether __attribute__((__noreturn__)) is supported],
[kyua_cv_attribute_noreturn], [
AC_RUN_IFELSE(
[AC_LANG_PROGRAM([], [
#if ((__GNUC__ == 2 && __GNUC_MINOR__ >= 5) || __GNUC__ > 2)
return 0;
#else
return 1;
#endif
])],
[kyua_cv_attribute_noreturn=yes],
[kyua_cv_attribute_noreturn=no])
])
if test x"${kyua_cv_attribute_noreturn}" = xyes; then
value="__attribute__((__noreturn__))"
else
value=""
fi
AC_SUBST([ATTRIBUTE_NORETURN], [${value}])
])
AC_DEFUN([ATF_ATTRIBUTE_UNUSED], [
AC_MSG_CHECKING(whether __attribute__((__unused__)) is supported)
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([
static void
function(int a __attribute__((__unused__)))
{
}], [
function(3);
return 0;
])],
[AC_MSG_RESULT(yes)
value="__attribute__((__unused__))"],
[AC_MSG_RESULT(no)
value=""]
)
AC_SUBST([ATTRIBUTE_UNUSED], [${value}])
])
AC_DEFUN([ATF_MODULE_DEFS], [
ATF_ATTRIBUTE_FORMAT_PRINTF
ATF_ATTRIBUTE_NORETURN
ATF_ATTRIBUTE_UNUSED
])

Some files were not shown because too many files have changed in this diff Show more