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.h" | 10 #include "base/message_loop.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 // Helper for memory accesses that can potentially corrupt memory or cause a | 21 // Helper for memory accesses that can potentially corrupt memory or cause a |
22 // crash during a native run. | 22 // crash during a native run. |
23 #ifdef ADDRESS_SANITIZER | 23 #ifdef ADDRESS_SANITIZER |
24 #define HARMFUL_ACCESS(action,error_regexp) EXPECT_DEATH(action,error_regexp) | 24 #define HARMFUL_ACCESS(action,error_regexp) EXPECT_DEATH(action,error_regexp) |
25 #else | 25 #else |
26 #define HARMFUL_ACCESS(action,error_regexp) \ | 26 #define HARMFUL_ACCESS(action,error_regexp) \ |
27 do { if (RunningOnValgrind()) { action; } } while (0) | 27 do { if (RunningOnValgrind()) { action; } } while (0) |
28 #endif | 28 #endif |
29 | 29 |
30 void ReadUninitializedValue(char *ptr) { | 30 void ReadUninitializedValue(char *ptr) { |
31 // The || in the conditional is to prevent clang from optimizing away the | 31 // Comparison with 64 is to prevent clang from optimizing away the |
32 // jump -- valgrind only catches jumps and conditional moves, but clang uses | 32 // jump -- valgrind only catches jumps and conditional moves, but clang uses |
33 // the borrow flag if the condition is just `*ptr == '\0'`. | 33 // the borrow flag if the condition is just `*ptr == '\0'`. |
34 if (*ptr == '\0' || *ptr == 64) { | 34 if (*ptr == 64) { |
35 (*ptr)++; | 35 (*ptr)++; |
36 } else { | 36 } else { |
37 (*ptr)--; | 37 (*ptr)--; |
38 } | 38 } |
39 } | 39 } |
40 | 40 |
41 void ReadValueOutOfArrayBoundsLeft(char *ptr) { | 41 void ReadValueOutOfArrayBoundsLeft(char *ptr) { |
42 char c = ptr[-2]; | 42 char c = ptr[-2]; |
43 VLOG(1) << "Reading a byte out of bounds: " << c; | 43 VLOG(1) << "Reading a byte out of bounds: " << c; |
44 } | 44 } |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 | 234 |
235 TEST(ToolsSanityTest, AtomicsAreIgnored) { | 235 TEST(ToolsSanityTest, AtomicsAreIgnored) { |
236 base::subtle::Atomic32 shared = 0; | 236 base::subtle::Atomic32 shared = 0; |
237 ReleaseStoreThread thread1(&shared); | 237 ReleaseStoreThread thread1(&shared); |
238 AcquireLoadThread thread2(&shared); | 238 AcquireLoadThread thread2(&shared); |
239 RunInParallel(&thread1, &thread2); | 239 RunInParallel(&thread1, &thread2); |
240 EXPECT_EQ(kMagicValue, shared); | 240 EXPECT_EQ(kMagicValue, shared); |
241 } | 241 } |
242 | 242 |
243 } // namespace base | 243 } // namespace base |
OLD | NEW |