nacl_gdb_browsertest.cc revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
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 "base/command_line.h" 6#include "base/environment.h" 7#include "base/file_util.h" 8#include "base/path_service.h" 9#include "base/win/windows_version.h" 10#include "chrome/common/chrome_switches.h" 11#include "chrome/test/ppapi/ppapi_test.h" 12 13static const base::FilePath::CharType kMockNaClGdb[] = 14#if defined(OS_WIN) 15 FILE_PATH_LITERAL("mock_nacl_gdb.exe"); 16#else 17 FILE_PATH_LITERAL("mock_nacl_gdb"); 18#endif 19 20class NaClGdbTest : public PPAPINaClNewlibTest { 21 public: 22 NaClGdbTest() { 23 } 24 25 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 26 PPAPINaClNewlibTest::SetUpCommandLine(command_line); 27 28 base::FilePath mock_nacl_gdb; 29 EXPECT_TRUE(PathService::Get(base::DIR_EXE, &mock_nacl_gdb)); 30 mock_nacl_gdb = mock_nacl_gdb.Append(kMockNaClGdb); 31 command_line->AppendSwitchPath(switches::kNaClGdb, mock_nacl_gdb); 32 EXPECT_TRUE(file_util::CreateTemporaryFile(&script_)); 33 command_line->AppendSwitchPath(switches::kNaClGdbScript, script_); 34 } 35 36 void RunWithNaClGdb(std::string test_name) { 37 base::FilePath mock_nacl_gdb_file; 38 scoped_ptr<base::Environment> env(base::Environment::Create()); 39 std::string content; 40 // TODO(halyavin): Make this test work on Windows 32-bit. Currently this 41 // is not possible because NaCl doesn't work without sandbox since 1Gb of 42 // space is not reserved. We can't reserve 1Gb of space because 43 // base::LaunchProcess doesn't support creating suspended processes. We need 44 // to either add suspended process support to base::LaunchProcess or use 45 // Win API. 46#if defined(OS_WIN) 47 if (base::win::OSInfo::GetInstance()->wow64_status() == 48 base::win::OSInfo::WOW64_DISABLED) { 49 return; 50 } 51#endif 52 EXPECT_TRUE(file_util::CreateTemporaryFile(&mock_nacl_gdb_file)); 53 env->SetVar("MOCK_NACL_GDB", mock_nacl_gdb_file.AsUTF8Unsafe()); 54 RunTestViaHTTP(test_name); 55 env->UnSetVar("MOCK_NACL_GDB"); 56 57 EXPECT_TRUE(file_util::ReadFileToString(mock_nacl_gdb_file, &content)); 58 EXPECT_STREQ("PASS", content.c_str()); 59 EXPECT_TRUE(file_util::Delete(mock_nacl_gdb_file, false)); 60 61 content.clear(); 62 EXPECT_TRUE(file_util::ReadFileToString(script_, &content)); 63 EXPECT_STREQ("PASS", content.c_str()); 64 EXPECT_TRUE(file_util::Delete(script_, false)); 65 } 66 67 private: 68 base::FilePath script_; 69}; 70 71// Fails on the ASAN test bot. See http://crbug.com/122219 72#if defined(ADDRESS_SANITIZER) 73#define MAYBE_Empty DISABLED_Empty 74#else 75#define MAYBE_Empty Empty 76#endif 77IN_PROC_BROWSER_TEST_F(NaClGdbTest, MAYBE_Empty) { 78 RunWithNaClGdb("Empty"); 79} 80