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

// Copyright 2021 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 "gmock/gmock.h"
#include "src/tint/lang/core/type/helper_test.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/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/resolver/resolver_helper_test.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/statement.h"
#include "src/tint/lang/wgsl/sem/variable.h"
#include "src/tint/utils/text/string.h"
#include "src/tint/utils/text/string_stream.h"

ElementsAre;
HasSubstr;

namespace tint::resolver {
namespace {

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

ExpressionList;

ResolverBuiltinTest;

struct BuiltinData {};

inline std::ostream& operator<<(std::ostream& out, BuiltinData data) {}

TEST_F(ResolverBuiltinTest, ModuleScopeUsage) {}

TEST_F(ResolverBuiltinTest, SameOverloadReturnsSameCallTarget) {}

// Tests for Logical builtins
namespace logical_builtin_tests {

ResolverBuiltinTest_BoolMethod;

TEST_P(ResolverBuiltinTest_BoolMethod, Scalar) {}
TEST_P(ResolverBuiltinTest_BoolMethod, Vector) {}
INSTANTIATE_TEST_SUITE_P();

TEST_F(ResolverBuiltinTest, Select) {}

TEST_F(ResolverBuiltinTest, Select_Error_NoParams) {}

TEST_F(ResolverBuiltinTest, Select_Error_SelectorInt) {}

TEST_F(ResolverBuiltinTest, Select_Error_Matrix) {}

TEST_F(ResolverBuiltinTest, Select_Error_MismatchTypes) {}

TEST_F(ResolverBuiltinTest, Select_Error_MismatchVectorSize) {}

}  // namespace logical_builtin_tests

// Tests for Array builtins
namespace array_builtin_tests {

ResolverBuiltinArrayTest;

TEST_F(ResolverBuiltinArrayTest, ArrayLength_Vector) {}

TEST_F(ResolverBuiltinArrayTest, ArrayLength_Error_ArraySized) {}

}  // namespace array_builtin_tests

// Tests for Numeric builtins with float parameter
namespace float_builtin_tests {

// Testcase parameters for float built-in having signature of (T, ...) -> T and (vecN<T>, ...) ->
// vecN<T>
struct BuiltinDataWithParamNum {};

inline std::ostream& operator<<(std::ostream& out, BuiltinDataWithParamNum data) {}

// Tests for float built-ins that has signiture (T, ...) -> T and (vecN<T>, ...) -> vecN<T>
ResolverBuiltinTest_FloatBuiltin_IdenticalType;

TEST_P(ResolverBuiltinTest_FloatBuiltin_IdenticalType, Error_NoParams) {}

TEST_P(ResolverBuiltinTest_FloatBuiltin_IdenticalType, OneParam_Scalar_f32) {}

TEST_P(ResolverBuiltinTest_FloatBuiltin_IdenticalType, OneParam_Vector_f32) {}

TEST_P(ResolverBuiltinTest_FloatBuiltin_IdenticalType, TwoParams_Scalar_f32) {}

TEST_P(ResolverBuiltinTest_FloatBuiltin_IdenticalType, TwoParams_Vector_f32) {}

TEST_P(ResolverBuiltinTest_FloatBuiltin_IdenticalType, ThreeParams_Scalar_f32) {}

TEST_P(ResolverBuiltinTest_FloatBuiltin_IdenticalType, ThreeParams_Vector_f32) {}

TEST_P(ResolverBuiltinTest_FloatBuiltin_IdenticalType, FourParams_Scalar_f32) {}

TEST_P(ResolverBuiltinTest_FloatBuiltin_IdenticalType, FourParams_Vector_f32) {}

TEST_P(ResolverBuiltinTest_FloatBuiltin_IdenticalType, OneParam_Scalar_f16) {}

TEST_P(ResolverBuiltinTest_FloatBuiltin_IdenticalType, OneParam_Vector_f16) {}

TEST_P(ResolverBuiltinTest_FloatBuiltin_IdenticalType, TwoParams_Scalar_f16) {}

TEST_P(ResolverBuiltinTest_FloatBuiltin_IdenticalType, TwoParams_Vector_f16) {}

TEST_P(ResolverBuiltinTest_FloatBuiltin_IdenticalType, ThreeParams_Scalar_f16) {}

TEST_P(ResolverBuiltinTest_FloatBuiltin_IdenticalType, ThreeParams_Vector_f16) {}

TEST_P(ResolverBuiltinTest_FloatBuiltin_IdenticalType, FourParams_Scalar_f16) {}

TEST_P(ResolverBuiltinTest_FloatBuiltin_IdenticalType, FourParams_Vector_f16) {}

INSTANTIATE_TEST_SUITE_P();

ResolverBuiltinFloatTest;

// cross: (vec3<T>, vec3<T>) -> vec3<T>
TEST_F(ResolverBuiltinFloatTest, Cross_f32) {}

TEST_F(ResolverBuiltinFloatTest, Cross_f16) {}

TEST_F(ResolverBuiltinFloatTest, Cross_Error_NoArgs) {}

TEST_F(ResolverBuiltinFloatTest, Cross_Error_Scalar) {}

TEST_F(ResolverBuiltinFloatTest, Cross_Error_Vec3Int) {}

TEST_F(ResolverBuiltinFloatTest, Cross_Error_Vec4) {}

TEST_F(ResolverBuiltinFloatTest, Cross_Error_TooManyParams) {}

// distance: (T, T) -> T, (vecN<T>, vecN<T>) -> T
TEST_F(ResolverBuiltinFloatTest, Distance_Scalar_f32) {}

TEST_F(ResolverBuiltinFloatTest, Distance_Scalar_f16) {}

TEST_F(ResolverBuiltinFloatTest, Distance_Vector_f32) {}

TEST_F(ResolverBuiltinFloatTest, Distance_Vector_f16) {}

TEST_F(ResolverBuiltinFloatTest, Distance_TooManyParams) {}

TEST_F(ResolverBuiltinFloatTest, Distance_TooFewParams) {}

TEST_F(ResolverBuiltinFloatTest, Distance_NoParams) {}

// frexp: (f32) -> __frexp_result, (vecN<f32>) -> __frexp_result_vecN, (f16) -> __frexp_result_16,
// (vecN<f16>) -> __frexp_result_vecN_f16
TEST_F(ResolverBuiltinFloatTest, FrexpScalar_f32) {}

TEST_F(ResolverBuiltinFloatTest, FrexpScalar_f16) {}

TEST_F(ResolverBuiltinFloatTest, FrexpVector_f32) {}

TEST_F(ResolverBuiltinFloatTest, FrexpVector_f16) {}

TEST_F(ResolverBuiltinFloatTest, Frexp_Error_FirstParamInt) {}

// length: (T) -> T, (vecN<T>) -> T
TEST_F(ResolverBuiltinFloatTest, Length_Scalar_f32) {}

TEST_F(ResolverBuiltinFloatTest, Length_Scalar_f16) {}

TEST_F(ResolverBuiltinFloatTest, Length_FloatVector_f32) {}

TEST_F(ResolverBuiltinFloatTest, Length_FloatVector_f16) {}

TEST_F(ResolverBuiltinFloatTest, Length_NoParams) {}

TEST_F(ResolverBuiltinFloatTest, Length_TooManyParams) {}

// mix(vecN<T>, vecN<T>, T) -> vecN<T>. Other overloads are tested in
// ResolverBuiltinTest_FloatBuiltin_IdenticalType above.
TEST_F(ResolverBuiltinFloatTest, Mix_VectorScalar_f32) {}

TEST_F(ResolverBuiltinFloatTest, Mix_VectorScalar_f16) {}

// modf: (f32) -> __modf_result, (vecN<f32>) -> __modf_result_vecN, (f16) -> __modf_result_f16,
// (vecN<f16>) -> __modf_result_vecN_f16
TEST_F(ResolverBuiltinFloatTest, ModfScalar_f32) {}

TEST_F(ResolverBuiltinFloatTest, ModfScalar_f16) {}

TEST_F(ResolverBuiltinFloatTest, ModfVector_f32) {}

TEST_F(ResolverBuiltinFloatTest, ModfVector_f16) {}

TEST_F(ResolverBuiltinFloatTest, Modf_Error_FirstParamInt) {}

TEST_F(ResolverBuiltinFloatTest, Modf_Error_SecondParamIntPtr) {}

TEST_F(ResolverBuiltinFloatTest, Modf_Error_SecondParamNotAPointer) {}

TEST_F(ResolverBuiltinFloatTest, Modf_Error_VectorSizesDontMatch) {}

// normalize: (vecN<T>) -> vecN<T>
TEST_F(ResolverBuiltinFloatTest, Normalize_Vector_f32) {}

TEST_F(ResolverBuiltinFloatTest, Normalize_Vector_f16) {}

TEST_F(ResolverBuiltinFloatTest, Normalize_Error_NoParams) {}

}  // namespace float_builtin_tests

// Tests for Numeric builtins with all integer parameter
namespace integer_builtin_tests {

// Testcase parameters for integer built-in having signature of (T, ...) -> T and (vecN<T>, ...) ->
// vecN<T>, where T is i32 and u32
struct BuiltinDataWithParamNum {};

inline std::ostream& operator<<(std::ostream& out, BuiltinDataWithParamNum data) {}

// Tests for integer built-ins that has signiture (T, ...) -> T and (vecN<T>, ...) -> vecN<T>
ResolverBuiltinTest_IntegerBuiltin_IdenticalType;

TEST_P(ResolverBuiltinTest_IntegerBuiltin_IdenticalType, Error_NoParams) {}

TEST_P(ResolverBuiltinTest_IntegerBuiltin_IdenticalType, OneParams_Scalar_i32) {}

TEST_P(ResolverBuiltinTest_IntegerBuiltin_IdenticalType, OneParams_Vector_i32) {}

TEST_P(ResolverBuiltinTest_IntegerBuiltin_IdenticalType, OneParams_Scalar_u32) {}

TEST_P(ResolverBuiltinTest_IntegerBuiltin_IdenticalType, OneParams_Vector_u32) {}

TEST_P(ResolverBuiltinTest_IntegerBuiltin_IdenticalType, TwoParams_Scalar_i32) {}

TEST_P(ResolverBuiltinTest_IntegerBuiltin_IdenticalType, TwoParams_Vector_i32) {}

TEST_P(ResolverBuiltinTest_IntegerBuiltin_IdenticalType, TwoParams_Scalar_u32) {}

TEST_P(ResolverBuiltinTest_IntegerBuiltin_IdenticalType, TwoParams_Vector_u32) {}

TEST_P(ResolverBuiltinTest_IntegerBuiltin_IdenticalType, ThreeParams_Scalar_i32) {}

TEST_P(ResolverBuiltinTest_IntegerBuiltin_IdenticalType, ThreeParams_Vector_i32) {}

TEST_P(ResolverBuiltinTest_IntegerBuiltin_IdenticalType, ThreeParams_Scalar_u32) {}

TEST_P(ResolverBuiltinTest_IntegerBuiltin_IdenticalType, ThreeParams_Vector_u32) {}

TEST_P(ResolverBuiltinTest_IntegerBuiltin_IdenticalType, FourParams_Scalar_i32) {}

TEST_P(ResolverBuiltinTest_IntegerBuiltin_IdenticalType, FourParams_Vector_i32) {}

TEST_P(ResolverBuiltinTest_IntegerBuiltin_IdenticalType, FourParams_Scalar_u32) {}

TEST_P(ResolverBuiltinTest_IntegerBuiltin_IdenticalType, FourParams_Vector_u32) {}

INSTANTIATE_TEST_SUITE_P();

}  // namespace integer_builtin_tests

// Tests for Numeric builtins with matrix parameter, i.e. "determinant" and "transpose"
namespace matrix_builtin_tests {

TEST_F(ResolverBuiltinTest, Determinant_2x2_f32) {}

TEST_F(ResolverBuiltinTest, Determinant_2x2_f16) {}

TEST_F(ResolverBuiltinTest, Determinant_3x3_f32) {}

TEST_F(ResolverBuiltinTest, Determinant_3x3_f16) {}

TEST_F(ResolverBuiltinTest, Determinant_4x4_f32) {}

TEST_F(ResolverBuiltinTest, Determinant_4x4_f16) {}

TEST_F(ResolverBuiltinTest, Determinant_NotSquare) {}

TEST_F(ResolverBuiltinTest, Determinant_NotMatrix) {}

}  // namespace matrix_builtin_tests

// Tests for Numeric builtins with float and integer vector parameter, i.e. "dot"
namespace vector_builtin_tests {

TEST_F(ResolverBuiltinTest, Dot_Vec2_f32) {}

TEST_F(ResolverBuiltinTest, Dot_Vec2_f16) {}

TEST_F(ResolverBuiltinTest, Dot_Vec3_i32) {}

TEST_F(ResolverBuiltinTest, Dot_Vec4_u32) {}

TEST_F(ResolverBuiltinTest, Dot_Error_Scalar) {}

}  // namespace vector_builtin_tests

// Tests for Derivative builtins
namespace derivative_builtin_tests {

ResolverBuiltinDerivativeTest;

TEST_P(ResolverBuiltinDerivativeTest, Scalar) {}

TEST_P(ResolverBuiltinDerivativeTest, Vector) {}

TEST_P(ResolverBuiltinDerivativeTest, MissingParam) {}

INSTANTIATE_TEST_SUITE_P();

}  // namespace derivative_builtin_tests

// Tests for Texture builtins
namespace texture_builtin_tests {

enum class Texture {};
template <typename STREAM, typename = traits::EnableIfIsOStream<STREAM>>
auto& operator<<(STREAM& out, Texture data) {}

struct TextureTestParams {};
inline std::ostream& operator<<(std::ostream& out, TextureTestParams data) {}

class ResolverBuiltinTest_TextureOperation : public ResolverTestWithParam<TextureTestParams> {};

ResolverBuiltinTest_SampledTextureOperation;
TEST_P(ResolverBuiltinTest_SampledTextureOperation, TextureLoadSampled) {}

INSTANTIATE_TEST_SUITE_P();

ResolverBuiltinTest_Texture;

INSTANTIATE_TEST_SUITE_P();

static std::string to_str(const std::string& func, VectorRef<const sem::Parameter*> params) {}

static const char* expected_texture_overload(ast::test::ValidTextureOverload overload) {}

TEST_P(ResolverBuiltinTest_Texture, Call) {}

}  // namespace texture_builtin_tests

// Tests for Data Packing builtins
namespace data_packing_builtin_tests {

ResolverBuiltinTest_DataPacking;
TEST_P(ResolverBuiltinTest_DataPacking, InferType) {}

TEST_P(ResolverBuiltinTest_DataPacking, Error_IncorrectParamType) {}

TEST_P(ResolverBuiltinTest_DataPacking, Error_NoParams) {}

TEST_P(ResolverBuiltinTest_DataPacking, Error_TooManyParams) {}

INSTANTIATE_TEST_SUITE_P();

}  // namespace data_packing_builtin_tests

// Tests for Data Unpacking builtins
namespace data_unpacking_builtin_tests {

ResolverBuiltinTest_DataUnpacking;
TEST_P(ResolverBuiltinTest_DataUnpacking, InferType) {}

INSTANTIATE_TEST_SUITE_P();

}  // namespace data_unpacking_builtin_tests

// Tests for Synchronization builtins
namespace synchronization_builtin_tests {

ResolverBuiltinTest_Barrier;
TEST_P(ResolverBuiltinTest_Barrier, InferType) {}

TEST_P(ResolverBuiltinTest_Barrier, Error_TooManyParams) {}

INSTANTIATE_TEST_SUITE_P();

}  // namespace synchronization_builtin_tests

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