1 /* Test support_record_failure state sharing.
2 Copyright (C) 2016-2024 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 <https://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>
30 static int exit_status_with_failure
= -1;
31 static bool test_verify
;
32 static bool test_verify_exit
;
39 #define CMDLINE_OPTIONS \
40 { "status", required_argument, NULL, OPT_STATUS }, \
41 { "test-verify", no_argument, NULL, OPT_TEST_VERIFY }, \
42 { "test-verify-exit", no_argument, NULL, OPT_TEST_VERIFY_EXIT },
44 cmdline_process (int c
)
49 exit_status_with_failure
= atoi (optarg
);
54 case OPT_TEST_VERIFY_EXIT
:
55 test_verify_exit
= true;
59 #define CMDLINE_PROCESS cmdline_process
62 check_failure_reporting (int phase
, int zero
, int unsupported
)
64 int status
= support_report_failure (0);
67 printf ("real-error (phase %d): support_report_failure (0) == %d\n",
71 status
= support_report_failure (1);
74 printf ("real-error (phase %d): support_report_failure (1) == %d\n",
78 status
= support_report_failure (2);
81 printf ("real-error (phase %d): support_report_failure (2) == %d\n",
85 status
= support_report_failure (EXIT_UNSUPPORTED
);
86 if (status
!= unsupported
)
88 printf ("real-error (phase %d): "
89 "support_report_failure (EXIT_UNSUPPORTED) == %d\n",
98 if (exit_status_with_failure
>= 0)
100 /* External invocation with requested error status. Used by
101 tst-support_report_failure-2.sh. */
102 support_record_failure ();
103 return exit_status_with_failure
;
106 TEST_VERIFY_EXIT (true);
111 printf ("info: execution passed failed TEST_VERIFY\n");
112 return 2; /* Expected exit status. */
114 if (test_verify_exit
)
116 TEST_VERIFY_EXIT (false);
117 return 3; /* Not reached. Expected exit status is 1. */
120 printf ("info: This test tests the test framework.\n"
121 "info: It reports some expected errors on stdout.\n");
123 /* Check that the status is passed through unchanged. */
124 check_failure_reporting (1, 0, EXIT_UNSUPPORTED
);
126 /* Check state propagation from a subprocess. */
127 pid_t pid
= xfork ();
130 support_record_failure ();
134 xwaitpid (pid
, &status
, 0);
137 printf ("real-error: incorrect status from subprocess: %d\n", status
);
140 check_failure_reporting (2, 1, 1);
142 /* Also test directly in the parent process. */
143 support_record_failure_reset ();
144 check_failure_reporting (3, 0, EXIT_UNSUPPORTED
);
145 support_record_failure ();
146 check_failure_reporting (4, 1, 1);
148 /* We need to mask the failure above. */
149 support_record_failure_reset ();
153 #include <support/test-driver.c>