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 SkAutoMutexAcquire lock(gFailureLock); |
| 65 for (int i = 0; i < gFailures.count(); i++) { |
| 66 Json::Value result; |
| 67 result["file_name"] = gFailures[i].fileName; |
| 68 result["line_no"] = gFailures[i].lineNo; |
| 69 result["condition"] = gFailures[i].condition; |
| 70 result["message"] = gFailures[i].message.c_str(); |
| 71 |
| 72 root["test_results"]["failures"].append(result); |
| 73 } |
| 74 } |
| 75 |
55 SkString path = SkOSPath::Join(FLAGS_writePath[0], "dm.json"); | 76 SkString path = SkOSPath::Join(FLAGS_writePath[0], "dm.json"); |
56 SkFILEWStream stream(path.c_str()); | 77 SkFILEWStream stream(path.c_str()); |
57 stream.writeText(Json::StyledWriter().write(root).c_str()); | 78 stream.writeText(Json::StyledWriter().write(root).c_str()); |
58 stream.flush(); | 79 stream.flush(); |
59 } | 80 } |
60 | 81 |
61 } // namespace DM | 82 } // namespace DM |
OLD | NEW |