|
Packit |
0b5880 |
.\" This manpage has been automatically generated by docbook2man
|
|
Packit |
0b5880 |
.\" from a DocBook document. This tool can be found at:
|
|
Packit |
0b5880 |
.\" <http://shell.ipoline.com/~elmert/comp/docbook2X/>
|
|
Packit |
0b5880 |
.\" Please send any bug reports, improvements, comments, patches,
|
|
Packit |
0b5880 |
.\" etc. to Steve Cheng <steve@ggi-project.org>.
|
|
Packit |
0b5880 |
.TH "CHECKMK" "1" "09 February 2010" "" ""
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
.SH NAME
|
|
Packit |
0b5880 |
checkmk \- Awk script for generating C unit tests for use with the Check unit testing framework.
|
|
Packit |
0b5880 |
.SH SYNOPSIS
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
\fBcheckmk\fR [ \fBclean_mode=1\fR ] [ \fB\fIinput-file\fB\fR ]
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
.SH "DESCRIPTION"
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
Generate C-language source files containing unit tests for use
|
|
Packit |
0b5880 |
with the Check unit testing framework. The aim of this script is
|
|
Packit |
0b5880 |
to automate away some of the typical boilerplate one must write when
|
|
Packit |
0b5880 |
writing a test suite using Check: specifically, the instantiation of
|
|
Packit |
0b5880 |
an SRunner, Suite(s), and TCase(s), and the building of
|
|
Packit |
0b5880 |
relationships between these objects and the test functions.
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
This tool is intended to be used by those who are familiar
|
|
Packit |
0b5880 |
with the Check unit testing framework. Familiarity with the
|
|
Packit |
0b5880 |
framework will be assumed throughout this manual.
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
The Check framework, along with information regarding it, is
|
|
Packit |
0b5880 |
available at http://check.sourceforge.net/ <URL:http://check.sourceforge.net/>\&.
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
The \fIinput-file\fR argument to
|
|
Packit |
0b5880 |
\fBcheckmk\fR uses a simple, C-preprocessor-like
|
|
Packit |
0b5880 |
syntax to declare test functions, and to describe their
|
|
Packit |
0b5880 |
relationships to Suites and TCases in Check.
|
|
Packit |
0b5880 |
\fBcheckmk\fR then uses this information to
|
|
Packit |
0b5880 |
automatically write a \fBmain()\fR function
|
|
Packit |
0b5880 |
containing all of the necessary declarations, and whatever code is
|
|
Packit |
0b5880 |
needed to run the test suites. The final C-language output is
|
|
Packit |
0b5880 |
printed to \fBcheckmk\fR\&'s standard output.
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
Facilities are provided for the insertion of user code into
|
|
Packit |
0b5880 |
the generated \fBmain()\fR function, to provide for
|
|
Packit |
0b5880 |
the use of logging, test fixtures or specialized exit values.
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
While it is possible to omit the
|
|
Packit |
0b5880 |
\fIinput-file\fR argument to
|
|
Packit |
0b5880 |
\fBcheckmk\fR and provide the input file on
|
|
Packit |
0b5880 |
\fBcheckmk\fR\&'s standard input instead, it is generally
|
|
Packit |
0b5880 |
recommended to provide it as an argument. Doing this allows
|
|
Packit |
0b5880 |
\fBcheckmk\fR to be aware of the file's name, to place
|
|
Packit |
0b5880 |
references to it in the initial comments of the C-language output,
|
|
Packit |
0b5880 |
and to intersperse C #line directives throughout, to
|
|
Packit |
0b5880 |
facilitate in debugging problems by directing the user to the
|
|
Packit |
0b5880 |
original input file.
|
|
Packit |
0b5880 |
.SH "OPTIONS"
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
The only officially supported option is specifying a true
|
|
Packit |
0b5880 |
value (using Awk's definition for "true") for the variable
|
|
Packit |
0b5880 |
\fBclean_mode\fR\&. This causes \fBcheckmk\fR
|
|
Packit |
0b5880 |
not to place appropriate #line directives in the
|
|
Packit |
0b5880 |
source code, which some might find to be unnecessary clutter.
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
The author recommends against the use of this option, as it
|
|
Packit |
0b5880 |
will cause C compilers and debugging tools to refer to lines in the
|
|
Packit |
0b5880 |
automatically generated output, rather than the original input files
|
|
Packit |
0b5880 |
to \fBcheckmk\fR\&. This would encourage users to edit the
|
|
Packit |
0b5880 |
output files instead of the original input files, would make it
|
|
Packit |
0b5880 |
difficult for intelligent editors or IDEs to pull up the right file
|
|
Packit |
0b5880 |
to edit, and could result in the fixes being overwritten when the
|
|
Packit |
0b5880 |
output files are regenerated.
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
#line directives are automatically
|
|
Packit |
0b5880 |
supressed when the input file is provided on standard input
|
|
Packit |
0b5880 |
instead of as a command-line argument.
|
|
Packit |
0b5880 |
.SH "BASIC EXAMPLE"
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
In its most basic form, an input file can be simply a
|
|
Packit |
0b5880 |
prologue and a test function. Anything that appears before the
|
|
Packit |
0b5880 |
first test function is in the prologue, and will be copied into
|
|
Packit |
0b5880 |
the output verbatim. The test function is begun by a line in the
|
|
Packit |
0b5880 |
form:
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
.nf
|
|
Packit |
0b5880 |
#test \fItest_name\fR
|
|
Packit |
0b5880 |
.fi
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
Where \fItest_name\fR is the name of
|
|
Packit |
0b5880 |
your test function. This will be used to name a C function, so
|
|
Packit |
0b5880 |
it must be a valid C identifier.
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
Here is a small, complete example:
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
.nf
|
|
Packit |
0b5880 |
--------------------------------------------------
|
|
Packit |
0b5880 |
/* A complete test example */
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
#include <stdio.h>
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
#test the_test
|
|
Packit |
0b5880 |
int nc;
|
|
Packit |
0b5880 |
const char msg[] = "\\n\\n Hello, world!\\n";
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
nc = printf("%s", msg);
|
|
Packit |
0b5880 |
ck_assert(nc == (sizeof(msg) - 1)); /* for terminating NUL. */
|
|
Packit |
0b5880 |
--------------------------------------------------
|
|
Packit |
0b5880 |
.fi
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
If you place the above into a file named
|
|
Packit |
0b5880 |
\fIbasic_complete.ts\fR and process it using the
|
|
Packit |
0b5880 |
following command:
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
\fB$ checkmk basic_complete.ts > basic_complete.c\fR
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
\fIbasic_complete.c\fR
|
|
Packit |
0b5880 |
will contain output similar to:
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
.nf
|
|
Packit |
0b5880 |
--------------------------------------------------
|
|
Packit |
0b5880 |
/*
|
|
Packit |
0b5880 |
* DO NOT EDIT THIS FILE. Generated by checkmk.
|
|
Packit |
0b5880 |
* Edit the original source file "in" instead.
|
|
Packit |
0b5880 |
*/
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
#include <check.h>
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
/* A complete test example */
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
#include <stdio.h>
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
START_TEST(the_test)
|
|
Packit |
0b5880 |
{
|
|
Packit |
0b5880 |
int nc;
|
|
Packit |
0b5880 |
const char msg[] = "\\n\\n Hello, world!\\n";
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
nc = printf("%s", msg);
|
|
Packit |
0b5880 |
ck_assert(nc == (sizeof(msg) - 1)); /* for terminating NUL. */
|
|
Packit |
0b5880 |
}
|
|
Packit |
0b5880 |
END_TEST
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
int main(void)
|
|
Packit |
0b5880 |
{
|
|
Packit |
0b5880 |
Suite *s1 = suite_create("Core");
|
|
Packit |
0b5880 |
TCase *tc1_1 = tcase_create("Core");
|
|
Packit |
0b5880 |
SRunner *sr = srunner_create(s1);
|
|
Packit |
0b5880 |
int nf;
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
suite_add_tcase(s1, tc1_1);
|
|
Packit |
0b5880 |
tcase_add_test(tc1_1, the_test);
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
srunner_run_all(sr, CK_ENV);
|
|
Packit |
0b5880 |
nf = srunner_ntests_failed(sr);
|
|
Packit |
0b5880 |
srunner_free(sr);
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
return nf == 0 ? 0 : 1;
|
|
Packit |
0b5880 |
}
|
|
Packit |
0b5880 |
--------------------------------------------------
|
|
Packit |
0b5880 |
.fi
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
In real usage, \fIbasic_complete.c\fR would
|
|
Packit |
0b5880 |
also contain #line directives.
|
|
Packit |
0b5880 |
.SH "DIRECTIVE SUMMARY"
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
Here is a complete summary of all the C-preprocessor-style
|
|
Packit |
0b5880 |
directives that are understood by \fBcheckmk\fR\&. See
|
|
Packit |
0b5880 |
below for more details.
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
.nf
|
|
Packit |
0b5880 |
# test \fItest_name\fR
|
|
Packit |
0b5880 |
# test-signal(\fIsignal\fR) \fItest_name\fR
|
|
Packit |
0b5880 |
# test-exit(\fIexit_code\fR) \fItest_name\fR
|
|
Packit |
0b5880 |
# test-loop(\fIstart\fR, \fIend\fR) \fItest_name\fR
|
|
Packit |
0b5880 |
# test-loop-signal(\fIsignal\fR, \fIstart\fR, \fIend\fR) \fItest_name\fR
|
|
Packit |
0b5880 |
# test-loop-exit(\fIexit_code\fR, \fIstart\fR, \fIend\fR) \fItest_name\fR
|
|
Packit |
0b5880 |
# suite \fITestSuiteName\fR
|
|
Packit |
0b5880 |
# tcase \fITestCaseName\fR
|
|
Packit |
0b5880 |
# main-pre
|
|
Packit |
0b5880 |
# main-post
|
|
Packit |
0b5880 |
.fi
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
All directives are case-insensitive. Whitespace may appear
|
|
Packit |
0b5880 |
at the beginning of the line before the #,
|
|
Packit |
0b5880 |
between the # and the directive, between the
|
|
Packit |
0b5880 |
directive and any argument, and at the end of the line.
|
|
Packit |
0b5880 |
.SH "TEST-DEFINING DIRECTIVES"
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
Here is a more detailed explanation of the directives that may be
|
|
Packit |
0b5880 |
used to define test functions and their containers.
|
|
Packit |
0b5880 |
.SS "TEST FUNCTIONS"
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
.nf
|
|
Packit |
0b5880 |
# test \fItest_name\fR
|
|
Packit |
0b5880 |
# test-signal(\fIsignal\fR) \fItest_name\fR
|
|
Packit |
0b5880 |
# test-exit(\fIexit_code\fR) \fItest_name\fR
|
|
Packit |
0b5880 |
# test-loop(\fIstart\fR, \fIend\fR) \fItest_name\fR
|
|
Packit |
0b5880 |
# test-loop-signal(\fIsignal\fR, \fIstart\fR, \fIend\fR) \fItest_name\fR
|
|
Packit |
0b5880 |
# test-loop-exit(\fIexit_code\fR, \fIstart\fR, \fIend\fR) \fItest_name\fR
|
|
Packit |
0b5880 |
.fi
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
These are the most basic directives for creating a template
|
|
Packit |
0b5880 |
for input to \fBcheckmk\fR\&. They are the only
|
|
Packit |
0b5880 |
directives that are required: there must be at least one
|
|
Packit |
0b5880 |
#test* directive appearing in the template, or
|
|
Packit |
0b5880 |
\fBcheckmk\fR will fail with an error message. The
|
|
Packit |
0b5880 |
#test* directives may be specified several times,
|
|
Packit |
0b5880 |
each one beginning the definition of a new test function.
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
The \fItest_name\fR argument will be
|
|
Packit |
0b5880 |
used as the name of a test function in the C-language output, so
|
|
Packit |
0b5880 |
it must be a valid C identifier. That is, it must begin with an
|
|
Packit |
0b5880 |
alphabetic character or the underscore (_),
|
|
Packit |
0b5880 |
followed by optional alpha-numeric characters and/or
|
|
Packit |
0b5880 |
underscores.
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
Universal Character Names (introduced in C99) are also
|
|
Packit |
0b5880 |
allowed, of the form \\uXXXX or
|
|
Packit |
0b5880 |
\\UXXXXXXXX, where the X\&'s
|
|
Packit |
0b5880 |
represent hexadecimal digits.
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
It is an error to specify the same
|
|
Packit |
0b5880 |
\fItest_name\fR in more than one
|
|
Packit |
0b5880 |
#test* directive, regardless of whether they
|
|
Packit |
0b5880 |
are associated with different test cases or suites.
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
See CHECKMK
|
|
Packit |
0b5880 |
IDENTIFIERS for the list of identifiers which should be
|
|
Packit |
0b5880 |
avoided for use as test function names.
|
|
Packit |
0b5880 |
.SS "TEST SUITES"
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
.nf
|
|
Packit |
0b5880 |
# suite \fITestSuiteName\fR
|
|
Packit |
0b5880 |
.fi
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
This directive specifies the name of the test suite
|
|
Packit |
0b5880 |
(\fBSuite\fR object in the Check test
|
|
Packit |
0b5880 |
framework) to which all future test cases (and their test
|
|
Packit |
0b5880 |
functions) will be added.
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
The \fITestSuiteName\fR is a text
|
|
Packit |
0b5880 |
string, and may contain any sort of characters at all (other
|
|
Packit |
0b5880 |
than ASCII NUL character, and the newline, which would terminate
|
|
Packit |
0b5880 |
the directive). Any leading or trailing whitespace will be omitted
|
|
Packit |
0b5880 |
from the test suite name.
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
Starting a new test suite also begins a new test case, whose
|
|
Packit |
0b5880 |
name is identical to the new test suite. This test case name may be
|
|
Packit |
0b5880 |
overridden by a subsequent #tcase directive.
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
Note that a \fBSuite\fR object won't
|
|
Packit |
0b5880 |
actually be defined by \fBcheckmk\fR in the C
|
|
Packit |
0b5880 |
output, unless it is followed at some point by a
|
|
Packit |
0b5880 |
#test directive (without an intervening
|
|
Packit |
0b5880 |
#suite). It is not an error for a
|
|
Packit |
0b5880 |
#suite to have no associated
|
|
Packit |
0b5880 |
#test\&';; the #suite (and any
|
|
Packit |
0b5880 |
associated #tcase\&'s) simply won't result in any
|
|
Packit |
0b5880 |
action on the part of \fBcheckmk\fR (and would
|
|
Packit |
0b5880 |
therefore be useless).
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
It is an error for a #suite directive to
|
|
Packit |
0b5880 |
specify the same (case sensitive) suite multiple times, unless the
|
|
Packit |
0b5880 |
previous uses were not instantiated by the presence of at least
|
|
Packit |
0b5880 |
one associated #test directive.
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
If you do not specify a #suite directive
|
|
Packit |
0b5880 |
before the first #test directive,
|
|
Packit |
0b5880 |
\fBcheckmk\fR performs the equivalent of an
|
|
Packit |
0b5880 |
implicit #suite directive, with the string
|
|
Packit |
0b5880 |
"Core" as the value for
|
|
Packit |
0b5880 |
\fITestSuiteName\fR (this also implies a
|
|
Packit |
0b5880 |
"Core" test case object). This is demonstrated
|
|
Packit |
0b5880 |
above in BASIC EXAMPLE\&.
|
|
Packit |
0b5880 |
.SS "TEST CASES"
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
.nf
|
|
Packit |
0b5880 |
# tcase \fITestCaseName\fR
|
|
Packit |
0b5880 |
.fi
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
This directive specifies the name of the test case
|
|
Packit |
0b5880 |
(\fBTCase\fR object in the Check test
|
|
Packit |
0b5880 |
framework) to which all future test functions will be added.
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
The #tcase works very in a way very
|
|
Packit |
0b5880 |
similar to #suite\&. The
|
|
Packit |
0b5880 |
\fITestCaseName\fR is a text string, and
|
|
Packit |
0b5880 |
may contain arbitrary characters; and a
|
|
Packit |
0b5880 |
\fBTCase\fR object won't actually be defined
|
|
Packit |
0b5880 |
unless it is followed by an associated
|
|
Packit |
0b5880 |
#test directive.
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
It is an error for a #tcase directive to
|
|
Packit |
0b5880 |
specify the same (case sensitive) test case multiple times, unless the
|
|
Packit |
0b5880 |
previous uses were not instantiated by the presence of at least
|
|
Packit |
0b5880 |
one associated #test directive.
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
See also the #suite directive, described
|
|
Packit |
0b5880 |
above.
|
|
Packit |
0b5880 |
.SH "USER CODE IN MAIN()"
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
The C \fBmain()\fR is automatically generated
|
|
Packit |
0b5880 |
by \fBcheckmk\fR, defining the necessary
|
|
Packit |
0b5880 |
\fBSRunner\fR\&'s, \fBSuite\fR\&'s,
|
|
Packit |
0b5880 |
and\~\fBTCase\fR\&'s required by the
|
|
Packit |
0b5880 |
test-defining directives specified by the user.
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
For most situations, this completely automated
|
|
Packit |
0b5880 |
\fBmain()\fR is quite suitable as-is. However,
|
|
Packit |
0b5880 |
there are situations where one might wish to add custom code to
|
|
Packit |
0b5880 |
the \fBmain()\fR\&. For instance, if the user wishes
|
|
Packit |
0b5880 |
to:
|
|
Packit |
0b5880 |
.TP 0.2i
|
|
Packit |
0b5880 |
\(bu
|
|
Packit |
0b5880 |
change the test timeout value via
|
|
Packit |
0b5880 |
\fBtcase_set_timeout()\fR,
|
|
Packit |
0b5880 |
.TP 0.2i
|
|
Packit |
0b5880 |
\(bu
|
|
Packit |
0b5880 |
specify Check's "no-fork-mode" via
|
|
Packit |
0b5880 |
\fBsrunner_set_fork_status()\fR,
|
|
Packit |
0b5880 |
.TP 0.2i
|
|
Packit |
0b5880 |
\(bu
|
|
Packit |
0b5880 |
set up test fixtures for some test cases, via
|
|
Packit |
0b5880 |
\fBtcase_add_checked_fixture()\fR
|
|
Packit |
0b5880 |
or\~\fBtcase_add_unchecked_fixture()\fR,
|
|
Packit |
0b5880 |
.TP 0.2i
|
|
Packit |
0b5880 |
\(bu
|
|
Packit |
0b5880 |
set up test logging for the suite
|
|
Packit |
0b5880 |
runner, via \fBsrunner_set_log()\fR
|
|
Packit |
0b5880 |
or\~\fBsrunner_set_xml()\fR, or
|
|
Packit |
0b5880 |
.TP 0.2i
|
|
Packit |
0b5880 |
\(bu
|
|
Packit |
0b5880 |
perform custom wrap-up after the test suites have
|
|
Packit |
0b5880 |
been run.
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
For these purposes, the #main-pre
|
|
Packit |
0b5880 |
and\~#main-post directives have been
|
|
Packit |
0b5880 |
provided.
|
|
Packit |
0b5880 |
.SS "MAIN() PROLOGUE"
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
.nf
|
|
Packit |
0b5880 |
# main-pre
|
|
Packit |
0b5880 |
.fi
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
The text following this directive will be placed verbatim
|
|
Packit |
0b5880 |
into the body of the generated \fBmain()\fR
|
|
Packit |
0b5880 |
function, just after \fBcheckmk\fR\&'s own local
|
|
Packit |
0b5880 |
variable declarations, and before any test running has taken
|
|
Packit |
0b5880 |
place (indeed, before even the relationships between the tests,
|
|
Packit |
0b5880 |
test cases, and test suites have been set up, though that
|
|
Packit |
0b5880 |
fact shouldn't make much difference). Since
|
|
Packit |
0b5880 |
\fBcheckmk\fR has only just finished making its
|
|
Packit |
0b5880 |
declarations, it is permissible, even under strict 1990 ISO C
|
|
Packit |
0b5880 |
guidelines, to make custom variable declarations here.
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
Unlike the previously-described directives,
|
|
Packit |
0b5880 |
#main-pre may be specified at most once. It may
|
|
Packit |
0b5880 |
not be preceded by the #main-post directive,
|
|
Packit |
0b5880 |
and no #suite, #tcase,
|
|
Packit |
0b5880 |
or #test directive may appear after it.
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
#main-pre is a good place to tweak
|
|
Packit |
0b5880 |
settings or set up test fixtures. Of course, in order to do so,
|
|
Packit |
0b5880 |
you need to know what names \fBcheckmk\fR has used
|
|
Packit |
0b5880 |
to instantiate the \fBSRunner\fR\&'s,
|
|
Packit |
0b5880 |
\fBSuite\fR\&'s,
|
|
Packit |
0b5880 |
and\~\fBTCase\fR\&'s.
|
|
Packit |
0b5880 |
.SS "CHECKMK IDENTIFIERS"
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
Pointers to \fBSuite\fR\&'s are declared
|
|
Packit |
0b5880 |
using the pattern
|
|
Packit |
0b5880 |
s\fIX\fR, where
|
|
Packit |
0b5880 |
\fIX\fR is a number
|
|
Packit |
0b5880 |
that starts at 1, and is incremented for each subsequent
|
|
Packit |
0b5880 |
#suite directive.
|
|
Packit |
0b5880 |
s1 always exists, and contains the test
|
|
Packit |
0b5880 |
function declared by the first #test
|
|
Packit |
0b5880 |
directive. If that directive was not preceded by a
|
|
Packit |
0b5880 |
#suite, it will be given the name "Core".
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
Pointers to \fBTCase\fR\&'s are declared
|
|
Packit |
0b5880 |
using the pattern
|
|
Packit |
0b5880 |
tc\fIX\fR_\fIY\fR,
|
|
Packit |
0b5880 |
where \fIX\fR corresponds to the number
|
|
Packit |
0b5880 |
used for the name of the \fBSuite\fR that
|
|
Packit |
0b5880 |
will contain this \fBTCase\fR; and
|
|
Packit |
0b5880 |
\fIY\fR is a number that starts at 1 for
|
|
Packit |
0b5880 |
each new \fBSuite\fR, and is incremented for
|
|
Packit |
0b5880 |
each \fBTCase\fR in that
|
|
Packit |
0b5880 |
\fBSuite\fR\&.
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
A pointer to \fBSRunner\fR is declared
|
|
Packit |
0b5880 |
using the identifier sr; there is also an
|
|
Packit |
0b5880 |
integer named nf which holds the number of
|
|
Packit |
0b5880 |
test failures (after the tests have run).
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
For obvious reasons, the user should not attempt to
|
|
Packit |
0b5880 |
declare local identifiers in \fBmain()\fR, or
|
|
Packit |
0b5880 |
define any macros or test functions, whose names might
|
|
Packit |
0b5880 |
conflict with the local variable names used by
|
|
Packit |
0b5880 |
\fBcheckmk\fR\&. To summarize, these names are:
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
s\fIX\fR
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
tc\fIX\fR_\fIY\fR
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
sr
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
nf\&.
|
|
Packit |
0b5880 |
.SS "MAIN() EPILOGUE"
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
.nf
|
|
Packit |
0b5880 |
# main-post
|
|
Packit |
0b5880 |
.fi
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
Though it is not as useful, \fBcheckmk\fR also
|
|
Packit |
0b5880 |
provides a #main-post directive to insert
|
|
Packit |
0b5880 |
custom code at the end of \fBmain()\fR, after the
|
|
Packit |
0b5880 |
tests have run. This could be used to clean up resources that
|
|
Packit |
0b5880 |
were allocated in the prologue, or to print information about
|
|
Packit |
0b5880 |
the failed tests, or to provide a custom exit status
|
|
Packit |
0b5880 |
code.
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
Note that, if you make use of this directive,
|
|
Packit |
0b5880 |
\fBcheckmk\fR will \fBnot\fR provide a
|
|
Packit |
0b5880 |
return statement: you will need
|
|
Packit |
0b5880 |
to provide one yourself.
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
The #main-post directive may not be
|
|
Packit |
0b5880 |
followed by any other directives recognized by
|
|
Packit |
0b5880 |
\fBcheckmk\fR\&.
|
|
Packit |
0b5880 |
.SH "COMPREHENSIVE EXAMPLE"
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
Now that you've gotten the detailed descriptions of the
|
|
Packit |
0b5880 |
various directives, let's see it all put to action with this
|
|
Packit |
0b5880 |
fairly comprehensive template.
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
.nf
|
|
Packit |
0b5880 |
--------------------------------------------------
|
|
Packit |
0b5880 |
#include "mempool.h" /* defines MEMPOOLSZ, prototypes for
|
|
Packit |
0b5880 |
mempool_init() and mempool_free() */
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
void *mempool;
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
void mp_setup(void)
|
|
Packit |
0b5880 |
{
|
|
Packit |
0b5880 |
mempool = mempool_init(MEMPOOLSZ);
|
|
Packit |
0b5880 |
ck_assert_msg(mempool != NULL, "Couldn't allocate mempool.");
|
|
Packit |
0b5880 |
}
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
void mp_teardown(void)
|
|
Packit |
0b5880 |
{
|
|
Packit |
0b5880 |
mempool_free(mempool);
|
|
Packit |
0b5880 |
}
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
/* end of prologue */
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
#suite Mempool
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
#tcase MP Init
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
#test mempool_init_zero_test
|
|
Packit |
0b5880 |
mempool = mempool_init(0);
|
|
Packit |
0b5880 |
ck_assert_msg(mempool == NULL, "Allocated a zero-sized mempool!");
|
|
Packit |
0b5880 |
ck_assert_msg(mempool_error(), "Didn't get an error for zero alloc.");
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
/* "MP Util" TCase uses checked fixture. */
|
|
Packit |
0b5880 |
#tcase MP Util
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
#test mempool_copy_test
|
|
Packit |
0b5880 |
void *cp = mempool_copy(mempool);
|
|
Packit |
0b5880 |
ck_assert_msg(cp != NULL, "Couldn't perform mempool copy.");
|
|
Packit |
0b5880 |
ck_assert_msg(cp != mempool, "Copy returned original pointer!");
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
#test mempool_size_test
|
|
Packit |
0b5880 |
ck_assert(mempool_getsize(mempool) == MEMPOOLSZ);
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
#main-pre
|
|
Packit |
0b5880 |
tcase_add_checked_fixture(tc1_2, mp_setup, mp_teardown);
|
|
Packit |
0b5880 |
srunner_set_log(sr, "mplog.txt");
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
#main-post
|
|
Packit |
0b5880 |
if (nf != 0) {
|
|
Packit |
0b5880 |
printf("Hey, something's wrong! %d whole tests failed!\\n", nf);
|
|
Packit |
0b5880 |
}
|
|
Packit |
0b5880 |
return 0; /* Harness checks for output, always return success
|
|
Packit |
0b5880 |
regardless. */
|
|
Packit |
0b5880 |
--------------------------------------------------
|
|
Packit |
0b5880 |
.fi
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
Plugging this into \fBcheckmk\fR, we'll get
|
|
Packit |
0b5880 |
output roughly like the following:
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
.nf
|
|
Packit |
0b5880 |
--------------------------------------------------
|
|
Packit |
0b5880 |
/*
|
|
Packit |
0b5880 |
* DO NOT EDIT THIS FILE. Generated by checkmk.
|
|
Packit |
0b5880 |
* Edit the original source file "comprehensive.ts" instead.
|
|
Packit |
0b5880 |
*/
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
#include <check.h>
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
#include "mempool.h"
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
void *mempool;
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
void mp_setup(void)
|
|
Packit |
0b5880 |
{
|
|
Packit |
0b5880 |
\&...
|
|
Packit |
0b5880 |
}
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
void mp_teardown(void)
|
|
Packit |
0b5880 |
{
|
|
Packit |
0b5880 |
\&...
|
|
Packit |
0b5880 |
}
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
/* end of prologue */
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
START_TEST(mempool_init_zero_test)
|
|
Packit |
0b5880 |
{
|
|
Packit |
0b5880 |
\&...
|
|
Packit |
0b5880 |
}
|
|
Packit |
0b5880 |
END_TEST
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
START_TEST(mempool_copy_test)
|
|
Packit |
0b5880 |
{
|
|
Packit |
0b5880 |
\&...
|
|
Packit |
0b5880 |
}
|
|
Packit |
0b5880 |
END_TEST
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
START_TEST(mempool_size_test)
|
|
Packit |
0b5880 |
{
|
|
Packit |
0b5880 |
\&...
|
|
Packit |
0b5880 |
}
|
|
Packit |
0b5880 |
END_TEST
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
int main(void)
|
|
Packit |
0b5880 |
{
|
|
Packit |
0b5880 |
Suite *s1 = suite_create("Mempool");
|
|
Packit |
0b5880 |
TCase *tc1_1 = tcase_create("MP Init");
|
|
Packit |
0b5880 |
TCase *tc1_2 = tcase_create("MP Util");
|
|
Packit |
0b5880 |
SRunner *sr = srunner_create(s1);
|
|
Packit |
0b5880 |
int nf;
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
/* User-specified pre-run code */
|
|
Packit |
0b5880 |
tcase_add_checked_fixture(tc1_2, mp_setup, mp_teardown);
|
|
Packit |
0b5880 |
srunner_set_log(sr, "mplog.txt");
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
suite_add_tcase(s1, tc1_1);
|
|
Packit |
0b5880 |
tcase_add_test(tc1_1, mempool_init_zero_test);
|
|
Packit |
0b5880 |
suite_add_tcase(s1, tc1_2);
|
|
Packit |
0b5880 |
tcase_add_test(tc1_2, mempool_copy_test);
|
|
Packit |
0b5880 |
tcase_add_test(tc1_2, mempool_size_test);
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
srunner_run_all(sr, CK_ENV);
|
|
Packit |
0b5880 |
nf = srunner_ntests_failed(sr);
|
|
Packit |
0b5880 |
srunner_free(sr);
|
|
Packit |
0b5880 |
|
|
Packit |
0b5880 |
/* User-specified post-run code */
|
|
Packit |
0b5880 |
if (nf != 0) {
|
|
Packit |
0b5880 |
printf("Hey, something's wrong! %d whole tests failed!\\n", nf);
|
|
Packit |
0b5880 |
}
|
|
Packit |
0b5880 |
return 0; /* Harness checks for output, always return success
|
|
Packit |
0b5880 |
regardless. */
|
|
Packit |
0b5880 |
}
|
|
Packit |
0b5880 |
--------------------------------------------------
|
|
Packit |
0b5880 |
.fi
|
|
Packit |
0b5880 |
.SH "AUTHOR"
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
\fBcheckmk\fR and this manual were written
|
|
Packit |
0b5880 |
by Micah J Cowan.
|
|
Packit |
0b5880 |
.PP
|
|
Packit |
0b5880 |
Copyright (C) 2006, 2010 Micah J Cowan.
|