1 /* Copyright (c) 2008 The NetBSD Foundation, Inc.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
14 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
15 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
20 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
24 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
28 #include <sys/types.h>
41 #include "atf-c/defs.h"
42 #include "atf-c/detail/env.h"
43 #include "atf-c/detail/fs.h"
44 #include "atf-c/detail/map.h"
45 #include "atf-c/detail/sanity.h"
46 #include "atf-c/detail/text.h"
47 #include "atf-c/error.h"
49 /* ---------------------------------------------------------------------
50 * Auxiliary functions.
51 * --------------------------------------------------------------------- */
67 enum expect_type expect;
68 atf_dynstr_t expect_reason;
69 size_t expect_previous_fail_count;
70 size_t expect_fail_count;
75 static void context_init(struct context *, const atf_tc_t *, const char *);
76 static void check_fatal_error(atf_error_t);
77 static void report_fatal_error(const char *, ...)
78 ATF_DEFS_ATTRIBUTE_NORETURN;
79 static atf_error_t write_resfile(const int, const char *, const int,
80 const atf_dynstr_t *);
81 static void create_resfile(const char *, const char *, const int,
83 static void error_in_expect(struct context *, const char *, ...)
84 ATF_DEFS_ATTRIBUTE_NORETURN;
85 static void validate_expect(struct context *);
86 static void expected_failure(struct context *, atf_dynstr_t *)
87 ATF_DEFS_ATTRIBUTE_NORETURN;
88 static void fail_requirement(struct context *, atf_dynstr_t *)
89 ATF_DEFS_ATTRIBUTE_NORETURN;
90 static void fail_check(struct context *, atf_dynstr_t *);
91 static void pass(struct context *)
92 ATF_DEFS_ATTRIBUTE_NORETURN;
93 static void skip(struct context *, atf_dynstr_t *)
94 ATF_DEFS_ATTRIBUTE_NORETURN;
95 static void format_reason_ap(atf_dynstr_t *, const char *, const size_t,
96 const char *, va_list);
97 static void format_reason_fmt(atf_dynstr_t *, const char *, const size_t,
99 static void errno_test(struct context *, const char *, const size_t,
100 const int, const char *, const bool,
101 void (*)(struct context *, atf_dynstr_t *));
102 static atf_error_t check_prog_in_dir(const char *, void *);
103 static atf_error_t check_prog(struct context *, const char *);
106 context_init(struct context *ctx, const atf_tc_t *tc, const char *resfile)
109 ctx->resfile = resfile;
111 ctx->expect = EXPECT_PASS;
112 check_fatal_error(atf_dynstr_init(&ctx->expect_reason));
113 ctx->expect_previous_fail_count = 0;
114 ctx->expect_fail_count = 0;
115 ctx->expect_exitcode = 0;
116 ctx->expect_signo = 0;
120 check_fatal_error(atf_error_t err)
122 if (atf_is_error(err)) {
124 atf_error_format(err, buf, sizeof(buf));
125 fprintf(stderr, "FATAL ERROR: %s\n", buf);
132 report_fatal_error(const char *msg, ...)
135 fprintf(stderr, "FATAL ERROR: ");
138 vfprintf(stderr, msg, ap);
141 fprintf(stderr, "\n");
145 /** Writes to a results file.
147 * The results file is supposed to be already open.
149 * This function returns an error code instead of exiting in case of error
150 * because the caller needs to clean up the reason object before terminating.
153 write_resfile(const int fd, const char *result, const int arg,
154 const atf_dynstr_t *reason)
156 static char NL[] = "\n", CS[] = ": ";
163 INV(arg == -1 || reason != NULL);
165 #define UNCONST(a) ((void *)(unsigned long)(const void *)(a))
166 iov[count].iov_base = UNCONST(result);
167 iov[count++].iov_len = strlen(result);
169 if (reason != NULL) {
171 iov[count].iov_base = buf;
172 iov[count++].iov_len = snprintf(buf, sizeof(buf), "(%d)", arg);
175 iov[count].iov_base = CS;
176 iov[count++].iov_len = sizeof(CS) - 1;
178 r = atf_dynstr_cstring(reason);
179 iov[count].iov_base = UNCONST(r);
180 iov[count++].iov_len = strlen(r);
184 iov[count].iov_base = NL;
185 iov[count++].iov_len = sizeof(NL) - 1;
187 while ((ret = writev(fd, iov, count)) == -1 && errno == EINTR)
188 continue; /* Retry. */
190 return atf_no_error();
192 return atf_libc_error(
193 errno, "Failed to write results file; result %s, reason %s", result,
194 reason == NULL ? "null" : atf_dynstr_cstring(reason));
197 /** Creates a results file.
199 * The input reason is released in all cases.
201 * An error in this function is considered to be fatal, hence why it does
202 * not return any error code.
205 create_resfile(const char *resfile, const char *result, const int arg,
206 atf_dynstr_t *reason)
210 if (strcmp("/dev/stdout", resfile) == 0) {
211 err = write_resfile(STDOUT_FILENO, result, arg, reason);
212 } else if (strcmp("/dev/stderr", resfile) == 0) {
213 err = write_resfile(STDERR_FILENO, result, arg, reason);
215 const int fd = open(resfile, O_WRONLY | O_CREAT | O_TRUNC,
216 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
218 err = atf_libc_error(errno, "Cannot create results file '%s'",
221 err = write_resfile(fd, result, arg, reason);
227 atf_dynstr_fini(reason);
229 check_fatal_error(err);
232 /** Fails a test case if validate_expect fails. */
234 error_in_expect(struct context *ctx, const char *fmt, ...)
240 format_reason_ap(&reason, NULL, 0, fmt, ap);
243 ctx->expect = EXPECT_PASS; /* Ensure fail_requirement really fails. */
244 fail_requirement(ctx, &reason);
247 /** Ensures that the "expect" state is correct.
249 * Call this function before modifying the current value of expect.
252 validate_expect(struct context *ctx)
254 if (ctx->expect == EXPECT_DEATH) {
255 error_in_expect(ctx, "Test case was expected to terminate abruptly "
256 "but it continued execution");
257 } else if (ctx->expect == EXPECT_EXIT) {
258 error_in_expect(ctx, "Test case was expected to exit cleanly but it "
259 "continued execution");
260 } else if (ctx->expect == EXPECT_FAIL) {
261 if (ctx->expect_fail_count == ctx->expect_previous_fail_count)
262 error_in_expect(ctx, "Test case was expecting a failure but none "
265 INV(ctx->expect_fail_count > ctx->expect_previous_fail_count);
266 } else if (ctx->expect == EXPECT_PASS) {
267 /* Nothing to validate. */
268 } else if (ctx->expect == EXPECT_SIGNAL) {
269 error_in_expect(ctx, "Test case was expected to receive a termination "
270 "signal but it continued execution");
271 } else if (ctx->expect == EXPECT_TIMEOUT) {
272 error_in_expect(ctx, "Test case was expected to hang but it continued "
279 expected_failure(struct context *ctx, atf_dynstr_t *reason)
281 check_fatal_error(atf_dynstr_prepend_fmt(reason, "%s: ",
282 atf_dynstr_cstring(&ctx->expect_reason)));
283 create_resfile(ctx->resfile, "expected_failure", -1, reason);
288 fail_requirement(struct context *ctx, atf_dynstr_t *reason)
290 if (ctx->expect == EXPECT_FAIL) {
291 expected_failure(ctx, reason);
292 } else if (ctx->expect == EXPECT_PASS) {
293 create_resfile(ctx->resfile, "failed", -1, reason);
296 error_in_expect(ctx, "Test case raised a failure but was not "
297 "expecting one; reason was %s", atf_dynstr_cstring(reason));
303 fail_check(struct context *ctx, atf_dynstr_t *reason)
305 if (ctx->expect == EXPECT_FAIL) {
306 fprintf(stderr, "*** Expected check failure: %s: %s\n",
307 atf_dynstr_cstring(&ctx->expect_reason),
308 atf_dynstr_cstring(reason));
309 ctx->expect_fail_count++;
310 } else if (ctx->expect == EXPECT_PASS) {
311 fprintf(stderr, "*** Check failed: %s\n", atf_dynstr_cstring(reason));
314 error_in_expect(ctx, "Test case raised a failure but was not "
315 "expecting one; reason was %s", atf_dynstr_cstring(reason));
318 atf_dynstr_fini(reason);
322 pass(struct context *ctx)
324 if (ctx->expect == EXPECT_FAIL) {
325 error_in_expect(ctx, "Test case was expecting a failure but got "
327 } else if (ctx->expect == EXPECT_PASS) {
328 create_resfile(ctx->resfile, "passed", -1, NULL);
331 error_in_expect(ctx, "Test case asked to explicitly pass but was "
332 "not expecting such condition");
338 skip(struct context *ctx, atf_dynstr_t *reason)
340 if (ctx->expect == EXPECT_PASS) {
341 create_resfile(ctx->resfile, "skipped", -1, reason);
344 error_in_expect(ctx, "Can only skip a test case when running in "
350 /** Formats a failure/skip reason message.
352 * The formatted reason is stored in out_reason. out_reason is initialized
353 * in this function and is supposed to be released by the caller. In general,
354 * the reason will eventually be fed to create_resfile, which will release
357 * Errors in this function are fatal. Rationale being: reasons are used to
358 * create results files; if we can't format the reason correctly, the result
359 * of the test program will be bogus. So it's better to just exit with a
363 format_reason_ap(atf_dynstr_t *out_reason,
364 const char *source_file, const size_t source_line,
365 const char *reason, va_list ap)
369 if (source_file != NULL) {
370 err = atf_dynstr_init_fmt(out_reason, "%s:%zd: ", source_file,
373 PRE(source_line == 0);
374 err = atf_dynstr_init(out_reason);
377 if (!atf_is_error(err)) {
380 err = atf_dynstr_append_ap(out_reason, reason, ap2);
384 check_fatal_error(err);
388 format_reason_fmt(atf_dynstr_t *out_reason,
389 const char *source_file, const size_t source_line,
390 const char *reason, ...)
394 va_start(ap, reason);
395 format_reason_ap(out_reason, source_file, source_line, reason, ap);
400 errno_test(struct context *ctx, const char *file, const size_t line,
401 const int exp_errno, const char *expr_str,
402 const bool expr_result,
403 void (*fail_func)(struct context *, atf_dynstr_t *))
405 const int actual_errno = errno;
408 if (exp_errno != actual_errno) {
411 format_reason_fmt(&reason, file, line, "Expected errno %d, got %d, "
412 "in %s", exp_errno, actual_errno, expr_str);
413 fail_func(ctx, &reason);
418 format_reason_fmt(&reason, file, line, "Expected true value in %s",
420 fail_func(ctx, &reason);
424 struct prog_found_pair {
430 check_prog_in_dir(const char *dir, void *data)
432 struct prog_found_pair *pf = data;
436 err = atf_no_error();
440 err = atf_fs_path_init_fmt(&p, "%s/%s", dir, pf->prog);
441 if (atf_is_error(err))
444 err = atf_fs_eaccess(&p, atf_fs_access_x);
445 if (!atf_is_error(err))
450 err = atf_no_error();
454 atf_fs_path_fini(&p);
461 check_prog(struct context *ctx, const char *prog)
466 err = atf_fs_path_init_fmt(&p, "%s", prog);
467 if (atf_is_error(err))
470 if (atf_fs_path_is_absolute(&p)) {
471 err = atf_fs_eaccess(&p, atf_fs_access_x);
472 if (atf_is_error(err)) {
476 atf_fs_path_fini(&p);
477 format_reason_fmt(&reason, NULL, 0, "The required program %s could "
478 "not be found", prog);
482 const char *path = atf_env_get("PATH");
483 struct prog_found_pair pf;
486 err = atf_fs_path_branch_path(&p, &bp);
487 if (atf_is_error(err))
490 if (strcmp(atf_fs_path_cstring(&bp), ".") != 0) {
491 atf_fs_path_fini(&bp);
492 atf_fs_path_fini(&p);
494 report_fatal_error("Relative paths are not allowed when searching "
495 "for a program (%s)", prog);
501 err = atf_text_for_each_word(path, ":", check_prog_in_dir, &pf);
502 if (atf_is_error(err))
508 atf_fs_path_fini(&bp);
509 atf_fs_path_fini(&p);
510 format_reason_fmt(&reason, NULL, 0, "The required program %s could "
511 "not be found in the PATH", prog);
512 fail_requirement(ctx, &reason);
516 atf_fs_path_fini(&bp);
520 atf_fs_path_fini(&p);
525 /* ---------------------------------------------------------------------
527 * --------------------------------------------------------------------- */
535 atf_tc_head_t m_head;
536 atf_tc_body_t m_body;
537 atf_tc_cleanup_t m_cleanup;
541 * Constructors/destructors.
545 atf_tc_init(atf_tc_t *tc, const char *ident, atf_tc_head_t head,
546 atf_tc_body_t body, atf_tc_cleanup_t cleanup,
547 const char *const *config)
551 tc->pimpl = malloc(sizeof(struct atf_tc_impl));
552 if (tc->pimpl == NULL) {
553 err = atf_no_memory_error();
557 tc->pimpl->m_ident = ident;
558 tc->pimpl->m_head = head;
559 tc->pimpl->m_body = body;
560 tc->pimpl->m_cleanup = cleanup;
562 err = atf_map_init_charpp(&tc->pimpl->m_config, config);
563 if (atf_is_error(err))
566 err = atf_map_init(&tc->pimpl->m_vars);
567 if (atf_is_error(err))
570 err = atf_tc_set_md_var(tc, "ident", ident);
571 if (atf_is_error(err))
574 if (cleanup != NULL) {
575 err = atf_tc_set_md_var(tc, "has.cleanup", "true");
576 if (atf_is_error(err))
580 /* XXX Should the head be able to return error codes? */
581 if (tc->pimpl->m_head != NULL)
582 tc->pimpl->m_head(tc);
584 if (strcmp(atf_tc_get_md_var(tc, "ident"), ident) != 0) {
585 report_fatal_error("Test case head modified the read-only 'ident' "
590 INV(!atf_is_error(err));
594 atf_map_fini(&tc->pimpl->m_vars);
596 atf_map_fini(&tc->pimpl->m_config);
602 atf_tc_init_pack(atf_tc_t *tc, const atf_tc_pack_t *pack,
603 const char *const *config)
605 return atf_tc_init(tc, pack->m_ident, pack->m_head, pack->m_body,
606 pack->m_cleanup, config);
610 atf_tc_fini(atf_tc_t *tc)
612 atf_map_fini(&tc->pimpl->m_vars);
621 atf_tc_get_ident(const atf_tc_t *tc)
623 return tc->pimpl->m_ident;
627 atf_tc_get_config_var(const atf_tc_t *tc, const char *name)
630 atf_map_citer_t iter;
632 PRE(atf_tc_has_config_var(tc, name));
633 iter = atf_map_find_c(&tc->pimpl->m_config, name);
634 val = atf_map_citer_data(iter);
641 atf_tc_get_config_var_wd(const atf_tc_t *tc, const char *name,
646 if (!atf_tc_has_config_var(tc, name))
649 val = atf_tc_get_config_var(tc, name);
655 atf_tc_get_config_var_as_bool(const atf_tc_t *tc, const char *name)
661 strval = atf_tc_get_config_var(tc, name);
662 err = atf_text_to_bool(strval, &val);
663 if (atf_is_error(err)) {
665 atf_tc_fail("Configuration variable %s does not have a valid "
666 "boolean value; found %s", name, strval);
673 atf_tc_get_config_var_as_bool_wd(const atf_tc_t *tc, const char *name,
678 if (!atf_tc_has_config_var(tc, name))
681 val = atf_tc_get_config_var_as_bool(tc, name);
687 atf_tc_get_config_var_as_long(const atf_tc_t *tc, const char *name)
693 strval = atf_tc_get_config_var(tc, name);
694 err = atf_text_to_long(strval, &val);
695 if (atf_is_error(err)) {
697 atf_tc_fail("Configuration variable %s does not have a valid "
698 "long value; found %s", name, strval);
705 atf_tc_get_config_var_as_long_wd(const atf_tc_t *tc, const char *name,
710 if (!atf_tc_has_config_var(tc, name))
713 val = atf_tc_get_config_var_as_long(tc, name);
719 atf_tc_get_md_var(const atf_tc_t *tc, const char *name)
722 atf_map_citer_t iter;
724 PRE(atf_tc_has_md_var(tc, name));
725 iter = atf_map_find_c(&tc->pimpl->m_vars, name);
726 val = atf_map_citer_data(iter);
733 atf_tc_get_md_vars(const atf_tc_t *tc)
735 return atf_map_to_charpp(&tc->pimpl->m_vars);
739 atf_tc_has_config_var(const atf_tc_t *tc, const char *name)
741 atf_map_citer_t end, iter;
743 iter = atf_map_find_c(&tc->pimpl->m_config, name);
744 end = atf_map_end_c(&tc->pimpl->m_config);
745 return !atf_equal_map_citer_map_citer(iter, end);
749 atf_tc_has_md_var(const atf_tc_t *tc, const char *name)
751 atf_map_citer_t end, iter;
753 iter = atf_map_find_c(&tc->pimpl->m_vars, name);
754 end = atf_map_end_c(&tc->pimpl->m_vars);
755 return !atf_equal_map_citer_map_citer(iter, end);
763 atf_tc_set_md_var(atf_tc_t *tc, const char *name, const char *fmt, ...)
770 err = atf_text_format_ap(&value, fmt, ap);
773 if (!atf_is_error(err))
774 err = atf_map_insert(&tc->pimpl->m_vars, name, value, true);
781 /* ---------------------------------------------------------------------
782 * Free functions, as they should be publicly but they can't.
783 * --------------------------------------------------------------------- */
785 static void _atf_tc_fail(struct context *, const char *, va_list)
786 ATF_DEFS_ATTRIBUTE_NORETURN;
787 static void _atf_tc_fail_nonfatal(struct context *, const char *, va_list);
788 static void _atf_tc_fail_check(struct context *, const char *, const size_t,
789 const char *, va_list);
790 static void _atf_tc_fail_requirement(struct context *, const char *,
791 const size_t, const char *, va_list) ATF_DEFS_ATTRIBUTE_NORETURN;
792 static void _atf_tc_pass(struct context *) ATF_DEFS_ATTRIBUTE_NORETURN;
793 static void _atf_tc_require_prog(struct context *, const char *);
794 static void _atf_tc_skip(struct context *, const char *, va_list)
795 ATF_DEFS_ATTRIBUTE_NORETURN;
796 static void _atf_tc_check_errno(struct context *, const char *, const size_t,
797 const int, const char *, const bool);
798 static void _atf_tc_require_errno(struct context *, const char *, const size_t,
799 const int, const char *, const bool);
800 static void _atf_tc_expect_pass(struct context *);
801 static void _atf_tc_expect_fail(struct context *, const char *, va_list);
802 static void _atf_tc_expect_exit(struct context *, const int, const char *,
804 static void _atf_tc_expect_signal(struct context *, const int, const char *,
806 static void _atf_tc_expect_death(struct context *, const char *,
810 _atf_tc_fail(struct context *ctx, const char *fmt, va_list ap)
816 format_reason_ap(&reason, NULL, 0, fmt, ap2);
819 fail_requirement(ctx, &reason);
824 _atf_tc_fail_nonfatal(struct context *ctx, const char *fmt, va_list ap)
830 format_reason_ap(&reason, NULL, 0, fmt, ap2);
833 fail_check(ctx, &reason);
837 _atf_tc_fail_check(struct context *ctx, const char *file, const size_t line,
838 const char *fmt, va_list ap)
844 format_reason_ap(&reason, file, line, fmt, ap2);
847 fail_check(ctx, &reason);
851 _atf_tc_fail_requirement(struct context *ctx, const char *file,
852 const size_t line, const char *fmt, va_list ap)
858 format_reason_ap(&reason, file, line, fmt, ap2);
861 fail_requirement(ctx, &reason);
866 _atf_tc_pass(struct context *ctx)
873 _atf_tc_require_prog(struct context *ctx, const char *prog)
875 check_fatal_error(check_prog(ctx, prog));
879 _atf_tc_skip(struct context *ctx, const char *fmt, va_list ap)
885 format_reason_ap(&reason, NULL, 0, fmt, ap2);
892 _atf_tc_check_errno(struct context *ctx, const char *file, const size_t line,
893 const int exp_errno, const char *expr_str,
894 const bool expr_result)
896 errno_test(ctx, file, line, exp_errno, expr_str, expr_result, fail_check);
900 _atf_tc_require_errno(struct context *ctx, const char *file, const size_t line,
901 const int exp_errno, const char *expr_str,
902 const bool expr_result)
904 errno_test(ctx, file, line, exp_errno, expr_str, expr_result,
909 _atf_tc_expect_pass(struct context *ctx)
911 validate_expect(ctx);
913 ctx->expect = EXPECT_PASS;
917 _atf_tc_expect_fail(struct context *ctx, const char *reason, va_list ap)
921 validate_expect(ctx);
923 ctx->expect = EXPECT_FAIL;
924 atf_dynstr_fini(&ctx->expect_reason);
926 check_fatal_error(atf_dynstr_init_ap(&ctx->expect_reason, reason, ap2));
928 ctx->expect_previous_fail_count = ctx->expect_fail_count;
932 _atf_tc_expect_exit(struct context *ctx, const int exitcode, const char *reason,
936 atf_dynstr_t formatted;
938 validate_expect(ctx);
940 ctx->expect = EXPECT_EXIT;
942 check_fatal_error(atf_dynstr_init_ap(&formatted, reason, ap2));
945 create_resfile(ctx->resfile, "expected_exit", exitcode, &formatted);
949 _atf_tc_expect_signal(struct context *ctx, const int signo, const char *reason,
953 atf_dynstr_t formatted;
955 validate_expect(ctx);
957 ctx->expect = EXPECT_SIGNAL;
959 check_fatal_error(atf_dynstr_init_ap(&formatted, reason, ap2));
962 create_resfile(ctx->resfile, "expected_signal", signo, &formatted);
966 _atf_tc_expect_death(struct context *ctx, const char *reason, va_list ap)
969 atf_dynstr_t formatted;
971 validate_expect(ctx);
973 ctx->expect = EXPECT_DEATH;
975 check_fatal_error(atf_dynstr_init_ap(&formatted, reason, ap2));
978 create_resfile(ctx->resfile, "expected_death", -1, &formatted);
982 _atf_tc_expect_timeout(struct context *ctx, const char *reason, va_list ap)
985 atf_dynstr_t formatted;
987 validate_expect(ctx);
989 ctx->expect = EXPECT_TIMEOUT;
991 check_fatal_error(atf_dynstr_init_ap(&formatted, reason, ap2));
994 create_resfile(ctx->resfile, "expected_timeout", -1, &formatted);
997 /* ---------------------------------------------------------------------
999 * --------------------------------------------------------------------- */
1001 static struct context Current;
1004 atf_tc_run(const atf_tc_t *tc, const char *resfile)
1006 context_init(&Current, tc, resfile);
1008 tc->pimpl->m_body(tc);
1010 validate_expect(&Current);
1012 if (Current.fail_count > 0) {
1013 atf_dynstr_t reason;
1015 format_reason_fmt(&reason, NULL, 0, "%d checks failed; see output for "
1016 "more details", Current.fail_count);
1017 fail_requirement(&Current, &reason);
1018 } else if (Current.expect_fail_count > 0) {
1019 atf_dynstr_t reason;
1021 format_reason_fmt(&reason, NULL, 0, "%d checks failed as expected; "
1022 "see output for more details", Current.expect_fail_count);
1023 expected_failure(&Current, &reason);
1028 return atf_no_error();
1032 atf_tc_cleanup(const atf_tc_t *tc)
1034 if (tc->pimpl->m_cleanup != NULL)
1035 tc->pimpl->m_cleanup(tc);
1036 return atf_no_error(); /* XXX */
1039 /* ---------------------------------------------------------------------
1040 * Free functions that depend on Current.
1041 * --------------------------------------------------------------------- */
1044 * All the functions below provide delegates to other internal functions
1045 * (prefixed by _) that take the current test case as an argument to
1046 * prevent them from accessing global state. This is to keep the side-
1047 * effects of the internal functions clearer and easier to understand.
1049 * The public API should never have hid the fact that it needs access to
1050 * the current test case (other than maybe in the macros), but changing it
1051 * is hard. TODO: Revisit in the future.
1055 atf_tc_fail(const char *fmt, ...)
1059 PRE(Current.tc != NULL);
1062 _atf_tc_fail(&Current, fmt, ap);
1067 atf_tc_fail_nonfatal(const char *fmt, ...)
1071 PRE(Current.tc != NULL);
1074 _atf_tc_fail_nonfatal(&Current, fmt, ap);
1079 atf_tc_fail_check(const char *file, const size_t line, const char *fmt, ...)
1083 PRE(Current.tc != NULL);
1086 _atf_tc_fail_check(&Current, file, line, fmt, ap);
1091 atf_tc_fail_requirement(const char *file, const size_t line,
1092 const char *fmt, ...)
1096 PRE(Current.tc != NULL);
1099 _atf_tc_fail_requirement(&Current, file, line, fmt, ap);
1106 PRE(Current.tc != NULL);
1108 _atf_tc_pass(&Current);
1112 atf_tc_require_prog(const char *prog)
1114 PRE(Current.tc != NULL);
1116 _atf_tc_require_prog(&Current, prog);
1120 atf_tc_skip(const char *fmt, ...)
1124 PRE(Current.tc != NULL);
1127 _atf_tc_skip(&Current, fmt, ap);
1132 atf_tc_check_errno(const char *file, const size_t line, const int exp_errno,
1133 const char *expr_str, const bool expr_result)
1135 PRE(Current.tc != NULL);
1137 _atf_tc_check_errno(&Current, file, line, exp_errno, expr_str,
1142 atf_tc_require_errno(const char *file, const size_t line, const int exp_errno,
1143 const char *expr_str, const bool expr_result)
1145 PRE(Current.tc != NULL);
1147 _atf_tc_require_errno(&Current, file, line, exp_errno, expr_str,
1152 atf_tc_expect_pass(void)
1154 PRE(Current.tc != NULL);
1156 _atf_tc_expect_pass(&Current);
1160 atf_tc_expect_fail(const char *reason, ...)
1164 PRE(Current.tc != NULL);
1166 va_start(ap, reason);
1167 _atf_tc_expect_fail(&Current, reason, ap);
1172 atf_tc_expect_exit(const int exitcode, const char *reason, ...)
1176 PRE(Current.tc != NULL);
1178 va_start(ap, reason);
1179 _atf_tc_expect_exit(&Current, exitcode, reason, ap);
1184 atf_tc_expect_signal(const int signo, const char *reason, ...)
1188 PRE(Current.tc != NULL);
1190 va_start(ap, reason);
1191 _atf_tc_expect_signal(&Current, signo, reason, ap);
1196 atf_tc_expect_death(const char *reason, ...)
1200 PRE(Current.tc != NULL);
1202 va_start(ap, reason);
1203 _atf_tc_expect_death(&Current, reason, ap);
1208 atf_tc_expect_timeout(const char *reason, ...)
1212 PRE(Current.tc != NULL);
1214 va_start(ap, reason);
1215 _atf_tc_expect_timeout(&Current, reason, ap);