summaryrefslogtreecommitdiffstats
path: root/tester/covoar/ReportsBase.h
blob: 8883ccb8ef3aa0ef91864505ce6176d03c65fc5a (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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
/*! @file ReportsBase.h
 *  @brief Reports Base Class Specification
 *
 *  This file contains the specification of the Reports methods.  This
 *  collection of methods is used to generate the various reports of
 *  the analysis results.
 */

#ifndef __REPORTSBASE_H__
#define __REPORTSBASE_H__

#include <stdint.h>
#include <string>
#include <iostream>
#include <fstream>
#include <time.h>
#include "DesiredSymbols.h"
#include "Explanations.h"

namespace Coverage {

/*!
 *   This class contains the base information to create a report
 *   set.  The report set may be text based, html based or some
 *   other format to be defined at a future time.
 */
class ReportsBase {

  public:
    ReportsBase(
      time_t                  timestamp,
      const std::string&      symbolSetName,
      Coverage::Explanations& allExplanations,
      const std::string&      projectName,
      const std::string&      outputDirectory,
      const DesiredSymbols&   symbolsToAnalyze,
      bool                    branchInfoAvailable
    );
    virtual ~ReportsBase();

    /*!
     *  This method produces an index of the reports generated.
     *
     *  @param[in] fileName identifies the report file name
     */
    virtual void WriteIndex( const std::string& fileName );

    /*!
     *  This method produces an annotated assembly listing report containing
     *  the disassembly of each symbol that was not completely covered.
     *
     *  @param[in] fileName identifies the annotated report file name
     */
    void WriteAnnotatedReport( const std::string& fileName );

    /*!
     *  This method produces a report that contains information about each
     *  uncovered branch statement.
     *
     *  @param[in] fileName identifies the branch report file name
     */
    void WriteBranchReport( const std::string& fileName );

    /*!
     *  This method produces a report that contains information about each
     *  uncovered range of bytes.
     *
     *  @param[in] fileName identifies the coverage report file name
     */
    void WriteCoverageReport( const std::string& fileName );

    /*!
     *  This method produces a summary report that lists each uncovered
     *  range of bytes.
     *
     *  @param[in] fileName identifies the report file name
     */
    void WriteSizeReport( const std::string& fileName );

    /*!
     *  This method produces a summary report that lists information on
     *  each symbol which did not achieve 100% coverage
     *
     *  @param[in] fileName identifies the report file name
     *  @param[in] symbolsToAnalyze the symbols to be analyzed
     */
    void WriteSymbolSummaryReport(
      const std::string&              fileName,
      const Coverage::DesiredSymbols& symbolsToAnalyze
    );

    /*!
     *  This method produces a sumary report for the overall test run.
     */
    static void  WriteSummaryReport(
      const std::string&              fileName,
      const std::string&              symbolSetName,
      const std::string&              outputDirectory,
      const Coverage::DesiredSymbols& symbolsToAnalyze,
      bool                            branchInfoAvailable
    );

    /*!
     *  This method returns the unique extension for the Report
     *  type.  If the extension is ".txt" files will be
     *  named "annotated.txt", "branch.txt" ......
     */
    std::string ReportExtension() { return reportExtension_m; }

  protected:

    /*!
     * This type is used to track a state during the annotated output.
     */
    typedef enum {
      A_SOURCE,
      A_EXECUTED,
      A_NEVER_EXECUTED,
      A_BRANCH_TAKEN,
      A_BRANCH_NOT_TAKEN
    } AnnotatedLineState_t;

    /*!
     *  This member variable contains the extension used for all reports.
     */
    std::string reportExtension_m;

    /*!
     *  This member variable contains the name of the symbol set for the report.
     */
    std::string symbolSetName_m;

    /*!
     *  This member variable contains the timestamp for the report.
     */
    time_t timestamp_m;

    /*!
     *  This member variable contains the explanations to report on.
     */
    Coverage::Explanations& allExplanations_m;

    /*!
     *  This variable stores the name of the project.
     */
    std::string projectName_m;

    /*!
     *  This variable stores the output directory.
     */
    std::string outputDirectory_m = "";

    /*!
     * This member variable contains the symbols to be analyzed.
     */
    const Coverage::DesiredSymbols& symbolsToAnalyze_m;

    /*!
     * This member variable tells whether the branch info is available
     */
    bool branchInfoAvailable_m = false;

    /*!
     *  This method Opens a report file and verifies that it opened
     *  correctly.  Upon failure NULL is returned.
     *
     *  @param[in] fileName identifies the report file name
     *  @param[in] symbolSetName identifies the name of the report's symbol set
     *  @param[in] aFile identifies the file to open
     *  @param[in] outputDirectory identifies the directory for the output
     */
    static void OpenFile(
      const std::string& fileName,
      const std::string& symbolSetName,
      std::ofstream&     aFile,
      const std::string& outputDirectory
    );

    /*!
     *  This method opens a report file and verifies that it opened.
     *  Then appedns any necessary header information onto the file.
     *
     *  @param[in] fileName identifies the report file name
     *  @param[in] aFile identifies the file to open
     */
    virtual void OpenAnnotatedFile(
      const std::string& fileName,
      std::ofstream&     aFile
    );

    /*!
     *  This method opens a report file and verifies that it opened.
     *  Then appedns any necessary header information onto the file.
     *
     *  @param[in] fileName identifies the report file name
     *  @param[in] hasBranches indicates if there are branches to report
     *  @param[in] aFile identifies the file to open
     */
    virtual void OpenBranchFile(
      const std::string& fileName,
      bool               hasBranches,
      std::ofstream&     aFile
    );

    /*!
     *  This method opens a report file and verifies that it opened.
     *  Then appedns any necessary header information onto the file.
     *
     *  @param[in] fileName identifies the report file name
     *  @param[in] aFile identifies the file to open
     */
    virtual void OpenCoverageFile(
      const std::string& fileName,
      std::ofstream&     aFile
    );

    /*!
     *  This method opens a report file and verifies that it opened.
     *  Then appends any necessary header information onto the file.
     *
     *  @param[in] fileName identifies the report file name
     *  @param[in] aFile identifies the file to open
     */
    virtual void OpenNoRangeFile(
      const std::string& fileName,
      std::ofstream&     aFile
    );

    /*!
     *  This method opens a report file and verifies that it opened.
     *  Then appedns any necessary header information onto the file.
     *
     *  @param[in] fileName identifies the report file name
     *  @param[in] aFile identifies the file to open
     */
    virtual void OpenSizeFile(
      const std::string& fileName,
      std::ofstream&     aFile
    );

    /*!
     *  This method opens a report file and verifies that it opened.
     *  Then appedns any necessary header information onto the file.
     *
     *  @param[in] fileName identifies the report file name
     *  @param[in] aFile identifies the file to open
     */
    virtual void OpenSymbolSummaryFile(
      const std::string& fileName,
      std::ofstream&     aFile
    );

    /*!
     *  This method Closes a report file.
     *
     *  @param[in] aFile identifies the file to close
     */
    static void CloseFile( std::ofstream& aFile );

    /*!
     *  This method puts any necessary footer information into
     *  the report then closes the file.
     *
     *  @param[in] aFile identifies the file to close
     */
    virtual void CloseAnnotatedFile( std::ofstream& aFile );

    /*!
     *  This method puts any necessary footer information into
     *  the report then closes the file.
     *
     *  @param[in] aFile identifies the file to close
     *  @param[in] hasBranches indicates if there are branches to report
     */
    virtual void CloseBranchFile( std::ofstream& aFile, bool hasBranches );

    /*!
     *  This method puts any necessary footer information into
     *  the report then closes the file.
     *
     *  @param[in] aFile identifies the file to close
     */
    virtual void CloseCoverageFile( std::ofstream& aFile );

    /*!
     *  This method puts any necessary footer information into
     *  the report then closes the file.
     *
     *  @param[in] aFile identifies the file to close
     */
    void  CloseNoRangeFile( std::ofstream& aFile );

    /*!
     *  This method puts any necessary footer information into
     *  the report then closes the file.
     *
     *  @param[in] aFile identifies the file to close
     */
    virtual void CloseSizeFile( std::ofstream& aFile );

    /*!
     *  This method puts any necessary footer information into
     *  the report then closes the file.
     *
     *  @param[in] aFile identifies the file to close
     */
    virtual void CloseSymbolSummaryFile( std::ofstream& aFile );

    /*!
     *  This method puts any necessary a line of annotated
     *  data into the file.
     *
     *  @param[in] aFile identifies the report file name
     *  @param[in] state identifies the state machine state
     *  @param[in] line identifies the string to print
     *  @param[in] id identifies the branch or range id.
     */
    virtual void PutAnnotatedLine(
      std::ofstream&       aFile,
      AnnotatedLineState_t state,
      const std::string&   line,
      uint32_t             id
    )=0;

    /*!
     *  This method puts any necessary header information in
     *  front of an annotated section.
     *
     *  @param[in] aFile identifies the report file name
     */
     virtual void AnnotatedStart( std::ofstream& aFile )=0;

    /*!
     *  This method puts any necessary footer information in
     *  front of an annotated section.
     *
     *  @param[in] aFile identifies the report file name
     */
     virtual void AnnotatedEnd( std::ofstream& aFile )=0;


    /*!
     *  This method puts any necessary footer information into
     *  the report then closes the file.
     *
     *  @param[in] report identifies the report file name
     */
    virtual bool PutNoBranchInfo( std::ofstream& report ) = 0;

    /*!
     *  This method puts a branch entry into the branch report.
     *
     *  @param[in] report identifies the report file name
     *  @param[in] number identifies the line number.
     *  @param[in] symbolName is the symbol's name.
     *  @param[in] symbolInfo is the symbol's information.
     *  @param[in] range is the range information.
     */
    virtual bool PutBranchEntry(
      std::ofstream&                         report,
      unsigned int                           number,
      const std::string&                     symbolName,
      const SymbolInformation&               symbolInfo,
      const CoverageRanges::coverageRange_t& range
    )=0;

    /*!
     *  This method reports when no range is available for
     *  a symbol in the coverage report.
     *
     *  @param[in] report identifies the report file name
     *  @param[in] number identifies the line number.
     *  @param[in] symbol is a pointer to the symbol information
     */
    virtual void putCoverageNoRange(
      std::ofstream&     report,
      std::ofstream&     noRangeFile,
      unsigned int       number,
      const std::string& symbol
    )=0;

    /*!
     *  This method puts a line in the coverage report.
     *
     *  @param[in] report identifies the report file name
     *  @param[in] number identifies the line number.
     *  @param[in] symbolName is the symbol's name.
     *  @param[in] symbolInfo is the symbol's information.
     *  @param[in] range is the range information.
     */
    virtual bool PutCoverageLine(
      std::ofstream&                         report,
      unsigned int                           number,
      const std::string&                     symbolName,
      const SymbolInformation&               symbolInfo,
      const CoverageRanges::coverageRange_t& range
    )=0;

    /*!
     *  This method method puts a line into the size report.
     *
     *  @param[in] report identifies the size report file name
     *  @param[in] number identifies the line number.
     *  @param[in] symbolName is the symbol's name.
     *  @param[in] range is the range information.
     */
    virtual bool PutSizeLine(
      std::ofstream&                         report,
      unsigned int                           number,
      const std::string&                     symbolName,
      const CoverageRanges::coverageRange_t& range
    )=0;

    /*!
     *  This method method puts a line into the symbol summary report.
     *
     *  @param[in] report identifies the report file name
     *  @param[in] number identifies the line number.
     *  @param[in] symbolName is the symbol's name.
     *  @param[in] symbolInfo is the symbol's information.
     */
    virtual bool PutSymbolSummaryLine(
      std::ofstream&           report,
      unsigned int             number,
      const std::string&       symbolName,
      const SymbolInformation& symbolInfo
    )=0;
};

/*!
 *  This method iterates over all report set types and generates
 *  all reports.
 *
 *  @param[in] symbolSetName is the name of the symbol set to report on.
 *  @param[in] allExplanations is the explanations to report on.
 *  @param[in] verbose specifies whether to be verbose with output
 *  @param[in] projectName specifies the name of the project
 *  @param[in] outputDirectory specifies the directory for the output
 *  @param[in] symbolsToAnalyze the symbols to be analyzed
 *  @param[in] branchInfoAvailable tells if branch info is available
 */
void GenerateReports(
  const std::string&              symbolSetName,
  Coverage::Explanations&         allExplanations,
  bool                            verbose,
  const std::string&              projectName,
  const std::string&              outputDirectory,
  const Coverage::DesiredSymbols& symbolsToAnalyze,
  bool                            branchInfoAvailable
);

}

#endif