summaryrefslogtreecommitdiffstats
path: root/tester/covoar/ReportsText.cc
blob: 33d350941494edf8e388a749b2748fca72e411fe (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#include <stdio.h>
#include <string.h>

#include "ReportsText.h"
#include "app_common.h"
#include "CoverageRanges.h"
#include "DesiredSymbols.h"
#include "Explanations.h"
#include "ObjdumpProcessor.h"


namespace Coverage {

ReportsText::ReportsText( time_t timestamp ):
  ReportsBase( timestamp )
{
  reportExtension_m = ".txt";
}

ReportsText::~ReportsText()
{
}

void ReportsText::AnnotatedStart(
  FILE*                aFile
)
{
  fprintf( 
    aFile, 
    "========================================"
    "=======================================\n" 
  );
}
 
void ReportsText::AnnotatedEnd(
  FILE*                aFile
)
{
}

void ReportsText::PutAnnotatedLine( 
  FILE*                aFile, 
  AnnotatedLineState_t state, 
  std::string          line, 
  uint32_t             id 
)
{
  fprintf( aFile, "%s\n", line.c_str());
}

bool ReportsText::PutNoBranchInfo(
  FILE*           report
)
{
  if ( BranchInfoAvailable )
    fprintf( report, "All branch paths taken.\n" );
  else
    fprintf( report, "No branch information found.\n" );
  return true;
}


bool ReportsText::PutBranchEntry(
  FILE*   report,
  unsigned int                                     number,
  Coverage::DesiredSymbols::symbolSet_t::iterator  symbolPtr,
  Coverage::CoverageRanges::ranges_t::iterator     rangePtr
)
{
  const Coverage::Explanation* explanation;

  // Add an entry to the report
  fprintf(
    report,
    "============================================\n"
    "Symbol        : %s (0x%x)\n"
    "Line          : %s (0x%x)\n"
    "Size in Bytes : %d\n",
    symbolPtr->first.c_str(),
    symbolPtr->second.baseAddress,
    rangePtr->lowSourceLine.c_str(),
    rangePtr->lowAddress,
    rangePtr->highAddress - rangePtr->lowAddress + 1
  );

  if (rangePtr->reason ==
    Coverage::CoverageRanges::UNCOVERED_REASON_BRANCH_ALWAYS_TAKEN)
    fprintf(
      report, "Reason        : %s\n\n", "ALWAYS TAKEN"
    );
  else if (rangePtr->reason ==
    Coverage::CoverageRanges::UNCOVERED_REASON_BRANCH_NEVER_TAKEN)
    fprintf( report, "Reason        : %s\n\n", "NEVER TAKEN" );

  // See if an explanation is available
  explanation = AllExplanations->lookupExplanation( rangePtr->lowSourceLine );

  if ( !explanation ) {
    fprintf(
      report,
      "Classification: NONE\n"
      "\n"
      "Explanation:\n"
      "No Explanation\n"
    );
  } else {
    fprintf(
      report,
      "Classification: %s\n"
      "\n"
      "Explanation:\n",
      explanation->classification.c_str()
    );

    for ( unsigned int i=0 ;
          i < explanation->explanation.size();
          i++) {
      fprintf(
        report,
        "%s\n",
        explanation->explanation[i].c_str()
      );
    }
  }

  fprintf(
    report, "============================================\n"
  );

  return true;
}

void ReportsText::putCoverageNoRange(
  FILE*         report,
  FILE*         noRangeFile,
  unsigned int  number,
  std::string   symbol
)
{
      fprintf(
        report,
        "============================================\n"
        "Symbol        : %s\n\n"
        "          *** NEVER REFERENCED ***\n\n"
        "This symbol was never referenced by an analyzed executable.\n"
        "Therefore there is no size or disassembly for this symbol.\n"
        "This could be due to symbol misspelling or lack of a test for\n"
        "this symbol.\n"
        "============================================\n",
        symbol.c_str()
      );
      fprintf( noRangeFile, "%s\n", symbol.c_str() );
}

bool ReportsText::PutCoverageLine(
  FILE*                                       report,
  unsigned int                                     number,
  Coverage::DesiredSymbols::symbolSet_t::iterator ditr,
  Coverage::CoverageRanges::ranges_t::iterator    ritr
)
{
  const Coverage::Explanation*   explanation;

  fprintf(
    report,
    "============================================\n"
    "Index                : %d\n"
    "Symbol               : %s (0x%x)\n"
    "Starting Line        : %s (0x%x)\n"
    "Ending Line          : %s (0x%x)\n"
    "Size in Bytes        : %d\n"
    "Size in Instructions : %d\n\n",
    ritr->id,
    ditr->first.c_str(),
    ditr->second.baseAddress,
    ritr->lowSourceLine.c_str(),
    ritr->lowAddress,
    ritr->highSourceLine.c_str(),
    ritr->highAddress,
    ritr->highAddress - ritr->lowAddress + 1,
    ritr->instructionCount
  );

  explanation = AllExplanations->lookupExplanation( ritr->lowSourceLine );

  if ( !explanation ) {
    fprintf(
      report,
      "Classification: NONE\n"
      "\n"
      "Explanation:\n"
      "No Explanation\n"
    );
  } else {
    fprintf(
      report,
      "Classification: %s\n"
      "\n"
      "Explanation:\n",
      explanation->classification.c_str()
    );

    for ( unsigned int i=0; i < explanation->explanation.size(); i++) {
      fprintf( report,"%s\n", explanation->explanation[i].c_str() );
    }
  }

  fprintf(report, "============================================\n");
  return true;
}

bool  ReportsText::PutSizeLine(
  FILE*                                      report,
  unsigned int                                     number,
  Coverage::DesiredSymbols::symbolSet_t::iterator symbol,
  Coverage::CoverageRanges::ranges_t::iterator    range
)
{
  fprintf(
    report,
    "%d\t%s\t%s\n",
    range->highAddress - range->lowAddress + 1,
    symbol->first.c_str(),
    range->lowSourceLine.c_str()
  );
  return true;
}

bool  ReportsText::PutSymbolSummaryLine(
  FILE*                                           report,
  unsigned int                                    number,
  Coverage::DesiredSymbols::symbolSet_t::iterator symbol
)
{
  float uncoveredBytes;
  float uncoveredInstructions;

  if ( symbol->second.stats.sizeInInstructions == 0 )
    uncoveredInstructions = 0;
  else
    uncoveredInstructions = (symbol->second.stats.uncoveredInstructions*100.0)/
                            symbol->second.stats.sizeInInstructions;

  if ( symbol->second.stats.sizeInBytes == 0 )
    uncoveredBytes = 0;
  else
    uncoveredBytes = (symbol->second.stats.uncoveredBytes*100.0)/
                     symbol->second.stats.sizeInBytes;

  fprintf(
    report,
    "============================================\n"
    "Symbol                            : %s\n"
    "Total Size in Bytes               : %d\n"
    "Total Size in Instructions        : %d\n"
    "Total number Branches             : %d\n"
    "Total Always Taken                : %d\n"
    "Total Never Taken                 : %d\n"
    "Percentage Uncovered Instructions : %.2f\n"
    "Percentage Uncovered Bytes        : %.2f\n",
    symbol->first.c_str(),
    symbol->second.stats.sizeInBytes,
    symbol->second.stats.sizeInInstructions,
    symbol->second.stats.branchesNotExecuted +  symbol->second.stats.branchesExecuted,
    symbol->second.stats.branchesAlwaysTaken,
    symbol->second.stats.branchesNeverTaken,
    uncoveredInstructions,
    uncoveredBytes
  );

  fprintf(report, "============================================\n");
  return true;
}

}