Fix ast_clone_fuzzer tests

Demangle the printed AST before comparing.

Many to_str() methods on AST nodes will print the symbol numerical identifiers, which is not guaranteed to be stable between clones.
By comparing the demangled AST, these should be stable.

Fixed: chromium:1160099
Change-Id: I4e62adbccc690a1531f78dc70cef8480ed6f3f2c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/36621
Commit-Queue: Ben Clayton <bclayton@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton 2021-01-06 14:30:11 +00:00 committed by Commit Bot service account
parent e9d7f7e640
commit 6653c13a75
1 changed files with 4 additions and 2 deletions

View File

@ -16,6 +16,7 @@
#include <string>
#include <unordered_set>
#include "src/demangler.h"
#include "src/reader/wgsl/parser_impl.h"
#include "src/writer/wgsl/generator.h"
@ -57,8 +58,9 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
// Clone the src module to dst
auto dst = src.Clone();
// Expect the AST printed with to_str() to match
ASSERT_EQ(src.to_str(), dst.to_str());
// Expect the demangled AST printed with to_str() to match
tint::Demangler d;
ASSERT_EQ(d.Demangle(src, src.to_str()), d.Demangle(dst, dst.to_str()));
// Check that none of the AST nodes or type pointers in dst are found in src
std::unordered_set<tint::ast::Node*> src_nodes;