From 89d502c0a668851f0bd85ee51ab4cd14a9d3b3dd Mon Sep 17 00:00:00 2001 From: Filip Niksic Date: Mon, 23 Oct 2023 08:00:13 -0700 Subject: [PATCH] Switch from std::string_view to absl::string_view at a few places. This is not a comprehensive fix to this inconsistency, but a local one for the code that has to do with test registration. PiperOrigin-RevId: 575819311 --- fuzztest/BUILD | 1 + fuzztest/CMakeLists.txt | 1 + fuzztest/internal/registry.cc | 10 +++++----- fuzztest/internal/registry.h | 9 ++++----- fuzztest/internal/runtime.cc | 3 ++- fuzztest/internal/runtime.h | 6 +----- 6 files changed, 14 insertions(+), 16 deletions(-) diff --git a/fuzztest/BUILD b/fuzztest/BUILD index 2e04944a..29fb29e8 100644 --- a/fuzztest/BUILD +++ b/fuzztest/BUILD @@ -393,6 +393,7 @@ cc_library( ":runtime", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/functional:function_ref", + "@com_google_absl//absl/strings:string_view", ] + select({ "@com_google_fuzztest//fuzztest:use_centipede": [":centipede_adaptor"], "//conditions:default": [], diff --git a/fuzztest/CMakeLists.txt b/fuzztest/CMakeLists.txt index 76bdec03..67df5569 100644 --- a/fuzztest/CMakeLists.txt +++ b/fuzztest/CMakeLists.txt @@ -625,6 +625,7 @@ target_link_libraries( fuzztest_runtime absl::flat_hash_map absl::function_ref + absl::string_view ) add_library( diff --git a/fuzztest/internal/registry.cc b/fuzztest/internal/registry.cc index 4dc5924d..cafa3775 100644 --- a/fuzztest/internal/registry.cc +++ b/fuzztest/internal/registry.cc @@ -16,11 +16,11 @@ #include #include -#include #include #include "absl/container/flat_hash_map.h" #include "absl/functional/function_ref.h" +#include "absl/strings/string_view.h" #include "./fuzztest/internal/registration.h" #include "./fuzztest/internal/runtime.h" @@ -43,7 +43,7 @@ auto& SetUpTearDownTestSuiteRegistry() { } SetUpTearDownTestSuiteFunctionPair GetSetUpTearDownTestSuiteFunctions( - std::string_view suite_name) { + absl::string_view suite_name) { if (auto it = SetUpTearDownTestSuiteRegistry().find(std::string(suite_name)); it != SetUpTearDownTestSuiteRegistry().end()) { return it->second; @@ -62,19 +62,19 @@ void RegisterImpl(BasicTestInfo test_info, FuzzTestFuzzerFactory factory) { } void RegisterSetUpTearDownTestSuiteFunctions( - std::string_view suite_name, + absl::string_view suite_name, SetUpTearDownTestSuiteFunction set_up_test_suite, SetUpTearDownTestSuiteFunction tear_down_test_suite) { SetUpTearDownTestSuiteRegistry().try_emplace( std::string(suite_name), set_up_test_suite, tear_down_test_suite); } -SetUpTearDownTestSuiteFunction GetSetUpTestSuite(std::string_view suite_name) { +SetUpTearDownTestSuiteFunction GetSetUpTestSuite(absl::string_view suite_name) { return GetSetUpTearDownTestSuiteFunctions(suite_name).first; } SetUpTearDownTestSuiteFunction GetTearDownTestSuite( - std::string_view suite_name) { + absl::string_view suite_name) { return GetSetUpTearDownTestSuiteFunctions(suite_name).second; } diff --git a/fuzztest/internal/registry.h b/fuzztest/internal/registry.h index a169308c..e9b9fcdc 100644 --- a/fuzztest/internal/registry.h +++ b/fuzztest/internal/registry.h @@ -16,12 +16,11 @@ #define FUZZTEST_FUZZTEST_INTERNAL_REGISTRY_H_ #include -#include #include #include #include "absl/functional/function_ref.h" - +#include "absl/strings/string_view.h" #ifdef FUZZTEST_USE_CENTIPEDE #include "./fuzztest/internal/centipede_adaptor.h" #endif @@ -41,14 +40,14 @@ void ForEachTest(absl::FunctionRef func); using SetUpTearDownTestSuiteFunction = void (*)(); void RegisterSetUpTearDownTestSuiteFunctions( - std::string_view suite_name, + absl::string_view suite_name, SetUpTearDownTestSuiteFunction set_up_test_suite, SetUpTearDownTestSuiteFunction tear_down_test_suite); -SetUpTearDownTestSuiteFunction GetSetUpTestSuite(std::string_view suite_name); +SetUpTearDownTestSuiteFunction GetSetUpTestSuite(absl::string_view suite_name); SetUpTearDownTestSuiteFunction GetTearDownTestSuite( - std::string_view suite_name); + absl::string_view suite_name); struct RegistrationToken { template FuzzTestFuzzerImpl::TryParse(std::string_view data) { +std::optional FuzzTestFuzzerImpl::TryParse( + absl::string_view data) { auto ir_value = IRObject::FromString(data); if (!ir_value) { absl::FPrintF(GetStderr(), "[!] Unexpected file format.\n"); diff --git a/fuzztest/internal/runtime.h b/fuzztest/internal/runtime.h index 085963f9..33bcbce0 100644 --- a/fuzztest/internal/runtime.h +++ b/fuzztest/internal/runtime.h @@ -84,9 +84,6 @@ class FuzzTest { std::string full_name() const { return suite_name() + std::string(".") + test_name(); } - const std::vector& param_names() const { - return param_names_; - } const char* file() const { return test_info_.file; } int line() const { return test_info_.line; } bool uses_fixture() const { return test_info_.uses_fixture; } @@ -94,7 +91,6 @@ class FuzzTest { private: BasicTestInfo test_info_; - std::vector param_names_; FuzzTestFuzzerFactory make_; }; @@ -259,7 +255,7 @@ class FuzzTestFuzzerImpl : public FuzzTestFuzzer { std::optional ReadReproducerToMinimize(); - std::optional TryParse(std::string_view data); + std::optional TryParse(absl::string_view data); void MutateValue(Input& input, absl::BitGenRef prng);