From 5db7d38c13419ecda9e3957ca023d7eca154dd00 Mon Sep 17 00:00:00 2001 From: James Price Date: Wed, 14 Jul 2021 12:49:32 +0000 Subject: [PATCH] fuzzers: Switch AST fuzzers to new generator API Change-Id: If9f843a318be6e9bbb44bc852814811a5e42baf0 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/57980 Commit-Queue: Ben Clayton Kokoro: Kokoro Reviewed-by: Ben Clayton --- fuzzers/tint_ast_fuzzer/fuzzer.cc | 18 ++++++++++-------- .../mutations/replace_identifier_test.cc | 14 ++++++++------ 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/fuzzers/tint_ast_fuzzer/fuzzer.cc b/fuzzers/tint_ast_fuzzer/fuzzer.cc index 59dc075864..ae39e6cd4b 100644 --- a/fuzzers/tint_ast_fuzzer/fuzzer.cc +++ b/fuzzers/tint_ast_fuzzer/fuzzer.cc @@ -82,14 +82,15 @@ extern "C" size_t LLVMFuzzerCustomMutator(uint8_t* data, if (!cli_params.record_mutations) { // If mutations are not being recorded, then the mutated `program` must be // stored into the `mutator_state`. - writer::wgsl::Generator generator(&program); - if (!generator.Generate()) { + writer::wgsl::Options options; + auto result = writer::wgsl::Generate(&program, options); + if (!result.success) { std::cout << "Can't generate WGSL for valid tint::Program:" << std::endl << " seed: " << seed << std::endl - << generator.error() << std::endl; + << result.error << std::endl; return 0; } - *mutator_state.mutable_program() = generator.result(); + *mutator_state.mutable_program() = result.wgsl; } if (mutator_state.ByteSizeLong() > max_size) { @@ -120,10 +121,11 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { Replay(reader::wgsl::Parse(&file), mutator_state.mutation_sequence()); assert(program.IsValid() && "Replayed program is invalid"); - writer::wgsl::Generator generator(&program); - success = generator.Generate(); - assert(success && "Can't generate a shader for the valid tint::Program"); - program_text = generator.result(); + writer::wgsl::Options options; + auto result = writer::wgsl::Generate(&program, options); + assert(result.success && + "Can't generate a shader for the valid tint::Program"); + program_text = result.wgsl; } else { program_text.assign(data, data + size); } diff --git a/fuzzers/tint_ast_fuzzer/mutations/replace_identifier_test.cc b/fuzzers/tint_ast_fuzzer/mutations/replace_identifier_test.cc index 84e47b55f9..3af0059d2a 100644 --- a/fuzzers/tint_ast_fuzzer/mutations/replace_identifier_test.cc +++ b/fuzzers/tint_ast_fuzzer/mutations/replace_identifier_test.cc @@ -540,8 +540,9 @@ fn f() { &program, &node_id_map, nullptr)); ASSERT_TRUE(program.IsValid()) << program.Diagnostics().str(); - writer::wgsl::Generator generator(&program); - ASSERT_TRUE(generator.Generate()) << generator.error(); + writer::wgsl::Options options; + auto result = writer::wgsl::Generate(&program, options); + ASSERT_TRUE(result.success) << result.error; std::string expected_shader = R"(fn f() { var b : vec2; @@ -549,7 +550,7 @@ fn f() { (*(&(b)))[1] = 3u; } )"; - ASSERT_EQ(expected_shader, generator.result()); + ASSERT_EQ(expected_shader, result.wgsl); } TEST(ReplaceIdentifierTest, Applicable2) { @@ -588,8 +589,9 @@ fn f(b: ptr>) { &program, &node_id_map, nullptr)); ASSERT_TRUE(program.IsValid()) << program.Diagnostics().str(); - writer::wgsl::Generator generator(&program); - ASSERT_TRUE(generator.Generate()) << generator.error(); + writer::wgsl::Options options; + auto result = writer::wgsl::Generate(&program, options); + ASSERT_TRUE(result.success) << result.error; std::string expected_shader = R"(fn f(b : ptr>) { var a = vec2(34u, 45u); @@ -597,7 +599,7 @@ fn f(b: ptr>) { (*(b))[1] = 3u; } )"; - ASSERT_EQ(expected_shader, generator.result()); + ASSERT_EQ(expected_shader, result.wgsl); } TEST(ReplaceIdentifierTest, NotApplicable12) {