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.
33 * ncdecode_tests.c - simple unit tests for NaCl decoder
36 #include "native_client/ncv/ncdecode.h"
38 struct NCDecodeTestCase
{
44 struct NCDecodeTestCase NCDecoderTests
[] = {
51 "\xe8\x81\x00\x00\x00"
52 "\xe8\xd3\x00\x00\x00"
53 "\xe8\xf3\x04\x00\x00"
61 (uint8_t *)"\x8d\x4c\x24\x04"
70 "\xc7\x45\xf4\x0a\x00\x00\x00"
79 "\xc7\x04\x24\x54\x14\x00\x08"
80 "\xe8\xc0\x02\x00\x00"
81 "\xc7\x04\x24\x01\x00\x00\x00"
83 "\xe8\xc0\x01\x00\x00"
91 "\x8d\xbc\x27\x00\x00\x00\x00"
92 "\xe8\x90\x09\x00\x00"
103 "\xe8\x70\x09\x00\x00"
105 "\x8d\xb6\x00\x00\x00\x00"
106 "\x8d\xbc\x27\x00\x00\x00\x00"
108 "\xa3\x28\x2f\x00\x08"
110 "\x8d\xb6\x00\x00\x00\x00"
111 "\xc7\x44\x24\x08\x03\x00\x00\x00, "
112 "\xc7\x44\x24\x04\x01\x00\x00\x00, "
117 "\xe8\x20\x00\x00\x00"
124 "\xc7\x04\x24\x00\x00\x00\x00"
126 "\xe8\x20\x01\x00\x00"
134 "\x8b\x04\x95\x24\x2f\x00\x08"
136 "\x8d\xb6\x00\x00\x00\x00"
137 "\x89\x04\x95\x24\x2f\x00\x08"
139 "\x8d\xb6\x00\x00\x00\x00"
140 "\x8b\x04\x95\x24\x2f\x00\x08"
142 "\x8d\xb6\x00\x00\x00\x00"
143 "\x89\x04\x95\x24\x2f\x00\x08"
145 "\x8d\xb4\x26\x00\x00\x00\x00"
149 "\xb8\x06\x00\x00\x00"
156 (uint8_t *)"\x3c\x25"
157 "\x90\x90\x90\x90\x90\x90\x90"
161 (uint8_t *)"\xc1\xf9\x1f\x89\x4d\xe4"
162 "\x90\x90\x90\x90\x90\x90\x90"
167 (uint8_t *)"\xc6\x44\x05\xd6\x00"
168 "\x90\x90\x90\x90\x90\x90\x90"
173 (uint8_t *)"\xff\x24\x95\xc8\x6e\x05\x08"
174 "\x90\x90\x90\x90\x90\x90\x90"
179 (uint8_t *)"\x0f\xab\x14\x85\x40\xfb\x27\x08"
180 "\x90\x90\x90\x90\x90\x90\x90"
185 (uint8_t *)"\x66\xbf\x08\x00"
186 "\x90\x90\x90\x90\x90\x90\x90"
191 (uint8_t *)"\x66\x0f\xbe\x04\x10"
192 "\x90\x90\x90\x90\x90\x90\x90"
194 /* ldmxcsr, stmxcsr */
198 (uint8_t *)"\x90\x0f\xae\x10\x90\x0f\xae\x18"
199 "\x90\x90\x90\x90\x90\x90\x90"
205 (uint8_t *)"\x90\x0f\xae\x21"
206 "\x90\x90\x90\x90\x90\x90\x90"
212 (uint8_t *)"\x90\x0f\xae\x28"
213 "\x90\x90\x90\x90\x90\x90\x90"
218 (uint8_t *)"\xf0\x0f\xb1\x8f\xa8\x01\x00\x00"
224 (uint8_t *)"\x84\xd4\x04\x53\xa0\x04\x6a\x5a\x20\xcc\xb8\x48\x03"
230 (uint8_t *)"\xb0\xb9\xd8\x3d\x60\xe4\x2c\x15\x43\x61\x4e\x03\x39"
236 (uint8_t *)"\x66\x66\x66\x66\x0f\x1f\x0d\x1a\xed\x25\x37\x27\x0a"
242 (uint8_t *)"\x66\xeb\x1b\x31\x51\x3d\xef\xcc\x2f\x36\x48\x6e\x44"
243 "\x2e\xcc\x14\x00\xf4"
248 (uint8_t *)"\x67\x8d\x1d\x22\xa0\x05\xe3\x7b\x9c\xdb\x08\x04\xb1"
254 (uint8_t *)"\x45\x7f\x89\x58\x94\x04\x24\x1b\xc3\xe2\x6f\x1a\x94\x87\x8f\x0b\x00\x00\x90\xf4",
259 (uint8_t *)"\x66\x0f\x3a\x0e\xd0\xc0\x90\xf4"
262 "test 21: palignr (SSSE3)",
264 (uint8_t *)"\x66\x0f\x3a\x0f\xd0\xc0\x90\xf4"
269 (uint8_t *)"\x66\x0f\x38\x00\x00\x00\x90\xf4"
274 (uint8_t *)"\x0f\x0f\x46\x01\xbf\x90\xf4"
277 "test 24: SSSE3 error",
279 (uint8_t *)"\x66\x0f\x3a\x0e\xd0\xc0\x90\xf4"
284 (uint8_t *)"\xf3\x0f\xbd\x00\x90\xf4",
289 (uint8_t *)"\x0f\x0f\x01\x0c\x90\xf4",
292 "test 27: addr16 variants",
294 (uint8_t *)"\x67\x01\x00"
296 "\x67\x01\x80\x00\x90"
301 "test 28: lock cmpxchg8b",
303 (uint8_t *)"\xf0\x0f\xc7\010\x90\xf4"
308 (uint8_t *)"\x66\x0f\x7d\x00\x90\x90\x90\xf4"
313 (uint8_t *)"\x66\x0f\x71\xf6\x00\x90\x90\x90\x90\xf4",
316 "test 31: call %esp",
319 (uint8_t *)"\x83\xe4\xf0\xff\xd4\x90\xf4",
324 #define sizeofA(array) (sizeof(array)/sizeof(array[0]))
325 void ncdecode_unittests() {
328 for (i
= 0; i
< sizeofA(NCDecoderTests
); i
++) {
329 printf("==========================================================\n");
330 printf("%s\n", NCDecoderTests
[i
].description
);
331 NCDecodeSegment(NCDecoderTests
[i
].testbytes
,
332 (uint32_t)(NCDecoderTests
[i
].testbytes
),
333 NCDecoderTests
[i
].testsize
,