33
44#include < cstdlib>
55#include < string>
6- #include < string_view>
76#include < type_traits>
87#include < utility>
98#include < vector>
1312#include " absl/strings/str_cat.h"
1413#include " absl/strings/str_format.h"
1514#include " absl/strings/string_view.h"
16- #include " ./common/crashing_input_filename.h"
1715#include " ./common/logging.h"
1816#include " ./fuzztest/internal/configuration.h"
1917#include " ./fuzztest/internal/corpus_database.h"
2018#include " ./fuzztest/internal/flag_name.h"
21- #include " ./fuzztest/internal/io.h"
2219#include " ./fuzztest/internal/registry.h"
2320#include " ./fuzztest/internal/runtime.h"
2421
@@ -48,16 +45,29 @@ namespace {
4845template <typename T>
4946void RegisterFuzzTestAsGTest (int * argc, char *** argv, FuzzTest& test,
5047 const Configuration& configuration,
51- absl::string_view suffix = " " ) {
48+ absl::string_view crashing_input_path = " " ) {
5249 auto fixture_factory = [argc, argv, &test,
53- configuration = configuration]() -> T* {
54- return new ::fuzztest::internal::GTest_TestAdaptor (test, argc, argv,
55- configuration);
50+ configuration = configuration]() mutable -> T* {
51+ return new ::fuzztest::internal::GTest_TestAdaptor (
52+ test, argc, argv, std::move ( configuration) );
5653 };
57- const std::string test_name_with_suffix =
58- absl::StrCat (test.test_name (), suffix);
54+ if (crashing_input_path.empty ()) {
55+ ::testing::RegisterTest (test.suite_name().c_str(), test.test_name().c_str(),
56+ nullptr, nullptr, test.file().c_str(), test.line(),
57+ std::move(fixture_factory));
58+ return ;
59+ }
60+ const absl::StatusOr<std::string> regression_test_name =
61+ RegressionTestNameForCrashingInput (test.test_name (), crashing_input_path);
62+ if (!regression_test_name.ok ()) {
63+ FUZZTEST_LOG (WARNING)
64+ << " Failed to get regression test name for crashing input "
65+ << crashing_input_path << " . Not registering a regression test for it. "
66+ << " Status: " << regression_test_name.status ();
67+ return ;
68+ }
5969 ::testing::RegisterTest (
60- test.suite_name().c_str(), test_name_with_suffix. c_str(), nullptr,
70+ test.suite_name().c_str(), regression_test_name-> c_str(), nullptr,
6171 nullptr, test.file().c_str(), test.line(), std::move(fixture_factory));
6272}
6373
@@ -77,19 +87,7 @@ void RegisterSeparateRegressionTestForEachCrashingInput(
7787 for (const std::string& input : crash_inputs) {
7888 Configuration updated_configuration = configuration;
7989 updated_configuration.crashing_input_to_reproduce = input;
80- absl::string_view file_name = Basename (input);
81- const absl::StatusOr<InputFileComponents> components =
82- ParseCrashingInputFilename (
83- std::string_view{file_name.data (), file_name.size ()});
84- if (!components.ok ()) {
85- FUZZTEST_LOG (WARNING)
86- << " Failed to parse crashing input filename " << file_name
87- << " . Not registering a regression test for it. Status: "
88- << components.status ();
89- continue ;
90- }
91- const std::string suffix = absl::StrCat (" /Regression/" , components->bug_id );
92- RegisterFuzzTestAsGTest<T>(argc, argv, test, updated_configuration, suffix);
90+ RegisterFuzzTestAsGTest<T>(argc, argv, test, updated_configuration, input);
9391 }
9492}
9593
0 commit comments