1 /* Test support_record_failure state sharing.
2 Copyright (C) 2016-2017 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #include <support/check.h>
20 #include <support/support.h>
21 #include <support/test-driver.h>
22 #include <support/xunistd.h>
29 static int exit_status_with_failure
= -1;
30 static bool test_verify
;
31 static bool test_verify_exit
;
38 #define CMDLINE_OPTIONS \
39 { "status", required_argument, NULL, OPT_STATUS }, \
40 { "test-verify", no_argument, NULL, OPT_TEST_VERIFY }, \
41 { "test-verify-exit", no_argument, NULL, OPT_TEST_VERIFY_EXIT },
43 cmdline_process (int c
)
48 exit_status_with_failure
= atoi (optarg
);
53 case OPT_TEST_VERIFY_EXIT
:
54 test_verify_exit
= true;
58 #define CMDLINE_PROCESS cmdline_process
61 check_failure_reporting (int phase
, int zero
, int unsupported
)
63 int status
= support_report_failure (0);
66 printf ("real-error (phase %d): support_report_failure (0) == %d\n",
70 status
= support_report_failure (1);
73 printf ("real-error (phase %d): support_report_failure (1) == %d\n",
77 status
= support_report_failure (2);
80 printf ("real-error (phase %d): support_report_failure (2) == %d\n",
84 status
= support_report_failure (EXIT_UNSUPPORTED
);
85 if (status
!= unsupported
)
87 printf ("real-error (phase %d): "
88 "support_report_failure (EXIT_UNSUPPORTED) == %d\n",
97 if (exit_status_with_failure
>= 0)
99 /* External invocation with requested error status. Used by
100 tst-support_report_failure-2.sh. */
101 support_record_failure ();
102 return exit_status_with_failure
;
105 TEST_VERIFY_EXIT (true);
110 printf ("info: execution passed failed TEST_VERIFY\n");
111 return 2; /* Expected exit status. */
113 if (test_verify_exit
)
115 TEST_VERIFY_EXIT (false);
116 return 3; /* Not reached. Expected exit status is 1. */
119 printf ("info: This test tests the test framework.\n"
120 "info: It reports some expected errors on stdout.\n");
122 /* Check that the status is passed through unchanged. */
123 check_failure_reporting (1, 0, EXIT_UNSUPPORTED
);
125 /* Check state propagation from a subprocess. */
126 pid_t pid
= xfork ();
129 support_record_failure ();
133 xwaitpid (pid
, &status
, 0);
136 printf ("real-error: incorrect status from subprocess: %d\n", status
);
139 check_failure_reporting (2, 1, 1);
141 /* Also test directly in the parent process. */
142 support_record_failure_reset ();
143 check_failure_reporting (3, 0, EXIT_UNSUPPORTED
);
144 support_record_failure ();
145 check_failure_reporting (4, 1, 1);
147 /* We need to mask the failure above. */
148 support_record_failure_reset ();
152 #include <support/test-driver.c>