Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor test #71

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions BuildAll.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ def FindVS2017OrUpFolder(programFilesFolder, vsVersion, vsName):
LogError("Could NOT find VS%s.\n" % vsName)
return ""

def FindVS2022Folder(programFilesFolder):
return FindVS2017OrUpFolder(programFilesFolder, 17, "2022")

def FindVS2019Folder(programFilesFolder):
return FindVS2017OrUpFolder(programFilesFolder, 16, "2019")

Expand Down Expand Up @@ -132,7 +135,9 @@ def Build(hostPlatform, hostArch, buildSys, compiler, arch, configuration, tblge
batCmd = BatchCommand(hostPlatform)
if hostPlatform == "win":
programFilesFolder = FindProgramFilesFolder()
if (buildSys == "vs2019") or ((buildSys == "ninja") and (compiler == "vc142")):
if (buildSys == "vs2022") or ((buildSys == "ninja") and (compiler == "vc143")):
vsFolder = FindVS2022Folder(programFilesFolder)
elif (buildSys == "vs2019") or ((buildSys == "ninja") and (compiler == "vc142")):
vsFolder = FindVS2019Folder(programFilesFolder)
elif (buildSys == "vs2017") or ((buildSys == "ninja") and (compiler == "vc141")):
vsFolder = FindVS2017Folder(programFilesFolder)
Expand All @@ -153,10 +158,13 @@ def Build(hostPlatform, hostArch, buildSys, compiler, arch, configuration, tblge
else:
LogError("Unsupported architecture.\n")
vcToolset = ""
if (buildSys == "vs2019") and (compiler == "vc141"):
if (buildSys == "vs2022") and (compiler == "vc142"):
vcOption += " -vcvars_ver=14.2"
vcToolset = "v142,"
elif ((buildSys == "vs2022") or (buildSys == "vs2019")) and (compiler == "vc141"):
vcOption += " -vcvars_ver=14.1"
vcToolset = "v141,"
elif ((buildSys == "vs2019") or (buildSys == "vs2017")) and (compiler == "vc140"):
elif ((buildSys == "vs2022") or (buildSys == "vs2019") or (buildSys == "vs2017")) and (compiler == "vc140"):
vcOption += " -vcvars_ver=14.0"
vcToolset = "v140,"
batCmd.AddCommand("@call \"%sVCVARSALL.BAT\" %s" % (vsFolder, vcOption))
Expand All @@ -176,7 +184,9 @@ def Build(hostPlatform, hostArch, buildSys, compiler, arch, configuration, tblge
else:
batCmd.AddCommand("ninja -j%d" % parallel)
else:
if buildSys == "vs2019":
if buildSys == "vs2022":
generator = "\"Visual Studio 17\""
elif buildSys == "vs2019":
generator = "\"Visual Studio 16\""
elif buildSys == "vs2017":
generator = "\"Visual Studio 15\""
Expand Down Expand Up @@ -240,7 +250,9 @@ def Build(hostPlatform, hostArch, buildSys, compiler, arch, configuration, tblge
if (argc > 2):
compiler = sys.argv[2]
else:
if buildSys == "vs2019":
if buildSys == "vs2022":
compiler = "vc143"
elif buildSys == "vs2019":
compiler = "vc142"
elif buildSys == "vs2017":
compiler = "vc141"
Expand Down
6 changes: 6 additions & 0 deletions CI/AzurePipelines/ContinuousBuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ steps:
git config --global user.name "Dummy Name"
displayName: 'Config git'

- task: UsePythonVersion@0
inputs:
versionSpec: '3.x'
addToPath: true
architecture: 'x64'

- task: PythonScript@0
displayName: 'Build'
inputs:
Expand Down
4 changes: 4 additions & 0 deletions External/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

if(NOT EXISTS ${git_executable})
unset(git_executable CACHE)
endif()

find_program(git_executable NAMES git git.exe git.cmd)
if(NOT git_executable)
message(FATAL_ERROR "Failed to find git.")
Expand Down
10 changes: 7 additions & 3 deletions External/DirectXShaderCompiler.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

set(DirectXShaderCompiler_REV "634a23537df7e85512437a4976f9bf9fcd095e18")
set(DirectXShaderCompiler_REV "cc50c79df1272a358fbf8b16e85dc6a9e5bc2ead")

UpdateExternalLib("DirectXShaderCompiler" "https://github.com/Microsoft/DirectXShaderCompiler.git" ${DirectXShaderCompiler_REV})

Expand Down Expand Up @@ -40,6 +40,7 @@ endif()
set(SPIRV_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(SPIRV_SKIP_EXECUTABLES ON CACHE BOOL "" FORCE)
set(SPIRV_SKIP_TESTS ON CACHE BOOL "" FORCE)

add_subdirectory(DirectXShaderCompiler EXCLUDE_FROM_ALL)
foreach(target
"clang" "dxc"
Expand All @@ -53,9 +54,12 @@ foreach(target
"ClangDiagnosticAnalysis" "ClangDiagnosticAST" "ClangDiagnosticComment" "ClangDiagnosticCommon" "ClangDiagnosticDriver"
"ClangDiagnosticFrontend" "ClangDiagnosticGroups" "ClangDiagnosticIndexName" "ClangDiagnosticLex" "ClangDiagnosticParse"
"ClangDiagnosticSema" "ClangDiagnosticSerialization" "ClangStmtNodes"
"LLVMAnalysis" "LLVMAsmParser" "LLVMBitReader" "LLVMBitWriter" "LLVMCore" "LLVMDxcSupport" "LLVMDXIL" "LLVMDxilContainer"
"DxcDisassembler" "DxcOptimizer" "DxilConstants" "DxilCounters" "DxilDocs" "DxilInstructions" "DxilIntrinsicTables"
"DxilMetadata" "DxilOperations" "DxilPIXPasses" "DxilShaderModel" "DxilShaderModelInc" "DxilSigPoint" "DxilValidation" "DxilValidationInc"
"HCTGen" "HLSLIntrinsicOp" "HLSLOptions"
"LLVMAnalysis" "LLVMAsmParser" "LLVMBitReader" "LLVMBitWriter" "LLVMCore" "LLVMDxcBindingTable" "LLVMDxcSupport" "LLVMDXIL" "LLVMDxilContainer"
"LLVMDxilPIXPasses" "LLVMDxilRootSignature" "LLVMDxrFallback" "LLVMHLSL" "LLVMInstCombine" "LLVMipa" "LLVMipo" "LLVMIRReader"
"LLVMLinker" "LLVMLTO" "LLVMMSSupport" "LLVMOption" "LLVMPasses" "LLVMPassPrinters" "LLVMProfileData" "LLVMScalarOpts" "LLVMSupport"
"LLVMLinker" "LLVMMiniz" "LLVMMSSupport" "LLVMOption" "LLVMPasses" "LLVMPassPrinters" "LLVMProfileData" "LLVMScalarOpts" "LLVMSupport"
"LLVMTableGen" "LLVMTarget" "LLVMTransformUtils" "LLVMVectorize"
"ClangDriverOptions" "DxcEtw" "intrinsics_gen" "TablegenHLSLOptions"
"clang-tblgen" "llvm-tblgen" "hlsl_dxcversion_autogen" "hlsl_version_autogen")
Expand Down
4 changes: 3 additions & 1 deletion External/SPIRV-Cross.cmake
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

set(SPIRV_Cross_REV "8891bd35120ca91c252a66ccfdc3f9a9d03c70cd")
set(SPIRV_Cross_REV "37dfb3f45f4fc47c841f81e618c602f6f3de0f17")

UpdateExternalLib("SPIRV-Cross" "https://github.com/KhronosGroup/SPIRV-Cross.git" ${SPIRV_Cross_REV})

set(SPIRV_CROSS_ENABLE_TESTS OFF CACHE BOOL "" FORCE)

add_subdirectory(SPIRV-Cross EXCLUDE_FROM_ALL)
foreach(target
"spirv-cross" "spirv-cross-core" "spirv-cross-cpp" "spirv-cross-glsl" "spirv-cross-hlsl" "spirv-cross-msl" "spirv-cross-reflect"
Expand Down
2 changes: 1 addition & 1 deletion External/SPIRV-Header.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

set(SPIRV_Headers_REV "3fdabd0da2932c276b25b9b4a988ba134eba1aa6")
set(SPIRV_Headers_REV "29817199b7069bac971e5365d180295d4b077ebe")

UpdateExternalLib("SPIRV-Headers" "https://github.com/KhronosGroup/SPIRV-Headers.git" ${SPIRV_Headers_REV})

Expand Down
16 changes: 13 additions & 3 deletions External/SPIRV-Tools.cmake
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

set(SPIRV_Tools_REV "c341f7a6cd441d05ca1347ee39f2f03f32225c59")
set(SPIRV_Tools_REV "1589720e1065bd163fb8e812f268413b13755f7c")

UpdateExternalLib("SPIRV-Tools" "https://github.com/KhronosGroup/SPIRV-Tools.git" ${SPIRV_Tools_REV})

set(SPIRV_SKIP_EXECUTABLES ON CACHE BOOL "" FORCE)
add_subdirectory(SPIRV-Tools EXCLUDE_FROM_ALL)

if(MSVC)
target_compile_options(SPIRV-Tools-static
PRIVATE
/wd4819
)
endif()

foreach(target
"core_tables" "enum_string_mapping" "extinst_tables"
"spirv-tools-pkg-config" "spirv-tools-shared-pkg-config"
"spirv-tools-build-version" "spirv-tools-header-DebugInfo"
"SPIRV-Tools-link" "SPIRV-Tools-shared"
"spirv-tools-header-OpenCLDebugInfo100" "spirv-tools-vimsyntax" "spv-tools-cldi100" "spv-tools-clspvreflection" "spv-tools-debuginfo" "spv-tools-spv-amd-gs"
"spv-tools-spv-amd-sb" "spv-tools-spv-amd-sevp" "spv-tools-spv-amd-stm")
"spirv-tools-header-OpenCLDebugInfo100" "spirv-tools-header-NonSemanticShaderDebugInfo100"
"spirv-tools-vimsyntax" "spv-tools-cldi100" "spv-tools-shdi100" "spv-tools-clspvreflection"
"spv-tools-debuginfo" "spv-tools-spv-amd-gs" "spv-tools-spv-amd-sb" "spv-tools-spv-amd-sevp"
"spv-tools-spv-amd-stm")
get_target_property(vsFolder ${target} FOLDER)
if(NOT vsFolder)
set(vsFolder "")
Expand Down
10 changes: 8 additions & 2 deletions Source/Tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@

set(EXE_NAME ShaderConductorTest)

set(HEADER_FILES
Common.hpp
)

set(SOURCE_FILES
ShaderConductorTest.cpp
Common.cpp
CrossCompileTest.cpp
)

set(DATA_INC_FILES
Expand Down Expand Up @@ -38,11 +43,12 @@ set_source_files_properties(${DATA_FILES}
PROPERTIES VS_TOOL_OVERRIDE "None"
)

source_group("Header Files" FILES ${HEADER_FILES})
source_group("Source Files" FILES ${SOURCE_FILES})
source_group("Data Files\\Input" FILES ${DATA_FILES})
source_group("Data Files\\Input\\Inc" FILES ${DATA_INC_FILES})

add_executable(${EXE_NAME} ${SOURCE_FILES} ${DATA_FILES} ${DATA_INC_FILES})
add_executable(${EXE_NAME} ${HEADER_FILES} ${SOURCE_FILES} ${DATA_FILES} ${DATA_INC_FILES})

target_compile_definitions(${EXE_NAME}
PRIVATE
Expand Down
88 changes: 88 additions & 0 deletions Source/Tests/Common.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* ShaderConductor
*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the "Software"), to deal in the Software
* without restriction, including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
* to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/

#include "Common.hpp"

#include <gtest/gtest.h>

#include <fstream>
#include <string>
#include <vector>

namespace ShaderConductor
{
std::vector<uint8_t> LoadFile(const std::string& name, bool isText)
{
std::vector<uint8_t> ret;
std::ios_base::openmode mode = std::ios_base::in;
if (!isText)
{
mode |= std::ios_base::binary;
}
std::ifstream file(name, mode);
if (file)
{
file.seekg(0, std::ios::end);
ret.resize(static_cast<size_t>(file.tellg()));
file.seekg(0, std::ios::beg);
file.read(reinterpret_cast<char*>(ret.data()), ret.size());
ret.resize(static_cast<size_t>(file.gcount()));
}
return ret;
}

void CompareWithExpected(const std::vector<uint8_t>& actual, bool isText, const std::string& compareName)
{
std::vector<uint8_t> expected = LoadFile(TEST_DATA_DIR "Expected/" + compareName, isText);
if (expected != actual)
{
if (!actual.empty())
{
std::ios_base::openmode mode = std::ios_base::out;
if (!isText)
{
mode |= std::ios_base::binary;
}
std::ofstream actualFile(TEST_DATA_DIR "Result/" + compareName, mode);
actualFile.write(reinterpret_cast<const char*>(actual.data()), actual.size());
}
}

EXPECT_EQ(std::string(expected.begin(), expected.end()), std::string(actual.begin(), actual.end()));
}
} // namespace ShaderConductor

int main(int argc, char** argv)
{
testing::InitGoogleTest(&argc, argv);

int retVal = RUN_ALL_TESTS();
if (retVal != 0)
{
getchar();
}

return retVal;
}
40 changes: 40 additions & 0 deletions Source/Tests/Common.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* ShaderConductor
*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the "Software"), to deal in the Software
* without restriction, including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
* to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/

#ifndef SHADER_CONDUCTOR_TEST_COMMON_HPP
#define SHADER_CONDUCTOR_TEST_COMMON_HPP

#pragma once

#include <string>
#include <vector>

namespace ShaderConductor
{
std::vector<uint8_t> LoadFile(const std::string& name, bool isText);
void CompareWithExpected(const std::vector<uint8_t>& actual, bool isText, const std::string& compareName);
} // namespace ShaderConductor

#endif
Loading