Make ncval-annotate and ncval-stubout executable
[nativeclient.git] / ncv / ncval_tests.c
blob4baa53f39097c2aff1f901079f96f2b47770169c
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 * ncval_tests.c - simple unit tests for NaCl validator
35 #include "native_client/include/portability.h"
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <string.h>
39 #include "native_client/ncv/ncvalidate.h"
40 #include "native_client/ncv/ncvalidate_internaltypes.h"
42 struct NCValTestCase {
43 char *name;
44 char *description;
45 int sawfailure;
46 uint32_t instructions;
47 uint32_t illegalinst;
48 int testsize;
49 uint32_t vaddr;
50 uint8_t *testbytes;
53 struct NCValTestCase NCValTests[] = {
55 "test 1",
56 "a first very simple test with an illegal inst.",
57 1, 9, 1, 26, 0x80000000,
58 (uint8_t *)"\x55"
59 "\x89\xe5"
60 "\x83\xec\x08"
61 "\xe8\x81\x00\x00\x00"
62 "\xe8\xd3\x00\x00\x00"
63 "\xe8\xf3\x04\x00\x00"
64 "\xc9"
65 "\xc3"
66 "\x00\x00\xf4",
69 "test 2",
70 "like test 1 but no illegal inst",
71 1, 9, 0, 26, 0x80000000,
72 (uint8_t *)"\x55"
73 "\x89\xe5"
74 "\x83\xec\x08"
75 "\xe8\x81\x00\x00\x00"
76 "\xe8\xd3\x00\x00\x00"
77 "\xe8\xf3\x04\x00\x00"
78 "\xc9"
79 "\x90"
80 "\x00\x00\xf4",
83 "test 3",
84 "like test 1 but no illegal inst, with bad alignment",
85 1, 9, 0, 26, 0x80000001,
86 (uint8_t *)"\x55"
87 "\x89\xe5"
88 "\x83\xec\x08"
89 "\xe8\x81\x00\x00\x00"
90 "\xe8\xd3\x00\x00\x00"
91 "\xe8\xf3\x04\x00\x00"
92 "\xc9"
93 "\x90"
94 "\x00\x00\xf4",
97 "test 4",
98 "a longer simple test with a bad jump target",
99 1, 90, 0, 336, 0x8054600,
100 (uint8_t *)"\x8d\x4c\x24\x04"
101 "\x83\xe4\xf0"
102 "\xff\x71\xfc"
103 "\x55"
104 "\x89\xe5"
105 "\x51"
106 "\x66\x90"
107 "\x83\xec\x24"
108 "\x89\x4d\xe8"
109 "\xc7\x45\xf4\x0a\x00\x00\x00"
110 "\x8b\x45\xe8"
111 "\x83\x38\x01"
112 "\x7f\x2b"
113 "\x8b\x55\xe8"
114 "\x8b\x42\x04"
115 "\x8b\x00"
116 "\x8d\x76\x00"
117 "\x89\x44\x24\x04"
118 "\xc7\x04\x24\x54\x14\x00\x08"
119 "\xe8\xc0\x02\x00\x00"
120 "\xc7\x04\x24\x01\x00\x00\x00"
121 "\x8d\x74\x26\x00"
122 "\xe8\xc0\x01\x00\x00"
123 "\x8b\x55\xe8"
124 "\x8b\x42\x04"
125 "\x83\xc0\x04"
126 "\x8b\x00"
127 "\x89\x04\x24"
128 "\x66\x90"
129 "\x8d\x74\x26\x00"
130 "\x8d\xbc\x27\x00\x00\x00\x00"
131 "\xe8\x90\x09\x00\x00"
132 "\x89\x45\xf8"
133 "\x8b\x45\xe8"
134 "\x83\x38\x02"
135 "\x7e\x25"
136 "\x8b\x55\xe8"
137 "\x66\x90"
138 "\x8b\x42\x04"
139 "\x83\xc0\x08"
140 "\x8b\x00"
141 "\x89\x04\x24"
142 "\xe8\x70\x09\x00\x00"
143 "\x89\x45\xf4"
144 "\x8d\xb6\x00\x00\x00\x00"
145 "\x8d\xbc\x27\x00\x00\x00\x00"
146 "\x8b\x45\xf4"
147 "\xa3\x28\x2f\x00\x08"
148 "\xeb\x26"
149 "\x8d\xb6\x00\x00\x00\x00"
150 "\xc7\x44\x24\x08\x03\x00\x00\x00"
151 "\xc7\x44\x24\x04\x01\x00\x00\x00"
152 "\x8b\x45\xf4"
153 "\x89\x04\x24"
154 "\x90"
155 "\x8d\x74\x26\x00"
156 "\xe8\x20\x00\x00\x00"
157 "\x83\x7d\xf8\x00"
158 "\x0f\x9f\xc0"
159 "\x83\x6d\xf8\x01"
160 "\x84\xc0"
161 "\x8d\x76\x00"
162 "\x75\xce"
163 "\xc7\x04\x24\x00\x00\x00\x00"
164 "\x66\x90"
165 "\xe8\x20\x01\x00\x00"
166 "\x55"
167 "\x89\xe5"
168 "\x83\xec\x1c"
169 "\x83\x7d\x08\x01"
170 "\x75\x44"
171 "\x8b\x55\x0c"
172 "\x90"
173 "\x8b\x04\x95\x24\x2f\x00\x08"
174 "\x83\xe8\x01"
175 "\x8d\xb6\x00\x00\x00\x00"
176 "\x89\x04\x95\x24\x2f\x00\x08"
177 "\x8b\x55\x10"
178 "\x8d\xb6\x00\x00\x00\x00"
179 "\x8b\x04\x95\x24\x2f\x00\x08"
180 "\x83\xc0\x01"
181 "\x8d\xb6\x00\x00\x00\x00"
182 "\x89\x04\x95\x24\x2f\x00\x08"
183 "\xeb\x77"
184 "\x8d\xb4\x26\x00\x00\x00\x00"
185 "\x8b\x45\x10"
186 "\x8b\x55\x0c"
187 "\x01\xc2"
188 "\xb8\x06\x00\x00\x00"
189 "\x29\xd0"
190 "\x90"
193 "test 5",
194 "like test 4; with bad jump target",
195 1, 90, 0, 336, 0x8054600,
196 (uint8_t *)"\x8d\x4c\x24\x04"
197 "\x83\xe4\xf0"
198 "\xff\x71\xfc"
199 "\x55"
200 "\x89\xe5"
201 "\x51"
202 "\x66\x90"
203 "\x83\xec\x24"
204 "\x89\x4d\xe8"
205 "\xc7\x45\xf4\x0a\x00\x00\x00"
206 "\x8b\x45\xe8"
207 "\x83\x38\x01"
208 "\x7f\x2b"
209 "\x8b\x55\xe8"
210 "\x8b\x42\x04"
211 "\x8b\x00"
212 "\x8d\x76\x00"
213 "\x89\x44\x24\x04"
214 "\xc7\x04\x24\x54\x14\x00\x08"
215 "\xe8\xc0\x02\x00\x00"
216 "\xc7\x04\x24\x01\x00\x00\x00"
217 "\x8d\x74\x26\x00"
218 "\xe8\xc0\x01\x00\x00"
219 "\x8b\x55\xe8"
220 "\x8b\x42\x04"
221 "\x83\xc0\x04"
222 "\x8b\x00"
223 "\x89\x04\x24"
224 "\x66\x90"
225 "\x8d\x74\x26\x00"
226 "\x8d\xbc\x27\x00\x00\x00\x00"
227 "\xe8\x90\x09\x00\x00"
228 "\x89\x45\xf8"
229 "\x8b\x45\xe8"
230 "\x83\x38\x02"
231 "\x7e\x25"
232 "\x8b\x55\xe8"
233 "\x66\x90"
234 "\x8b\x42\x04"
235 "\x83\xc0\x08"
236 "\x8b\x00"
237 "\x89\x04\x24"
238 "\xe8\x70\x09\x00\x00"
239 "\x89\x45\xf4"
240 "\x8d\xb6\x00\x00\x00\x00"
241 "\x8d\xbc\x27\x00\x00\x00\x00"
242 "\x8b\x45\xf4"
243 "\xa3\x28\x2f\x00\x08"
244 "\xeb\x26"
245 "\x8d\xb6\x00\x00\x00\x00"
246 "\xc7\x44\x24\x08\x03\x00\x00\x00"
247 "\xc7\x44\x24\x04\x01\x00\x00\x00"
248 "\x8b\x45\xf4"
249 "\x89\x04\x24"
250 "\x90"
251 "\x8d\x74\x26\x00"
252 "\xe8\x20\x00\x00\x00"
253 "\x83\x7d\xf8\x00"
254 "\x0f\x9f\xc0"
255 "\x83\x6d\xf8\x01"
256 "\x84\xc0"
257 "\x8d\x76\x00"
258 "\x75\xce"
259 "\xc7\x04\x24\x00\x00\x00\x00"
260 "\x66\x90"
261 "\xe8\x20\x01\x00\x00"
262 "\x55"
263 "\x89\xe5"
264 "\x83\xec\x1c"
265 "\x83\x7d\x08\x01"
266 "\x75\x44"
267 "\x8b\x55\x0c"
268 "\x90"
269 "\x8b\x04\x95\x24\x2f\x00\x08"
270 "\x83\xe8\x01"
271 "\x8d\xb6\x00\x00\x00\x00"
272 "\x89\x04\x95\x24\x2f\x00\x08"
273 "\x8b\x55\x10"
274 "\x8d\xb6\x00\x00\x00\x00"
275 "\x8b\x04\x95\x24\x2f\x00\x08"
276 "\x83\xc0\x01"
277 "\x8d\xb6\x00\x00\x00\x00"
278 "\x89\x04\x95\x24\x2f\x00\x08"
279 "\x00\x00"
280 "\x8d\xb4\x26\x00\x00\x00\x00"
281 "\x8b\x45\x10"
282 "\x8b\x55\x0c"
283 "\x01\xc2"
284 "\xb8\x06\x00\x00\x00"
285 "\x29\xd0"
286 "\xf4"
289 "test 6",
290 "test 6: 3c 25 cmp %al, $I",
291 0, 7, 0, 9, 0x80000000,
292 (uint8_t *)"\x3c\x25"
293 "\x90\x90\x90\x90\x90\x90\xf4"
296 "test 7",
297 "test 7: group2, three byte move",
298 0, 8, 0, 13, 0x80000000,
299 (uint8_t *)"\xc1\xf9\x1f\x89\x4d\xe4"
300 "\x90\x90\x90\x90\x90\x90\xf4"
303 "test 8",
304 "test 8: five byte move",
305 0, 7, 0, 12, 0x80000000,
306 (uint8_t *)"\xc6\x44\x05\xd6\x00"
307 "\x90\x90\x90\x90\x90\x90\xf4"
310 "test 9",
311 "test 9: seven byte control transfer, unprotected",
312 1, 7, 0, 14, 0x80000000,
313 (uint8_t *)"\xff\x24\x95\xc8\x6e\x05\x08"
314 "\x90\x90\x90\x90\x90\x90\xf4"
317 "test 10",
318 "test 10: eight byte bts instruction",
319 1, 7, 1, 15, 0x80000000,
320 (uint8_t *)"\x0f\xab\x14\x85\x40\xfb\x27\x08"
321 "\x90\x90\x90\x90\x90\x90\xf4",
324 "test 11",
325 "test 11: four byte move",
326 0, 7, 0, 11, 0x80000000,
327 (uint8_t *)"\x66\xbf\x08\x00"
328 "\x90\x90\x90\x90\x90\x90\xf4",
331 "test 12",
332 "test 12: five byte movsx",
333 0, 7, 0, 12, 0x80000000,
334 (uint8_t *)"\x66\x0f\xbe\x04\x10"
335 "\x90\x90\x90\x90\x90\x90\xf4"
338 "test 13",
339 "test 13: eight byte bts instruction, missing full stop",
340 1, 7, 1, 15, 0x80000000,
341 (uint8_t *)"\x0f\xab\x14\x85\x40\xfb\x27\x08"
342 "\x90\x90\x90\x90\x90\x90\x90",
344 /* ldmxcsr, stmxcsr */
346 "test 14",
347 "test 14: ldmxcsr, stmxcsr",
348 1, 10, 2, 15, 0x80000000,
349 (uint8_t *)"\x90\x0f\xae\x10\x90\x0f\xae\x18"
350 "\x90\x90\x90\x90\x90\x90\xf4",
352 /* invalid */
354 "test 15",
355 "test 15: invalid instruction",
356 1, 8, 1, 11, 0x80000000,
357 (uint8_t *)"\x90\x0f\xae\x21"
358 "\x90\x90\x90\x90\x90\x90\xf4",
360 /* lfence */
362 "test 16",
363 "test 16: lfence",
364 1, 8, 1, 11, 0x80000000,
365 (uint8_t *)"\x90\x0f\xae\x28"
366 "\x90\x90\x90\x90\x90\x90\xf4",
369 "test 17",
370 "test 17: lock cmpxchg",
371 0, 4, 0, 12, 0x80000000,
372 (uint8_t *)"\xf0\x0f\xb1\x8f\xa8\x01\x00\x00"
373 "\x90\x90\x90\xf4",
376 "test 18",
377 "test 18: loop branch into overlapping instruction",
378 1, 3, 1, 10, 0x80000000,
379 (uint8_t *)"\xbb\x90\x40\xcd\x80\x85\xc0\xe1\xf8\xf4",
382 "test 19",
383 "test 19: aad test",
384 1, 5, 2, 15, 0x80000000,
385 (uint8_t *)"\x68\x8a\x80\x04\x08\xd5\xb0\xc3\x90\xbb\x90\x40\xcd\x80\xf4"
388 "test 20",
389 "test 20: addr16 lea",
390 1, 5, 1, 19, 0x80000000,
391 (uint8_t *)"\x68\x8e\x80\x04\x08\x66\x67\x8d\x98\xff\xff\xc3\x90\xbb\x90\x40\xcd\x80\xf4"
394 "test 21",
395 "test 21: aam",
396 1, 4, 2, 14, 0x80000000,
397 (uint8_t *)"\x68\x89\x80\x04\x08\xd4\xb0\xc3\xbb\x90\x40\xcd\xf4",
400 "test 22",
401 "test 22: pshufw",
402 1, 4, 1, 16, 0x80000000,
403 (uint8_t *)"\x68\x8b\x80\x04\x08\x0f\x70\xca\xb3\xc3\xbb\x90\x40\xcd\x80\xf4",
406 "test 23",
407 "test 23: 14-byte nacljmp using eax",
408 1, 3, 0, 15, 0x80000000,
409 (uint8_t *)"\x81\xe0\xff\xff\xff\xff\x81\xc8\x00\x00\x00\x00\xff\xd0\xf4",
412 "test 24",
413 "test 24: 5-byte nacljmp",
414 0, 2, 0, 6, 0x80000000,
415 (uint8_t *)"\x83\xe0\xf0\xff\xe0\xf4",
418 "test 25",
419 "test 25: 0xe3 jmp",
420 1, 1, 1, 3, 0x80000000,
421 (uint8_t *)"\xe3\x00\xf4",
424 "test 26",
425 "test 26: 0xe9 jmp, nop",
426 0, 2, 0, 7, 0x80000000,
427 (uint8_t *)"\xe9\x00\x00\x00\x00\x90\xf4",
430 "test 27",
431 "test 27: 0xf0 0x80 jmp, nop",
432 0, 2, 0, 8, 0x80000000,
433 (uint8_t *)"\x0f\x80\x00\x00\x00\x00\x90\xf4",
436 "test 28",
437 "test 28: 0xe9 jmp",
438 1, 1, 0, 6, 0x80000000,
439 (uint8_t *)"\xe9\x00\x00\x00\x00\xf4",
442 "test 30",
443 "test 30: addr16 lea ret",
444 1, 3, 1, 8, 0x80000000,
445 (uint8_t *)"\x67\x8d\xb4\x9a\x40\xc3\x90\xf4",
448 "test 31",
449 "test 31: repz movsbl",
450 1, 3, 2, 8, 0x80000000,
451 (uint8_t *)"\xf3\x0f\xbe\x40\xd0\xc3\x90\xf4",
454 "test 32",
455 "test 32: infinite loop",
456 0, 1, 0, 3, 0x80000000,
457 (uint8_t *)"\x7f\xfe\xf4",
460 "test 33",
461 "test 33: bad branch",
462 1, 1, 0, 3, 0x80000000,
463 (uint8_t *)"\x7f\xfd\xf4",
466 "test 34",
467 "test 34: bad branch",
468 1, 1, 0, 3, 0x80000000,
469 (uint8_t *)"\x7f\xff\xf4",
472 "test 35",
473 "test 35: bad branch",
474 1, 1, 0, 3, 0x80000000,
475 (uint8_t *)"\x7f\x00\xf4",
478 "test 36",
479 "test 36: bad branch",
480 1, 1, 0, 3, 0x80000000,
481 (uint8_t *)"\x7f\x01\xf4",
484 "test 37",
485 "test 37: bad branch",
486 1, 1, 0, 3, 0x80000000,
487 (uint8_t *)"\x7f\x02\xf4",
490 "test 38",
491 "test 38: intc",
492 1, 10, 5, 18, 0x80000000,
493 (uint8_t *)"\x66\xeb\x1b\x31\x51\x3d\xef\xcc\x2f\x36\x48\x6e\x44\x2e\xcc\x14\xf4\xf4",
496 "test 39",
497 "test 39: bad branch",
498 1, 7, 1, 18, 0x80000000,
499 (uint8_t *)"\x67\x8d\x1d\x22\xa0\x05\xe3\x7b\x9c\xdb\x08\x04\xb1\x90\xed\x12\xf4\xf4",
502 "test 40",
503 "test 40: more addr16 problems",
504 1, 4, 1, 9, 0x80000000,
505 (uint8_t *)"\x67\xa0\x00\x00\xcd\x80\x90\x90\xf4",
508 "test 41",
509 "test 41: the latest non-bug from hcf",
510 1, 5, 1, 17, 0x80000000,
511 (uint8_t *)"\x84\xd4\x04\x53\xa0\x04\x6a\x5a\x20\xcc\xb8\x48\x03\x2b\x96\x11\xf4"
514 "test 42",
515 "test 42: another case from hcf",
516 1, 7, 1, 17, 0x80000000,
517 (uint8_t *)"\x45\x7f\x89\x58\x94\x04\x24\x1b\xc3\xe2\x6f\x1a\x94\x87\x8f\x0b\xf4",
520 "test 43",
521 "test 43: too many prefix bytes",
522 1, 2, 0, 8, 0x80000000,
523 (uint8_t *)"\x66\x66\x66\x66\x00\x00\x90\xf4"
526 "test 44",
527 "test 44: palignr (SSSE3)",
528 0, 2, 0, 8, 0x80000000,
529 (uint8_t *)"\x66\x0f\x3a\x0f\xd0\xc0\x90\xf4"
532 "test 45",
533 "test 45: undefined inst in 3-byte opcode space",
534 1, 2, 2, 8, 0x80000000,
535 (uint8_t *)"\x66\x0f\x39\x0f\xd0\xc0\x90\xf4"
538 "test 46",
539 "test 46: SSE2x near miss",
540 1, 2, 1, 7, 0x80000000,
541 (uint8_t *)"\x66\x0f\x73\x00\x00\x90\xf4"
544 "test 47",
545 "test 47: SSE2x",
546 0, 2, 0, 7, 0x80000000,
547 (uint8_t *)"\x66\x0f\x73\xff\x00\x90\xf4"
550 "test 48",
551 "test 48: SSE2x, missing required prefix byte",
552 1, 2, 0, 6, 0x80000000,
553 (uint8_t *)"\x0f\x73\xff\x00\x90\xf4"
556 "test 49",
557 "test 49: 3DNow example",
558 0, 2, 0, 7, 0x80000000,
559 (uint8_t *)"\x0f\x0f\x46\x01\xbf\x90\xf4"
562 "test 50",
563 "test 50: 3DNow error example 1",
564 1, 2, 1, 7, 0x80000000,
565 (uint8_t *)"\x0f\x0f\x46\x01\x00\x90\xf4"
568 "test 51",
569 "test 51: 3DNow error example 2",
570 1, 0, 0, 5, 0x80000000,
571 (uint8_t *)"\x0f\x0f\x46\x01\xf4"
574 "test 52",
575 "test 52: 3DNow error example 3",
576 1, 2, 1, 7, 0x80000000,
577 (uint8_t *)"\x0f\x0f\x46\x01\xbe\x90\xf4"
580 "test 53",
581 "test 53: 3DNow error example 4",
582 1, 2, 1, 7, 0x80000000,
583 (uint8_t *)"\x0f\x0f\x46\x01\xaf\x90\xf4"
586 "test 54",
587 "test 54: SSSE3 error 1",
588 1, 3, 1, 8, 0x80000000,
589 (uint8_t *)"\x66\x0f\x3a\x0e\xd0\xc0\x90\xf4"
592 "test 55",
593 "test 55: SSSE3 error 2",
594 1, 3, 1, 8, 0x80000000,
595 (uint8_t *)"\x66\x0f\x38\x0f\xd0\xc0\x90\xf4"
598 "test 56",
599 "test 56: incb decb",
600 0, 3, 0, 14, 0x80000000,
601 (uint8_t *)"\xfe\x85\x4f\xfd\xff\xff\xfe\x8d\x73\xfd\xff\xff\x90\xf4",
604 "test 57",
605 "test 57: lzcnt",
606 0, 2, 0, 6, 0x80000000,
607 (uint8_t *)"\xf3\x0f\xbd\x00\x90\xf4",
610 "test 58",
611 "test 58: fldz",
612 0, 2, 0, 4, 0x80000000,
613 (uint8_t *)"\xd9\xee\x90\xf4",
616 "test 59",
617 "test 59: x87",
618 0, 7, 0, 25, 0x80000000,
619 (uint8_t *)"\xdd\x9c\xfd\xb0\xfe\xff\xff"
620 "\xdd\x9d\x40\xff\xff\xff"
621 "\xdb\x04\x24"
622 "\xdd\x5d\xa0"
623 "\xda\xe9"
624 "\xdf\xe0"
625 "\x90\xf4",
628 "test 60",
629 "test 60: x87 bad instructions",
630 1, 19, 9, 40, 0x80000000,
631 (uint8_t *)"\xdd\xcc"
632 "\xdd\xc0"
633 "\xdd\xc7"
634 "\xdd\xc8"
635 "\xdd\xcf"
636 "\xdd\xf0"
637 "\xdd\xff"
638 "\xdd\xfd"
639 "\xde\xd1"
640 "\xde\xd9"
641 "\xdb\x04\x24"
642 "\xdd\x5d\xa0"
643 "\xdb\xe0"
644 "\xdb\xff"
645 "\xdb\xe8"
646 "\xdb\xf7"
647 "\xda\xe9"
648 "\xdf\xe0"
649 "\x90\xf4",
652 "test 61",
653 "test 61: 3DNow prefetch",
654 0, 2, 0, 5, 0x80000000,
655 (uint8_t *)"\x0f\x0d\x00"
656 "\x90\xf4",
659 "test 61.1",
660 "test 61.1: F2 0F ...",
661 1, 3, 1, 13, 0x80000000,
662 (uint8_t *)"\xf2\x0f\x48\x0f\x48\xa4\x52"
663 "\xf2\x0f\x10\xc8"
664 "\x90\xf4",
667 "test 62",
668 "test 62: f6/f7 test Ib/Iv ...",
669 0, 10, 0, 28, 0x80000000,
670 (uint8_t *)"\xf6\xc1\xff"
671 "\xf6\x44\x43\x01\x02"
672 "\xf7\xc6\x03\x00\x00\x00"
673 "\x90\x90\x90\x90\x90"
674 "\xf7\x45\x18\x00\x00\x00\x20"
675 "\x90\xf4",
678 "test 63",
679 "test 63: addr16 corner cases ...",
680 1, 5, 0, 17, 0x80000000,
681 (uint8_t *)"\x67\x01\x00"
682 "\x67\x01\x40\x00"
683 "\x67\x01\x80\x00\x90"
684 "\x67\x01\xc0"
685 "\x90\xf4",
688 "test 64",
689 "test 64: text starts with indirect jmp ...",
690 1, 2, 0, 4, 0x80000000,
691 (uint8_t *)"\xff\xd0\x90\xf4"
694 "test 65",
695 "test 65: nacljmp crosses 32-byte boundary ...",
696 1, 32, 0, 36, 0x80000000,
697 (uint8_t *)"\x90\x90\x90\x90\x90\x90\x90\x90"
698 "\x90\x90\x90\x90\x90\x90\x90\x90"
699 "\x90\x90\x90\x90\x90\x90\x90\x90"
700 "\x90\x90\x90\x90\x90\x83\xe0\xff"
701 "\xff\xd0\x90\xf4"
704 /* I think this is currently NACLi_ILLEGAL */
705 "test 65",
706 "test 65: NACLi_CFLUSH",
707 1, 2, 1, 10, 0x80000000,
708 (uint8_t *)"\x0f\xae\x00\x00\x90\x90\x90\x90\x90\xf4"
711 "test 66",
712 "test 66: NACLi_CMPXCHG8B",
713 0, 2, 0, 6, 0x80000000,
714 (uint8_t *)"\xf0\x0f\xc7\010\x90\xf4"
717 "test 67",
718 "test 67: NACLi_FCMOV",
719 0, 7, 0, 10, 0x80000000,
720 (uint8_t *)"\xda\xc0\x00\x00\x90\x90\x90\x90\x90\xf4"
723 "test 68",
724 "test 68: NACLi_MMX",
725 0, 4, 0, 7, 0x80000000,
726 (uint8_t *)"\x0f\x60\x00\x90\x90\x90\xf4"
729 "test 69",
730 "test 69: NACLi_SSE",
731 0, 2, 0, 9, 0x80000000,
732 (uint8_t *)"\x0f\x5e\x90\x90\x90\x90\x90\x90\xf4"
735 "test 70",
736 "test 70: NACLi_SSE2",
737 0, 4, 0, 8, 0x80000000,
738 (uint8_t *)"\x66\x0f\x60\x00\x90\x90\x90\xf4"
741 "test 71",
742 "test 71: NACLi_SSE3",
743 0, 4, 0, 8, 0x80000000,
744 (uint8_t *)"\x66\x0f\x7d\x00\x90\x90\x90\xf4"
747 "test 72",
748 "test 72: NACLi_SSE4A",
749 0, 4, 0, 8, 0x80000000,
750 (uint8_t *)"\xf2\x0f\x79\x00\x90\x90\x90\xf4"
753 "test 73",
754 "test 73: NACLi_POPCNT",
755 0, 2, 0, 6, 0x80000000,
756 (uint8_t *)"\xf3\x0f\xb8\x00\x90\xf4"
759 "test 74",
760 "test 74: NACLi_E3DNOW",
761 0, 2, 0, 7, 0x80000000,
762 (uint8_t *)"\x0f\x0f\x46\x01\xbb\x90\xf4"
765 "test 75",
766 "test 75: NACLi_MMXSSE2",
767 0, 2, 0, 7, 0x80000000,
768 (uint8_t *)"\x66\x0f\x71\xf6\x00\x90\xf4",
771 "test 76",
772 "test 76: mov eax, ss",
773 1, 4, 3, 9, 0x80000000,
774 (uint8_t *)"\x8e\xd0\x8c\xd0\x66\x8c\xd0\x90\xf4",
777 "test 77",
778 "test 77: call esp",
779 1, 3, 0, 7, 0x80000000,
780 (uint8_t *)"\x83\xe4\xf0\xff\xd4\x90\xf4",
782 /* code.google.com issue 23 reported by defend.the.world on 11 Dec 2008 */
784 "test 78",
785 "test 79: call (*edx)",
786 1, 30, 0, 34, 0x80000000,
787 (uint8_t *)
788 "\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
789 "\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
790 "\x83\xe2\xf0" /* and */
791 "\xff\x12" /* call (*edx) */
792 "\x90\xf4", /* nop halt */
795 "test 79",
796 "test 79: call *edx",
797 0, 30, 0, 34, 0x80000000,
798 (uint8_t *)
799 "\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
800 "\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
801 "\x83\xe2\xf0" /* and */
802 "\xff\xd2" /* call *edx */
803 "\x90\xf4", /* nop halt */
807 static uint8_t *memdup(uint8_t *s, int len) {
808 return memcpy(malloc(len), s, len);
811 static void TestValidator(struct NCValTestCase *vtest) {
812 struct NCValidatorState *vstate;
813 uint8_t *byte0 = memdup(vtest->testbytes, vtest->testsize);
814 int rc;
816 vstate = NCValidateInit(vtest->vaddr,
817 vtest->vaddr + vtest->testsize, 16);
818 NCValidateSegment(byte0, (uint32_t)vtest->vaddr, vtest->testsize, vstate);
819 free(byte0);
820 rc = NCValidateFinish(vstate);
821 do {
822 if (vtest->sawfailure ^ vstate->stats.sawfailure) break;
823 if (vtest->instructions != vstate->stats.instructions) break;
824 if (vtest->illegalinst != vstate->stats.illegalinst) break;
825 fprintf(stderr, "*** %s passed (%s)\n", vtest->name, vtest->description);
826 NCValidateFreeState(&vstate);
827 return;
828 } while (0);
829 Stats_Print(stderr, vstate);
830 NCValidateFreeState(&vstate);
831 fprintf(stderr, "*** %s failed (%s)\n", vtest->name, vtest->description);
832 exit(-1);
835 #define sizeofA(array) (sizeof(array)/sizeof(array[0]))
836 void ncvalidate_unittests() {
837 size_t i;
839 for (i = 0; i < sizeofA(NCValTests); i++) {
840 TestValidator(&NCValTests[i]);
842 fprintf(stderr, "\nAll tests passed.\n\n");