Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1046)

Side by Side Diff: courgette/program_detector_unittest.cc

Issue 2055343002: Courgette: Add static method QuickDetect() to optimize program detection. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nit cleanup Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
huangs 2016/06/13 18:30:28 No "(c) "
etiennep 2016/06/14 21:16:38 Done.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "courgette/program_detector.h"
6
7 #include <string>
8
9 #include "courgette/base_test_unittest.h"
10 #include "courgette/courgette.h"
11 #include "courgette/disassembler.h"
12 #include "courgette/disassembler_elf_32_arm.h"
13 #include "courgette/disassembler_elf_32_x86.h"
14 #include "courgette/disassembler_win32_x64.h"
15 #include "courgette/disassembler_win32_x86.h"
16
17 namespace courgette {
18
19 namespace {
20
21 class ProgramDetectorTest : public BaseTest {
22 public:
23 void TestQuickDetect(const std::string& test_data,
24 ExecutableType expected_type) const;
25 void TestDetectDisassembler(const std::string& test_data,
26 ExecutableType expected_type) const;
27 };
28
29 void ProgramDetectorTest::TestQuickDetect(const std::string& test_data,
30 ExecutableType expected_type) const {
31 // QuickDetect should be positive only on the expected ExecutableType
huangs 2016/06/13 18:30:28 NIT: // QuickDetect() should return true only for
etiennep 2016/06/14 21:16:38 Done.
32 EXPECT_EQ(
33 expected_type == EXE_WIN_32_X86,
34 DisassemblerWin32X86::QuickDetect(test_data.data(), test_data.size()));
35 EXPECT_EQ(
36 expected_type == EXE_WIN_32_X64,
37 DisassemblerWin32X64::QuickDetect(test_data.data(), test_data.size()));
38 EXPECT_EQ(
39 expected_type == EXE_ELF_32_X86,
40 DisassemblerElf32X86::QuickDetect(test_data.data(), test_data.size()));
41 EXPECT_EQ(
42 expected_type == EXE_ELF_32_ARM,
43 DisassemblerElf32ARM::QuickDetect(test_data.data(), test_data.size()));
44 }
45
46 void ProgramDetectorTest::TestDetectDisassembler(
47 const std::string& test_data,
48 ExecutableType expected_type) const {
49 ExecutableType detected_type;
50 size_t detected_length;
huangs 2016/06/13 18:30:28 Initilize: ExecutableType detected_type = EXE_UNKN
huangs 2016/06/13 18:34:06 Oops I mean size_t detected_length = 0;
etiennep 2016/06/14 21:16:37 Done.
51 DetectExecutableType(test_data.data(), test_data.size(), &detected_type,
52 &detected_length);
53 EXPECT_EQ(expected_type, detected_type);
54 EXPECT_EQ(test_data.size(), detected_length);
55 }
56
57 TEST_F(ProgramDetectorTest, All) {
58 std::string win32_x86 = FileContents("setup1.exe");
59 std::string win32_x64 = FileContents("chrome64_1.exe");
60 std::string elf_32 = FileContents("elf-32-1");
61 std::string elf_arm = FileContents("elf-armv7");
62
63 TestQuickDetect(win32_x86, EXE_WIN_32_X86);
64 TestQuickDetect(win32_x64, EXE_WIN_32_X64);
65 TestQuickDetect(elf_32, EXE_ELF_32_X86);
66 TestQuickDetect(elf_arm, EXE_ELF_32_ARM);
67
68 TestDetectDisassembler(win32_x86, EXE_WIN_32_X86);
69 TestDetectDisassembler(win32_x64, EXE_WIN_32_X64);
70 TestDetectDisassembler(elf_32, EXE_ELF_32_X86);
71 TestDetectDisassembler(elf_arm, EXE_ELF_32_ARM);
72 }
73
74 } // namespace
75
76 } // namespace courgette
OLDNEW
« courgette/disassembler_win32.cc ('K') | « courgette/program_detector.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698