GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 95.4% 62 / 0 / 65
Functions: 100.0% 7 / 0 / 7
Branches: 84.3% 59 / 0 / 70

src/energyplus/ErrorFile.cpp
Line Branch Exec Source
1 /***********************************************************************************************************************
2 * OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC.
3 * See also https://openstudio.net/license
4 ***********************************************************************************************************************/
5
6 #include "ErrorFile.hpp"
7
8 #include <boost/regex.hpp>
9 #include <boost/algorithm/string.hpp>
10
11 namespace openstudio {
12 namespace energyplus {
13
14 /// constructor
15 16 ErrorFile::ErrorFile(const openstudio::path& errPath) : m_completed(false), m_completedSuccessfully(false) {
16
1/1
✓ Branch 1 taken 16 times.
16 openstudio::filesystem::ifstream ifs(errPath);
17
1/1
✓ Branch 1 taken 16 times.
16 parse(ifs);
18
1/1
✓ Branch 1 taken 16 times.
16 ifs.close();
19 16 }
20
21 /// get warnings
22 10 std::vector<std::string> ErrorFile::warnings() const {
23 10 return m_warnings;
24 }
25
26 /// get severe errors
27 8 std::vector<std::string> ErrorFile::severeErrors() const {
28 8 return m_severeErrors;
29 }
30
31 /// get fatal errors
32 7 std::vector<std::string> ErrorFile::fatalErrors() const {
33 7 return m_fatalErrors;
34 }
35
36 /// did EnergyPlus complete or crash
37 5 bool ErrorFile::completed() const {
38 5 return m_completed;
39 }
40
41 /// completed successfully
42 27 bool ErrorFile::completedSuccessfully() const {
43 27 return m_completedSuccessfully;
44 }
45
46 16 void ErrorFile::parse(openstudio::filesystem::ifstream& is) {
47 16 std::string line;
48
49 // matches[1], warning/error type
50 // matches[2], rest of line
51
1/1
✓ Branch 1 taken 16 times.
16 boost::regex warningOrError(R"(^\s*\**\s+\*\*\s*([[:alpha:]]+)\s*\*\*(.*)$)");
52
53 // matches[1], rest of line
54
1/1
✓ Branch 1 taken 16 times.
16 boost::regex warningOrErrorContinue(R"(^\s*\**\s+\*\*\s*~~~\s*\*\*(.*)$)");
55
56 // completed successfully
57
1/1
✓ Branch 1 taken 16 times.
16 boost::regex completedSuccessful(R"(^\s*\*+ EnergyPlus Completed Successfully.*)");
58
59 // ground temp completed successfully
60
1/1
✓ Branch 1 taken 16 times.
16 boost::regex groundTempCompletedSuccessful(R"(^\s*\*+ GroundTempCalc\S* Completed Successfully.*)");
61
62 // completed unsuccessfully
63
1/1
✓ Branch 1 taken 16 times.
16 boost::regex completedUnsuccessful(R"(^\s*\*+ EnergyPlus Terminated.*)");
64
65 // repeat count
66
67 // read the file line by line using regexes
68 16 bool alreadyGotLine = false;
69
70
8/8
✓ Branch 0 taken 489 times.
✓ Branch 1 taken 536 times.
✓ Branch 3 taken 489 times.
✓ Branch 6 taken 489 times.
✓ Branch 8 taken 488 times.
✓ Branch 9 taken 1 time.
✓ Branch 10 taken 1024 times.
✓ Branch 11 taken 1 time.
1025 while (alreadyGotLine || std::getline(is, line)) {
71
72 1024 alreadyGotLine = false;
73
1/1
✓ Branch 1 taken 1024 times.
1024 boost::smatch matches;
74
75 // LOG(Trace, "Parsing ErrorFile Line '" << line << "'");
76
77 // parse the file
78
3/3
✓ Branch 1 taken 1024 times.
✓ Branch 3 taken 537 times.
✓ Branch 4 taken 487 times.
1024 if (boost::regex_search(line, matches, warningOrError)) {
79
80
3/3
✓ Branch 1 taken 537 times.
✓ Branch 4 taken 537 times.
✓ Branch 7 taken 537 times.
537 std::string warningOrErrorType = std::string(matches[1].first, matches[1].second);
81
1/1
✓ Branch 2 taken 537 times.
537 boost::trim(warningOrErrorType);
82
3/3
✓ Branch 1 taken 537 times.
✓ Branch 4 taken 537 times.
✓ Branch 7 taken 537 times.
537 std::string warningOrErrorString = std::string(matches[2].first, matches[2].second);
83
1/1
✓ Branch 2 taken 537 times.
537 boost::trim(warningOrErrorString);
84
85 // read the rest of the multi line warning or error
86 while (true) {
87 // std::streampos pos = is.tellg();
88
4/4
✓ Branch 1 taken 1376 times.
✓ Branch 4 taken 1376 times.
✓ Branch 6 taken 1 time.
✓ Branch 7 taken 1375 times.
1376 if (!std::getline(is, line)) {
89 1 break;
90 }
91
3/3
✓ Branch 1 taken 1375 times.
✓ Branch 3 taken 839 times.
✓ Branch 4 taken 536 times.
1375 if (boost::regex_search(line, matches, warningOrErrorContinue)) {
92
3/3
✓ Branch 1 taken 839 times.
✓ Branch 4 taken 839 times.
✓ Branch 7 taken 839 times.
839 std::string temp = std::string(matches[1].first, matches[1].second);
93
1/1
✓ Branch 2 taken 839 times.
839 boost::trim_right(temp);
94
2/2
✓ Branch 1 taken 839 times.
✓ Branch 4 taken 839 times.
839 warningOrErrorString += "\n" + temp;
95 839 } else {
96 // unget the line
97 // is.seekg(pos);
98 // Instead of rewind then reread (which fails on Windows if you have LF line endings)
99 // We just use this bool to avoid having to re-read the line.
100 536 alreadyGotLine = true;
101 536 break;
102 }
103 839 }
104
105 // LOG(Trace, "Error parsed: " << warningOrErrorString);
106
107 // correctly sort warnings and errors
108 try {
109
1/1
✓ Branch 1 taken 537 times.
537 ErrorLevel level(warningOrErrorType);
110
111
4/5
✓ Branch 1 taken 537 times.
✓ Branch 3 taken 501 times.
✓ Branch 4 taken 34 times.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
537 switch (level.value()) {
112 501 case ErrorLevel::Warning:
113
1/1
✓ Branch 1 taken 501 times.
501 m_warnings.push_back(warningOrErrorString);
114 501 break;
115 34 case ErrorLevel::Severe:
116
1/1
✓ Branch 1 taken 34 times.
34 m_severeErrors.push_back(warningOrErrorString);
117 34 break;
118 2 case ErrorLevel::Fatal:
119
1/1
✓ Branch 1 taken 2 times.
2 m_fatalErrors.push_back(warningOrErrorString);
120 2 break;
121 }
122
123 ✗ } catch (...) {
124 ✗ LOG(Error, "Unknown warning or error level '" << warningOrErrorType << "' for line '" << line << "'");
125 ✗ }
126
127
7/8
✓ Branch 3 taken 487 times.
✓ Branch 5 taken 474 times.
✓ Branch 6 taken 13 times.
✓ Branch 8 taken 474 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 474 times.
✓ Branch 12 taken 13 times.
✓ Branch 13 taken 474 times.
1024 } else if (boost::regex_match(line, completedSuccessful) || boost::regex_match(line, groundTempCompletedSuccessful)) {
128 13 m_completed = true;
129 13 m_completedSuccessfully = true;
130 13 break;
131
3/3
✓ Branch 1 taken 474 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 472 times.
474 } else if (boost::regex_match(line, completedUnsuccessful)) {
132 2 m_completed = true;
133 2 m_completedSuccessfully = false;
134 2 break;
135 }
136 1024 }
137 16 }
138
139 } // namespace energyplus
140 } // namespace openstudio
141