0ee2627026
Add skiatest::Failure to keep track of data about a test failure. Reporter::reportFailed and ::onReportFailed now take Failure as a parameter. This allows the implementation to treat the failure as it wishes. Provide a helper to format the failure the same as prior to the change. Update the macros for calling reportFailed (REPORTER_ASSERT etc) to create a Failure object. Convert a direct call to reportFailed to the macro ERRORF. Write Failures to Json. Sample output when running dm on the dummy test crrev.com/705723004: { "test_results" : { "failures" : [ { "condition" : "0 > 3", "file_name" : "../../tests/DummyTest.cpp", "line_no" : 10, "message" : "" }, { "condition" : "false", "file_name" : "../../tests/DummyTest.cpp", "line_no" : 4, "message" : "" }, { "condition" : "1 == 3", "file_name" : "../../tests/DummyTest.cpp", "line_no" : 5, "message" : "I can too count!" }, { "condition" : "", "file_name" : "../../tests/DummyTest.cpp", "line_no" : 6, "message" : "seven is 7" }, { "condition" : "1 == 3", "file_name" : "../../tests/DummyTest.cpp", "line_no" : 14, "message" : "I can too count!" } ] } } Report all of the failures from one test. Previously, if one test had multiple failures, only one was reportered. e.g: Failures: test Dummy: ../../tests/DummyTest.cpp:6 seven is 7 test Dummy2: ../../tests/DummyTest.cpp:10 0 > 3 test Dummy3: ../../tests/DummyTest.cpp:14 I can too count!: 1 == 3 3 failures. Now, we get all the messages: Failures: test Dummy: ../../tests/DummyTest.cpp:4 false ../../tests/DummyTest.cpp:5 I can too count!: 1 == 3 ../../tests/DummyTest.cpp:6 seven is 7 test Dummy2: ../../tests/DummyTest.cpp:10 0 > 3 test Dummy3: ../../tests/DummyTest.cpp:14 I can too count!: 1 == 3 3 failures. (Note that we still state "3 failures" because 3 DM::Tasks failed.) BUG=skia:3082 BUG=skia:2454 Review URL: https://codereview.chromium.org/694703005
71 lines
1.7 KiB
C++
71 lines
1.7 KiB
C++
#ifndef DMTestTask_DEFINED
|
|
#define DMTestTask_DEFINED
|
|
|
|
#include "DMReporter.h"
|
|
#include "DMJsonWriter.h"
|
|
#include "DMTask.h"
|
|
#include "DMTaskRunner.h"
|
|
#include "SkString.h"
|
|
#include "SkTemplates.h"
|
|
#include "Test.h"
|
|
|
|
// Runs a unit test.
|
|
namespace DM {
|
|
|
|
class TestReporter : public skiatest::Reporter {
|
|
public:
|
|
TestReporter() {}
|
|
|
|
const char* failure() const { return fFailure.c_str(); }
|
|
|
|
private:
|
|
virtual bool allowExtendedTest() const SK_OVERRIDE;
|
|
virtual bool verbose() const SK_OVERRIDE;
|
|
|
|
virtual void onReportFailed(const skiatest::Failure& failure) SK_OVERRIDE {
|
|
JsonWriter::AddTestFailure(failure);
|
|
|
|
SkString newFailure;
|
|
failure.getFailureString(&newFailure);
|
|
// TODO: Better to store an array of failures?
|
|
if (!fFailure.isEmpty()) {
|
|
fFailure.append("\n\t\t");
|
|
}
|
|
fFailure.append(newFailure);
|
|
}
|
|
|
|
SkString fFailure;
|
|
};
|
|
|
|
class CpuTestTask : public CpuTask {
|
|
public:
|
|
CpuTestTask(Reporter*, TaskRunner*, skiatest::TestRegistry::Factory);
|
|
|
|
virtual void draw() SK_OVERRIDE;
|
|
virtual bool shouldSkip() const SK_OVERRIDE { return false; }
|
|
virtual SkString name() const SK_OVERRIDE { return fName; }
|
|
|
|
private:
|
|
TestReporter fTestReporter;
|
|
SkAutoTDelete<skiatest::Test> fTest;
|
|
const SkString fName;
|
|
};
|
|
|
|
class GpuTestTask : public GpuTask {
|
|
public:
|
|
GpuTestTask(Reporter*, TaskRunner*, skiatest::TestRegistry::Factory);
|
|
|
|
virtual void draw(GrContextFactory*) SK_OVERRIDE;
|
|
virtual bool shouldSkip() const SK_OVERRIDE;
|
|
virtual SkString name() const SK_OVERRIDE { return fName; }
|
|
|
|
private:
|
|
TestReporter fTestReporter;
|
|
SkAutoTDelete<skiatest::Test> fTest;
|
|
const SkString fName;
|
|
};
|
|
|
|
} // namespace DM
|
|
|
|
#endif // DMTestTask_DEFINED
|