summaryrefslogtreecommitdiff
path: root/rtems-coverage/CoverageReaderTSIM.cc
blob: 90ed4b58ec9e19d430908e4b5d037b319002031a (plain)
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
/*
 *  $Id$
 */

/*! @file CoverageReaderTSIM.cc
 *  @brief CoverageReaderTSIM Implementation
 *
 *  This file contains the implementation of the CoverageReader class
 *  for the coverage files written by the SPARC simulator TSIM.
 */

#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>

#include "CoverageReaderTSIM.h"
#include "CoverageMap.h"
#include "ExecutableInfo.h"

namespace Coverage {

  CoverageReaderTSIM::CoverageReaderTSIM()
  {
  }

  CoverageReaderTSIM::~CoverageReaderTSIM()
  {
  }

  void CoverageReaderTSIM::processFile(
    const char* const     file,
    ExecutableInfo* const executableInformation
  )
  {
    CoverageMapBase* aCoverageMap = NULL;
    int              baseAddress;
    int              cover;
    FILE*            coverageFile;
    int              i;
    int              status;

    //
    // Open the coverage file.
    //
    coverageFile = fopen( file, "r" );
    if (!coverageFile) {
      fprintf(
        stderr,
        "ERROR: CoverageReaderTSIM::processFile - Unable to open %s\n",
        file
      );
      exit( -1 );
    }

    //
    // Read and process each line of the coverage file.
    //
    while ( 1 ) {
      status = fscanf( coverageFile, "%x : ", &baseAddress );
      if (status == EOF || status == 0) {
        break;
      }

      for (i=0; i < 0x80; i+=4) {
        status = fscanf( coverageFile, "%d", &cover );
	if (status == EOF || status == 0) {
          fprintf(
            stderr,
            "CoverageReaderTSIM: WARNING! Short line in %s at address 0x%08x\n",
            file,
            baseAddress
          );
          break;
	}

        //
        // Obtain the coverage map containing the address and
        // mark the address as executed.
        //
        if (cover & 1) {
          aCoverageMap = executableInformation->getCoverageMap(
            baseAddress + i
          );
          if (aCoverageMap) {
            aCoverageMap->setWasExecuted( baseAddress + i );
            aCoverageMap->setWasExecuted( baseAddress + i + 1 );
            aCoverageMap->setWasExecuted( baseAddress + i + 2 );
            aCoverageMap->setWasExecuted( baseAddress + i + 3 );
          }
        }
      }
    }

    fclose( coverageFile );
  }
}