OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "DMJsonWriter.h" | 8 #include "DMJsonWriter.h" |
9 | 9 |
10 #include "SkCommonFlags.h" | 10 #include "SkCommonFlags.h" |
11 #include "SkJSONCPP.h" | 11 #include "SkJSONCPP.h" |
12 #include "SkOSFile.h" | 12 #include "SkOSFile.h" |
13 #include "SkStream.h" | 13 #include "SkStream.h" |
14 #include "SkTArray.h" | 14 #include "SkTArray.h" |
15 #include "SkThread.h" | 15 #include "SkThread.h" |
16 | 16 |
17 namespace DM { | 17 namespace DM { |
18 | 18 |
19 SkTArray<JsonWriter::BitmapResult> gBitmapResults; | 19 SkTArray<JsonWriter::BitmapResult> gBitmapResults; |
20 SK_DECLARE_STATIC_MUTEX(gBitmapResultLock); | 20 SK_DECLARE_STATIC_MUTEX(gBitmapResultLock); |
21 | 21 |
22 void JsonWriter::AddBitmapResult(const BitmapResult& result) { | 22 void JsonWriter::AddBitmapResult(const BitmapResult& result) { |
23 SkAutoMutexAcquire lock(&gBitmapResultLock); | 23 SkAutoMutexAcquire lock(&gBitmapResultLock); |
24 gBitmapResults.push_back(result); | 24 gBitmapResults.push_back(result); |
25 } | 25 } |
26 | 26 |
27 SkTArray<skiatest::Failure> gFailures; | |
28 SK_DECLARE_STATIC_MUTEX(gFailureLock); | |
29 | |
30 void JsonWriter::AddTestFailure(const skiatest::Failure& failure) { | |
31 SkAutoMutexAcquire lock(gFailureLock); | |
32 gFailures.push_back(failure); | |
33 } | |
34 | |
27 void JsonWriter::DumpJson() { | 35 void JsonWriter::DumpJson() { |
28 if (FLAGS_writePath.isEmpty()) { | 36 if (FLAGS_writePath.isEmpty()) { |
29 return; | 37 return; |
30 } | 38 } |
31 | 39 |
32 Json::Value root; | 40 Json::Value root; |
33 | 41 |
34 for (int i = 1; i < FLAGS_properties.count(); i += 2) { | 42 for (int i = 1; i < FLAGS_properties.count(); i += 2) { |
35 root[FLAGS_properties[i-1]] = FLAGS_properties[i]; | 43 root[FLAGS_properties[i-1]] = FLAGS_properties[i]; |
36 } | 44 } |
37 for (int i = 1; i < FLAGS_key.count(); i += 2) { | 45 for (int i = 1; i < FLAGS_key.count(); i += 2) { |
38 root["key"][FLAGS_key[i-1]] = FLAGS_key[i]; | 46 root["key"][FLAGS_key[i-1]] = FLAGS_key[i]; |
39 } | 47 } |
40 | 48 |
41 { | 49 { |
42 SkAutoMutexAcquire lock(&gBitmapResultLock); | 50 SkAutoMutexAcquire lock(&gBitmapResultLock); |
43 for (int i = 0; i < gBitmapResults.count(); i++) { | 51 for (int i = 0; i < gBitmapResults.count(); i++) { |
44 Json::Value result; | 52 Json::Value result; |
45 result["key"]["name"] = gBitmapResults[i].name.c_str(); | 53 result["key"]["name"] = gBitmapResults[i].name.c_str(); |
46 result["key"]["config"] = gBitmapResults[i].config.c_str(); | 54 result["key"]["config"] = gBitmapResults[i].config.c_str(); |
47 result["key"]["mode"] = gBitmapResults[i].mode.c_str(); | 55 result["key"]["mode"] = gBitmapResults[i].mode.c_str(); |
48 result["options"]["source_type"] = gBitmapResults[i].sourceType.c_st r(); | 56 result["options"]["source_type"] = gBitmapResults[i].sourceType.c_st r(); |
49 result["md5"] = gBitmapResults[i].md5.c_str(); | 57 result["md5"] = gBitmapResults[i].md5.c_str(); |
50 | 58 |
51 root["results"].append(result); | 59 root["results"].append(result); |
52 } | 60 } |
53 } | 61 } |
54 | 62 |
63 { | |
64 const char* test_results = "test_results"; | |
scroggo
2014/11/05 20:40:17
This block writes out the test results in the form
mtklein
2014/11/06 15:24:05
It's probably OK to just write "test_results" wher
mtklein
2014/11/06 15:24:05
You're adding this, so you tell us what's a good f
scroggo
2014/11/06 16:52:32
I was being cautious since I used it twice. I've r
| |
65 SkAutoMutexAcquire lock(gFailureLock); | |
66 root[test_results]["num_failures"] = gFailures.count(); | |
mtklein
2014/11/06 15:24:05
Isn't this redundant? It's sort of clear from the
scroggo
2014/11/06 16:52:32
It is redundant, but I thought maybe it's easier t
| |
67 for (int i = 0; i < gFailures.count(); i++) { | |
68 Json::Value result; | |
69 result["file_name"] = gFailures[i].fileName.c_str(); | |
70 result["line_no"] = gFailures[i].lineNo; | |
71 result["condition"] = gFailures[i].condition.c_str(); | |
72 result["message"] = gFailures[i].message.c_str(); | |
73 | |
74 root[test_results]["failures"].append(result); | |
75 } | |
76 } | |
77 | |
55 SkString path = SkOSPath::Join(FLAGS_writePath[0], "dm.json"); | 78 SkString path = SkOSPath::Join(FLAGS_writePath[0], "dm.json"); |
56 SkFILEWStream stream(path.c_str()); | 79 SkFILEWStream stream(path.c_str()); |
57 stream.writeText(Json::StyledWriter().write(root).c_str()); | 80 stream.writeText(Json::StyledWriter().write(root).c_str()); |
58 stream.flush(); | 81 stream.flush(); |
59 } | 82 } |
60 | 83 |
61 } // namespace DM | 84 } // namespace DM |
OLD | NEW |