OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 #include <assert.h> | 7 #include <assert.h> |
8 #include <errno.h> | 8 #include <errno.h> |
9 #include <pthread.h> | 9 #include <pthread.h> |
10 #include <setjmp.h> | 10 #include <setjmp.h> |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 void test_catching_various_exception_types(void) { | 307 void test_catching_various_exception_types(void) { |
308 int rc = nacl_exception_set_handler(simple_exception_handler); | 308 int rc = nacl_exception_set_handler(simple_exception_handler); |
309 assert(rc == 0); | 309 assert(rc == 0); |
310 | 310 |
311 printf("Testing __builtin_trap()...\n"); | 311 printf("Testing __builtin_trap()...\n"); |
312 if (!setjmp(g_jmp_buf)) { | 312 if (!setjmp(g_jmp_buf)) { |
313 __builtin_trap(); | 313 __builtin_trap(); |
314 exit(1); | 314 exit(1); |
315 } | 315 } |
316 | 316 |
317 #if defined(__i386__) || defined(__x86_64__) | 317 #if !NONSFI_MODE && (defined(__i386__) || defined(__x86_64__)) |
318 printf("Testing hlt...\n"); | 318 printf("Testing hlt...\n"); |
319 if (!setjmp(g_jmp_buf)) { | 319 if (!setjmp(g_jmp_buf)) { |
320 __asm__("hlt"); | 320 __asm__("hlt"); |
321 exit(1); | 321 exit(1); |
322 } | 322 } |
323 printf("Testing ud2a (an illegal instruction)...\n"); | 323 printf("Testing ud2a (an illegal instruction)...\n"); |
324 if (!setjmp(g_jmp_buf)) { | 324 if (!setjmp(g_jmp_buf)) { |
325 __asm__("ud2a"); | 325 __asm__("ud2a"); |
326 exit(1); | 326 exit(1); |
327 } | 327 } |
328 printf("Testing integer division by zero...\n"); | 328 printf("Testing integer division by zero...\n"); |
329 if (!setjmp(g_jmp_buf)) { | 329 if (!setjmp(g_jmp_buf)) { |
330 uint32_t result; | 330 uint32_t result; |
331 __asm__ volatile("idivb %1" | 331 __asm__ volatile("idivb %1" |
332 : "=a"(result) | 332 : "=a"(result) |
333 : "r"((uint8_t) 0), "a"((uint16_t) 1)); | 333 : "r"((uint8_t) 0), "a"((uint16_t) 1)); |
334 exit(1); | 334 exit(1); |
335 } | 335 } |
336 #endif | 336 #endif |
337 | 337 |
338 /* Clear the jmp_buf to prevent it from being reused accidentally. */ | 338 /* Clear the jmp_buf to prevent it from being reused accidentally. */ |
339 memset(g_jmp_buf, 0, sizeof(g_jmp_buf)); | 339 memset(g_jmp_buf, 0, sizeof(g_jmp_buf)); |
340 } | 340 } |
341 | 341 |
342 | 342 |
343 #if defined(__i386__) || defined(__x86_64__) | 343 #if !NONSFI_MODE && (defined(__i386__) || defined(__x86_64__)) |
344 | 344 |
345 int get_x86_direction_flag(void); | 345 int get_x86_direction_flag(void); |
346 | 346 |
347 void test_get_x86_direction_flag(void) { | 347 void test_get_x86_direction_flag(void) { |
348 /* | 348 /* |
349 * Sanity check: Ensure that get_x86_direction_flag() works. We | 349 * Sanity check: Ensure that get_x86_direction_flag() works. We |
350 * avoid calling assert() with the flag set, because that might not | 350 * avoid calling assert() with the flag set, because that might not |
351 * work. | 351 * work. |
352 */ | 352 */ |
353 assert(get_x86_direction_flag() == 0); | 353 assert(get_x86_direction_flag() == 0); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 int TestMain(void) { | 397 int TestMain(void) { |
398 RUN_TEST(test_exceptions_minimally); | 398 RUN_TEST(test_exceptions_minimally); |
399 RUN_TEST(test_exception_stack_alignments); | 399 RUN_TEST(test_exception_stack_alignments); |
400 RUN_TEST(test_getting_previous_handler); | 400 RUN_TEST(test_getting_previous_handler); |
401 RUN_TEST(test_invalid_handlers); | 401 RUN_TEST(test_invalid_handlers); |
402 /* pthread_join() is broken under qemu-arm. */ | 402 /* pthread_join() is broken under qemu-arm. */ |
403 if (getenv("UNDER_QEMU_ARM") == NULL) | 403 if (getenv("UNDER_QEMU_ARM") == NULL) |
404 RUN_TEST(test_exceptions_on_non_main_thread); | 404 RUN_TEST(test_exceptions_on_non_main_thread); |
405 RUN_TEST(test_catching_various_exception_types); | 405 RUN_TEST(test_catching_various_exception_types); |
406 | 406 |
407 #if defined(__i386__) || defined(__x86_64__) | 407 #if !NONSFI_MODE && (defined(__i386__) || defined(__x86_64__)) |
408 RUN_TEST(test_get_x86_direction_flag); | 408 RUN_TEST(test_get_x86_direction_flag); |
409 RUN_TEST(test_unsetting_x86_direction_flag); | 409 RUN_TEST(test_unsetting_x86_direction_flag); |
410 #endif | 410 #endif |
411 | 411 |
412 fprintf(stderr, "** intended_exit_status=0\n"); | 412 fprintf(stderr, "** intended_exit_status=0\n"); |
413 return 0; | 413 return 0; |
414 } | 414 } |
415 | 415 |
416 int main(void) { | 416 int main(void) { |
417 return RunTests(TestMain); | 417 return RunTests(TestMain); |
418 } | 418 } |
OLD | NEW |