chromium/third_party/dawn/src/tint/lang/wgsl/inspector/inspector_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 "gmock/gmock.h"

#include "src/tint/lang/core/fluent_types.h"
#include "src/tint/lang/core/type/depth_texture.h"
#include "src/tint/lang/core/type/external_texture.h"
#include "src/tint/lang/core/type/multisampled_texture.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/call_statement.h"
#include "src/tint/lang/wgsl/ast/disable_validation_attribute.h"
#include "src/tint/lang/wgsl/ast/id_attribute.h"
#include "src/tint/lang/wgsl/ast/stage_attribute.h"
#include "src/tint/lang/wgsl/ast/workgroup_attribute.h"
#include "src/tint/lang/wgsl/inspector/entry_point.h"
#include "src/tint/lang/wgsl/inspector/inspector.h"
#include "src/tint/lang/wgsl/inspector/inspector_builder_test.h"
#include "src/tint/lang/wgsl/inspector/inspector_runner_test.h"
#include "src/tint/lang/wgsl/program/program_builder.h"
#include "src/tint/lang/wgsl/sem/variable.h"

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

namespace tint::inspector {
namespace {

// All the tests that descend from InspectorBuilder are expected to define their test state via
// building up the AST through InspectorBuilder and then generate the program with ::Build. The
// returned Inspector from ::Build can then be used to test expectations.
//
// All the tests that descend from InspectorRunner are expected to define their test state via a
// WGSL shader, which will be parsed to generate a Program and Inspector in ::Initialize. The
// returned Inspector from ::Initialize can then be used to test expectations.

class InspectorGetEntryPointTest : public InspectorBuilder, public testing::Test {};

InspectorGetEntryPointComponentAndCompositionTestParams;
class InspectorGetEntryPointComponentAndCompositionTest
    : public InspectorBuilder,
      public testing::TestWithParam<InspectorGetEntryPointComponentAndCompositionTestParams> {};
struct InspectorGetEntryPointInterpolateTestParams {};
class InspectorGetEntryPointInterpolateTest
    : public InspectorBuilder,
      public testing::TestWithParam<InspectorGetEntryPointInterpolateTestParams> {};
class InspectorGetOverrideDefaultValuesTest : public InspectorBuilder, public testing::Test {};
class InspectorGetConstantNameToIdMapTest : public InspectorBuilder, public testing::Test {};
class InspectorGetResourceBindingsTest : public InspectorBuilder, public testing::Test {};
class InspectorGetUniformBufferResourceBindingsTest : public InspectorBuilder,
                                                      public testing::Test {};
class InspectorGetStorageBufferResourceBindingsTest : public InspectorBuilder,
                                                      public testing::Test {};
class InspectorGetReadOnlyStorageBufferResourceBindingsTest : public InspectorBuilder,
                                                              public testing::Test {};
class InspectorGetSamplerResourceBindingsTest : public InspectorBuilder, public testing::Test {};
class InspectorGetComparisonSamplerResourceBindingsTest : public InspectorBuilder,
                                                          public testing::Test {};
class InspectorGetSampledTextureResourceBindingsTest : public InspectorBuilder,
                                                       public testing::Test {};
class InspectorGetSampledArrayTextureResourceBindingsTest : public InspectorBuilder,
                                                            public testing::Test {};
struct GetSampledTextureTestParams {};
class InspectorGetSampledTextureResourceBindingsTestWithParam
    : public InspectorBuilder,
      public testing::TestWithParam<GetSampledTextureTestParams> {};
class InspectorGetSampledArrayTextureResourceBindingsTestWithParam
    : public InspectorBuilder,
      public testing::TestWithParam<GetSampledTextureTestParams> {};
class InspectorGetMultisampledTextureResourceBindingsTest : public InspectorBuilder,
                                                            public testing::Test {};
class InspectorGetMultisampledArrayTextureResourceBindingsTest : public InspectorBuilder,
                                                                 public testing::Test {};
GetMultisampledTextureTestParams;
class InspectorGetMultisampledArrayTextureResourceBindingsTestWithParam
    : public InspectorBuilder,
      public testing::TestWithParam<GetMultisampledTextureTestParams> {};
class InspectorGetMultisampledTextureResourceBindingsTestWithParam
    : public InspectorBuilder,
      public testing::TestWithParam<GetMultisampledTextureTestParams> {};
class InspectorGetStorageTextureResourceBindingsTest : public InspectorBuilder,
                                                       public testing::Test {};
struct GetDepthTextureTestParams {};
class InspectorGetDepthTextureResourceBindingsTestWithParam
    : public InspectorBuilder,
      public testing::TestWithParam<GetDepthTextureTestParams> {};

class InspectorGetDepthMultisampledTextureResourceBindingsTest : public InspectorBuilder,
                                                                 public testing::Test {};

DimensionParams;
TexelFormatParams;
GetStorageTextureTestParams;
class InspectorGetStorageTextureResourceBindingsTestWithParam
    : public InspectorBuilder,
      public testing::TestWithParam<GetStorageTextureTestParams> {};

class InspectorGetExternalTextureResourceBindingsTest : public InspectorBuilder,
                                                        public testing::Test {};

class InspectorGetSamplerTextureUsesTest : public InspectorRunner, public testing::Test {};

class InspectorGetUsedExtensionNamesTest : public InspectorRunner, public testing::Test {};

class InspectorGetEnableDirectivesTest : public InspectorRunner, public testing::Test {};

class InspectorGetBlendSrcTest : public InspectorBuilder, public testing::Test {};

// This is a catch all for shaders that have demonstrated regressions/crashes in
// the wild.
class InspectorRegressionTest : public InspectorRunner, public testing::Test {};

TEST_F(InspectorGetEntryPointTest, NoFunctions) {}

TEST_F(InspectorGetEntryPointTest, NoEntryPoints) {}

TEST_F(InspectorGetEntryPointTest, OneEntryPoint) {}

TEST_F(InspectorGetEntryPointTest, MultipleEntryPoints) {}

TEST_F(InspectorGetEntryPointTest, MixFunctionsAndEntryPoints) {}

TEST_F(InspectorGetEntryPointTest, DefaultWorkgroupSize) {}

// Test that push_constant_size is zero if there are no push constants.
TEST_F(InspectorGetEntryPointTest, PushConstantSizeNone) {}

// Test that push_constant_size is 4 (bytes) if there is a single F32 push constant.
TEST_F(InspectorGetEntryPointTest, PushConstantSizeOneWord) {}

// Test that push_constant_size is 12 (bytes) if there is a struct containing one
// each of i32, f32 and u32.
TEST_F(InspectorGetEntryPointTest, PushConstantSizeThreeWords) {}

// Test that push_constant_size is 4 (bytes) if there are two push constants,
// one used by the entry point containing an f32, and one unused by the entry
// point containing a struct of size 12 bytes.
TEST_F(InspectorGetEntryPointTest, PushConstantSizeTwoConstants) {}

TEST_F(InspectorGetEntryPointTest, NonDefaultWorkgroupSize) {}

TEST_F(InspectorGetEntryPointTest, WorkgroupStorageSizeEmpty) {}

TEST_F(InspectorGetEntryPointTest, WorkgroupStorageSizeSimple) {}

TEST_F(InspectorGetEntryPointTest, WorkgroupStorageSizeCompoundTypes) {}

TEST_F(InspectorGetEntryPointTest, WorkgroupStorageSizeAlignmentPadding) {}

TEST_F(InspectorGetEntryPointTest, WorkgroupStorageSizeStructAlignment) {}

TEST_F(InspectorGetEntryPointTest, NoInOutVariables) {}

TEST_P(InspectorGetEntryPointComponentAndCompositionTest, Test) {}
INSTANTIATE_TEST_SUITE_P();

TEST_F(InspectorGetEntryPointTest, MultipleInOutVariables) {}

TEST_F(InspectorGetEntryPointTest, MultipleEntryPointsInOutVariables) {}

TEST_F(InspectorGetEntryPointTest, BuiltInsNotStageVariables) {}

TEST_F(InspectorGetEntryPointTest, InOutStruct) {}

TEST_F(InspectorGetEntryPointTest, MultipleEntryPointsInOutSharedStruct) {}

TEST_F(InspectorGetEntryPointTest, MixInOutVariablesAndStruct) {}

TEST_F(InspectorGetEntryPointTest, OverrideUnreferenced) {}

TEST_F(InspectorGetEntryPointTest, OverrideReferencedByEntryPoint) {}

TEST_F(InspectorGetEntryPointTest, OverrideReferencedByCallee) {}

TEST_F(InspectorGetEntryPointTest, OverrideSomeReferenced) {}

TEST_F(InspectorGetEntryPointTest, OverrideReferencedIndirectly) {}

TEST_F(InspectorGetEntryPointTest, OverrideReferencedIndirectly_ViaPrivateInitializer) {}

TEST_F(InspectorGetEntryPointTest, OverrideReferencedIndirectly_MultipleEntryPoints) {}

TEST_F(InspectorGetEntryPointTest, OverrideReferencedByAttribute) {}

TEST_F(InspectorGetEntryPointTest, OverrideReferencedByAttributeIndirectly) {}

TEST_F(InspectorGetEntryPointTest, OverrideReferencedByArraySize) {}

TEST_F(InspectorGetEntryPointTest, OverrideReferencedByArraySizeIndirectly) {}

TEST_F(InspectorGetEntryPointTest, OverrideReferencedByArraySizeViaAlias) {}

TEST_F(InspectorGetEntryPointTest, OverrideTypes) {}

TEST_F(InspectorGetEntryPointTest, OverrideInitialized) {}

TEST_F(InspectorGetEntryPointTest, OverrideUninitialized) {}

TEST_F(InspectorGetEntryPointTest, OverrideNumericIDSpecified) {}

TEST_F(InspectorGetEntryPointTest, NonOverrideSkipped) {}

TEST_F(InspectorGetEntryPointTest, BuiltinNotReferenced) {}

TEST_F(InspectorGetEntryPointTest, InputSampleMaskSimpleReferenced) {}

TEST_F(InspectorGetEntryPointTest, InputSampleMaskStructReferenced) {}

TEST_F(InspectorGetEntryPointTest, OutputSampleMaskSimpleReferenced) {}

TEST_F(InspectorGetEntryPointTest, OutputSampleMaskStructReferenced) {}

TEST_F(InspectorGetEntryPointTest, InputPositionSimpleReferenced) {}

TEST_F(InspectorGetEntryPointTest, InputPositionStructReferenced) {}

TEST_F(InspectorGetEntryPointTest, FrontFacingSimpleReferenced) {}

TEST_F(InspectorGetEntryPointTest, FrontFacingStructReferenced) {}

TEST_F(InspectorGetEntryPointTest, SampleIndexSimpleReferenced) {}

TEST_F(InspectorGetEntryPointTest, SampleIndexStructReferenced) {}

TEST_F(InspectorGetEntryPointTest, NumWorkgroupsSimpleReferenced) {}

TEST_F(InspectorGetEntryPointTest, NumWorkgroupsStructReferenced) {}

TEST_F(InspectorGetEntryPointTest, FragDepthSimpleReferenced) {}

TEST_F(InspectorGetEntryPointTest, FragDepthStructReferenced) {}

TEST_F(InspectorGetEntryPointTest, ImplicitInterpolate) {}

TEST_F(InspectorGetEntryPointTest, PixelLocalMemberDefault) {}

TEST_F(InspectorGetEntryPointTest, PixelLocalMemberTypes) {}

TEST_P(InspectorGetEntryPointInterpolateTest, Test) {}

INSTANTIATE_TEST_SUITE_P();

TEST_F(InspectorGetOverrideDefaultValuesTest, Bool) {}

TEST_F(InspectorGetOverrideDefaultValuesTest, U32) {}

TEST_F(InspectorGetOverrideDefaultValuesTest, I32) {}

TEST_F(InspectorGetOverrideDefaultValuesTest, F32) {}

TEST_F(InspectorGetOverrideDefaultValuesTest, F16) {}

TEST_F(InspectorGetConstantNameToIdMapTest, WithAndWithoutIds) {}

TEST_F(InspectorGetResourceBindingsTest, Empty) {}

TEST_F(InspectorGetResourceBindingsTest, Simple) {}

TEST_F(InspectorGetResourceBindingsTest, InputAttachment) {}

TEST_F(InspectorGetUniformBufferResourceBindingsTest, MissingEntryPoint) {}

TEST_F(InspectorGetUniformBufferResourceBindingsTest, NonEntryPointFunc) {}

TEST_F(InspectorGetUniformBufferResourceBindingsTest, Simple_NonStruct) {}

TEST_F(InspectorGetUniformBufferResourceBindingsTest, Simple_Struct) {}

TEST_F(InspectorGetUniformBufferResourceBindingsTest, MultipleMembers) {}

TEST_F(InspectorGetUniformBufferResourceBindingsTest, ContainingPadding) {}

TEST_F(InspectorGetUniformBufferResourceBindingsTest, NonStructVec3) {}

TEST_F(InspectorGetUniformBufferResourceBindingsTest, MultipleUniformBuffers) {}

TEST_F(InspectorGetUniformBufferResourceBindingsTest, ContainingArray) {}

TEST_F(InspectorGetStorageBufferResourceBindingsTest, Simple_NonStruct) {}

TEST_F(InspectorGetStorageBufferResourceBindingsTest, Simple_Struct) {}

TEST_F(InspectorGetStorageBufferResourceBindingsTest, MultipleMembers) {}

TEST_F(InspectorGetStorageBufferResourceBindingsTest, MultipleStorageBuffers) {}

TEST_F(InspectorGetStorageBufferResourceBindingsTest, ContainingArray) {}

TEST_F(InspectorGetStorageBufferResourceBindingsTest, ContainingRuntimeArray) {}

TEST_F(InspectorGetStorageBufferResourceBindingsTest, ContainingPadding) {}

TEST_F(InspectorGetStorageBufferResourceBindingsTest, NonStructVec3) {}

TEST_F(InspectorGetStorageBufferResourceBindingsTest, SkipReadOnly) {}

TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, Simple) {}

TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, MultipleStorageBuffers) {}

TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, ContainingArray) {}

TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, ContainingRuntimeArray) {}

TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, SkipNonReadOnly) {}

TEST_F(InspectorGetSamplerResourceBindingsTest, Simple) {}

TEST_F(InspectorGetSamplerResourceBindingsTest, NoSampler) {}

TEST_F(InspectorGetSamplerResourceBindingsTest, InFunction) {}

TEST_F(InspectorGetSamplerResourceBindingsTest, UnknownEntryPoint) {}

TEST_F(InspectorGetSamplerResourceBindingsTest, SkipsComparisonSamplers) {}

TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, Simple) {}

TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, NoSampler) {}

TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, InFunction) {}

TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, UnknownEntryPoint) {}

TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, SkipsSamplers) {}

TEST_F(InspectorGetSampledTextureResourceBindingsTest, Empty) {}

TEST_P(InspectorGetSampledTextureResourceBindingsTestWithParam, textureSample) {}

INSTANTIATE_TEST_SUITE_P();

TEST_P(InspectorGetSampledArrayTextureResourceBindingsTestWithParam, textureSample) {}

INSTANTIATE_TEST_SUITE_P();

TEST_P(InspectorGetMultisampledTextureResourceBindingsTestWithParam, textureLoad) {}

INSTANTIATE_TEST_SUITE_P();

TEST_F(InspectorGetMultisampledArrayTextureResourceBindingsTest, Empty) {}

TEST_F(InspectorGetStorageTextureResourceBindingsTest, Empty) {}

TEST_P(InspectorGetStorageTextureResourceBindingsTestWithParam, Simple) {}

INSTANTIATE_TEST_SUITE_P();

TEST_P(InspectorGetDepthTextureResourceBindingsTestWithParam, textureDimensions) {}

INSTANTIATE_TEST_SUITE_P();

TEST_F(InspectorGetDepthMultisampledTextureResourceBindingsTest, textureDimensions) {}

TEST_F(InspectorGetExternalTextureResourceBindingsTest, Simple) {}

TEST_F(InspectorGetSamplerTextureUsesTest, None) {}

TEST_F(InspectorGetSamplerTextureUsesTest, Simple) {}

TEST_F(InspectorGetSamplerTextureUsesTest, UnknownEntryPoint) {}

TEST_F(InspectorGetSamplerTextureUsesTest, MultipleCalls) {}

TEST_F(InspectorGetSamplerTextureUsesTest, BothIndirect) {}

TEST_F(InspectorGetSamplerTextureUsesTest, SamplerIndirect) {}

TEST_F(InspectorGetSamplerTextureUsesTest, TextureIndirect) {}

TEST_F(InspectorGetSamplerTextureUsesTest, NeitherIndirect) {}

TEST_F(InspectorGetSamplerTextureUsesTest, Complex) {}

// Test calling GetUsedExtensionNames on a empty shader.
TEST_F(InspectorGetUsedExtensionNamesTest, Empty) {}

// Test calling GetUsedExtensionNames on a shader with no extension.
TEST_F(InspectorGetUsedExtensionNamesTest, None) {}

// Test calling GetUsedExtensionNames on a shader with valid extension.
TEST_F(InspectorGetUsedExtensionNamesTest, Simple) {}

// Test calling GetUsedExtensionNames on a shader with a extension enabled for
// multiple times.
TEST_F(InspectorGetUsedExtensionNamesTest, Duplicated) {}

// Test calling GetEnableDirectives on a empty shader.
TEST_F(InspectorGetEnableDirectivesTest, Empty) {}

// Test calling GetEnableDirectives on a shader with no extension.
TEST_F(InspectorGetEnableDirectivesTest, None) {}

// Test calling GetEnableDirectives on a shader with valid extension.
TEST_F(InspectorGetEnableDirectivesTest, Simple) {}

// Test calling GetEnableDirectives on a shader with a extension enabled for
// multiple times.
TEST_F(InspectorGetEnableDirectivesTest, Duplicated) {}

// Crash was occuring in ::GenerateSamplerTargets, when
// ::GetSamplerTextureUses was called.
TEST_F(InspectorRegressionTest, tint967) {}

class InspectorTextureTest : public InspectorRunner, public testing::Test {};

TEST_F(InspectorTextureTest, TextureLevelInEP) {}

TEST_F(InspectorTextureTest, TextureLevelInEPNoDups) {}

TEST_F(InspectorTextureTest, TextureLevelInEPMultiple) {}

TEST_F(InspectorTextureTest, TextureSamplesInEP) {}

TEST_F(InspectorTextureTest, TextureSamplesInEPNoDups) {}

TEST_F(InspectorTextureTest, TextureSamplesInEPMultiple) {}

TEST_F(InspectorTextureTest, TextureLoadInEP) {}

TEST_F(InspectorTextureTest, TextureLoadMultisampledInEP) {}

TEST_F(InspectorTextureTest, TextureLoadMultipleInEP) {}

TEST_F(InspectorTextureTest, TextureInSubfunction) {}

TEST_F(InspectorTextureTest, TextureMultipleEPs) {}

TEST_F(InspectorGetBlendSrcTest, Basic) {}

}  // namespace

static std::ostream& operator<<(std::ostream& out, const Inspector::TextureQueryType& ty) {}

}  // namespace tint::inspector