Sat Nov 7 17:35:31 2015 UTC ()
Fix code style errors pointed out by christos during the review of the
aligned_alloc test that also applies to the posix_memalign test.
Fix code style errors that I forgot to fix in the aligned_alloc test.


(nros)
diff -r1.3 -r1.4 src/tests/lib/libc/stdlib/t_posix_memalign.c

cvs diff -r1.3 -r1.4 src/tests/lib/libc/stdlib/t_posix_memalign.c (expand / switch to unified diff)

--- src/tests/lib/libc/stdlib/t_posix_memalign.c 2015/11/07 16:21:42 1.3
+++ src/tests/lib/libc/stdlib/t_posix_memalign.c 2015/11/07 17:35:31 1.4
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: t_posix_memalign.c,v 1.3 2015/11/07 16:21:42 nros Exp $ */ 1/* $NetBSD: t_posix_memalign.c,v 1.4 2015/11/07 17:35:31 nros Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2008 The NetBSD Foundation, Inc. 4 * Copyright (c) 2008 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Christos Zoulas. 8 * by Christos Zoulas.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -22,59 +22,59 @@ @@ -22,59 +22,59 @@
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33__COPYRIGHT("@(#) Copyright (c) 2008\ 33__COPYRIGHT("@(#) Copyright (c) 2008\
34 The NetBSD Foundation, inc. All rights reserved."); 34 The NetBSD Foundation, inc. All rights reserved.");
35__RCSID("$NetBSD: t_posix_memalign.c,v 1.3 2015/11/07 16:21:42 nros Exp $"); 35__RCSID("$NetBSD: t_posix_memalign.c,v 1.4 2015/11/07 17:35:31 nros Exp $");
36 36
37#include <atf-c.h> 37#include <atf-c.h>
38 38
39#include <errno.h> 39#include <errno.h>
40#include <stdbool.h> 40#include <stdbool.h>
41#include <stdint.h> 41#include <stdint.h>
42#include <stdio.h> 42#include <stdio.h>
43#include <stdlib.h> 43#include <stdlib.h>
44#include <string.h> 44#include <string.h>
45 45
46ATF_TC(posix_memalign_basic); 46ATF_TC(posix_memalign_basic);
47ATF_TC_HEAD(posix_memalign_basic, tc) 47ATF_TC_HEAD(posix_memalign_basic, tc)
48{ 48{
49 atf_tc_set_md_var(tc, "descr", "Checks posix_memalign(3)"); 49 atf_tc_set_md_var(tc, "descr", "Checks posix_memalign(3)");
50} 50}
51ATF_TC_BODY(posix_memalign_basic, tc) 51ATF_TC_BODY(posix_memalign_basic, tc)
52{ 52{
53 size_t size[] = { 53 static const size_t size[] = {
54 1, 2, 3, 4, 10, 100, 16384, 32768, 65536 54 1, 2, 3, 4, 10, 100, 16384, 32768, 65536
55 }; 55 };
56 size_t align[] = { 56 static const size_t align[] = {
57 512, 1024, 16, 32, 64, 4, 2048, 16, 2 57 512, 1024, 16, 32, 64, 4, 2048, 16, 2
58 }; 58 };
59 59
60 size_t i; 60 size_t i;
61 void *p; 61 void *p;
62 62
63 for (i = 0; i < __arraycount(size); i++) { 63 for (i = 0; i < __arraycount(size); i++) {
64 int ret; 64 int ret;
65 p = (void*)0x1; 65 p = (void*)0x1;
66 66
67 (void)printf("Checking posix_memalign(&p, %zd, %zd)...\n", 67 (void)printf("Checking posix_memalign(&p, %zu, %zu)...\n",
68 align[i], size[i]); 68 align[i], size[i]);
69 ret = posix_memalign(&p, align[i], size[i]); 69 ret = posix_memalign(&p, align[i], size[i]);
70 70
71 if ( align[i] < sizeof(void *)) 71 if ( align[i] < sizeof(void *))
72 ATF_REQUIRE_EQ_MSG(ret, EINVAL, 72 ATF_REQUIRE_EQ_MSG(ret, EINVAL,
73 "posix_memalign: %s", strerror(ret)); 73 "posix_memalign: %s", strerror(ret));
74 else { 74 else {
75 ATF_REQUIRE_EQ_MSG(ret, 0, 75 ATF_REQUIRE_EQ_MSG(ret, 0,
76 "posix_memalign: %s", strerror(ret)); 76 "posix_memalign: %s", strerror(ret));
77 ATF_REQUIRE_EQ_MSG(((intptr_t)p) & (align[i] - 1), 0, 77 ATF_REQUIRE_EQ_MSG(((intptr_t)p) & (align[i] - 1), 0,
78 "p = %p", p); 78 "p = %p", p);
79 free(p); 79 free(p);
80 } 80 }
@@ -94,41 +94,41 @@ ATF_TC_BODY(aligned_alloc_basic, tc) @@ -94,41 +94,41 @@ ATF_TC_BODY(aligned_alloc_basic, tc)
94 }; 94 };
95 static const size_t align[] = { 95 static const size_t align[] = {
96 512, 1024, 16, 32, 64, 4, 2048, 16, 2, 2048, 0 96 512, 1024, 16, 32, 64, 4, 2048, 16, 2, 2048, 0
97 }; 97 };
98 98
99 size_t i; 99 size_t i;
100 void *p; 100 void *p;
101 101
102 for (i = 0; i < __arraycount(size); i++) { 102 for (i = 0; i < __arraycount(size); i++) {
103 (void)printf("Checking aligned_alloc(%zu, %zu)...\n", 103 (void)printf("Checking aligned_alloc(%zu, %zu)...\n",
104 align[i], size[i]); 104 align[i], size[i]);
105 p = aligned_alloc(align[i], size[i]); 105 p = aligned_alloc(align[i], size[i]);
106 if (p == NULL) { 106 if (p == NULL) {
107 if (align[i] == 0 || ((align[i]-1) & align[i]) != 0 || 107 if (align[i] == 0 || ((align[i] - 1) & align[i]) != 0 ||
108 size[i] % align[i] != 0) { 108 size[i] % align[i] != 0) {
109 ATF_REQUIRE_EQ_MSG(errno, EINVAL, 109 ATF_REQUIRE_EQ_MSG(errno, EINVAL,
110 "aligned_alloc: %s", strerror(errno)); 110 "aligned_alloc: %s", strerror(errno));
111 } 111 }
112 else { 112 else {
113 ATF_REQUIRE_EQ_MSG(errno, ENOMEM, 113 ATF_REQUIRE_EQ_MSG(errno, ENOMEM,
114 "aligned_alloc: %s", strerror(errno)); 114 "aligned_alloc: %s", strerror(errno));
115 } 115 }
116 } 116 }
117 else { 117 else {
118 ATF_REQUIRE_EQ_MSG(align[i] == 0, false, 118 ATF_REQUIRE_EQ_MSG(align[i] == 0, false,
119 "aligned_alloc: success when alignment was not " 119 "aligned_alloc: success when alignment was not "
120 "a power of 2"); 120 "a power of 2");
121 ATF_REQUIRE_EQ_MSG((align[i]-1) & align[i], 0, 121 ATF_REQUIRE_EQ_MSG((align[i] - 1) & align[i], 0,
122 "aligned_alloc: success when alignment was not " 122 "aligned_alloc: success when alignment was not "
123 "a power of 2"); 123 "a power of 2");
124 ATF_REQUIRE_EQ_MSG(size[i] % align[i], 0, 124 ATF_REQUIRE_EQ_MSG(size[i] % align[i], 0,
125 "aligned_alloc: success when size was not an " 125 "aligned_alloc: success when size was not an "
126 "integer multiple of alignment"); 126 "integer multiple of alignment");
127 ATF_REQUIRE_EQ_MSG(((intptr_t)p) & (align[i] - 1), 0, 127 ATF_REQUIRE_EQ_MSG(((intptr_t)p) & (align[i] - 1), 0,
128 "p = %p", p); 128 "p = %p", p);
129 free(p); 129 free(p);
130 } 130 }
131 } 131 }
132} 132}
133 133
134 134