| 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, |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 ASSERT_FALSE(internal::IsZeroBufferImpl<AccessType>(buf + i, end - j)); | 72 ASSERT_FALSE(internal::IsZeroBufferImpl<AccessType>(buf + i, end - j)); |
| 73 buf[k] = 0; | 73 buf[k] = 0; |
| 74 } | 74 } |
| 75 } | 75 } |
| 76 } | 76 } |
| 77 } | 77 } |
| 78 | 78 |
| 79 // A derived class to expose protected members for unit-testing. | 79 // A derived class to expose protected members for unit-testing. |
| 80 class TestShadow : public Shadow { | 80 class TestShadow : public Shadow { |
| 81 public: | 81 public: |
| 82 TestShadow() : Shadow(kTestShadowSize) { | 82 TestShadow() : Shadow(kDefaultTestShadowSize) { |
| 83 } |
| 84 |
| 85 TestShadow(size_t digits, size_t power) |
| 86 : Shadow(digits << (power - kShadowRatioLog)) { |
| 83 } | 87 } |
| 84 | 88 |
| 85 // We'll simulate memory as being 1GB in size. | 89 // We'll simulate memory as being 1GB in size. |
| 86 static const size_t kTestShadowSize = | 90 static const size_t kDefaultTestShadowSize = |
| 87 (1 * 1024 * 1024 * 1024) >> kShadowRatioLog; | 91 (1 * 1024 * 1024 * 1024) >> kShadowRatioLog; |
| 88 | 92 |
| 89 // Protected functions that we want to unittest directly. | 93 // Protected functions that we want to unittest directly. |
| 90 using Shadow::Reset; | 94 using Shadow::Reset; |
| 91 using Shadow::ScanLeftForBracketingBlockStart; | 95 using Shadow::ScanLeftForBracketingBlockStart; |
| 92 using Shadow::ScanRightForBracketingBlockEnd; | 96 using Shadow::ScanRightForBracketingBlockEnd; |
| 93 using Shadow::shadow_; | 97 using Shadow::shadow_; |
| 94 }; | 98 }; |
| 95 | 99 |
| 96 // A fixture for shadow memory tests. | 100 // A fixture for shadow memory tests. |
| (...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 namespace { | 746 namespace { |
| 743 | 747 |
| 744 // A fixture for shadow walker tests. | 748 // A fixture for shadow walker tests. |
| 745 class ShadowWalkerTest : public testing::Test { | 749 class ShadowWalkerTest : public testing::Test { |
| 746 public: | 750 public: |
| 747 TestShadow test_shadow; | 751 TestShadow test_shadow; |
| 748 }; | 752 }; |
| 749 | 753 |
| 750 } // namespace | 754 } // namespace |
| 751 | 755 |
| 756 TEST_F(ShadowWalkerTest, WalkEmptyRange) { |
| 757 ShadowWalker w(&test_shadow, true, &test_shadow, &test_shadow); |
| 758 BlockInfo i = {}; |
| 759 EXPECT_FALSE(w.Next(&i)); |
| 760 } |
| 761 |
| 762 TEST_F(ShadowWalkerTest, WalkRangeAtEndOfAddressSpace) { |
| 763 TestShadow ts1(4, 30); // 4GB. |
| 764 ShadowWalker w( |
| 765 &ts1, true, |
| 766 reinterpret_cast<const void*>(ts1.memory_size() - 100), |
| 767 reinterpret_cast<const void*>(ts1.memory_size())); |
| 768 BlockInfo i = {}; |
| 769 EXPECT_FALSE(w.Next(&i)); |
| 770 } |
| 771 |
| 752 TEST_F(ShadowWalkerTest, WalksNonNestedBlocks) { | 772 TEST_F(ShadowWalkerTest, WalksNonNestedBlocks) { |
| 753 BlockLayout l = {}; | 773 BlockLayout l = {}; |
| 754 EXPECT_TRUE(BlockPlanLayout(kShadowRatio, kShadowRatio, 7, 0, 0, &l)); | 774 EXPECT_TRUE(BlockPlanLayout(kShadowRatio, kShadowRatio, 7, 0, 0, &l)); |
| 755 | 775 |
| 756 size_t data_size = l.block_size * 3 + kShadowRatio; | 776 size_t data_size = l.block_size * 3 + kShadowRatio; |
| 757 uint8_t* data = new uint8_t[data_size]; | 777 uint8_t* data = new uint8_t[data_size]; |
| 758 uint8_t* data0 = data; | 778 uint8_t* data0 = data; |
| 759 uint8_t* data1 = data0 + l.block_size + kShadowRatio; | 779 uint8_t* data1 = data0 + l.block_size + kShadowRatio; |
| 760 uint8_t* data2 = data1 + l.block_size; | 780 uint8_t* data2 = data1 + l.block_size; |
| 761 | 781 |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 895 EXPECT_EQ(0, ::memcmp(&i, &i2, sizeof(i))); | 915 EXPECT_EQ(0, ::memcmp(&i, &i2, sizeof(i))); |
| 896 EXPECT_FALSE(w1.Next(&i)); | 916 EXPECT_FALSE(w1.Next(&i)); |
| 897 EXPECT_EQ(-1, w1.nesting_depth()); | 917 EXPECT_EQ(-1, w1.nesting_depth()); |
| 898 | 918 |
| 899 test_shadow.Unpoison(data, data_size); | 919 test_shadow.Unpoison(data, data_size); |
| 900 delete [] data; | 920 delete [] data; |
| 901 } | 921 } |
| 902 | 922 |
| 903 } // namespace asan | 923 } // namespace asan |
| 904 } // namespace agent | 924 } // namespace agent |
| OLD | NEW |