LCOV - code coverage report
Current view: top level - lib/FuzzMutate - FuzzerCLI.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 25 28 89.3 %
Date: 2017-09-14 15:23:50 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===-- FuzzerCLI.cpp -----------------------------------------------------===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : 
      10             : #include "llvm/FuzzMutate/FuzzerCLI.h"
      11             : #include "llvm/ADT/StringRef.h"
      12             : #include "llvm/Support/CommandLine.h"
      13             : #include "llvm/Support/Compiler.h"
      14             : #include "llvm/Support/Error.h"
      15             : #include "llvm/Support/MemoryBuffer.h"
      16             : #include "llvm/Support/raw_ostream.h"
      17             : 
      18             : using namespace llvm;
      19             : 
      20           5 : void llvm::parseFuzzerCLOpts(int ArgC, char *ArgV[]) {
      21          10 :   std::vector<const char *> CLArgs;
      22          10 :   CLArgs.push_back(ArgV[0]);
      23             : 
      24           5 :   int I = 1;
      25          10 :   while (I < ArgC)
      26          22 :     if (StringRef(ArgV[I++]).equals("-ignore_remaining_args=1"))
      27             :       break;
      28          21 :   while (I < ArgC)
      29          16 :     CLArgs.push_back(ArgV[I++]);
      30             : 
      31          15 :   cl::ParseCommandLineOptions(CLArgs.size(), CLArgs.data());
      32           5 : }
      33             : 
      34           5 : int llvm::runFuzzerOnInputs(int ArgC, char *ArgV[], FuzzerTestFun TestOne,
      35             :                             FuzzerInitFun Init) {
      36           5 :   errs() << "*** This tool was not linked to libFuzzer.\n"
      37           5 :          << "*** No fuzzing will be performed.\n";
      38           5 :   if (int RC = Init(&ArgC, &ArgV)) {
      39           1 :     errs() << "Initialization failed\n";
      40           1 :     return RC;
      41             :   }
      42             : 
      43          12 :   for (int I = 1; I < ArgC; ++I) {
      44          16 :     StringRef Arg(ArgV[I]);
      45          12 :     if (Arg.startswith("-")) {
      46           8 :       if (Arg.equals("-ignore_remaining_args=1"))
      47             :         break;
      48           0 :       continue;
      49             :     }
      50             : 
      51             :     auto BufOrErr = MemoryBuffer::getFile(Arg, /*FileSize-*/ -1,
      52           8 :                                           /*RequiresNullTerminator=*/false);
      53           4 :     if (std::error_code EC = BufOrErr.getError()) {
      54           0 :       errs() << "Error reading file: " << Arg << ": " << EC.message() << "\n";
      55           0 :       return 1;
      56             :     }
      57          12 :     std::unique_ptr<MemoryBuffer> Buf = std::move(BufOrErr.get());
      58          12 :     errs() << "Running: " << Arg << " (" << Buf->getBufferSize() << " bytes)\n";
      59          12 :     TestOne(reinterpret_cast<const uint8_t *>(Buf->getBufferStart()),
      60             :             Buf->getBufferSize());
      61             :   }
      62             :   return 0;
      63             : }

Generated by: LCOV version 1.13