george.karpenkov | 29efa6d | 2017-08-21 23:25:50 +0000 | [diff] [blame] | 1 | //===- FuzzerMerge.cpp - merging corpora ----------------------------------===// |
| 2 | // |
chandlerc | 4028449 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
george.karpenkov | 29efa6d | 2017-08-21 23:25:50 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // Merging corpora. |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | |
morehouse | a80f645 | 2017-12-04 19:25:59 +0000 | [diff] [blame] | 11 | #include "FuzzerCommand.h" |
george.karpenkov | 29efa6d | 2017-08-21 23:25:50 +0000 | [diff] [blame] | 12 | #include "FuzzerMerge.h" |
| 13 | #include "FuzzerIO.h" |
| 14 | #include "FuzzerInternal.h" |
| 15 | #include "FuzzerTracePC.h" |
| 16 | #include "FuzzerUtil.h" |
| 17 | |
| 18 | #include <fstream> |
| 19 | #include <iterator> |
| 20 | #include <set> |
| 21 | #include <sstream> |
| 22 | |
| 23 | namespace fuzzer { |
| 24 | |
| 25 | bool Merger::Parse(const std::string &Str, bool ParseCoverage) { |
| 26 | std::istringstream SS(Str); |
| 27 | return Parse(SS, ParseCoverage); |
| 28 | } |
| 29 | |
| 30 | void Merger::ParseOrExit(std::istream &IS, bool ParseCoverage) { |
| 31 | if (!Parse(IS, ParseCoverage)) { |
| 32 | Printf("MERGE: failed to parse the control file (unexpected error)\n"); |
| 33 | exit(1); |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | // The control file example: |
| 38 | // |
| 39 | // 3 # The number of inputs |
| 40 | // 1 # The number of inputs in the first corpus, <= the previous number |
| 41 | // file0 |
| 42 | // file1 |
| 43 | // file2 # One file name per line. |
| 44 | // STARTED 0 123 # FileID, file size |
| 45 | // DONE 0 1 4 6 8 # FileID COV1 COV2 ... |
| 46 | // STARTED 1 456 # If DONE is missing, the input crashed while processing. |
| 47 | // STARTED 2 567 |
| 48 | // DONE 2 8 9 |
| 49 | bool Merger::Parse(std::istream &IS, bool ParseCoverage) { |
| 50 | LastFailure.clear(); |
| 51 | std::string Line; |
| 52 | |
| 53 | // Parse NumFiles. |
| 54 | if (!std::getline(IS, Line, '\n')) return false; |
| 55 | std::istringstream L1(Line); |
| 56 | size_t NumFiles = 0; |
| 57 | L1 >> NumFiles; |
| 58 | if (NumFiles == 0 || NumFiles > 10000000) return false; |
| 59 | |
| 60 | // Parse NumFilesInFirstCorpus. |
| 61 | if (!std::getline(IS, Line, '\n')) return false; |
| 62 | std::istringstream L2(Line); |
| 63 | NumFilesInFirstCorpus = NumFiles + 1; |
| 64 | L2 >> NumFilesInFirstCorpus; |
| 65 | if (NumFilesInFirstCorpus > NumFiles) return false; |
| 66 | |
| 67 | // Parse file names. |
| 68 | Files.resize(NumFiles); |
| 69 | for (size_t i = 0; i < NumFiles; i++) |
| 70 | if (!std::getline(IS, Files[i].Name, '\n')) |
| 71 | return false; |
| 72 | |
| 73 | // Parse STARTED and DONE lines. |
| 74 | size_t ExpectedStartMarker = 0; |
| 75 | const size_t kInvalidStartMarker = -1; |
| 76 | size_t LastSeenStartMarker = kInvalidStartMarker; |
george.karpenkov | fbfa45c | 2017-08-27 23:20:09 +0000 | [diff] [blame] | 77 | Vector<uint32_t> TmpFeatures; |
george.karpenkov | 29efa6d | 2017-08-21 23:25:50 +0000 | [diff] [blame] | 78 | while (std::getline(IS, Line, '\n')) { |
| 79 | std::istringstream ISS1(Line); |
| 80 | std::string Marker; |
| 81 | size_t N; |
| 82 | ISS1 >> Marker; |
| 83 | ISS1 >> N; |
| 84 | if (Marker == "STARTED") { |
| 85 | // STARTED FILE_ID FILE_SIZE |
| 86 | if (ExpectedStartMarker != N) |
| 87 | return false; |
| 88 | ISS1 >> Files[ExpectedStartMarker].Size; |
| 89 | LastSeenStartMarker = ExpectedStartMarker; |
| 90 | assert(ExpectedStartMarker < Files.size()); |
| 91 | ExpectedStartMarker++; |
| 92 | } else if (Marker == "DONE") { |
| 93 | // DONE FILE_ID COV1 COV2 COV3 ... |
| 94 | size_t CurrentFileIdx = N; |
| 95 | if (CurrentFileIdx != LastSeenStartMarker) |
| 96 | return false; |
| 97 | LastSeenStartMarker = kInvalidStartMarker; |
| 98 | if (ParseCoverage) { |
| 99 | TmpFeatures.clear(); // use a vector from outer scope to avoid resizes. |
| 100 | while (ISS1 >> std::hex >> N) |
| 101 | TmpFeatures.push_back(N); |
mgrang | 2c1f00d | 2018-03-20 01:17:18 +0000 | [diff] [blame] | 102 | std::sort(TmpFeatures.begin(), TmpFeatures.end()); |
george.karpenkov | 29efa6d | 2017-08-21 23:25:50 +0000 | [diff] [blame] | 103 | Files[CurrentFileIdx].Features = TmpFeatures; |
| 104 | } |
| 105 | } else { |
| 106 | return false; |
| 107 | } |
| 108 | } |
| 109 | if (LastSeenStartMarker != kInvalidStartMarker) |
| 110 | LastFailure = Files[LastSeenStartMarker].Name; |
| 111 | |
| 112 | FirstNotProcessedFile = ExpectedStartMarker; |
| 113 | return true; |
| 114 | } |
| 115 | |
| 116 | size_t Merger::ApproximateMemoryConsumption() const { |
| 117 | size_t Res = 0; |
| 118 | for (const auto &F: Files) |
| 119 | Res += sizeof(F) + F.Features.size() * sizeof(F.Features[0]); |
| 120 | return Res; |
| 121 | } |
| 122 | |
kcc | 243006d | 2019-02-12 00:12:33 +0000 | [diff] [blame] | 123 | // Decides which files need to be merged (add those to NewFiles). |
george.karpenkov | 29efa6d | 2017-08-21 23:25:50 +0000 | [diff] [blame] | 124 | // Returns the number of new features added. |
kcc | 4b5aa12 | 2019-02-09 00:16:21 +0000 | [diff] [blame] | 125 | size_t Merger::Merge(const Set<uint32_t> &InitialFeatures, |
kcc | 243006d | 2019-02-12 00:12:33 +0000 | [diff] [blame] | 126 | Set<uint32_t> *NewFeatures, |
george.karpenkov | fbfa45c | 2017-08-27 23:20:09 +0000 | [diff] [blame] | 127 | Vector<std::string> *NewFiles) { |
george.karpenkov | 29efa6d | 2017-08-21 23:25:50 +0000 | [diff] [blame] | 128 | NewFiles->clear(); |
| 129 | assert(NumFilesInFirstCorpus <= Files.size()); |
kcc | 243006d | 2019-02-12 00:12:33 +0000 | [diff] [blame] | 130 | Set<uint32_t> AllFeatures = InitialFeatures; |
george.karpenkov | 29efa6d | 2017-08-21 23:25:50 +0000 | [diff] [blame] | 131 | |
| 132 | // What features are in the initial corpus? |
| 133 | for (size_t i = 0; i < NumFilesInFirstCorpus; i++) { |
| 134 | auto &Cur = Files[i].Features; |
kcc | 243006d | 2019-02-12 00:12:33 +0000 | [diff] [blame] | 135 | AllFeatures.insert(Cur.begin(), Cur.end()); |
george.karpenkov | 29efa6d | 2017-08-21 23:25:50 +0000 | [diff] [blame] | 136 | } |
kcc | 243006d | 2019-02-12 00:12:33 +0000 | [diff] [blame] | 137 | size_t InitialNumFeatures = AllFeatures.size(); |
george.karpenkov | 29efa6d | 2017-08-21 23:25:50 +0000 | [diff] [blame] | 138 | |
| 139 | // Remove all features that we already know from all other inputs. |
| 140 | for (size_t i = NumFilesInFirstCorpus; i < Files.size(); i++) { |
| 141 | auto &Cur = Files[i].Features; |
george.karpenkov | fbfa45c | 2017-08-27 23:20:09 +0000 | [diff] [blame] | 142 | Vector<uint32_t> Tmp; |
kcc | 243006d | 2019-02-12 00:12:33 +0000 | [diff] [blame] | 143 | std::set_difference(Cur.begin(), Cur.end(), AllFeatures.begin(), |
| 144 | AllFeatures.end(), std::inserter(Tmp, Tmp.begin())); |
george.karpenkov | 29efa6d | 2017-08-21 23:25:50 +0000 | [diff] [blame] | 145 | Cur.swap(Tmp); |
| 146 | } |
| 147 | |
| 148 | // Sort. Give preference to |
| 149 | // * smaller files |
| 150 | // * files with more features. |
mgrang | 2c1f00d | 2018-03-20 01:17:18 +0000 | [diff] [blame] | 151 | std::sort(Files.begin() + NumFilesInFirstCorpus, Files.end(), |
| 152 | [&](const MergeFileInfo &a, const MergeFileInfo &b) -> bool { |
| 153 | if (a.Size != b.Size) |
| 154 | return a.Size < b.Size; |
| 155 | return a.Features.size() > b.Features.size(); |
| 156 | }); |
george.karpenkov | 29efa6d | 2017-08-21 23:25:50 +0000 | [diff] [blame] | 157 | |
| 158 | // One greedy pass: add the file's features to AllFeatures. |
| 159 | // If new features were added, add this file to NewFiles. |
| 160 | for (size_t i = NumFilesInFirstCorpus; i < Files.size(); i++) { |
| 161 | auto &Cur = Files[i].Features; |
| 162 | // Printf("%s -> sz %zd ft %zd\n", Files[i].Name.c_str(), |
| 163 | // Files[i].Size, Cur.size()); |
kcc | 243006d | 2019-02-12 00:12:33 +0000 | [diff] [blame] | 164 | bool FoundNewFeatures = false; |
| 165 | for (auto Fe: Cur) { |
| 166 | if (AllFeatures.insert(Fe).second) { |
| 167 | FoundNewFeatures = true; |
| 168 | NewFeatures->insert(Fe); |
| 169 | } |
| 170 | } |
| 171 | if (FoundNewFeatures) |
george.karpenkov | 29efa6d | 2017-08-21 23:25:50 +0000 | [diff] [blame] | 172 | NewFiles->push_back(Files[i].Name); |
| 173 | } |
kcc | 243006d | 2019-02-12 00:12:33 +0000 | [diff] [blame] | 174 | return AllFeatures.size() - InitialNumFeatures; |
george.karpenkov | 29efa6d | 2017-08-21 23:25:50 +0000 | [diff] [blame] | 175 | } |
| 176 | |
george.karpenkov | fbfa45c | 2017-08-27 23:20:09 +0000 | [diff] [blame] | 177 | Set<uint32_t> Merger::AllFeatures() const { |
| 178 | Set<uint32_t> S; |
george.karpenkov | 29efa6d | 2017-08-21 23:25:50 +0000 | [diff] [blame] | 179 | for (auto &File : Files) |
| 180 | S.insert(File.Features.begin(), File.Features.end()); |
| 181 | return S; |
| 182 | } |
| 183 | |
george.karpenkov | 29efa6d | 2017-08-21 23:25:50 +0000 | [diff] [blame] | 184 | // Inner process. May crash if the target crashes. |
| 185 | void Fuzzer::CrashResistantMergeInternalStep(const std::string &CFPath) { |
| 186 | Printf("MERGE-INNER: using the control file '%s'\n", CFPath.c_str()); |
| 187 | Merger M; |
| 188 | std::ifstream IF(CFPath); |
| 189 | M.ParseOrExit(IF, false); |
| 190 | IF.close(); |
| 191 | if (!M.LastFailure.empty()) |
| 192 | Printf("MERGE-INNER: '%s' caused a failure at the previous merge step\n", |
| 193 | M.LastFailure.c_str()); |
| 194 | |
| 195 | Printf("MERGE-INNER: %zd total files;" |
| 196 | " %zd processed earlier; will process %zd files now\n", |
| 197 | M.Files.size(), M.FirstNotProcessedFile, |
| 198 | M.Files.size() - M.FirstNotProcessedFile); |
| 199 | |
| 200 | std::ofstream OF(CFPath, std::ofstream::out | std::ofstream::app); |
kcc | b966c9e | 2017-09-15 22:02:26 +0000 | [diff] [blame] | 201 | Set<size_t> AllFeatures; |
george.karpenkov | 29efa6d | 2017-08-21 23:25:50 +0000 | [diff] [blame] | 202 | for (size_t i = M.FirstNotProcessedFile; i < M.Files.size(); i++) { |
kcc | a381586 | 2019-02-08 21:27:23 +0000 | [diff] [blame] | 203 | Fuzzer::MaybeExitGracefully(); |
george.karpenkov | 29efa6d | 2017-08-21 23:25:50 +0000 | [diff] [blame] | 204 | auto U = FileToVector(M.Files[i].Name); |
| 205 | if (U.size() > MaxInputLen) { |
| 206 | U.resize(MaxInputLen); |
| 207 | U.shrink_to_fit(); |
| 208 | } |
| 209 | std::ostringstream StartedLine; |
| 210 | // Write the pre-run marker. |
| 211 | OF << "STARTED " << std::dec << i << " " << U.size() << "\n"; |
morehouse | a80f645 | 2017-12-04 19:25:59 +0000 | [diff] [blame] | 212 | OF.flush(); // Flush is important since Command::Execute may crash. |
george.karpenkov | 29efa6d | 2017-08-21 23:25:50 +0000 | [diff] [blame] | 213 | // Run. |
| 214 | TPC.ResetMaps(); |
| 215 | ExecuteCallback(U.data(), U.size()); |
kcc | b966c9e | 2017-09-15 22:02:26 +0000 | [diff] [blame] | 216 | // Collect coverage. We are iterating over the files in this order: |
| 217 | // * First, files in the initial corpus ordered by size, smallest first. |
| 218 | // * Then, all other files, smallest first. |
| 219 | // So it makes no sense to record all features for all files, instead we |
| 220 | // only record features that were not seen before. |
| 221 | Set<size_t> UniqFeatures; |
kcc | c924e38 | 2017-09-15 22:10:36 +0000 | [diff] [blame] | 222 | TPC.CollectFeatures([&](size_t Feature) { |
kcc | b966c9e | 2017-09-15 22:02:26 +0000 | [diff] [blame] | 223 | if (AllFeatures.insert(Feature).second) |
| 224 | UniqFeatures.insert(Feature); |
george.karpenkov | 29efa6d | 2017-08-21 23:25:50 +0000 | [diff] [blame] | 225 | }); |
| 226 | // Show stats. |
| 227 | if (!(TotalNumberOfRuns & (TotalNumberOfRuns - 1))) |
| 228 | PrintStats("pulse "); |
| 229 | // Write the post-run marker and the coverage. |
| 230 | OF << "DONE " << i; |
kcc | b966c9e | 2017-09-15 22:02:26 +0000 | [diff] [blame] | 231 | for (size_t F : UniqFeatures) |
george.karpenkov | 29efa6d | 2017-08-21 23:25:50 +0000 | [diff] [blame] | 232 | OF << " " << std::hex << F; |
| 233 | OF << "\n"; |
kcc | a00e807 | 2017-11-09 21:30:33 +0000 | [diff] [blame] | 234 | OF.flush(); |
george.karpenkov | 29efa6d | 2017-08-21 23:25:50 +0000 | [diff] [blame] | 235 | } |
| 236 | } |
| 237 | |
kcc | 99a71a1 | 2017-11-09 05:49:28 +0000 | [diff] [blame] | 238 | static void WriteNewControlFile(const std::string &CFPath, |
kcc | d1449be | 2019-02-08 22:59:03 +0000 | [diff] [blame] | 239 | const Vector<SizedFile> &OldCorpus, |
| 240 | const Vector<SizedFile> &NewCorpus) { |
george.karpenkov | 29efa6d | 2017-08-21 23:25:50 +0000 | [diff] [blame] | 241 | RemoveFile(CFPath); |
| 242 | std::ofstream ControlFile(CFPath); |
kcc | d1449be | 2019-02-08 22:59:03 +0000 | [diff] [blame] | 243 | ControlFile << (OldCorpus.size() + NewCorpus.size()) << "\n"; |
| 244 | ControlFile << OldCorpus.size() << "\n"; |
| 245 | for (auto &SF: OldCorpus) |
| 246 | ControlFile << SF.File << "\n"; |
| 247 | for (auto &SF: NewCorpus) |
kcc | b966c9e | 2017-09-15 22:02:26 +0000 | [diff] [blame] | 248 | ControlFile << SF.File << "\n"; |
george.karpenkov | 29efa6d | 2017-08-21 23:25:50 +0000 | [diff] [blame] | 249 | if (!ControlFile) { |
| 250 | Printf("MERGE-OUTER: failed to write to the control file: %s\n", |
| 251 | CFPath.c_str()); |
| 252 | exit(1); |
| 253 | } |
kcc | 99a71a1 | 2017-11-09 05:49:28 +0000 | [diff] [blame] | 254 | } |
george.karpenkov | 29efa6d | 2017-08-21 23:25:50 +0000 | [diff] [blame] | 255 | |
kcc | d1449be | 2019-02-08 22:59:03 +0000 | [diff] [blame] | 256 | // Outer process. Does not call the target code and thus should not fail. |
kcc | 4b5aa12 | 2019-02-09 00:16:21 +0000 | [diff] [blame] | 257 | void CrashResistantMerge(const Vector<std::string> &Args, |
kcc | bfb5975 | 2019-02-12 03:12:40 +0000 | [diff] [blame^] | 258 | const Vector<SizedFile> &OldCorpus, |
| 259 | const Vector<SizedFile> &NewCorpus, |
| 260 | Vector<std::string> *NewFiles, |
| 261 | const Set<uint32_t> &InitialFeatures, |
| 262 | Set<uint32_t> *NewFeatures, const std::string &CFPath, |
| 263 | bool V /*Verbose*/) { |
kcc | 99a71a1 | 2017-11-09 05:49:28 +0000 | [diff] [blame] | 264 | size_t NumAttempts = 0; |
kcc | a381586 | 2019-02-08 21:27:23 +0000 | [diff] [blame] | 265 | if (FileSize(CFPath)) { |
kcc | bfb5975 | 2019-02-12 03:12:40 +0000 | [diff] [blame^] | 266 | VPrintf(V, "MERGE-OUTER: non-empty control file provided: '%s'\n", |
kcc | a381586 | 2019-02-08 21:27:23 +0000 | [diff] [blame] | 267 | CFPath.c_str()); |
kcc | 99a71a1 | 2017-11-09 05:49:28 +0000 | [diff] [blame] | 268 | Merger M; |
kcc | a381586 | 2019-02-08 21:27:23 +0000 | [diff] [blame] | 269 | std::ifstream IF(CFPath); |
kcc | 99a71a1 | 2017-11-09 05:49:28 +0000 | [diff] [blame] | 270 | if (M.Parse(IF, /*ParseCoverage=*/false)) { |
kcc | bfb5975 | 2019-02-12 03:12:40 +0000 | [diff] [blame^] | 271 | VPrintf(V, "MERGE-OUTER: control file ok, %zd files total," |
kcc | 99a71a1 | 2017-11-09 05:49:28 +0000 | [diff] [blame] | 272 | " first not processed file %zd\n", |
| 273 | M.Files.size(), M.FirstNotProcessedFile); |
| 274 | if (!M.LastFailure.empty()) |
kcc | bfb5975 | 2019-02-12 03:12:40 +0000 | [diff] [blame^] | 275 | VPrintf(V, "MERGE-OUTER: '%s' will be skipped as unlucky " |
kcc | 99a71a1 | 2017-11-09 05:49:28 +0000 | [diff] [blame] | 276 | "(merge has stumbled on it the last time)\n", |
| 277 | M.LastFailure.c_str()); |
| 278 | if (M.FirstNotProcessedFile >= M.Files.size()) { |
kcc | bfb5975 | 2019-02-12 03:12:40 +0000 | [diff] [blame^] | 279 | VPrintf( |
| 280 | V, "MERGE-OUTER: nothing to do, merge has been completed before\n"); |
kcc | 99a71a1 | 2017-11-09 05:49:28 +0000 | [diff] [blame] | 281 | exit(0); |
| 282 | } |
| 283 | |
| 284 | NumAttempts = M.Files.size() - M.FirstNotProcessedFile; |
| 285 | } else { |
kcc | bfb5975 | 2019-02-12 03:12:40 +0000 | [diff] [blame^] | 286 | VPrintf(V, "MERGE-OUTER: bad control file, will overwrite it\n"); |
kcc | 99a71a1 | 2017-11-09 05:49:28 +0000 | [diff] [blame] | 287 | } |
| 288 | } |
| 289 | |
| 290 | if (!NumAttempts) { |
| 291 | // The supplied control file is empty or bad, create a fresh one. |
kcc | d1449be | 2019-02-08 22:59:03 +0000 | [diff] [blame] | 292 | NumAttempts = OldCorpus.size() + NewCorpus.size(); |
kcc | bfb5975 | 2019-02-12 03:12:40 +0000 | [diff] [blame^] | 293 | VPrintf(V, "MERGE-OUTER: %zd files, %zd in the initial corpus\n", |
| 294 | NumAttempts, OldCorpus.size()); |
kcc | d1449be | 2019-02-08 22:59:03 +0000 | [diff] [blame] | 295 | WriteNewControlFile(CFPath, OldCorpus, NewCorpus); |
kcc | 99a71a1 | 2017-11-09 05:49:28 +0000 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | // Execute the inner process until it passes. |
george.karpenkov | 29efa6d | 2017-08-21 23:25:50 +0000 | [diff] [blame] | 299 | // Every inner process should execute at least one input. |
morehouse | a80f645 | 2017-12-04 19:25:59 +0000 | [diff] [blame] | 300 | Command BaseCmd(Args); |
| 301 | BaseCmd.removeFlag("merge"); |
kcc | a381586 | 2019-02-08 21:27:23 +0000 | [diff] [blame] | 302 | BaseCmd.removeFlag("fork"); |
kcc | 99a71a1 | 2017-11-09 05:49:28 +0000 | [diff] [blame] | 303 | for (size_t Attempt = 1; Attempt <= NumAttempts; Attempt++) { |
kcc | a381586 | 2019-02-08 21:27:23 +0000 | [diff] [blame] | 304 | Fuzzer::MaybeExitGracefully(); |
kcc | bfb5975 | 2019-02-12 03:12:40 +0000 | [diff] [blame^] | 305 | VPrintf(V, "MERGE-OUTER: attempt %zd\n", Attempt); |
morehouse | a80f645 | 2017-12-04 19:25:59 +0000 | [diff] [blame] | 306 | Command Cmd(BaseCmd); |
| 307 | Cmd.addFlag("merge_control_file", CFPath); |
| 308 | Cmd.addFlag("merge_inner", "1"); |
kcc | bfb5975 | 2019-02-12 03:12:40 +0000 | [diff] [blame^] | 309 | if (!V) { |
| 310 | Cmd.setOutputFile("/dev/null"); // TODO: need to handle this on Windows? |
| 311 | Cmd.combineOutAndErr(); |
| 312 | } |
morehouse | a80f645 | 2017-12-04 19:25:59 +0000 | [diff] [blame] | 313 | auto ExitCode = ExecuteCommand(Cmd); |
george.karpenkov | 29efa6d | 2017-08-21 23:25:50 +0000 | [diff] [blame] | 314 | if (!ExitCode) { |
kcc | bfb5975 | 2019-02-12 03:12:40 +0000 | [diff] [blame^] | 315 | VPrintf(V, "MERGE-OUTER: succesfull in %zd attempt(s)\n", Attempt); |
george.karpenkov | 29efa6d | 2017-08-21 23:25:50 +0000 | [diff] [blame] | 316 | break; |
| 317 | } |
| 318 | } |
george.karpenkov | 29efa6d | 2017-08-21 23:25:50 +0000 | [diff] [blame] | 319 | // Read the control file and do the merge. |
| 320 | Merger M; |
| 321 | std::ifstream IF(CFPath); |
| 322 | IF.seekg(0, IF.end); |
kcc | bfb5975 | 2019-02-12 03:12:40 +0000 | [diff] [blame^] | 323 | VPrintf(V, "MERGE-OUTER: the control file has %zd bytes\n", |
| 324 | (size_t)IF.tellg()); |
george.karpenkov | 29efa6d | 2017-08-21 23:25:50 +0000 | [diff] [blame] | 325 | IF.seekg(0, IF.beg); |
| 326 | M.ParseOrExit(IF, true); |
| 327 | IF.close(); |
kcc | bfb5975 | 2019-02-12 03:12:40 +0000 | [diff] [blame^] | 328 | VPrintf(V, |
| 329 | "MERGE-OUTER: consumed %zdMb (%zdMb rss) to parse the control file\n", |
| 330 | M.ApproximateMemoryConsumption() >> 20, GetPeakRSSMb()); |
kcc | 4b5aa12 | 2019-02-09 00:16:21 +0000 | [diff] [blame] | 331 | size_t NumNewFeatures = M.Merge(InitialFeatures, NewFeatures, NewFiles); |
kcc | bfb5975 | 2019-02-12 03:12:40 +0000 | [diff] [blame^] | 332 | VPrintf(V, "MERGE-OUTER: %zd new files with %zd new features added\n", |
kcc | 4b5aa12 | 2019-02-09 00:16:21 +0000 | [diff] [blame] | 333 | NewFiles->size(), NumNewFeatures); |
george.karpenkov | 29efa6d | 2017-08-21 23:25:50 +0000 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | } // namespace fuzzer |