Skip to content

Commit

Permalink
Switch from std::string_view to absl::string_view at a few places.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
fniksic authored and copybara-github committed Oct 23, 2023
1 parent 27393e3 commit 89d502c
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 16 deletions.
1 change: 1 addition & 0 deletions fuzztest/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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": [],
Expand Down
1 change: 1 addition & 0 deletions fuzztest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,7 @@ target_link_libraries(
fuzztest_runtime
absl::flat_hash_map
absl::function_ref
absl::string_view
)

add_library(
Expand Down
10 changes: 5 additions & 5 deletions fuzztest/internal/registry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

#include <deque>
#include <string>
#include <string_view>
#include <utility>

#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"

Expand All @@ -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;
Expand All @@ -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;
}

Expand Down
9 changes: 4 additions & 5 deletions fuzztest/internal/registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@
#define FUZZTEST_FUZZTEST_INTERNAL_REGISTRY_H_

#include <memory>
#include <string_view>
#include <type_traits>
#include <utility>

#include "absl/functional/function_ref.h"

#include "absl/strings/string_view.h"
#ifdef FUZZTEST_USE_CENTIPEDE
#include "./fuzztest/internal/centipede_adaptor.h"
#endif
Expand All @@ -41,14 +40,14 @@ void ForEachTest(absl::FunctionRef<void(FuzzTest&)> 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 <typename RegBase, typename Fixture, typename TargetFunction,
Expand Down
3 changes: 2 additions & 1 deletion fuzztest/internal/runtime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ FuzzTestFuzzerImpl::~FuzzTestFuzzerImpl() {
Runtime::instance().DisableReporter();
}

std::optional<corpus_type> FuzzTestFuzzerImpl::TryParse(std::string_view data) {
std::optional<corpus_type> FuzzTestFuzzerImpl::TryParse(
absl::string_view data) {
auto ir_value = IRObject::FromString(data);
if (!ir_value) {
absl::FPrintF(GetStderr(), "[!] Unexpected file format.\n");
Expand Down
6 changes: 1 addition & 5 deletions fuzztest/internal/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,13 @@ class FuzzTest {
std::string full_name() const {
return suite_name() + std::string(".") + test_name();
}
const std::vector<std::string_view>& 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; }
auto make() const { return make_(*this); }

private:
BasicTestInfo test_info_;
std::vector<std::string_view> param_names_;
FuzzTestFuzzerFactory make_;
};

Expand Down Expand Up @@ -259,7 +255,7 @@ class FuzzTestFuzzerImpl : public FuzzTestFuzzer {

std::optional<corpus_type> ReadReproducerToMinimize();

std::optional<corpus_type> TryParse(std::string_view data);
std::optional<corpus_type> TryParse(absl::string_view data);

void MutateValue(Input& input, absl::BitGenRef prng);

Expand Down

0 comments on commit 89d502c

Please sign in to comment.