Coverage for /Syzygy/assm/buffer_serializer_unittest.cc

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

Line-by-line coverage:

   1    :  // Copyright 2015 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/assm/buffer_serializer.h"
  16    :  
  17    :  #include "gtest/gtest.h"
  18    :  #include "syzygy/assm/unittest_util.h"
  19    :  
  20    :  namespace assm {
  21    :  
  22    :  class BufferSerializerTest : public testing::Test {
  23    :   public:
  24  E :    BufferSerializerTest() {
  25  E :    }
  26    :  
  27  E :    void NopTest(size_t nop_size) {
  28  E :      const size_t kOffset = 5U;
  29  E :      const size_t kBufferSize = 1024U;
  30    :  
  31    :      // Initialize buffer.
  32    :      uint8 buffer[kBufferSize];
  33  E :      ::memset(buffer, 0, kBufferSize);
  34    :  
  35    :      // Assemble a NOP into the buffer.
  36  E :      BufferSerializer bs(buffer, kBufferSize);
  37  E :      AssemblerImpl asm_(reinterpret_cast<uint32>(&buffer[kOffset]), &bs);
  38  E :      asm_.nop(nop_size);
  39    :  
  40    :      // Should not touch any bytes before offset.
  41  E :      for (size_t i = 0; i < kOffset; ++i) {
  42  E :        EXPECT_EQ(0U, buffer[i]);
  43  E :      }
  44    :  
  45    :      // Should write the proper NOP.
  46  E :      for (size_t i = 0; i < nop_size; ++i) {
  47  E :        EXPECT_EQ(testing::kNops[nop_size][i], buffer[kOffset + i]);
  48  E :      }
  49    :  
  50    :      // Should not touch any bytes after the NOP.
  51  E :      for (size_t i = kOffset + nop_size; i < kBufferSize; ++i) {
  52  E :        EXPECT_EQ(0U, buffer[i]);
  53  E :      }
  54  E :    }
  55    :  };
  56    :  
  57  E :  TEST_F(BufferSerializerTest, Nop) {
  58  E :    const size_t kMaxNopSizeToTest = 10;
  59    :  
  60  E :    for (size_t nop_size = 0; nop_size <= kMaxNopSizeToTest; ++nop_size) {
  61  E :      NopTest(nop_size);
  62  E :    }
  63  E :  }
  64    :  
  65    :  }  // namespace assm

Coverage information generated Thu Jan 14 17:40:38 2016.