chromium/third_party/dawn/src/tint/lang/wgsl/resolver/resolver_test.cc

// Copyright 2020 The Dawn & Tint Authors
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this
//    list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
//    this list of conditions and the following disclaimer in the documentation
//    and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its
//    contributors may be used to endorse or promote products derived from
//    this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "src/tint/lang/wgsl/resolver/resolver.h"

#include <tuple>

#include "gmock/gmock.h"
#include "src/tint/lang/core/address_space.h"
#include "src/tint/lang/core/builtin_value.h"
#include "src/tint/lang/core/type/reference.h"
#include "src/tint/lang/core/type/sampled_texture.h"
#include "src/tint/lang/core/type/texture_dimension.h"
#include "src/tint/lang/wgsl/ast/assignment_statement.h"
#include "src/tint/lang/wgsl/ast/break_statement.h"
#include "src/tint/lang/wgsl/ast/builtin_texture_helper_test.h"
#include "src/tint/lang/wgsl/ast/call_statement.h"
#include "src/tint/lang/wgsl/ast/continue_statement.h"
#include "src/tint/lang/wgsl/ast/float_literal_expression.h"
#include "src/tint/lang/wgsl/ast/id_attribute.h"
#include "src/tint/lang/wgsl/ast/if_statement.h"
#include "src/tint/lang/wgsl/ast/loop_statement.h"
#include "src/tint/lang/wgsl/ast/return_statement.h"
#include "src/tint/lang/wgsl/ast/stage_attribute.h"
#include "src/tint/lang/wgsl/ast/switch_statement.h"
#include "src/tint/lang/wgsl/ast/unary_op_expression.h"
#include "src/tint/lang/wgsl/ast/variable_decl_statement.h"
#include "src/tint/lang/wgsl/ast/workgroup_attribute.h"
#include "src/tint/lang/wgsl/resolver/resolver_helper_test.h"
#include "src/tint/lang/wgsl/sem/array.h"
#include "src/tint/lang/wgsl/sem/call.h"
#include "src/tint/lang/wgsl/sem/function.h"
#include "src/tint/lang/wgsl/sem/member_accessor_expression.h"
#include "src/tint/lang/wgsl/sem/module.h"
#include "src/tint/lang/wgsl/sem/statement.h"
#include "src/tint/lang/wgsl/sem/switch_statement.h"
#include "src/tint/lang/wgsl/sem/variable.h"
#include "src/tint/utils/text/string_stream.h"

namespace tint::resolver {
namespace {

ElementsAre;
HasSubstr;

usingnamespacetint::core::fluent_types;     // NOLINT
usingnamespacetint::core::number_suffixes;  // NOLINT

// Helpers and typedefs
DataType;
alias;
alias1;
alias2;
alias3;
Op;

TEST_F(ResolverTest, Stmt_Assign) {}

TEST_F(ResolverTest, Stmt_Case) {}

TEST_F(ResolverTest, Stmt_Case_AddressOf_Invalid) {}

TEST_F(ResolverTest, Stmt_Block) {}

TEST_F(ResolverTest, Stmt_If) {}

TEST_F(ResolverTest, Stmt_Loop) {}

TEST_F(ResolverTest, Stmt_Return) {}

TEST_F(ResolverTest, Stmt_Return_WithoutValue) {}

TEST_F(ResolverTest, Stmt_Switch) {}

TEST_F(ResolverTest, Stmt_Call) {}

TEST_F(ResolverTest, Stmt_VariableDecl) {}

TEST_F(ResolverTest, Stmt_VariableDecl_Alias) {}

TEST_F(ResolverTest, Stmt_VariableDecl_ModuleScope) {}

TEST_F(ResolverTest, Stmt_VariableDecl_OuterScopeAfterInnerScope) {}

TEST_F(ResolverTest, Stmt_VariableDecl_ModuleScopeAfterFunctionScope) {}

TEST_F(ResolverTest, ArraySize_UnsignedLiteral) {}

TEST_F(ResolverTest, ArraySize_SignedLiteral) {}

TEST_F(ResolverTest, ArraySize_UnsignedConst) {}

TEST_F(ResolverTest, ArraySize_SignedConst) {}

TEST_F(ResolverTest, ArraySize_NamedOverride) {}

TEST_F(ResolverTest, ArraySize_NamedOverride_Equivalence) {}

TEST_F(ResolverTest, ArraySize_UnnamedOverride) {}

TEST_F(ResolverTest, ArraySize_UnamedOverride_Equivalence) {}

TEST_F(ResolverTest, Expr_Bitcast) {}

TEST_F(ResolverTest, Expr_Call) {}

TEST_F(ResolverTest, Expr_Call_InBinaryOp) {}

TEST_F(ResolverTest, Expr_Call_WithParams) {}

TEST_F(ResolverTest, Expr_Call_Builtin) {}

TEST_F(ResolverTest, Expr_Cast) {}

TEST_F(ResolverTest, Expr_Initializer_Scalar) {}

TEST_F(ResolverTest, Expr_Initializer_Type_Vec2) {}

TEST_F(ResolverTest, Expr_Initializer_Type_Vec3) {}

TEST_F(ResolverTest, Expr_Initializer_Type_Vec4) {}

TEST_F(ResolverTest, Expr_Identifier_GlobalVariable) {}

TEST_F(ResolverTest, Expr_Identifier_GlobalConst) {}

TEST_F(ResolverTest, Expr_Identifier_FunctionVariable_Const) {}

TEST_F(ResolverTest, IndexAccessor_Dynamic_Ref_F32) {}

TEST_F(ResolverTest, Expr_Identifier_FunctionVariable) {}

TEST_F(ResolverTest, Expr_Identifier_Function_Ptr) {}

TEST_F(ResolverTest, Expr_Call_Function) {}

TEST_F(ResolverTest, Expr_Identifier_Unknown) {}

TEST_F(ResolverTest, Function_Parameters) {}

TEST_F(ResolverTest, Function_Parameters_Locations) {}

TEST_F(ResolverTest, Function_GlobalVariable_Location) {}

TEST_F(ResolverTest, Function_RegisterInputOutputVariables) {}

TEST_F(ResolverTest, Function_ReturnType_Location) {}

TEST_F(ResolverTest, Function_ReturnType_NoLocation) {}

TEST_F(ResolverTest, Function_RegisterInputOutputVariables_SubFunction) {}

TEST_F(ResolverTest, Function_NotRegisterFunctionVariable) {}

TEST_F(ResolverTest, Function_NotRegisterFunctionConstant) {}

TEST_F(ResolverTest, Function_NotRegisterFunctionParams) {}

TEST_F(ResolverTest, Function_CallSites) {}

TEST_F(ResolverTest, Function_WorkgroupSize_NotSet) {}

TEST_F(ResolverTest, Function_WorkgroupSize_Literals) {}

TEST_F(ResolverTest, Function_WorkgroupSize_ViaConst) {}

TEST_F(ResolverTest, Function_WorkgroupSize_ViaConst_NestedInitializer) {}

TEST_F(ResolverTest, Function_WorkgroupSize_OverridableConsts) {}

TEST_F(ResolverTest, Function_WorkgroupSize_OverridableConsts_NoInit) {}

TEST_F(ResolverTest, Function_WorkgroupSize_Mixed) {}

TEST_F(ResolverTest, Expr_MemberAccessor_Type) {}

TEST_F(ResolverTest, Expr_MemberAccessor_NonCompoundType) {}

TEST_F(ResolverTest, Expr_MemberAccessor_Struct) {}

TEST_F(ResolverTest, Expr_MemberAccessor_Struct_Alias) {}

TEST_F(ResolverTest, Expr_MemberAccessor_VectorSwizzle) {}

TEST_F(ResolverTest, Expr_MemberAccessor_VectorSwizzle_SingleElement) {}

TEST_F(ResolverTest, Expr_Accessor_MultiLevel) {}

TEST_F(ResolverTest, Expr_MemberAccessor_InBinaryOp) {}

namespace ExprBinaryTest {

template <typename T, int ID>
struct Aliased {};

Aliased<vec<N, T>, ID>;

Aliased<mat<N, M, T>, ID>;

struct Params {};

template <typename LHS, typename RHS, typename RES>
constexpr Params ParamsFor(core::BinaryOp op) {}

static constexpr core::BinaryOp all_ops[] =;

static constexpr builder::ast_type_func_ptr all_create_type_funcs[] =;

// A list of all valid test cases for 'lhs op rhs', except that for vecN and
// matNxN, we only test N=3.
static constexpr Params all_valid_cases[] =;

Expr_Binary_Test_Valid;
TEST_P(Expr_Binary_Test_Valid, All) {}
INSTANTIATE_TEST_SUITE_P();

enum class BinaryExprSide {};
Expr_Binary_Test_WithAlias_Valid;
TEST_P(Expr_Binary_Test_WithAlias_Valid, All) {}
INSTANTIATE_TEST_SUITE_P();

// This test works by taking the cartesian product of all possible
// (type * type * op), and processing only the triplets that are not found in
// the `all_valid_cases` table.
Expr_Binary_Test_Invalid;
TEST_P(Expr_Binary_Test_Invalid, All) {}
INSTANTIATE_TEST_SUITE_P();

Expr_Binary_Test_Invalid_VectorMatrixMultiply;
TEST_P(Expr_Binary_Test_Invalid_VectorMatrixMultiply, All) {}
auto all_dimension_values =;
INSTANTIATE_TEST_SUITE_P();

Expr_Binary_Test_Invalid_MatrixMatrixMultiply;
TEST_P(Expr_Binary_Test_Invalid_MatrixMatrixMultiply, All) {}
INSTANTIATE_TEST_SUITE_P();

}  // namespace ExprBinaryTest

UnaryOpExpressionTest;
TEST_P(UnaryOpExpressionTest, Expr_UnaryOp) {}
INSTANTIATE_TEST_SUITE_P();

TEST_F(ResolverTest, AddressSpace_SetsIfMissing) {}

TEST_F(ResolverTest, AddressSpace_SetForSampler) {}

TEST_F(ResolverTest, AddressSpace_SetForTexture) {}

TEST_F(ResolverTest, AddressSpace_DoesNotSetOnConst) {}

TEST_F(ResolverTest, Access_SetForStorageBuffer) {}

TEST_F(ResolverTest, BindingPoint_SetForResources) {}

TEST_F(ResolverTest, Function_EntryPoints_StageAttribute) {}

// Check for linear-time traversal of functions reachable from entry points.
// See: crbug.com/tint/245
TEST_F(ResolverTest, Function_EntryPoints_LinearTime) {}

// Test for crbug.com/tint/728
TEST_F(ResolverTest, ASTNodesAreReached) {}

TEST_F(ResolverDeathTest, ASTNodeNotReached) {}

TEST_F(ResolverDeathTest, ASTNodeReachedTwice) {}

TEST_F(ResolverTest, UnaryOp_Not) {}

TEST_F(ResolverTest, UnaryOp_Complement) {}

TEST_F(ResolverTest, UnaryOp_Negation) {}

TEST_F(ResolverTest, TextureSampler_TextureSample) {}

TEST_F(ResolverTest, TextureSampler_TextureSampleInFunction) {}

TEST_F(ResolverTest, TextureSampler_TextureSampleFunctionDiamondSameVariables) {}

TEST_F(ResolverTest, TextureSampler_TextureSampleFunctionDiamondDifferentVariables) {}

TEST_F(ResolverTest, TextureSampler_TextureSampleInFunctionPassedAsArguments) {}

TEST_F(ResolverTest, TextureSampler_UnusedTextureSampleInFunctionPassedAsArguments) {}

TEST_F(ResolverTest, TextureSampler_TextureDimensions) {}

TEST_F(ResolverTest, TextureSampler_Bug1715) {}

TEST_F(ResolverTest, ModuleDependencyOrderedDeclarations) {}

constexpr size_t kMaxExpressionDepth =;

TEST_F(ResolverTest, MaxExpressionDepth_Pass) {}

TEST_F(ResolverTest, MaxExpressionDepth_Fail) {}

// Windows debug builds have significantly smaller stack than other builds, and these tests will
// stack overflow.
#if !defined(NDEBUG)

TEST_F(ResolverTest, ScopeDepth_NestedBlocks) {}

TEST_F(ResolverTest, ScopeDepth_NestedIf) {}

TEST_F(ResolverTest, ScopeDepth_IfElseChain) {}

#endif  // !defined(NDEBUG)

const size_t kMaxNumStructMembers =;

TEST_F(ResolverTest, MaxNumStructMembers_Valid) {}

TEST_F(ResolverTest, MaxNumStructMembers_Invalid) {}

TEST_F(ResolverTest, MaxNumStructMembers_WithIgnoreStructMemberLimit_Valid) {}

uint32_t kMaxNestDepthOfCompositeType =;

TEST_F(ResolverTest, MaxNestDepthOfCompositeType_Structs_Valid) {}

TEST_F(ResolverTest, MaxNestDepthOfCompositeType_Structs_Invalid) {}

TEST_F(ResolverTest, MaxNestDepthOfCompositeType_StructsWithVector_Valid) {}

TEST_F(ResolverTest, MaxNestDepthOfCompositeType_StructsWithVector_Invalid) {}

TEST_F(ResolverTest, MaxNestDepthOfCompositeType_StructsWithMatrix_Valid) {}

TEST_F(ResolverTest, MaxNestDepthOfCompositeType_StructsWithMatrix_Invalid) {}

TEST_F(ResolverTest, MaxNestDepthOfCompositeType_Arrays_Valid) {}

TEST_F(ResolverTest, MaxNestDepthOfCompositeType_Arrays_Invalid) {}

TEST_F(ResolverTest, MaxNestDepthOfCompositeType_ArraysOfVector_Valid) {}

TEST_F(ResolverTest, MaxNestDepthOfCompositeType_ArraysOfVector_Invalid) {}

TEST_F(ResolverTest, MaxNestDepthOfCompositeType_ArraysOfMatrix_Valid) {}

TEST_F(ResolverTest, MaxNestDepthOfCompositeType_ArraysOfMatrix_Invalid) {}

TEST_F(ResolverTest, MaxNestDepthOfCompositeType_StructsOfArray_Valid) {}

TEST_F(ResolverTest, MaxNestDepthOfCompositeType_StructsOfArray_Invalid) {}

TEST_F(ResolverTest, MaxNestDepthOfCompositeType_ArraysOfStruct_Valid) {}

TEST_F(ResolverTest, MaxNestDepthOfCompositeType_ArraysOfStruct_Invalid) {}

TEST_F(ResolverTest, PointerToHandleTextureParameter) {}

TEST_F(ResolverTest, PointerToHandleTextureReturn) {}

TEST_F(ResolverTest, PointerToHandleSamplerParameter) {}

TEST_F(ResolverTest, PointerToHandleTextureParameterAlias) {}

TEST_F(ResolverTest, PointerToHandleSamplerParameterAlias) {}

TEST_F(ResolverTest, PointerToHandleTextureVar) {}

TEST_F(ResolverTest, PointerToHandleSamplerVar) {}

TEST_F(ResolverTest, PointerToHandleTextureVarAlias) {}

TEST_F(ResolverTest, PointerToHandleSamplerVarAlias) {}

TEST_F(ResolverTest, PointerToHandleTextureAlias) {}

TEST_F(ResolverTest, PointerToHandleSamplerAlias) {}

}  // namespace
}  // namespace tint::resolver