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 <errno.h>
17 #include <stdlib.h>
18 #include "functionalext.h"
19
20 #define TEST_MEMALIGN_ALIGN 16
21
22 /**
23 * @tc.name : posix_memalign_0100
24 * @tc.desc : Allocate memory blocks with 16-byte alignment
25 * @tc.level : Level 0
26 */
posix_memalign_0100(void)27 void posix_memalign_0100(void)
28 {
29 size_t block[] = {1, 4, 8, 256, 1024, 65000, 128000, 256000, 1000000};
30 int count = sizeof(block) / sizeof(size_t);
31 int i = 0;
32 for (i = 0; i < count; i++) {
33 void *memory = NULL;
34 int rev = posix_memalign(&memory, TEST_MEMALIGN_ALIGN, block[i]);
35 EXPECT_EQ("posix_memalign_0100", rev, 0);
36 EXPECT_TRUE("posix_memalign_0100", memory != NULL);
37 if (memory) {
38 free(memory);
39 }
40 }
41 }
42
43 /**
44 * @tc.name : posix_memalign_0200
45 * @tc.desc : Synchronize a file with a memory map
46 * @tc.level : Level 2
47 */
posix_memalign_0200(void)48 void posix_memalign_0200(void)
49 {
50 void *memory = NULL;
51 int rev = posix_memalign(&memory, 1, 1);
52 EXPECT_EQ("posix_memalign_0200", rev, EINVAL);
53 if (memory) {
54 free(memory);
55 }
56 }
57
main(void)58 int main(void)
59 {
60 posix_memalign_0100();
61 posix_memalign_0200();
62 return t_status;
63 }