diff options
author | jmmv <jmmv@FreeBSD.org> | 2014-11-01 11:17:54 +0000 |
---|---|---|
committer | jmmv <jmmv@FreeBSD.org> | 2014-11-01 11:17:54 +0000 |
commit | 120021745eb3a1c1b24fdc54769f808151deb621 (patch) | |
tree | 7e1f2a559f61d17aad44cfb95b6fefcaa593c4af /contrib/atf/atf-c/utils_test.c | |
parent | 595e4e5bc797fd4a63eb344ae9df352db666a94d (diff) | |
parent | 3b6cf63a5c1f2de80b3b7fdd30eab1717f5c9407 (diff) | |
download | FreeBSD-src-120021745eb3a1c1b24fdc54769f808151deb621.zip FreeBSD-src-120021745eb3a1c1b24fdc54769f808151deb621.tar.gz |
MFV: Import atf-0.21.
Diffstat (limited to 'contrib/atf/atf-c/utils_test.c')
-rw-r--r-- | contrib/atf/atf-c/utils_test.c | 62 |
1 files changed, 47 insertions, 15 deletions
diff --git a/contrib/atf/atf-c/utils_test.c b/contrib/atf/atf-c/utils_test.c index 57d6af8..fb81cd3 100644 --- a/contrib/atf/atf-c/utils_test.c +++ b/contrib/atf/atf-c/utils_test.c @@ -1,7 +1,4 @@ -/* - * Automated Testing Framework (atf) - * - * Copyright (c) 2010 The NetBSD Foundation, Inc. +/* Copyright (c) 2010 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,8 +21,9 @@ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +#include "atf-c/utils.h" #include <sys/stat.h> #include <sys/wait.h> @@ -39,9 +37,8 @@ #include <atf-c.h> -#include "atf-c/utils.h" - -#include "detail/test_helpers.h" +#include "atf-c/detail/dynstr.h" +#include "atf-c/detail/test_helpers.h" /** Reads the contents of a file into a buffer. * @@ -246,11 +243,19 @@ ATF_TC_BODY(fork, tc) ATF_REQUIRE(WIFEXITED(status)); ATF_REQUIRE_EQ(EXIT_SUCCESS, WEXITSTATUS(status)); + atf_dynstr_t out_name; + RE(atf_dynstr_init_fmt(&out_name, "atf_utils_fork_%d_out.txt", (int)pid)); + atf_dynstr_t err_name; + RE(atf_dynstr_init_fmt(&err_name, "atf_utils_fork_%d_err.txt", (int)pid)); + char buffer[1024]; - read_file("atf_utils_fork_out.txt", buffer, sizeof(buffer)); + read_file(atf_dynstr_cstring(&out_name), buffer, sizeof(buffer)); ATF_REQUIRE_STREQ("Child stdout\n", buffer); - read_file("atf_utils_fork_err.txt", buffer, sizeof(buffer)); + read_file(atf_dynstr_cstring(&err_name), buffer, sizeof(buffer)); ATF_REQUIRE_STREQ("Child stderr\n", buffer); + + atf_dynstr_fini(&err_name); + atf_dynstr_fini(&out_name); } ATF_TC_WITHOUT_HEAD(free_charpp__empty); @@ -384,6 +389,7 @@ static void fork_and_wait(const int exitstatus, const char* expout, const char* experr) { const pid_t pid = atf_utils_fork(); + ATF_REQUIRE(pid != -1); if (pid == 0) { fprintf(stdout, "Some output\n"); fprintf(stderr, "Some error\n"); @@ -408,6 +414,35 @@ ATF_TC_BODY(wait__ok, tc) } } +ATF_TC_WITHOUT_HEAD(wait__ok_nested); +ATF_TC_BODY(wait__ok_nested, tc) +{ + const pid_t parent = atf_utils_fork(); + ATF_REQUIRE(parent != -1); + if (parent == 0) { + const pid_t child = atf_utils_fork(); + ATF_REQUIRE(child != -1); + if (child == 0) { + fflush(stderr); + fprintf(stdout, "Child output\n"); + fflush(stdout); + fprintf(stderr, "Child error\n"); + exit(50); + } else { + fprintf(stdout, "Parent output\n"); + fprintf(stderr, "Parent error\n"); + atf_utils_wait(child, 50, "Child output\n", "Child error\n"); + exit(40); + } + } else { + atf_utils_wait(parent, 40, + "Parent output\n" + "subprocess stdout: Child output\n" + "subprocess stderr: Child error\n", + "Parent error\n"); + } +} + ATF_TC_WITHOUT_HEAD(wait__invalid_exitstatus); ATF_TC_BODY(wait__invalid_exitstatus, tc) { @@ -487,8 +522,6 @@ ATF_TC_BODY(wait__save_stderr, tc) } } -HEADER_TC(include, "atf-c/utils.h"); - ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, cat_file__empty); @@ -526,13 +559,12 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, redirect__other); ATF_TP_ADD_TC(tp, wait__ok); + ATF_TP_ADD_TC(tp, wait__ok_nested); ATF_TP_ADD_TC(tp, wait__save_stdout); ATF_TP_ADD_TC(tp, wait__save_stderr); ATF_TP_ADD_TC(tp, wait__invalid_exitstatus); ATF_TP_ADD_TC(tp, wait__invalid_stdout); ATF_TP_ADD_TC(tp, wait__invalid_stderr); - ATF_TP_ADD_TC(tp, include); - return atf_no_error(); } |