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

Unified Diff: sandbox/win/src/address_sanitizer_test.cc

Issue 868253011: Make chrome.exe built with ASan/Win work with sandbox enabled (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: compile but not run all the test w/o ASan Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sandbox/win/sandbox_win.gypi ('k') | sandbox/win/src/handle_inheritance_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sandbox/win/src/address_sanitizer_test.cc
diff --git a/sandbox/win/src/address_sanitizer_test.cc b/sandbox/win/src/address_sanitizer_test.cc
new file mode 100644
index 0000000000000000000000000000000000000000..26ac53af9d6fce60dfb8e1571097cf76c1b9c7d9
--- /dev/null
+++ b/sandbox/win/src/address_sanitizer_test.cc
@@ -0,0 +1,104 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <stdio.h>
+
+#include "base/environment.h"
+#include "base/files/file_path.h"
+#include "base/files/file_util.h"
+#include "base/path_service.h"
+#include "base/win/windows_version.h"
+#include "sandbox/win/tests/common/controller.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace sandbox {
+
+class AddressSanitizerTests : public ::testing::Test {
+ public:
+ void SetUp() {
+ env_.reset(base::Environment::Create());
+ had_asan_options_ = env_->GetVar("ASAN_OPTIONS", &old_asan_options_);
+ }
+
+ void TearDown() {
+ if (had_asan_options_)
+ ASSERT_TRUE(env_->SetVar("ASAN_OPTIONS", old_asan_options_));
+ else
+ env_->UnSetVar("ASAN_OPTIONS");
+ }
+
+ protected:
+ scoped_ptr<base::Environment> env_;
+ bool had_asan_options_;
+ std::string old_asan_options_;
+};
+
+SBOX_TESTS_COMMAND int AddressSanitizerTests_Report(int argc, wchar_t** argv) {
+ volatile int idx = 42;
+ int *blah = new int[42];
cpu_(ooo_6.6-7.5) 2015/02/04 20:59:55 state what errors we should see from asan, what wo
Timur Iskhodzhanov 2015/02/05 08:15:51 Done. The memory leak was not important, but I've
+ blah[idx] = 42;
+ return SBOX_TEST_FAILED;
+}
+
+TEST_F(AddressSanitizerTests, TestAddressSanitizer) {
+ // This test is only supposed to work when using AddressSanitizer.
+ // However, ASan/Win is not on the CQ yet, so compiler breakages may get into
+ // the code unnoticed. To avoid that, we compile this test in all Windows
+ // builds, but only run the AddressSanitizer-specific part of the test when
+ // compiled with AddressSanitizer.
+#if defined(ADDRESS_SANITIZER)
Timur Iskhodzhanov 2015/02/04 20:29:57 How about this? Unfortunately, I don't think there
+ bool asan_build = true;
+#else
+ bool asan_build = false;
+#endif
+ wchar_t temp_directory[MAX_PATH];
+ wchar_t temp_file_name[MAX_PATH];
+ ASSERT_NE(::GetTempPath(MAX_PATH, temp_directory), 0u);
+ ASSERT_NE(::GetTempFileName(temp_directory, L"test", 0, temp_file_name), 0u);
cpu_(ooo_6.6-7.5) 2015/02/04 20:59:55 we have scoped temp directory temp file helpers i
Timur Iskhodzhanov 2015/02/05 08:15:51 Done, thanks for the suggestion!
+
+ SECURITY_ATTRIBUTES attrs = {};
+ attrs.nLength = sizeof(attrs);
+ attrs.bInheritHandle = TRUE;
+ HANDLE file_handle = CreateFile(
+ temp_file_name, GENERIC_WRITE,
+ FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE,
+ &attrs, OPEN_EXISTING, 0, NULL);
+ ASSERT_NE(file_handle, INVALID_HANDLE_VALUE);
+
+ TestRunner runner;
+ ASSERT_EQ(SBOX_ALL_OK, runner.GetPolicy()->SetStderrHandle(file_handle));
+
+ base::FilePath exe;
+ ASSERT_TRUE(PathService::Get(base::FILE_EXE, &exe));
+ base::FilePath pdb_path = exe.DirName().Append(L"*.pdb");
+ ASSERT_TRUE(runner.AddFsRule(sandbox::TargetPolicy::FILES_ALLOW_READONLY,
+ pdb_path.value().c_str()));
Timur Iskhodzhanov 2015/02/04 20:29:57 Please note I actually run the ASan-inspecific par
+
+ env_->SetVar("ASAN_OPTIONS", "exitcode=123");
+ if (asan_build) {
+ int result = runner.RunTest(L"AddressSanitizerTests_Report");
+ EXPECT_EQ(123, result);
+ EXPECT_TRUE(::CloseHandle(file_handle));
+
+ std::string data;
+ ASSERT_TRUE(base::ReadFileToString(base::FilePath(temp_file_name), &data));
+ // Redirection uses a feature that was added in Windows Vista.
+ if (base::win::GetVersion() >= base::win::VERSION_VISTA) {
+ ASSERT_TRUE(strstr(data.c_str(), "ERROR: AddressSanitizer"))
+ << "There doesn't seem to be an ASan report:\n" << data;
+ ASSERT_TRUE(strstr(data.c_str(), "AddressSanitizerTests_Report"))
+ << "The ASan report doesn't appear to be symbolized:\n" << data;
+ ASSERT_TRUE(strstr(data.c_str(), strrchr(__FILE__, '\\')))
+ << "The stack trace doesn't have a correct filename:\n" << data;
+ } else {
+ LOG(WARNING) << "Pre-Vista versions are not supported.";
+ }
+ } else {
+ LOG(WARNING) << "Not an AddressSanitizer build, skipping the run.";
+ }
+
+ EXPECT_TRUE(::DeleteFile(temp_file_name));
+}
+
+}
« no previous file with comments | « sandbox/win/sandbox_win.gypi ('k') | sandbox/win/src/handle_inheritance_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698