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 { ASSERT_NO_FATAL_FAILURE(DecomposeTestDll()); }
40 : };
41 :
42 : } // namespace
43 :
44 E : TEST_F(CoverageInstrumentationTransformTest, Apply) {
45 E : CoverageInstrumentationTransform tx;
46 : ASSERT_TRUE(block_graph::ApplyBlockGraphTransform(
47 E : &tx, policy_, &block_graph_, header_block_));
48 :
49 E : BlockGraph::Block* frequency_data_block = tx.frequency_data_block();
50 :
51 E : block_graph::ConstTypedBlock<IndexedFrequencyData> coverage_data;
52 E : ASSERT_TRUE(coverage_data.Init(0, frequency_data_block));
53 :
54 : // The frequency data block should have the appropriate size.
55 E : ASSERT_EQ(sizeof(IndexedFrequencyData), frequency_data_block->size());
56 E : ASSERT_EQ(sizeof(IndexedFrequencyData), frequency_data_block->data_size());
57 : EXPECT_EQ(coverage_data->num_entries,
58 E : tx.frequency_data_buffer_block()->size());
59 :
60 E : EXPECT_EQ(common::kBasicBlockCoverageAgentId, coverage_data->agent_id);
61 E : EXPECT_EQ(common::kBasicBlockFrequencyDataVersion, coverage_data->version);
62 E : EXPECT_EQ(IndexedFrequencyData::COVERAGE, coverage_data->data_type);
63 E : EXPECT_EQ(tx.bb_ranges().size(), coverage_data->num_entries);
64 : EXPECT_TRUE(coverage_data.HasReferenceAt(
65 E : coverage_data.OffsetOf(coverage_data->frequency_data)));
66 E : }
67 :
68 : } // namespace transforms
69 : } // namespace instrument
|