OLD | NEW |
(Empty) | |
| 1 /* |
| 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 |
| 4 * found in the LICENSE file. |
| 5 */ |
| 6 |
| 7 #include <stdio.h> |
| 8 |
| 9 #include "native_client/src/include/portability.h" |
| 10 #include "native_client/src/include/nacl_macros.h" |
| 11 |
| 12 #include "native_client/src/shared/platform/nacl_check.h" |
| 13 #include "native_client/src/shared/platform/nacl_exit.h" |
| 14 #include "native_client/src/shared/platform/nacl_log.h" |
| 15 #include "native_client/src/shared/platform/platform_init.h" |
| 16 |
| 17 #include "native_client/src/trusted/platform/nacl_process.h" |
| 18 |
| 19 int main(int argc, char **argv) { |
| 20 struct NaClProcess proc; |
| 21 #if NACL_WINDOWS |
| 22 #define MAX_CMD_CHARS 512 |
| 23 char cmd[MAX_CMD_CHARS]; |
| 24 #else |
| 25 char *args[] = { argv[0], "-e 0", NULL }; |
| 26 #endif |
| 27 int exit_code = -1; |
| 28 int opt; |
| 29 |
| 30 while (EOF != (opt = getopt(argc, argv, "e:"))) { |
| 31 switch (opt) { |
| 32 case 'e': |
| 33 exit_code = strtoul(optarg, (char **) NULL, 0); |
| 34 default: |
| 35 fprintf(stderr, |
| 36 "Usage: nacl_process_test [args]\n" |
| 37 " -e N program exit code\n"); |
| 38 goto cleanup0; |
| 39 } |
| 40 } |
| 41 |
| 42 if (-1 != exit_code) { |
| 43 goto cleanup0; |
| 44 } |
| 45 |
| 46 NaClPlatformInit(); |
| 47 |
| 48 #if NACL_WINDOWS |
| 49 _snprintf(cmd, MAX_CMD_CHARS, "%s -e 0", argv[0]); |
| 50 if (NaClProcessLaunch(&proc, cmd, NULL, 0) < 0) { |
| 51 #else |
| 52 if (NaClProcessLaunch(&proc, args, NULL, 0) < 0) { |
| 53 #endif |
| 54 fprintf(stderr, |
| 55 "nacl_process_test: could not launch process %s\n", |
| 56 argv[0]); |
| 57 goto cleanup1; |
| 58 } |
| 59 |
| 60 if (!NaClProcessWaitForExitCode(&proc, &exit_code)) { |
| 61 fprintf(stderr, |
| 62 "nacl_process_test: failed waiting for process exit code\n"); |
| 63 } |
| 64 |
| 65 if (0 == exit_code) { |
| 66 printf("SUCCESS\n"); |
| 67 } |
| 68 |
| 69 cleanup1: |
| 70 NaClPlatformFini(); |
| 71 cleanup0: |
| 72 return exit_code; |
| 73 } |
OLD | NEW |