1 : // Copyright 2012 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 : // Coverage instrumentation transform unittests.
16 :
17 : #include "syzygy/instrument/transforms/coverage_transform.h"
18 :
19 : #include "gtest/gtest.h"
20 : #include "syzygy/block_graph/transform.h"
21 : #include "syzygy/block_graph/typed_block.h"
22 : #include "syzygy/common/indexed_frequency_data.h"
23 : #include "syzygy/core/unittest_util.h"
24 : #include "syzygy/instrument/transforms/unittest_util.h"
25 : #include "syzygy/pe/decomposer.h"
26 : #include "syzygy/pe/unittest_util.h"
27 :
28 : namespace instrument {
29 : namespace transforms {
30 :
31 : namespace {
32 :
33 : using common::IndexedFrequencyData;
34 : using block_graph::BlockGraph;
35 :
36 : class CoverageInstrumentationTransformTest
37 : : public testing::TestDllTransformTest {
38 : public:
39 E : virtual void SetUp() OVERRIDE {
40 E : ASSERT_NO_FATAL_FAILURE(DecomposeTestDll());
41 E : }
42 : };
43 :
44 : } // namespace
45 :
46 E : TEST_F(CoverageInstrumentationTransformTest, Apply) {
47 E : CoverageInstrumentationTransform tx;
48 : ASSERT_TRUE(block_graph::ApplyBlockGraphTransform(
49 E : &tx, policy_, &block_graph_, header_block_));
50 :
51 E : BlockGraph::Block* frequency_data_block = tx.frequency_data_block();
52 :
53 E : block_graph::ConstTypedBlock<IndexedFrequencyData> coverage_data;
54 E : ASSERT_TRUE(coverage_data.Init(0, frequency_data_block));
55 :
56 : // The frequency data block should have the appropriate size.
57 E : ASSERT_EQ(sizeof(IndexedFrequencyData), frequency_data_block->size());
58 E : ASSERT_EQ(sizeof(IndexedFrequencyData), frequency_data_block->data_size());
59 : EXPECT_EQ(coverage_data->num_entries,
60 E : tx.frequency_data_buffer_block()->size());
61 :
62 E : EXPECT_EQ(common::kBasicBlockCoverageAgentId, coverage_data->agent_id);
63 E : EXPECT_EQ(common::kBasicBlockFrequencyDataVersion, coverage_data->version);
64 E : EXPECT_EQ(IndexedFrequencyData::COVERAGE, coverage_data->data_type);
65 E : EXPECT_EQ(tx.bb_ranges().size(), coverage_data->num_entries);
66 : EXPECT_TRUE(coverage_data.HasReferenceAt(
67 E : coverage_data.OffsetOf(coverage_data->frequency_data)));
68 E : }
69 :
70 : } // namespace transforms
71 : } // namespace instrument
|