Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | |
|
rvargas (doing something else)
2015/02/02 20:55:58
nit: no (c)
Timur Iskhodzhanov
2015/02/03 13:25:22
Thanks for catching this!
Self-for-the-record: I'v
| |
| 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 <stdio.h> | |
| 6 | |
| 7 #include "base/environment.h" | |
| 8 #include "base/files/file_path.h" | |
| 9 #include "base/files/file_util.h" | |
| 10 #include "base/win/windows_version.h" | |
| 11 #include "sandbox/win/tests/common/controller.h" | |
| 12 #include "testing/gtest/include/gtest/gtest.h" | |
| 13 | |
| 14 namespace sandbox { | |
| 15 | |
| 16 class AddressSanitizerTests : public ::testing::Test { | |
| 17 public: | |
| 18 void SetUp() { | |
| 19 env_.reset(base::Environment::Create()); | |
| 20 had_asan_options_ = env_->GetVar("ASAN_OPTIONS", &old_asan_options_); | |
| 21 } | |
| 22 | |
| 23 void TearDown() { | |
| 24 if (had_asan_options_) | |
| 25 ASSERT_TRUE(env_->SetVar("ASAN_OPTIONS", old_asan_options_)); | |
| 26 else | |
| 27 env_->UnSetVar("ASAN_OPTIONS"); | |
| 28 } | |
| 29 | |
| 30 protected: | |
| 31 scoped_ptr<base::Environment> env_; | |
| 32 bool had_asan_options_; | |
| 33 std::string old_asan_options_; | |
| 34 }; | |
| 35 | |
| 36 SBOX_TESTS_COMMAND int AddressSanitizerTests_Report(int argc, wchar_t** argv) { | |
| 37 volatile int idx = 42; | |
| 38 int *blah = new int[42]; | |
| 39 blah[idx] = 42; | |
| 40 return SBOX_TEST_FAILED; | |
| 41 } | |
| 42 | |
| 43 #if defined(ADDRESS_SANITIZER) | |
|
rvargas (doing something else)
2015/02/02 20:55:58
Can we just have the whole test inside the ifdef?
Timur Iskhodzhanov
2015/02/02 21:28:38
The idea behind using MAYBE_ here was that I want
rvargas (doing something else)
2015/02/03 00:42:29
That's a good point. Maybe we need another name fo
Timur Iskhodzhanov
2015/02/03 13:25:22
Why do you think disabling tests leads to regressi
rvargas (doing something else)
2015/02/03 19:47:11
What I've seen happening with disabled tests is th
| |
| 44 #define MAYBE_TestAddressSanitizer TestAddressSanitizer | |
| 45 #else | |
| 46 #define MAYBE_TestAddressSanitizer DISABLED_TestAddressSanitizer | |
| 47 #endif | |
| 48 TEST_F(AddressSanitizerTests, MAYBE_TestAddressSanitizer) { | |
| 49 wchar_t temp_directory[MAX_PATH]; | |
| 50 wchar_t temp_file_name[MAX_PATH]; | |
| 51 ASSERT_NE(::GetTempPath(MAX_PATH, temp_directory), 0u); | |
| 52 ASSERT_NE(::GetTempFileName(temp_directory, L"test", 0, temp_file_name), 0u); | |
| 53 | |
| 54 SECURITY_ATTRIBUTES attrs = {}; | |
| 55 attrs.nLength = sizeof(attrs); | |
| 56 attrs.bInheritHandle = TRUE; | |
| 57 HANDLE file_handle = CreateFile( | |
| 58 temp_file_name, GENERIC_WRITE, | |
| 59 FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE, | |
| 60 &attrs, OPEN_EXISTING, 0, NULL); | |
| 61 ASSERT_NE(file_handle, INVALID_HANDLE_VALUE); | |
| 62 | |
| 63 TestRunner runner; | |
| 64 ASSERT_EQ(SBOX_ALL_OK, runner.GetPolicy()->SetStderrHandle(file_handle)); | |
| 65 | |
| 66 base::FilePath exe; | |
| 67 ASSERT_TRUE(PathService::Get(base::FILE_EXE, &exe); | |
| 68 base::FilePath pdb_path = exe.DirName().Append(L"*.pdb"); | |
| 69 ASSERT_TRUE(runner.AddFsRule(sandbox::TargetPolicy::FILES_ALLOW_READONLY, | |
| 70 pdb_path.value().c_str())); | |
| 71 | |
| 72 env_->SetVar("ASAN_OPTIONS", "exitcode=123"); | |
| 73 int result = runner.RunTest(L"AddressSanitizerTests_Report"); | |
| 74 EXPECT_EQ(123, result); | |
| 75 EXPECT_TRUE(::CloseHandle(file_handle)); | |
| 76 | |
| 77 std::string data; | |
| 78 ASSERT_TRUE(base::ReadFileToString(base::FilePath(temp_file_name), &data)); | |
| 79 // Redirection uses a feature that was added in Windows Vista. | |
| 80 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { | |
| 81 ASSERT_TRUE(strstr(data.c_str(), "ERROR: AddressSanitizer")) | |
| 82 << "There doesn't seem to be an ASan report:\n" << data; | |
| 83 ASSERT_TRUE(strstr(data.c_str(), "AddressSanitizerTests_Report")) | |
| 84 << "The ASan report doesn't appear to be symbolized:\n" << data; | |
| 85 ASSERT_TRUE(strstr(data.c_str(), strrchr(__FILE__, '\\'))) | |
| 86 << "The stack trace doesn't have a correct filename:\n" << data; | |
| 87 } else { | |
| 88 EXPECT_EQ("", data); | |
| 89 } | |
| 90 | |
| 91 EXPECT_TRUE(::DeleteFile(temp_file_name)); | |
| 92 } | |
| 93 | |
| 94 } | |
| OLD | NEW |