• 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 <sys/mman.h>
17 #include <spawn.h>
18 #include <sys/stat.h>
19 #include <fcntl.h>
20 #include "functionalext.h"
21 
22 /**
23  * @tc.name      : posix_spawnattr_setflags_0100
24  * @tc.desc      : set the flags of spawn attr(success)
25  * @tc.level     : Level 0
26  */
posix_spawnattr_setflags_0100(void)27 void posix_spawnattr_setflags_0100(void)
28 {
29     posix_spawnattr_t spawnattr;
30 
31     int ret = posix_spawnattr_init(&spawnattr);
32     ret = posix_spawnattr_setflags(&spawnattr, POSIX_SPAWN_RESETIDS);
33     EXPECT_EQ("posix_spawnattr_setflags_0100", ret, CMPFLAG);
34     ret = posix_spawnattr_setflags(&spawnattr, POSIX_SPAWN_SETPGROUP);
35     EXPECT_EQ("posix_spawnattr_setflags_0100", ret, CMPFLAG);
36     ret = posix_spawnattr_setflags(&spawnattr, POSIX_SPAWN_SETSIGDEF);
37     EXPECT_EQ("posix_spawnattr_setflags_0100", ret, CMPFLAG);
38     ret = posix_spawnattr_setflags(&spawnattr, POSIX_SPAWN_SETSIGMASK);
39     EXPECT_EQ("posix_spawnattr_setflags_0100", ret, CMPFLAG);
40     ret = posix_spawnattr_setflags(&spawnattr, POSIX_SPAWN_SETSCHEDPARAM);
41     EXPECT_EQ("posix_spawnattr_setflags_0100", ret, CMPFLAG);
42     ret = posix_spawnattr_setflags(&spawnattr, POSIX_SPAWN_SETSCHEDULER);
43     EXPECT_EQ("posix_spawnattr_setflags_0100", ret, CMPFLAG);
44     ret = posix_spawnattr_setflags(&spawnattr, POSIX_SPAWN_USEVFORK);
45     EXPECT_EQ("posix_spawnattr_setflags_0100", ret, CMPFLAG);
46     ret = posix_spawnattr_setflags(&spawnattr, POSIX_SPAWN_SETSID);
47     EXPECT_EQ("posix_spawnattr_setflags_0100", ret, CMPFLAG);
48 
49     ret = posix_spawnattr_setflags(&spawnattr, POSIX_SPAWN_SETSID | POSIX_SPAWN_RESETIDS | POSIX_SPAWN_SETPGROUP);
50     EXPECT_EQ("posix_spawnattr_setflags_0100", ret, CMPFLAG);
51 
52     posix_spawnattr_destroy(&spawnattr);
53 }
54 
55 /**
56  * @tc.name      : posix_spawnattr_setflags_0200
57  * @tc.desc      : set the flags of spawn attr(failed)
58  * @tc.level     : Level 2
59  */
posix_spawnattr_setflags_0200(void)60 void posix_spawnattr_setflags_0200(void)
61 {
62     posix_spawnattr_t spawnattr;
63     short overflow = 256;
64     int ret = posix_spawnattr_init(&spawnattr);
65     ret = posix_spawnattr_setflags(&spawnattr, overflow);
66     EXPECT_EQ("posix_spawnattr_setflags_0200", ret, EINVAL);
67 
68     posix_spawnattr_destroy(&spawnattr);
69 }
70 
main(void)71 int main(void)
72 {
73     posix_spawnattr_setflags_0100();
74     posix_spawnattr_setflags_0200();
75     return t_status;
76 }
77