2 * Copyright 2008, Google Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 * A simple test to exercise the DynArray class.
40 #include "native_client/service_runtime/dyn_array.h"
42 int ReadWriteTest(void)
44 static int test_data
[] = {
45 3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3, 8, 4, 6, 2, 6, 4, 3, 3, 8, 3, 2, 7, 9, 5, 0, 2, 8, 8, 4, 1, 9, 7, 1, 6, 9, 3, 9, 9, 3, 7, 5, 1, 0, 5, 8, 2, 0, 9, 7, 4, 9, 4, 4, 5, 9, 2, 3, 0, 7, 8, 1, 6, 4, 0, 6, 2, 8, 6, 2, 0, 8, 9, 9, 8, 6, 2, 8, 0, 3, 4, 8, 2, 5, 3, 4, 2, 1, 1, 7, 0, 6, 7, 6,
52 printf("\nReadWriteTest\n");
55 for (i
= 0; i
< sizeof test_data
/sizeof test_data
[0]; ++i
) {
56 if (!DynArraySet(&da
, i
, (void *) test_data
[i
])) {
57 printf("insert for position %d failed\n", i
);
62 for (i
= 0; i
< sizeof test_data
/sizeof test_data
[0]; ++i
) {
63 if ((int) DynArrayGet(&da
, i
) != test_data
[i
]) {
64 printf("check for value at position %d failed\n", i
);
71 DynArrayCtor(&da
, 10);
73 for (i
= sizeof test_data
/sizeof test_data
[0]; --i
>= 0; ) {
74 if (!DynArraySet(&da
, i
, (void *) test_data
[i
])) {
75 printf("insert for position %d failed\n", i
);
80 for (i
= sizeof test_data
/sizeof test_data
[0]; --i
>= 0; ) {
81 if ((int) DynArrayGet(&da
, i
) != test_data
[i
]) {
82 printf("check for value at position %d failed\n", i
);
89 printf(0 != nerrors
? "FAIL\n" : "OK\n");
100 { 1, (void *) 0xdeadbeef, 0 },
101 { 3, (void *) 0xdeadbeef, 0 },
102 { 0, (void *) 0xdeadbeef, 2 },
103 { 2, (void *) 0xdeadbeef, 4 },
104 { 1, (void *) 0, 1 },
105 { 1, (void *) 0xdeadbeef, 4 },
106 { 4, (void *) 0xdeadbeef, 5 },
107 { 5, (void *) 0xdeadbeef, 6 },
108 { 6, (void *) 0xdeadbeef, 7 },
109 { 8, (void *) 0xdeadbeef, 7 },
110 { 7, (void *) 0xdeadbeef, 9 },
111 { 9, (void *) 0xdeadbeef, 10 },
112 { 10, (void *) 0xdeadbeef, 11 },
113 { 11, (void *) 0xdeadbeef, 12 },
114 { 12, (void *) 0xdeadbeef, 13 },
115 { 13, (void *) 0xdeadbeef, 14 },
116 { 14, (void *) 0xdeadbeef, 15 },
117 { 15, (void *) 0xdeadbeef, 16 },
118 { 16, (void *) 0xdeadbeef, 17 },
119 { 17, (void *) 0xdeadbeef, 18 },
120 { 18, (void *) 0xdeadbeef, 19 },
121 { 19, (void *) 0xdeadbeef, 20 },
122 { 20, (void *) 0xdeadbeef, 21 },
123 { 21, (void *) 0xdeadbeef, 22 },
124 { 22, (void *) 0xdeadbeef, 23 },
125 { 23, (void *) 0xdeadbeef, 24 },
126 { 24, (void *) 0xdeadbeef, 25 },
127 { 25, (void *) 0xdeadbeef, 26 },
128 { 26, (void *) 0xdeadbeef, 27 },
129 { 27, (void *) 0xdeadbeef, 28 },
130 { 28, (void *) 0xdeadbeef, 29 },
131 { 29, (void *) 0xdeadbeef, 30 },
132 { 30, (void *) 0xdeadbeef, 31 },
133 { 32, (void *) 0xdeadbeef, 31 },
134 { 32, (void *) 0, 31 },
135 { 31, (void *) 0xdeadbeef, 32 },
136 { 32, (void *) 0xdeadbeef, 33 },
137 { 31, (void *) 0, 31 },
138 { 31, (void *) 0xdeadbeef, 33 },
139 { 34, (void *) 0xdeadbeef, 33 },
140 { 35, (void *) 0xdeadbeef, 33 },
141 { 36, (void *) 0xdeadbeef, 33 },
142 { 37, (void *) 0xdeadbeef, 33 },
143 { 38, (void *) 0xdeadbeef, 33 },
144 { 39, (void *) 0xdeadbeef, 33 },
145 { 40, (void *) 0xdeadbeef, 33 },
146 { 41, (void *) 0xdeadbeef, 33 },
147 { 42, (void *) 0xdeadbeef, 33 },
148 { 43, (void *) 0xdeadbeef, 33 },
149 { 44, (void *) 0xdeadbeef, 33 },
150 { 45, (void *) 0xdeadbeef, 33 },
151 { 46, (void *) 0xdeadbeef, 33 },
152 { 47, (void *) 0xdeadbeef, 33 },
153 { 48, (void *) 0xdeadbeef, 33 },
154 { 49, (void *) 0xdeadbeef, 33 },
155 { 50, (void *) 0xdeadbeef, 33 },
156 { 51, (void *) 0xdeadbeef, 33 },
157 { 52, (void *) 0xdeadbeef, 33 },
158 { 53, (void *) 0xdeadbeef, 33 },
159 { 54, (void *) 0xdeadbeef, 33 },
160 { 55, (void *) 0xdeadbeef, 33 },
161 { 56, (void *) 0xdeadbeef, 33 },
162 { 57, (void *) 0xdeadbeef, 33 },
163 { 58, (void *) 0xdeadbeef, 33 },
164 { 59, (void *) 0xdeadbeef, 33 },
165 { 60, (void *) 0xdeadbeef, 33 },
166 { 61, (void *) 0xdeadbeef, 33 },
167 { 62, (void *) 0xdeadbeef, 33 },
168 { 63, (void *) 0xdeadbeef, 33 },
169 { 64, (void *) 0xdeadbeef, 33 },
170 { 65, (void *) 0xdeadbeef, 33 },
171 { 66, (void *) 0xdeadbeef, 33 },
172 { 33, (void *) 0xdeadbeef, 67 },
173 { 31, (void *) 0, 31 },
174 { 32, (void *) 0, 31 },
175 { 63, (void *) 0, 31 },
176 { 31, (void *) 0xdeadbeef, 32 },
177 { 32, (void *) 0xdeadbeef, 63 },
178 { 63, (void *) 0xdeadbeef, 67 },
184 printf("\nFFS test\n");
185 DynArrayCtor(&da
, 32);
187 for (ix
= 0; ix
< sizeof test_data
/sizeof test_data
[0]; ++ix
) {
188 if (!DynArraySet(&da
, test_data
[ix
].pos
, test_data
[ix
].val
)) {
189 printf("setting at position %d to 0x%x, test_data entry %d faild\n",
190 test_data
[ix
].pos
, (uintptr_t) test_data
[ix
].val
, ix
);
193 if (DynArrayFirstAvail(&da
) != test_data
[ix
].expected
) {
194 printf("ix %d, first avail: expected %d, got %d\n",
196 test_data
[ix
].expected
,
197 DynArrayFirstAvail(&da
));
203 printf(0 != nerrors
? "FAIL\n" : "OK\n");
211 nerrors
= ReadWriteTest();
212 nerrors
+= FfsTest();