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 : // Unittests for FuzzingTransform.
16 :
17 : #include "syzygy/block_graph/transforms/fuzzing_transform.h"
18 :
19 : #include "gtest/gtest.h"
20 : #include "syzygy/block_graph/basic_block.h"
21 : #include "syzygy/block_graph/basic_block_assembler.h"
22 : #include "syzygy/block_graph/basic_block_decomposer.h"
23 : #include "syzygy/block_graph/basic_block_subgraph.h"
24 : #include "syzygy/block_graph/block_graph.h"
25 : #include "syzygy/block_graph/transform.h"
26 : #include "syzygy/block_graph/unittest_util.h"
27 :
28 : #include "mnemonics.h" // NOLINT
29 :
30 : namespace block_graph {
31 : namespace transforms {
32 : namespace {
33 :
34 : using block_graph::BasicBlock;
35 : using block_graph::BasicBlockAssembler;
36 : using block_graph::BasicCodeBlock;
37 : using block_graph::BasicBlockDecomposer;
38 : using block_graph::Instruction;
39 : using block_graph::Immediate;
40 : using testing::DummyTransformPolicy;
41 :
42 : class TestLivenessFuzzingBasicBlockTransform :
43 : public LivenessFuzzingBasicBlockTransform {
44 : public:
45 : using LivenessFuzzingBasicBlockTransform::TransformBasicBlockSubGraph;
46 : };
47 :
48 : } // namespace
49 :
50 E : TEST(LivenessFuzzingBasicBlockTransformTest, SingleBasicBlock) {
51 E : BlockGraph bg;
52 E : BasicBlockSubGraph subgraph;
53 E : BasicCodeBlock* bb = subgraph.AddBasicCodeBlock("bb");
54 E : ASSERT_TRUE(bb != NULL);
55 :
56 : // Insert instructions into basic block.
57 E : BasicBlockAssembler assembly(bb->instructions().end(), &bb->instructions());
58 E : assembly.cmp(assm::eax, Immediate(42, assm::kSize32Bit));
59 E : assembly.mov(assm::eax, Immediate(0, assm::kSize32Bit));
60 :
61 : // Transforms the basic block.
62 E : DummyTransformPolicy policy;
63 E : TestLivenessFuzzingBasicBlockTransform tx;
64 E : size_t previous_size = bb->instructions().size();
65 E : ASSERT_TRUE(tx.TransformBasicBlockSubGraph(&policy, &bg, &subgraph));
66 :
67 : // Expecting two new instructions.
68 E : size_t expected_size = previous_size + 2;
69 E : size_t current_size = bb->instructions().size();
70 E : EXPECT_EQ(expected_size, current_size);
71 E : }
72 :
73 : } // namespace transforms
74 : } // namespace block_graph
|