| Index: src/trusted/platform/nacl_process_test.c
|
| diff --git a/src/trusted/platform/nacl_process_test.c b/src/trusted/platform/nacl_process_test.c
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..a59dc57345478984a9c59c68a4a52533b96672b0
|
| --- /dev/null
|
| +++ b/src/trusted/platform/nacl_process_test.c
|
| @@ -0,0 +1,73 @@
|
| +/*
|
| + * Copyright (c) 2012 The Native Client Authors. All rights reserved.
|
| + * Use of this source code is governed by a BSD-style license that can be
|
| + * found in the LICENSE file.
|
| + */
|
| +
|
| +#include <stdio.h>
|
| +
|
| +#include "native_client/src/include/portability.h"
|
| +#include "native_client/src/include/nacl_macros.h"
|
| +
|
| +#include "native_client/src/shared/platform/nacl_check.h"
|
| +#include "native_client/src/shared/platform/nacl_exit.h"
|
| +#include "native_client/src/shared/platform/nacl_log.h"
|
| +#include "native_client/src/shared/platform/platform_init.h"
|
| +
|
| +#include "native_client/src/trusted/platform/nacl_process.h"
|
| +
|
| +int main(int argc, char **argv) {
|
| + struct NaClProcess proc;
|
| +#if NACL_WINDOWS
|
| + #define MAX_CMD_CHARS 512
|
| + char cmd[MAX_CMD_CHARS];
|
| +#else
|
| + char *args[] = { argv[0], "-e 0", NULL };
|
| +#endif
|
| + int exit_code = -1;
|
| + int opt;
|
| +
|
| + while (EOF != (opt = getopt(argc, argv, "e:"))) {
|
| + switch (opt) {
|
| + case 'e':
|
| + exit_code = strtoul(optarg, (char **) NULL, 0);
|
| + default:
|
| + fprintf(stderr,
|
| + "Usage: nacl_process_test [args]\n"
|
| + " -e N program exit code\n");
|
| + goto cleanup0;
|
| + }
|
| + }
|
| +
|
| + if (-1 != exit_code) {
|
| + goto cleanup0;
|
| + }
|
| +
|
| + NaClPlatformInit();
|
| +
|
| +#if NACL_WINDOWS
|
| + _snprintf(cmd, MAX_CMD_CHARS, "%s -e 0", argv[0]);
|
| + if (NaClProcessLaunch(&proc, cmd, NULL, 0) < 0) {
|
| +#else
|
| + if (NaClProcessLaunch(&proc, args, NULL, 0) < 0) {
|
| +#endif
|
| + fprintf(stderr,
|
| + "nacl_process_test: could not launch process %s\n",
|
| + argv[0]);
|
| + goto cleanup1;
|
| + }
|
| +
|
| + if (!NaClProcessWaitForExitCode(&proc, &exit_code)) {
|
| + fprintf(stderr,
|
| + "nacl_process_test: failed waiting for process exit code\n");
|
| + }
|
| +
|
| + if (0 == exit_code) {
|
| + printf("SUCCESS\n");
|
| + }
|
| +
|
| + cleanup1:
|
| + NaClPlatformFini();
|
| + cleanup0:
|
| + return exit_code;
|
| +}
|
|
|