math: Remove slow paths in tan [BZ #15267]
[glibc.git] / stdlib / tst-system.c
blob178808e048a9b3bc4668ad6001e1ec60f6d2b397
1 /* Copyright (C) 2002-2021 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
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 <stdlib.h>
20 #include <unistd.h>
21 #include <string.h>
22 #include <signal.h>
23 #include <paths.h>
25 #include <support/capture_subprocess.h>
26 #include <support/check.h>
27 #include <support/temp_file.h>
28 #include <support/support.h>
29 #include <support/xunistd.h>
31 static char *tmpdir;
32 static long int namemax;
34 static void
35 do_prepare (int argc, char *argv[])
37 tmpdir = support_create_temp_directory ("tst-system-");
38 /* Include the last '/0'. */
39 namemax = pathconf (tmpdir, _PC_NAME_MAX) + 1;
40 TEST_VERIFY_EXIT (namemax != -1);
42 #define PREPARE do_prepare
44 struct args
46 const char *command;
47 int exit_status;
48 int term_sig;
49 const char *path;
52 static void
53 call_system (void *closure)
55 struct args *args = (struct args *) closure;
56 int ret;
58 if (args->path != NULL)
59 TEST_COMPARE (setenv ("PATH", args->path, 1), 0);
60 ret = system (args->command);
61 if (args->term_sig == 0)
63 /* Expect regular termination. */
64 TEST_VERIFY (WIFEXITED (ret) != 0);
65 TEST_COMPARE (WEXITSTATUS (ret), args->exit_status);
67 else
69 /* status_or_signal < 0. Expect termination by signal. */
70 TEST_VERIFY (WIFSIGNALED (ret) != 0);
71 TEST_COMPARE (WTERMSIG (ret), args->term_sig);
75 static int
76 do_test (void)
78 TEST_VERIFY (system (NULL) != 0);
81 char cmd[namemax];
82 memset (cmd, 'a', sizeof(cmd));
83 cmd[sizeof(cmd) - 1] = '\0';
85 struct support_capture_subprocess result;
86 result = support_capture_subprocess (call_system,
87 &(struct args) {
88 cmd, 127, 0, tmpdir
89 });
90 support_capture_subprocess_check (&result, "system", 0, sc_allow_stderr);
92 char *returnerr = xasprintf ("%s: execing %s failed: "
93 "No such file or directory",
94 basename(_PATH_BSHELL), cmd);
95 TEST_COMPARE_STRING (result.err.buffer, returnerr);
96 free (returnerr);
100 char cmd[namemax + 1];
101 memset (cmd, 'a', sizeof(cmd));
102 cmd[sizeof(cmd) - 1] = '\0';
104 struct support_capture_subprocess result;
105 result = support_capture_subprocess (call_system,
106 &(struct args) {
107 cmd, 127, 0, tmpdir
109 support_capture_subprocess_check (&result, "system", 0, sc_allow_stderr);
111 char *returnerr = xasprintf ("%s: execing %s failed: "
112 "File name too long",
113 basename(_PATH_BSHELL), cmd);
114 TEST_COMPARE_STRING (result.err.buffer, returnerr);
115 free (returnerr);
119 struct support_capture_subprocess result;
120 result = support_capture_subprocess (call_system,
121 &(struct args) {
122 "kill $$", 0, SIGTERM
124 support_capture_subprocess_check (&result, "system", 0, sc_allow_none);
128 struct support_capture_subprocess result;
129 result = support_capture_subprocess (call_system,
130 &(struct args) { "echo ...", 0 });
131 support_capture_subprocess_check (&result, "system", 0, sc_allow_stdout);
132 TEST_COMPARE_STRING (result.out.buffer, "...\n");
136 struct support_capture_subprocess result;
137 result = support_capture_subprocess (call_system,
138 &(struct args) { "exit 1", 1 });
139 support_capture_subprocess_check (&result, "system", 0, sc_allow_none);
143 struct stat64 st;
144 xstat (_PATH_BSHELL, &st);
145 mode_t mode = st.st_mode;
146 xchmod (_PATH_BSHELL, mode & ~(S_IXUSR | S_IXGRP | S_IXOTH));
148 struct support_capture_subprocess result;
149 result = support_capture_subprocess (call_system,
150 &(struct args) {
151 "exit 1", 127, 0
153 support_capture_subprocess_check (&result, "system", 0, sc_allow_none);
155 xchmod (_PATH_BSHELL, st.st_mode);
158 TEST_COMPARE (system (""), 0);
160 return 0;
163 #include <support/test-driver.c>