Coverage for /Syzygy/agent/asan/memory_notifiers/shadow_memory_notifier_unittest.cc

CoverageLines executed / instrumented / missingexe / inst / missLanguageGroup
100.0%36360.C++test

Line-by-line coverage:

   1    :  // Copyright 2014 Google Inc. All Rights Reserved.
   2    :  //
   3    :  // Licensed under the Apache License, Version 2.0 (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
   6    :  //
   7    :  //     http://www.apache.org/licenses/LICENSE-2.0
   8    :  //
   9    :  // Unless required by applicable law or agreed to in writing, software
  10    :  // distributed under the License is distributed on an "AS IS" BASIS,
  11    :  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12    :  // See the License for the specific language governing permissions and
  13    :  // limitations under the License.
  14    :  
  15    :  #include "syzygy/agent/asan/memory_notifiers/shadow_memory_notifier.h"
  16    :  
  17    :  #include <memory>
  18    :  
  19    :  #include "gtest/gtest.h"
  20    :  #include "syzygy/agent/asan/shadow.h"
  21    :  
  22    :  namespace agent {
  23    :  namespace asan {
  24    :  namespace memory_notifiers {
  25    :  
  26    :  namespace {
  27    :  
  28    :  class ShadowMemoryNotifierTest : public testing::Test {
  29    :   public:
  30  E :    virtual void SetUp() override {
  31  E :      shadow_.SetUp();
  32  E :    }
  33    :  
  34  E :    virtual void TearDown() override {
  35  E :      shadow_.TearDown();
  36  E :    }
  37    :  
  38    :    Shadow shadow_;
  39    :  };
  40    :  
  41    :  }  // namespace
  42    :  
  43  E :  TEST_F(ShadowMemoryNotifierTest, ShadowStateTransitionsWithNotification) {
  44    :    // A buffer to use. This is allocated dynamically to ensure it has 8 byte
  45    :    // alignment.
  46  E :    const size_t kBufferSize = 1024;
  47  E :    std::unique_ptr<uint8_t[]> buffer(new uint8_t[kBufferSize]);
  48    :  
  49  E :    ShadowMemoryNotifier n(&shadow_);
  50  E :    n.NotifyInternalUse(buffer.get(), kBufferSize);
  51  E :    EXPECT_FALSE(shadow_.IsAccessible(buffer.get()));
  52  E :    EXPECT_FALSE(shadow_.IsAccessible(buffer.get() + 10));
  53  E :    EXPECT_TRUE(shadow_.IsAccessible(buffer.get() + kBufferSize));
  54  E :    for (size_t i = 0; i < kBufferSize; ++i) {
  55  E :      EXPECT_EQ(kAsanMemoryMarker,
  56  E :                shadow_.GetShadowMarkerForAddress(buffer.get() + i));
  57  E :    }
  58    :  
  59  E :    n.NotifyFutureHeapUse(buffer.get(), kBufferSize);
  60  E :    EXPECT_FALSE(shadow_.IsAccessible(buffer.get()));
  61  E :    EXPECT_FALSE(shadow_.IsAccessible(buffer.get() + 10));
  62  E :    EXPECT_TRUE(shadow_.IsAccessible(buffer.get() + kBufferSize));
  63  E :    for (size_t i = 0; i < kBufferSize; ++i) {
  64  E :      EXPECT_EQ(kAsanReservedMarker,
  65  E :                shadow_.GetShadowMarkerForAddress(buffer.get() + i));
  66  E :    }
  67    :  
  68  E :    n.NotifyReturnedToOS(buffer.get(), kBufferSize);
  69  E :    EXPECT_TRUE(shadow_.IsAccessible(buffer.get()));
  70  E :    EXPECT_TRUE(shadow_.IsAccessible(buffer.get() + 10));
  71  E :    EXPECT_TRUE(shadow_.IsAccessible(buffer.get() + kBufferSize));
  72  E :    for (size_t i = 0; i < kBufferSize; ++i) {
  73  E :      EXPECT_EQ(kHeapAddressableMarker,
  74  E :                shadow_.GetShadowMarkerForAddress(buffer.get() + i));
  75  E :    }
  76    :  
  77  E :    EXPECT_TRUE(shadow_.IsClean());
  78  E :  }
  79    :  
  80    :  }  // namespace memory_notifiers
  81    :  }  // namespace asan
  82    :  }  // namespace agent

Coverage information generated Fri Jul 29 11:00:21 2016.