source: rtems-tools/tester/covoar/CoverageReaderTSIM.cc @ 0c4884a

Last change on this file since 0c4884a was 092bf04, checked in by Joel Sherrill <joel@…>, on 04/06/21 at 20:40:42

covoar: Eliminate tabs

  • Property mode set to 100644
File size: 2.6 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 <iostream>
13#include <iomanip>
14
15#include <rld.h>
16
17#include "app_common.h"
18#include "CoverageReaderTSIM.h"
19#include "CoverageMap.h"
20#include "ExecutableInfo.h"
21
22namespace Coverage {
23
24  CoverageReaderTSIM::CoverageReaderTSIM()
25  {
26
27  }
28
29  CoverageReaderTSIM::~CoverageReaderTSIM()
30  {
31  }
32
33  void CoverageReaderTSIM::processFile(
34    const char* const     file,
35    ExecutableInfo* const executableInformation
36  )
37  {
38    CoverageMapBase* aCoverageMap = NULL;
39    int              baseAddress;
40    int              cover;
41    FILE*            coverageFile;
42    int              i;
43    int              status;
44
45    //
46    // Open the coverage file.
47    //
48    coverageFile = ::fopen( file, "r" );
49    if (!coverageFile) {
50      std::ostringstream what;
51      what << "Unable to open " << file;
52      throw rld::error( what, "CoverageReaderTSIM::processFile" );
53    }
54
55    //
56    // Read and process each line of the coverage file.
57    //
58    while ( true ) {
59      status = ::fscanf( coverageFile, "%x : ", &baseAddress );
60      if (status == EOF || status == 0) {
61        break;
62      }
63
64      for (i = 0; i < 0x80; i += 4) {
65        unsigned int a;
66        status = ::fscanf( coverageFile, "%x", &cover );
67        if (status == EOF || status == 0) {
68          std::cerr << "CoverageReaderTSIM: WARNING! Short line in "
69                    << file
70                    << " at address 0x"
71                    << std::hex << std::setfill('0')
72                    << baseAddress
73                    << std::setfill(' ') << std::dec
74                    << std::endl;
75          break;
76        }
77
78        //
79        // Obtain the coverage map containing the address and
80        // mark the address as executed.
81        //
82        a = baseAddress + i;
83        aCoverageMap = executableInformation->getCoverageMap( a );
84        if ( !aCoverageMap )
85          continue;
86        if ( cover & 0x01 ) {
87          aCoverageMap->setWasExecuted( a );
88          aCoverageMap->setWasExecuted( a + 1 );
89          aCoverageMap->setWasExecuted( a + 2 );
90          aCoverageMap->setWasExecuted( a + 3 );
91          if ( cover & 0x08 ) {
92            aCoverageMap->setWasTaken( a );
93            BranchInfoAvailable = true;
94          }
95          if ( cover & 0x10 ) {
96            aCoverageMap->setWasNotTaken( a );
97            BranchInfoAvailable = true;
98          }
99        }
100      }
101    }
102
103    ::fclose( coverageFile );
104  }
105}
Note: See TracBrowser for help on using the repository browser.