summaryrefslogtreecommitdiff
path: root/render-test/parser.cpp
diff options
context:
space:
mode:
authorMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2019-08-26 18:30:22 +0300
committerMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2019-08-27 12:34:09 +0300
commit1b020eeb1195a7afcac35c263220cd3568a4bc69 (patch)
tree910a01e97c802d488f0706b988336a09877e6e4a /render-test/parser.cpp
parentd0a84cb7d9866d4d46141ef2735697de3302d50b (diff)
downloadqtlocation-mapboxgl-1b020eeb1195a7afcac35c263220cd3568a4bc69.tar.gz
[test runner] Test metrics reports. Check metrics results.
Diffstat (limited to 'render-test/parser.cpp')
-rw-r--r--render-test/parser.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/render-test/parser.cpp b/render-test/parser.cpp
index 49f084465c..581529a745 100644
--- a/render-test/parser.cpp
+++ b/render-test/parser.cpp
@@ -187,6 +187,29 @@ std::string serializeJsonValue(const mbgl::JSValue& value) {
return buffer.GetString();
}
+std::string serializeMetrics(const TestMetrics& metrics) {
+ rapidjson::StringBuffer s;
+ rapidjson::Writer<rapidjson::StringBuffer> writer(s);
+
+ writer.StartObject();
+ // Start memory section.
+ writer.Key("memory");
+ writer.StartArray();
+ for (const auto& memoryProbe : metrics.memory) {
+ assert(!memoryProbe.first.empty());
+ writer.StartArray();
+ writer.String(memoryProbe.first.c_str());
+ writer.Uint64(memoryProbe.second.size);
+ writer.Uint64(memoryProbe.second.allocations);
+ writer.EndArray();
+ }
+ // End memory section.
+ writer.EndArray();
+ writer.EndObject();
+
+ return s.GetString();
+}
+
std::vector<std::string> readExpectedEntries(const mbgl::filesystem::path& base) {
static const std::regex regex(".*expected.*.png");
@@ -290,6 +313,36 @@ std::vector<std::pair<std::string, std::string>> parseIgnores() {
return ignores;
}
+TestMetrics readExpectedMetrics(const mbgl::filesystem::path& path) {
+ TestMetrics result;
+
+ auto maybeJson = readJson(path.string());
+ if (!maybeJson.is<mbgl::JSDocument>()) { // NOLINT
+ return result;
+ }
+
+ const auto& document = maybeJson.get<mbgl::JSDocument>();
+ if (document.HasMember("memory")) {
+ const mbgl::JSValue& memoryValue = document["memory"];
+ assert(memoryValue.IsArray());
+ for (auto& probeValue : memoryValue.GetArray()) {
+ assert(probeValue.IsArray());
+ assert(probeValue.Size() >= 3u);
+ assert(probeValue[0].IsString());
+ assert(probeValue[1].IsNumber());
+ assert(probeValue[2].IsNumber());
+
+ const std::string mark { probeValue[0].GetString(), probeValue[0].GetStringLength() };
+ assert(!mark.empty());
+ result.memory.emplace(std::piecewise_construct,
+ std::forward_as_tuple(std::move(mark)),
+ std::forward_as_tuple(probeValue[1].GetUint64(), probeValue[2].GetUint64()));
+ }
+ }
+
+ return result;
+}
+
TestMetadata parseTestMetadata(const TestPaths& paths) {
TestMetadata metadata;
metadata.paths = paths;