OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 14 matching lines...) Expand all Loading... | |
25 // EXPECT_DEATH is not supported on IOS. | 25 // EXPECT_DEATH is not supported on IOS. |
26 #define HARMFUL_ACCESS(action,error_regexp) do { action; } while (0) | 26 #define HARMFUL_ACCESS(action,error_regexp) do { action; } while (0) |
27 #else | 27 #else |
28 #define HARMFUL_ACCESS(action,error_regexp) EXPECT_DEATH(action,error_regexp) | 28 #define HARMFUL_ACCESS(action,error_regexp) EXPECT_DEATH(action,error_regexp) |
29 #endif // !OS_IOS | 29 #endif // !OS_IOS |
30 #else | 30 #else |
31 #define HARMFUL_ACCESS(action,error_regexp) \ | 31 #define HARMFUL_ACCESS(action,error_regexp) \ |
32 do { if (RunningOnValgrind()) { action; } } while (0) | 32 do { if (RunningOnValgrind()) { action; } } while (0) |
33 #endif | 33 #endif |
34 | 34 |
35 void ReadUninitializedValue(char *ptr) { | 35 void DoReadUninitializedValue(char *ptr) { |
36 // Comparison with 64 is to prevent clang from optimizing away the | 36 // Comparison with 64 is to prevent clang from optimizing away the |
37 // jump -- valgrind only catches jumps and conditional moves, but clang uses | 37 // jump -- valgrind only catches jumps and conditional moves, but clang uses |
38 // the borrow flag if the condition is just `*ptr == '\0'`. | 38 // the borrow flag if the condition is just `*ptr == '\0'`. |
39 if (*ptr == 64) { | 39 if (*ptr == 64) { |
40 (*ptr)++; | 40 VLOG(1) << "Uninit condition is true"; |
Nico
2014/01/15 17:46:18
why this change?
| |
41 } else { | 41 } else { |
42 (*ptr)--; | 42 VLOG(1) << "Uninit condition is false"; |
43 } | 43 } |
44 } | 44 } |
45 | 45 |
46 void ReadUninitializedValue(char *ptr) { | |
47 #if defined(MEMORY_SANITIZER) | |
48 EXPECT_DEATH(DoReadUninitializedValue(ptr), | |
49 "use-of-uninitialized-value"); | |
50 #else | |
51 DoReadUninitializedValue(ptr); | |
52 #endif | |
53 } | |
54 | |
46 void ReadValueOutOfArrayBoundsLeft(char *ptr) { | 55 void ReadValueOutOfArrayBoundsLeft(char *ptr) { |
47 char c = ptr[-2]; | 56 char c = ptr[-2]; |
48 VLOG(1) << "Reading a byte out of bounds: " << c; | 57 VLOG(1) << "Reading a byte out of bounds: " << c; |
49 } | 58 } |
50 | 59 |
51 void ReadValueOutOfArrayBoundsRight(char *ptr, size_t size) { | 60 void ReadValueOutOfArrayBoundsRight(char *ptr, size_t size) { |
52 char c = ptr[size + 1]; | 61 char c = ptr[size + 1]; |
53 VLOG(1) << "Reading a byte out of bounds: " << c; | 62 VLOG(1) << "Reading a byte out of bounds: " << c; |
54 } | 63 } |
55 | 64 |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
265 | 274 |
266 TEST(ToolsSanityTest, AtomicsAreIgnored) { | 275 TEST(ToolsSanityTest, AtomicsAreIgnored) { |
267 base::subtle::Atomic32 shared = 0; | 276 base::subtle::Atomic32 shared = 0; |
268 ReleaseStoreThread thread1(&shared); | 277 ReleaseStoreThread thread1(&shared); |
269 AcquireLoadThread thread2(&shared); | 278 AcquireLoadThread thread2(&shared); |
270 RunInParallel(&thread1, &thread2); | 279 RunInParallel(&thread1, &thread2); |
271 EXPECT_EQ(kMagicValue, shared); | 280 EXPECT_EQ(kMagicValue, shared); |
272 } | 281 } |
273 | 282 |
274 } // namespace base | 283 } // namespace base |
OLD | NEW |