source: rtems-tools/tester/covoar/CoverageReaderTSIM.cc @ 3e187ba

5
Last change on this file since 3e187ba was 100f517, checked in by Chris Johns <chrisj@…>, on 05/09/14 at 11:50:37

covoar: Merger the covoar source from rtems-testing.git.

Use waf to build covoar.

  • Property mode set to 100644
File size: 2.4 KB
Line 
1/*! @file CoverageReaderTSIM.cc
2 *  @brief CoverageReaderTSIM Implementation
3 *
4 *  This file contains the implementation of the CoverageReader class
5 *  for the coverage files written by the SPARC simulator TSIM.
6 */
7
8#include <stdio.h>
9#include <stdlib.h>
10#include <sys/stat.h>
11
12#include "app_common.h"
13#include "CoverageReaderTSIM.h"
14#include "CoverageMap.h"
15#include "ExecutableInfo.h"
16
17namespace Coverage {
18
19  CoverageReaderTSIM::CoverageReaderTSIM()
20  {
21
22  }
23
24  CoverageReaderTSIM::~CoverageReaderTSIM()
25  {
26  }
27
28  void CoverageReaderTSIM::processFile(
29    const char* const     file,
30    ExecutableInfo* const executableInformation
31  )
32  {
33    CoverageMapBase* aCoverageMap = NULL;
34    int              baseAddress;
35    int              cover;
36    FILE*            coverageFile;
37    int              i;
38    int              status;
39
40    //
41    // Open the coverage file.
42    //
43    coverageFile = fopen( file, "r" );
44    if (!coverageFile) {
45      fprintf(
46        stderr,
47        "ERROR: CoverageReaderTSIM::processFile - Unable to open %s\n",
48        file
49      );
50      exit( -1 );
51    }
52
53    //
54    // Read and process each line of the coverage file.
55    //
56    while ( 1 ) {
57      status = fscanf( coverageFile, "%x : ", &baseAddress );
58      if (status == EOF || status == 0) {
59        break;
60      }
61
62      for (i=0; i < 0x80; i+=4) {
63        unsigned int a;
64        status = fscanf( coverageFile, "%x", &cover );
65        if (status == EOF || status == 0) {
66          fprintf(
67            stderr,
68            "CoverageReaderTSIM: WARNING! Short line in %s at address 0x%08x\n",
69            file,
70            baseAddress
71          );
72          break;
73        }
74
75        //
76        // Obtain the coverage map containing the address and
77        // mark the address as executed.
78        //
79        a = baseAddress + i;
80        aCoverageMap = executableInformation->getCoverageMap( a );
81        if ( !aCoverageMap )
82          continue;
83        if ( cover & 0x01 ) {
84          aCoverageMap->setWasExecuted( a );
85          aCoverageMap->setWasExecuted( a + 1 );
86          aCoverageMap->setWasExecuted( a + 2 );
87          aCoverageMap->setWasExecuted( a + 3 );
88          if ( cover & 0x08 ) {
89            aCoverageMap->setWasTaken( a );
90            BranchInfoAvailable = true;
91          }
92          if ( cover & 0x10 ) {
93            aCoverageMap->setWasNotTaken( a );
94            BranchInfoAvailable = true;
95          }
96        }
97      }
98    }
99
100    fclose( coverageFile );
101  }
102}
Note: See TracBrowser for help on using the repository browser.