Coverage for /Syzygy/instrument/instrumenters/entry_call_instrumenter_unittest.cc

CoverageLines executed / instrumented / missingexe / inst / missLanguageGroup
100.0%1151150.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/instrument/instrumenters/entry_call_instrumenter.h"
  16    :  
  17    :  #include "base/command_line.h"
  18    :  #include "gtest/gtest.h"
  19    :  #include "syzygy/core/unittest_util.h"
  20    :  #include "syzygy/pe/unittest_util.h"
  21    :  
  22    :  namespace instrument {
  23    :  namespace instrumenters {
  24    :  
  25    :  namespace {
  26    :  
  27    :  class TestEntryCallInstrumenter : public EntryCallInstrumenter {
  28    :   public:
  29    :    using EntryCallInstrumenter::agent_dll_;
  30    :    using EntryCallInstrumenter::input_image_path_;
  31    :    using EntryCallInstrumenter::input_pdb_path_;
  32    :    using EntryCallInstrumenter::output_image_path_;
  33    :    using EntryCallInstrumenter::output_pdb_path_;
  34    :    using EntryCallInstrumenter::allow_overwrite_;
  35    :    using EntryCallInstrumenter::old_decomposer_;
  36    :    using EntryCallInstrumenter::no_augment_pdb_;
  37    :    using EntryCallInstrumenter::no_strip_strings_;
  38    :    using EntryCallInstrumenter::thunk_imports_;
  39    :    using EntryCallInstrumenter::debug_friendly_;
  40    :    using EntryCallInstrumenter::kAgentDllProfile;
  41    :    using EntryCallInstrumenter::InstrumentImpl;
  42    :    using InstrumenterWithAgent::CreateRelinker;
  43    :  
  44  E :    explicit TestEntryCallInstrumenter() {
  45    :      // Call the GetPERelinker function to initialize it.
  46  E :      EXPECT_TRUE(GetPERelinker() != NULL);
  47  E :    }
  48    :  };
  49    :  
  50    :  class EntryCallInstrumenterTest : public testing::PELibUnitTest {
  51    :   public:
  52    :    typedef testing::PELibUnitTest Super;
  53    :  
  54  E :    EntryCallInstrumenterTest()
  55    :        : cmd_line_(base::FilePath(L"instrument.exe")) {
  56  E :    }
  57    :  
  58  E :    virtual void SetUp() OVERRIDE {
  59  E :      testing::Test::SetUp();
  60    :  
  61    :      // Several of the tests generate progress and (deliberate) error messages
  62    :      // that would otherwise clutter the unittest output.
  63  E :      logging::SetMinLogLevel(logging::LOG_FATAL);
  64    :  
  65    :      // Setup the IO streams.
  66  E :      CreateTemporaryDir(&temp_dir_);
  67  E :      stdin_path_ = temp_dir_.Append(L"NUL");
  68  E :      stdout_path_ = temp_dir_.Append(L"stdout.txt");
  69  E :      stderr_path_ = temp_dir_.Append(L"stderr.txt");
  70  E :      InitStreams(stdin_path_, stdout_path_, stderr_path_);
  71    :  
  72    :      // Initialize the (potential) input and output path values.
  73  E :      abs_input_image_path_ = testing::GetExeRelativePath(testing::kTestDllName);
  74  E :      input_image_path_ = testing::GetRelativePath(abs_input_image_path_);
  75  E :      abs_input_pdb_path_ = testing::GetExeRelativePath(testing::kTestDllPdbName);
  76  E :      input_pdb_path_ = testing::GetRelativePath(abs_input_pdb_path_);
  77  E :      output_image_path_ = temp_dir_.Append(input_image_path_.BaseName());
  78  E :      output_pdb_path_ = temp_dir_.Append(input_pdb_path_.BaseName());
  79  E :    }
  80    :  
  81  E :    void SetUpValidCommandLine() {
  82  E :      cmd_line_.AppendSwitchPath("input-image", input_image_path_);
  83  E :      cmd_line_.AppendSwitchPath("output-image", output_image_path_);
  84  E :    }
  85    :  
  86    :   protected:
  87    :    base::FilePath temp_dir_;
  88    :  
  89    :    // @name The redirected streams paths.
  90    :    // @{
  91    :    base::FilePath stdin_path_;
  92    :    base::FilePath stdout_path_;
  93    :    base::FilePath stderr_path_;
  94    :    // @}
  95    :  
  96    :    // @name Command-line and parameters.
  97    :    // @{
  98    :    CommandLine cmd_line_;
  99    :    base::FilePath input_image_path_;
 100    :    base::FilePath input_pdb_path_;
 101    :    base::FilePath output_image_path_;
 102    :    base::FilePath output_pdb_path_;
 103    :    // @}
 104    :  
 105    :    // @name Expected final values of input parameters.
 106    :    // @{
 107    :    base::FilePath abs_input_image_path_;
 108    :    base::FilePath abs_input_pdb_path_;
 109    :    // @}
 110    :  
 111    :    // The fake instrumenter we delegate to.
 112    :    scoped_ptr<TestEntryCallInstrumenter> instrumenter_;
 113    :  };
 114    :  
 115    :  }  // namespace
 116    :  
 117  E :  TEST_F(EntryCallInstrumenterTest, ParseMinimalCallTrace) {
 118  E :    SetUpValidCommandLine();
 119  E :    instrumenter_.reset(new TestEntryCallInstrumenter());
 120    :  
 121  E :    EXPECT_TRUE(instrumenter_->ParseCommandLine(&cmd_line_));
 122  E :    EXPECT_EQ(abs_input_image_path_, instrumenter_->input_image_path_);
 123  E :    EXPECT_EQ(output_image_path_, instrumenter_->output_image_path_);
 124  E :    EXPECT_FALSE(instrumenter_->allow_overwrite_);
 125  E :    EXPECT_FALSE(instrumenter_->old_decomposer_);
 126  E :    EXPECT_FALSE(instrumenter_->no_augment_pdb_);
 127  E :    EXPECT_FALSE(instrumenter_->no_strip_strings_);
 128  E :    EXPECT_FALSE(instrumenter_->debug_friendly_);
 129  E :    EXPECT_FALSE(instrumenter_->thunk_imports_);
 130  E :  }
 131    :  
 132  E :  TEST_F(EntryCallInstrumenterTest, ParseFullCallTrace) {
 133  E :    SetUpValidCommandLine();
 134  E :    instrumenter_.reset(new TestEntryCallInstrumenter());
 135    :  
 136  E :    cmd_line_.AppendSwitchASCII("agent", "foo.dll");
 137  E :    cmd_line_.AppendSwitch("debug-friendly");
 138  E :    cmd_line_.AppendSwitchPath("input-pdb", input_pdb_path_);
 139  E :    cmd_line_.AppendSwitch("old-decomposer");
 140  E :    cmd_line_.AppendSwitch("no-augment-pdb");
 141  E :    cmd_line_.AppendSwitch("no-strip-strings");
 142  E :    cmd_line_.AppendSwitchPath("output-pdb", output_pdb_path_);
 143  E :    cmd_line_.AppendSwitch("overwrite");
 144  E :    cmd_line_.AppendSwitch("instrument-imports");
 145    :  
 146  E :    EXPECT_TRUE(instrumenter_->ParseCommandLine(&cmd_line_));
 147    :  
 148  E :    EXPECT_EQ(abs_input_image_path_, instrumenter_->input_image_path_);
 149  E :    EXPECT_EQ(output_image_path_, instrumenter_->output_image_path_);
 150  E :    EXPECT_EQ(abs_input_pdb_path_, instrumenter_->input_pdb_path_);
 151  E :    EXPECT_EQ(output_pdb_path_, instrumenter_->output_pdb_path_);
 152  E :    EXPECT_EQ(std::string("foo.dll"), instrumenter_->agent_dll_);
 153  E :    EXPECT_TRUE(instrumenter_->allow_overwrite_);
 154  E :    EXPECT_TRUE(instrumenter_->old_decomposer_);
 155  E :    EXPECT_TRUE(instrumenter_->no_augment_pdb_);
 156  E :    EXPECT_TRUE(instrumenter_->no_strip_strings_);
 157  E :    EXPECT_TRUE(instrumenter_->debug_friendly_);
 158  E :    EXPECT_TRUE(instrumenter_->thunk_imports_);
 159  E :  }
 160    :  
 161  E :  TEST_F(EntryCallInstrumenterTest, ParseMinimalProfile) {
 162  E :    SetUpValidCommandLine();
 163  E :    instrumenter_.reset(new TestEntryCallInstrumenter());
 164    :  
 165  E :    EXPECT_TRUE(instrumenter_->ParseCommandLine(&cmd_line_));
 166    :  
 167  E :    EXPECT_EQ(abs_input_image_path_, instrumenter_->input_image_path_);
 168  E :    EXPECT_EQ(output_image_path_, instrumenter_->output_image_path_);
 169    :  
 170    :    EXPECT_EQ(std::string(TestEntryCallInstrumenter::kAgentDllProfile),
 171  E :              instrumenter_->agent_dll_);
 172    :  
 173  E :    EXPECT_FALSE(instrumenter_->allow_overwrite_);
 174  E :    EXPECT_FALSE(instrumenter_->old_decomposer_);
 175  E :    EXPECT_FALSE(instrumenter_->no_augment_pdb_);
 176  E :    EXPECT_FALSE(instrumenter_->no_strip_strings_);
 177  E :    EXPECT_FALSE(instrumenter_->debug_friendly_);
 178  E :    EXPECT_FALSE(instrumenter_->thunk_imports_);
 179  E :  }
 180    :  
 181  E :  TEST_F(EntryCallInstrumenterTest, ParseFullProfile) {
 182  E :    SetUpValidCommandLine();
 183  E :    instrumenter_.reset(new TestEntryCallInstrumenter());
 184  E :    cmd_line_.AppendSwitchASCII("agent", "foo.dll");
 185  E :    cmd_line_.AppendSwitch("debug-friendly");
 186  E :    cmd_line_.AppendSwitchPath("input-pdb", input_pdb_path_);
 187  E :    cmd_line_.AppendSwitch("old-decomposer");
 188  E :    cmd_line_.AppendSwitch("no-augment-pdb");
 189  E :    cmd_line_.AppendSwitch("no-strip-strings");
 190  E :    cmd_line_.AppendSwitchPath("output-pdb", output_pdb_path_);
 191  E :    cmd_line_.AppendSwitch("overwrite");
 192  E :    cmd_line_.AppendSwitch("instrument-imports");
 193    :  
 194  E :    EXPECT_TRUE(instrumenter_->ParseCommandLine(&cmd_line_));
 195    :  
 196  E :    EXPECT_EQ(abs_input_image_path_, instrumenter_->input_image_path_);
 197  E :    EXPECT_EQ(output_image_path_, instrumenter_->output_image_path_);
 198  E :    EXPECT_EQ(abs_input_pdb_path_, instrumenter_->input_pdb_path_);
 199  E :    EXPECT_EQ(output_pdb_path_, instrumenter_->output_pdb_path_);
 200  E :    EXPECT_EQ(std::string("foo.dll"), instrumenter_->agent_dll_);
 201  E :    EXPECT_TRUE(instrumenter_->allow_overwrite_);
 202  E :    EXPECT_TRUE(instrumenter_->old_decomposer_);
 203  E :    EXPECT_TRUE(instrumenter_->no_augment_pdb_);
 204  E :    EXPECT_TRUE(instrumenter_->no_strip_strings_);
 205  E :    EXPECT_TRUE(instrumenter_->debug_friendly_);
 206  E :    EXPECT_TRUE(instrumenter_->thunk_imports_);
 207  E :  }
 208    :  
 209  E :  TEST_F(EntryCallInstrumenterTest, InstrumentImplCallTrace) {
 210  E :    SetUpValidCommandLine();
 211  E :    instrumenter_.reset(new TestEntryCallInstrumenter());
 212    :  
 213  E :    EXPECT_TRUE(instrumenter_->ParseCommandLine(&cmd_line_));
 214  E :    EXPECT_TRUE(instrumenter_->CreateRelinker());
 215  E :    EXPECT_TRUE(instrumenter_->InstrumentImpl());
 216  E :  }
 217    :  
 218  E :  TEST_F(EntryCallInstrumenterTest, InstrumentImplProfile) {
 219  E :    SetUpValidCommandLine();
 220  E :    instrumenter_.reset(new TestEntryCallInstrumenter());
 221    :  
 222  E :    EXPECT_TRUE(instrumenter_->ParseCommandLine(&cmd_line_));
 223  E :    EXPECT_TRUE(instrumenter_->CreateRelinker());
 224  E :    EXPECT_TRUE(instrumenter_->InstrumentImpl());
 225  E :  }
 226    :  
 227    :  }  // namespace instrumenters
 228    :  }  // namespace instrument

Coverage information generated Wed Dec 11 11:34:16 2013.