fuzzer_util_test.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #include "executable_semantics/fuzzing/fuzzer_util.h"
  5. #include <gmock/gmock.h>
  6. #include <google/protobuf/text_format.h>
  7. #include <gtest/gtest.h>
  8. #include <fstream>
  9. #include "llvm/ADT/StringRef.h"
  10. #include "llvm/Support/raw_ostream.h"
  11. namespace Carbon::Testing {
  12. namespace {
  13. static std::vector<llvm::StringRef>* carbon_files = nullptr;
  14. // A workaround for https://github.com/carbon-language/carbon-lang/issues/1208.
  15. TEST(FuzzerUtilTest, RunFuzzerOnCorpus) {
  16. int file_count = 0;
  17. for (const llvm::StringRef f : *carbon_files) {
  18. llvm::outs() << "Processing " << f << "\n";
  19. std::ifstream file(f.str(), std::ios::in);
  20. ASSERT_TRUE(file.is_open());
  21. std::stringstream contents;
  22. contents << file.rdbuf();
  23. Fuzzing::Carbon carbon_proto;
  24. ASSERT_TRUE(google::protobuf::TextFormat::ParseFromString(contents.str(),
  25. &carbon_proto));
  26. ParseAndExecute(carbon_proto.compilation_unit());
  27. ++file_count;
  28. }
  29. EXPECT_GT(file_count, 0);
  30. }
  31. } // namespace
  32. } // namespace Carbon::Testing
  33. auto main(int argc, char** argv) -> int {
  34. ::testing::InitGoogleTest(&argc, argv);
  35. Carbon::Testing::carbon_files =
  36. new std::vector<llvm::StringRef>(&argv[1], &argv[argc]);
  37. return RUN_ALL_TESTS();
  38. }