OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // This file contains intentional memory errors, some of which may lead to | 5 // This file contains intentional memory errors, some of which may lead to |
6 // crashes if the test is ran without special memory testing tools. We use these | 6 // crashes if the test is ran without special memory testing tools. We use these |
7 // errors to verify the sanity of the tools. | 7 // errors to verify the sanity of the tools. |
8 | 8 |
9 #include "base/atomicops.h" | 9 #include "base/atomicops.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 return; | 116 return; |
117 #endif | 117 #endif |
118 | 118 |
119 // Without the |volatile|, clang optimizes away the next two lines. | 119 // Without the |volatile|, clang optimizes away the next two lines. |
120 int* volatile foo = new int; | 120 int* volatile foo = new int; |
121 (void) foo; | 121 (void) foo; |
122 delete [] foo; | 122 delete [] foo; |
123 } | 123 } |
124 | 124 |
125 #ifdef ADDRESS_SANITIZER | 125 #ifdef ADDRESS_SANITIZER |
126 TEST(ToolsSanityTest, DISABLED_AddressSanitizerCrashTest) { | 126 TEST(ToolsSanityTest, DISABLED_AddressSanitizerNullDerefCrashTest) { |
127 // Intentionally crash to make sure AddressSanitizer is running. | 127 // Intentionally crash to make sure AddressSanitizer is running. |
128 // This test should not be ran on bots. | 128 // This test should not be ran on bots. |
129 int* volatile zero = NULL; | 129 int* volatile zero = NULL; |
130 *zero = 0; | 130 *zero = 0; |
131 } | 131 } |
| 132 |
| 133 TEST(ToolsSanityTest, DISABLED_AddressSanitizerLocalOOBCrashTest) { |
| 134 // Intentionally crash to make sure AddressSanitizer is instrumenting |
| 135 // the local variables. |
| 136 // This test should not be ran on bots. |
| 137 int array[5]; |
| 138 // Work around the OOB warning reported by Clang. |
| 139 int* volatile access = &array[5]; |
| 140 *access = 43; |
| 141 } |
| 142 |
| 143 namespace { |
| 144 int g_asan_test_global_array[10]; |
| 145 } // namespace |
| 146 |
| 147 TEST(ToolsSanityTest, DISABLED_AddressSanitizerGlobalOOBCrashTest) { |
| 148 // Intentionally crash to make sure AddressSanitizer is instrumenting |
| 149 // the global variables. |
| 150 // This test should not be ran on bots. |
| 151 |
| 152 // Work around the OOB warning reported by Clang. |
| 153 int* volatile access = g_asan_test_global_array - 1; |
| 154 *access = 43; |
| 155 } |
| 156 |
132 #endif | 157 #endif |
133 | 158 |
134 namespace { | 159 namespace { |
135 | 160 |
136 // We use caps here just to ensure that the method name doesn't interfere with | 161 // We use caps here just to ensure that the method name doesn't interfere with |
137 // the wildcarded suppressions. | 162 // the wildcarded suppressions. |
138 class TOOLS_SANITY_TEST_CONCURRENT_THREAD : public PlatformThread::Delegate { | 163 class TOOLS_SANITY_TEST_CONCURRENT_THREAD : public PlatformThread::Delegate { |
139 public: | 164 public: |
140 explicit TOOLS_SANITY_TEST_CONCURRENT_THREAD(bool *value) : value_(value) {} | 165 explicit TOOLS_SANITY_TEST_CONCURRENT_THREAD(bool *value) : value_(value) {} |
141 ~TOOLS_SANITY_TEST_CONCURRENT_THREAD() {} | 166 ~TOOLS_SANITY_TEST_CONCURRENT_THREAD() {} |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 | 234 |
210 TEST(ToolsSanityTest, AtomicsAreIgnored) { | 235 TEST(ToolsSanityTest, AtomicsAreIgnored) { |
211 base::subtle::Atomic32 shared = 0; | 236 base::subtle::Atomic32 shared = 0; |
212 ReleaseStoreThread thread1(&shared); | 237 ReleaseStoreThread thread1(&shared); |
213 AcquireLoadThread thread2(&shared); | 238 AcquireLoadThread thread2(&shared); |
214 RunInParallel(&thread1, &thread2); | 239 RunInParallel(&thread1, &thread2); |
215 EXPECT_EQ(kMagicValue, shared); | 240 EXPECT_EQ(kMagicValue, shared); |
216 } | 241 } |
217 | 242 |
218 } // namespace base | 243 } // namespace base |
OLD | NEW |