2014-11-04 15:21:10 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "DMJsonWriter.h"
|
|
|
|
|
2019-03-20 15:50:33 +00:00
|
|
|
#include "CommonFlags.h"
|
2015-04-01 20:31:34 +00:00
|
|
|
#include "ProcStats.h"
|
2019-01-25 18:02:59 +00:00
|
|
|
#include "SkData.h"
|
2019-01-25 21:34:20 +00:00
|
|
|
#include "SkJSON.h"
|
2019-01-25 15:02:27 +00:00
|
|
|
#include "SkJSONWriter.h"
|
2015-07-07 19:21:21 +00:00
|
|
|
#include "SkMutex.h"
|
2014-11-04 15:21:10 +00:00
|
|
|
#include "SkOSFile.h"
|
2016-11-07 23:05:29 +00:00
|
|
|
#include "SkOSPath.h"
|
2014-11-04 15:21:10 +00:00
|
|
|
#include "SkStream.h"
|
2019-01-25 18:02:59 +00:00
|
|
|
#include "SkTArray.h"
|
2014-11-04 15:21:10 +00:00
|
|
|
|
|
|
|
namespace DM {
|
|
|
|
|
|
|
|
SkTArray<JsonWriter::BitmapResult> gBitmapResults;
|
2016-05-05 00:12:46 +00:00
|
|
|
SK_DECLARE_STATIC_MUTEX(gBitmapResultLock);
|
2014-11-04 15:21:10 +00:00
|
|
|
|
|
|
|
void JsonWriter::AddBitmapResult(const BitmapResult& result) {
|
|
|
|
SkAutoMutexAcquire lock(&gBitmapResultLock);
|
|
|
|
gBitmapResults.push_back(result);
|
|
|
|
}
|
|
|
|
|
When running DM, write test failures to json.
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
2014-11-07 14:07:32 +00:00
|
|
|
SkTArray<skiatest::Failure> gFailures;
|
2016-05-05 00:12:46 +00:00
|
|
|
SK_DECLARE_STATIC_MUTEX(gFailureLock);
|
When running DM, write test failures to json.
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
2014-11-07 14:07:32 +00:00
|
|
|
|
|
|
|
void JsonWriter::AddTestFailure(const skiatest::Failure& failure) {
|
|
|
|
SkAutoMutexAcquire lock(gFailureLock);
|
|
|
|
gFailures.push_back(failure);
|
|
|
|
}
|
|
|
|
|
2014-11-04 15:21:10 +00:00
|
|
|
void JsonWriter::DumpJson() {
|
|
|
|
if (FLAGS_writePath.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-25 15:02:27 +00:00
|
|
|
SkString path = SkOSPath::Join(FLAGS_writePath[0], "dm.json");
|
|
|
|
sk_mkdir(FLAGS_writePath[0]);
|
|
|
|
SkFILEWStream stream(path.c_str());
|
|
|
|
SkJSONWriter writer(&stream, SkJSONWriter::Mode::kPretty);
|
|
|
|
|
|
|
|
writer.beginObject(); // root
|
2014-11-04 15:21:10 +00:00
|
|
|
|
|
|
|
for (int i = 1; i < FLAGS_properties.count(); i += 2) {
|
2019-01-25 15:02:27 +00:00
|
|
|
writer.appendString(FLAGS_properties[i-1], FLAGS_properties[i]);
|
2014-11-04 15:21:10 +00:00
|
|
|
}
|
2019-01-25 15:02:27 +00:00
|
|
|
|
|
|
|
writer.beginObject("key");
|
2014-11-04 15:21:10 +00:00
|
|
|
for (int i = 1; i < FLAGS_key.count(); i += 2) {
|
2019-01-25 15:02:27 +00:00
|
|
|
writer.appendString(FLAGS_key[i-1], FLAGS_key[i]);
|
|
|
|
}
|
|
|
|
writer.endObject();
|
|
|
|
|
|
|
|
int maxResidentSetSizeMB = sk_tools::getMaxResidentSetSizeMB();
|
|
|
|
if (maxResidentSetSizeMB != -1) {
|
|
|
|
writer.appendS32("max_rss_MB", maxResidentSetSizeMB);
|
2014-11-04 15:21:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkAutoMutexAcquire lock(&gBitmapResultLock);
|
2019-01-25 15:02:27 +00:00
|
|
|
writer.beginArray("results");
|
2014-11-04 15:21:10 +00:00
|
|
|
for (int i = 0; i < gBitmapResults.count(); i++) {
|
2019-01-25 15:02:27 +00:00
|
|
|
writer.beginObject();
|
|
|
|
|
|
|
|
writer.beginObject("key");
|
|
|
|
writer.appendString("name" , gBitmapResults[i].name.c_str());
|
|
|
|
writer.appendString("config" , gBitmapResults[i].config.c_str());
|
|
|
|
writer.appendString("source_type", gBitmapResults[i].sourceType.c_str());
|
2015-04-06 14:22:05 +00:00
|
|
|
|
|
|
|
// Source options only need to be part of the key if they exist.
|
|
|
|
// Source type by source type, we either always set options or never set options.
|
|
|
|
if (!gBitmapResults[i].sourceOptions.isEmpty()) {
|
2019-01-25 15:02:27 +00:00
|
|
|
writer.appendString("source_options", gBitmapResults[i].sourceOptions.c_str());
|
2015-04-06 14:22:05 +00:00
|
|
|
}
|
2019-01-25 15:02:27 +00:00
|
|
|
writer.endObject(); // key
|
2014-11-04 15:21:10 +00:00
|
|
|
|
2019-01-25 15:02:27 +00:00
|
|
|
writer.beginObject("options");
|
2019-02-12 18:03:54 +00:00
|
|
|
writer.appendString("ext" , gBitmapResults[i].ext.c_str());
|
|
|
|
writer.appendString("gamut", gBitmapResults[i].gamut.c_str());
|
|
|
|
writer.appendString("transfer_fn", gBitmapResults[i].transferFn.c_str());
|
2019-03-06 15:57:49 +00:00
|
|
|
writer.appendString("color_type", gBitmapResults[i].colorType.c_str());
|
|
|
|
writer.appendString("alpha_type", gBitmapResults[i].alphaType.c_str());
|
2019-03-07 20:11:16 +00:00
|
|
|
writer.appendString("color_depth", gBitmapResults[i].colorDepth.c_str());
|
2019-01-25 15:02:27 +00:00
|
|
|
writer.endObject(); // options
|
|
|
|
|
|
|
|
writer.appendString("md5", gBitmapResults[i].md5.c_str());
|
|
|
|
|
|
|
|
writer.endObject(); // 1 result
|
2014-11-04 15:21:10 +00:00
|
|
|
}
|
2019-01-25 15:02:27 +00:00
|
|
|
writer.endArray(); // results
|
2014-11-04 15:21:10 +00:00
|
|
|
}
|
|
|
|
|
When running DM, write test failures to json.
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
2014-11-07 14:07:32 +00:00
|
|
|
{
|
|
|
|
SkAutoMutexAcquire lock(gFailureLock);
|
2019-01-25 15:02:27 +00:00
|
|
|
if (gFailures.count() > 0) {
|
|
|
|
writer.beginObject("test_results");
|
|
|
|
writer.beginArray("failures");
|
|
|
|
for (int i = 0; i < gFailures.count(); i++) {
|
|
|
|
writer.beginObject();
|
|
|
|
writer.appendString("file_name", gFailures[i].fileName);
|
|
|
|
writer.appendS32 ("line_no" , gFailures[i].lineNo);
|
|
|
|
writer.appendString("condition", gFailures[i].condition);
|
|
|
|
writer.appendString("message" , gFailures[i].message.c_str());
|
|
|
|
writer.endObject(); // 1 failure
|
|
|
|
}
|
|
|
|
writer.endArray(); // failures
|
|
|
|
writer.endObject(); // test_results
|
When running DM, write test failures to json.
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
2014-11-07 14:07:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-25 15:02:27 +00:00
|
|
|
writer.endObject(); // root
|
|
|
|
writer.flush();
|
2014-11-04 15:21:10 +00:00
|
|
|
stream.flush();
|
|
|
|
}
|
|
|
|
|
2019-01-25 21:34:20 +00:00
|
|
|
using namespace skjson;
|
|
|
|
|
2019-01-25 18:02:59 +00:00
|
|
|
bool JsonWriter::ReadJson(const char* path, void(*callback)(BitmapResult)) {
|
|
|
|
sk_sp<SkData> json(SkData::MakeFromFileName(path));
|
|
|
|
if (!json) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-01-25 21:34:20 +00:00
|
|
|
DOM dom((const char*)json->data(), json->size());
|
|
|
|
const ObjectValue* root = dom.root();
|
|
|
|
if (!root) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ArrayValue* results = (*root)["results"];
|
|
|
|
if (!results) {
|
2019-01-25 18:02:59 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
BitmapResult br;
|
2019-01-25 21:34:20 +00:00
|
|
|
for (const ObjectValue* r : *results) {
|
|
|
|
const ObjectValue& key = (*r)["key"].as<ObjectValue>();
|
|
|
|
const ObjectValue& options = (*r)["options"].as<ObjectValue>();
|
|
|
|
|
|
|
|
br.name = key["name"].as<StringValue>().begin();
|
|
|
|
br.config = key["config"].as<StringValue>().begin();
|
|
|
|
br.sourceType = key["source_type"].as<StringValue>().begin();
|
|
|
|
br.ext = options["ext"].as<StringValue>().begin();
|
2019-02-12 18:03:54 +00:00
|
|
|
br.gamut = options["gamut"].as<StringValue>().begin();
|
|
|
|
br.transferFn = options["transfer_fn"].as<StringValue>().begin();
|
2019-03-06 15:57:49 +00:00
|
|
|
br.colorType = options["color_type"].as<StringValue>().begin();
|
|
|
|
br.alphaType = options["alpha_type"].as<StringValue>().begin();
|
2019-03-07 20:11:16 +00:00
|
|
|
br.colorDepth = options["color_depth"].as<StringValue>().begin();
|
2019-01-25 21:34:20 +00:00
|
|
|
br.md5 = (*r)["md5"].as<StringValue>().begin();
|
|
|
|
|
|
|
|
if (const StringValue* so = key["source_options"]) {
|
|
|
|
br.sourceOptions = so->begin();
|
2019-01-25 18:02:59 +00:00
|
|
|
}
|
|
|
|
callback(br);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-04 15:21:10 +00:00
|
|
|
} // namespace DM
|