• 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 /**
19  * @tc.name      : execv_0100
20  * @tc.desc      : Each parameter is valid, and the specified file can be executed.
21  * @tc.level     : Level 0
22  */
execv_0100(void)23 void execv_0100(void)
24 {
25     pid_t fpid;
26     fpid = fork();
27     FILE *fp;
28     if (fpid == 0) {
29         char *argv[] = {"touch", "touch", "execvtest.txt", NULL};
30         int ret = execv("/bin/touch", argv);
31         EXPECT_NE("execv_0100", ret, -1);
32     }
33     sleep(1);
34     int isExist = access("execvtest.txt", F_OK);
35     EXPECT_EQ("execv_0100", isExist, 0);
36     remove("execvtest.txt");
37 }
38 
39 /**
40  * @tc.name      : execv_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  */
execv_0200(void)44 void execv_0200(void)
45 {
46     char *argv[] = {"touch", "touch", "execvtest.txt", NULL};
47     int ret = execv(" ", argv);
48     EXPECT_TRUE("execv_0200", ret == -1);
49 }
50 
51 /**
52  * @tc.name      : execv_0300
53  * @tc.desc      : The length of path exceeds NAME_MAX, and the specified file cannot be executed.
54  * @tc.level     : Level 2
55  */
execv_0300(void)56 void execv_0300(void)
57 {
58     char buff[300];
59     for (int i = 0; i < 300; i++) {
60         buff[i] = 'a';
61     }
62     char *argv[] = {"touch", "touch", "execvtest.txt", NULL};
63     int ret = execv(buff, argv);
64     EXPECT_TRUE("execv_0300", ret == -1);
65 }
66 
main(int argc,char * argv[])67 int main(int argc, char *argv[])
68 {
69     execv_0100();
70     execv_0200();
71     execv_0300();
72     return t_status;
73 }