regression_runner.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include <boost/filesystem.hpp>
  2. #include <gtest/gtest.h>
  3. #include <fstream>
  4. #include <iostream>
  5. #include <vector>
  6. #include "unpack_pack_fuzzer.cpp"
  7. using ::testing::TestWithParam;
  8. using ::testing::ValuesIn;
  9. std::vector<std::string> ListDirectory(const std::string& path) {
  10. std::vector<std::string> v;
  11. boost::filesystem::path p(path);
  12. boost::filesystem::directory_iterator f{p};
  13. if(boost::filesystem::is_directory(p)) {
  14. while (f != boost::filesystem::directory_iterator{}) {
  15. v.push_back((*f++).path().string());
  16. }
  17. }
  18. return v;
  19. }
  20. class UnpackPackFuzzerRegressionTest : public ::testing::TestWithParam<std::string> {
  21. public:
  22. };
  23. TEST_P(UnpackPackFuzzerRegressionTest, Returns0) {
  24. auto fpath = GetParam();
  25. std::ifstream in(fpath, std::ifstream::binary);
  26. if (!in) {
  27. FAIL() << fpath << " not found";
  28. }
  29. in.seekg(0, in.end);
  30. size_t length = in.tellg();
  31. in.seekg(0, in.beg);
  32. std::vector<char> bytes(length);
  33. in.read(bytes.data(), bytes.size());
  34. assert(in);
  35. EXPECT_EQ(0, LLVMFuzzerTestOneInput(reinterpret_cast<const uint8_t *>(bytes.data()),
  36. bytes.size()));
  37. }
  38. INSTANTIATE_TEST_CASE_P(UnpackPackFuzzerRegressions,
  39. UnpackPackFuzzerRegressionTest,
  40. ::testing::ValuesIn(ListDirectory("../../fuzz/unpack_pack_fuzzer_regressions")));