Validator: print message for unsafe indirects
[nativeclient.git] / ncv / ncdecode_tests.c
blobce95a5015529f6fa1f12bdc4a262b181fd3deb1c
1 /*
2 * Copyright 2008, Google Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
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
14 * distribution.
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
35 #include <stdio.h>
36 #include "native_client/ncv/ncdecode.h"
38 struct NCDecodeTestCase {
39 char *description;
40 size_t testsize;
41 uint8_t *testbytes;
44 struct NCDecodeTestCase NCDecoderTests[] = {
46 "test 1",
47 25,
48 (uint8_t *)"\x55"
49 "\x89\xe5"
50 "\x83\xec\x08"
51 "\xe8\x81\x00\x00\x00"
52 "\xe8\xd3\x00\x00\x00"
53 "\xe8\xf3\x04\x00\x00"
54 "\xc9"
55 "\xc3"
56 "\x00\x00",
59 "test2",
60 342,
61 (uint8_t *)"\x8d\x4c\x24\x04"
62 "\x83\xe4\xf0"
63 "\xff\x71\xfc"
64 "\x55"
65 "\x89\xe5"
66 "\x51"
67 "\x66\x90"
68 "\x83\xec\x24"
69 "\x89\x4d\xe8"
70 "\xc7\x45\xf4\x0a\x00\x00\x00"
71 "\x8b\x45\xe8"
72 "\x83\x38\x01"
73 "\x7f\x2b"
74 "\x8b\x55\xe8"
75 "\x8b\x42\x04"
76 "\x8b\x00"
77 "\x8d\x76\x00"
78 "\x89\x44\x24\x04"
79 "\xc7\x04\x24\x54\x14\x00\x08"
80 "\xe8\xc0\x02\x00\x00"
81 "\xc7\x04\x24\x01\x00\x00\x00"
82 "\x8d\x74\x26\x00"
83 "\xe8\xc0\x01\x00\x00"
84 "\x8b\x55\xe8"
85 "\x8b\x42\x04"
86 "\x83\xc0\x04"
87 "\x8b\x00"
88 "\x89\x04\x24"
89 "\x66\x90"
90 "\x8d\x74\x26\x00"
91 "\x8d\xbc\x27\x00\x00\x00\x00"
92 "\xe8\x90\x09\x00\x00"
93 "\x89\x45\xf8"
94 "\x8b\x45\xe8"
95 "\x83\x38\x02"
96 "\x7e\x25"
97 "\x8b\x55\xe8"
98 "\x66\x90"
99 "\x8b\x42\x04"
100 "\x83\xc0\x08"
101 "\x8b\x00"
102 "\x89\x04\x24"
103 "\xe8\x70\x09\x00\x00"
104 "\x89\x45\xf4"
105 "\x8d\xb6\x00\x00\x00\x00"
106 "\x8d\xbc\x27\x00\x00\x00\x00"
107 "\x8b\x45\xf4"
108 "\xa3\x28\x2f\x00\x08"
109 "\xeb\x26"
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, "
113 "\x8b\x45\xf4"
114 "\x89\x04\x24"
115 "\x90"
116 "\x8d\x74\x26\x00"
117 "\xe8\x20\x00\x00\x00"
118 "\x83\x7d\xf8\x00"
119 "\x0f\x9f\xc0"
120 "\x83\x6d\xf8\x01"
121 "\x84\xc0"
122 "\x8d\x76\x00"
123 "\x75\xce"
124 "\xc7\x04\x24\x00\x00\x00\x00"
125 "\x66\x90"
126 "\xe8\x20\x01\x00\x00"
127 "\x55"
128 "\x89\xe5"
129 "\x83\xec\x1c"
130 "\x83\x7d\x08\x01"
131 "\x75\x44"
132 "\x8b\x55\x0c"
133 "\x90"
134 "\x8b\x04\x95\x24\x2f\x00\x08"
135 "\x83\xe8\x01"
136 "\x8d\xb6\x00\x00\x00\x00"
137 "\x89\x04\x95\x24\x2f\x00\x08"
138 "\x8b\x55\x10"
139 "\x8d\xb6\x00\x00\x00\x00"
140 "\x8b\x04\x95\x24\x2f\x00\x08"
141 "\x83\xc0\x01"
142 "\x8d\xb6\x00\x00\x00\x00"
143 "\x89\x04\x95\x24\x2f\x00\x08"
144 "\xeb\x77"
145 "\x8d\xb4\x26\x00\x00\x00\x00"
146 "\x8b\x45\x10"
147 "\x8b\x55\x0c"
148 "\x01\xc2"
149 "\xb8\x06\x00\x00\x00"
150 "\x29\xd0"
151 "\x90"
154 "test 3",
156 (uint8_t *)"\x3c\x25"
157 "\x90\x90\x90\x90\x90\x90\x90"
159 { "test4",
161 (uint8_t *)"\xc1\xf9\x1f\x89\x4d\xe4"
162 "\x90\x90\x90\x90\x90\x90\x90"
165 "test5",
167 (uint8_t *)"\xc6\x44\x05\xd6\x00"
168 "\x90\x90\x90\x90\x90\x90\x90"
171 "test6",
173 (uint8_t *)"\xff\x24\x95\xc8\x6e\x05\x08"
174 "\x90\x90\x90\x90\x90\x90\x90"
177 "test7",
179 (uint8_t *)"\x0f\xab\x14\x85\x40\xfb\x27\x08"
180 "\x90\x90\x90\x90\x90\x90\x90"
183 "test8",
185 (uint8_t *)"\x66\xbf\x08\x00"
186 "\x90\x90\x90\x90\x90\x90\x90"
189 "test9",
191 (uint8_t *)"\x66\x0f\xbe\x04\x10"
192 "\x90\x90\x90\x90\x90\x90\x90"
194 /* ldmxcsr, stmxcsr */
196 "test10",
198 (uint8_t *)"\x90\x0f\xae\x10\x90\x0f\xae\x18"
199 "\x90\x90\x90\x90\x90\x90\x90"
201 /* invalid */
203 "test11",
205 (uint8_t *)"\x90\x0f\xae\x21"
206 "\x90\x90\x90\x90\x90\x90\x90"
208 /* lfence */
210 "test12",
212 (uint8_t *)"\x90\x0f\xae\x28"
213 "\x90\x90\x90\x90\x90\x90\x90"
216 "test13",
218 (uint8_t *)"\xf0\x0f\xb1\x8f\xa8\x01\x00\x00"
219 "\x90"
222 "test14",
224 (uint8_t *)"\x84\xd4\x04\x53\xa0\x04\x6a\x5a\x20\xcc\xb8\x48\x03"
225 "\x2b\x96\x11\xf4"
228 "test15",
230 (uint8_t *)"\xb0\xb9\xd8\x3d\x60\xe4\x2c\x15\x43\x61\x4e\x03\x39"
231 "\xfc\x79\x4b\xf4"
234 "test16",
236 (uint8_t *)"\x66\x66\x66\x66\x0f\x1f\x0d\x1a\xed\x25\x37\x27\x0a"
237 "\xff\xc6\x1a\xf4"
240 "test17",
242 (uint8_t *)"\x66\xeb\x1b\x31\x51\x3d\xef\xcc\x2f\x36\x48\x6e\x44"
243 "\x2e\xcc\x14\x00\xf4"
246 "test18",
248 (uint8_t *)"\x67\x8d\x1d\x22\xa0\x05\xe3\x7b\x9c\xdb\x08\x04\xb1"
249 "\x90\xed\x12\xf4"
252 "test 19",
254 (uint8_t *)"\x45\x7f\x89\x58\x94\x04\x24\x1b\xc3\xe2\x6f\x1a\x94\x87\x8f\x0b\x00\x00\x90\xf4",
257 "test 20",
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"
267 "test 22: SSSE3",
269 (uint8_t *)"\x66\x0f\x38\x00\x00\x00\x90\xf4"
272 "test 23: 3DNow",
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"
282 "test 25: lzcnt",
284 (uint8_t *)"\xf3\x0f\xbd\x00\x90\xf4",
287 "test 26: 3dnow",
289 (uint8_t *)"\x0f\x0f\x01\x0c\x90\xf4",
292 "test 27: addr16 variants",
294 (uint8_t *)"\x67\x01\x00"
295 "\x67\x01\x40\x00"
296 "\x67\x01\x80\x00\x90"
297 "\x67\x01\xc0"
298 "\x90\xf4",
301 "test 28: lock cmpxchg8b",
303 (uint8_t *)"\xf0\x0f\xc7\010\x90\xf4"
306 "test 29: SSE3",
308 (uint8_t *)"\x66\x0f\x7d\x00\x90\x90\x90\xf4"
311 "test 30: MMXSSE2",
313 (uint8_t *)"\x66\x0f\x71\xf6\x00\x90\x90\x90\x90\xf4",
316 "test 31: call %esp",
318 /* 11 100 000 */
319 (uint8_t *)"\x83\xe4\xf0\xff\xd4\x90\xf4",
324 #define sizeofA(array) (sizeof(array)/sizeof(array[0]))
325 void ncdecode_unittests() {
326 size_t i;
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,
334 NULL);