1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
4 * of this software and associated documentation files (the "Software"), to
5 * deal in the Software without restriction, including without limitation the
6 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 * sell copies of the Software, and to permit persons to whom the Software is
8 * furnished to do so, subject to the following conditions:
9 *
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19 * IN THE SOFTWARE.
20 */
21
22 #include <errno.h>
23 #include <signal.h>
24 #include <pthread.h>
25 #include <sys/wait.h>
26 #include "stdio.h"
27 #include <pthread.h>
28 #include <limits.h>
29 #include <locale.h>
30 #include <wchar.h>
31 #include <stdlib.h>
32 #include <dirent.h>
33 #include <utime.h>
34 #include "functionalext.h"
35
36 /**
37 * @tc.name : ftell_0100
38 * @tc.desc : Verify clearerr with invalid parameter
39 * @tc.level : Level 2
40 */
ftell_0100(void)41 void ftell_0100(void)
42 {
43 pid_t pid = fork();
44 if (pid == -1) {
45 t_error("ftell_0100: Error forking process");
46 } else if (pid == 0) {
47 ftell(NULL);
48 } else {
49 int status;
50 waitpid(pid, &status, 0);
51 if (WIFSIGNALED(status)) {
52 int sig = WTERMSIG(status);
53 EXPECT_EQ("ftell_0100", SIGABRT, sig);
54 }
55 }
56 }
57
58 /**
59 * @tc.name : fwrite_0100
60 * @tc.desc : Verify clearerr with invalid parameter
61 * @tc.level : Level 2
62 */
fwrite_0100(void)63 void fwrite_0100(void)
64 {
65 pid_t pid = fork();
66 if (pid == -1) {
67 t_error("fwrite_0100: Error forking process");
68 } else if (pid == 0) {
69 char buf[] = "this is test";
70 fwrite(buf, sizeof(char), strlen(buf), NULL);
71 } else {
72 int status;
73 waitpid(pid, &status, 0);
74 if (WIFSIGNALED(status)) {
75 int sig = WTERMSIG(status);
76 EXPECT_EQ("fwrite_0100", SIGABRT, sig);
77 }
78 }
79 }
80
81 /**
82 * @tc.name : getc_0100
83 * @tc.desc : Verify clearerr with invalid parameter
84 * @tc.level : Level 2
85 */
getc_0100(void)86 void getc_0100(void)
87 {
88 pid_t pid = fork();
89 if (pid == -1) {
90 t_error("getc_0100: Error forking process");
91 } else if (pid == 0) {
92 getc(NULL);
93 } else {
94 int status;
95 waitpid(pid, &status, 0);
96 if (WIFSIGNALED(status)) {
97 int sig = WTERMSIG(status);
98 EXPECT_EQ("getc_0100", SIGABRT, sig);
99 }
100 }
101 }
102
103 /**
104 * @tc.name : pclose_0100
105 * @tc.desc : Verify clearerr with invalid parameter
106 * @tc.level : Level 2
107 */
pclose_0100(void)108 void pclose_0100(void)
109 {
110 pid_t pid = fork();
111 if (pid == -1) {
112 t_error("pclose_0100: Error forking process");
113 } else if (pid == 0) {
114 pclose(NULL);
115 } else {
116 int status;
117 waitpid(pid, &status, 0);
118 if (WIFSIGNALED(status)) {
119 int sig = WTERMSIG(status);
120 EXPECT_EQ("pclose_0100", SIGABRT, sig);
121 }
122 }
123 }
124
125 /**
126 * @tc.name : rewind_0100
127 * @tc.desc : Verify clearerr with invalid parameter
128 * @tc.level : Level 2
129 */
rewind_0100(void)130 void rewind_0100(void)
131 {
132 pid_t pid = fork();
133 if (pid == -1) {
134 t_error("rewind_0100: Error forking process");
135 } else if (pid == 0) {
136 rewind(NULL);
137 } else {
138 int status;
139 waitpid(pid, &status, 0);
140 if (WIFSIGNALED(status)) {
141 int sig = WTERMSIG(status);
142 EXPECT_EQ("rewind_0100", SIGABRT, sig);
143 }
144 }
145 }
146
147 /**
148 * @tc.name : setvbuf_0100
149 * @tc.desc : Verify clearerr with invalid parameter
150 * @tc.level : Level 2
151 */
setvbuf_0100(void)152 void setvbuf_0100(void)
153 {
154 pid_t pid = fork();
155 if (pid == -1) {
156 t_error("setvbuf_0100: Error forking process");
157 } else if (pid == 0) {
158 char buff[1024] = {0};
159 setvbuf(NULL, buff, -1, 1024);
160 } else {
161 int status;
162 waitpid(pid, &status, 0);
163 if (WIFSIGNALED(status)) {
164 int sig = WTERMSIG(status);
165 EXPECT_EQ("setvbuf_0100", SIGABRT, sig);
166 }
167 }
168 }
169
170 /**
171 * @tc.name : wcsnrtombs_0100
172 * @tc.desc : Verify clearerr with invalid parameter
173 * @tc.level : Level 2
174 */
wcsnrtombs_0100(void)175 void wcsnrtombs_0100(void)
176 {
177 pid_t pid = fork();
178 if (pid == -1) {
179 t_error("wcsnrtombs_0100: Error forking process");
180 } else if (pid == 0) {
181 char buffer[32];
182 mbstate_t mbs;
183 size_t wn = 4;
184 size_t n = 4;
185 mbrlen(NULL, 0, &mbs);
186 memset(buffer, 0, sizeof(buffer));
187 wcsnrtombs(buffer, NULL, wn, n, &mbs);
188 } else {
189 int status;
190 waitpid(pid, &status, 0);
191 if (WIFSIGNALED(status)) {
192 int sig = WTERMSIG(status);
193 EXPECT_EQ("wcsnrtombs_0100", SIGABRT, sig);
194 }
195 }
196 }
197
198 /**
199 * @tc.name : unsetenv_0100
200 * @tc.desc : Verify clearerr with invalid parameter
201 * @tc.level : Level 2
202 */
unsetenv_0100(void)203 void unsetenv_0100(void)
204 {
205 pid_t pid = fork();
206 if (pid == -1) {
207 t_error("unsetenv_0100: Error forking process");
208 } else if (pid == 0) {
209 unsetenv(NULL);
210 } else {
211 int status;
212 waitpid(pid, &status, 0);
213 if (WIFSIGNALED(status)) {
214 int sig = WTERMSIG(status);
215 EXPECT_EQ("unsetenv_0100", SIGABRT, sig);
216 }
217 }
218 }
219
220 /**
221 * @tc.name : readdir_0100
222 * @tc.desc : Verify clearerr with invalid parameter
223 * @tc.level : Level 2
224 */
readdir_0100(void)225 void readdir_0100(void)
226 {
227 pid_t pid = fork();
228 if (pid == -1) {
229 t_error("readdir_0100: Error forking process");
230 } else if (pid == 0) {
231 readdir(NULL);
232 } else {
233 int status;
234 waitpid(pid, &status, 0);
235 if (WIFSIGNALED(status)) {
236 int sig = WTERMSIG(status);
237 EXPECT_EQ("readdir_0100", SIGABRT, sig);
238 }
239 }
240 }
241
242 /**
243 * @tc.name : pthread_join_0100
244 * @tc.desc : Verify clearerr with invalid parameter
245 * @tc.level : Level 2
246 */
pthread_join_0100(void)247 void pthread_join_0100(void)
248 {
249 pid_t pid = fork();
250 if (pid == -1) {
251 t_error("pthread_join_0100: Error forking process");
252 } else if (pid == 0) {
253 pthread_t invalid_thread = 0;
254 void *res;
255 pthread_join(invalid_thread, &res);
256 } else {
257 int status;
258 waitpid(pid, &status, 0);
259 if (WIFSIGNALED(status)) {
260 int sig = WTERMSIG(status);
261 EXPECT_EQ("pthread_join_0100", SIGABRT, sig);
262 }
263 }
264 }
265
266 /**
267 * @tc.name : pthread_kill_0100
268 * @tc.desc : Verify clearerr with invalid parameter
269 * @tc.level : Level 2
270 */
pthread_kill_0100(void)271 void pthread_kill_0100(void)
272 {
273 pid_t pid = fork();
274 if (pid == -1) {
275 t_error("pthread_kill_0100: Error forking process");
276 } else if (pid == 0) {
277 pthread_t invalid_thread = 0;
278 int valid_sig = SIGTERM;
279 pthread_kill(invalid_thread, valid_sig);
280 } else {
281 int status;
282 waitpid(pid, &status, 0);
283 if (WIFSIGNALED(status)) {
284 int sig = WTERMSIG(status);
285 EXPECT_EQ("pthread_kill_0100", SIGABRT, sig);
286 }
287 }
288 }
289
290 /**
291 * @tc.name : pthread_setschedparam_0100
292 * @tc.desc : Verify clearerr with invalid parameter
293 * @tc.level : Level 2
294 */
pthread_setschedparam_0100(void)295 void pthread_setschedparam_0100(void)
296 {
297 pid_t pid = fork();
298 if (pid == -1) {
299 t_error("pthread_setschedparam_0100: Error forking process");
300 } else if (pid == 0) {
301 pthread_t invalid_thread = 0;
302 struct sched_param param;
303 param.sched_priority = 1;
304 pthread_setschedparam(invalid_thread, SCHED_FIFO, ¶m);
305 } else {
306 int status;
307 waitpid(pid, &status, 0);
308 if (WIFSIGNALED(status)) {
309 int sig = WTERMSIG(status);
310 EXPECT_EQ("pthread_setschedparam_0100", SIGABRT, sig);
311 }
312 }
313 }
314
main(int argc,char * argv[])315 int main(int argc, char *argv[])
316 {
317 ftell_0100();
318 fwrite_0100();
319 getc_0100();
320 pclose_0100();
321 rewind_0100();
322 setvbuf_0100();
323 wcsnrtombs_0100();
324 unsetenv_0100();
325 readdir_0100();
326 pthread_join_0100();
327 pthread_kill_0100();
328 pthread_setschedparam_0100();
329
330 return t_status;
331 }
332