6690 set_nfsv4_ephemeral_mount_to() tries to read AUTOMOUNT_TIMEOUT from defunct...
[unleashed.git] / usr / src / test / libc-tests / tests / aligned_alloc.c
blobbbff168ef35182eed66246d9cc70684a964ac66d
1 /*
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
5 * 1.0 of the CDDL.
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.
24 #include <stdlib.h>
25 #include <errno.h>
26 #include <libproc.h>
27 #include <sys/sysmacros.h>
28 #include <sys/mman.h>
29 #include <sys/debug.h>
31 int
32 main(void)
34 pstatus_t status;
35 void *buf;
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);
52 free(buf);
55 * Cause ENOMEM
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),
61 !=, (void *)-1);
63 for (;;) {
64 if (malloc(16) == NULL)
65 break;
68 for (;;) {
69 if (aligned_alloc(sizeof (void *), 16) == NULL)
70 break;
73 VERIFY3P(aligned_alloc(sizeof (void *), 16), ==, NULL);
74 VERIFY3S(errno, ==, ENOMEM);
76 return (0);