Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / nacl_host / test / gdb_debug_stub_browsertest.cc
blobb485361cc3bba529dd46e86a174ad640c4ec90b3
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.
5 #include "base/command_line.h"
6 #include "base/environment.h"
7 #include "base/path_service.h"
8 #include "base/process/kill.h"
9 #include "base/process/launch.h"
10 #include "base/process/process.h"
11 #include "base/strings/string_number_conversions.h"
12 #include "chrome/common/chrome_paths.h"
13 #include "chrome/test/ppapi/ppapi_test.h"
14 #include "components/nacl/browser/nacl_browser.h"
15 #include "components/nacl/common/nacl_switches.h"
16 #include "content/public/test/test_utils.h"
18 class NaClGdbDebugStubTest : public PPAPINaClNewlibTest {
19 public:
20 NaClGdbDebugStubTest() {
23 void SetUpCommandLine(base::CommandLine* command_line) override;
25 void StartTestScript(base::Process* test_process,
26 std::string test_name, int debug_stub_port);
27 void RunDebugStubTest(const std::string& nacl_module,
28 const std::string& test_name);
31 void NaClGdbDebugStubTest::SetUpCommandLine(base::CommandLine* command_line) {
32 PPAPINaClNewlibTest::SetUpCommandLine(command_line);
33 command_line->AppendSwitch(switches::kEnableNaClDebug);
36 void NaClGdbDebugStubTest::StartTestScript(base::Process* test_process,
37 std::string test_name,
38 int debug_stub_port) {
39 // We call python script to reuse GDB RSP protocol implementation.
40 base::CommandLine cmd(base::FilePath(FILE_PATH_LITERAL("python")));
41 base::FilePath script;
42 PathService::Get(chrome::DIR_TEST_DATA, &script);
43 script = script.AppendASCII("nacl/debug_stub_browser_tests.py");
44 cmd.AppendArgPath(script);
45 cmd.AppendArg(base::IntToString(debug_stub_port));
46 cmd.AppendArg(test_name);
47 LOG(INFO) << cmd.GetCommandLineString();
48 *test_process = base::LaunchProcess(cmd, base::LaunchOptions());
51 void NaClGdbDebugStubTest::RunDebugStubTest(const std::string& nacl_module,
52 const std::string& test_name) {
53 base::Process test_script;
54 scoped_ptr<base::Environment> env(base::Environment::Create());
55 nacl::NaClBrowser::GetInstance()->SetGdbDebugStubPortListener(
56 base::Bind(&NaClGdbDebugStubTest::StartTestScript,
57 base::Unretained(this), &test_script, test_name));
58 // Turn on debug stub logging.
59 env->SetVar("NACLVERBOSITY", "1");
60 RunTestViaHTTP(nacl_module);
61 env->UnSetVar("NACLVERBOSITY");
62 nacl::NaClBrowser::GetInstance()->ClearGdbDebugStubPortListener();
63 int exit_code;
64 test_script.WaitForExit(&exit_code);
65 EXPECT_EQ(0, exit_code);
68 // NaCl tests are disabled under ASAN because of qualification test.
69 #if defined(ADDRESS_SANITIZER)
70 # define MAYBE_Empty DISABLED_Empty
71 #else
72 # define MAYBE_Empty Empty
73 #endif
75 IN_PROC_BROWSER_TEST_F(NaClGdbDebugStubTest, MAYBE_Empty) {
76 RunDebugStubTest("Empty", "continue");
79 #if defined(ADDRESS_SANITIZER)
80 # define MAYBE_Breakpoint DISABLED_Breakpoint
81 #elif defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
82 // Timing out on ARM linux: http://crbug.com/238469
83 # define MAYBE_Breakpoint DISABLED_Breakpoint
84 #else
85 # define MAYBE_Breakpoint Breakpoint
86 #endif
88 IN_PROC_BROWSER_TEST_F(NaClGdbDebugStubTest, MAYBE_Breakpoint) {
89 RunDebugStubTest("Empty", "breakpoint");