brarcher [Tue, 17 Dec 2013 16:06:53 +0000 (16:06 +0000)]
Add tests for tap logging
These tests follow closely with what the logging tests cover, with
one small change. If fork() is disabled, one test case will
invoked exit() and cause the unit testing program to terminate
early. In that case, the tap output is expected to be incomplete.
brarcher [Tue, 17 Dec 2013 16:06:50 +0000 (16:06 +0000)]
add support for logging in TAP format
Logging in the Test Anything Protcol (TAP) format is useful
in general, but is especially useful on platforms where
fork() is unavailable. The TAP format requires that the
planned number of tests to run be specified, either at the
start or end of a test run. If the number of tests run does not
match the plan, the test run is marked as failed. As running
without fork() leaves the unit testing program open to failure
if a test aborts/segfaults/etc, validating the TAP output is
useful.
brarcher [Tue, 17 Dec 2013 03:28:26 +0000 (03:28 +0000)]
check.h: only mark _ck_assert_failed as noreturn when using fork
When fork is used, _ck_assert_failed will call exit() when a
failure occurs. Marking it as noreturn makes sense in this case.
When fork() is not used, longjmp() is called, which is a type of
return. Marking it as noreturn allows the compiler (gcc) to
make assumptions which are not true. Using longjmp causes
the unit testing program to segfault.
For this reason, the function is only marked as noreturn when
using fork(). Any static source code analysis to catch issues
must be done on a system with fork() to avoid possible false
positives.
brarcher [Mon, 16 Dec 2013 23:27:14 +0000 (23:27 +0000)]
change how assertions are called, to support source code analyzers
The assert functions that check provides are really macros that
funnel down to the _ck_assert_msg() function. That function receives
the result from the operation being checked, then decides if the unit
test should continue or should halt.
The assert function in C is sometimes also a macro. For example, the
following:
The __assert_rtn function is marked as "noreturn", and only gets invoked
when an assertion has failed. Because it only gets called when something
bad has happened, static code analysis can reason about when it is and is
not called, and make assumptions about the code being compiled.
To the point, this change refactors check's assert macros in such a way
that they result in a function being called only when the assertion
fails, and thus static code analyzers (such as clang's scan-build tool)
can reason when something is possible and impossible in test code. As a
result, if one wanted to run static analysis on unit test code, there
would be far fewer false positives.
brarcher [Mon, 16 Dec 2013 16:29:34 +0000 (16:29 +0000)]
web: change layout of landing page
Instead of a plain black/white page with text, the new layout
contains some color, a side pane with links and info on the
latest release, and some links.
All data related to the page is in the new subfolder "web".
The layout was from Open Source Web Design (oswd.org), and is
the NewsPortal layout by "Designs by Darren".
Compiled using gcc 4.7.2 with -Wall gives the following warning.
myfile.c:70:2: warning: initialization discards ‘const’ qualifier from pointer target type [enabled by default]
Adding a const qualifier to the variables in the _ck_assert_ptr macro,
as done for _ck_assert_str makes the problem go away.
brarcher [Thu, 24 Oct 2013 02:14:55 +0000 (02:14 +0000)]
change check for valid clockid
cygwin does not support CLOCK_MONOTONIC. However, a call to
clock_gettime(CLOCK_MONOTONIC, ...) will pass, whereas
a timer_create(CLOCK_MONOTONIC, ...) will fail. Use the
timer_create() call for the check instead.
However, be careful to only make the check if librt is available,
otherwise it is a waste. Or worse, if librt and alarm() are
unavailable, a timer_delete() will result in an assert(0).
brarcher [Mon, 21 Oct 2013 03:26:29 +0000 (03:26 +0000)]
configure.ac: do not compile with -ansi for now
There is currently a bug on the MinGW/MinGW-w64 platforms:
sourceforge.net/p/mingw/bugs/2024
where compiling with -ansi will not define the off64_t type,
but including unistd.h will require it to be defined else
a compile error will result.
Attempting to define a replacement in config.h also fails; config.h
will work for check's code, but the code that libtool produces
then fails, meaning unit tests fail to compile.
When the MinGW bug is resolved, we can start compiling with -ansi again.
brarcher [Mon, 21 Oct 2013 03:26:27 +0000 (03:26 +0000)]
configure.ac: also use pthread.h for time struct checks
In MinGW and MinGW-w64, the timespec and itimerspec structs
are defined in pthread.h instead of time.h. To properly
check for this, we now also will include pthread.h if it is
available on the system.
brarcher [Mon, 14 Oct 2013 23:03:27 +0000 (23:03 +0000)]
snprintf: disable 'long long', as is not supported in C90
-Wlong-long warns that C90 does not support the 'long long' data type.
However, the snprintf replacement provides support for it. As
check does not use long long anywhere, and also does not
use it to print anything, references to the data types are removed
from the snprintf replacement.
brarcher [Mon, 14 Oct 2013 23:03:17 +0000 (23:03 +0000)]
Add configure option to force snprintf replacement
The configure argument --enable-snprintf-replacement will be used
for force the snprintf replacement in libcompat to be compiled,
even on systems that provide a C99 compliant replacement.
This will be useful for vetting the replacement, as a system
without a C99 snprintf may not be readily available.
brarcher [Fri, 4 Oct 2013 01:38:08 +0000 (01:38 +0000)]
silence warning about ck_do_nothing being able to return
The prototype for ck_do_nothing marks it as noreturn.
gcc thought that the function could still return. Adding
an exit() call at the end (although the assert() will not
let it get that far) to silence the warning.
brarcher [Thu, 3 Oct 2013 02:01:48 +0000 (02:01 +0000)]
Remove -Werror from automake
On newer versions of automake, doc/Makefile.am causes a warning:
It appears this file (or files included by it) are triggering
an undocumented, soon-to-be-removed automake hack.
Future automake versions will no longer place in the builddir
(rather than in the srcdir) the generated '.info' files that
appear to be cleaned, by e.g. being listed in CLEANFILES or
DISTCLEANFILES. If you want your '.info' files to be placed in the
builddir rather than in the srcdir, you have to use the
shiny new 'info-in-builddir' automake option.
brarcher [Tue, 1 Oct 2013 22:21:08 +0000 (22:21 +0000)]
If clocks are not defined, set to (hopefully) invalid value
Likely, if clock_gettime() is implemented on a system, the first
valid clock will be set to '0'. If not all clock are defined,
by setting our fake definitions to '0', we may accidental use a
valid clock when we did not mean to. Setting the clocks to '-1'
in hopes to avoid this.
if tmpfile() fails, remember the filename and delete it later
One feature of tmpfile() is to unlink the file, causing it to be
deleted after it is closed. Unlinking an open file fails in Windows.
To prevent the case where the temp directory just fills up with
files, the created file name is remembered, and deleted when
it is closed.
Certainly, if a unit test fails before it deletes the file,
the temp directory will still fill up. However, this is better
than not deleting the files.
There is some issue with MinGW-w64 builds run on wine, if multiple
unit test programs are run concurrently. Sometimes they will fail
to get something from punpack. It may be a failure to read the file,
or the file, or some other issue.
When this happens, later in receive_test_result the rmesg is free'd,
but only by freeing its elements first, which causes a segfault.
Instead of crashing, check should error out gracefully.
If tmpfile() fails, try to make a unique file with tempnam() and getpid()
On systems where tmpfile() does not work, we try to fallback on
using tempnam() and fopen() to get a temporary unique file.
However, tempnam is not enough to get a unique name. Between
getting the name and opening the file, something else also
calling tempnam() could get the same name. It has been observed
on MinGW-w64 builds on Wine that this exact thing happens
if multiple instances of a unit tests are running concurrently.
To prevent two concurrent unit tests from getting the same file,
we append the pid to the file. The pid should be unique on the
system.
Do not make decision based on fork status for which ctx to assign
This condition worked when the fork status was CK_FORK. However,
if the fork status was CK_NOFORK, it would fail. The values of
lastctx and failctx would be the same, however the wrong one would
be written if CK_NOFORK was being used.
There does not seem to be any reason why lastctx could not be used
all the time. No decision in messaging seems to be related to
the fork status.
test_check_nofork: removing assumption that HAVE_FORK=0 implied Windows
With the configuration option --disable-fork, *nix systems
can also be compiled without using fork. To fix the
line encoding, sed is used to remove \r before the check.
test_output: removing assumption that HAVE_FORK=0 implied Windows
With the configuration option --disable-fork, *nix systems
can also be compiled without using fork. To fix the
line encoding, sed is used to remove \r before the check.
test_log_output: removing assumption that HAVE_FORK=0 implied Windows
With the configuration option --disable-fork, *nix systems
can also be compiled without using fork. To fix the
line encoding, sed is used to remove \r before the check.
This test is only valid on platforms that have a functional
clock_gettime() and do not have a good replacement in libcompat.
If there is no good replacement, then all durations will be 0,
even during failures. Instead of forcing the duration to be
negative during a failure artificially, we remove the requirement.
test_xml_output: removing assumption that HAVE_FORK=0 implied Windows
With the configuration option --disable-fork, *nix systems
can also be compiled without using fork. To fix the
line encodings, sed is used to remove \r before the check.
The code at the top of this file for signals and fork is protected by
HAVE_FORK. The signals usage is not very useful without fork, so
now protecting the signal code with HAVE_FORK as well.
disable checked signal tests if fork is unavailable
As mentioned in a previous commit, checked fixtures are disabled
if fork is unavailable, as they are unable to provide the guarantees
that they advertise without fork.
In addition, some line numbers are updated. This is because some tests
are looking through error messages, and the line number of the
messages is important.
checked fixtures allow setup and teardown functions to be run in the
same process space as tests. If a fixture fails, the error is caught
and reported as a failure for the associated test.
If fork is not used, then the guarantee that checked fixtures try to
provide is not possible. Further, using checked fixtures without fork can
cause issues. For example, without fork if a checked teardown
calls ck_assert() which fails, this results in longjmp being called,
which results in the teardowns being called again. An infinate loop
results.
Add noreturn attribute to select functions and added -Wmissing-noreturn
Added the gcc attribute noreturn to a few functions that could use it
(but only if the compiler is gcc 2.5 >=), and added the warning to
point out when a function should use noreturn.
Determine at runtime which clockid_t to use for clock_gettime
The cygwin platform (perhaps others) does not support
CLOCK_MONOTONIC in clock_gettime. However, it does support
CLOCK_REALTIME. Instead of having every call to clock_gettime
check which clock to use, check once and cache the result.
The only two clock options which seemed useful are CLOCK_MONOTONIC
and CLOCK_REALTIME. If others are available in the future
(or another clock type seems a good alternative if these two are
missing on a system) it can be added later.
Do not expect the duration for no-fork mode tests to be negative
For tests using fork, if the test fails exit() is called, which results
in the duration not being recorded for the test.
no-fork mode instead requires all tests to return, meaning their
duration is always recorded.
The test_xml_output.sh test expected that all failed tests have a negative
duration, which is not the case for no-fork mode. Removing
this expectation, and instead forcing all durations to be >=0 for
no-fork mode.
modify test_xml_output.sh to compare output based on HAVE_FORK
When run in Windows, the output differs slightly from when it is run
under *NIX due to line endings. *NIX uses \n, whereas Windows
uses \r\n. To account for this, printf is used to generate the
Windows expected string.
Additionally, the test_exit test was removed, as it is not valid
if fork is unavailable.
Note that the test does not yet pass for MinGW due to a bug yet to be
identified. The last test failure to compare against currently has
a duration which is not -1.
modify test_log_output.sh to compare output based on HAVE_FORK
When run in Windows, the output differs slightly from when it is run
under *NIX due to line endings. *NIX uses \n, whereas Windows
uses \r\n. To account for this, printf is used to generate the
Windows expected string.
Additionally, the test_exit test was removed, as it is not valid
if fork is unavailable.