Coverage for /Syzygy/agent/asan/stack_capture_unittest.cc

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

Line-by-line coverage:

   1    :  // Copyright 2013 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/stack_capture.h"
  16    :  
  17    :  #include "base/memory/scoped_ptr.h"
  18    :  #include "gtest/gtest.h"
  19    :  
  20    :  namespace agent {
  21    :  namespace asan {
  22    :  
  23  E :  TEST(StackCaptureTest, InitFromBuffer) {
  24  E :    StackCapture capture;
  25    :  
  26    :    // Validate the capture's initial state.
  27  E :    EXPECT_FALSE(capture.IsValid());
  28  E :    EXPECT_EQ(0u, capture.stack_id());
  29  E :    EXPECT_EQ(0, capture.num_frames());
  30  E :    EXPECT_EQ(StackCapture::kMaxNumFrames, capture.max_num_frames());
  31  E :    EXPECT_EQ(NULL, capture.frames());
  32    :  
  33    :    // Create some fake stack trace data.
  34  E :    ULONG stack_id = 10;
  35  E :    void* frames[StackCapture::kMaxNumFrames + 1] = { 0 };
  36  E :    for (size_t i = 0; i < arraysize(frames); ++i) {
  37  E :      frames[i] = reinterpret_cast<void*>(i);
  38  E :    }
  39    :  
  40    :    // Initialize the stack capture without using all of the frames.
  41  E :    capture.InitFromBuffer(stack_id, frames, 7);
  42  E :    EXPECT_TRUE(capture.IsValid());
  43  E :    EXPECT_EQ(10u, capture.stack_id());
  44  E :    EXPECT_EQ(7, capture.num_frames());
  45  E :    EXPECT_EQ(StackCapture::kMaxNumFrames, capture.max_num_frames());
  46  E :    EXPECT_TRUE(capture.frames() != NULL);
  47    :  
  48    :    // Attempt to initialize the stack capture using too many frames; the
  49    :    // resulting capture should truncate to kMaxNumFrames.
  50  E :    capture.InitFromBuffer(stack_id, frames, arraysize(frames));
  51  E :    EXPECT_TRUE(capture.IsValid());
  52  E :    EXPECT_EQ(10u, capture.stack_id());
  53  E :    EXPECT_EQ(StackCapture::kMaxNumFrames, capture.num_frames());
  54  E :    EXPECT_EQ(StackCapture::kMaxNumFrames, capture.max_num_frames());
  55  E :    EXPECT_TRUE(capture.frames() != NULL);
  56  E :  }
  57    :  
  58  E :  TEST(StackCaptureTest, InitFromStack) {
  59  E :    StackCapture capture;
  60  E :    EXPECT_FALSE(capture.IsValid());
  61  E :    EXPECT_EQ(0u, capture.stack_id());
  62  E :    EXPECT_EQ(0, capture.num_frames());
  63  E :    EXPECT_EQ(StackCapture::kMaxNumFrames, capture.max_num_frames());
  64    :  
  65  E :    capture.InitFromStack();
  66  E :    EXPECT_TRUE(capture.IsValid());
  67  E :    EXPECT_LT(0u, capture.num_frames());
  68  E :    EXPECT_EQ(StackCapture::kMaxNumFrames, capture.max_num_frames());
  69  E :  }
  70    :  
  71  E :  TEST(StackCaptureTest, RestrictedFrameCount) {
  72  E :    StackCapture::set_bottom_frames_to_skip(0);
  73    :    // Restrict this to a stack depth that is smaller than the stack depth of
  74    :    // this test.
  75  E :    StackCapture capture(5);
  76  E :    EXPECT_FALSE(capture.IsValid());
  77  E :    EXPECT_EQ(0u, capture.stack_id());
  78  E :    EXPECT_EQ(0, capture.num_frames());
  79  E :    EXPECT_EQ(5u, capture.max_num_frames());
  80    :  
  81  E :    capture.InitFromStack();
  82  E :    EXPECT_TRUE(capture.IsValid());
  83  E :    EXPECT_EQ(5u, capture.num_frames());
  84  E :    EXPECT_EQ(5u, capture.max_num_frames());
  85  E :  }
  86    :  
  87    :  }  // namespace asan
  88    :  }  // namespace agent

Coverage information generated Thu Mar 14 11:53:36 2013.