Chromium Code Reviews| Index: testing/libfuzzer/unittest_main.cc |
| diff --git a/testing/libfuzzer/unittest_main.cc b/testing/libfuzzer/unittest_main.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..45fd2c6b3413141c7ba40b15da0563a82cbd66d7 |
| --- /dev/null |
| +++ b/testing/libfuzzer/unittest_main.cc |
| @@ -0,0 +1,32 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +// A simple unit-test style driver for libfuzzer tests. |
| +// Usage: <fuzzer_test> <file>... |
| + |
| +#include <fstream> |
| +#include <iostream> |
| +#include <iterator> |
| +#include <vector> |
| + |
| +extern "C" int LLVMFuzzerTestOneInput(const unsigned char* data, size_t size); |
| + |
| +std::vector<char> readFile(std::string path) { |
| + std::ifstream in(path); |
| + return std::vector<char>((std::istreambuf_iterator<char>(in)), |
| + std::istreambuf_iterator<char>()); |
| +} |
| + |
| +int main(int argc, char **argv) { |
| + if (argc == 1) { |
| + std::cerr << "Usage: " << argv[0] << " <file>..." << std::endl; |
| + exit(1); |
| + } |
| + |
| + for (int i = 1; i < argc; ++i) { |
| + std::cout << argv[i] << std::endl; |
| + auto v = readFile(argv[i]); |
| + LLVMFuzzerTestOneInput((const unsigned char *)v.data(), v.size()); |
|
mmoroz
2016/01/13 10:16:09
C++ type casts are preferable to C-style casts.
|
| + } |
| +} |