Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(382)

Side by Side Diff: chrome/browser/nacl_host/test/mock_nacl_gdb.cc

Issue 9662055: Test for --nacl-gdb functionality. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <cstdio>
6 #include <cstring>
7
8 #include "base/command_line.h"
9 #include "base/environment.h"
10 #include "base/file_util.h"
11 #include "base/logging.h"
12 #include "base/process_util.h"
13
14 static const char kArgs[] = "--args";
15 static const char kEvalCommand[] = "--eval-command";
16 static const char kNaClIrt[] = "nacl-irt ";
17 static const char kPass[] = "PASS";
18
19 int main(int argc, char** argv) {
20 scoped_ptr<base::Environment> env(base::Environment::Create());
21 std::string mock_nacl_gdb_file;
22 env->GetVar("MOCK_NACL_GDB", &mock_nacl_gdb_file);
23 file_util::WriteFile(FilePath::FromUTF8Unsafe(mock_nacl_gdb_file),
24 kPass, strlen(kPass));
25 CHECK_GE(argc, 3);
26 // First argument should be --eval-command.
27 CHECK_EQ(strcmp(argv[1], kEvalCommand), 0);
28 // Second argument should start with nacl-irt.
29 CHECK_GE(strlen(argv[2]), strlen(kNaClIrt));
30 CHECK_EQ(strncmp(argv[2], kNaClIrt, strlen(kNaClIrt)), 0);
31 char* irt_file_name = &argv[2][strlen(kNaClIrt)];
32 FILE* irt_file = fopen(irt_file_name, "r");
33 // nacl-irt parameter must be a file name.
34 PCHECK(irt_file);
35 fclose(irt_file);
36 int i = 3;
37 // Skip additional --eval-command parameters.
38 while (i < argc) {
39 if (strcmp(argv[i], kArgs) == 0) {
40 i++;
41 break;
42 }
43 if (strcmp(argv[i], kEvalCommand) == 0) {
44 i += 2;
45 // Command line shouldn't end with --eval-command switch without value.
46 CHECK_LE(i, argc);
47 continue;
48 }
49 // Unknown argument.
50 NOTREACHED() << "Invalid argument " << argv[i];
51 }
52 // --args switch must be present.
53 CHECK_LT(i, argc);
54
55 CommandLine::StringVector arguments;
56 for (; i < argc; i++) {
57 arguments.push_back(
58 CommandLine::StringType(argv[i], argv[i] + strlen(argv[i])));
59 }
60 CommandLine cmd_line(arguments);
61 // Process must be launched successfully.
62 PCHECK(base::LaunchProcess(cmd_line, base::LaunchOptions(), NULL));
63 return 0;
64 }
OLDNEW
« no previous file with comments | « chrome/browser/nacl_host/nacl_process_host.cc ('k') | chrome/browser/nacl_host/test/mock_nacl_gdb.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698