xref: /freebsd/contrib/atf/atf-c/atf-c.3 (revision 71a1ae7cebd3791d4d18ac9620a7a4ce8cf15819)
10677dfd1SJulio Merino.\" Copyright (c) 2008 The NetBSD Foundation, Inc.
20677dfd1SJulio Merino.\" All rights reserved.
30677dfd1SJulio Merino.\"
40677dfd1SJulio Merino.\" Redistribution and use in source and binary forms, with or without
50677dfd1SJulio Merino.\" modification, are permitted provided that the following conditions
60677dfd1SJulio Merino.\" are met:
70677dfd1SJulio Merino.\" 1. Redistributions of source code must retain the above copyright
80677dfd1SJulio Merino.\"    notice, this list of conditions and the following disclaimer.
90677dfd1SJulio Merino.\" 2. Redistributions in binary form must reproduce the above copyright
100677dfd1SJulio Merino.\"    notice, this list of conditions and the following disclaimer in the
110677dfd1SJulio Merino.\"    documentation and/or other materials provided with the distribution.
120677dfd1SJulio Merino.\"
130677dfd1SJulio Merino.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
140677dfd1SJulio Merino.\" CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
150677dfd1SJulio Merino.\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
160677dfd1SJulio Merino.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
170677dfd1SJulio Merino.\" IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
180677dfd1SJulio Merino.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
190677dfd1SJulio Merino.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
200677dfd1SJulio Merino.\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
210677dfd1SJulio Merino.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
220677dfd1SJulio Merino.\" IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
230677dfd1SJulio Merino.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
240677dfd1SJulio Merino.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25*71a1ae7cSAlan Somers.Dd February 23, 2021
260677dfd1SJulio Merino.Dt ATF-C 3
270677dfd1SJulio Merino.Os
280677dfd1SJulio Merino.Sh NAME
290677dfd1SJulio Merino.Nm atf-c ,
300677dfd1SJulio Merino.Nm ATF_CHECK ,
310677dfd1SJulio Merino.Nm ATF_CHECK_MSG ,
320677dfd1SJulio Merino.Nm ATF_CHECK_EQ ,
330677dfd1SJulio Merino.Nm ATF_CHECK_EQ_MSG ,
340677dfd1SJulio Merino.Nm ATF_CHECK_MATCH ,
350677dfd1SJulio Merino.Nm ATF_CHECK_MATCH_MSG ,
360677dfd1SJulio Merino.Nm ATF_CHECK_STREQ ,
370677dfd1SJulio Merino.Nm ATF_CHECK_STREQ_MSG ,
38*71a1ae7cSAlan Somers.Nm ATF_CHECK_INTEQ ,
39*71a1ae7cSAlan Somers.Nm ATF_CHECK_INTEQ_MSG ,
400677dfd1SJulio Merino.Nm ATF_CHECK_ERRNO ,
410677dfd1SJulio Merino.Nm ATF_REQUIRE ,
420677dfd1SJulio Merino.Nm ATF_REQUIRE_MSG ,
430677dfd1SJulio Merino.Nm ATF_REQUIRE_EQ ,
440677dfd1SJulio Merino.Nm ATF_REQUIRE_EQ_MSG ,
450677dfd1SJulio Merino.Nm ATF_REQUIRE_MATCH ,
460677dfd1SJulio Merino.Nm ATF_REQUIRE_MATCH_MSG ,
470677dfd1SJulio Merino.Nm ATF_REQUIRE_STREQ ,
480677dfd1SJulio Merino.Nm ATF_REQUIRE_STREQ_MSG ,
49*71a1ae7cSAlan Somers.Nm ATF_REQUIRE_INTEQ ,
50*71a1ae7cSAlan Somers.Nm ATF_REQUIRE_INTEQ_MSG ,
510677dfd1SJulio Merino.Nm ATF_REQUIRE_ERRNO ,
520677dfd1SJulio Merino.Nm ATF_TC ,
530677dfd1SJulio Merino.Nm ATF_TC_BODY ,
540677dfd1SJulio Merino.Nm ATF_TC_BODY_NAME ,
550677dfd1SJulio Merino.Nm ATF_TC_CLEANUP ,
560677dfd1SJulio Merino.Nm ATF_TC_CLEANUP_NAME ,
570677dfd1SJulio Merino.Nm ATF_TC_HEAD ,
580677dfd1SJulio Merino.Nm ATF_TC_HEAD_NAME ,
590677dfd1SJulio Merino.Nm ATF_TC_NAME ,
600677dfd1SJulio Merino.Nm ATF_TC_WITH_CLEANUP ,
610677dfd1SJulio Merino.Nm ATF_TC_WITHOUT_HEAD ,
620677dfd1SJulio Merino.Nm ATF_TP_ADD_TC ,
630677dfd1SJulio Merino.Nm ATF_TP_ADD_TCS ,
640677dfd1SJulio Merino.Nm atf_tc_get_config_var ,
650677dfd1SJulio Merino.Nm atf_tc_get_config_var_wd ,
660677dfd1SJulio Merino.Nm atf_tc_get_config_var_as_bool ,
670677dfd1SJulio Merino.Nm atf_tc_get_config_var_as_bool_wd ,
680677dfd1SJulio Merino.Nm atf_tc_get_config_var_as_long ,
690677dfd1SJulio Merino.Nm atf_tc_get_config_var_as_long_wd ,
700677dfd1SJulio Merino.Nm atf_no_error ,
710677dfd1SJulio Merino.Nm atf_tc_expect_death ,
720677dfd1SJulio Merino.Nm atf_tc_expect_exit ,
730677dfd1SJulio Merino.Nm atf_tc_expect_fail ,
740677dfd1SJulio Merino.Nm atf_tc_expect_pass ,
750677dfd1SJulio Merino.Nm atf_tc_expect_signal ,
760677dfd1SJulio Merino.Nm atf_tc_expect_timeout ,
770677dfd1SJulio Merino.Nm atf_tc_fail ,
780677dfd1SJulio Merino.Nm atf_tc_fail_nonfatal ,
790677dfd1SJulio Merino.Nm atf_tc_pass ,
800677dfd1SJulio Merino.Nm atf_tc_skip ,
810677dfd1SJulio Merino.Nm atf_utils_cat_file ,
820677dfd1SJulio Merino.Nm atf_utils_compare_file ,
830677dfd1SJulio Merino.Nm atf_utils_copy_file ,
840677dfd1SJulio Merino.Nm atf_utils_create_file ,
850677dfd1SJulio Merino.Nm atf_utils_file_exists ,
860677dfd1SJulio Merino.Nm atf_utils_fork ,
870677dfd1SJulio Merino.Nm atf_utils_free_charpp ,
880677dfd1SJulio Merino.Nm atf_utils_grep_file ,
890677dfd1SJulio Merino.Nm atf_utils_grep_string ,
900677dfd1SJulio Merino.Nm atf_utils_readline ,
910677dfd1SJulio Merino.Nm atf_utils_redirect ,
920677dfd1SJulio Merino.Nm atf_utils_wait
930677dfd1SJulio Merino.Nd C API to write ATF-based test programs
940677dfd1SJulio Merino.Sh SYNOPSIS
950677dfd1SJulio Merino.In atf-c.h
960677dfd1SJulio Merino.\" NO_CHECK_STYLE_BEGIN
970677dfd1SJulio Merino.Fn ATF_CHECK "expression"
980677dfd1SJulio Merino.Fn ATF_CHECK_MSG "expression" "fail_msg_fmt" ...
990677dfd1SJulio Merino.Fn ATF_CHECK_EQ "expected_expression" "actual_expression"
1000677dfd1SJulio Merino.Fn ATF_CHECK_EQ_MSG "expected_expression" "actual_expression" "fail_msg_fmt" ...
1010677dfd1SJulio Merino.Fn ATF_CHECK_MATCH "regexp" "string"
1020677dfd1SJulio Merino.Fn ATF_CHECK_MATCH_MSG "regexp" "string" "fail_msg_fmt" ...
103*71a1ae7cSAlan Somers.Fn ATF_CHECK_STREQ "expected_string" "actual_string"
104*71a1ae7cSAlan Somers.Fn ATF_CHECK_STREQ_MSG "expected_string" "actual_string" "fail_msg_fmt" ...
105*71a1ae7cSAlan Somers.Fn ATF_CHECK_INTEQ "expected_int" "actual_int"
106*71a1ae7cSAlan Somers.Fn ATF_CHECK_INTEQ_MSG "expected_int" "actual_int" "fail_msg_fmt" ...
1070677dfd1SJulio Merino.Fn ATF_CHECK_ERRNO "expected_errno" "bool_expression"
1080677dfd1SJulio Merino.Fn ATF_REQUIRE "expression"
1090677dfd1SJulio Merino.Fn ATF_REQUIRE_MSG "expression" "fail_msg_fmt" ...
1100677dfd1SJulio Merino.Fn ATF_REQUIRE_EQ "expected_expression" "actual_expression"
1110677dfd1SJulio Merino.Fn ATF_REQUIRE_EQ_MSG "expected_expression" "actual_expression" "fail_msg_fmt" ...
1120677dfd1SJulio Merino.Fn ATF_REQUIRE_MATCH "regexp" "string"
1130677dfd1SJulio Merino.Fn ATF_REQUIRE_MATCH_MSG "regexp" "string" "fail_msg_fmt" ...
1140677dfd1SJulio Merino.Fn ATF_REQUIRE_STREQ "expected_string" "actual_string"
1150677dfd1SJulio Merino.Fn ATF_REQUIRE_STREQ_MSG "expected_string" "actual_string" "fail_msg_fmt" ...
116*71a1ae7cSAlan Somers.Fn ATF_REQUIRE_INTEQ "expected_int" "actual_int"
117*71a1ae7cSAlan Somers.Fn ATF_REQUIRE_INTEQ_MSG "expected_int" "actual_int" "fail_msg_fmt" ...
1180677dfd1SJulio Merino.Fn ATF_REQUIRE_ERRNO "expected_errno" "bool_expression"
1190677dfd1SJulio Merino.\" NO_CHECK_STYLE_END
1200677dfd1SJulio Merino.Fn ATF_TC "name"
1210677dfd1SJulio Merino.Fn ATF_TC_BODY "name" "tc"
1220677dfd1SJulio Merino.Fn ATF_TC_BODY_NAME "name"
1230677dfd1SJulio Merino.Fn ATF_TC_CLEANUP "name" "tc"
1240677dfd1SJulio Merino.Fn ATF_TC_CLEANUP_NAME "name"
1250677dfd1SJulio Merino.Fn ATF_TC_HEAD "name" "tc"
1260677dfd1SJulio Merino.Fn ATF_TC_HEAD_NAME "name"
1270677dfd1SJulio Merino.Fn ATF_TC_NAME "name"
1280677dfd1SJulio Merino.Fn ATF_TC_WITH_CLEANUP "name"
1290677dfd1SJulio Merino.Fn ATF_TC_WITHOUT_HEAD "name"
1300677dfd1SJulio Merino.Fn ATF_TP_ADD_TC "tp_name" "tc_name"
1310677dfd1SJulio Merino.Fn ATF_TP_ADD_TCS "tp_name"
1320677dfd1SJulio Merino.Fn atf_tc_get_config_var "tc" "varname"
1330677dfd1SJulio Merino.Fn atf_tc_get_config_var_wd "tc" "variable_name" "default_value"
1340677dfd1SJulio Merino.Fn atf_tc_get_config_var_as_bool "tc" "variable_name"
1350677dfd1SJulio Merino.Fn atf_tc_get_config_var_as_bool_wd "tc" "variable_name" "default_value"
1360677dfd1SJulio Merino.Fn atf_tc_get_config_var_as_long "tc" "variable_name"
1370677dfd1SJulio Merino.Fn atf_tc_get_config_var_as_long_wd "tc" "variable_name" "default_value"
1380677dfd1SJulio Merino.Fn atf_no_error
1390677dfd1SJulio Merino.Fn atf_tc_expect_death "reason" "..."
1400677dfd1SJulio Merino.Fn atf_tc_expect_exit "exitcode" "reason" "..."
1410677dfd1SJulio Merino.Fn atf_tc_expect_fail "reason" "..."
1420677dfd1SJulio Merino.Fn atf_tc_expect_pass
1430677dfd1SJulio Merino.Fn atf_tc_expect_signal "signo" "reason" "..."
1440677dfd1SJulio Merino.Fn atf_tc_expect_timeout "reason" "..."
1450677dfd1SJulio Merino.Fn atf_tc_fail "reason"
1460677dfd1SJulio Merino.Fn atf_tc_fail_nonfatal "reason"
1470677dfd1SJulio Merino.Fn atf_tc_pass
1480677dfd1SJulio Merino.Fn atf_tc_skip "reason"
1490677dfd1SJulio Merino.Ft void
1500677dfd1SJulio Merino.Fo atf_utils_cat_file
1510677dfd1SJulio Merino.Fa "const char *file"
1520677dfd1SJulio Merino.Fa "const char *prefix"
1530677dfd1SJulio Merino.Fc
1540677dfd1SJulio Merino.Ft bool
1550677dfd1SJulio Merino.Fo atf_utils_compare_file
1560677dfd1SJulio Merino.Fa "const char *file"
1570677dfd1SJulio Merino.Fa "const char *contents"
1580677dfd1SJulio Merino.Fc
1590677dfd1SJulio Merino.Ft void
1600677dfd1SJulio Merino.Fo atf_utils_copy_file
1610677dfd1SJulio Merino.Fa "const char *source"
1620677dfd1SJulio Merino.Fa "const char *destination"
1630677dfd1SJulio Merino.Fc
1640677dfd1SJulio Merino.Ft void
1650677dfd1SJulio Merino.Fo atf_utils_create_file
1660677dfd1SJulio Merino.Fa "const char *file"
1670677dfd1SJulio Merino.Fa "const char *contents"
1680677dfd1SJulio Merino.Fa "..."
1690677dfd1SJulio Merino.Fc
1700677dfd1SJulio Merino.Ft void
1710677dfd1SJulio Merino.Fo atf_utils_file_exists
1720677dfd1SJulio Merino.Fa "const char *file"
1730677dfd1SJulio Merino.Fc
1740677dfd1SJulio Merino.Ft pid_t
1750677dfd1SJulio Merino.Fo atf_utils_fork
1760677dfd1SJulio Merino.Fa "void"
1770677dfd1SJulio Merino.Fc
1780677dfd1SJulio Merino.Ft void
1790677dfd1SJulio Merino.Fo atf_utils_free_charpp
1800677dfd1SJulio Merino.Fa "char **argv"
1810677dfd1SJulio Merino.Fc
1820677dfd1SJulio Merino.Ft bool
1830677dfd1SJulio Merino.Fo atf_utils_grep_file
1840677dfd1SJulio Merino.Fa "const char *regexp"
1850677dfd1SJulio Merino.Fa "const char *file"
1860677dfd1SJulio Merino.Fa "..."
1870677dfd1SJulio Merino.Fc
1880677dfd1SJulio Merino.Ft bool
1890677dfd1SJulio Merino.Fo atf_utils_grep_string
1900677dfd1SJulio Merino.Fa "const char *regexp"
1910677dfd1SJulio Merino.Fa "const char *str"
1920677dfd1SJulio Merino.Fa "..."
1930677dfd1SJulio Merino.Fc
1940677dfd1SJulio Merino.Ft char *
1950677dfd1SJulio Merino.Fo atf_utils_readline
1960677dfd1SJulio Merino.Fa "int fd"
1970677dfd1SJulio Merino.Fc
1980677dfd1SJulio Merino.Ft void
1990677dfd1SJulio Merino.Fo atf_utils_redirect
2000677dfd1SJulio Merino.Fa "const int fd"
2010677dfd1SJulio Merino.Fa "const char *file"
2020677dfd1SJulio Merino.Fc
2030677dfd1SJulio Merino.Ft void
2040677dfd1SJulio Merino.Fo atf_utils_wait
2050677dfd1SJulio Merino.Fa "const pid_t pid"
2060677dfd1SJulio Merino.Fa "const int expected_exit_status"
2070677dfd1SJulio Merino.Fa "const char *expected_stdout"
2080677dfd1SJulio Merino.Fa "const char *expected_stderr"
2090677dfd1SJulio Merino.Fc
2100677dfd1SJulio Merino.Sh DESCRIPTION
2110677dfd1SJulio MerinoATF provides a C programming interface to implement test programs.
2120677dfd1SJulio MerinoC-based test programs follow this template:
2130677dfd1SJulio Merino.Bd -literal -offset indent
214ddde9fa7SEnji Cooper\&... C-specific includes go here ...
2150677dfd1SJulio Merino
2160677dfd1SJulio Merino#include <atf-c.h>
2170677dfd1SJulio Merino
2180677dfd1SJulio MerinoATF_TC(tc1);
2190677dfd1SJulio MerinoATF_TC_HEAD(tc1, tc)
2200677dfd1SJulio Merino{
2210677dfd1SJulio Merino    ... first test case's header ...
2220677dfd1SJulio Merino}
2230677dfd1SJulio MerinoATF_TC_BODY(tc1, tc)
2240677dfd1SJulio Merino{
2250677dfd1SJulio Merino    ... first test case's body ...
2260677dfd1SJulio Merino}
2270677dfd1SJulio Merino
2280677dfd1SJulio MerinoATF_TC_WITH_CLEANUP(tc2);
2290677dfd1SJulio MerinoATF_TC_HEAD(tc2, tc)
2300677dfd1SJulio Merino{
2310677dfd1SJulio Merino    ... second test case's header ...
2320677dfd1SJulio Merino}
2330677dfd1SJulio MerinoATF_TC_BODY(tc2, tc)
2340677dfd1SJulio Merino{
2350677dfd1SJulio Merino    ... second test case's body ...
2360677dfd1SJulio Merino}
2370677dfd1SJulio MerinoATF_TC_CLEANUP(tc2, tc)
2380677dfd1SJulio Merino{
2390677dfd1SJulio Merino    ... second test case's cleanup ...
2400677dfd1SJulio Merino}
2410677dfd1SJulio Merino
2420677dfd1SJulio MerinoATF_TC_WITHOUT_HEAD(tc3);
2430677dfd1SJulio MerinoATF_TC_BODY(tc3, tc)
2440677dfd1SJulio Merino{
2450677dfd1SJulio Merino    ... third test case's body ...
2460677dfd1SJulio Merino}
2470677dfd1SJulio Merino
248ddde9fa7SEnji Cooper\&... additional test cases ...
2490677dfd1SJulio Merino
2500677dfd1SJulio MerinoATF_TP_ADD_TCS(tp)
2510677dfd1SJulio Merino{
2520677dfd1SJulio Merino    ATF_TP_ADD_TC(tcs, tc1);
2530677dfd1SJulio Merino    ATF_TP_ADD_TC(tcs, tc2);
2540677dfd1SJulio Merino    ATF_TP_ADD_TC(tcs, tc3);
2550677dfd1SJulio Merino    ... add additional test cases ...
2560677dfd1SJulio Merino
2570677dfd1SJulio Merino    return atf_no_error();
2580677dfd1SJulio Merino}
2590677dfd1SJulio Merino.Ed
2600677dfd1SJulio Merino.Ss Definition of test cases
2610677dfd1SJulio MerinoTest cases have an identifier and are composed of three different parts:
2620677dfd1SJulio Merinothe header, the body and an optional cleanup routine, all of which are
2630677dfd1SJulio Merinodescribed in
2640677dfd1SJulio Merino.Xr atf-test-case 4 .
2650677dfd1SJulio MerinoTo define test cases, one can use the
2660677dfd1SJulio Merino.Fn ATF_TC ,
2670677dfd1SJulio Merino.Fn ATF_TC_WITH_CLEANUP
2680677dfd1SJulio Merinoor the
2690677dfd1SJulio Merino.Fn ATF_TC_WITHOUT_HEAD
270ddde9fa7SEnji Coopermacros, which take a single parameter specifying the test case's name.
2710677dfd1SJulio Merino.Fn ATF_TC ,
2720677dfd1SJulio Merinorequires to define a head and a body for the test case,
2730677dfd1SJulio Merino.Fn ATF_TC_WITH_CLEANUP
2740677dfd1SJulio Merinorequires to define a head, a body and a cleanup for the test case and
2750677dfd1SJulio Merino.Fn ATF_TC_WITHOUT_HEAD
2760677dfd1SJulio Merinorequires only a body for the test case.
2770677dfd1SJulio MerinoIt is important to note that these
2780677dfd1SJulio Merino.Em do not
2790677dfd1SJulio Merinoset the test case up for execution when the program is run.
2800677dfd1SJulio MerinoIn order to do so, a later registration is needed with the
2810677dfd1SJulio Merino.Fn ATF_TP_ADD_TC
2820677dfd1SJulio Merinomacro detailed in
2830677dfd1SJulio Merino.Sx Program initialization .
2840677dfd1SJulio Merino.Pp
2850677dfd1SJulio MerinoLater on, one must define the three parts of the body by means of three
2860677dfd1SJulio Merinofunctions.
2870677dfd1SJulio MerinoTheir headers are given by the
2880677dfd1SJulio Merino.Fn ATF_TC_HEAD ,
2890677dfd1SJulio Merino.Fn ATF_TC_BODY
2900677dfd1SJulio Merinoand
2910677dfd1SJulio Merino.Fn ATF_TC_CLEANUP
2920677dfd1SJulio Merinomacros, all of which take the test case name provided to the
2930677dfd1SJulio Merino.Fn ATF_TC
2940677dfd1SJulio Merino.Fn ATF_TC_WITH_CLEANUP ,
2950677dfd1SJulio Merinoor
2960677dfd1SJulio Merino.Fn ATF_TC_WITHOUT_HEAD
2970677dfd1SJulio Merinomacros and the name of the variable that will hold a pointer to the
2980677dfd1SJulio Merinotest case data.
2990677dfd1SJulio MerinoFollowing each of these, a block of code is expected, surrounded by the
3000677dfd1SJulio Merinoopening and closing brackets.
3010677dfd1SJulio Merino.Ss Program initialization
3020677dfd1SJulio MerinoThe library provides a way to easily define the test program's
3030677dfd1SJulio Merino.Fn main
3040677dfd1SJulio Merinofunction.
3050677dfd1SJulio MerinoYou should never define one on your own, but rely on the
3060677dfd1SJulio Merinolibrary to do it for you.
3070677dfd1SJulio MerinoThis is done by using the
3080677dfd1SJulio Merino.Fn ATF_TP_ADD_TCS
3090677dfd1SJulio Merinomacro, which is passed the name of the object that will hold the test
310ddde9fa7SEnji Coopercases, i.e., the test program instance.
3110677dfd1SJulio MerinoThis name can be whatever you want as long as it is a valid variable
3120677dfd1SJulio Merinoidentifier.
3130677dfd1SJulio Merino.Pp
3140677dfd1SJulio MerinoAfter the macro, you are supposed to provide the body of a function, which
3150677dfd1SJulio Merinoshould only use the
3160677dfd1SJulio Merino.Fn ATF_TP_ADD_TC
3170677dfd1SJulio Merinomacro to register the test cases the test program will execute and return
3180677dfd1SJulio Merinoa success error code.
3190677dfd1SJulio MerinoThe first parameter of this macro matches the name you provided in the
3200677dfd1SJulio Merinoformer call.
3210677dfd1SJulio MerinoThe success status can be returned using the
3220677dfd1SJulio Merino.Fn atf_no_error
3230677dfd1SJulio Merinofunction.
3240677dfd1SJulio Merino.Ss Header definitions
3250677dfd1SJulio MerinoThe test case's header can define the meta-data by using the
3260677dfd1SJulio Merino.Fn atf_tc_set_md_var
3270677dfd1SJulio Merinomethod, which takes three parameters: the first one points to the test
3280677dfd1SJulio Merinocase data, the second one specifies the meta-data variable to be set
3290677dfd1SJulio Merinoand the third one specifies its value.
3300677dfd1SJulio MerinoBoth of them are strings.
3310677dfd1SJulio Merino.Ss Configuration variables
3320677dfd1SJulio MerinoThe test case has read-only access to the current configuration variables
3330677dfd1SJulio Merinoby means of the
3340677dfd1SJulio Merino.Ft bool
3350677dfd1SJulio Merino.Fn atf_tc_has_config_var ,
3360677dfd1SJulio Merino.Ft const char *
3370677dfd1SJulio Merino.Fn atf_tc_get_config_var ,
3380677dfd1SJulio Merino.Ft const char *
3390677dfd1SJulio Merino.Fn atf_tc_get_config_var_wd ,
3400677dfd1SJulio Merino.Ft bool
3410677dfd1SJulio Merino.Fn atf_tc_get_config_var_as_bool ,
3420677dfd1SJulio Merino.Ft bool
3430677dfd1SJulio Merino.Fn atf_tc_get_config_var_as_bool_wd ,
3440677dfd1SJulio Merino.Ft long
3450677dfd1SJulio Merino.Fn atf_tc_get_config_var_as_long ,
3460677dfd1SJulio Merinoand the
3470677dfd1SJulio Merino.Ft long
3480677dfd1SJulio Merino.Fn atf_tc_get_config_var_as_long_wd
3490677dfd1SJulio Merinofunctions, which can be called in any of the three parts of a test case.
3500677dfd1SJulio Merino.Pp
3510677dfd1SJulio MerinoThe
3520677dfd1SJulio Merino.Sq _wd
3530677dfd1SJulio Merinovariants take a default value for the variable which is returned if the
3540677dfd1SJulio Merinovariable is not defined.
3550677dfd1SJulio MerinoThe other functions without the
3560677dfd1SJulio Merino.Sq _wd
3570677dfd1SJulio Merinosuffix
3580677dfd1SJulio Merino.Em require
3590677dfd1SJulio Merinothe variable to be defined.
3600677dfd1SJulio Merino.Ss Access to the source directory
3610677dfd1SJulio MerinoIt is possible to get the path to the test case's source directory from any
3620677dfd1SJulio Merinoof its three components by querying the
3630677dfd1SJulio Merino.Sq srcdir
3640677dfd1SJulio Merinoconfiguration variable.
3650677dfd1SJulio Merino.Ss Requiring programs
3660677dfd1SJulio MerinoAside from the
3670677dfd1SJulio Merino.Va require.progs
3680677dfd1SJulio Merinometa-data variable available in the header only, one can also check for
3690677dfd1SJulio Merinoadditional programs in the test case's body by using the
3700677dfd1SJulio Merino.Fn atf_tc_require_prog
3710677dfd1SJulio Merinofunction, which takes the base name or full path of a single binary.
3720677dfd1SJulio MerinoRelative paths are forbidden.
3730677dfd1SJulio MerinoIf it is not found, the test case will be automatically skipped.
3740677dfd1SJulio Merino.Ss Test case finalization
3750677dfd1SJulio MerinoThe test case finalizes either when the body reaches its end, at which
3760677dfd1SJulio Merinopoint the test is assumed to have
3770677dfd1SJulio Merino.Em passed ,
3780677dfd1SJulio Merinounless any non-fatal errors were raised using
3790677dfd1SJulio Merino.Fn atf_tc_fail_nonfatal ,
3800677dfd1SJulio Merinoor at any explicit call to
3810677dfd1SJulio Merino.Fn atf_tc_pass ,
3820677dfd1SJulio Merino.Fn atf_tc_fail
3830677dfd1SJulio Merinoor
3840677dfd1SJulio Merino.Fn atf_tc_skip .
3850677dfd1SJulio MerinoThese three functions terminate the execution of the test case immediately.
3860677dfd1SJulio MerinoThe cleanup routine will be processed afterwards in a completely automated
3870677dfd1SJulio Merinoway, regardless of the test case's termination reason.
3880677dfd1SJulio Merino.Pp
3890677dfd1SJulio Merino.Fn atf_tc_pass
3900677dfd1SJulio Merinodoes not take any parameters.
3910677dfd1SJulio Merino.Fn atf_tc_fail ,
3920677dfd1SJulio Merino.Fn atf_tc_fail_nonfatal
3930677dfd1SJulio Merinoand
3940677dfd1SJulio Merino.Fn atf_tc_skip
3950677dfd1SJulio Merinotake a format string and a variable list of parameters, which describe, in
3960677dfd1SJulio Merinoa user-friendly manner, why the test case failed or was skipped,
3970677dfd1SJulio Merinorespectively.
3980677dfd1SJulio MerinoIt is very important to provide a clear error message in both cases so that
3990677dfd1SJulio Merinothe user can quickly know why the test did not pass.
4000677dfd1SJulio Merino.Ss Expectations
4010677dfd1SJulio MerinoEverything explained in the previous section changes when the test case
4020677dfd1SJulio Merinoexpectations are redefined by the programmer.
4030677dfd1SJulio Merino.Pp
4040677dfd1SJulio MerinoEach test case has an internal state called
4050677dfd1SJulio Merino.Sq expect
4060677dfd1SJulio Merinothat describes what the test case expectations are at any point in time.
4070677dfd1SJulio MerinoThe value of this property can change during execution by any of:
4080677dfd1SJulio Merino.Bl -tag -width indent
4090677dfd1SJulio Merino.It Fn atf_tc_expect_death "reason" "..."
4100677dfd1SJulio MerinoExpects the test case to exit prematurely regardless of the nature of the
4110677dfd1SJulio Merinoexit.
4120677dfd1SJulio Merino.It Fn atf_tc_expect_exit "exitcode" "reason" "..."
4130677dfd1SJulio MerinoExpects the test case to exit cleanly.
4140677dfd1SJulio MerinoIf
4150677dfd1SJulio Merino.Va exitcode
4160677dfd1SJulio Merinois not
4170677dfd1SJulio Merino.Sq -1 ,
4180677dfd1SJulio Merinothe runtime engine will validate that the exit code of the test case
4190677dfd1SJulio Merinomatches the one provided in this call.
4200677dfd1SJulio MerinoOtherwise, the exact value will be ignored.
4210677dfd1SJulio Merino.It Fn atf_tc_expect_fail "reason" "..."
4220677dfd1SJulio MerinoAny failure (be it fatal or non-fatal) raised in this mode is recorded.
4230677dfd1SJulio MerinoHowever, such failures do not report the test case as failed; instead, the
4240677dfd1SJulio Merinotest case finalizes cleanly and is reported as
4250677dfd1SJulio Merino.Sq expected failure ;
4260677dfd1SJulio Merinothis report includes the provided
4270677dfd1SJulio Merino.Fa reason
4280677dfd1SJulio Merinoas part of it.
4290677dfd1SJulio MerinoIf no error is raised while running in this mode, then the test case is
4300677dfd1SJulio Merinoreported as
4310677dfd1SJulio Merino.Sq failed .
4320677dfd1SJulio Merino.Pp
4330677dfd1SJulio MerinoThis mode is useful to reproduce actual known bugs in tests.
4340677dfd1SJulio MerinoWhenever the developer fixes the bug later on, the test case will start
4350677dfd1SJulio Merinoreporting a failure, signaling the developer that the test case must be
4360677dfd1SJulio Merinoadjusted to the new conditions.
4370677dfd1SJulio MerinoIn this situation, it is useful, for example, to set
4380677dfd1SJulio Merino.Fa reason
4390677dfd1SJulio Merinoas the bug number for tracking purposes.
4400677dfd1SJulio Merino.It Fn atf_tc_expect_pass
4410677dfd1SJulio MerinoThis is the normal mode of execution.
4420677dfd1SJulio MerinoIn this mode, any failure is reported as such to the user and the test case
4430677dfd1SJulio Merinois marked as
4440677dfd1SJulio Merino.Sq failed .
4450677dfd1SJulio Merino.It Fn atf_tc_expect_signal "signo" "reason" "..."
4460677dfd1SJulio MerinoExpects the test case to terminate due to the reception of a signal.
4470677dfd1SJulio MerinoIf
4480677dfd1SJulio Merino.Va signo
4490677dfd1SJulio Merinois not
4500677dfd1SJulio Merino.Sq -1 ,
4510677dfd1SJulio Merinothe runtime engine will validate that the signal that terminated the test
4520677dfd1SJulio Merinocase matches the one provided in this call.
4530677dfd1SJulio MerinoOtherwise, the exact value will be ignored.
4540677dfd1SJulio Merino.It Fn atf_tc_expect_timeout "reason" "..."
4550677dfd1SJulio MerinoExpects the test case to execute for longer than its timeout.
4560677dfd1SJulio Merino.El
4570677dfd1SJulio Merino.Ss Helper macros for common checks
4580677dfd1SJulio MerinoThe library provides several macros that are very handy in multiple
4590677dfd1SJulio Merinosituations.
4600677dfd1SJulio MerinoThese basically check some condition after executing a given statement or
4610677dfd1SJulio Merinoprocessing a given expression and, if the condition is not met, they
4620677dfd1SJulio Merinoreport the test case as failed.
4630677dfd1SJulio Merino.Pp
4640677dfd1SJulio MerinoThe
4650677dfd1SJulio Merino.Sq REQUIRE
4660677dfd1SJulio Merinovariant of the macros immediately abort the test case as soon as an error
4670677dfd1SJulio Merinocondition is detected by calling the
4680677dfd1SJulio Merino.Fn atf_tc_fail
4690677dfd1SJulio Merinofunction.
4700677dfd1SJulio MerinoUse this variant whenever it makes no sense to continue the execution of a
4710677dfd1SJulio Merinotest case when the checked condition is not met.
4720677dfd1SJulio MerinoThe
4730677dfd1SJulio Merino.Sq CHECK
4740677dfd1SJulio Merinovariant, on the other hand, reports a failure as soon as it is encountered
4750677dfd1SJulio Merinousing the
4760677dfd1SJulio Merino.Fn atf_tc_fail_nonfatal
4770677dfd1SJulio Merinofunction, but the execution of the test case continues as if nothing had
4780677dfd1SJulio Merinohappened.
4790677dfd1SJulio MerinoUse this variant whenever the checked condition is important as a result of
4800677dfd1SJulio Merinothe test case, but there are other conditions that can be subsequently
4810677dfd1SJulio Merinochecked on the same run without aborting.
4820677dfd1SJulio Merino.Pp
4830677dfd1SJulio MerinoAdditionally, the
4840677dfd1SJulio Merino.Sq MSG
4850677dfd1SJulio Merinovariants take an extra set of parameters to explicitly specify the failure
4860677dfd1SJulio Merinomessage.
4870677dfd1SJulio MerinoThis failure message is formatted according to the
4880677dfd1SJulio Merino.Xr printf 3
4890677dfd1SJulio Merinoformatters.
4900677dfd1SJulio Merino.Pp
4910677dfd1SJulio Merino.Fn ATF_CHECK ,
4920677dfd1SJulio Merino.Fn ATF_CHECK_MSG ,
4930677dfd1SJulio Merino.Fn ATF_REQUIRE
4940677dfd1SJulio Merinoand
4950677dfd1SJulio Merino.Fn ATF_REQUIRE_MSG
4960677dfd1SJulio Merinotake an expression and fail if the expression evaluates to false.
4970677dfd1SJulio Merino.Pp
4980677dfd1SJulio Merino.Fn ATF_CHECK_EQ ,
4990677dfd1SJulio Merino.Fn ATF_CHECK_EQ_MSG ,
5000677dfd1SJulio Merino.Fn ATF_REQUIRE_EQ
5010677dfd1SJulio Merinoand
5020677dfd1SJulio Merino.Fn ATF_REQUIRE_EQ_MSG
5030677dfd1SJulio Merinotake two expressions and fail if the two evaluated values are not equal.
5040677dfd1SJulio MerinoThe common style is to put the expected value in the first parameter and the
505*71a1ae7cSAlan Somersobserved value in the second parameter.
5060677dfd1SJulio Merino.Pp
5070677dfd1SJulio Merino.Fn ATF_CHECK_MATCH ,
5080677dfd1SJulio Merino.Fn ATF_CHECK_MATCH_MSG ,
5090677dfd1SJulio Merino.Fn ATF_REQUIRE_MATCH
5100677dfd1SJulio Merinoand
5110677dfd1SJulio Merino.Fn ATF_REQUIRE_MATCH_MSG
5120677dfd1SJulio Merinotake a regular expression and a string and fail if the regular expression does
5130677dfd1SJulio Merinonot match the given string.
5140677dfd1SJulio MerinoNote that the regular expression is not anchored, so it will match anywhere in
5150677dfd1SJulio Merinothe string.
5160677dfd1SJulio Merino.Pp
5170677dfd1SJulio Merino.Fn ATF_CHECK_STREQ ,
5180677dfd1SJulio Merino.Fn ATF_CHECK_STREQ_MSG ,
5190677dfd1SJulio Merino.Fn ATF_REQUIRE_STREQ
5200677dfd1SJulio Merinoand
5210677dfd1SJulio Merino.Fn ATF_REQUIRE_STREQ_MSG
5220677dfd1SJulio Merinotake two strings and fail if the two are not equal character by character.
5230677dfd1SJulio MerinoThe common style is to put the expected string in the first parameter and the
524*71a1ae7cSAlan Somersobserved string in the second parameter.
525*71a1ae7cSAlan Somers.Pp
526*71a1ae7cSAlan Somers.Fn ATF_CHECK_INTEQ ,
527*71a1ae7cSAlan Somers.Fn ATF_CHECK_INTEQ_MSG ,
528*71a1ae7cSAlan Somers.Fn ATF_REQUIRE_INTEQ
529*71a1ae7cSAlan Somersand
530*71a1ae7cSAlan Somers.Fn ATF_REQUIRE_INTQ_MSG
531*71a1ae7cSAlan Somerstake two integers and fail if the two are not equal.
532*71a1ae7cSAlan SomersThe common style is to put the expected integer in the first parameter and the
533*71a1ae7cSAlan Somersobserved integer in the second parameter.
5340677dfd1SJulio Merino.Pp
5350677dfd1SJulio Merino.Fn ATF_CHECK_ERRNO
5360677dfd1SJulio Merinoand
5370677dfd1SJulio Merino.Fn ATF_REQUIRE_ERRNO
5380677dfd1SJulio Merinotake, first, the error code that the check is expecting to find in the
5390677dfd1SJulio Merino.Va errno
5400677dfd1SJulio Merinovariable and, second, a boolean expression that, if evaluates to true,
5410677dfd1SJulio Merinomeans that a call failed and
5420677dfd1SJulio Merino.Va errno
5430677dfd1SJulio Merinohas to be checked against the first value.
5440677dfd1SJulio Merino.Ss Utility functions
5450677dfd1SJulio MerinoThe following functions are provided as part of the
5460677dfd1SJulio Merino.Nm
5470677dfd1SJulio MerinoAPI to simplify the creation of a variety of tests.
5480677dfd1SJulio MerinoIn particular, these are useful to write tests for command-line interfaces.
5490677dfd1SJulio Merino.Pp
5500677dfd1SJulio Merino.Ft void
5510677dfd1SJulio Merino.Fo atf_utils_cat_file
5520677dfd1SJulio Merino.Fa "const char *file"
5530677dfd1SJulio Merino.Fa "const char *prefix"
5540677dfd1SJulio Merino.Fc
5550677dfd1SJulio Merino.Bd -ragged -offset indent
5560677dfd1SJulio MerinoPrints the contents of
5570677dfd1SJulio Merino.Fa file
5580677dfd1SJulio Merinoto the standard output, prefixing every line with the string in
5590677dfd1SJulio Merino.Fa prefix .
5600677dfd1SJulio Merino.Ed
5610677dfd1SJulio Merino.Pp
5620677dfd1SJulio Merino.Ft bool
5630677dfd1SJulio Merino.Fo atf_utils_compare_file
5640677dfd1SJulio Merino.Fa "const char *file"
5650677dfd1SJulio Merino.Fa "const char *contents"
5660677dfd1SJulio Merino.Fc
5670677dfd1SJulio Merino.Bd -ragged -offset indent
5680677dfd1SJulio MerinoReturns true if the given
5690677dfd1SJulio Merino.Fa file
5700677dfd1SJulio Merinomatches exactly the expected inlined
5710677dfd1SJulio Merino.Fa contents .
5720677dfd1SJulio Merino.Ed
5730677dfd1SJulio Merino.Pp
5740677dfd1SJulio Merino.Ft void
5750677dfd1SJulio Merino.Fo atf_utils_copy_file
5760677dfd1SJulio Merino.Fa "const char *source"
5770677dfd1SJulio Merino.Fa "const char *destination"
5780677dfd1SJulio Merino.Fc
5790677dfd1SJulio Merino.Bd -ragged -offset indent
5800677dfd1SJulio MerinoCopies the file
5810677dfd1SJulio Merino.Fa source
5820677dfd1SJulio Merinoto
5830677dfd1SJulio Merino.Fa destination .
5840677dfd1SJulio MerinoThe permissions of the file are preserved during the code.
5850677dfd1SJulio Merino.Ed
5860677dfd1SJulio Merino.Pp
5870677dfd1SJulio Merino.Ft void
5880677dfd1SJulio Merino.Fo atf_utils_create_file
5890677dfd1SJulio Merino.Fa "const char *file"
5900677dfd1SJulio Merino.Fa "const char *contents"
5910677dfd1SJulio Merino.Fa "..."
5920677dfd1SJulio Merino.Fc
5930677dfd1SJulio Merino.Bd -ragged -offset indent
5940677dfd1SJulio MerinoCreates
5950677dfd1SJulio Merino.Fa file
5960677dfd1SJulio Merinowith the text given in
5970677dfd1SJulio Merino.Fa contents ,
5980677dfd1SJulio Merinowhich is a formatting string that uses the rest of the variable arguments.
5990677dfd1SJulio Merino.Ed
6000677dfd1SJulio Merino.Pp
6010677dfd1SJulio Merino.Ft void
6020677dfd1SJulio Merino.Fo atf_utils_file_exists
6030677dfd1SJulio Merino.Fa "const char *file"
6040677dfd1SJulio Merino.Fc
6050677dfd1SJulio Merino.Bd -ragged -offset indent
6060677dfd1SJulio MerinoChecks if
6070677dfd1SJulio Merino.Fa file
6080677dfd1SJulio Merinoexists.
6090677dfd1SJulio Merino.Ed
6100677dfd1SJulio Merino.Pp
6110677dfd1SJulio Merino.Ft pid_t
6120677dfd1SJulio Merino.Fo atf_utils_fork
6130677dfd1SJulio Merino.Fa "void"
6140677dfd1SJulio Merino.Fc
6150677dfd1SJulio Merino.Bd -ragged -offset indent
6160677dfd1SJulio MerinoForks a process and redirects the standard output and standard error of the
6170677dfd1SJulio Merinochild to files for later validation with
6180677dfd1SJulio Merino.Fn atf_utils_wait .
6190677dfd1SJulio MerinoFails the test case if the fork fails, so this does not return an error.
6200677dfd1SJulio Merino.Ed
6210677dfd1SJulio Merino.Pp
6220677dfd1SJulio Merino.Ft void
6230677dfd1SJulio Merino.Fo atf_utils_free_charpp
6240677dfd1SJulio Merino.Fa "char **argv"
6250677dfd1SJulio Merino.Fc
6260677dfd1SJulio Merino.Bd -ragged -offset indent
6270677dfd1SJulio MerinoFrees a dynamically-allocated array of dynamically-allocated strings.
6280677dfd1SJulio Merino.Ed
6290677dfd1SJulio Merino.Pp
6300677dfd1SJulio Merino.Ft bool
6310677dfd1SJulio Merino.Fo atf_utils_grep_file
6320677dfd1SJulio Merino.Fa "const char *regexp"
6330677dfd1SJulio Merino.Fa "const char *file"
6340677dfd1SJulio Merino.Fa "..."
6350677dfd1SJulio Merino.Fc
6360677dfd1SJulio Merino.Bd -ragged -offset indent
6370677dfd1SJulio MerinoSearches for the
6380677dfd1SJulio Merino.Fa regexp ,
6390677dfd1SJulio Merinowhich is a formatting string representing the regular expression,
6400677dfd1SJulio Merinoin the
6410677dfd1SJulio Merino.Fa file .
6420677dfd1SJulio MerinoThe variable arguments are used to construct the regular expression.
6430677dfd1SJulio Merino.Ed
6440677dfd1SJulio Merino.Pp
6450677dfd1SJulio Merino.Ft bool
6460677dfd1SJulio Merino.Fo atf_utils_grep_string
6470677dfd1SJulio Merino.Fa "const char *regexp"
6480677dfd1SJulio Merino.Fa "const char *str"
6490677dfd1SJulio Merino.Fa "..."
6500677dfd1SJulio Merino.Fc
6510677dfd1SJulio Merino.Bd -ragged -offset indent
6520677dfd1SJulio MerinoSearches for the
6530677dfd1SJulio Merino.Fa regexp ,
6540677dfd1SJulio Merinowhich is a formatting string representing the regular expression,
6550677dfd1SJulio Merinoin the literal string
6560677dfd1SJulio Merino.Fa str .
6570677dfd1SJulio MerinoThe variable arguments are used to construct the regular expression.
6580677dfd1SJulio Merino.Ed
6590677dfd1SJulio Merino.Pp
6600677dfd1SJulio Merino.Ft char *
6610677dfd1SJulio Merino.Fo atf_utils_readline
6620677dfd1SJulio Merino.Fa "int fd"
6630677dfd1SJulio Merino.Fc
6640677dfd1SJulio Merino.Bd -ragged -offset indent
6650677dfd1SJulio MerinoReads a line from the file descriptor
6660677dfd1SJulio Merino.Fa fd .
6670677dfd1SJulio MerinoThe line, if any, is returned as a dynamically-allocated buffer that must be
6680677dfd1SJulio Merinoreleased with
6690677dfd1SJulio Merino.Xr free 3 .
6700677dfd1SJulio MerinoIf there was nothing to read, returns
6710677dfd1SJulio Merino.Sq NULL .
6720677dfd1SJulio Merino.Ed
6730677dfd1SJulio Merino.Pp
6740677dfd1SJulio Merino.Ft void
6750677dfd1SJulio Merino.Fo atf_utils_redirect
6760677dfd1SJulio Merino.Fa "const int fd"
6770677dfd1SJulio Merino.Fa "const char *file"
6780677dfd1SJulio Merino.Fc
6790677dfd1SJulio Merino.Bd -ragged -offset indent
6800677dfd1SJulio MerinoRedirects the given file descriptor
6810677dfd1SJulio Merino.Fa fd
6820677dfd1SJulio Merinoto
6830677dfd1SJulio Merino.Fa file .
6840677dfd1SJulio MerinoThis function exits the process in case of an error and does not properly mark
6850677dfd1SJulio Merinothe test case as failed.
6860677dfd1SJulio MerinoAs a result, it should only be used in subprocesses of the test case; specially
6870677dfd1SJulio Merinothose spawned by
6880677dfd1SJulio Merino.Fn atf_utils_fork .
6890677dfd1SJulio Merino.Ed
6900677dfd1SJulio Merino.Pp
6910677dfd1SJulio Merino.Ft void
6920677dfd1SJulio Merino.Fo atf_utils_wait
6930677dfd1SJulio Merino.Fa "const pid_t pid"
6940677dfd1SJulio Merino.Fa "const int expected_exit_status"
6950677dfd1SJulio Merino.Fa "const char *expected_stdout"
6960677dfd1SJulio Merino.Fa "const char *expected_stderr"
6970677dfd1SJulio Merino.Fc
6980677dfd1SJulio Merino.Bd -ragged -offset indent
6990677dfd1SJulio MerinoWaits and validates the result of a subprocess spawned with
7001d303879SEnji Cooper.Fn atf_utils_fork .
7010677dfd1SJulio MerinoThe validation involves checking that the subprocess exited cleanly and returned
7020677dfd1SJulio Merinothe code specified in
7030677dfd1SJulio Merino.Fa expected_exit_status
7040677dfd1SJulio Merinoand that its standard output and standard error match the strings given in
7050677dfd1SJulio Merino.Fa expected_stdout
7060677dfd1SJulio Merinoand
7070677dfd1SJulio Merino.Fa expected_stderr .
7080677dfd1SJulio Merino.Pp
7090677dfd1SJulio MerinoIf any of the
7100677dfd1SJulio Merino.Fa expected_stdout
7110677dfd1SJulio Merinoor
7120677dfd1SJulio Merino.Fa expected_stderr
7130677dfd1SJulio Merinostrings are prefixed with
7140677dfd1SJulio Merino.Sq save: ,
7150677dfd1SJulio Merinothen they specify the name of the file into which to store the stdout or stderr
7160677dfd1SJulio Merinoof the subprocess, and no comparison is performed.
7170677dfd1SJulio Merino.Ed
7180677dfd1SJulio Merino.Sh ENVIRONMENT
7190677dfd1SJulio MerinoThe following variables are recognized by
7200677dfd1SJulio Merino.Nm
7210677dfd1SJulio Merinobut should not be overridden other than for testing purposes:
7220677dfd1SJulio Merino.Pp
7230677dfd1SJulio Merino.Bl -tag -width ATFXBUILDXCXXFLAGSXX -compact
7240677dfd1SJulio Merino.It Va ATF_BUILD_CC
7250677dfd1SJulio MerinoPath to the C compiler.
7260677dfd1SJulio Merino.It Va ATF_BUILD_CFLAGS
7270677dfd1SJulio MerinoC compiler flags.
7280677dfd1SJulio Merino.It Va ATF_BUILD_CPP
7290677dfd1SJulio MerinoPath to the C/C++ preprocessor.
7300677dfd1SJulio Merino.It Va ATF_BUILD_CPPFLAGS
7310677dfd1SJulio MerinoC/C++ preprocessor flags.
7320677dfd1SJulio Merino.It Va ATF_BUILD_CXX
7330677dfd1SJulio MerinoPath to the C++ compiler.
7340677dfd1SJulio Merino.It Va ATF_BUILD_CXXFLAGS
7350677dfd1SJulio MerinoC++ compiler flags.
7360677dfd1SJulio Merino.El
7370677dfd1SJulio Merino.Sh EXAMPLES
7380677dfd1SJulio MerinoThe following shows a complete test program with a single test case that
7390677dfd1SJulio Merinovalidates the addition operator:
7400677dfd1SJulio Merino.Bd -literal -offset indent
7410677dfd1SJulio Merino#include <atf-c.h>
7420677dfd1SJulio Merino
7430677dfd1SJulio MerinoATF_TC(addition);
7440677dfd1SJulio MerinoATF_TC_HEAD(addition, tc)
7450677dfd1SJulio Merino{
7460677dfd1SJulio Merino    atf_tc_set_md_var(tc, "descr",
7470677dfd1SJulio Merino                      "Sample tests for the addition operator");
7480677dfd1SJulio Merino}
7490677dfd1SJulio MerinoATF_TC_BODY(addition, tc)
7500677dfd1SJulio Merino{
7510677dfd1SJulio Merino    ATF_CHECK_EQ(0, 0 + 0);
7520677dfd1SJulio Merino    ATF_CHECK_EQ(1, 0 + 1);
7530677dfd1SJulio Merino    ATF_CHECK_EQ(1, 1 + 0);
7540677dfd1SJulio Merino
7550677dfd1SJulio Merino    ATF_CHECK_EQ(2, 1 + 1);
7560677dfd1SJulio Merino
7570677dfd1SJulio Merino    ATF_CHECK_EQ(300, 100 + 200);
7580677dfd1SJulio Merino}
7590677dfd1SJulio Merino
7600677dfd1SJulio MerinoATF_TC(string_formatting);
7610677dfd1SJulio MerinoATF_TC_HEAD(string_formatting, tc)
7620677dfd1SJulio Merino{
7630677dfd1SJulio Merino    atf_tc_set_md_var(tc, "descr",
7640677dfd1SJulio Merino                      "Sample tests for the snprintf");
7650677dfd1SJulio Merino}
7660677dfd1SJulio MerinoATF_TC_BODY(string_formatting, tc)
7670677dfd1SJulio Merino{
7680677dfd1SJulio Merino    char buf[1024];
7690677dfd1SJulio Merino    snprintf(buf, sizeof(buf), "a %s", "string");
7700677dfd1SJulio Merino    ATF_CHECK_STREQ_MSG("a string", buf, "%s is not working");
7710677dfd1SJulio Merino}
7720677dfd1SJulio Merino
7730677dfd1SJulio MerinoATF_TC(open_failure);
7740677dfd1SJulio MerinoATF_TC_HEAD(open_failure, tc)
7750677dfd1SJulio Merino{
7760677dfd1SJulio Merino    atf_tc_set_md_var(tc, "descr",
7770677dfd1SJulio Merino                      "Sample tests for the open function");
7780677dfd1SJulio Merino}
7790677dfd1SJulio MerinoATF_TC_BODY(open_failure, tc)
7800677dfd1SJulio Merino{
7810677dfd1SJulio Merino    ATF_CHECK_ERRNO(ENOENT, open("non-existent", O_RDONLY) == -1);
7820677dfd1SJulio Merino}
7830677dfd1SJulio Merino
7840677dfd1SJulio MerinoATF_TC(known_bug);
7850677dfd1SJulio MerinoATF_TC_HEAD(known_bug, tc)
7860677dfd1SJulio Merino{
7870677dfd1SJulio Merino    atf_tc_set_md_var(tc, "descr",
7880677dfd1SJulio Merino                      "Reproduces a known bug");
7890677dfd1SJulio Merino}
7900677dfd1SJulio MerinoATF_TC_BODY(known_bug, tc)
7910677dfd1SJulio Merino{
7920677dfd1SJulio Merino    atf_tc_expect_fail("See bug number foo/bar");
7930677dfd1SJulio Merino    ATF_CHECK_EQ(3, 1 + 1);
7940677dfd1SJulio Merino    atf_tc_expect_pass();
7950677dfd1SJulio Merino    ATF_CHECK_EQ(3, 1 + 2);
7960677dfd1SJulio Merino}
7970677dfd1SJulio Merino
7980677dfd1SJulio MerinoATF_TP_ADD_TCS(tp)
7990677dfd1SJulio Merino{
8000677dfd1SJulio Merino    ATF_TP_ADD_TC(tp, addition);
8010677dfd1SJulio Merino    ATF_TP_ADD_TC(tp, string_formatting);
8020677dfd1SJulio Merino    ATF_TP_ADD_TC(tp, open_failure);
8030677dfd1SJulio Merino    ATF_TP_ADD_TC(tp, known_bug);
8040677dfd1SJulio Merino
8050677dfd1SJulio Merino    return atf_no_error();
8060677dfd1SJulio Merino}
8070677dfd1SJulio Merino.Ed
8080677dfd1SJulio Merino.Sh SEE ALSO
8090677dfd1SJulio Merino.Xr atf-test-program 1 ,
8100677dfd1SJulio Merino.Xr atf-test-case 4
811