1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
// test-context.h
#ifndef TEST_CONTEXT_H_INCLUDED
#define TEST_CONTEXT_H_INCLUDED
#include "../../source/core/slang-string-util.h"
#include "../../source/core/slang-platform.h"
#include "../../source/core/slang-std-writers.h"
#include "../../source/core/slang-dictionary.h"
#include "../../source/core/slang-test-tool-util.h"
#include "../../source/core/slang-render-api-util.h"
#include "../../source/core/slang-cpp-compiler.h"
#include "options.h"
typedef uint32_t PassThroughFlags;
struct PassThroughFlag
{
enum Enum : PassThroughFlags
{
Dxc = 1 << int(SLANG_PASS_THROUGH_DXC),
Fxc = 1 << int(SLANG_PASS_THROUGH_FXC),
Glslang = 1 << int(SLANG_PASS_THROUGH_GLSLANG),
VisualStudio = 1 << int(SLANG_PASS_THROUGH_VISUAL_STUDIO),
GCC = 1 << int(SLANG_PASS_THROUGH_GCC),
Clang = 1 << int(SLANG_PASS_THROUGH_CLANG),
Generic_C_CPP = 1 << int(SLANG_PASS_THROUGH_GENERIC_C_CPP),
};
};
/// Structure that describes requirements needs to run - such as rendering APIs or
/// back-end availability
struct TestRequirements
{
TestRequirements& addUsedRenderApi(Slang::RenderApiType type)
{
using namespace Slang;
if (type != RenderApiType::Unknown)
{
usedRenderApiFlags |=RenderApiFlags(1) << int(type);
}
return *this;
}
TestRequirements& addUsedBackEnd(SlangPassThrough type)
{
if (type != SLANG_PASS_THROUGH_NONE)
{
usedBackendFlags |= PassThroughFlags(1) << int(type);
}
return *this;
}
TestRequirements& addUsedBackends(PassThroughFlags flags)
{
usedBackendFlags |= flags;
return *this;
}
TestRequirements& addUsedRenderApis(Slang::RenderApiFlags flags)
{
usedRenderApiFlags |= flags;
return *this;
}
/// True if has this render api as used
bool isUsed(Slang::RenderApiType apiType) const
{
return (apiType != Slang::RenderApiType::Unknown) && ((usedRenderApiFlags & (Slang::RenderApiFlags(1) << int(apiType))) != 0);
}
Slang::RenderApiType explicitRenderApi = Slang::RenderApiType::Unknown; ///< The render api explicitly specified
PassThroughFlags usedBackendFlags = 0; ///< Used backends
Slang::RenderApiFlags usedRenderApiFlags = 0; ///< Used render api flags (some might be implied)
};
class TestContext
{
public:
typedef Slang::TestToolUtil::InnerMainFunc InnerMainFunc;
/// Get the slang session
SlangSession* getSession() const { return m_session; }
SlangResult init();
/// Get the inner main function (from shared library)
InnerMainFunc getInnerMainFunc(const Slang::String& dirPath, const Slang::String& name);
/// Set the function for the shared library
void setInnerMainFunc(const Slang::String& name, InnerMainFunc func);
/// If true tests aren't being run just the information on testing is being accumulated
bool isCollectingRequirements() const { return testRequirements != nullptr; }
/// If set, then tests are executed
bool isExecuting() const { return testRequirements == nullptr; }
/// Get compiler factory
Slang::CPPCompilerSet* getCPPCompilerSet();
Slang::CPPCompiler* getDefaultCPPCompiler();
/// Ctor
TestContext();
/// Dtor
~TestContext();
Options options;
TestReporter* reporter = nullptr;
TestCategorySet categorySet;
/// If set then tests are not run, but their requirements are set
TestRequirements* testRequirements = nullptr;
PassThroughFlags availableBackendFlags = 0;
Slang::RenderApiFlags availableRenderApiFlags = 0;
bool isAvailableRenderApiFlagsValid = false;
Slang::RefPtr<Slang::CPPCompilerSet> cppCompilerSet;
protected:
struct SharedLibraryTool
{
Slang::SharedLibrary::Handle m_sharedLibrary;
InnerMainFunc m_func;
};
SlangSession* m_session;
Slang::Dictionary<Slang::String, SharedLibraryTool> m_sharedLibTools;
};
#endif // TEST_CONTEXT_H_INCLUDED
|