| 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 "native_client/tests/thread_suspension/suspend_test.h" | 7 #include "native_client/tests/thread_suspension/suspend_test.h" |
| 8 | 8 |
| 9 #include "native_client/src/include/nacl_assert.h" | 9 #include "native_client/src/include/nacl_assert.h" |
| 10 #include "native_client/src/include/portability_io.h" | 10 #include "native_client/src/include/portability_io.h" |
| 11 #include "native_client/src/shared/gio/gio.h" | |
| 12 #include "native_client/src/shared/platform/nacl_check.h" | 11 #include "native_client/src/shared/platform/nacl_check.h" |
| 13 #include "native_client/src/shared/platform/nacl_exit.h" | 12 #include "native_client/src/shared/platform/nacl_exit.h" |
| 14 #include "native_client/src/shared/platform/nacl_log.h" | 13 #include "native_client/src/shared/platform/nacl_log.h" |
| 15 #include "native_client/src/shared/platform/nacl_sync_checked.h" | 14 #include "native_client/src/shared/platform/nacl_sync_checked.h" |
| 16 #include "native_client/src/trusted/service_runtime/include/bits/mman.h" | 15 #include "native_client/src/trusted/service_runtime/include/bits/mman.h" |
| 17 #include "native_client/src/trusted/service_runtime/include/bits/nacl_syscalls.h
" | 16 #include "native_client/src/trusted/service_runtime/include/bits/nacl_syscalls.h
" |
| 17 #include "native_client/src/trusted/service_runtime/load_file.h" |
| 18 #include "native_client/src/trusted/service_runtime/nacl_all_modules.h" | 18 #include "native_client/src/trusted/service_runtime/nacl_all_modules.h" |
| 19 #include "native_client/src/trusted/service_runtime/nacl_app.h" | 19 #include "native_client/src/trusted/service_runtime/nacl_app.h" |
| 20 #include "native_client/src/trusted/service_runtime/nacl_app_thread.h" | 20 #include "native_client/src/trusted/service_runtime/nacl_app_thread.h" |
| 21 #include "native_client/src/trusted/service_runtime/nacl_copy.h" | 21 #include "native_client/src/trusted/service_runtime/nacl_copy.h" |
| 22 #include "native_client/src/trusted/service_runtime/nacl_signal.h" | 22 #include "native_client/src/trusted/service_runtime/nacl_signal.h" |
| 23 #include "native_client/src/trusted/service_runtime/nacl_syscall_common.h" | 23 #include "native_client/src/trusted/service_runtime/nacl_syscall_common.h" |
| 24 #include "native_client/src/trusted/service_runtime/nacl_valgrind_hooks.h" | |
| 25 #include "native_client/src/trusted/service_runtime/sel_ldr.h" | 24 #include "native_client/src/trusted/service_runtime/sel_ldr.h" |
| 26 #include "native_client/src/trusted/service_runtime/thread_suspension.h" | 25 #include "native_client/src/trusted/service_runtime/thread_suspension.h" |
| 27 #include "native_client/tests/common/register_set.h" | 26 #include "native_client/tests/common/register_set.h" |
| 28 | 27 |
| 29 | 28 |
| 30 /* | 29 /* |
| 31 * These tests mirror thread_suspension_test.cc, but they operate on | 30 * These tests mirror thread_suspension_test.cc, but they operate on |
| 32 * threads running real untrusted code rather than on mock untrusted | 31 * threads running real untrusted code rather than on mock untrusted |
| 33 * threads. | 32 * threads. |
| 34 */ | 33 */ |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 NaClAppThreadGetSuspendedRegisters(natp, ®s); | 365 NaClAppThreadGetSuspendedRegisters(natp, ®s); |
| 367 NaClUntrustedThreadsResumeAll(nap); | 366 NaClUntrustedThreadsResumeAll(nap); |
| 368 test_shm->should_exit = 1; | 367 test_shm->should_exit = 1; |
| 369 CHECK(NaClWaitForMainThreadToExit(nap) == 0); | 368 CHECK(NaClWaitForMainThreadToExit(nap) == 0); |
| 370 | 369 |
| 371 RegsAssertEqual(®s, &test_shm->expected_regs); | 370 RegsAssertEqual(®s, &test_shm->expected_regs); |
| 372 } | 371 } |
| 373 | 372 |
| 374 int main(int argc, char **argv) { | 373 int main(int argc, char **argv) { |
| 375 struct NaClApp app; | 374 struct NaClApp app; |
| 376 struct GioMemoryFileSnapshot gio_file; | |
| 377 | 375 |
| 378 NaClHandleBootstrapArgs(&argc, &argv); | 376 NaClHandleBootstrapArgs(&argc, &argv); |
| 379 | 377 |
| 380 /* Turn off buffering to aid debugging. */ | 378 /* Turn off buffering to aid debugging. */ |
| 381 setvbuf(stdout, NULL, _IONBF, 0); | 379 setvbuf(stdout, NULL, _IONBF, 0); |
| 382 setvbuf(stderr, NULL, _IONBF, 0); | 380 setvbuf(stderr, NULL, _IONBF, 0); |
| 383 | 381 |
| 384 NaClAllModulesInit(); | 382 NaClAllModulesInit(); |
| 385 | 383 |
| 386 #if NACL_LINUX | 384 #if NACL_LINUX |
| 387 NaClSignalHandlerInit(); | 385 NaClSignalHandlerInit(); |
| 388 #endif | 386 #endif |
| 389 | 387 |
| 390 if (argc != 2) { | 388 if (argc != 2) { |
| 391 NaClLog(LOG_FATAL, "Expected 1 argument: executable filename\n"); | 389 NaClLog(LOG_FATAL, "Expected 1 argument: executable filename\n"); |
| 392 } | 390 } |
| 393 | 391 |
| 394 NaClFileNameForValgrind(argv[1]); | |
| 395 CHECK(GioMemoryFileSnapshotCtor(&gio_file, argv[1])); | |
| 396 CHECK(NaClAppCtor(&app)); | 392 CHECK(NaClAppCtor(&app)); |
| 397 CHECK(NaClAppLoadFile((struct Gio *) &gio_file, &app) == LOAD_OK); | 393 CHECK(NaClAppLoadFileFromFilename(&app, argv[1]) == LOAD_OK); |
| 398 NaClAppInitialDescriptorHookup(&app); | 394 NaClAppInitialDescriptorHookup(&app); |
| 399 CHECK(NaClAppPrepareToLaunch(&app) == LOAD_OK); | 395 CHECK(NaClAppPrepareToLaunch(&app) == LOAD_OK); |
| 400 | 396 |
| 401 NaClAddSyscall(NACL_sys_test_syscall_1, SuspendTestSyscall); | 397 NaClAddSyscall(NACL_sys_test_syscall_1, SuspendTestSyscall); |
| 402 | 398 |
| 403 /* | 399 /* |
| 404 * We reuse the same sandbox for both tests. | 400 * We reuse the same sandbox for both tests. |
| 405 * | 401 * |
| 406 * TODO(mseaborn): It would be cleaner to create a new sandbox for | 402 * TODO(mseaborn): It would be cleaner to create a new sandbox for |
| 407 * each test, but if we are to do that in a single process without | 403 * each test, but if we are to do that in a single process without |
| (...skipping 20 matching lines...) Expand all Loading... |
| 428 | 424 |
| 429 printf("Running TestGettingRegisterSnapshotInSyscall...\n"); | 425 printf("Running TestGettingRegisterSnapshotInSyscall...\n"); |
| 430 TestGettingRegisterSnapshotInSyscall(&app); | 426 TestGettingRegisterSnapshotInSyscall(&app); |
| 431 | 427 |
| 432 /* | 428 /* |
| 433 * Avoid calling exit() because it runs process-global destructors | 429 * Avoid calling exit() because it runs process-global destructors |
| 434 * which might break code that is running in our unjoined threads. | 430 * which might break code that is running in our unjoined threads. |
| 435 */ | 431 */ |
| 436 NaClExit(0); | 432 NaClExit(0); |
| 437 } | 433 } |
| OLD | NEW |