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

Side by Side Diff: testing/libfuzzer/tests/fuzzer_launcher_test.cc

Issue 2714053003: Fix GCC build for target 'all' (Closed)
Patch Set: #if defined(__GNUC__) Created 3 years, 9 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 // Fuzzer launcher script tests. 5 // Fuzzer launcher script tests.
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/path_service.h" 11 #include "base/path_service.h"
12 #include "base/process/launch.h" 12 #include "base/process/launch.h"
13 #include "base/strings/string_split.h" 13 #include "base/strings/string_split.h"
14 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 17
18 TEST(FuzzerConfigTest, DictOnly) { 18 TEST(FuzzerConfigTest, DictOnly) {
19 // Test of automatically generated .options file for fuzzer with dict option. 19 // Test of automatically generated .options file for fuzzer with dict option.
20 base::FilePath exe_path; 20 base::FilePath exe_path;
21 PathService::Get(base::FILE_EXE, &exe_path); 21 PathService::Get(base::FILE_EXE, &exe_path);
22 std::string launcher_path = 22 std::string launcher_path =
23 exe_path.DirName().Append("check_fuzzer_config.py").value(); 23 exe_path.DirName().Append("check_fuzzer_config.py").value();
24 24
25 std::string output; 25 std::string output;
26 base::CommandLine cmd({{launcher_path, "test_dict_only.options"}}); 26 base::CommandLine cmd(
27 std::vector<std::string>({launcher_path, "test_dict_only.options"}));
27 bool success = base::GetAppOutputAndError(cmd, &output); 28 bool success = base::GetAppOutputAndError(cmd, &output);
28 EXPECT_TRUE(success); 29 EXPECT_TRUE(success);
29 std::vector<std::string> fuzzer_args = base::SplitString( 30 std::vector<std::string> fuzzer_args = base::SplitString(
30 output, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); 31 output, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
31 32
32 EXPECT_EQ(1UL, fuzzer_args.size()); 33 EXPECT_EQ(1UL, fuzzer_args.size());
33 34
34 EXPECT_EQ(fuzzer_args[0], "dict=test_dict_only.dict"); 35 EXPECT_EQ(fuzzer_args[0], "dict=test_dict_only.dict");
35 } 36 }
36 37
37 38
38 TEST(FuzzerConfigTest, ConfigOnly) { 39 TEST(FuzzerConfigTest, ConfigOnly) {
39 // Test of .options file for fuzzer with libfuzzer_options and without dict. 40 // Test of .options file for fuzzer with libfuzzer_options and without dict.
40 base::FilePath exe_path; 41 base::FilePath exe_path;
41 PathService::Get(base::FILE_EXE, &exe_path); 42 PathService::Get(base::FILE_EXE, &exe_path);
42 std::string launcher_path = 43 std::string launcher_path =
43 exe_path.DirName().Append("check_fuzzer_config.py").value(); 44 exe_path.DirName().Append("check_fuzzer_config.py").value();
44 45
45 std::string output; 46 std::string output;
46 base::CommandLine cmd({{launcher_path, "test_config_only.options"}}); 47 base::CommandLine cmd(
48 std::vector<std::string>({launcher_path, "test_config_only.options"}));
47 bool success = base::GetAppOutputAndError(cmd, &output); 49 bool success = base::GetAppOutputAndError(cmd, &output);
48 EXPECT_TRUE(success); 50 EXPECT_TRUE(success);
49 std::vector<std::string> fuzzer_args = base::SplitString( 51 std::vector<std::string> fuzzer_args = base::SplitString(
50 output, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); 52 output, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
51 53
52 EXPECT_EQ(2UL, fuzzer_args.size()); 54 EXPECT_EQ(2UL, fuzzer_args.size());
53 55
54 EXPECT_EQ(fuzzer_args[0], "some_test_option=test_value"); 56 EXPECT_EQ(fuzzer_args[0], "some_test_option=test_value");
55 EXPECT_EQ(fuzzer_args[1], "max_len=1024"); 57 EXPECT_EQ(fuzzer_args[1], "max_len=1024");
56 } 58 }
57 59
58 60
59 TEST(FuzzerConfigTest, ConfigAndDict) { 61 TEST(FuzzerConfigTest, ConfigAndDict) {
60 // Test of .options file for fuzzer with options file and dictionary. 62 // Test of .options file for fuzzer with options file and dictionary.
61 base::FilePath exe_path; 63 base::FilePath exe_path;
62 PathService::Get(base::FILE_EXE, &exe_path); 64 PathService::Get(base::FILE_EXE, &exe_path);
63 std::string launcher_path = 65 std::string launcher_path =
64 exe_path.DirName().Append("check_fuzzer_config.py").value(); 66 exe_path.DirName().Append("check_fuzzer_config.py").value();
65 67
66 std::string output; 68 std::string output;
67 base::CommandLine cmd({{launcher_path, "test_config_and_dict.options"}}); 69 base::CommandLine cmd(std::vector<std::string>(
70 {launcher_path, "test_config_and_dict.options"}));
68 bool success = base::GetAppOutputAndError(cmd, &output); 71 bool success = base::GetAppOutputAndError(cmd, &output);
69 EXPECT_TRUE(success); 72 EXPECT_TRUE(success);
70 std::vector<std::string> fuzzer_args = base::SplitString( 73 std::vector<std::string> fuzzer_args = base::SplitString(
71 output, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); 74 output, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
72 75
73 EXPECT_EQ(4UL, fuzzer_args.size()); 76 EXPECT_EQ(4UL, fuzzer_args.size());
74 77
75 EXPECT_EQ(fuzzer_args[0], "dict=test_config_and_dict.dict"); 78 EXPECT_EQ(fuzzer_args[0], "dict=test_config_and_dict.dict");
76 EXPECT_EQ(fuzzer_args[1], "max_len=random(1337, 31337)"); 79 EXPECT_EQ(fuzzer_args[1], "max_len=random(1337, 31337)");
77 EXPECT_EQ(fuzzer_args[2], "timeout=666"); 80 EXPECT_EQ(fuzzer_args[2], "timeout=666");
78 EXPECT_EQ(fuzzer_args[3], "use_traces=1"); 81 EXPECT_EQ(fuzzer_args[3], "use_traces=1");
79 } 82 }
80 83
81 84
82 TEST(FuzzerConfigTest, ConfigAndSeedCorpus) { 85 TEST(FuzzerConfigTest, ConfigAndSeedCorpus) {
83 // Test of .options file for fuzzer with libfuzzer_options and seed corpus. 86 // Test of .options file for fuzzer with libfuzzer_options and seed corpus.
84 base::FilePath exe_path; 87 base::FilePath exe_path;
85 PathService::Get(base::FILE_EXE, &exe_path); 88 PathService::Get(base::FILE_EXE, &exe_path);
86 std::string launcher_path = 89 std::string launcher_path =
87 exe_path.DirName().Append("check_fuzzer_config.py").value(); 90 exe_path.DirName().Append("check_fuzzer_config.py").value();
88 91
89 std::string output; 92 std::string output;
90 base::CommandLine cmd( 93 base::CommandLine cmd(std::vector<std::string>(
91 {{launcher_path, "test_config_and_seed_corpus.options"}}); 94 {launcher_path, "test_config_and_seed_corpus.options"}));
92 bool success = base::GetAppOutputAndError(cmd, &output); 95 bool success = base::GetAppOutputAndError(cmd, &output);
93 EXPECT_TRUE(success); 96 EXPECT_TRUE(success);
94 std::vector<std::string> fuzzer_args = base::SplitString( 97 std::vector<std::string> fuzzer_args = base::SplitString(
95 output, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); 98 output, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
96 99
97 EXPECT_EQ(2UL, fuzzer_args.size()); 100 EXPECT_EQ(2UL, fuzzer_args.size());
98 101
99 EXPECT_EQ(fuzzer_args[0], "some_test_option=test_value"); 102 EXPECT_EQ(fuzzer_args[0], "some_test_option=test_value");
100 EXPECT_EQ(fuzzer_args[1], "max_len=1024"); 103 EXPECT_EQ(fuzzer_args[1], "max_len=1024");
101 104
102 // Test seed_corpus archive. 105 // Test seed_corpus archive.
103 launcher_path = 106 launcher_path =
104 exe_path.DirName().Append("check_seed_corpus_archive.py").value(); 107 exe_path.DirName().Append("check_seed_corpus_archive.py").value();
105 108
106 cmd = base::CommandLine( 109 cmd = base::CommandLine(std::vector<std::string>(
107 {{launcher_path, "test_config_and_seed_corpus_seed_corpus.zip"}}); 110 {launcher_path, "test_config_and_seed_corpus_seed_corpus.zip"}));
108 success = base::GetAppOutputAndError(cmd, &output); 111 success = base::GetAppOutputAndError(cmd, &output);
109 EXPECT_TRUE(success); 112 EXPECT_TRUE(success);
110 std::vector<std::string> seed_corpus_info = base::SplitString( 113 std::vector<std::string> seed_corpus_info = base::SplitString(
111 output, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); 114 output, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
112 115
113 EXPECT_EQ(1UL, seed_corpus_info.size()); 116 EXPECT_EQ(1UL, seed_corpus_info.size());
114 EXPECT_EQ(seed_corpus_info[0], "3"); 117 EXPECT_EQ(seed_corpus_info[0], "3");
115 } 118 }
116 119
117 120
118 TEST(FuzzerConfigTest, ConfigAndSeedCorpuses) { 121 TEST(FuzzerConfigTest, ConfigAndSeedCorpuses) {
119 // Test of .options file for fuzzer with libfuzzer_options and seed corpuses. 122 // Test of .options file for fuzzer with libfuzzer_options and seed corpuses.
120 base::FilePath exe_path; 123 base::FilePath exe_path;
121 PathService::Get(base::FILE_EXE, &exe_path); 124 PathService::Get(base::FILE_EXE, &exe_path);
122 std::string launcher_path = 125 std::string launcher_path =
123 exe_path.DirName().Append("check_fuzzer_config.py").value(); 126 exe_path.DirName().Append("check_fuzzer_config.py").value();
124 127
125 std::string output; 128 std::string output;
126 base::CommandLine cmd( 129 base::CommandLine cmd(std::vector<std::string>(
127 {{launcher_path, "test_config_and_seed_corpuses.options"}}); 130 {launcher_path, "test_config_and_seed_corpuses.options"}));
128 bool success = base::GetAppOutputAndError(cmd, &output); 131 bool success = base::GetAppOutputAndError(cmd, &output);
129 EXPECT_TRUE(success); 132 EXPECT_TRUE(success);
130 std::vector<std::string> fuzzer_args = base::SplitString( 133 std::vector<std::string> fuzzer_args = base::SplitString(
131 output, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); 134 output, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
132 135
133 EXPECT_EQ(2UL, fuzzer_args.size()); 136 EXPECT_EQ(2UL, fuzzer_args.size());
134 137
135 EXPECT_EQ(fuzzer_args[0], "some_test_option=another_test_value"); 138 EXPECT_EQ(fuzzer_args[0], "some_test_option=another_test_value");
136 EXPECT_EQ(fuzzer_args[1], "max_len=1337"); 139 EXPECT_EQ(fuzzer_args[1], "max_len=1337");
137 140
138 // Test seed_corpus archive. 141 // Test seed_corpus archive.
139 launcher_path = 142 launcher_path =
140 exe_path.DirName().Append("check_seed_corpus_archive.py").value(); 143 exe_path.DirName().Append("check_seed_corpus_archive.py").value();
141 144
142 cmd = base::CommandLine( 145 cmd = base::CommandLine(std::vector<std::string>(
143 {{launcher_path, "test_config_and_seed_corpuses_seed_corpus.zip"}}); 146 {launcher_path, "test_config_and_seed_corpuses_seed_corpus.zip"}));
144 success = base::GetAppOutputAndError(cmd, &output); 147 success = base::GetAppOutputAndError(cmd, &output);
145 EXPECT_TRUE(success); 148 EXPECT_TRUE(success);
146 std::vector<std::string> seed_corpus_info = base::SplitString( 149 std::vector<std::string> seed_corpus_info = base::SplitString(
147 output, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); 150 output, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
148 151
149 EXPECT_EQ(1UL, seed_corpus_info.size()); 152 EXPECT_EQ(1UL, seed_corpus_info.size());
150 EXPECT_EQ(seed_corpus_info[0], "5"); 153 EXPECT_EQ(seed_corpus_info[0], "5");
151 } 154 }
152 155
153 156
154 TEST(FuzzerConfigTest, DictSubdir) { 157 TEST(FuzzerConfigTest, DictSubdir) {
155 // Test of auto-generated .options file for fuzzer with dict in sub-directory. 158 // Test of auto-generated .options file for fuzzer with dict in sub-directory.
156 base::FilePath exe_path; 159 base::FilePath exe_path;
157 PathService::Get(base::FILE_EXE, &exe_path); 160 PathService::Get(base::FILE_EXE, &exe_path);
158 std::string launcher_path = 161 std::string launcher_path =
159 exe_path.DirName().Append("check_fuzzer_config.py").value(); 162 exe_path.DirName().Append("check_fuzzer_config.py").value();
160 163
161 std::string output; 164 std::string output;
162 base::CommandLine cmd({{launcher_path, "test_dict_from_subdir.options"}}); 165 base::CommandLine cmd(std::vector<std::string>(
166 {launcher_path, "test_dict_from_subdir.options"}));
163 bool success = base::GetAppOutputAndError(cmd, &output); 167 bool success = base::GetAppOutputAndError(cmd, &output);
164 EXPECT_TRUE(success); 168 EXPECT_TRUE(success);
165 std::vector<std::string> fuzzer_args = base::SplitString( 169 std::vector<std::string> fuzzer_args = base::SplitString(
166 output, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); 170 output, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
167 171
168 EXPECT_EQ(1UL, fuzzer_args.size()); 172 EXPECT_EQ(1UL, fuzzer_args.size());
169 173
170 EXPECT_EQ(fuzzer_args[0], "dict=test_dict_from_subdir.dict"); 174 EXPECT_EQ(fuzzer_args[0], "dict=test_dict_from_subdir.dict");
171 } 175 }
OLDNEW
« no previous file with comments | « remoting/host/security_key/fake_security_key_ipc_server.cc ('k') | third_party/WebKit/Source/core/page/NetworkStateNotifier.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698