Annotation of wikisrc/tutorials/atf.mdwn, revision 1.3

1.1       jmmv        1: # Creating atf-based tests for NetBSD src
                      2: 
                      3: This quick tutorial is an attempt to workaround the lack of proper documentation
                      4: in atf.  The tutorial provides a guideline on how to start creating new test
                      5: programs and/or test cases, how these tests are tied to the NetBSD source tree
                      6: and a short reference of the most commonly used functions.
                      7: 
                      8: You should start by reading the
                      9: [tests(7)](http://netbsd.gw.com/cgi-bin/man-cgi?tests++NetBSD-current) manual
                     10: page, which is probably the only sane document in the whole documentation.  Any
                     11: other attempts at reading the atf-* manual pages are probably doomed unless you
                     12: are already familiar with atf itself and its internals.  Still, you may be able
                     13: to get some useful information out of
                     14: [atf-run(1)](http://netbsd.gw.com/cgi-bin/man-cgi?atf-run++NetBSD-current),
                     15: [atf-report(1)](http://netbsd.gw.com/cgi-bin/man-cgi?atf-report++NetBSD-current),
                     16: [atf-test-program(1)](http://netbsd.gw.com/cgi-bin/man-cgi?atf-test-program++NetBSD-current),
                     17: [atf-c-api(3)](http://netbsd.gw.com/cgi-bin/man-cgi?atf-c-api++NetBSD-current)
                     18: and
                     19: [atf-sh-api(3)](http://netbsd.gw.com/cgi-bin/man-cgi?atf-sh-api++NetBSD-current).
                     20: 
                     21: **IMPORTANT: Do not take anything for granted, SPECIALLY if you have previously
                     22: worked with and/or have seen src/regress/.  Your assumptions are most likely
1.2       jmmv       23: incorrect.**
1.1       jmmv       24: 
                     25: ## Test programs vs. test cases
                     26: 
                     27: So, what is what and how do you organize your tests?
                     28: 
                     29: A **test case** is a piece of code that exercises a particular functionality of
                     30: another piece of code.  Commonly, test cases validate the outcome of a
                     31: particular source function or class method, the validity of the execution of a
                     32: command with a particular combination of flags/arguments, etc.  Test cases are
                     33: supposed to be very concise, in the sense that they should just be testing *one
                     34: behavior*.
                     35: 
                     36: A **test program** is a binary that collects and exposes a group of test cases.
                     37: Typically, these test programs expose conceptually-related tests or all the
                     38: tests for a particular source file.
                     39: 
                     40: In general, having many test programs with **just one test case** in them is
                     41: **wrong** and smells from the previous layout of src/regress/.  Think about some
                     42: other organization.  And don't blame atf for this separation: this is extremely
                     43: common in (almost?) all other test frameworks and, when used wisely, becomes an
                     44: invaluable classification.
                     45: 
                     46: For example, suppose you have the following fictitious source files for the ls
                     47: tool:
                     48: 
                     49: * bin/ls/fs.c: Provides the list_files() and stat_files() functions.
                     50: 
                     51: * bin/ls/ui.c: Provides the format_columns() function.
                     52: 
                     53: * bin/ls/main.c: The main method for ls.
                     54: 
                     55: Then, you could define the following test programs and test cases:
                     56: 
                     57: * bin/ls/fs_test.c: Provides test cases for list_files and stat_files.  These
                     58:   would be named list_files__empty_directory, list_files__one_file,
                     59:   list_files__multiple_files, stat_files__directory, stat_files__symlink, etc.
                     60: 
                     61: * bin/ls/ui_test.c: Provides test cases for the format_columns function.  These
                     62:   would be named format_columns__no_files, format_columns__multiple_files, etc.
                     63: 
                     64: * bin/ls/integration_test.sh: Provides "black box" test cases for the binary
                     65:   itself.  These would be named lflag, lflag_and_Fflag, no_flags, no_files, etc.
                     66: 
1.2       jmmv       67: Try to keep your test case names as descriptive as possible so that they do not
                     68: require comments to explain what they intend to test.
                     69: 
1.3     ! jmmv       70: ## Test case parts
        !            71: 
        !            72: A test case is composed by three parts: the *head*, the *body* and the
        !            73: *cleanup*.  Only the body is required; the other two routines are optional.
        !            74: 
        !            75: ### The head
        !            76: 
        !            77: The *head* is used **for the sole purpose** to define meta-data properties for
        !            78: the test case.  (Eventually, this would not be specified programmatically, but
        !            79: is how we deal with the information right now.)
        !            80: 
        !            81: The following properties are commonly useful:
        !            82: 
        !            83: * descr: A textual description of the purpose of the test case.
        !            84: 
        !            85: * require.user: Set to 'root' to mark the test case as root-specific.  It is
        !            86:   nice not to abuse this; see puffs and rump.
        !            87: 
        !            88: * use.fs: Set to 'true' if the test case creates temporary files in the "current
        !            89:   directory".  Otherwise the atf runtime will isolate the test case in such a
        !            90:   way to forbid this, which will misteriously make your test to fail.
        !            91: 
        !            92: ### The body
        !            93: 
        !            94: The *body* is the actual meat of the test case.  This is just a regular function
        !            95: that executes any code you want and calls special atf functions to report
        !            96: failures; see below.
        !            97: 
        !            98: In particular, be aware that the atf run-time **isolates** the execution of
        !            99: every test case to prevent side-effects (such as temporary file leftovers,
        !           100: in-memory data corruption, etc.).  In particular:
        !           101: 
        !           102: * A test case is **always executed as a subprocess** that is separate from the
        !           103:   head and the cleanup.
        !           104: 
        !           105: * The current working directory of a test case is changed to a temporary
        !           106:   location that gets cleaned up later on automatically.  (Set the use.fs
        !           107:   property to true in the head if you need to write to this temporary
        !           108:   directory.)
        !           109: 
        !           110: * The environment of the test case is "sanitized" to get rid of variables that
        !           111:   can cause side-effects; e.g. LC_ALL, TZ, etc.
        !           112: 
1.2       jmmv      113: ## Installation of test programs: the why and the where
                    114: 
                    115: Test programs get installed into the /usr/tests/ hierarchy.  The main reason for
                    116: doing that is to allow *any* user to test his system and to be able to convince
                    117: himself that everything is working correctly.
                    118: 
                    119: Imagine that you install NetBSD-current on a public-facing machine that has some
                    120: particular hardware only supported in the bleeding-edge source tree.  In this
                    121: scenario, you, as the administrator, could just go into /usr/tests/, run the
                    122: tests and know immediately if everything is working correctly in your
                    123: software+hardware combination or not.  No need to rely on promises from the
                    124: vendor, no need to deal with a source tree, no need to have a compiler
                    125: installed...
                    126: 
                    127: So, that's the theory.  Now, how does this map to our source tree?
                    128: 
                    129: At the moment, the source test programs are located somewhere under src/tests/.
                    130: Say, for example, that you have the src/tests/bin/ls/ui_test.c source file.
                    131: This Makefile in src/tests/bin/ls/ will take this source file and generate a
                    132: ui_test binary.  The Makefile will also generate an Atffile.  Both files (the
                    133: ui_test binary and the Atffile) will later be installed to /usr/tests/bin/ls/
1.1       jmmv      134: 
                    135: ## Adding a new test
                    136: 
                    137: To add a new *test case* to the source tree, look for any test program in
                    138: src/tests/ that can assimilate it.  If you find such a program, just add the
1.2       jmmv      139: test case to it: no other changes are required so your life is easy.  Otherwise,
                    140: you will have to create a new test program.
1.1       jmmv      141: 
                    142: To add a new *test program* to the source tree:
                    143: 
                    144: 1. Locate the appropriate subdirectory in which to put your test program.  It is
                    145: OK (and **expected**) to have multiple test programs into the same directory.
                    146: **Restrain yourself from creating one directory per test program.**
                    147: 
                    148: If the subdirectory exists:
                    149: 
                    150: 1. Choose a sane name for the test program; the name must not be so specific
                    151:    that it restricts the addition of future test cases into it.
                    152: 
                    153: 1. Create the test program source file using one of the templates below.
                    154:    E.g. src/tests/tutorial/sample_test.c.
                    155: 
                    156: 1. Add the new test program to the Makefile.
                    157: 
                    158: If the subdirectory does not exist:
                    159: 
                    160: 1. Do the same as above.
                    161: 
                    162: 1. Create the Makefile for the directory using the templates below.
                    163: 
                    164: 1. Edit the parent Makefile to recurse into the new subdirectory.
                    165: 
                    166: 1. Edit src/etc/mtree/NetBSD.base.dist to register the new subdirectory.  Your
                    167:    test will be installed under /usr/tests/.
                    168: 
                    169: 1. Edit src/distrib/sets/lists/tests/mi to register the new test program.  Do
                    170:    not forget to add .debug entries if your test program is a C/C++ binary.
                    171: 
                    172: ### Makefile template
                    173: 
1.3     ! jmmv      174:     # $NetBSD: atf.mdwn,v 1.2 2010/09/02 22:59:38 jmmv Exp $
1.1       jmmv      175: 
                    176:     .include <bsd.own.mk>
                    177: 
                    178:     # This must always be defined.
                    179:     TESTSDIR= ${TESTSBASE}/bin/ls
                    180: 
                    181:     # Define only the variables you actually need for the directory.
                    182:     TESTS_C+= c1_test c2_test  # Correspond to c1_test.c and c2_test.c.
                    183:     TESTS_SH+= sh1_test sh2_test  # Correspond to sh1_test.c and sh2_test.c
                    184: 
                    185:     # Define only if your tests need any data files.
                    186:     FILESDIR= ${TESTSDIR}
                    187:     FILES= testdata1.txt testdata2.bin  # Any necessary data files.
                    188: 
                    189:     .include <bsd.test.mk>
                    190: 
1.2       jmmv      191: ### Atffile template
                    192: 
                    193: What is an Atffile?  An Atffile is the atf-run counterpart of a "Makefile".
                    194: Given that atf tests *do not rely on a toolchain*, they cannot use make(1) to
                    195: script their execution as the old tests in src/regress/ did.
                    196: 
                    197: The Atffiles, in general, just provide a list of test programs in a particular
                    198: directory and the list of the subdirectories to descend into.
                    199: 
                    200: Atffiles are automatically generated by bsd.test.mk, so in general you will not
                    201: have to deal with them.  However, if you have to provide one explicitly, they
                    202: follow the following format:
                    203: 
                    204:     Content-Type: application/X-atf-atffile; version="1"
                    205: 
                    206:     prop: test-suite = NetBSD
                    207: 
                    208:     tp: first_test
                    209:     tp: second_test
                    210:     tp-glob: optional_*_test
                    211:     tp: subdir1
                    212:     tp: subdir2
                    213: 
1.1       jmmv      214: ## C test programs
                    215: 
                    216: ### Template
                    217: 
1.2       jmmv      218: The following code snippet provides a C test program with two test cases:
                    219: 
1.1       jmmv      220:     #include <atf-c.h>
                    221: 
                    222:     ATF_TC(tc, my_test_case);
                    223:     ATF_TC_HEAD(tc, my_test_case)
                    224:     {
                    225:         atf_tc_set_md_var(tc, "descr", "This test case ensures that...");
                    226:     }
                    227:     ATF_TC_BODY(tc, my_test_case)
                    228:     {
                    229:         ATF_CHECK(returns_a_boolean()); /* Non-fatal test. */
                    230:         ATF_REQUIRE(returns_a_boolean()); /* Non-fatal test. */
                    231: 
                    232:         ATF_CHECK_EQ(4, 2 + 2); /* Non-fatal test. */
                    233:         ATF_REQUIRE_EQ(4, 2 + 2); /* Fatal test. */
                    234: 
                    235:         if (!condition)
                    236:             atf_tc_fail("Condition not met!"); /* Explicit failure. */
                    237:     }
                    238: 
1.2       jmmv      239:     ATF_TC_WITHOUT_HEAD(tc, another_test_case);
                    240:     ATF_TC_BODY(tc, another_test_case)
                    241:     {
                    242:         /* Do more tests here... */
                    243:     }
                    244: 
1.1       jmmv      245:     ATF_TP_ADD_TCS(tp)
                    246:     {
                    247:         ATF_TP_ADD_TC(tp, my_test_case);
1.2       jmmv      248:         ATF_TP_ADD_TC(tp, another_test_case);
1.1       jmmv      249:     }
                    250: 
1.2       jmmv      251: This program needs to be linked against libatf-c as described below.  Once
                    252: linked, the program automatically gains a main() method that provides a
                    253: consistent user interface to all test programs.  You are simply not inteded to
                    254: provide your own main method, nor to deal with the command-line of the
                    255: invocation.
                    256: 
1.1       jmmv      257: ### How to build
                    258: 
                    259: To build a C test program, append the name of the test program (without the .c
                    260: extension) to the TESTS_C variable in the Makefile.
                    261: 
                    262: For example:
                    263: 
                    264:     .include <bsd.own.mk>
                    265: 
                    266:     TESTSDIR= ${TESTSBASE}/bin/ls
                    267: 
                    268:     TESTS_C+= fs_test ui_test
                    269: 
                    270:     .include <bsd.test.mk>
                    271: 
1.3     ! jmmv      272: ### Common functions
        !           273: 
        !           274: The following functions are commonly used from within a test case body:
        !           275: 
        !           276: * ATF_CHECK(boolean_expression): Checks if the given boolean expression is true
        !           277:   and, if not, records a failure for the test case but *execution continues*.
        !           278:   Using ATF_REQUIRE aborts execution immediately after a failure.
        !           279: 
        !           280: * ATF_CHECK_EQ(expected_expression, actual_expression): Checks if the two
        !           281:   expressions match and, if not, records a failure.  Similarly, ATF_REQUIRE_EQ
        !           282:   aborts immediately if the check fails.
        !           283: 
        !           284: * ATF_CHECK_STREQ(expected_string, actual_string): Same as ATF_CHECK_EQ but
        !           285:   performs string comparisons with strcmp.
        !           286: 
        !           287: * atf_tc_skip(const char *format, ...): Marks the test case as skipped with the
        !           288:   provided reason and exits.
        !           289: 
        !           290: * atf_tc_fail(const char *format, ...): Marks the test case as failed with the
        !           291:   provided reason and exits.
        !           292: 
        !           293: * atf_tc_pass(void): Explicitly marks the test case as passed.  This is
        !           294:   *implied* when the test case function ends, so you should not use this in
        !           295:   general.
        !           296: 
        !           297: * atf_expect_fail(const char *format, ...): Tells the atf runtime that the code
        !           298:   following this call is expected to raise one or more failures (be it with
        !           299:   atf_tc_fail, ATF_CHECK_*, etc.).  Use this to mark a block of code that is
        !           300:   known to be broken (e.g. a test that reproduces a known bug).  Use the string
        !           301:   parameter to provide an explanation about why the code is broken; if possible,
        !           302:   provide a PR number.  Lastly, to terminate the "expected failure" code block
        !           303:   and reset the runtime to the default functionality, use the atf_expect_pass()
        !           304:   function.
        !           305: 
        !           306: * atf_expect_death(const char *format, ...): Same as atf_expect_fail but expects
        !           307:   an abrupt termination of the test case, be it due to a call to exit() or to
        !           308:   the reception of a signal.
        !           309: 
        !           310: * atf_expect_exit(int exitcode, const char *fomat, ...): Same as atf_expect_fail
        !           311:   but expects the test case to exit with a specific exitcode.  Provide -1 to
        !           312:   indicate any exit code.
        !           313: 
        !           314: * atf_expect_signal(int signo, const char *fomat, ...): Same as atf_expect_fail
        !           315:   but expects the test case to receive a specific signal.  Provide -1 to
        !           316:   indicate any signal.
        !           317: 
        !           318: * atf_expect_timeout(const char *reason, ...): Same as atf_expect_fail but
        !           319:   expects the test case to get stuck and time out.
        !           320: 
1.1       jmmv      321: ## Shell test programs
                    322: 
                    323: ### Template
                    324: 
1.2       jmmv      325: The following code snippet provides a shell test program with two test cases:
                    326: 
1.1       jmmv      327:     atf_test_case my_test_case
                    328:     my_test_case_head() {
                    329:         atf_set "descr" "This test case ensures that..."
                    330:     }
                    331:     my_test_case_body() {
                    332:         touch file1 file2
                    333: 
                    334:         cat >expout <<EOF
                    335:     file1
                    336:     file2
                    337:     EOF
                    338:         atf_check -s eq:0 -o file:expout -e empty 'ls'
                    339: 
                    340:         atf_check_equal 4 $((2 + 2))
                    341: 
                    342:         if [ 'a' != 'b' ]; then
                    343:             atf_fail "Condition not met!"  # Explicit failure.
                    344:         fi
                    345:     }
                    346: 
1.2       jmmv      347:     atf_test_case another_test_case
                    348:     another_test_case_body() {
                    349:         # Do more tests...
                    350:     }
                    351: 
1.1       jmmv      352:     atf_init_test_cases() {
                    353:         atf_add_test_case my_test_case
1.2       jmmv      354:         atf_add_test_case another_test_case
1.1       jmmv      355:     }
                    356: 
1.2       jmmv      357: This program needs to be be executed with the atf-sh(1) interpreter as described
                    358: below.  The program automatically gains an entry point that provides a
                    359: consistent user interface to all test programs.  You are simply not inteded to
                    360: provide your own "main method", nor to deal with the command-line of the
                    361: invocation.
                    362: 
1.1       jmmv      363: ### How to build
                    364: 
                    365: To build a shell test program, append the name of the test program (without the
                    366: .sh extension) to the TESTS_SH variable in the Makefile.
                    367: 
                    368: For example:
                    369: 
                    370:     .include <bsd.own.mk>
                    371: 
                    372:     TESTSDIR= ${TESTSBASE}/bin/ls
                    373: 
                    374:     TESTS_SH+= integration_test something_else_test
                    375: 
                    376:     .include <bsd.test.mk>
                    377: 
                    378: If you want to run the test program yourself, you should know that shell-based
                    379: test programs are processed with the atf-sh interpreter.  atf-sh is just a thin
                    380: wrapper over /bin/sh that loads the shared atf code and then delegates execution
                    381: to your source file.
                    382: 
1.3     ! jmmv      383: ### Common functions
        !           384: 
        !           385: The following functions are commonly used from within a test case body:
        !           386: 
        !           387: * atf_check: This is probably the most useful function for shell-based tests.
        !           388:   It may need some experience to get it right, but it allows, in one line, to
        !           389:   check the execution of a command.  Where check means: validate exit code,
        !           390:   stdout and stderr.  This is just a wrapper over atf-check, so please refer to
        !           391:   [atf-check(1)](http://netbsd.gw.com/cgi-bin/man-cgi?atf-check++NetBSD-current)
        !           392:   for more details.
        !           393: 
        !           394: * atf_check_equal value1 value2: Check that the two values are equal and, if
        !           395:   not, abort execution.
        !           396: 
        !           397: * atf_expect_*: Same as their C counterparts; see above.
        !           398: 
        !           399: * atf_fail reason: Explicitly marks the test case as failed and aborts it.
        !           400: 
        !           401: * atf_skip reason: Explicitly marks the test case as skipped and exits.
        !           402: 
        !           403: * atf_pass: Explicitly markts the test case as passed and exits.
        !           404: 
        !           405: * atf_get_srcdir: Prints the path to the directory where the test case lives.
        !           406:   Use as $(atf_get_srcdir)/my-static-data-file.
        !           407: 
1.1       jmmv      408: ## FAQ
                    409: 
                    410: ### How do I atfify a plain test program?
                    411: 
                    412: Let's suppose you have a program to exercise a particular piece of code.
                    413: Conceptually this implements a test but it does not use atf at all.  For
                    414: example:
                    415: 
                    416:     #include <err.h>
                    417:     #include <stdio.h>
                    418:     #include <stdlib.h>
                    419:     #include <string.h>
                    420: 
                    421:     /* This test program exercises the snprintf function. */
                    422: 
                    423:     int main(void)
                    424:     {
                    425:         char buf[1024];
                    426: 
                    427:         printf("Testing integers");
                    428:         snprintf(buf, sizeof(buf), "%d", 3);
                    429:         if (strcmp(buf, "3") != 0)
                    430:             errx(EXIT_FAILURE, "%d failed");
                    431:         snprintf(buf, sizeof(buf), "a %d b", 5);
                    432:         if (strcmp(buf, "a 5 b") != 0)
                    433:             errx(EXIT_FAILURE, "%d failed");
                    434: 
                    435:         printf("Testing strings");
                    436:         snprintf(buf, sizeof(buf), "%s", "foo");
                    437:         if (strcmp(buf, "foo") != 0)
                    438:             errx(EXIT_FAILURE, "%s failed");
                    439:         snprintf(buf, sizeof(buf), "a %s b", "bar");
                    440:         if (strcmp(buf, "a bar b") != 0)
                    441:             errx(EXIT_FAILURE, "%s failed");
                    442: 
                    443:         return EXIT_SUCCESS;
                    444:     }
                    445: 
                    446: To convert this program into an atf test program, use the template above and
                    447: keep this in mind:
                    448: 
                    449: * Split the whole main function into separate test cases.  In this scenario, the
                    450:   calls to printf(3) delimit a good granularity for the test cases: one for the
                    451:   integer formatter, one for the string formatter, etc.
                    452: 
                    453: * Use the ATF_CHECK* and/or atf_tc_fail functions to do the comparisons and
                    454:   report errors.  errx should not be used.
                    455: 
                    456: The result would look like:
                    457: 
                    458:     #include <atf-c.h>
                    459:     #include <stdio.h>
                    460: 
                    461:     ATF_TC(tc, integer_formatter);
                    462:     ATF_TC_HEAD(tc, integer_formatter)
                    463:     {
                    464:         atf_tc_set_md_var(tc, "descr", "Validates the %d formatter");
                    465:     }
                    466:     ATF_TC_BODY(tc, integer_formatter)
                    467:     {
                    468:         char buf[1024];
                    469: 
                    470:         snprintf(buf, sizeof(1024), "%d", 3);
                    471:         ATF_CHECK_STREQ("3", buf);
                    472: 
                    473:         snprintf(buf, sizeof(1024), "a %d b", 5);
                    474:         ATF_CHECK_STREQ("a 5 b", buf);
                    475:     }
                    476: 
                    477:     ATF_TC(tc, string_formatter);
                    478:     ATF_TC_HEAD(tc, string_formatter)
                    479:     {
                    480:         atf_tc_set_md_var(tc, "descr", "Validates the %s formatter");
                    481:     }
                    482:     ATF_TC_BODY(tc, string_formatter)
                    483:     {
                    484:         char buf[1024];
                    485: 
                    486:         snprintf(buf, sizeof(1024), "%s", "foo");
                    487:         ATF_CHECK_STREQ("foo", buf);
                    488: 
                    489:         snprintf(buf, sizeof(1024), "a %s b", "bar");
                    490:         ATF_CHECK_STREQ("a bar b", buf);
                    491:     }
                    492: 
                    493:     ATF_TP_ADD_TCS(tp)
                    494:     {
                    495:         ATF_TP_ADD_TC(tp, integer_formatter);
                    496:         ATF_TP_ADD_TC(tp, string_formatter);
                    497:     }
                    498: 
                    499: Which can later be invoked as any of:
                    500: 
                    501:     $ ./snprintf_test integer_formatter
                    502:     $ ./snprintf_test string_formatter
                    503:     $ atf-run snprintf_test | atf-report
                    504: 
1.3     ! jmmv      505: ### How do I write a test case for an unfixed PR?
        !           506: 
        !           507: Use the "expectations" mechanism to define part of the test case as faulty,
        !           508: crashy, etc.  For example, suppose we have PR 1 that reports a condition in
        !           509: which snprintf() does the wrong formatting when using %s, and PR 2 that mentions
        !           510: that another snprintf() call using %d with number 5 causes a segfault.  We could
        !           511: do:
        !           512: 
        !           513:     #include <atf-c.h>
        !           514:     #include <signal.h>
        !           515:     #include <stdio.h>
        !           516: 
        !           517:     ATF_TC_WITHOUT_HEAD(tc, integer_formatter);
        !           518:     ATF_TC_BODY(tc, integer_formatter)
        !           519:     {
        !           520:         char buf[1024];
        !           521: 
        !           522:         snprintf(buf, sizeof(buf), "Hello %d\n", 1);
        !           523:         ATF_CHECK_STREQ("Hello 1", buf);
        !           524: 
        !           525:         atf_tc_expect_signal(SIGSEGV, "PR 2: %%d with 5 causes a crash");
        !           526:         snprintf(buf, sizeof(buf), "Hello %d\n", 5);
        !           527:         atf_tc_expect_pass();
        !           528:         ATF_CHECK_STREQ("Hello 5", buf);
        !           529:     }
        !           530: 
        !           531:     ATF_TC_WITHOUT_HEAD(tc, string_formatter);
        !           532:     ATF_TC_BODY(tc, string_formatter)
        !           533:     {
        !           534:         char buf[1024];
        !           535: 
        !           536:         snprintf(buf, sizeof(buf), "Hello %s\n", "world!");
        !           537:         atf_tc_expect_failure("PR 1: %%s does not work");
        !           538:         ATF_CHECK_STREQ("Hello world!", buf);
        !           539:         atf_tc_expect_pass();
        !           540:     }
        !           541: 
        !           542:     ATF_TP_ADD_TCS(tp)
        !           543:     {
        !           544:         ATF_TP_ADD_TC(tp, integer_formatter);
        !           545:         ATF_TP_ADD_TC(tp, string_formatter);
        !           546:     }
        !           547: 
1.1       jmmv      548: ### Do I need to remove temporary files?
                    549: 
                    550: No.  atf-run does this automatically for you, because it runs every test program
                    551: in its own temporary subdirectory.

CVSweb for NetBSD wikisrc <wikimaster@NetBSD.org> software: FreeBSD-CVSweb