Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a few incompatibilities with C++17 and clean up included headers. #1546

Merged
merged 1 commit into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion domain_tests/string_domains_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class HandleTypeTest : public testing::Test {};
using HandleTypeTypes =
testing::Types<std::string_view, std::vector<std::string_view>>;

TYPED_TEST_SUITE(HandleTypeTest, HandleTypeTypes);
TYPED_TEST_SUITE(HandleTypeTest, HandleTypeTypes, );

TYPED_TEST(HandleTypeTest, Arbitrary) {
absl::BitGen bitgen;
Expand Down
18 changes: 12 additions & 6 deletions e2e_tests/benchmark_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@
// It runs each micro-benchmark fuzz test in a child process and measures the
// time and number of iterations it takes to find the exit condition.

#include <filesystem>
#include <sys/types.h>
#include <unistd.h>

#include <cstddef>
#include <cstdint>
#include <filesystem> // NOLINT
#include <iostream>
#include <string>
#include <vector>

Expand Down Expand Up @@ -105,11 +111,11 @@ uint64_t ExtractNumber(absl::string_view output, absl::string_view name) {
// We might want to pass a richer format later.
Stats ParseStats(absl::string_view output) {
return {
.nanos = ExtractTime(output),
.runs = ExtractNumber(output, "Total runs"),
.edges_covered = ExtractNumber(output, "Edges covered"),
.total_edges = ExtractNumber(output, "Total edges"),
.corpus_size = ExtractNumber(output, "Corpus size"),
/*nanos=*/ExtractTime(output),
/*runs=*/ExtractNumber(output, "Total runs"),
/*edges_covered=*/ExtractNumber(output, "Edges covered"),
/*total_edges=*/ExtractNumber(output, "Total edges"),
/*corpus_size=*/ExtractNumber(output, "Corpus size"),
};
}

Expand Down
8 changes: 4 additions & 4 deletions e2e_tests/functional_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -676,10 +676,10 @@ class GenericCommandLineInterfaceTest : public ::testing::Test {
{}) {
flags["print_subprocess_log"] = "true";
return RunBinary(BinaryPath(binary),
RunOptions{.flags = non_fuzztest_flags,
.fuzztest_flags = flags,
.env = WithTestSanitizerOptions(env),
.timeout = timeout});
RunOptions{/*flags=*/non_fuzztest_flags,
/*fuzztest_flags=*/flags,
/*env=*/WithTestSanitizerOptions(env),
/*timeout=*/timeout});
}
};

Expand Down
16 changes: 8 additions & 8 deletions e2e_tests/testdata/fuzz_tests_with_proto_inputs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -312,18 +312,18 @@ std::vector<DeliveryResult> RoboCourierRun(const RoboCourier560Plan& plan) {
}
case RoboCourier560Plan::ExtraAction::POST_NOTICE: {
results.push_back(
DeliveryResult{.location_name = name,
.location_address = mail.address(),
.mail_name = mail.name(),
.mail_content = extra_action.content()});
DeliveryResult{/*location_name=*/name,
/*location_address=*/mail.address(),
/*mail_name=*/mail.name(),
/*mail_content=*/extra_action.content()});
break;
}
}
}
results.push_back(DeliveryResult{.location_name = name,
.location_address = mail.address(),
.mail_name = mail.name(),
.mail_content = mail.content()});
results.push_back(DeliveryResult{/*location_name=*/name,
/*location_address=*/mail.address(),
/*mail_name=*/mail.name(),
/*mail_content=*/mail.content()});
}
return results;
}
Expand Down
3 changes: 1 addition & 2 deletions fuzztest/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,9 @@ cc_library(
"@com_google_fuzztest//centipede:centipede_interface",
"@com_google_fuzztest//centipede:centipede_runner_no_main",
"@com_google_fuzztest//centipede:environment",
"@com_google_fuzztest//centipede:execution_metadata",
"@com_google_fuzztest//centipede:mutation_input",
"@com_google_fuzztest//centipede:runner_result",
"@com_google_fuzztest//centipede:shared_memory_blob_sequence",
"@com_google_fuzztest//centipede:stop",
"@com_google_fuzztest//centipede:workdir",
"@com_google_fuzztest//common:defs",
"@com_google_fuzztest//common:temp_dir",
Expand Down
9 changes: 5 additions & 4 deletions fuzztest/internal/centipede_adaptor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@

#include "./fuzztest/internal/centipede_adaptor.h"

#include <sys/mman.h>
#ifdef __APPLE__
#include <sys/sysctl.h>
#else // __APPLE__
#include <linux/limits.h> // ARG_MAX
#endif // __APPLE__
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include <cerrno>
#include <cinttypes>
#include <cstddef>
#include <cstdint>
Expand Down Expand Up @@ -60,11 +62,10 @@
#include "./centipede/centipede_default_callbacks.h"
#include "./centipede/centipede_interface.h"
#include "./centipede/environment.h"
#include "./centipede/execution_metadata.h"
#include "./centipede/mutation_input.h"
#include "./centipede/runner_interface.h"
#include "./centipede/runner_result.h"
#include "./centipede/shared_memory_blob_sequence.h"
#include "./centipede/stop.h"
#include "./centipede/workdir.h"
#include "./common/defs.h"
#include "./common/temp_dir.h"
Expand Down Expand Up @@ -389,7 +390,7 @@ class CentipedeAdaptorRunnerCallbacks : public centipede::RunnerCallbacks {
}
auto mutant = FuzzTestFuzzerImpl::Input{*std::move(parsed_origin)};
fuzzer_impl_.MutateValue(mutant, prng_,
{.cmp_tables = cmp_tables_.get()});
{/*cmp_tables=*/cmp_tables_.get()});
mutant_data =
fuzzer_impl_.params_domain_.SerializeCorpus(mutant.args).ToString();
}
Expand Down
85 changes: 43 additions & 42 deletions fuzztest/internal/domains/protobuf_domain_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ class ProtoPolicy {

public:
ProtoPolicy()
: optional_policies_({{.filter = IncludeAll<FieldDescriptor>(),
.value = OptionalPolicy::kWithNull}}) {}
: optional_policies_({{/*filter=*/IncludeAll<FieldDescriptor>(),
/*value=*/OptionalPolicy::kWithNull}}) {}

void SetOptionalPolicy(OptionalPolicy optional_policy) {
SetOptionalPolicy(IncludeAll<FieldDescriptor>(), optional_policy);
Expand All @@ -242,20 +242,20 @@ class ProtoPolicy {
void SetOptionalPolicy(Filter filter, OptionalPolicy optional_policy) {
if (optional_policy == OptionalPolicy::kAlwaysNull) {
max_repeated_fields_sizes_.push_back(
{.filter = And(IsRepeated<FieldDescriptor>(), filter), .value = 0});
{/*filter=*/And(IsRepeated<FieldDescriptor>(), filter), /*value=*/0});
min_repeated_fields_sizes_.push_back(
{.filter = And(IsRepeated<FieldDescriptor>(), filter), .value = 0});
{/*filter=*/And(IsRepeated<FieldDescriptor>(), filter), /*value=*/0});
} else if (optional_policy == OptionalPolicy::kWithoutNull) {
// TODO(b/298168054): Ideally, min/max should get updated only if the
// fields are not already always set.
min_repeated_fields_sizes_.push_back(
{.filter = And(IsRepeated<FieldDescriptor>(), filter), .value = 1});
{/*filter=*/And(IsRepeated<FieldDescriptor>(), filter), /*value=*/1});
max_repeated_fields_sizes_.push_back(
{.filter = And(IsRepeated<FieldDescriptor>(), filter),
.value = fuzztest::internal::kDefaultContainerMaxSize});
{/*filter=*/And(IsRepeated<FieldDescriptor>(), filter),
/*value=*/fuzztest::internal::kDefaultContainerMaxSize});
}
optional_policies_.push_back(
{.filter = std::move(filter), .value = optional_policy});
{/*filter=*/std::move(filter), /*value=*/optional_policy});
}

void SetMinRepeatedFieldsSize(int64_t min_size) {
Expand All @@ -264,7 +264,7 @@ class ProtoPolicy {

void SetMinRepeatedFieldsSize(Filter filter, int64_t min_size) {
min_repeated_fields_sizes_.push_back(
{.filter = std::move(filter), .value = min_size});
{/*filter=*/std::move(filter), /*value=*/min_size});
}

void SetMaxRepeatedFieldsSize(int64_t max_size) {
Expand All @@ -273,7 +273,7 @@ class ProtoPolicy {

void SetMaxRepeatedFieldsSize(Filter filter, int64_t max_size) {
max_repeated_fields_sizes_.push_back(
{.filter = std::move(filter), .value = max_size});
{/*filter=*/std::move(filter), /*value=*/max_size});
}

OptionalPolicy GetOptionalPolicy(const FieldDescriptor* field) const {
Expand Down Expand Up @@ -349,38 +349,39 @@ class ProtoPolicy {
std::vector<FilterToValue<int64_t>> min_repeated_fields_sizes_;
std::vector<FilterToValue<int64_t>> max_repeated_fields_sizes_;

#define FUZZTEST_INTERNAL_POLICY_MEMBERS(Camel, cpp) \
private: \
std::vector<FilterToValue<Domain<cpp>>> domains_for_##Camel##_; \
std::vector<FilterToValue<std::function<Domain<cpp>(Domain<cpp>)>>> \
transformers_for_##Camel##_; \
\
public: \
void SetDefaultDomainFor##Camel##s( \
Domain<MakeDependentType<cpp, Message>> domain) { \
domains_for_##Camel##_.push_back({.filter = IncludeAll<FieldDescriptor>(), \
.value = std::move(domain)}); \
} \
void SetDefaultDomainFor##Camel##s( \
Filter filter, Domain<MakeDependentType<cpp, Message>> domain) { \
domains_for_##Camel##_.push_back( \
{.filter = std::move(filter), .value = std::move(domain)}); \
} \
void SetDomainTransformerFor##Camel##s( \
Filter filter, std::function<Domain<MakeDependentType<cpp, Message>>( \
Domain<MakeDependentType<cpp, Message>>)> \
transformer) { \
transformers_for_##Camel##_.push_back( \
{.filter = std::move(filter), .value = std::move(transformer)}); \
} \
std::optional<Domain<MakeDependentType<cpp, Message>>> \
GetDefaultDomainFor##Camel##s(const FieldDescriptor* field) const { \
return GetPolicyValue(domains_for_##Camel##_, field); \
} \
std::optional<std::function<Domain<MakeDependentType<cpp, Message>>( \
Domain<MakeDependentType<cpp, Message>>)>> \
GetDomainTransformerFor##Camel##s(const FieldDescriptor* field) const { \
return GetPolicyValue(transformers_for_##Camel##_, field); \
#define FUZZTEST_INTERNAL_POLICY_MEMBERS(Camel, cpp) \
private: \
std::vector<FilterToValue<Domain<cpp>>> domains_for_##Camel##_; \
std::vector<FilterToValue<std::function<Domain<cpp>(Domain<cpp>)>>> \
transformers_for_##Camel##_; \
\
public: \
void SetDefaultDomainFor##Camel##s( \
Domain<MakeDependentType<cpp, Message>> domain) { \
domains_for_##Camel##_.push_back( \
{/*filter=*/IncludeAll<FieldDescriptor>(), \
/*value=*/std::move(domain)}); \
} \
void SetDefaultDomainFor##Camel##s( \
Filter filter, Domain<MakeDependentType<cpp, Message>> domain) { \
domains_for_##Camel##_.push_back( \
{/*filter=*/std::move(filter), /*value=*/std::move(domain)}); \
} \
void SetDomainTransformerFor##Camel##s( \
Filter filter, std::function<Domain<MakeDependentType<cpp, Message>>( \
Domain<MakeDependentType<cpp, Message>>)> \
transformer) { \
transformers_for_##Camel##_.push_back( \
{/*filter=*/std::move(filter), /*value=*/std::move(transformer)}); \
} \
std::optional<Domain<MakeDependentType<cpp, Message>>> \
GetDefaultDomainFor##Camel##s(const FieldDescriptor* field) const { \
return GetPolicyValue(domains_for_##Camel##_, field); \
} \
std::optional<std::function<Domain<MakeDependentType<cpp, Message>>( \
Domain<MakeDependentType<cpp, Message>>)>> \
GetDomainTransformerFor##Camel##s(const FieldDescriptor* field) const { \
return GetPolicyValue(transformers_for_##Camel##_, field); \
}

FUZZTEST_INTERNAL_POLICY_MEMBERS(Bool, bool)
Expand Down
Loading