2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
13 * Copyright 2016 Joyent, Inc.
17 * Basic tests for aligned_alloc(3C). Note that we test ENOMEM failure by
18 * relying on the implementation of the current libc malloc. Specifically we go
19 * through and add a mapping so we can't expand the heap and then use it up. If
20 * the memory allocator is ever changed, this test will start failing, at which
21 * point, it may not be worth the cost of keeping it around.
27 #include <sys/sysmacros.h>
29 #include <sys/debug.h>
38 * Alignment must be sizeof (void *) (word) aligned.
40 VERIFY3P(aligned_alloc(sizeof (void *) - 1, 16), ==, NULL
);
41 VERIFY3S(errno
, ==, EINVAL
);
43 VERIFY3P(aligned_alloc(sizeof (void *) + 1, 16), ==, NULL
);
44 VERIFY3S(errno
, ==, EINVAL
);
47 VERIFY3P(aligned_alloc(23, 16), ==, NULL
);
48 VERIFY3S(errno
, ==, EINVAL
);
50 buf
= aligned_alloc(sizeof (void *), 16);
51 VERIFY3P(buf
, !=, NULL
);
57 VERIFY0(proc_get_status(getpid(), &status
));
58 VERIFY3P(mmap((caddr_t
)P2ROUNDUP(status
.pr_brkbase
+
59 status
.pr_brksize
, 0x1000), 0x1000,
60 PROT_READ
, MAP_ANON
| MAP_FIXED
| MAP_PRIVATE
, -1, 0),
64 if (malloc(16) == NULL
)
69 if (aligned_alloc(sizeof (void *), 16) == NULL
)
73 VERIFY3P(aligned_alloc(sizeof (void *), 16), ==, NULL
);
74 VERIFY3S(errno
, ==, ENOMEM
);