source: rtems-tools/tester/covoar/ReportsHtml.cc @ b857151

5
Last change on this file since b857151 was b857151, checked in by Hermann Felbinger <hermann19829@…>, on 08/26/17 at 08:15:52

covoar: Fix buffer overflow and fix br tag in html report.

Co-Author: Krzysztof Miesowicz <krzysztof.miesowicz@…>

  • Property mode set to 100644
File size: 26.3 KB
Line 
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4
5#include "ReportsHtml.h"
6#include "app_common.h"
7#include "CoverageRanges.h"
8#include "DesiredSymbols.h"
9#include "ObjdumpProcessor.h"
10
11#if 0
12#define TABLE_HEADER_CLASS \
13  " table-autopage:10 table-page-number:pagenum table-page-count:pages "
14#define TABLE_FOOTER \
15   "<tfoot>\n" \
16   "<tr>\n" \
17   "<td class=\"table-page:previous\" " \
18      "style=\"cursor:pointer;\">&lt; &lt; Previous</td>\n" \
19   "<td colspan=\"4\" style=\"text-align:center;\">Page " \
20      "<span id=\"pagenum\"></span>&nbsp;of <span id=\"pages\"></span></td>\n" \
21   "<td class=\"table-page:next\" " \
22     "style=\"cursor:pointer;\">Next &gt; &gt;</td>\n" \
23   "</tr>\n" \
24   "</tfoot>\n"
25#else
26#define TABLE_HEADER_CLASS
27#define TABLE_FOOTER
28#endif
29
30namespace Coverage {
31
32  ReportsHtml::ReportsHtml( time_t timestamp ):
33    ReportsBase( timestamp )
34  {
35    reportExtension_m = ".html";
36  }
37
38  ReportsHtml::~ReportsHtml()
39  {
40  }
41
42  void ReportsHtml::WriteIndex(
43    const char* const fileName
44  )
45  {
46    #define PRINT_ITEM( _t, _n ) \
47       fprintf( \
48         aFile, \
49         "<li>%s (<a href=\"%s.html\">html</a> or "\
50         "<a href=\"%s.txt\">text</a>)</li>\n", \
51        _t, _n, _n );
52    #define PRINT_TEXT_ITEM( _t, _n ) \
53       fprintf( \
54         aFile, \
55         "<li>%s (<a href=\"%s\">text</a>)</li>\n", \
56        _t, _n );
57
58    FILE*  aFile;
59   
60    // Open the file
61    aFile = OpenFile( fileName );
62
63    fprintf(
64      aFile,
65      "<title>Index</title>\n"
66      "<div class=\"heading-title\">"
67    );
68
69    if (projectName)
70      fprintf(
71        aFile,
72         "%s<br>",
73         projectName
74      );
75
76    fprintf(
77      aFile,
78      "Coverage Analysis Reports</div>\n"
79      "<div class =\"datetime\">%s</div>\n",
80      asctime( localtime(&timestamp_m) )
81    );
82
83    fprintf( aFile, "<ul>\n" );
84
85    PRINT_TEXT_ITEM( "Summary",         "summary.txt" );
86    PRINT_ITEM( "Coverage Report",      "uncovered" );
87    PRINT_ITEM( "Branch Report",        "branch" );
88    PRINT_ITEM( "Annotated Assembly",   "annotated" );
89    PRINT_ITEM( "Symbol Summary",       "symbolSummary" );
90    PRINT_ITEM( "Size Report",          "sizes" );
91
92    PRINT_TEXT_ITEM( "Explanations Not Found", "ExplanationsNotFound.txt" );
93
94    fprintf(
95      aFile,
96      "</ul>\n"
97      "<!-- INSERT PROJECT SPECIFIC ITEMS HERE -->\n"
98      "</html>\n"
99    );
100
101    CloseFile( aFile );
102
103    #undef PRINT_ITEM
104    #undef PRINT_TEXT_ITEM
105  }
106
107  FILE* ReportsHtml::OpenFile(
108    const char* const fileName
109  )
110  {
111    FILE*  aFile;
112   
113    // Open the file
114    aFile = ReportsBase::OpenFile( fileName );
115
116    // Put Header information on the file
117    fprintf(
118      aFile,
119      "<html>\n"
120      "<meta http-equiv=\"Content-Language\" content=\"English\" >\n"
121      "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=us-ascii\" >\n"
122      "<link rel=\"stylesheet\" type=\"text/css\" href=\"covoar.css\" media=\"screen\" >\n"
123      "<script type=\"text/javascript\" src=\"table.js\"></script>\n"
124    );
125
126    return aFile;
127  }
128
129  FILE* ReportsHtml::OpenAnnotatedFile(
130    const char* const fileName
131  )
132  {
133    FILE *aFile;
134
135    // Open the file
136    aFile = OpenFile(fileName);
137
138    fprintf(
139      aFile,
140      "<title>Annotated Report</title>\n"
141      "<div class=\"heading-title\">"
142    );
143
144    if (projectName)
145      fprintf(
146        aFile,
147         "%s<br>",
148         projectName
149      );
150
151    fprintf(
152      aFile,
153      "Annotated Report</div>\n"
154      "<div class =\"datetime\">%s</div>\n"
155      "<body>\n"
156      "<pre class=\"code\">\n",
157      asctime( localtime(&timestamp_m) )
158    );
159
160    return aFile;
161  }
162
163  FILE* ReportsHtml::OpenBranchFile(
164    const char* const fileName,
165    bool              hasBranches
166  )
167  {
168    FILE *aFile;
169
170    // Open the file
171    aFile = OpenFile(fileName);
172
173    if ( hasBranches ) {
174      // Put header information into the file
175      fprintf(
176        aFile,
177        "<title>Branch Report</title\n"
178        "<div class=\"heading-title\">"
179      );
180
181      if (projectName)
182        fprintf(
183          aFile,
184          "%s<br>",
185          projectName
186        );
187
188      fprintf(
189        aFile,
190        "Branch Report</div>\n"
191        "<div class =\"datetime\">%s</div>\n"
192        "<body>\n"
193        "<table class=\"covoar table-autosort:0 table-autofilter table-stripeclass:covoar-tr-odd"
194           TABLE_HEADER_CLASS "\">\n"
195        "<thead>\n"
196        "<tr>\n"
197        "<th class=\"table-sortable:default\" align=\"left\">Symbol</th>\n"
198        "<th class=\"table-sortable:default\" align=\"left\">Line</th>\n"
199        "<th class=\"table-filterable table-sortable:default\" align=\"left\">File</th>\n"
200        "<th class=\"table-sortable:numeric\" align=\"left\">Size <br>Bytes</th>\n"
201        "<th class=\"table-sortable:default\" align=\"left\">Reason</th>\n"
202        "<th class=\"table-filterable table-sortable:default\" align=\"left\">Taken</th>\n"
203        "<th class=\"table-filterable table-sortable:default\" align=\"left\">Not Taken</th>\n"
204        "<th class=\"table-filterable table-sortable:default\" align=\"left\">Classification</th>\n"
205        "<th class=\"table-sortable:default\" align=\"left\">Explanation</th>\n"
206        "</tr>\n"
207        "</thead>\n"
208        "<tbody>\n",
209        asctime( localtime(&timestamp_m) )
210      );
211    }
212   
213    return aFile;
214  }
215
216  FILE*  ReportsHtml::OpenCoverageFile(
217    const char* const fileName
218  )
219  {
220    FILE *aFile;
221
222    // Open the file
223    aFile = OpenFile(fileName);
224
225    // Put header information into the file
226    fprintf(
227      aFile,
228        "<title>Coverage Report</title>\n"
229        "<div class=\"heading-title\">"
230    );
231
232    if (projectName)
233      fprintf(
234        aFile,
235        "%s<br>",
236        projectName
237      );
238
239    fprintf(
240      aFile,
241       "Coverage Report</div>\n"
242       "<div class =\"datetime\">%s</div>\n"
243       "<body>\n"
244       "<table class=\"covoar table-autosort:0 table-autofilter table-stripeclass:covoar-tr-odd"
245           TABLE_HEADER_CLASS "\">\n"
246      "<thead>\n"
247      "<tr>\n"
248      "<th class=\"table-sortable:default\" align=\"left\">Symbol</th>\n"
249      "<th class=\"table-sortable:default\" align=\"left\">Range</th>\n"
250      "<th class=\"table-filterable table-sortable:default\" align=\"left\">File</th>\n"
251      "<th class=\"table-sortable:numeric\" align=\"left\">Size <br>Bytes</th>\n"
252      "<th class=\"table-sortable:numeric\" align=\"left\">Size <br>Instructions</th>\n"
253      "<th class=\"table-filterable table-sortable:default\" align=\"left\">Classification</th>\n"
254      "<th class=\"table-sortable:default\" align=\"left\">Explanation</th>\n"
255      "</tr>\n"
256      "</thead>\n"
257      "<tbody>\n",
258        asctime( localtime(&timestamp_m) )
259
260     );
261
262    return aFile;
263  }
264
265  FILE* ReportsHtml::OpenNoRangeFile(
266    const char* const fileName
267  )
268  {
269    FILE *aFile;
270
271    // Open the file
272    aFile = OpenFile(fileName);
273
274    // Put header information into the file
275    fprintf(
276      aFile,
277        "<title> Report</title>\n"
278        "<div class=\"heading-title\">"
279    );
280
281    if (projectName)
282      fprintf(
283        aFile,
284        "%s<br>",
285        projectName
286      );
287
288    fprintf(
289      aFile,
290       "No Range Report</div>\n"
291       "<div class =\"datetime\">%s</div>\n"
292        "<body>\n"
293      "<table class=\"covoar table-autosort:0 table-autofilter table-stripeclass:covoar-tr-odd"
294           TABLE_HEADER_CLASS "\">\n"
295      "<thead>\n"
296      "<tr>\n"
297      "<th class=\"table-sortable:default\" align=\"left\">Symbol</th>\n"
298      "</tr>\n"
299      "</thead>\n"
300      "<tbody>\n",
301        asctime( localtime(&timestamp_m) )
302
303     );
304
305    return aFile;
306   }
307
308
309
310  FILE*  ReportsHtml::OpenSizeFile(
311    const char* const fileName
312  )
313  {
314    FILE *aFile;
315
316    // Open the file
317    aFile = OpenFile(fileName);
318
319    // Put header information into the file
320    fprintf(
321      aFile,
322      "<title>Size Report</title>\n"
323        "<div class=\"heading-title\">"
324    );
325
326    if (projectName)
327      fprintf(
328        aFile,
329        "%s<br>",
330        projectName
331      );
332
333    fprintf(
334      aFile,
335      "Size Report</div>\n"
336       "<div class =\"datetime\">%s</div>\n"
337      "<body>\n"
338      "<table class=\"covoar table-autosort:0 table-autofilter table-stripeclass:covoar-tr-odd"
339           TABLE_HEADER_CLASS "\">\n"
340      "<thead>\n"
341      "<tr>\n"
342      "<th class=\"table-sortable:numeric\" align=\"left\">Size</th>\n"
343      "<th class=\"table-sortable:default\" align=\"left\">Symbol</th>\n"
344      "<th class=\"table-sortable:default\" align=\"left\">Line</th>\n"
345      "<th class=\"table-filterable table-sortable:default\" align=\"left\">File</th>\n"
346      "</tr>\n"
347      "</thead>\n"
348      "<tbody>\n",
349        asctime( localtime(&timestamp_m) )
350
351    );
352    return aFile;
353  }
354
355  FILE*  ReportsHtml::OpenSymbolSummaryFile(
356    const char* const fileName
357  )
358  {
359    FILE *aFile;
360
361    // Open the file
362    aFile = OpenFile(fileName);
363
364    // Put header information into the file
365    fprintf(
366      aFile,
367      "<title>Symbol Summary Report</title>\n"
368      "<div class=\"heading-title\">"
369    );
370
371    if (projectName)
372      fprintf(
373        aFile,
374        "%s<br>",
375        projectName
376      );
377
378    fprintf(
379      aFile,
380      "Symbol Summary Report</div>\n"
381       "<div class =\"datetime\">%s</div>\n"
382      "<body>\n"
383      "<table class=\"covoar table-autosort:0 table-autofilter table-stripeclass:covoar-tr-odd"
384           TABLE_HEADER_CLASS "\">\n"
385      "<thead>\n"
386      "<tr>\n"
387      "<th class=\"table-sortable:default\" align=\"center\">Symbol</th>\n"
388      "<th class=\"table-sortable:numeric\" align=\"center\">Total<br>Size<br>Bytes</th>\n"
389      "<th class=\"table-sortable:numeric\" align=\"center\">Total<br>Size<br>Instr</th>\n"
390      "<th class=\"table-sortable:numeric\" align=\"center\">#<br>Ranges</th>\n"
391      "<th class=\"table-sortable:numeric\" align=\"center\">Uncovered<br>Size<br>Bytes</th>\n"
392      "<th class=\"table-sortable:numeric\" align=\"center\">Uncovered<br>Size<br>Instr</th>\n"
393      "<th class=\"table-sortable:numeric\" align=\"center\">#<br>Branches</th>\n"
394      "<th class=\"table-sortable:numeric\" align=\"center\">#<br>Always<br>Taken</th>\n"
395      "<th class=\"table-sortable:numeric\" align=\"center\">#<br>Never<br>Taken</th>\n"
396      "<th class=\"table-sortable:numeric\" align=\"center\">Percent<br>Uncovered<br>Instructions</th>\n"
397      "<th class=\"table-sortable:numeric\" align=\"center\">Percent<br>Uncovered<br>Bytes</th>\n"
398      "</tr>\n"
399      "</thead>\n"
400      "<tbody>\n",
401        asctime( localtime(&timestamp_m) )
402
403    );
404    return aFile;
405  }
406
407  void ReportsHtml::AnnotatedStart(
408    FILE*                aFile
409  )
410  {
411    fprintf(
412      aFile,
413      "<hr>\n"
414    );
415  }
416 
417  void ReportsHtml::AnnotatedEnd(
418    FILE*                aFile
419  )
420  {
421  }
422
423  void ReportsHtml::PutAnnotatedLine(
424    FILE*                aFile,
425    AnnotatedLineState_t state,
426    std::string          line,
427    uint32_t             id
428  )
429  {
430    std::string stateText;
431    char        number[10];
432
433   
434    sprintf(number,"%d", id);
435
436    // Set the stateText based upon the current state.
437    switch (state) {
438      case  A_SOURCE:
439        stateText = "</pre>\n<pre class=\"code\">\n";
440        break;
441      case  A_EXECUTED:
442        stateText = "</pre>\n<pre class=\"codeExecuted\">\n";
443        break;
444      case  A_NEVER_EXECUTED:
445        stateText = "</pre>\n";
446        stateText += "<a name=\"range";
447        stateText += number;
448        stateText += "\"></a><pre class=\"codeNotExecuted\">\n";
449        break;
450      case  A_BRANCH_TAKEN:
451        stateText = "</pre>\n";
452        stateText += "<a name=\"range";
453        stateText += number;
454        stateText += "\"></a><pre class=\"codeAlwaysTaken\">\n";
455        break;
456      case  A_BRANCH_NOT_TAKEN:
457        stateText = "</pre>\n";
458        stateText += "<a name=\"range";
459        stateText += number;
460        stateText += "\"></a><pre class=\"codeNeverTaken\">\n";
461        break;
462      default:
463        fprintf(stderr, "ERROR:  ReportsHtml::PutAnnotatedLine Unknown state\n");
464        exit( -1 );
465        break;
466    }
467
468    // If the state has not changed there is no need to change the text block
469    // format.  If it has changed close out the old format and open up the
470    // new format.
471    if ( state != lastState_m ) {
472      fprintf( aFile, "%s", stateText.c_str() );
473      lastState_m = state;
474    }
475
476    // For all the characters in the line replace html reserved special
477    // characters and output the line. Note that for a /pre block this
478    // is only a '<' symbol.
479    for (unsigned int i=0; i<line.size(); i++ ) {
480      if ( line[i] == '<' )
481        fprintf( aFile, "&lt;" );
482      else
483        fprintf( aFile, "%c", line[i] );
484    }
485    fprintf( aFile, "\n");
486  }
487
488  bool ReportsHtml::PutNoBranchInfo(
489    FILE* report
490  )
491  {
492    if ( BranchInfoAvailable )
493      fprintf( report, "All branch paths taken.\n" );
494    else
495      fprintf( report, "No branch information found.\n" );
496    return true;
497  }
498
499  bool ReportsHtml::PutBranchEntry(
500    FILE*                                            report,
501    unsigned int                                     count,
502    Coverage::DesiredSymbols::symbolSet_t::iterator  symbolPtr,
503    Coverage::CoverageRanges::ranges_t::iterator     rangePtr
504  )
505  {
506    const Coverage::Explanation* explanation;
507    std::string                  temp;
508    int                          i;
509    uint32_t                     bAddress = 0;
510    uint32_t                     lowAddress = 0;
511    Coverage::CoverageMapBase*   theCoverageMap = NULL;
512
513    // Mark the background color different for odd and even lines.
514    if ( ( count%2 ) != 0 )
515      fprintf( report, "<tr class=\"covoar-tr-odd\">\n");
516    else
517      fprintf( report, "<tr>\n");
518
519    // symbol
520    fprintf(
521      report,
522      "<td class=\"covoar-td\" align=\"center\">%s</td>\n",     
523      symbolPtr->first.c_str()
524    );
525
526    // line
527    fprintf(
528      report,
529      "<td class=\"covoar-td\" align=\"center\"><a href =\"annotated.html#range%d\">%s</td>\n",     
530      rangePtr->id,
531      rangePtr->lowSourceLine.c_str()
532    );
533
534    // File
535    i = rangePtr->lowSourceLine.find(":");
536    temp =  rangePtr->lowSourceLine.substr (0, i);
537    fprintf(
538      report,
539      "<td class=\"covoar-td\" align=\"center\">%s</td>\n",     
540      temp.c_str()
541    );
542 
543    // Size in bytes
544    fprintf(
545      report,
546      "<td class=\"covoar-td\" align=\"center\">%d</td>\n",
547      rangePtr->highAddress - rangePtr->lowAddress + 1
548    );
549
550    // Reason Branch was uncovered
551    if (rangePtr->reason ==
552      Coverage::CoverageRanges::UNCOVERED_REASON_BRANCH_ALWAYS_TAKEN)
553      fprintf(
554        report,
555        "<td class=\"covoar-td\" align=\"center\">Always Taken</td>\n"
556      );
557    else if (rangePtr->reason ==
558      Coverage::CoverageRanges::UNCOVERED_REASON_BRANCH_NEVER_TAKEN)
559      fprintf(
560        report,
561        "<td class=\"covoar-td\" align=\"center\">Never Taken</td>\n"
562      );
563
564    // Taken / Not taken counts
565    lowAddress = rangePtr->lowAddress;
566    bAddress = symbolPtr->second.baseAddress;
567    theCoverageMap = symbolPtr->second.unifiedCoverageMap;
568    fprintf(
569      report,
570      "<td class=\"covoar-td\" align=\"center\">%d</td>\n",
571      theCoverageMap->getWasTaken( lowAddress - bAddress )
572    );
573        fprintf(
574      report,
575      "<td class=\"covoar-td\" align=\"center\">%d</td>\n",
576      theCoverageMap->getWasNotTaken( lowAddress - bAddress )
577    );
578
579    // See if an explanation is available and write the Classification and
580    // the Explination Columns.
581    explanation = AllExplanations->lookupExplanation( rangePtr->lowSourceLine );
582    if ( !explanation ) {
583      // Write Classificationditr->second.baseAddress
584      fprintf(
585        report,
586        "<td class=\"covoar-td\" align=\"center\">NONE</td>\n"
587        "<td class=\"covoar-td\" align=\"center\">No Explanation</td>\n"
588      );
589    } else {
590      char explanationFile[48];
591      sprintf( explanationFile, "explanation%d.html", rangePtr->id );
592      fprintf(
593        report,
594        "<td class=\"covoar-td\" align=\"center\">%s</td>\n"
595        "<td class=\"covoar-td\" align=\"center\">"
596        "<a href=\"%s\">Explanation</a></td>\n",
597        explanation->classification.c_str(),
598        explanationFile
599      );
600      WriteExplationFile( explanationFile, explanation );
601    }
602
603    fprintf( report, "</tr>\n");
604
605    return true;
606  }
607
608  bool ReportsHtml::WriteExplationFile(
609    const char*                  fileName,
610    const Coverage::Explanation* explanation
611  )
612  {
613    FILE* report;
614
615    report = OpenFile( fileName );
616
617    for ( unsigned int i=0 ; i < explanation->explanation.size(); i++) {
618      fprintf(
619        report,
620        "%s\n",
621        explanation->explanation[i].c_str()
622      );
623    }
624    CloseFile( report );
625    return true;
626  }
627
628  void ReportsHtml::putCoverageNoRange(
629    FILE*         report,
630    FILE*         noRangeFile,
631    unsigned int  count,
632    std::string   symbol
633  )
634  {
635    Coverage::Explanation explanation;
636
637    explanation.explanation.push_back(
638      "<html><p>\n"
639      "This symbol was never referenced by an analyzed executable.  "
640      "Therefore there is no size or disassembly for this symbol.  "
641      "This could be due to symbol misspelling or lack of a test for "
642      "this symbol."
643      "</p></html>\n"
644    );
645
646    // Mark the background color different for odd and even lines.
647    if ( ( count%2 ) != 0 ){
648      fprintf( report, "<tr class=\"covoar-tr-odd\">\n");
649      fprintf( noRangeFile,  "<tr class=\"covoar-tr-odd\">\n");
650    } else {
651      fprintf( report, "<tr>\n");
652      fprintf( noRangeFile,  "<tr>\n");
653    }
654
655    // symbol
656    fprintf(
657      report,
658      "<td class=\"covoar-td\" align=\"center\">%s</td>\n",     
659      symbol.c_str()
660    );
661    fprintf(
662      noRangeFile,
663      "<td class=\"covoar-td\" align=\"center\">%s</td>\n",     
664      symbol.c_str()
665    );
666
667    // starting line
668    fprintf(
669      report,
670      "<td class=\"covoar-td\" align=\"center\">unknown</td>\n"
671     );
672     
673    // file
674    fprintf(
675      report,
676      "<td class=\"covoar-td\" align=\"center\">unknown</td>\n"
677     );
678     
679     // Size in bytes
680    fprintf(
681      report,
682      "<td class=\"covoar-td\" align=\"center\">unknown</td>\n"
683    );
684
685    // Size in instructions
686    fprintf(
687      report,
688      "<td class=\"covoar-td\" align=\"center\">unknown</td>\n"
689    );
690
691    // See if an explanation is available
692    fprintf(
693      report,
694      "<td class=\"covoar-td\" align=\"center\">Unknown</td>\n"
695      "<td class=\"covoar-td\" align=\"center\">"
696      "<a href=\"NotReferenced.html\">No data</a></td>\n"
697    );
698    WriteExplationFile( "NotReferenced.html", &explanation );
699
700    fprintf( report, "</tr>\n");
701    fprintf( noRangeFile, "</tr>\n");
702  }
703
704  bool ReportsHtml::PutCoverageLine(
705    FILE*                                            report,
706    unsigned int                                     count,
707    Coverage::DesiredSymbols::symbolSet_t::iterator  symbolPtr,
708    Coverage::CoverageRanges::ranges_t::iterator     rangePtr
709  )
710  {
711    const Coverage::Explanation*   explanation;
712    std::string                    temp;
713    int                            i;
714
715    // Mark the background color different for odd and even lines.
716    if ( ( count%2 ) != 0 )
717      fprintf( report, "<tr class=\"covoar-tr-odd\">\n");
718    else
719      fprintf( report, "<tr>\n");
720
721    // symbol
722    fprintf(
723      report,
724      "<td class=\"covoar-td\" align=\"center\">%s</td>\n",     
725      symbolPtr->first.c_str()
726    );
727
728    // Range
729    fprintf(
730      report,
731      "<td class=\"covoar-td\" align=\"center\"><a href =\"annotated.html#range%d\">%s <br>%s</td>\n",
732      rangePtr->id,   
733      rangePtr->lowSourceLine.c_str(),
734      rangePtr->highSourceLine.c_str()
735     );
736
737    // File
738    i = rangePtr->lowSourceLine.find(":");
739    temp =  rangePtr->lowSourceLine.substr (0, i);
740    fprintf(
741      report,
742      "<td class=\"covoar-td\" align=\"center\">%s</td>\n",     
743      temp.c_str()
744    );
745       
746    // Size in bytes
747    fprintf(
748      report,
749      "<td class=\"covoar-td\" align=\"center\">%d</td>\n",
750      rangePtr->highAddress - rangePtr->lowAddress + 1
751    );
752
753    // Size in instructions
754    fprintf(
755      report,
756      "<td class=\"covoar-td\" align=\"center\">%d</td>\n",
757      rangePtr->instructionCount
758    );
759
760    // See if an explanation is available
761    explanation = AllExplanations->lookupExplanation( rangePtr->lowSourceLine );
762    if ( !explanation ) {
763      fprintf(
764        report,
765        "<td class=\"covoar-td\" align=\"center\">NONE</td>\n"
766      );
767      fprintf(
768        report,
769        "<td class=\"covoar-td\" align=\"center\">No Explanation</td>\n"
770      );
771    } else {
772      char explanationFile[48];
773
774      sprintf( explanationFile, "explanation%d.html", rangePtr->id );
775      fprintf(
776        report,
777        "<td class=\"covoar-td\" align=\"center\">%s</td>\n"
778        "<td class=\"covoar-td\" align=\"center\">"
779        "<a href=\"%s\">Explanation</a></td>\n",
780        explanation->classification.c_str(),
781        explanationFile
782      );
783      WriteExplationFile( explanationFile, explanation );
784    }
785
786    fprintf( report, "</tr>\n");
787
788    return true;
789  }
790
791  bool  ReportsHtml::PutSizeLine(
792    FILE*                                           report,
793    unsigned int                                    count,
794    Coverage::DesiredSymbols::symbolSet_t::iterator symbol,
795    Coverage::CoverageRanges::ranges_t::iterator    range
796  )
797  {
798    std::string  temp;
799    int          i;
800
801    // Mark the background color different for odd and even lines.
802    if ( ( count%2 ) != 0 )
803      fprintf( report, "<tr class=\"covoar-tr-odd\">\n");
804    else
805      fprintf( report, "<tr>\n");
806
807    // size
808    fprintf(
809      report,
810      "<td class=\"covoar-td\" align=\"center\">%d</td>\n",
811      range->highAddress - range->lowAddress + 1
812    );
813
814    // symbol
815    fprintf(
816      report,
817      "<td class=\"covoar-td\" align=\"center\">%s</td>\n",     
818      symbol->first.c_str()
819    );
820
821    // line
822    fprintf(
823      report,
824      "<td class=\"covoar-td\" align=\"center\"><a href =\"annotated.html#range%d\">%s</td>\n",     
825      range->id,
826      range->lowSourceLine.c_str()
827    );
828
829    // File
830    i = range->lowSourceLine.find(":");
831    temp =  range->lowSourceLine.substr (0, i);
832    fprintf(
833      report,
834      "<td class=\"covoar-td\" align=\"center\">%s</td>\n",     
835      temp.c_str()
836    );
837   
838    fprintf( report, "</tr>\n");
839
840    return true;
841  }
842
843  bool  ReportsHtml::PutSymbolSummaryLine(
844    FILE*                                           report,
845    unsigned int                                    count,
846    Coverage::DesiredSymbols::symbolSet_t::iterator symbol
847  )
848  {
849 
850    // Mark the background color different for odd and even lines.
851    if ( ( count%2 ) != 0 )
852      fprintf( report, "<tr class=\"covoar-tr-odd\">\n");
853    else
854      fprintf( report, "<tr>\n");
855
856    // symbol
857    fprintf(
858      report,
859      "<td class=\"covoar-td\" align=\"center\">%s</td>\n",     
860      symbol->first.c_str()
861    );
862
863    // Total Size in Bytes
864    fprintf(
865      report,
866      "<td class=\"covoar-td\" align=\"center\">%d</td>\n",
867      symbol->second.stats.sizeInBytes
868    );
869
870    // Total Size in Instructions
871    fprintf(
872      report,
873      "<td class=\"covoar-td\" align=\"center\">%d</td>\n",
874      symbol->second.stats.sizeInInstructions
875    );
876
877    // Total Uncovered Ranges
878    fprintf(
879      report,
880      "<td class=\"covoar-td\" align=\"center\">%d</td>\n",     
881      symbol->second.stats.uncoveredRanges
882    );
883
884    // Uncovered Size in Bytes
885    fprintf(
886      report,
887      "<td class=\"covoar-td\" align=\"center\">%d</td>\n",
888      symbol->second.stats.uncoveredBytes
889    );
890
891    // Uncovered Size in Instructions
892    fprintf(
893      report,
894      "<td class=\"covoar-td\" align=\"center\">%d</td>\n",
895       symbol->second.stats.uncoveredInstructions
896    );
897
898    // Total number of branches
899    fprintf(
900      report,
901      "<td class=\"covoar-td\" align=\"center\">%d</td>\n",     
902      symbol->second.stats.branchesNotExecuted +  symbol->second.stats.branchesExecuted
903    );
904
905    // Total Always Taken
906    fprintf(
907      report,
908      "<td class=\"covoar-td\" align=\"center\">%d</td>\n",
909      symbol->second.stats.branchesAlwaysTaken
910    );
911
912    // Total Never Taken
913    fprintf(
914      report,
915      "<td class=\"covoar-td\" align=\"center\">%d</td>\n",
916      symbol->second.stats.branchesNeverTaken
917     );
918
919    // % Uncovered Instructions
920    if ( symbol->second.stats.sizeInInstructions == 0 )
921      fprintf(
922        report,
923        "<td class=\"covoar-td\" align=\"center\">100.00</td>\n"
924      );
925    else     
926      fprintf(
927        report,
928        "<td class=\"covoar-td\" align=\"center\">%.2f</td>\n",
929        (symbol->second.stats.uncoveredInstructions*100.0)/
930         symbol->second.stats.sizeInInstructions
931      );
932
933    // % Uncovered Bytes
934    if ( symbol->second.stats.sizeInBytes == 0 )
935      fprintf(
936        report,
937        "<td class=\"covoar-td\" align=\"center\">100.00</td>\n"
938      );
939    else     
940      fprintf(
941        report,
942        "<td class=\"covoar-td\" align=\"center\">%.2f</td>\n",
943        (symbol->second.stats.uncoveredBytes*100.0)/
944         symbol->second.stats.sizeInBytes
945      );
946
947    fprintf( report, "</tr>\n");
948    return true;
949  }
950
951  void ReportsHtml::CloseAnnotatedFile(
952    FILE*  aFile
953  )
954  {
955    fprintf(
956      aFile,
957      "</pre>\n"
958      "</body>\n"
959      "</html>"
960    );
961
962    CloseFile(aFile);
963  }
964
965  void ReportsHtml::CloseBranchFile(
966    FILE*  aFile,
967    bool   hasBranches
968  )
969  {
970    if ( hasBranches ) {
971      fprintf(
972        aFile,
973        TABLE_FOOTER
974        "</tbody>\n"
975        "</table>\n"
976      );
977    }
978    fprintf(
979      aFile,
980      "</pre>\n"
981      "</body>\n"
982      "</html>"
983    );
984
985    CloseFile(aFile);
986  }
987
988  void ReportsHtml::CloseCoverageFile(
989    FILE*  aFile
990  )
991  {
992    fprintf(
993      aFile,
994      TABLE_FOOTER
995      "</tbody>\n"
996      "</table>\n"
997      "</pre>\n"
998      "</body>\n"
999      "</html>"
1000    );
1001
1002    CloseFile(aFile);
1003  }
1004
1005  void ReportsHtml::CloseNoRangeFile(
1006    FILE*  aFile
1007  )
1008  {
1009    fprintf(
1010      aFile,
1011      TABLE_FOOTER
1012      "</tbody>\n"
1013      "</table>\n"
1014      "</pre>\n"
1015      "</body>\n"
1016      "</html>"
1017    );
1018
1019    CloseFile(aFile);
1020  }
1021
1022
1023  void ReportsHtml::CloseSizeFile(
1024    FILE*  aFile
1025  )
1026  {
1027    fprintf(
1028      aFile,
1029      TABLE_FOOTER
1030      "</tbody>\n"
1031      "</table>\n"
1032      "</pre>\n"
1033      "</body>\n"
1034      "</html>"
1035    );
1036
1037    CloseFile( aFile );
1038  }
1039
1040  void ReportsHtml::CloseSymbolSummaryFile(
1041    FILE*  aFile
1042  )
1043  {
1044    fprintf(
1045      aFile,
1046      TABLE_FOOTER
1047       "</tbody>\n"
1048      "</table>\n"
1049      "</pre>\n"
1050      "</body>\n"
1051      "</html>"
1052    );
1053
1054     CloseFile( aFile );
1055  }
1056
1057}
Note: See TracBrowser for help on using the repository browser.