• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "functionalext.h"
17 
18 char *my_env[] = {0, NULL};
19 
20 /**
21  * @tc.name      : execve_0100
22  * @tc.desc      : Each parameter is valid, and the specified file can be executed.
23  * @tc.level     : Level 0
24  */
execve_0100(void)25 void execve_0100(void)
26 {
27     pid_t fpid;
28     fpid = fork();
29     if (fpid == 0) {
30         char *argv[] = {"touch", "execvetest.txt", NULL};
31         execve("/bin/touch", argv, my_env);
32     }
33     sleep(1);
34     int isExist = access("execvetest.txt", F_OK);
35     EXPECT_EQ("execve_0100", isExist, 0);
36     remove("execvetest.txt");
37 }
38 
39 /**
40  * @tc.name      : execve_0200
41  * @tc.desc      : The content pointed to by the path parameter is empty, and the specified file cannot be executed.
42  * @tc.level     : Level 2
43  */
execve_0200(void)44 void execve_0200(void)
45 {
46     char *argv[] = {"touch", "execvetest.txt", NULL};
47     int ret = execve(" ", argv, my_env);
48     EXPECT_EQ("execve_0200", ret, -1);
49 }
50 
51 /**
52  * @tc.name      : execve_0300
53  * @tc.desc      : The length of path exceeds NAME_MAX, and the specified file cannot be executed.
54  * @tc.level     : Level 2
55  */
execve_0300(void)56 void execve_0300(void)
57 {
58     char buff[300];
59     for (int i = 0; i < 300; i++) {
60         buff[i] = 'a';
61     }
62     char *argv[] = {"touch", "execvetest.txt", NULL};
63     int ret = execve(buff, argv, my_env);
64     EXPECT_EQ("execve_0300", ret, -1);
65 }
66 
main(int argc,char * argv[])67 int main(int argc, char *argv[])
68 {
69     execve_0100();
70     execve_0200();
71     execve_0300();
72     return t_status;
73 }