Add a context stack to Reporter, for better error messages
Currently, just inject the Ganesh context type when running unit tests. Obviously, we can use this to supply other contextual information around tests that do many variations of configs, formats, etc... BUG=skia: Change-Id: Iab96632a92ec632e4d132bbcc17a91a8dd251e78 Reviewed-on: https://skia-review.googlesource.com/5565 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Brian Osman <brianosman@google.com>
This commit is contained in:
parent
91db12d89c
commit
287f6512f3
31
dm/DM.cpp
31
dm/DM.cpp
@ -1410,6 +1410,36 @@ bool IsRenderingGLContextType(sk_gpu_test::GrContextFactory::ContextType type) {
|
||||
bool IsNullGLContextType(sk_gpu_test::GrContextFactory::ContextType type) {
|
||||
return type == GrContextFactory::kNullGL_ContextType;
|
||||
}
|
||||
const char* ContextTypeName(GrContextFactory::ContextType contextType) {
|
||||
switch (contextType) {
|
||||
case GrContextFactory::kGL_ContextType:
|
||||
return "OpenGL";
|
||||
case GrContextFactory::kGLES_ContextType:
|
||||
return "OpenGLES";
|
||||
case GrContextFactory::kANGLE_D3D9_ES2_ContextType:
|
||||
return "ANGLE D3D9 ES2";
|
||||
case GrContextFactory::kANGLE_D3D11_ES2_ContextType:
|
||||
return "ANGLE D3D11 ES2";
|
||||
case GrContextFactory::kANGLE_D3D11_ES3_ContextType:
|
||||
return "ANGLE D3D11 ES3";
|
||||
case GrContextFactory::kANGLE_GL_ES2_ContextType:
|
||||
return "ANGLE GL ES2";
|
||||
case GrContextFactory::kANGLE_GL_ES3_ContextType:
|
||||
return "ANGLE GL ES3";
|
||||
case GrContextFactory::kCommandBuffer_ContextType:
|
||||
return "Command Buffer";
|
||||
case GrContextFactory::kMESA_ContextType:
|
||||
return "Mesa";
|
||||
case GrContextFactory::kNullGL_ContextType:
|
||||
return "Null GL";
|
||||
case GrContextFactory::kDebugGL_ContextType:
|
||||
return "Debug GL";
|
||||
case GrContextFactory::kVulkan_ContextType:
|
||||
return "Vulkan";
|
||||
}
|
||||
SkDEBUGFAIL("Unreachable");
|
||||
return "Unknown";
|
||||
}
|
||||
#else
|
||||
bool IsGLContextType(int) { return false; }
|
||||
bool IsVulkanContextType(int) { return false; }
|
||||
@ -1435,6 +1465,7 @@ void RunWithGPUTestContexts(GrContextTestFn* test, GrContextTypeFilterFn* contex
|
||||
if (contextTypeFilter && !(*contextTypeFilter)(contextType)) {
|
||||
continue;
|
||||
}
|
||||
ReporterContext ctx(reporter, SkString(ContextTypeName(contextType)));
|
||||
if (ctxInfo.grContext()) {
|
||||
(*test)(reporter, ctxInfo);
|
||||
}
|
||||
|
39
tests/Test.h
39
tests/Test.h
@ -44,10 +44,47 @@ public:
|
||||
virtual bool allowExtendedTest() const;
|
||||
virtual bool verbose() const;
|
||||
virtual void* stats() const { return nullptr; }
|
||||
|
||||
void reportFailedWithContext(const skiatest::Failure& f) {
|
||||
SkString fullMessage = f.message;
|
||||
if (!fContextStack.empty()) {
|
||||
fullMessage.append(" [");
|
||||
for (int i = 0; i < fContextStack.count(); ++i) {
|
||||
if (i > 0) {
|
||||
fullMessage.append(", ");
|
||||
}
|
||||
fullMessage.append(fContextStack[i]);
|
||||
}
|
||||
fullMessage.append("]");
|
||||
}
|
||||
this->reportFailed(skiatest::Failure(f.fileName, f.lineNo, f.condition, fullMessage));
|
||||
}
|
||||
void push(const SkString& message) {
|
||||
fContextStack.push_back(message);
|
||||
}
|
||||
void pop() {
|
||||
fContextStack.pop_back();
|
||||
}
|
||||
|
||||
private:
|
||||
SkTArray<SkString> fContextStack;
|
||||
};
|
||||
|
||||
#define REPORT_FAILURE(reporter, cond, message) \
|
||||
reporter->reportFailed(skiatest::Failure(__FILE__, __LINE__, cond, message))
|
||||
reporter->reportFailedWithContext(skiatest::Failure(__FILE__, __LINE__, cond, message))
|
||||
|
||||
class ReporterContext : SkNoncopyable {
|
||||
public:
|
||||
ReporterContext(Reporter* reporter, const SkString& message) : fReporter(reporter) {
|
||||
fReporter->push(message);
|
||||
}
|
||||
~ReporterContext() {
|
||||
fReporter->pop();
|
||||
}
|
||||
|
||||
private:
|
||||
Reporter* fReporter;
|
||||
};
|
||||
|
||||
typedef void (*TestProc)(skiatest::Reporter*, sk_gpu_test::GrContextFactory*);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user