powerpc: Fix adapt_count update in __lll_unlock_elision
[glibc.git] / support / tst-support_record_failure.c
blob62d8e1f0572da0abe5f3a86d864cb0b776e7a2b4
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>
24 #include <getopt.h>
25 #include <stdbool.h>
26 #include <stdlib.h>
27 #include <stdio.h>
29 static int exit_status_with_failure = -1;
30 static bool test_verify;
31 static bool test_verify_exit;
32 enum
34 OPT_STATUS = 10001,
35 OPT_TEST_VERIFY,
36 OPT_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 },
42 static void
43 cmdline_process (int c)
45 switch (c)
47 case OPT_STATUS:
48 exit_status_with_failure = atoi (optarg);
49 break;
50 case OPT_TEST_VERIFY:
51 test_verify = true;
52 break;
53 case OPT_TEST_VERIFY_EXIT:
54 test_verify_exit = true;
55 break;
58 #define CMDLINE_PROCESS cmdline_process
60 static void
61 check_failure_reporting (int phase, int zero, int unsupported)
63 int status = support_report_failure (0);
64 if (status != zero)
66 printf ("real-error (phase %d): support_report_failure (0) == %d\n",
67 phase, status);
68 exit (1);
70 status = support_report_failure (1);
71 if (status != 1)
73 printf ("real-error (phase %d): support_report_failure (1) == %d\n",
74 phase, status);
75 exit (1);
77 status = support_report_failure (2);
78 if (status != 2)
80 printf ("real-error (phase %d): support_report_failure (2) == %d\n",
81 phase, status);
82 exit (1);
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",
89 phase, status);
90 exit (1);
94 static int
95 do_test (void)
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;
104 TEST_VERIFY (true);
105 TEST_VERIFY_EXIT (true);
106 if (test_verify)
108 TEST_VERIFY (false);
109 if (test_verbose)
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 ();
127 if (pid == 0)
129 support_record_failure ();
130 _exit (0);
132 int status;
133 xwaitpid (pid, &status, 0);
134 if (status != 0)
136 printf ("real-error: incorrect status from subprocess: %d\n", status);
137 return 1;
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 ();
149 return 0;
152 #include <support/test-driver.c>