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

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

Issue 1703523002: [libfuzzer] support of custom libfuzzer options via .options file. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix nits in check_fuzzer_config.py script and fuzzer_launcher_test.cc Created 4 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
11 #include "base/command_line.h" 10 #include "base/command_line.h"
12 #include "base/path_service.h" 11 #include "base/path_service.h"
13 #include "base/process/launch.h" 12 #include "base/process/launch.h"
14 #include "base/strings/string_split.h" 13 #include "base/strings/string_split.h"
15 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
17 using testing::EndsWith;
18 using testing::StartsWith;
19 16
20 TEST(FuzzerLauncherTest, Dict) { 17
18 TEST(FuzzerConfigTest, DictOnly) {
19 // Test of automatically generated .options file for fuzzer with dict option.
21 base::FilePath exe_path; 20 base::FilePath exe_path;
22 PathService::Get(base::FILE_EXE, &exe_path); 21 PathService::Get(base::FILE_EXE, &exe_path);
23 std::string launcher_path = 22 std::string launcher_path =
24 exe_path.DirName().Append("test_dict_launcher.sh").value(); 23 exe_path.DirName().Append("check_fuzzer_config.py").value();
25 24
26 std::string output; 25 std::string output;
27 base::CommandLine cmd({{launcher_path, "-custom_option"}}); 26 base::CommandLine cmd({{launcher_path, "test_dict_only.options"}});
28 bool success = base::GetAppOutputAndError(cmd, &output); 27 bool success = base::GetAppOutputAndError(cmd, &output);
29 EXPECT_TRUE(success); 28 EXPECT_TRUE(success);
30 std::vector<std::string> fuzzer_args = base::SplitString( 29 std::vector<std::string> fuzzer_args = base::SplitString(
31 output, "\n\r", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); 30 output, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
31
32 EXPECT_EQ(1UL, fuzzer_args.size());
33
34 EXPECT_EQ(fuzzer_args[0], "dict=test_dict_only.dict");
35 }
36
37
38 TEST(FuzzerConfigTest, ConfigOnly) {
39 // Test of .options file for fuzzer with libfuzzer_options and without dict.
40 base::FilePath exe_path;
41 PathService::Get(base::FILE_EXE, &exe_path);
42 std::string launcher_path =
43 exe_path.DirName().Append("check_fuzzer_config.py").value();
44
45 std::string output;
46 base::CommandLine cmd({{launcher_path, "test_config_only.options"}});
47 bool success = base::GetAppOutputAndError(cmd, &output);
48 EXPECT_TRUE(success);
49 std::vector<std::string> fuzzer_args = base::SplitString(
50 output, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
32 51
33 EXPECT_EQ(3UL, fuzzer_args.size()); 52 EXPECT_EQ(3UL, fuzzer_args.size());
34 53
35 EXPECT_THAT(fuzzer_args[0], EndsWith("print_args.py")); 54 EXPECT_EQ(fuzzer_args[0], "max_len=random(1337, 31337)");
36 EXPECT_THAT(fuzzer_args[1], StartsWith("-dict")); 55 EXPECT_EQ(fuzzer_args[1], "timeout=666");
37 EXPECT_THAT(fuzzer_args[1], EndsWith("test_dict")); 56 EXPECT_EQ(fuzzer_args[2], "use_traces=1");
38 EXPECT_EQ("-custom_option", fuzzer_args[2]);
39 } 57 }
58
59
60 TEST(FuzzerConfigTest, ConfigAndDict) {
61 // Test of .options file for fuzzer with options file and dictionary.
62 base::FilePath exe_path;
63 PathService::Get(base::FILE_EXE, &exe_path);
64 std::string launcher_path =
65 exe_path.DirName().Append("check_fuzzer_config.py").value();
66
67 std::string output;
68 base::CommandLine cmd({{launcher_path, "test_config_and_dict.options"}});
69 bool success = base::GetAppOutputAndError(cmd, &output);
70 EXPECT_TRUE(success);
71 std::vector<std::string> fuzzer_args = base::SplitString(
72 output, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
73
74 EXPECT_EQ(4UL, fuzzer_args.size());
75
76 EXPECT_EQ(fuzzer_args[0], "max_len=random(1337, 31337)");
77 EXPECT_EQ(fuzzer_args[1], "timeout=666");
78 EXPECT_EQ(fuzzer_args[2], "use_traces=1");
79 EXPECT_EQ(fuzzer_args[3], "dict=test_config_and_dict.dict");
80 }
81
82
83 TEST(FuzzerConfigTest, DictSubdir) {
84 // Test of auto-generated .options file for fuzzer with dict in sub-directory.
85 base::FilePath exe_path;
86 PathService::Get(base::FILE_EXE, &exe_path);
87 std::string launcher_path =
88 exe_path.DirName().Append("check_fuzzer_config.py").value();
89
90 std::string output;
91 base::CommandLine cmd({{launcher_path, "test_dict_from_subdir.options"}});
92 bool success = base::GetAppOutputAndError(cmd, &output);
93 EXPECT_TRUE(success);
94 std::vector<std::string> fuzzer_args = base::SplitString(
95 output, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
96
97 EXPECT_EQ(1UL, fuzzer_args.size());
98
99 EXPECT_EQ(fuzzer_args[0], "dict=test_dict_from_subdir.dict");
100 }
OLDNEW
« no previous file with comments | « testing/libfuzzer/tests/fuzzer_config_only_test.options ('k') | testing/libfuzzer/tests/print_args.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698