| 686 | const auto kDefaultEnvironment = SPV_ENV_UNIVERSAL_1_3; |
| 687 | |
| 688 | int main(int argc, const char** argv) { |
| 689 | std::string in_binary_file; |
| 690 | std::string out_binary_file; |
| 691 | std::string donors_file; |
| 692 | std::string replay_transformations_file; |
| 693 | std::vector<std::string> interestingness_test; |
| 694 | std::string shrink_transformations_file; |
| 695 | std::string shrink_temp_file_prefix = "temp_"; |
| 696 | spvtools::fuzz::RepeatedPassStrategy repeated_pass_strategy; |
| 697 | auto fuzzing_target = FuzzingTarget::kSpirv; |
| 698 | |
| 699 | spvtools::FuzzerOptions fuzzer_options; |
| 700 | spvtools::ValidatorOptions validator_options; |
| 701 | |
| 702 | FuzzStatus status = |
| 703 | ParseFlags(argc, argv, &in_binary_file, &out_binary_file, &donors_file, |
| 704 | &replay_transformations_file, &interestingness_test, |
| 705 | &shrink_transformations_file, &shrink_temp_file_prefix, |
| 706 | &repeated_pass_strategy, &fuzzing_target, &fuzzer_options, |
| 707 | &validator_options); |
| 708 | |
| 709 | if (status.action == FuzzActions::STOP) { |
| 710 | return status.code; |
| 711 | } |
| 712 | |
| 713 | std::vector<uint32_t> binary_in; |
| 714 | if (!ReadBinaryFile(in_binary_file.c_str(), &binary_in)) { |
| 715 | return 1; |
| 716 | } |
| 717 | |
| 718 | spvtools::fuzz::protobufs::FactSequence initial_facts; |
| 719 | |
| 720 | // If not found, dot_pos will be std::string::npos, which can be used in |
| 721 | // substr to mean "the end of the string"; there is no need to check the |
| 722 | // result. |
| 723 | size_t dot_pos = in_binary_file.rfind('.'); |
| 724 | std::string in_facts_file = in_binary_file.substr(0, dot_pos) + ".facts"; |
| 725 | std::ifstream facts_input(in_facts_file); |
| 726 | if (facts_input) { |
| 727 | std::string facts_json_string((std::istreambuf_iterator<char>(facts_input)), |
| 728 | std::istreambuf_iterator<char>()); |
| 729 | facts_input.close(); |
| 730 | if (!google::protobuf::util::JsonStringToMessage(facts_json_string, |
| 731 | &initial_facts) |
| 732 | .ok()) { |
| 733 | spvtools::Error(FuzzDiagnostic, nullptr, {}, "Error reading facts data"); |
| 734 | return 1; |
| 735 | } |
| 736 | } |
| 737 | |
| 738 | std::vector<uint32_t> binary_out; |
| 739 | spvtools::fuzz::protobufs::TransformationSequence transformations_applied; |
| 740 | |
| 741 | spv_target_env target_env = kDefaultEnvironment; |
| 742 | |
| 743 | switch (status.action) { |
| 744 | case FuzzActions::FORCE_RENDER_RED: |
| 745 | if (!spvtools::fuzz::ForceRenderRed( |
nothing calls this directly
no test coverage detected