Revert designated initializer list usages so we are C++17 compliant. PiperOrigin-RevId: 723175869
diff --git a/centipede/execution_metadata_test.cc b/centipede/execution_metadata_test.cc index c7d7edd..d1ec7fa 100644 --- a/centipede/execution_metadata_test.cc +++ b/centipede/execution_metadata_test.cc
@@ -30,15 +30,16 @@ using ::testing::UnorderedElementsAreArray; TEST(ExecutionMetadata, ForEachCmpEntryEnumeratesEntriesInRawBytes) { - ExecutionMetadata metadata{.cmp_data = { - 2, // size - 1, 2, // a - 3, 4, // b - 0, // zero-sized entry - 3, // size - 5, 6, 7, // a - 8, 9, 10, // b - }}; + ExecutionMetadata metadata; + metadata.cmp_data = { + 2, // size + 1, 2, // a + 3, 4, // b + 0, // zero-sized entry + 3, // size + 5, 6, 7, // a + 8, 9, 10, // b + }; std::vector<std::pair<ByteSpan, ByteSpan>> enumeration_result; EXPECT_TRUE(metadata.ForEachCmpEntry( [&](ByteSpan a, ByteSpan b) { enumeration_result.emplace_back(a, b); })); @@ -54,15 +55,17 @@ TEST(ExecutionMetadata, ForEachCmpEntryHandlesEmptyCmpData) { auto noop_callback = [](ByteSpan, ByteSpan) {}; - EXPECT_TRUE(ExecutionMetadata{.cmp_data = {}}.ForEachCmpEntry(noop_callback)); + EXPECT_TRUE(ExecutionMetadata{}.ForEachCmpEntry(noop_callback)); } TEST(ExecutionMetadata, ForEachCmpEntryReturnsFalseOnCmpDataWithNotEnoughBytes) { auto noop_callback = [](ByteSpan, ByteSpan) {}; - const auto bad_metadata_1 = ExecutionMetadata{.cmp_data = {3, 1, 2, 3}}; + auto bad_metadata_1 = ExecutionMetadata{}; + bad_metadata_1.cmp_data = {3, 1, 2, 3}; EXPECT_FALSE(bad_metadata_1.ForEachCmpEntry(noop_callback)); - const auto bad_metadata_2 = ExecutionMetadata{.cmp_data = {3, 1, 2, 3, 4, 5}}; + auto bad_metadata_2 = ExecutionMetadata{}; + bad_metadata_2.cmp_data = {3, 1, 2, 3, 4, 5}; EXPECT_FALSE(bad_metadata_2.ForEachCmpEntry(noop_callback)); }
diff --git a/centipede/fuzztest_mutator.cc b/centipede/fuzztest_mutator.cc index 3ea290d..388fa56 100644 --- a/centipede/fuzztest_mutator.cc +++ b/centipede/fuzztest_mutator.cc
@@ -17,6 +17,7 @@ #include <algorithm> #include <cstddef> #include <cstdint> +#include <cstdlib> #include <memory> #include <utility> #include <vector> @@ -47,11 +48,9 @@ class FuzzTestMutator::MutatorDomain : public MutatorDomainBase { public: MutatorDomain() - : MutatorDomainBase(fuzztest::VectorOf(fuzztest::Arbitrary<uint8_t>())) { - } + : MutatorDomainBase(fuzztest::VectorOf(fuzztest::Arbitrary<uint8_t>())) {} - ~MutatorDomain() { - } + ~MutatorDomain() {} }; FuzzTestMutator::FuzzTestMutator(const Knobs &knobs, uint64_t seed) @@ -99,9 +98,9 @@ } } -void FuzzTestMutator::MutateMany(const std::vector<MutationInputRef>& inputs, +void FuzzTestMutator::MutateMany(const std::vector<MutationInputRef> &inputs, size_t num_mutants, - std::vector<ByteArray>& mutants) { + std::vector<ByteArray> &mutants) { if (inputs.empty()) abort(); // TODO(xinhaoyuan): Consider metadata in other inputs instead of always the // first one. @@ -119,14 +118,14 @@ CrossOver(mutant, other_input); } else { domain_->Mutate(mutant, prng_, - {.cmp_tables = &mutation_metadata_->cmp_tables}, + {/*cmp_tables=*/&mutation_metadata_->cmp_tables}, /*only_shrink=*/false); } mutants.push_back(std::move(mutant)); } } -void FuzzTestMutator::SetMetadata(const ExecutionMetadata& metadata) { +void FuzzTestMutator::SetMetadata(const ExecutionMetadata &metadata) { metadata.ForEachCmpEntry([this](ByteSpan a, ByteSpan b) { size_t size = a.size(); if (size < kMinCmpEntrySize) return; @@ -145,7 +144,7 @@ } void FuzzTestMutator::AddToDictionary( - const std::vector<ByteArray>& dict_entries) { + const std::vector<ByteArray> &dict_entries) { domain_->WithDictionary(dict_entries); }
diff --git a/centipede/fuzztest_mutator_test.cc b/centipede/fuzztest_mutator_test.cc index 79862c3..9964c72 100644 --- a/centipede/fuzztest_mutator_test.cc +++ b/centipede/fuzztest_mutator_test.cc
@@ -46,7 +46,7 @@ std::vector<ByteArray> res[2]; for (size_t i = 0; i < 2; i++) { ByteArray data = {0}; - std::vector<MutationInputRef> mutation_inputs = {{.data = data}}; + std::vector<MutationInputRef> mutation_inputs = {{data}}; std::vector<ByteArray> mutants; constexpr size_t kMutantSequenceLength = 100; for (size_t iter = 0; iter < kMutantSequenceLength; iter++) { @@ -68,11 +68,11 @@ mutator.MutateMany( { - {.data = {0, 1, 2, 3, 4, 5, 6, 7}}, - {.data = {0}}, - {.data = {0, 1}}, - {.data = {0, 1, 2}}, - {.data = {0, 1, 2, 3}}, + {/*data=*/{0, 1, 2, 3, 4, 5, 6, 7}}, + {/*data=*/{0}}, + {/*data=*/{0, 1}}, + {/*data=*/{0, 1, 2}}, + {/*data=*/{0, 1, 2, 3}}, }, kNumMutantsToGenerate, mutants); @@ -88,8 +88,8 @@ mutator.MutateMany( { - {.data = {0, 1, 2, 3}}, - {.data = {4, 5, 6, 7}}, + {/*data=*/{0, 1, 2, 3}}, + {/*data=*/{4, 5, 6, 7}}, }, kNumMutantsToGenerate, mutants); @@ -121,8 +121,8 @@ mutator.MutateMany( { - {.data = {0, 1, 2, 3, 4, 5, 6, 7}}, - {.data = {100, 101, 102, 103}}, + {/*data=*/{0, 1, 2, 3, 4, 5, 6, 7}}, + {/*data=*/{100, 101, 102, 103}}, }, kNumMutantsToGenerate, mutants); @@ -182,9 +182,10 @@ absl::flat_hash_set<ByteArray> unmatched_expected_mutants = GetParam().expected_mutants; const auto& unexpected_mutants = GetParam().unexpected_mutants; - ExecutionMetadata metadata = {.cmp_data = GetParam().cmp_data}; + ExecutionMetadata metadata; + metadata.cmp_data = GetParam().cmp_data; const std::vector<MutationInputRef> inputs = { - {.data = GetParam().seed_input, .metadata = &metadata}}; + {/*data=*/GetParam().seed_input, /*metadata=*/&metadata}}; std::vector<ByteArray> mutants; for (size_t i = 0; i < GetParam().max_num_iterations; i++) { mutator.MutateMany(inputs, 1, mutants); @@ -200,124 +201,114 @@ EXPECT_TRUE(unmatched_expected_mutants.empty()); } -INSTANTIATE_TEST_SUITE_P(InsertByteUpToMaxLen, MutationStepTest, - Values(MutationStepTestParameter{ - .seed_input = {0, 1, 2}, - .expected_mutants = - { - {0, 1, 2, 3}, - {0, 3, 1, 2}, - {3, 0, 1, 2}, - }, - .unexpected_mutants = - { - {0, 1, 2, 3, 4}, - {0, 3, 4, 1, 2}, - {3, 4, 0, 1, 2}, - }, - .max_len = 4, - })); +INSTANTIATE_TEST_SUITE_P(InsertByteUpToMaxLen, MutationStepTest, Values([] { + MutationStepTestParameter params; + params.seed_input = {0, 1, 2}; + params.expected_mutants = { + {0, 1, 2, 3}, + {0, 3, 1, 2}, + {3, 0, 1, 2}, + }; + params.unexpected_mutants = { + {0, 1, 2, 3, 4}, + {0, 3, 4, 1, 2}, + {3, 4, 0, 1, 2}, + }; + params.max_len = 4; + return params; + }())); -INSTANTIATE_TEST_SUITE_P(OverwriteFromDictionary, MutationStepTest, - Values(MutationStepTestParameter{ - .seed_input = {1, 2, 3, 4, 5}, - .expected_mutants = - { - {1, 2, 7, 8, 9}, - {1, 7, 8, 9, 5}, - {7, 8, 9, 4, 5}, - {1, 2, 3, 0, 6}, - {1, 2, 0, 6, 5}, - {1, 0, 6, 4, 5}, - {0, 6, 3, 4, 5}, - {42, 2, 3, 4, 5}, - {1, 42, 3, 4, 5}, - {1, 2, 42, 4, 5}, - {1, 2, 3, 42, 5}, - {1, 2, 3, 4, 42}, - }, - .dictionary = - { - {7, 8, 9}, - {0, 6}, - {42}, - }, - })); +INSTANTIATE_TEST_SUITE_P(OverwriteFromDictionary, MutationStepTest, Values([] { + MutationStepTestParameter params; + params.seed_input = {1, 2, 3, 4, 5}; + params.expected_mutants = { + {1, 2, 7, 8, 9}, {1, 7, 8, 9, 5}, + {7, 8, 9, 4, 5}, {1, 2, 3, 0, 6}, + {1, 2, 0, 6, 5}, {1, 0, 6, 4, 5}, + {0, 6, 3, 4, 5}, {42, 2, 3, 4, 5}, + {1, 42, 3, 4, 5}, {1, 2, 42, 4, 5}, + {1, 2, 3, 42, 5}, {1, 2, 3, 4, 42}, + }; + params.dictionary = { + {7, 8, 9}, + {0, 6}, + {42}, + }; + return params; + }())); -INSTANTIATE_TEST_SUITE_P( - OverwriteFromCmpDictionary, MutationStepTest, - Values(MutationStepTestParameter{ - .seed_input = {1, 2, 40, 50, 60}, - .expected_mutants = - { - {3, 4, 40, 50, 60}, - {1, 2, 10, 20, 30}, - }, - .cmp_data = {/*size*/ 2, /*lhs*/ 1, 2, /*rhs*/ 3, 4, /*size*/ 3, - /*lhs*/ 10, 20, 30, /*rhs*/ 40, 50, 60}, - })); +INSTANTIATE_TEST_SUITE_P(OverwriteFromCmpDictionary, MutationStepTest, + Values([] { + MutationStepTestParameter params; + params.seed_input = {1, 2, 40, 50, 60}; + params.expected_mutants = { + {3, 4, 40, 50, 60}, + {1, 2, 10, 20, 30}, + }; + params.cmp_data = {2, // size + 1, 2, // lhs + 3, 4, // rhs + 3, // size + 10, 20, 30, // lhs + 40, 50, 60}; // rhs + return params; + }())); -INSTANTIATE_TEST_SUITE_P(InsertFromDictionary, MutationStepTest, - Values(MutationStepTestParameter{ - .seed_input = {1, 2, 3}, - .expected_mutants = - { - {1, 2, 3, 4, 5}, - {1, 2, 4, 5, 3}, - {1, 4, 5, 2, 3}, - {4, 5, 1, 2, 3}, - {1, 2, 3, 6, 7, 8}, - {1, 2, 6, 7, 8, 3}, - {1, 6, 7, 8, 2, 3}, - {6, 7, 8, 1, 2, 3}, - }, - .dictionary = - { - {4, 5}, - {6, 7, 8}, - }, - })); +INSTANTIATE_TEST_SUITE_P(InsertFromDictionary, MutationStepTest, Values([] { + MutationStepTestParameter params; + params.seed_input = {1, 2, 3}; + params.expected_mutants = { + {1, 2, 3, 4, 5}, {1, 2, 4, 5, 3}, + {1, 4, 5, 2, 3}, {4, 5, 1, 2, 3}, + {1, 2, 3, 6, 7, 8}, {1, 2, 6, 7, 8, 3}, + {1, 6, 7, 8, 2, 3}, {6, 7, 8, 1, 2, 3}, + }; + params.dictionary = { + {4, 5}, + {6, 7, 8}, + }; + return params; + }())); -INSTANTIATE_TEST_SUITE_P(InsertFromCmpDictionary, MutationStepTest, - Values(MutationStepTestParameter{ - .seed_input = {1, 2, 3}, - .expected_mutants = - { - {1, 2, 3, 4, 5}, - {1, 2, 4, 5, 3}, - {1, 4, 5, 2, 3}, - {4, 5, 1, 2, 3}, - {1, 2, 3, 6, 7, 8}, - {1, 2, 6, 7, 8, 3}, - {1, 6, 7, 8, 2, 3}, - {6, 7, 8, 1, 2, 3}, - }, - .cmp_data = {/*size*/ 2, /*lhs*/ 4, 5, /*rhs*/ 4, - 5, /*size*/ 3, - /*lhs*/ 6, 7, 8, /*rhs*/ 6, 7, 8}, - })); +INSTANTIATE_TEST_SUITE_P(InsertFromCmpDictionary, MutationStepTest, Values([] { + MutationStepTestParameter params; + params.seed_input = {1, 2, 3}; + params.expected_mutants = { + {1, 2, 3, 4, 5}, {1, 2, 4, 5, 3}, + {1, 4, 5, 2, 3}, {4, 5, 1, 2, 3}, + {1, 2, 3, 6, 7, 8}, {1, 2, 6, 7, 8, 3}, + {1, 6, 7, 8, 2, 3}, {6, 7, 8, 1, 2, 3}, + }; + params.cmp_data = {2, // size + 4, 5, // lhs + 4, 5, // rhs + 3, // size + 6, 7, 8, // lhs + 6, 7, 8}; // rhs + return params; + }())); -INSTANTIATE_TEST_SUITE_P( - SkipsLongCmpEntry, MutationStepTest, - Values(MutationStepTestParameter{ - .seed_input = {0}, - .expected_mutants = - { - {0, 1, 2, 3, 4}, - }, - .unexpected_mutants = - { - {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, - 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}, - }, - .cmp_data = {/*size*/ 20, /*lhs*/ 1, 2, 3, 4, 5, 6, - 7, 8, 9, 10, 11, 12, 13, - 14, 15, 16, 17, 18, 19, 20, - /*rhs*/ 1, 2, 3, 4, 5, 6, 7, - 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, - /*size*/ 4, /*lhs*/ 1, 2, 3, 4, /*rhs*/ 1, 2, - 3, 4}})); +INSTANTIATE_TEST_SUITE_P(SkipsLongCmpEntry, MutationStepTest, Values([] { + MutationStepTestParameter params; + params.seed_input = {0}; + params.expected_mutants = { + {0, 1, 2, 3, 4}, + }; + params.unexpected_mutants = { + {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, + 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}, + }; + params.cmp_data = { + 20, // size + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, + 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, // lhs + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, + 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, // rhs + 4, // size + 1, 2, 3, 4, // lhs + 1, 2, 3, 4}; // rhs + return params; + }())); } // namespace