1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <fcntl.h>
17 #include <stdlib.h>
18 #include "functionalext.h"
19
20 /**
21 * @tc.name : fexecve_0100
22 * @tc.desc : Each parameter is valid, the fexecve function can execute the specified file.
23 * @tc.level : Level 0
24 */
fexecve_0100(void)25 void fexecve_0100(void)
26 {
27 pid_t fpid;
28 fpid = fork();
29 if (fpid == 0) {
30 char *argv[] = {"./fexecverely", NULL};
31 char *environ[] = {0, NULL};
32 int fd = open("fexecverely", O_RDONLY);
33 int ret = fexecve(fd, argv, environ);
34 EXPECT_NE("fexecve_0100", ret, -1);
35 }
36 }
37
38 /**
39 * @tc.name : fexecve_0200
40 * @tc.desc : The fd parameter is invalid (NULL), the fexecve function cannot execute the specified file.
41 * @tc.level : Level 2
42 */
fexecve_0200(void)43 void fexecve_0200(void)
44 {
45 char *my_env[] = {NULL};
46 char *argv[] = {"touch", "fexecvetest.txt", NULL};
47 int ret = fexecve(-1, argv, my_env);
48 EXPECT_EQ("fexecve_0200", ret, -1);
49 }
50
main(int argc,char * argv[])51 int main(int argc, char *argv[])
52 {
53 fexecve_0100();
54 fexecve_0200();
55 return t_status;
56 }