1617a3babSopenharmony_ci//
2617a3babSopenharmony_ci// Copyright (C) 2016 LunarG, Inc.
3617a3babSopenharmony_ci//
4617a3babSopenharmony_ci// All rights reserved.
5617a3babSopenharmony_ci//
6617a3babSopenharmony_ci// Redistribution and use in source and binary forms, with or without
7617a3babSopenharmony_ci// modification, are permitted provided that the following conditions
8617a3babSopenharmony_ci// are met:
9617a3babSopenharmony_ci//
10617a3babSopenharmony_ci//    Redistributions of source code must retain the above copyright
11617a3babSopenharmony_ci//    notice, this list of conditions and the following disclaimer.
12617a3babSopenharmony_ci//
13617a3babSopenharmony_ci//    Redistributions in binary form must reproduce the above
14617a3babSopenharmony_ci//    copyright notice, this list of conditions and the following
15617a3babSopenharmony_ci//    disclaimer in the documentation and/or other materials provided
16617a3babSopenharmony_ci//    with the distribution.
17617a3babSopenharmony_ci//
18617a3babSopenharmony_ci//    Neither the name of Google Inc. nor the names of its
19617a3babSopenharmony_ci//    contributors may be used to endorse or promote products derived
20617a3babSopenharmony_ci//    from this software without specific prior written permission.
21617a3babSopenharmony_ci//
22617a3babSopenharmony_ci// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23617a3babSopenharmony_ci// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24617a3babSopenharmony_ci// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25617a3babSopenharmony_ci// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26617a3babSopenharmony_ci// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27617a3babSopenharmony_ci// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28617a3babSopenharmony_ci// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29617a3babSopenharmony_ci// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30617a3babSopenharmony_ci// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31617a3babSopenharmony_ci// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32617a3babSopenharmony_ci// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33617a3babSopenharmony_ci// POSSIBILITY OF SUCH DAMAGE.
34617a3babSopenharmony_ci
35617a3babSopenharmony_ci#include <gtest/gtest.h>
36617a3babSopenharmony_ci
37617a3babSopenharmony_ci#include "TestFixture.h"
38617a3babSopenharmony_ci
39617a3babSopenharmony_cinamespace glslangtest {
40617a3babSopenharmony_cinamespace {
41617a3babSopenharmony_ci
42617a3babSopenharmony_cistruct RemapTestArgs {
43617a3babSopenharmony_ci    const char*  fileName;
44617a3babSopenharmony_ci    const char*  entryPoint;
45617a3babSopenharmony_ci    Source       sourceLanguage;
46617a3babSopenharmony_ci    unsigned int remapOpts;
47617a3babSopenharmony_ci};
48617a3babSopenharmony_ci
49617a3babSopenharmony_ci// We are using FileNameEntryPointPair objects as parameters for instantiating
50617a3babSopenharmony_ci// the template, so the global FileNameAsCustomTestSuffix() won't work since
51617a3babSopenharmony_ci// it assumes std::string as parameters. Thus, an overriding one here.
52617a3babSopenharmony_cistd::string FileNameAsCustomTestSuffix(
53617a3babSopenharmony_ci    const ::testing::TestParamInfo<RemapTestArgs>& info) {
54617a3babSopenharmony_ci    std::string name = info.param.fileName;
55617a3babSopenharmony_ci    // A valid test case suffix cannot have '.' and '-' inside.
56617a3babSopenharmony_ci    std::replace(name.begin(), name.end(), '.', '_');
57617a3babSopenharmony_ci    std::replace(name.begin(), name.end(), '-', '_');
58617a3babSopenharmony_ci    return name;
59617a3babSopenharmony_ci}
60617a3babSopenharmony_ci
61617a3babSopenharmony_ciusing RemapTest = GlslangTest<::testing::TestWithParam<RemapTestArgs>>;
62617a3babSopenharmony_ci
63617a3babSopenharmony_ci// Remapping SPIR-V modules.
64617a3babSopenharmony_ciTEST_P(RemapTest, FromFile)
65617a3babSopenharmony_ci{
66617a3babSopenharmony_ci    if (GetSuffix(GetParam().fileName) == "spv") {
67617a3babSopenharmony_ci        loadFileRemapAndCheck(GlobalTestSettings.testRoot, GetParam().fileName,
68617a3babSopenharmony_ci                              GetParam().sourceLanguage,
69617a3babSopenharmony_ci                              Semantics::Vulkan,
70617a3babSopenharmony_ci                              Target::Spv,
71617a3babSopenharmony_ci                              GetParam().remapOpts);
72617a3babSopenharmony_ci    } else {
73617a3babSopenharmony_ci        loadFileCompileRemapAndCheck(GlobalTestSettings.testRoot, GetParam().fileName,
74617a3babSopenharmony_ci                                     GetParam().sourceLanguage,
75617a3babSopenharmony_ci                                     Semantics::Vulkan,
76617a3babSopenharmony_ci                                     Target::Spv,
77617a3babSopenharmony_ci                                     GetParam().entryPoint,
78617a3babSopenharmony_ci                                     GetParam().remapOpts);
79617a3babSopenharmony_ci    }
80617a3babSopenharmony_ci}
81617a3babSopenharmony_ci
82617a3babSopenharmony_ci// clang-format off
83617a3babSopenharmony_ciINSTANTIATE_TEST_SUITE_P(
84617a3babSopenharmony_ci    ToSpirv, RemapTest,
85617a3babSopenharmony_ci    ::testing::ValuesIn(std::vector<RemapTestArgs>{
86617a3babSopenharmony_ci            // GLSL remapper tests
87617a3babSopenharmony_ci            // testname                                   entry   language      remapper_options
88617a3babSopenharmony_ci            { "remap.basic.none.frag",                    "main", Source::GLSL, spv::spirvbin_t::NONE },
89617a3babSopenharmony_ci            { "remap.basic.everything.frag",              "main", Source::GLSL, spv::spirvbin_t::DO_EVERYTHING },
90617a3babSopenharmony_ci            { "remap.basic.dcefunc.frag",                 "main", Source::GLSL, spv::spirvbin_t::DCE_FUNCS },
91617a3babSopenharmony_ci            { "remap.basic.strip.frag",                   "main", Source::GLSL, spv::spirvbin_t::STRIP },
92617a3babSopenharmony_ci            { "remap.specconst.comp",                     "main", Source::GLSL, spv::spirvbin_t::DO_EVERYTHING },
93617a3babSopenharmony_ci            { "remap.switch.none.frag",                   "main", Source::GLSL, spv::spirvbin_t::NONE },
94617a3babSopenharmony_ci            { "remap.switch.everything.frag",             "main", Source::GLSL, spv::spirvbin_t::DO_EVERYTHING },
95617a3babSopenharmony_ci            { "remap.literal64.none.spv",                 "main", Source::GLSL, spv::spirvbin_t::NONE },
96617a3babSopenharmony_ci            { "remap.literal64.everything.spv",           "main", Source::GLSL, spv::spirvbin_t::DO_EVERYTHING },
97617a3babSopenharmony_ci            { "remap.if.none.frag",                       "main", Source::GLSL, spv::spirvbin_t::NONE },
98617a3babSopenharmony_ci            { "remap.if.everything.frag",                 "main", Source::GLSL, spv::spirvbin_t::DO_EVERYTHING },
99617a3babSopenharmony_ci            { "remap.similar_1a.none.frag",               "main", Source::GLSL, spv::spirvbin_t::NONE },
100617a3babSopenharmony_ci            { "remap.similar_1b.none.frag",               "main", Source::GLSL, spv::spirvbin_t::NONE },
101617a3babSopenharmony_ci            { "remap.similar_1a.everything.frag",         "main", Source::GLSL, spv::spirvbin_t::DO_EVERYTHING },
102617a3babSopenharmony_ci            { "remap.similar_1b.everything.frag",         "main", Source::GLSL, spv::spirvbin_t::DO_EVERYTHING },
103617a3babSopenharmony_ci            { "remap.uniformarray.none.frag",             "main", Source::GLSL, spv::spirvbin_t::NONE },
104617a3babSopenharmony_ci            { "remap.uniformarray.everything.frag",       "main", Source::GLSL, spv::spirvbin_t::DO_EVERYTHING },
105617a3babSopenharmony_ci
106617a3babSopenharmony_ci            // HLSL remapper tests
107617a3babSopenharmony_ci            { "remap.hlsl.sample.basic.strip.frag",       "main", Source::HLSL, spv::spirvbin_t::STRIP },
108617a3babSopenharmony_ci            { "remap.hlsl.sample.basic.everything.frag",  "main", Source::HLSL, spv::spirvbin_t::DO_EVERYTHING },
109617a3babSopenharmony_ci            { "remap.hlsl.sample.basic.none.frag",        "main", Source::HLSL, spv::spirvbin_t::NONE },
110617a3babSopenharmony_ci            { "remap.hlsl.templatetypes.none.frag",       "main", Source::HLSL, spv::spirvbin_t::NONE },
111617a3babSopenharmony_ci            { "remap.hlsl.templatetypes.everything.frag", "main", Source::HLSL, spv::spirvbin_t::DO_EVERYTHING },
112617a3babSopenharmony_ci            }),
113617a3babSopenharmony_ci    FileNameAsCustomTestSuffix
114617a3babSopenharmony_ci);
115617a3babSopenharmony_ci// clang-format on
116617a3babSopenharmony_ci
117617a3babSopenharmony_ci}  // anonymous namespace
118617a3babSopenharmony_ci}  // namespace glslangtest
119