| OLD | NEW |
| 1 // Copyright 2012 Google Inc. All Rights Reserved. | 1 // Copyright 2012 Google Inc. All Rights Reserved. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. | 13 // limitations under the License. |
| 14 | 14 |
| 15 #include "syzygy/agent/asan/rtl_impl.h" | 15 #include "syzygy/agent/asan/rtl_impl.h" |
| 16 | 16 |
| 17 #include <windows.h> // NOLINT | 17 #include <windows.h> // NOLINT |
| 18 | 18 |
| 19 #include "base/rand_util.h" | 19 #include "base/rand_util.h" |
| 20 #include "gtest/gtest.h" | 20 #include "gtest/gtest.h" |
| 21 #include "syzygy/agent/asan/runtime.h" | 21 #include "syzygy/agent/asan/runtime.h" |
| 22 #include "syzygy/agent/asan/shadow.h" | 22 #include "syzygy/agent/asan/shadow.h" |
| 23 #include "syzygy/agent/asan/unittest_util.h" | 23 #include "syzygy/agent/asan/unittest_util.h" |
| 24 #include "syzygy/core/unittest_util.h" | 24 #include "syzygy/core/unittest_util.h" |
| 25 | 25 |
| 26 namespace agent { |
| 27 namespace asan { |
| 28 |
| 26 namespace { | 29 namespace { |
| 27 | 30 |
| 28 class AsanRtlImplTest : public testing::TestWithAsanLogger { | 31 class AsanRtlImplTest : public testing::TestWithAsanLogger { |
| 29 public: | 32 public: |
| 30 AsanRtlImplTest() : heap_(NULL) { | 33 AsanRtlImplTest() : heap_(NULL) { |
| 31 } | 34 } |
| 32 | 35 |
| 33 void SetUp() override { | 36 void SetUp() override { |
| 34 testing::TestWithAsanLogger::SetUp(); | 37 testing::TestWithAsanLogger::SetUp(); |
| 35 asan_runtime_.SetUp(std::wstring()); | 38 asan_runtime_.SetUp(runtime_command_line_); |
| 36 agent::asan::SetUpRtl(&asan_runtime_); | 39 agent::asan::SetUpRtl(&asan_runtime_); |
| 37 heap_ = asan_HeapCreate(0, 0, 0); | 40 heap_ = asan_HeapCreate(0, 0, 0); |
| 38 ASSERT_TRUE(heap_ != NULL); | 41 ASSERT_TRUE(heap_ != NULL); |
| 39 } | 42 } |
| 40 | 43 |
| 41 void TearDown() override { | 44 void TearDown() override { |
| 42 if (heap_ != NULL) { | 45 if (heap_ != NULL) { |
| 43 asan_HeapDestroy(heap_); | 46 asan_HeapDestroy(heap_); |
| 44 heap_ = NULL; | 47 heap_ = NULL; |
| 45 } | 48 } |
| 46 agent::asan::TearDownRtl(); | 49 agent::asan::TearDownRtl(); |
| 47 asan_runtime_.TearDown(); | 50 asan_runtime_.TearDown(); |
| 48 testing::TestWithAsanLogger::TearDown(); | 51 testing::TestWithAsanLogger::TearDown(); |
| 49 } | 52 } |
| 50 | 53 |
| 51 protected: | 54 protected: |
| 52 agent::asan::AsanRuntime asan_runtime_; | 55 agent::asan::AsanRuntime asan_runtime_; |
| 53 | 56 |
| 54 // Arbitrary constant for all size limit. | 57 // Arbitrary constant for all size limit. |
| 55 static const size_t kMaxAllocSize = 134584; | 58 static const size_t kMaxAllocSize = 134584; |
| 56 | 59 |
| 57 // Scratch heap handle valid from SetUp to TearDown. | 60 // Scratch heap handle valid from SetUp to TearDown. |
| 58 HANDLE heap_; | 61 HANDLE heap_; |
| 62 |
| 63 // The command line used to initialize the runtime. Empty by default but |
| 64 // can be override by the derived classes to enable some runtime flags |
| 65 // during setup. |
| 66 std::wstring runtime_command_line_; |
| 59 }; | 67 }; |
| 60 | 68 |
| 61 } // namespace | 69 } // namespace |
| 62 | 70 |
| 63 TEST_F(AsanRtlImplTest, CreateDestroy) { | 71 TEST_F(AsanRtlImplTest, CreateDestroy) { |
| 64 HANDLE heap = asan_HeapCreate(0, 0, 0); | 72 HANDLE heap = asan_HeapCreate(0, 0, 0); |
| 65 ASSERT_TRUE(heap != NULL); | 73 ASSERT_TRUE(heap != NULL); |
| 66 ASSERT_TRUE(asan_HeapDestroy(heap)); | 74 ASSERT_TRUE(asan_HeapDestroy(heap)); |
| 67 } | 75 } |
| 68 | 76 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 &compat_flag, sizeof(compat_flag))); | 152 &compat_flag, sizeof(compat_flag))); |
| 145 } | 153 } |
| 146 | 154 |
| 147 TEST_F(AsanRtlImplTest, SetInformationWithNullHeapPtr) { | 155 TEST_F(AsanRtlImplTest, SetInformationWithNullHeapPtr) { |
| 148 // The documentation of HeapSetInformation specify that the heap handle is | 156 // The documentation of HeapSetInformation specify that the heap handle is |
| 149 // optional. | 157 // optional. |
| 150 ASSERT_TRUE( | 158 ASSERT_TRUE( |
| 151 asan_HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, | 159 asan_HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, |
| 152 NULL, 0)); | 160 NULL, 0)); |
| 153 } | 161 } |
| 162 |
| 163 namespace { |
| 164 |
| 165 // Derived class that defers the crash reporter initialization. |
| 166 class AsanRtlImplTestCrashReporterInitialization : public AsanRtlImplTest { |
| 167 public: |
| 168 AsanRtlImplTestCrashReporterInitialization() { |
| 169 runtime_command_line_ = L"--defer_crash_reporter_initialization"; |
| 170 } |
| 171 }; |
| 172 |
| 173 } // namespace |
| 174 |
| 175 TEST_F(AsanRtlImplTestCrashReporterInitialization, InitializeCrashReporter) { |
| 176 EXPECT_FALSE(asan_runtime_.crash_reporter_initialized()); |
| 177 asan_InitializeCrashReporter(); |
| 178 EXPECT_TRUE(asan_runtime_.crash_reporter_initialized()); |
| 179 } |
| 180 |
| 181 } // namespace asan |
| 182 } // namespace agent |
| OLD | NEW |