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 <bclayton@google.com> Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
6e459fecb7
commit
5db7d38c13
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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<u32>;
|
||||
|
@ -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<function, vec2<u32>>) {
|
|||
&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<function, vec2<u32>>) {
|
||||
var a = vec2<u32>(34u, 45u);
|
||||
|
@ -597,7 +599,7 @@ fn f(b: ptr<function, vec2<u32>>) {
|
|||
(*(b))[1] = 3u;
|
||||
}
|
||||
)";
|
||||
ASSERT_EQ(expected_shader, generator.result());
|
||||
ASSERT_EQ(expected_shader, result.wgsl);
|
||||
}
|
||||
|
||||
TEST(ReplaceIdentifierTest, NotApplicable12) {
|
||||
|
|
Loading…
Reference in New Issue