xref: /minix3/external/bsd/atf/dist/atf-c/atf-c-api.3 (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
111be35a1SLionel Sambuc.\"
211be35a1SLionel Sambuc.\" Automated Testing Framework (atf)
311be35a1SLionel Sambuc.\"
411be35a1SLionel Sambuc.\" Copyright (c) 2008 The NetBSD Foundation, Inc.
511be35a1SLionel Sambuc.\" All rights reserved.
611be35a1SLionel Sambuc.\"
711be35a1SLionel Sambuc.\" Redistribution and use in source and binary forms, with or without
811be35a1SLionel Sambuc.\" modification, are permitted provided that the following conditions
911be35a1SLionel Sambuc.\" are met:
1011be35a1SLionel Sambuc.\" 1. Redistributions of source code must retain the above copyright
1111be35a1SLionel Sambuc.\"    notice, this list of conditions and the following disclaimer.
1211be35a1SLionel Sambuc.\" 2. Redistributions in binary form must reproduce the above copyright
1311be35a1SLionel Sambuc.\"    notice, this list of conditions and the following disclaimer in the
1411be35a1SLionel Sambuc.\"    documentation and/or other materials provided with the distribution.
1511be35a1SLionel Sambuc.\"
1611be35a1SLionel Sambuc.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
1711be35a1SLionel Sambuc.\" CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
1811be35a1SLionel Sambuc.\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
1911be35a1SLionel Sambuc.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2011be35a1SLionel Sambuc.\" IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
2111be35a1SLionel Sambuc.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2211be35a1SLionel Sambuc.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
2311be35a1SLionel Sambuc.\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2411be35a1SLionel Sambuc.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
2511be35a1SLionel Sambuc.\" IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
2611be35a1SLionel Sambuc.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
2711be35a1SLionel Sambuc.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2811be35a1SLionel Sambuc.\"
29*0a6a1f1dSLionel Sambuc.Dd November 15, 2013
3011be35a1SLionel Sambuc.Dt ATF-C-API 3
3111be35a1SLionel Sambuc.Os
3211be35a1SLionel Sambuc.Sh NAME
3311be35a1SLionel Sambuc.Nm atf-c-api ,
3411be35a1SLionel Sambuc.Nm ATF_CHECK ,
3511be35a1SLionel Sambuc.Nm ATF_CHECK_MSG ,
3611be35a1SLionel Sambuc.Nm ATF_CHECK_EQ ,
3711be35a1SLionel Sambuc.Nm ATF_CHECK_EQ_MSG ,
3811be35a1SLionel Sambuc.Nm ATF_CHECK_MATCH ,
3911be35a1SLionel Sambuc.Nm ATF_CHECK_MATCH_MSG ,
4011be35a1SLionel Sambuc.Nm ATF_CHECK_STREQ ,
4111be35a1SLionel Sambuc.Nm ATF_CHECK_STREQ_MSG ,
4211be35a1SLionel Sambuc.Nm ATF_CHECK_ERRNO ,
4311be35a1SLionel Sambuc.Nm ATF_REQUIRE ,
4411be35a1SLionel Sambuc.Nm ATF_REQUIRE_MSG ,
4511be35a1SLionel Sambuc.Nm ATF_REQUIRE_EQ ,
4611be35a1SLionel Sambuc.Nm ATF_REQUIRE_EQ_MSG ,
4711be35a1SLionel Sambuc.Nm ATF_REQUIRE_MATCH ,
4811be35a1SLionel Sambuc.Nm ATF_REQUIRE_MATCH_MSG ,
4911be35a1SLionel Sambuc.Nm ATF_REQUIRE_STREQ ,
5011be35a1SLionel Sambuc.Nm ATF_REQUIRE_STREQ_MSG ,
5111be35a1SLionel Sambuc.Nm ATF_REQUIRE_ERRNO ,
5211be35a1SLionel Sambuc.Nm ATF_TC ,
5311be35a1SLionel Sambuc.Nm ATF_TC_BODY ,
5411be35a1SLionel Sambuc.Nm ATF_TC_BODY_NAME ,
5511be35a1SLionel Sambuc.Nm ATF_TC_CLEANUP ,
5611be35a1SLionel Sambuc.Nm ATF_TC_CLEANUP_NAME ,
5711be35a1SLionel Sambuc.Nm ATF_TC_HEAD ,
5811be35a1SLionel Sambuc.Nm ATF_TC_HEAD_NAME ,
5911be35a1SLionel Sambuc.Nm ATF_TC_NAME ,
6011be35a1SLionel Sambuc.Nm ATF_TC_WITH_CLEANUP ,
6111be35a1SLionel Sambuc.Nm ATF_TC_WITHOUT_HEAD ,
6211be35a1SLionel Sambuc.Nm ATF_TP_ADD_TC ,
6311be35a1SLionel Sambuc.Nm ATF_TP_ADD_TCS ,
6411be35a1SLionel Sambuc.Nm atf_tc_get_config_var ,
6511be35a1SLionel Sambuc.Nm atf_tc_get_config_var_wd ,
6611be35a1SLionel Sambuc.Nm atf_tc_get_config_var_as_bool ,
6711be35a1SLionel Sambuc.Nm atf_tc_get_config_var_as_bool_wd ,
6811be35a1SLionel Sambuc.Nm atf_tc_get_config_var_as_long ,
6911be35a1SLionel Sambuc.Nm atf_tc_get_config_var_as_long_wd ,
7011be35a1SLionel Sambuc.Nm atf_no_error ,
7111be35a1SLionel Sambuc.Nm atf_tc_expect_death ,
7211be35a1SLionel Sambuc.Nm atf_tc_expect_exit ,
7311be35a1SLionel Sambuc.Nm atf_tc_expect_fail ,
7411be35a1SLionel Sambuc.Nm atf_tc_expect_pass ,
7511be35a1SLionel Sambuc.Nm atf_tc_expect_signal ,
7611be35a1SLionel Sambuc.Nm atf_tc_expect_timeout ,
7711be35a1SLionel Sambuc.Nm atf_tc_fail ,
7811be35a1SLionel Sambuc.Nm atf_tc_fail_nonfatal ,
7911be35a1SLionel Sambuc.Nm atf_tc_pass ,
8011be35a1SLionel Sambuc.Nm atf_tc_skip ,
8111be35a1SLionel Sambuc.Nm atf_utils_cat_file ,
8211be35a1SLionel Sambuc.Nm atf_utils_compare_file ,
8311be35a1SLionel Sambuc.Nm atf_utils_copy_file ,
8411be35a1SLionel Sambuc.Nm atf_utils_create_file ,
8511be35a1SLionel Sambuc.Nm atf_utils_file_exists ,
8611be35a1SLionel Sambuc.Nm atf_utils_fork ,
8711be35a1SLionel Sambuc.Nm atf_utils_free_charpp ,
8811be35a1SLionel Sambuc.Nm atf_utils_grep_file ,
8911be35a1SLionel Sambuc.Nm atf_utils_grep_string ,
9011be35a1SLionel Sambuc.Nm atf_utils_readline ,
9111be35a1SLionel Sambuc.Nm atf_utils_redirect ,
9211be35a1SLionel Sambuc.Nm atf_utils_wait
9311be35a1SLionel Sambuc.Nd C API to write ATF-based test programs
9411be35a1SLionel Sambuc.Sh SYNOPSIS
9511be35a1SLionel Sambuc.In atf-c.h
9611be35a1SLionel Sambuc.Fn ATF_CHECK "expression"
9711be35a1SLionel Sambuc.Fn ATF_CHECK_MSG "expression" "fail_msg_fmt" ...
9811be35a1SLionel Sambuc.Fn ATF_CHECK_EQ "expression_1" "expression_2"
9911be35a1SLionel Sambuc.Fn ATF_CHECK_EQ_MSG "expression_1" "expression_2" "fail_msg_fmt" ...
10011be35a1SLionel Sambuc.Fn ATF_CHECK_MATCH "regexp" "string"
10111be35a1SLionel Sambuc.Fn ATF_CHECK_MATCH_MSG "regexp" "string" "fail_msg_fmt" ...
10211be35a1SLionel Sambuc.Fn ATF_CHECK_STREQ "string_1" "string_2"
10311be35a1SLionel Sambuc.Fn ATF_CHECK_STREQ_MSG "string_1" "string_2" "fail_msg_fmt" ...
10411be35a1SLionel Sambuc.Fn ATF_CHECK_ERRNO "exp_errno" "bool_expression"
10511be35a1SLionel Sambuc.Fn ATF_REQUIRE "expression"
10611be35a1SLionel Sambuc.Fn ATF_REQUIRE_MSG "expression" "fail_msg_fmt" ...
10711be35a1SLionel Sambuc.Fn ATF_REQUIRE_EQ "expression_1" "expression_2"
10811be35a1SLionel Sambuc.Fn ATF_REQUIRE_EQ_MSG "expression_1" "expression_2" "fail_msg_fmt" ...
10911be35a1SLionel Sambuc.Fn ATF_REQUIRE_MATCH "regexp" "string"
11011be35a1SLionel Sambuc.Fn ATF_REQUIRE_MATCH_MSG "regexp" "string" "fail_msg_fmt" ...
11111be35a1SLionel Sambuc.Fn ATF_REQUIRE_STREQ "string_1" "string_2"
11211be35a1SLionel Sambuc.Fn ATF_REQUIRE_STREQ_MSG "string_1" "string_2" "fail_msg_fmt" ...
11311be35a1SLionel Sambuc.Fn ATF_REQUIRE_ERRNO "exp_errno" "bool_expression"
11411be35a1SLionel Sambuc.Fn ATF_TC "name"
11511be35a1SLionel Sambuc.Fn ATF_TC_BODY "name" "tc"
11611be35a1SLionel Sambuc.Fn ATF_TC_BODY_NAME "name"
11711be35a1SLionel Sambuc.Fn ATF_TC_CLEANUP "name" "tc"
11811be35a1SLionel Sambuc.Fn ATF_TC_CLEANUP_NAME "name"
11911be35a1SLionel Sambuc.Fn ATF_TC_HEAD "name" "tc"
12011be35a1SLionel Sambuc.Fn ATF_TC_HEAD_NAME "name"
12111be35a1SLionel Sambuc.Fn ATF_TC_NAME "name"
12211be35a1SLionel Sambuc.Fn ATF_TC_WITH_CLEANUP "name"
12311be35a1SLionel Sambuc.Fn ATF_TC_WITHOUT_HEAD "name"
12411be35a1SLionel Sambuc.Fn ATF_TP_ADD_TC "tp_name" "tc_name"
12511be35a1SLionel Sambuc.Fn ATF_TP_ADD_TCS "tp_name"
12611be35a1SLionel Sambuc.Fn atf_tc_get_config_var "tc" "varname"
12711be35a1SLionel Sambuc.Fn atf_tc_get_config_var_wd "tc" "variable_name" "default_value"
12811be35a1SLionel Sambuc.Fn atf_tc_get_config_var_as_bool "tc" "variable_name"
12911be35a1SLionel Sambuc.Fn atf_tc_get_config_var_as_bool_wd "tc" "variable_name" "default_value"
13011be35a1SLionel Sambuc.Fn atf_tc_get_config_var_as_long "tc" "variable_name"
13111be35a1SLionel Sambuc.Fn atf_tc_get_config_var_as_long_wd "tc" "variable_name" "default_value"
13211be35a1SLionel Sambuc.Fn atf_no_error
13311be35a1SLionel Sambuc.Fn atf_tc_expect_death "reason" "..."
13411be35a1SLionel Sambuc.Fn atf_tc_expect_exit "exitcode" "reason" "..."
13511be35a1SLionel Sambuc.Fn atf_tc_expect_fail "reason" "..."
13611be35a1SLionel Sambuc.Fn atf_tc_expect_pass
13711be35a1SLionel Sambuc.Fn atf_tc_expect_signal "signo" "reason" "..."
13811be35a1SLionel Sambuc.Fn atf_tc_expect_timeout "reason" "..."
13911be35a1SLionel Sambuc.Fn atf_tc_fail "reason"
14011be35a1SLionel Sambuc.Fn atf_tc_fail_nonfatal "reason"
14111be35a1SLionel Sambuc.Fn atf_tc_pass
14211be35a1SLionel Sambuc.Fn atf_tc_skip "reason"
14311be35a1SLionel Sambuc.Ft void
14411be35a1SLionel Sambuc.Fo atf_utils_cat_file
14511be35a1SLionel Sambuc.Fa "const char *file"
14611be35a1SLionel Sambuc.Fa "const char *prefix"
14711be35a1SLionel Sambuc.Fc
14811be35a1SLionel Sambuc.Ft bool
14911be35a1SLionel Sambuc.Fo atf_utils_compare_file
15011be35a1SLionel Sambuc.Fa "const char *file"
15111be35a1SLionel Sambuc.Fa "const char *contents"
15211be35a1SLionel Sambuc.Fc
15311be35a1SLionel Sambuc.Ft void
15411be35a1SLionel Sambuc.Fo atf_utils_copy_file
15511be35a1SLionel Sambuc.Fa "const char *source"
15611be35a1SLionel Sambuc.Fa "const char *destination"
15711be35a1SLionel Sambuc.Fc
15811be35a1SLionel Sambuc.Ft void
15911be35a1SLionel Sambuc.Fo atf_utils_create_file
16011be35a1SLionel Sambuc.Fa "const char *file"
16111be35a1SLionel Sambuc.Fa "const char *contents"
16211be35a1SLionel Sambuc.Fa "..."
16311be35a1SLionel Sambuc.Fc
16411be35a1SLionel Sambuc.Ft void
16511be35a1SLionel Sambuc.Fo atf_utils_file_exists
16611be35a1SLionel Sambuc.Fa "const char *file"
16711be35a1SLionel Sambuc.Fc
16811be35a1SLionel Sambuc.Ft pid_t
16911be35a1SLionel Sambuc.Fo atf_utils_fork
17011be35a1SLionel Sambuc.Fa "void"
17111be35a1SLionel Sambuc.Fc
17211be35a1SLionel Sambuc.Ft void
17311be35a1SLionel Sambuc.Fo atf_utils_free_charpp
17411be35a1SLionel Sambuc.Fa "char **argv"
17511be35a1SLionel Sambuc.Fc
17611be35a1SLionel Sambuc.Ft bool
17711be35a1SLionel Sambuc.Fo atf_utils_grep_file
17811be35a1SLionel Sambuc.Fa "const char *regexp"
17911be35a1SLionel Sambuc.Fa "const char *file"
18011be35a1SLionel Sambuc.Fa "..."
18111be35a1SLionel Sambuc.Fc
18211be35a1SLionel Sambuc.Ft bool
18311be35a1SLionel Sambuc.Fo atf_utils_grep_string
18411be35a1SLionel Sambuc.Fa "const char *regexp"
18511be35a1SLionel Sambuc.Fa "const char *str"
18611be35a1SLionel Sambuc.Fa "..."
18711be35a1SLionel Sambuc.Fc
18811be35a1SLionel Sambuc.Ft char *
18911be35a1SLionel Sambuc.Fo atf_utils_readline
19011be35a1SLionel Sambuc.Fa "int fd"
19111be35a1SLionel Sambuc.Fc
19211be35a1SLionel Sambuc.Ft void
19311be35a1SLionel Sambuc.Fo atf_utils_redirect
19411be35a1SLionel Sambuc.Fa "const int fd"
19511be35a1SLionel Sambuc.Fa "const char *file"
19611be35a1SLionel Sambuc.Fc
19711be35a1SLionel Sambuc.Ft void
19811be35a1SLionel Sambuc.Fo atf_utils_wait
19911be35a1SLionel Sambuc.Fa "const pid_t pid"
20011be35a1SLionel Sambuc.Fa "const int expected_exit_status"
20111be35a1SLionel Sambuc.Fa "const char *expected_stdout"
20211be35a1SLionel Sambuc.Fa "const char *expected_stderr"
20311be35a1SLionel Sambuc.Fc
20411be35a1SLionel Sambuc.Sh DESCRIPTION
205*0a6a1f1dSLionel SambucATF provides a C programming interface to implement test programs.
206*0a6a1f1dSLionel SambucC-based test programs follow this template:
20711be35a1SLionel Sambuc.Bd -literal -offset indent
20811be35a1SLionel Sambuc.Ns ... C-specific includes go here ...
20911be35a1SLionel Sambuc
21011be35a1SLionel Sambuc#include <atf-c.h>
21111be35a1SLionel Sambuc
21211be35a1SLionel SambucATF_TC(tc1);
21311be35a1SLionel SambucATF_TC_HEAD(tc1, tc)
21411be35a1SLionel Sambuc{
21511be35a1SLionel Sambuc    ... first test case's header ...
21611be35a1SLionel Sambuc}
21711be35a1SLionel SambucATF_TC_BODY(tc1, tc)
21811be35a1SLionel Sambuc{
21911be35a1SLionel Sambuc    ... first test case's body ...
22011be35a1SLionel Sambuc}
22111be35a1SLionel Sambuc
22211be35a1SLionel SambucATF_TC_WITH_CLEANUP(tc2);
22311be35a1SLionel SambucATF_TC_HEAD(tc2, tc)
22411be35a1SLionel Sambuc{
22511be35a1SLionel Sambuc    ... second test case's header ...
22611be35a1SLionel Sambuc}
22711be35a1SLionel SambucATF_TC_BODY(tc2, tc)
22811be35a1SLionel Sambuc{
22911be35a1SLionel Sambuc    ... second test case's body ...
23011be35a1SLionel Sambuc}
23111be35a1SLionel SambucATF_TC_CLEANUP(tc2, tc)
23211be35a1SLionel Sambuc{
23311be35a1SLionel Sambuc    ... second test case's cleanup ...
23411be35a1SLionel Sambuc}
23511be35a1SLionel Sambuc
23611be35a1SLionel SambucATF_TC_WITHOUT_HEAD(tc3);
23711be35a1SLionel SambucATF_TC_BODY(tc3, tc)
23811be35a1SLionel Sambuc{
23911be35a1SLionel Sambuc    ... third test case's body ...
24011be35a1SLionel Sambuc}
24111be35a1SLionel Sambuc
24211be35a1SLionel Sambuc.Ns ... additional test cases ...
24311be35a1SLionel Sambuc
24411be35a1SLionel SambucATF_TP_ADD_TCS(tp)
24511be35a1SLionel Sambuc{
24611be35a1SLionel Sambuc    ATF_TP_ADD_TC(tcs, tc1);
24711be35a1SLionel Sambuc    ATF_TP_ADD_TC(tcs, tc2);
24811be35a1SLionel Sambuc    ATF_TP_ADD_TC(tcs, tc3);
24911be35a1SLionel Sambuc    ... add additional test cases ...
25011be35a1SLionel Sambuc
25111be35a1SLionel Sambuc    return atf_no_error();
25211be35a1SLionel Sambuc}
25311be35a1SLionel Sambuc.Ed
25411be35a1SLionel Sambuc.Ss Definition of test cases
25511be35a1SLionel SambucTest cases have an identifier and are composed of three different parts:
25611be35a1SLionel Sambucthe header, the body and an optional cleanup routine, all of which are
25711be35a1SLionel Sambucdescribed in
25811be35a1SLionel Sambuc.Xr atf-test-case 4 .
25911be35a1SLionel SambucTo define test cases, one can use the
26011be35a1SLionel Sambuc.Fn ATF_TC ,
26111be35a1SLionel Sambuc.Fn ATF_TC_WITH_CLEANUP
26211be35a1SLionel Sambucor the
26311be35a1SLionel Sambuc.Fn ATF_TC_WITHOUT_HEAD
26411be35a1SLionel Sambucmacros, which take a single parameter specifiying the test case's name.
26511be35a1SLionel Sambuc.Fn ATF_TC ,
26611be35a1SLionel Sambucrequires to define a head and a body for the test case,
26711be35a1SLionel Sambuc.Fn ATF_TC_WITH_CLEANUP
26811be35a1SLionel Sambucrequires to define a head, a body and a cleanup for the test case and
26911be35a1SLionel Sambuc.Fn ATF_TC_WITHOUT_HEAD
27011be35a1SLionel Sambucrequires only a body for the test case.
27111be35a1SLionel SambucIt is important to note that these
27211be35a1SLionel Sambuc.Em do not
27311be35a1SLionel Sambucset the test case up for execution when the program is run.
27411be35a1SLionel SambucIn order to do so, a later registration is needed with the
27511be35a1SLionel Sambuc.Fn ATF_TP_ADD_TC
27611be35a1SLionel Sambucmacro detailed in
27711be35a1SLionel Sambuc.Sx Program initialization .
27811be35a1SLionel Sambuc.Pp
27911be35a1SLionel SambucLater on, one must define the three parts of the body by means of three
28011be35a1SLionel Sambucfunctions.
28111be35a1SLionel SambucTheir headers are given by the
28211be35a1SLionel Sambuc.Fn ATF_TC_HEAD ,
28311be35a1SLionel Sambuc.Fn ATF_TC_BODY
28411be35a1SLionel Sambucand
28511be35a1SLionel Sambuc.Fn ATF_TC_CLEANUP
28611be35a1SLionel Sambucmacros, all of which take the test case name provided to the
28711be35a1SLionel Sambuc.Fn ATF_TC
28811be35a1SLionel Sambuc.Fn ATF_TC_WITH_CLEANUP ,
28911be35a1SLionel Sambucor
29011be35a1SLionel Sambuc.Fn ATF_TC_WITHOUT_HEAD
29111be35a1SLionel Sambucmacros and the name of the variable that will hold a pointer to the
29211be35a1SLionel Sambuctest case data.
29311be35a1SLionel SambucFollowing each of these, a block of code is expected, surrounded by the
29411be35a1SLionel Sambucopening and closing brackets.
29511be35a1SLionel Sambuc.Ss Program initialization
29611be35a1SLionel SambucThe library provides a way to easily define the test program's
29711be35a1SLionel Sambuc.Fn main
29811be35a1SLionel Sambucfunction.
29911be35a1SLionel SambucYou should never define one on your own, but rely on the
30011be35a1SLionel Sambuclibrary to do it for you.
30111be35a1SLionel SambucThis is done by using the
30211be35a1SLionel Sambuc.Fn ATF_TP_ADD_TCS
30311be35a1SLionel Sambucmacro, which is passed the name of the object that will hold the test
30411be35a1SLionel Sambuccases; i.e. the test program instance.
30511be35a1SLionel SambucThis name can be whatever you want as long as it is a valid variable
30611be35a1SLionel Sambucidentifier.
30711be35a1SLionel Sambuc.Pp
30811be35a1SLionel SambucAfter the macro, you are supposed to provide the body of a function, which
30911be35a1SLionel Sambucshould only use the
31011be35a1SLionel Sambuc.Fn ATF_TP_ADD_TC
31111be35a1SLionel Sambucmacro to register the test cases the test program will execute and return
31211be35a1SLionel Sambuca success error code.
31311be35a1SLionel SambucThe first parameter of this macro matches the name you provided in the
31411be35a1SLionel Sambucformer call.
31511be35a1SLionel SambucThe success status can be returned using the
31611be35a1SLionel Sambuc.Fn atf_no_error
31711be35a1SLionel Sambucfunction.
31811be35a1SLionel Sambuc.Ss Header definitions
31911be35a1SLionel SambucThe test case's header can define the meta-data by using the
32011be35a1SLionel Sambuc.Fn atf_tc_set_md_var
32111be35a1SLionel Sambucmethod, which takes three parameters: the first one points to the test
32211be35a1SLionel Sambuccase data, the second one specifies the meta-data variable to be set
32311be35a1SLionel Sambucand the third one specifies its value.
32411be35a1SLionel SambucBoth of them are strings.
32511be35a1SLionel Sambuc.Ss Configuration variables
32611be35a1SLionel SambucThe test case has read-only access to the current configuration variables
32711be35a1SLionel Sambucby means of the
32811be35a1SLionel Sambuc.Ft bool
32911be35a1SLionel Sambuc.Fn atf_tc_has_config_var ,
33011be35a1SLionel Sambuc.Ft const char *
33111be35a1SLionel Sambuc.Fn atf_tc_get_config_var ,
33211be35a1SLionel Sambuc.Ft const char *
33311be35a1SLionel Sambuc.Fn atf_tc_get_config_var_wd ,
33411be35a1SLionel Sambuc.Ft bool
33511be35a1SLionel Sambuc.Fn atf_tc_get_config_var_as_bool ,
33611be35a1SLionel Sambuc.Ft bool
33711be35a1SLionel Sambuc.Fn atf_tc_get_config_var_as_bool_wd ,
33811be35a1SLionel Sambuc.Ft long
33911be35a1SLionel Sambuc.Fn atf_tc_get_config_var_as_long ,
34011be35a1SLionel Sambucand the
34111be35a1SLionel Sambuc.Ft long
34211be35a1SLionel Sambuc.Fn atf_tc_get_config_var_as_long_wd
34311be35a1SLionel Sambucfunctions, which can be called in any of the three parts of a test case.
34411be35a1SLionel Sambuc.Pp
34511be35a1SLionel SambucThe
34611be35a1SLionel Sambuc.Sq _wd
34711be35a1SLionel Sambucvariants take a default value for the variable which is returned if the
34811be35a1SLionel Sambucvariable is not defined.
34911be35a1SLionel SambucThe other functions without the
35011be35a1SLionel Sambuc.Sq _wd
35111be35a1SLionel Sambucsuffix
35211be35a1SLionel Sambuc.Em require
35311be35a1SLionel Sambucthe variable to be defined.
35411be35a1SLionel Sambuc.Ss Access to the source directory
35511be35a1SLionel SambucIt is possible to get the path to the test case's source directory from any
35611be35a1SLionel Sambucof its three components by querying the
35711be35a1SLionel Sambuc.Sq srcdir
35811be35a1SLionel Sambucconfiguration variable.
35911be35a1SLionel Sambuc.Ss Requiring programs
36011be35a1SLionel SambucAside from the
36111be35a1SLionel Sambuc.Va require.progs
36211be35a1SLionel Sambucmeta-data variable available in the header only, one can also check for
36311be35a1SLionel Sambucadditional programs in the test case's body by using the
36411be35a1SLionel Sambuc.Fn atf_tc_require_prog
36511be35a1SLionel Sambucfunction, which takes the base name or full path of a single binary.
36611be35a1SLionel SambucRelative paths are forbidden.
36711be35a1SLionel SambucIf it is not found, the test case will be automatically skipped.
36811be35a1SLionel Sambuc.Ss Test case finalization
36911be35a1SLionel SambucThe test case finalizes either when the body reaches its end, at which
37011be35a1SLionel Sambucpoint the test is assumed to have
37111be35a1SLionel Sambuc.Em passed ,
37211be35a1SLionel Sambucunless any non-fatal errors were raised using
37311be35a1SLionel Sambuc.Fn atf_tc_fail_nonfatal ,
37411be35a1SLionel Sambucor at any explicit call to
37511be35a1SLionel Sambuc.Fn atf_tc_pass ,
37611be35a1SLionel Sambuc.Fn atf_tc_fail
37711be35a1SLionel Sambucor
37811be35a1SLionel Sambuc.Fn atf_tc_skip .
37911be35a1SLionel SambucThese three functions terminate the execution of the test case immediately.
38011be35a1SLionel SambucThe cleanup routine will be processed afterwards in a completely automated
38111be35a1SLionel Sambucway, regardless of the test case's termination reason.
38211be35a1SLionel Sambuc.Pp
38311be35a1SLionel Sambuc.Fn atf_tc_pass
38411be35a1SLionel Sambucdoes not take any parameters.
38511be35a1SLionel Sambuc.Fn atf_tc_fail ,
38611be35a1SLionel Sambuc.Fn atf_tc_fail_nonfatal
38711be35a1SLionel Sambucand
38811be35a1SLionel Sambuc.Fn atf_tc_skip
38911be35a1SLionel Sambuctake a format string and a variable list of parameters, which describe, in
39011be35a1SLionel Sambuca user-friendly manner, why the test case failed or was skipped,
39111be35a1SLionel Sambucrespectively.
39211be35a1SLionel SambucIt is very important to provide a clear error message in both cases so that
39311be35a1SLionel Sambucthe user can quickly know why the test did not pass.
39411be35a1SLionel Sambuc.Ss Expectations
39511be35a1SLionel SambucEverything explained in the previous section changes when the test case
39611be35a1SLionel Sambucexpectations are redefined by the programmer.
39711be35a1SLionel Sambuc.Pp
39811be35a1SLionel SambucEach test case has an internal state called
39911be35a1SLionel Sambuc.Sq expect
40011be35a1SLionel Sambucthat describes what the test case expectations are at any point in time.
40111be35a1SLionel SambucThe value of this property can change during execution by any of:
40211be35a1SLionel Sambuc.Bl -tag -width indent
40311be35a1SLionel Sambuc.It Fn atf_tc_expect_death "reason" "..."
40411be35a1SLionel SambucExpects the test case to exit prematurely regardless of the nature of the
40511be35a1SLionel Sambucexit.
40611be35a1SLionel Sambuc.It Fn atf_tc_expect_exit "exitcode" "reason" "..."
40711be35a1SLionel SambucExpects the test case to exit cleanly.
40811be35a1SLionel SambucIf
40911be35a1SLionel Sambuc.Va exitcode
41011be35a1SLionel Sambucis not
41111be35a1SLionel Sambuc.Sq -1 ,
41211be35a1SLionel Sambuc.Xr atf-run 1
41311be35a1SLionel Sambucwill validate that the exit code of the test case matches the one provided
41411be35a1SLionel Sambucin this call.
41511be35a1SLionel SambucOtherwise, the exact value will be ignored.
41611be35a1SLionel Sambuc.It Fn atf_tc_expect_fail "reason" "..."
41711be35a1SLionel SambucAny failure (be it fatal or non-fatal) raised in this mode is recorded.
41811be35a1SLionel SambucHowever, such failures do not report the test case as failed; instead, the
41911be35a1SLionel Sambuctest case finalizes cleanly and is reported as
42011be35a1SLionel Sambuc.Sq expected failure ;
42111be35a1SLionel Sambucthis report includes the provided
42211be35a1SLionel Sambuc.Fa reason
42311be35a1SLionel Sambucas part of it.
42411be35a1SLionel SambucIf no error is raised while running in this mode, then the test case is
42511be35a1SLionel Sambucreported as
42611be35a1SLionel Sambuc.Sq failed .
42711be35a1SLionel Sambuc.Pp
42811be35a1SLionel SambucThis mode is useful to reproduce actual known bugs in tests.
42911be35a1SLionel SambucWhenever the developer fixes the bug later on, the test case will start
43011be35a1SLionel Sambucreporting a failure, signaling the developer that the test case must be
43111be35a1SLionel Sambucadjusted to the new conditions.
43211be35a1SLionel SambucIn this situation, it is useful, for example, to set
43311be35a1SLionel Sambuc.Fa reason
43411be35a1SLionel Sambucas the bug number for tracking purposes.
43511be35a1SLionel Sambuc.It Fn atf_tc_expect_pass
43611be35a1SLionel SambucThis is the normal mode of execution.
43711be35a1SLionel SambucIn this mode, any failure is reported as such to the user and the test case
43811be35a1SLionel Sambucis marked as
43911be35a1SLionel Sambuc.Sq failed .
44011be35a1SLionel Sambuc.It Fn atf_tc_expect_signal "signo" "reason" "..."
44111be35a1SLionel SambucExpects the test case to terminate due to the reception of a signal.
44211be35a1SLionel SambucIf
44311be35a1SLionel Sambuc.Va signo
44411be35a1SLionel Sambucis not
44511be35a1SLionel Sambuc.Sq -1 ,
44611be35a1SLionel Sambuc.Xr atf-run 1
44711be35a1SLionel Sambucwill validate that the signal that terminated the test case matches the one
44811be35a1SLionel Sambucprovided in this call.
44911be35a1SLionel SambucOtherwise, the exact value will be ignored.
45011be35a1SLionel Sambuc.It Fn atf_tc_expect_timeout "reason" "..."
45111be35a1SLionel SambucExpects the test case to execute for longer than its timeout.
45211be35a1SLionel Sambuc.El
45311be35a1SLionel Sambuc.Ss Helper macros for common checks
45411be35a1SLionel SambucThe library provides several macros that are very handy in multiple
45511be35a1SLionel Sambucsituations.
45611be35a1SLionel SambucThese basically check some condition after executing a given statement or
45711be35a1SLionel Sambucprocessing a given expression and, if the condition is not met, they
45811be35a1SLionel Sambucreport the test case as failed.
45911be35a1SLionel Sambuc.Pp
46011be35a1SLionel SambucThe
46111be35a1SLionel Sambuc.Sq REQUIRE
46211be35a1SLionel Sambucvariant of the macros immediately abort the test case as soon as an error
46311be35a1SLionel Sambuccondition is detected by calling the
46411be35a1SLionel Sambuc.Fn atf_tc_fail
46511be35a1SLionel Sambucfunction.
46611be35a1SLionel SambucUse this variant whenever it makes no sense to continue the execution of a
46711be35a1SLionel Sambuctest case when the checked condition is not met.
46811be35a1SLionel SambucThe
46911be35a1SLionel Sambuc.Sq CHECK
47011be35a1SLionel Sambucvariant, on the other hand, reports a failure as soon as it is encountered
47111be35a1SLionel Sambucusing the
47211be35a1SLionel Sambuc.Fn atf_tc_fail_nonfatal
47311be35a1SLionel Sambucfunction, but the execution of the test case continues as if nothing had
47411be35a1SLionel Sambuchappened.
47511be35a1SLionel SambucUse this variant whenever the checked condition is important as a result of
47611be35a1SLionel Sambucthe test case, but there are other conditions that can be subsequently
47711be35a1SLionel Sambucchecked on the same run without aborting.
47811be35a1SLionel Sambuc.Pp
47911be35a1SLionel SambucAdditionally, the
48011be35a1SLionel Sambuc.Sq MSG
48111be35a1SLionel Sambucvariants take an extra set of parameters to explicitly specify the failure
48211be35a1SLionel Sambucmessage.
48311be35a1SLionel SambucThis failure message is formatted according to the
48411be35a1SLionel Sambuc.Xr printf 3
48511be35a1SLionel Sambucformatters.
48611be35a1SLionel Sambuc.Pp
48711be35a1SLionel Sambuc.Fn ATF_CHECK ,
48811be35a1SLionel Sambuc.Fn ATF_CHECK_MSG ,
48911be35a1SLionel Sambuc.Fn ATF_REQUIRE
49011be35a1SLionel Sambucand
49111be35a1SLionel Sambuc.Fn ATF_REQUIRE_MSG
49211be35a1SLionel Sambuctake an expression and fail if the expression evaluates to false.
49311be35a1SLionel Sambuc.Pp
49411be35a1SLionel Sambuc.Fn ATF_CHECK_EQ ,
49511be35a1SLionel Sambuc.Fn ATF_CHECK_EQ_MSG ,
49611be35a1SLionel Sambuc.Fn ATF_REQUIRE_EQ
49711be35a1SLionel Sambucand
49811be35a1SLionel Sambuc.Fn ATF_REQUIRE_EQ_MSG
49911be35a1SLionel Sambuctake two expressions and fail if the two evaluated values are not equal.
50011be35a1SLionel Sambuc.Pp
50111be35a1SLionel Sambuc.Fn ATF_CHECK_MATCH ,
50211be35a1SLionel Sambuc.Fn ATF_CHECK_MATCH_MSG ,
50311be35a1SLionel Sambuc.Fn ATF_REQUIRE_MATCH
50411be35a1SLionel Sambucand
50511be35a1SLionel Sambuc.Fn ATF_REQUIRE_MATCH_MSG
50611be35a1SLionel Sambuctake a regular expression and a string and fail if the regular expression does
50711be35a1SLionel Sambucnot match the given string.
50811be35a1SLionel SambucNote that the regular expression is not anchored, so it will match anywhere in
50911be35a1SLionel Sambucthe string.
51011be35a1SLionel Sambuc.Pp
51111be35a1SLionel Sambuc.Fn ATF_CHECK_STREQ ,
51211be35a1SLionel Sambuc.Fn ATF_CHECK_STREQ_MSG ,
51311be35a1SLionel Sambuc.Fn ATF_REQUIRE_STREQ
51411be35a1SLionel Sambucand
51511be35a1SLionel Sambuc.Fn ATF_REQUIRE_STREQ_MSG
51611be35a1SLionel Sambuctake two strings and fail if the two are not equal character by character.
51711be35a1SLionel Sambuc.Pp
51811be35a1SLionel Sambuc.Fn ATF_CHECK_ERRNO
51911be35a1SLionel Sambucand
52011be35a1SLionel Sambuc.Fn ATF_REQUIRE_ERRNO
52111be35a1SLionel Sambuctake, first, the error code that the check is expecting to find in the
52211be35a1SLionel Sambuc.Va errno
52311be35a1SLionel Sambucvariable and, second, a boolean expression that, if evaluates to true,
52411be35a1SLionel Sambucmeans that a call failed and
52511be35a1SLionel Sambuc.Va errno
52611be35a1SLionel Sambuchas to be checked against the first value.
52711be35a1SLionel Sambuc.Ss Utility functions
52811be35a1SLionel SambucThe following functions are provided as part of the
52911be35a1SLionel Sambuc.Nm
53011be35a1SLionel SambucAPI to simplify the creation of a variety of tests.
53111be35a1SLionel SambucIn particular, these are useful to write tests for command-line interfaces.
53211be35a1SLionel Sambuc.Pp
53311be35a1SLionel Sambuc.Ft void
53411be35a1SLionel Sambuc.Fo atf_utils_cat_file
53511be35a1SLionel Sambuc.Fa "const char *file"
53611be35a1SLionel Sambuc.Fa "const char *prefix"
53711be35a1SLionel Sambuc.Fc
538*0a6a1f1dSLionel Sambuc.Bd -ragged -offset indent
53911be35a1SLionel SambucPrints the contents of
54011be35a1SLionel Sambuc.Fa file
54111be35a1SLionel Sambucto the standard output, prefixing every line with the string in
54211be35a1SLionel Sambuc.Fa prefix .
54311be35a1SLionel Sambuc.Ed
54411be35a1SLionel Sambuc.Pp
54511be35a1SLionel Sambuc.Ft bool
54611be35a1SLionel Sambuc.Fo atf_utils_compare_file
54711be35a1SLionel Sambuc.Fa "const char *file"
54811be35a1SLionel Sambuc.Fa "const char *contents"
54911be35a1SLionel Sambuc.Fc
550*0a6a1f1dSLionel Sambuc.Bd -ragged -offset indent
55111be35a1SLionel SambucReturns true if the given
55211be35a1SLionel Sambuc.Fa file
55311be35a1SLionel Sambucmatches exactly the expected inlined
55411be35a1SLionel Sambuc.Fa contents .
55511be35a1SLionel Sambuc.Ed
55611be35a1SLionel Sambuc.Pp
55711be35a1SLionel Sambuc.Ft void
55811be35a1SLionel Sambuc.Fo atf_utils_copy_file
55911be35a1SLionel Sambuc.Fa "const char *source"
56011be35a1SLionel Sambuc.Fa "const char *destination"
56111be35a1SLionel Sambuc.Fc
562*0a6a1f1dSLionel Sambuc.Bd -ragged -offset indent
56311be35a1SLionel SambucCopies the file
56411be35a1SLionel Sambuc.Fa source
56511be35a1SLionel Sambucto
56611be35a1SLionel Sambuc.Fa destination .
56711be35a1SLionel SambucThe permissions of the file are preserved during the code.
56811be35a1SLionel Sambuc.Ed
56911be35a1SLionel Sambuc.Pp
57011be35a1SLionel Sambuc.Ft void
57111be35a1SLionel Sambuc.Fo atf_utils_create_file
57211be35a1SLionel Sambuc.Fa "const char *file"
57311be35a1SLionel Sambuc.Fa "const char *contents"
57411be35a1SLionel Sambuc.Fa "..."
57511be35a1SLionel Sambuc.Fc
576*0a6a1f1dSLionel Sambuc.Bd -ragged -offset indent
57711be35a1SLionel SambucCreates
57811be35a1SLionel Sambuc.Fa file
57911be35a1SLionel Sambucwith the text given in
58011be35a1SLionel Sambuc.Fa contents ,
58111be35a1SLionel Sambucwhich is a formatting string that uses the rest of the variable arguments.
58211be35a1SLionel Sambuc.Ed
58311be35a1SLionel Sambuc.Pp
58411be35a1SLionel Sambuc.Ft void
58511be35a1SLionel Sambuc.Fo atf_utils_file_exists
58611be35a1SLionel Sambuc.Fa "const char *file"
58711be35a1SLionel Sambuc.Fc
588*0a6a1f1dSLionel Sambuc.Bd -ragged -offset indent
58911be35a1SLionel SambucChecks if
59011be35a1SLionel Sambuc.Fa file
59111be35a1SLionel Sambucexists.
59211be35a1SLionel Sambuc.Ed
59311be35a1SLionel Sambuc.Pp
59411be35a1SLionel Sambuc.Ft pid_t
59511be35a1SLionel Sambuc.Fo atf_utils_fork
59611be35a1SLionel Sambuc.Fa "void"
59711be35a1SLionel Sambuc.Fc
598*0a6a1f1dSLionel Sambuc.Bd -ragged -offset indent
59911be35a1SLionel SambucForks a process and redirects the standard output and standard error of the
60011be35a1SLionel Sambucchild to files for later validation with
60111be35a1SLionel Sambuc.Fn atf_utils_wait .
60211be35a1SLionel SambucFails the test case if the fork fails, so this does not return an error.
60311be35a1SLionel Sambuc.Ed
60411be35a1SLionel Sambuc.Pp
60511be35a1SLionel Sambuc.Ft void
60611be35a1SLionel Sambuc.Fo atf_utils_free_charpp
60711be35a1SLionel Sambuc.Fa "char **argv"
60811be35a1SLionel Sambuc.Fc
609*0a6a1f1dSLionel Sambuc.Bd -ragged -offset indent
61011be35a1SLionel SambucFrees a dynamically-allocated array of dynamically-allocated strings.
61111be35a1SLionel Sambuc.Ed
61211be35a1SLionel Sambuc.Pp
61311be35a1SLionel Sambuc.Ft bool
61411be35a1SLionel Sambuc.Fo atf_utils_grep_file
61511be35a1SLionel Sambuc.Fa "const char *regexp"
61611be35a1SLionel Sambuc.Fa "const char *file"
61711be35a1SLionel Sambuc.Fa "..."
61811be35a1SLionel Sambuc.Fc
619*0a6a1f1dSLionel Sambuc.Bd -ragged -offset indent
62011be35a1SLionel SambucSearches for the
62111be35a1SLionel Sambuc.Fa regexp ,
62211be35a1SLionel Sambucwhich is a formatting string representing the regular expression,
62311be35a1SLionel Sambucin the
62411be35a1SLionel Sambuc.Fa file .
62511be35a1SLionel SambucThe variable arguments are used to construct the regular expression.
62611be35a1SLionel Sambuc.Ed
62711be35a1SLionel Sambuc.Pp
62811be35a1SLionel Sambuc.Ft bool
62911be35a1SLionel Sambuc.Fo atf_utils_grep_string
63011be35a1SLionel Sambuc.Fa "const char *regexp"
63111be35a1SLionel Sambuc.Fa "const char *str"
63211be35a1SLionel Sambuc.Fa "..."
63311be35a1SLionel Sambuc.Fc
634*0a6a1f1dSLionel Sambuc.Bd -ragged -offset indent
63511be35a1SLionel SambucSearches for the
63611be35a1SLionel Sambuc.Fa regexp ,
63711be35a1SLionel Sambucwhich is a formatting string representing the regular expression,
63811be35a1SLionel Sambucin the literal string
63911be35a1SLionel Sambuc.Fa str .
64011be35a1SLionel SambucThe variable arguments are used to construct the regular expression.
64111be35a1SLionel Sambuc.Ed
64211be35a1SLionel Sambuc.Pp
64311be35a1SLionel Sambuc.Ft char *
64411be35a1SLionel Sambuc.Fo atf_utils_readline
64511be35a1SLionel Sambuc.Fa "int fd"
64611be35a1SLionel Sambuc.Fc
647*0a6a1f1dSLionel Sambuc.Bd -ragged -offset indent
64811be35a1SLionel SambucReads a line from the file descriptor
64911be35a1SLionel Sambuc.Fa fd .
65011be35a1SLionel SambucThe line, if any, is returned as a dynamically-allocated buffer that must be
65111be35a1SLionel Sambucreleased with
65211be35a1SLionel Sambuc.Xr free 3 .
65311be35a1SLionel SambucIf there was nothing to read, returns
65411be35a1SLionel Sambuc.Sq NULL .
65511be35a1SLionel Sambuc.Ed
65611be35a1SLionel Sambuc.Pp
65711be35a1SLionel Sambuc.Ft void
65811be35a1SLionel Sambuc.Fo atf_utils_redirect
65911be35a1SLionel Sambuc.Fa "const int fd"
66011be35a1SLionel Sambuc.Fa "const char *file"
66111be35a1SLionel Sambuc.Fc
662*0a6a1f1dSLionel Sambuc.Bd -ragged -offset indent
66311be35a1SLionel SambucRedirects the given file descriptor
66411be35a1SLionel Sambuc.Fa fd
66511be35a1SLionel Sambucto
66611be35a1SLionel Sambuc.Fa file .
66711be35a1SLionel SambucThis function exits the process in case of an error and does not properly mark
66811be35a1SLionel Sambucthe test case as failed.
66911be35a1SLionel SambucAs a result, it should only be used in subprocesses of the test case; specially
67011be35a1SLionel Sambucthose spawned by
67111be35a1SLionel Sambuc.Fn atf_utils_fork .
67211be35a1SLionel Sambuc.Ed
67311be35a1SLionel Sambuc.Pp
67411be35a1SLionel Sambuc.Ft void
67511be35a1SLionel Sambuc.Fo atf_utils_wait
67611be35a1SLionel Sambuc.Fa "const pid_t pid"
67711be35a1SLionel Sambuc.Fa "const int expected_exit_status"
67811be35a1SLionel Sambuc.Fa "const char *expected_stdout"
67911be35a1SLionel Sambuc.Fa "const char *expected_stderr"
68011be35a1SLionel Sambuc.Fc
681*0a6a1f1dSLionel Sambuc.Bd -ragged -offset indent
68211be35a1SLionel SambucWaits and validates the result of a subprocess spawned with
68311be35a1SLionel Sambuc.Fn atf_utils_wait .
68411be35a1SLionel SambucThe validation involves checking that the subprocess exited cleanly and returned
68511be35a1SLionel Sambucthe code specified in
68611be35a1SLionel Sambuc.Fa expected_exit_status
68711be35a1SLionel Sambucand that its standard output and standard error match the strings given in
68811be35a1SLionel Sambuc.Fa expected_stdout
68911be35a1SLionel Sambucand
69011be35a1SLionel Sambuc.Fa expected_stderr .
69111be35a1SLionel Sambuc.Pp
69211be35a1SLionel SambucIf any of the
69311be35a1SLionel Sambuc.Fa expected_stdout
69411be35a1SLionel Sambucor
69511be35a1SLionel Sambuc.Fa expected_stderr
69611be35a1SLionel Sambucstrings are prefixed with
69711be35a1SLionel Sambuc.Sq save: ,
69811be35a1SLionel Sambucthen they specify the name of the file into which to store the stdout or stderr
69911be35a1SLionel Sambucof the subprocess, and no comparison is performed.
70011be35a1SLionel Sambuc.Ed
70111be35a1SLionel Sambuc.Sh EXAMPLES
70211be35a1SLionel SambucThe following shows a complete test program with a single test case that
70311be35a1SLionel Sambucvalidates the addition operator:
70411be35a1SLionel Sambuc.Bd -literal -offset indent
70511be35a1SLionel Sambuc#include <atf-c.h>
70611be35a1SLionel Sambuc
70711be35a1SLionel SambucATF_TC(addition);
70811be35a1SLionel SambucATF_TC_HEAD(addition, tc)
70911be35a1SLionel Sambuc{
71011be35a1SLionel Sambuc    atf_tc_set_md_var(tc, "descr",
71111be35a1SLionel Sambuc                      "Sample tests for the addition operator");
71211be35a1SLionel Sambuc}
71311be35a1SLionel SambucATF_TC_BODY(addition, tc)
71411be35a1SLionel Sambuc{
71511be35a1SLionel Sambuc    ATF_CHECK_EQ(0 + 0, 0);
71611be35a1SLionel Sambuc    ATF_CHECK_EQ(0 + 1, 1);
71711be35a1SLionel Sambuc    ATF_CHECK_EQ(1 + 0, 1);
71811be35a1SLionel Sambuc
71911be35a1SLionel Sambuc    ATF_CHECK_EQ(1 + 1, 2);
72011be35a1SLionel Sambuc
72111be35a1SLionel Sambuc    ATF_CHECK_EQ(100 + 200, 300);
72211be35a1SLionel Sambuc}
72311be35a1SLionel Sambuc
72411be35a1SLionel SambucATF_TC(string_formatting);
72511be35a1SLionel SambucATF_TC_HEAD(string_formatting, tc)
72611be35a1SLionel Sambuc{
72711be35a1SLionel Sambuc    atf_tc_set_md_var(tc, "descr",
72811be35a1SLionel Sambuc                      "Sample tests for the snprintf");
72911be35a1SLionel Sambuc}
73011be35a1SLionel SambucATF_TC_BODY(string_formatting, tc)
73111be35a1SLionel Sambuc{
73211be35a1SLionel Sambuc    char buf[1024];
73311be35a1SLionel Sambuc    snprintf(buf, sizeof(buf), "a %s", "string");
73411be35a1SLionel Sambuc    ATF_CHECK_STREQ_MSG("a string", buf, "%s is not working");
73511be35a1SLionel Sambuc}
73611be35a1SLionel Sambuc
73711be35a1SLionel SambucATF_TC(open_failure);
73811be35a1SLionel SambucATF_TC_HEAD(open_failure, tc)
73911be35a1SLionel Sambuc{
74011be35a1SLionel Sambuc    atf_tc_set_md_var(tc, "descr",
74111be35a1SLionel Sambuc                      "Sample tests for the open function");
74211be35a1SLionel Sambuc}
74311be35a1SLionel SambucATF_TC_BODY(open_failure, tc)
74411be35a1SLionel Sambuc{
74511be35a1SLionel Sambuc    ATF_CHECK_ERRNO(ENOENT, open("non-existent", O_RDONLY) == -1);
74611be35a1SLionel Sambuc}
74711be35a1SLionel Sambuc
74811be35a1SLionel SambucATF_TC(known_bug);
74911be35a1SLionel SambucATF_TC_HEAD(known_bug, tc)
75011be35a1SLionel Sambuc{
75111be35a1SLionel Sambuc    atf_tc_set_md_var(tc, "descr",
75211be35a1SLionel Sambuc                      "Reproduces a known bug");
75311be35a1SLionel Sambuc}
75411be35a1SLionel SambucATF_TC_BODY(known_bug, tc)
75511be35a1SLionel Sambuc{
75611be35a1SLionel Sambuc    atf_tc_expect_fail("See bug number foo/bar");
75711be35a1SLionel Sambuc    ATF_CHECK_EQ(3, 1 + 1);
75811be35a1SLionel Sambuc    atf_tc_expect_pass();
75911be35a1SLionel Sambuc    ATF_CHECK_EQ(3, 1 + 2);
76011be35a1SLionel Sambuc}
76111be35a1SLionel Sambuc
76211be35a1SLionel SambucATF_TP_ADD_TCS(tp)
76311be35a1SLionel Sambuc{
76411be35a1SLionel Sambuc    ATF_TP_ADD_TC(tp, addition);
76511be35a1SLionel Sambuc    ATF_TP_ADD_TC(tp, string_formatting);
76611be35a1SLionel Sambuc    ATF_TP_ADD_TC(tp, open_failure);
76711be35a1SLionel Sambuc    ATF_TP_ADD_TC(tp, known_bug);
76811be35a1SLionel Sambuc
76911be35a1SLionel Sambuc    return atf_no_error();
77011be35a1SLionel Sambuc}
77111be35a1SLionel Sambuc.Ed
77211be35a1SLionel Sambuc.Sh SEE ALSO
77311be35a1SLionel Sambuc.Xr atf-test-program 1 ,
77411be35a1SLionel Sambuc.Xr atf-test-case 4 ,
77511be35a1SLionel Sambuc.Xr atf 7
776