| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "courgette/assembly_program.h" | |
| 10 #include "courgette/base_test_unittest.h" | 9 #include "courgette/base_test_unittest.h" |
| 11 #include "courgette/courgette.h" | 10 #include "courgette/courgette.h" |
| 12 #include "courgette/courgette_flow.h" | 11 #include "courgette/courgette_flow.h" |
| 13 #include "courgette/encoded_program.h" | |
| 14 #include "courgette/program_detector.h" | |
| 15 #include "courgette/streams.h" | 12 #include "courgette/streams.h" |
| 16 | 13 |
| 17 namespace courgette { | 14 namespace courgette { |
| 18 | 15 |
| 19 class EncodeDecodeTest : public BaseTest { | 16 class EncodeDecodeTest : public BaseTest { |
| 20 public: | 17 public: |
| 21 void TestAssembleToStreamDisassemble(const std::string& file, | 18 void TestAssembleToStreamDisassemble(const std::string& file, |
| 22 size_t expected_encoded_length) const; | 19 size_t expected_encoded_length) const; |
| 23 }; | 20 }; |
| 24 | 21 |
| 25 void EncodeDecodeTest::TestAssembleToStreamDisassemble( | 22 void EncodeDecodeTest::TestAssembleToStreamDisassemble( |
| 26 const std::string& file, | 23 const std::string& file, |
| 27 size_t expected_encoded_length) const { | 24 size_t expected_encoded_length) const { |
| 28 const uint8_t* original_data = reinterpret_cast<const uint8_t*>(file.data()); | 25 const uint8_t* original_data = reinterpret_cast<const uint8_t*>(file.data()); |
| 29 size_t original_length = file.length(); | 26 size_t original_length = file.length(); |
| 30 CourgetteFlow flow; | 27 CourgetteFlow flow; |
| 31 | 28 |
| 32 // Convert executable to encoded assembly. | 29 // Convert executable to encoded assembly. |
| 33 RegionBuffer original_buffer(Region(original_data, original_length)); | 30 RegionBuffer original_buffer(Region(original_data, original_length)); |
| 34 flow.ReadAssemblyProgramFromBuffer(flow.ONLY, original_buffer, false); | 31 flow.ReadDisassemblerFromBuffer(flow.ONLY, original_buffer); |
| 32 EXPECT_EQ(C_OK, flow.status()); |
| 33 EXPECT_TRUE(nullptr != flow.data(flow.ONLY)->disassembler.get()); |
| 34 |
| 35 flow.CreateAssemblyProgramFromDisassembler(flow.ONLY, false); |
| 35 EXPECT_EQ(C_OK, flow.status()); | 36 EXPECT_EQ(C_OK, flow.status()); |
| 36 EXPECT_TRUE(nullptr != flow.data(flow.ONLY)->program.get()); | 37 EXPECT_TRUE(nullptr != flow.data(flow.ONLY)->program.get()); |
| 37 | 38 |
| 38 flow.CreateEncodedProgramFromAssemblyProgram(flow.ONLY); | 39 flow.CreateEncodedProgramFromDisassemblerAndAssemblyProgram(flow.ONLY); |
| 39 EXPECT_EQ(C_OK, flow.status()); | 40 EXPECT_EQ(C_OK, flow.status()); |
| 40 EXPECT_TRUE(nullptr != flow.data(flow.ONLY)->encoded.get()); | 41 EXPECT_TRUE(nullptr != flow.data(flow.ONLY)->encoded.get()); |
| 41 | 42 |
| 42 flow.DestroyAssemblyProgram(flow.ONLY); | 43 flow.DestroyAssemblyProgram(flow.ONLY); |
| 43 EXPECT_EQ(C_OK, flow.status()); | 44 EXPECT_EQ(C_OK, flow.status()); |
| 44 EXPECT_TRUE(nullptr == flow.data(flow.ONLY)->program.get()); | 45 EXPECT_TRUE(nullptr == flow.data(flow.ONLY)->program.get()); |
| 45 | 46 |
| 47 flow.DestroyDisassembler(flow.ONLY); |
| 48 EXPECT_EQ(C_OK, flow.status()); |
| 49 EXPECT_TRUE(nullptr == flow.data(flow.ONLY)->disassembler.get()); |
| 50 |
| 46 flow.WriteSinkStreamSetFromEncodedProgram(flow.ONLY); | 51 flow.WriteSinkStreamSetFromEncodedProgram(flow.ONLY); |
| 47 EXPECT_EQ(C_OK, flow.status()); | 52 EXPECT_EQ(C_OK, flow.status()); |
| 48 | 53 |
| 49 flow.DestroyEncodedProgram(flow.ONLY); | 54 flow.DestroyEncodedProgram(flow.ONLY); |
| 50 EXPECT_EQ(C_OK, flow.status()); | 55 EXPECT_EQ(C_OK, flow.status()); |
| 51 EXPECT_TRUE(nullptr == flow.data(flow.ONLY)->encoded.get()); | 56 EXPECT_TRUE(nullptr == flow.data(flow.ONLY)->encoded.get()); |
| 52 | 57 |
| 53 SinkStream sink; | 58 SinkStream sink; |
| 54 flow.WriteSinkStreamFromSinkStreamSet(flow.ONLY, &sink); | 59 flow.WriteSinkStreamFromSinkStreamSet(flow.ONLY, &sink); |
| 55 EXPECT_EQ(C_OK, flow.status()); | 60 EXPECT_EQ(C_OK, flow.status()); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 std::string file = FileContents("elf-32-high-bss"); | 108 std::string file = FileContents("elf-32-high-bss"); |
| 104 TestAssembleToStreamDisassemble(file, 7308); | 109 TestAssembleToStreamDisassemble(file, 7308); |
| 105 } | 110 } |
| 106 | 111 |
| 107 TEST_F(EncodeDecodeTest, Elf_Arm) { | 112 TEST_F(EncodeDecodeTest, Elf_Arm) { |
| 108 std::string file = FileContents("elf-armv7"); | 113 std::string file = FileContents("elf-armv7"); |
| 109 TestAssembleToStreamDisassemble(file, 8531); | 114 TestAssembleToStreamDisassemble(file, 8531); |
| 110 } | 115 } |
| 111 | 116 |
| 112 } // namespace courgette | 117 } // namespace courgette |
| OLD | NEW |