Chromium Code Reviews| Index: chrome/browser/nacl_host/mock_nacl_gdb.cc |
| =================================================================== |
| --- chrome/browser/nacl_host/mock_nacl_gdb.cc (revision 0) |
| +++ chrome/browser/nacl_host/mock_nacl_gdb.cc (working copy) |
| @@ -0,0 +1,72 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
|
Mark Seaborn
2012/03/13 01:05:20
I think this file belongs in a directory with "tes
halyavin
2012/03/13 12:48:27
Done.
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include <cstdio> |
| +#include <cstring> |
| + |
| +#include "base/command_line.h" |
| +#include "base/process_util.h" |
| + |
| +const char kArgs[] = "--args"; |
| +const char kEvalCommand[] = "--eval-command"; |
| +const char kNaClIrt[] = "nacl-irt "; |
| + |
| +int main(int argc, char** argv) { |
| + if (argc < 3) { |
| + // Too few arguments. |
| + return 1; |
|
Mark Seaborn
2012/03/13 01:05:20
Having different numbers for each failure is weird
halyavin
2012/03/13 12:48:27
Done.
|
| + } |
| + if (strcmp(argv[1], kEvalCommand) != 0) { |
| + // First argument should be --eval-command. |
| + return 2; |
| + } |
| + if (strlen(argv[2]) < strlen(kNaClIrt)) { |
| + // Second argument should start with nacl-irt. |
| + return 3; |
| + } |
| + if (strncmp(argv[2], kNaClIrt, strlen(kNaClIrt)) != 0) { |
| + // Second argument should start with nacl-irt. |
| + return 4; |
| + } |
| + char* irtFileName = &argv[2][strlen(kNaClIrt)]; |
|
brettw
2012/03/13 05:57:49
style: irt_file_name (no caps in var names)
halyavin
2012/03/13 12:48:27
Done.
|
| + FILE* irtFile = fopen(irtFileName, "r"); |
|
brettw
2012/03/13 05:57:49
Ditto
halyavin
2012/03/13 12:48:27
Done.
|
| + if (irtFile == NULL) { |
| + // nacl-irt parameter must be a file name. |
| + return 5; |
| + } |
| + fclose(irtFile); |
| + int i = 3; |
| + // Skip additional --eval-command parameters. |
| + while (i < argc) { |
| + if (strcmp(argv[i], kArgs) == 0) { |
| + i++; |
| + break; |
| + } |
| + if (strcmp(argv[i], kEvalCommand) == 0) { |
| + i += 2; |
| + if (i > argc) { |
| + // Command line ends with --eval-command switch without value. |
| + return 6; |
| + } |
| + } |
| + // Unknown argument |
| + return 7; |
| + } |
| + if (i >= argc) { |
| + // --args not found. |
| + return 8; |
| + } |
| + |
| + CommandLine::StringVector arguments; |
| + for (; i < argc; i++) { |
| + arguments.push_back( |
| + CommandLine::StringType(argv[i], argv[i] + strlen(argv[i]))); |
| + } |
| + CommandLine cmd_line(arguments); |
| + if (!base::LaunchProcess(cmd_line, base::LaunchOptions(), NULL)) { |
| + // process is not launched successfully |
| + return 9; |
| + } |
| + return 0; |
| +} |