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 <stdlib.h>
17 #include <sys/mman.h>
18 #include "functionalext.h"
19
20 /**
21 * @tc.name : memfd_create_0100
22 * @tc.desc : Process memfd_create success.
23 * @tc.level : Level 0
24 */
memfd_create_0100(void)25 void memfd_create_0100(void)
26 {
27 char tmpfile[] = "/data/memfd_create_0100.txt";
28 int fd = memfd_create(tmpfile, 0);
29 EXPECT_TRUE("memfd_create_0100", fd != -1);
30 if (fd != -1) {
31 int cnt = write(fd, tmpfile, strlen(tmpfile));
32 EXPECT_TRUE("memfd_create_0100", cnt == strlen(tmpfile));
33 close(fd);
34 }
35 }
36
37 /**
38 * @tc.name: memfd_create_0200
39 * @tc.desc: Process memfd_create fail. because param is error.
40 * @tc.level: Level 2
41 */
memfd_create_0200(void)42 void memfd_create_0200(void)
43 {
44 char tmpfile[] = "/data/memfd_create_0200.txt";
45 int fd = memfd_create(tmpfile, -1);
46 EXPECT_TRUE("memfd_create_0200", fd == -1);
47 if (fd != -1) {
48 int cnt = write(fd, tmpfile, strlen(tmpfile));
49 EXPECT_TRUE("memfd_create_0200", cnt == strlen(tmpfile));
50 close(fd);
51 }
52 }
53
main(void)54 int main(void)
55 {
56 memfd_create_0100();
57 memfd_create_0200();
58 return t_status;
59 }