yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
ba8132345
master
1// test-context.h 2 3#ifndef TEST_CONTEXT_H_INCLUDED 4#define TEST_CONTEXT_H_INCLUDED 5 6#include "../../source/compiler-core/slang-downstream-compiler-util.h" 7#include "../../source/compiler-core/slang-downstream-compiler.h" 8#include "../../source/compiler-core/slang-json-rpc-connection.h" 9#include "../../source/core/slang-dictionary.h" 10#include "../../source/core/slang-platform.h" 11#include "../../source/core/slang-render-api-util.h" 12#include "../../source/core/slang-std-writers.h" 13#include "../../source/core/slang-string-util.h" 14#include "../../source/core/slang-test-tool-util.h" 15#include "filecheck.h" 16#include "options.h" 17#include "slang-com-ptr.h" 18 19#include <mutex> 20 21typedef uint32_t PassThroughFlags ; 22struct PassThroughFlag 23{ 24enum Enum :PassThroughFlags 25 { 26Dxc = 1 <<int (SLANG_PASS_THROUGH_DXC ), 27Fxc = 1 <<int (SLANG_PASS_THROUGH_FXC ), 28Glslang = 1 <<int (SLANG_PASS_THROUGH_GLSLANG ), 29VisualStudio = 1 <<int (SLANG_PASS_THROUGH_VISUAL_STUDIO ), 30GCC = 1 <<int (SLANG_PASS_THROUGH_GCC ), 31Clang = 1 <<int (SLANG_PASS_THROUGH_CLANG ), 32Generic_C_CPP = 1 <<int (SLANG_PASS_THROUGH_GENERIC_C_CPP ), 33NVRTC = 1 <<int (SLANG_PASS_THROUGH_NVRTC ), 34LLVM = 1 <<int (SLANG_PASS_THROUGH_LLVM ), 35Metal = 1 <<int (SLANG_PASS_THROUGH_METAL ), 36Tint = 1 <<int (SLANG_PASS_THROUGH_TINT ), 37 }; 38}; 39 40/// Structure that describes requirements needs to run - such as rendering APIs or 41/// back-end availability 42struct TestRequirements 43{ 44 45TestRequirements & addUsedRenderApi (Slang ::RenderApiType type ) 46 { 47using namespace Slang ; 48if (type != RenderApiType ::Unknown ) 49 { 50usedRenderApiFlags |=RenderApiFlags (1 ) <<int (type ); 51 } 52return * this ; 53 } 54TestRequirements & addUsedBackEnd (SlangPassThrough type ) 55 { 56if (type != SLANG_PASS_THROUGH_NONE ) 57 { 58usedBackendFlags |=PassThroughFlags (1 ) <<int (type ); 59 } 60return * this ; 61 } 62TestRequirements & addUsedBackends (PassThroughFlags flags ) 63 { 64usedBackendFlags |=flags ; 65return * this ; 66 } 67TestRequirements & addUsedRenderApis (Slang ::RenderApiFlags flags ) 68 { 69usedRenderApiFlags |=flags ; 70return * this ; 71 } 72/// True if has this render api as used 73bool isUsed (Slang ::RenderApiType apiType )const 74 { 75return (apiType != Slang ::RenderApiType ::Unknown )&& 76 ((usedRenderApiFlags & (Slang ::RenderApiFlags (1 ) <<int (apiType )))!= 0 ); 77 } 78 79Slang ::RenderApiType explicitRenderApi = 80Slang ::RenderApiType ::Unknown ;///< The render api explicitly specified 81PassThroughFlags usedBackendFlags = 0 ;///< Used backends 82Slang ::RenderApiFlags usedRenderApiFlags = 0 ;///< Used render api flags (some might be implied) 83}; 84 85struct FileTestInfo :public Slang ::RefObject 86{ 87}; 88 89class TestContext 90{ 91public : 92typedef Slang ::TestToolUtil ::InnerMainFunc InnerMainFunc ; 93typedef void (* CleanDeviceCacheFunc )(); 94 95/// Get the slang session 96SlangSession * getSession ()const {return m_session ; } 97 98SlangResult init (const char * exePath ); 99 100/// Get the inner main function (from shared library) 101InnerMainFunc getInnerMainFunc (const Slang ::String & dirPath ,const Slang ::String & name ); 102/// Set the function for the shared library 103void setInnerMainFunc (const Slang ::String & name ,InnerMainFunc func ); 104 105/// Get the device cache cleanup function (from shared library) 106CleanDeviceCacheFunc getCleanDeviceCacheFunc (const Slang ::String & name ); 107 108void setTestRequirements (TestRequirements * req ); 109 110TestRequirements * getTestRequirements ()const ; 111 112/// If true tests aren't being run just the information on testing is being accumulated 113bool isCollectingRequirements ()const {return getTestRequirements ()!= nullptr ; } 114/// If set, then tests are executed 115bool isExecuting ()const {return getTestRequirements ()== nullptr ; } 116 117/// True if a render API filter is enabled 118bool isRenderApiFilterEnabled ()const 119 { 120return options .enabledApis != Slang ::RenderApiFlag ::AllOf && options .enabledApis != 0 ; 121 } 122 123/// True if a test with the requiredFlags can in principal run (it may not be possible if the 124/// API is not available though) 125bool canRunTestWithRenderApiFlags (Slang ::RenderApiFlags requiredFlags ); 126 127/// True if can run unit tests 128bool canRunUnitTests ()const {return options .apiOnly == false; } 129 130/// Given a spawn type, return the final spawn type. 131/// In particular we want 'Default' spawn type to vary by the environment (for example running 132/// on test server on CI) 133SpawnType getFinalSpawnType (SpawnType spawnType ); 134 135SpawnType getFinalSpawnType (); 136 137/// Get compiler set 138Slang ::DownstreamCompilerSet * getCompilerSet (); 139Slang ::IDownstreamCompiler * getDefaultCompiler (SlangSourceLanguage sourceLanguage ); 140 141Slang ::JSONRPCConnection * getOrCreateJSONRPCConnection (); 142void destroyRPCConnection (); 143 144/// Ctor 145TestContext (); 146/// Dtor 147 ~TestContext (); 148 149Options options ; 150TestCategorySet categorySet ; 151 152/// If set then tests are not run, but their requirements are set 153 154PassThroughFlags availableBackendFlags = 0 ; 155Slang ::RenderApiFlags availableRenderApiFlags = 0 ; 156bool isAvailableRenderApiFlagsValid = false; 157 158Slang ::RefPtr < Slang ::DownstreamCompilerSet > compilerSet ; 159 160Slang ::String exeDirectoryPath ; 161Slang ::String dllDirectoryPath ; 162Slang ::String exePath ; 163 164/// Timeout time for communication over connection. 165/// NOTE! If the timeout is hit, the connection will be destroyed, and then recreated. 166/// To test it, compile the core module, if it takes too much time, the core module will be 167/// repeatedly compiled and each time fail. 168/// NOTE! This timeout may be altered in the ctor for a specific target, the initializatoin 169/// value is just the default. 170/// 171/// TODO(JS): We could split the core module compilation from other actions, and have timeout 172/// specific for that. To do this we could have a 'compileCoreModule' RPC method. 173/// 174/// Current default is 60 seconds. 175Slang ::Int connectionTimeOutInMs = 60 * 1000 ; 176 177void setThreadIndex (int index ); 178void setMaxTestRunnerThreadCount (int count ); 179 180void setTestReporter (TestReporter * reporter ); 181TestReporter * getTestReporter (); 182SlangResult createLanguageServerJSONRPCConnection (Slang ::RefPtr < Slang ::JSONRPCConnection >& out ); 183 184std ::mutex mutex ; 185Slang ::RefPtr < Slang ::JSONRPCConnection > m_languageServerConnection ; 186 187bool isRetry = false; 188std ::mutex mutexFailedTests ; 189Slang ::List < Slang ::RefPtr < FileTestInfo >>failedFileTests ; 190Slang ::List < Slang ::String > failedUnitTests ; 191 192Slang ::IFileCheck * getFileCheck () {return m_fileCheck ; }; 193 194protected : 195SlangResult _createJSONRPCConnection (Slang ::RefPtr < Slang ::JSONRPCConnection >& out ); 196 197SlangResult locateFileCheck (); 198 199struct SharedLibraryTool 200 { 201Slang ::ComPtr < ISlangSharedLibrary > m_sharedLibrary ; 202InnerMainFunc m_func ; 203CleanDeviceCacheFunc m_cleanDeviceCacheFunc ; 204 }; 205 206Slang ::List < Slang ::RefPtr < Slang ::JSONRPCConnection >>m_jsonRpcConnections ; 207Slang ::List < TestReporter *> m_reporters ; 208Slang ::List < TestRequirements *> m_testRequirements = nullptr ; 209 210Slang ::ComPtr < SlangSession > m_session ; 211 212Slang ::Dictionary < Slang ::String ,SharedLibraryTool > m_sharedLibTools ; 213 214Slang ::ComPtr < ISlangSharedLibrary > m_fileCheckLibrary ; 215Slang ::ComPtr < Slang ::IFileCheck > m_fileCheck ; 216}; 217 218#endif // TEST_CONTEXT_H_INCLUDED