source: rtems-tools/tester/covoar/CoverageWriterTSIM.cc @ 881824f

5
Last change on this file since 881824f was 881824f, checked in by Chris Johns <chrisj@…>, on 05/11/18 at 02:24:11

tester/covoar: Remove all exit() calls and throw an rld::error exception.

Add a suitable catch to covoar's main.

  • Property mode set to 100644
File size: 1.8 KB
Line 
1/*! @file CoverageWriterTSIM.cc
2 *  @brief CoverageWriterTSIM Implementation
3 *
4 *  This file contains the implementation of the CoverageWriter class
5 *  for the coverage files written by the SPARC simulator TSIM.
6 */
7
8#include <stdio.h>
9#include <stdlib.h>
10
11#include <iostream>
12#include <iomanip>
13
14#include <rld.h>
15
16#include "CoverageWriterTSIM.h"
17
18namespace Coverage {
19
20  CoverageWriterTSIM::CoverageWriterTSIM()
21  {
22  }
23
24  CoverageWriterTSIM::~CoverageWriterTSIM()
25  {
26  }
27
28
29  void CoverageWriterTSIM::writeFile(
30    const char* const file,
31    CoverageMapBase*  coverage,
32    uint32_t          lowAddress,
33    uint32_t          highAddress
34  )
35  {
36    uint32_t a;
37    int      cover;
38    FILE*    coverageFile;
39    int      i;
40    int      status;
41
42    /*
43     *  read the file and update the coverage map passed in
44     */
45    coverageFile = ::fopen( file, "w" );
46    if ( !coverageFile ) {
47      std::ostringstream what;
48      what << "Unable to open " << file;
49      throw rld::error( what, "CoverageWriterTSIM::writeFile" );
50    }
51
52    for ( a = lowAddress; a < highAddress; a += 0x80 ) {
53      status = fprintf( coverageFile, "%x : ", a );
54      if ( status == EOF || status == 0 ) {
55        break;
56      }
57      for ( i = 0; i < 0x80; i += 4 ) {
58        cover = ((coverage->wasExecuted( a + i )) ? 1 : 0);
59        status = ::fprintf( coverageFile, "%d ", cover );
60        if ( status == EOF || status == 0 ) {
61          ::fclose( coverageFile );
62          std::ostringstream what;
63          what << "write to " << file
64               << " at address 0x"
65               << std::hex << std::setfill('0')
66               << std::setw(8) << a
67               << std::setfill(' ') << std::dec
68               << "failed";
69          throw rld::error( what, "CoverageWriterTSIM::writeFile" );
70        }
71      }
72      ::fprintf( coverageFile, "\n" );
73    }
74
75    ::fclose( coverageFile );
76  }
77}
Note: See TracBrowser for help on using the repository browser.