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

5
Last change on this file since b857151 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: 7.9 KB
Line 
1
2/*! @file CoverageMapBase.cc
3 *  @brief CoverageMapBase Implementation
4 *
5 *  This file contains the implementation of the functions
6 *  which provide a base level of functionality of a CoverageMap.
7 */
8
9#include <libgen.h>
10#include <limits.h>
11#include <stdio.h>
12#include <stdlib.h>
13
14#include "CoverageMapBase.h"
15
16namespace Coverage {
17
18  CoverageMapBase::CoverageMapBase(
19    uint32_t low,
20    uint32_t high
21  )
22  {
23    uint32_t       a;
24    AddressRange_t range;
25
26    range.lowAddress  = low;
27    range.highAddress = high;
28    RangeList.push_back( range );
29
30    Size = high - low + 1;
31
32    Info = new perAddressInfo_t[ Size ];
33
34    for (a=0; a<Size; a++) {
35
36      perAddressInfo_t *i = &Info[ a ];
37
38      i->isStartOfInstruction = false;
39      i->wasExecuted          = 0;
40      i->isBranch             = false;
41      i->isNop                = false;
42      i->wasTaken             = 0;
43      i->wasNotTaken          = 0;
44    }
45  }
46
47  CoverageMapBase::~CoverageMapBase()
48  {
49    if (Info)
50      delete Info;
51  }
52 
53  void  CoverageMapBase::Add( uint32_t low, uint32_t high )
54  {
55    AddressRange_t range;
56
57    range.lowAddress  = low;
58    range.highAddress = high;
59    RangeList.push_back( range );
60  }
61 
62  bool CoverageMapBase::determineOffset(
63    uint32_t  address,
64    uint32_t *offset
65  )const
66  {
67    AddressRange::const_iterator  itr;
68
69    for ( itr = RangeList.begin(); itr != RangeList.end(); itr++ ) {
70      if ((address >= itr->lowAddress) && (address <= itr->highAddress)){
71        *offset = address - itr->lowAddress;
72        return true;
73      }
74    }
75    *offset = 0;
76    return false;
77  }
78
79
80  void CoverageMapBase::dump( void ) const {
81
82    uint32_t          a;
83    perAddressInfo_t* entry;
84
85    fprintf( stderr, "Coverage Map Contents:\n" );
86
87    /*
88     * XXX - Dump is only marking the first Address Range.
89     */
90
91    for (a = 0; a < Size; a++) {
92
93      entry = &Info[ a ];
94
95      fprintf(
96        stderr,
97        "0x%x - isStartOfInstruction = %s, wasExecuted = %s\n",
98        a + RangeList.front().lowAddress,
99        entry->isStartOfInstruction ? "TRUE" : "FALSE",
100        entry->wasExecuted ? "TRUE" : "FALSE"
101      );
102      fprintf(
103        stderr,
104        "           isBranch = %s, wasTaken = %s, wasNotTaken = %s\n",
105        entry->isBranch ? "TRUE" : "FALSE",
106        entry->wasTaken ? "TRUE" : "FALSE",
107        entry->wasNotTaken ? "TRUE" : "FALSE"
108      );
109    }
110  }
111
112  bool CoverageMapBase::getBeginningOfInstruction(
113    uint32_t  address,
114    uint32_t* beginning
115  ) const
116  {
117    bool           status = false;
118    uint32_t       start;
119    AddressRange_t range;
120
121
122    status = getRange( address, &range );
123    if ( status != true )
124      return status;
125
126    start = address;
127
128    while (start >= range.lowAddress ) {
129      if (Info[ start - range.lowAddress ].isStartOfInstruction) {
130        *beginning = start;
131        status = true;
132        break;
133      }
134      else
135        start--;
136    }
137
138    return status;
139  }
140
141  int32_t CoverageMapBase::getFirstLowAddress() const
142  {
143    return RangeList.front().lowAddress;
144  }
145
146  bool CoverageMapBase::getRange( uint32_t address, AddressRange_t *range ) const
147  {
148    AddressRange::const_iterator  itr;
149
150    for ( itr = RangeList.begin(); itr != RangeList.end(); itr++ ) {
151      if ((address >= itr->lowAddress) && (address <= itr->highAddress)){
152        range->lowAddress = itr->lowAddress;
153        range->highAddress = itr->highAddress;
154        return true;
155      }
156    }
157
158    range->lowAddress  = 0;
159    range->highAddress = 0;
160
161    return false;
162
163  }
164
165  uint32_t CoverageMapBase::getSize() const
166  {
167    return Size;
168  }
169
170  void CoverageMapBase::setIsStartOfInstruction(
171    uint32_t    address
172  )
173  {
174    uint32_t offset;
175 
176    if (determineOffset( address, &offset ) != true)
177      return;
178
179    Info[ offset ].isStartOfInstruction = true;
180  }
181
182  bool CoverageMapBase::isStartOfInstruction( uint32_t address ) const
183  {
184    uint32_t offset;
185 
186    if (determineOffset( address, &offset ) != true)
187      return false;
188
189    return Info[ offset ].isStartOfInstruction;
190  }
191
192  void CoverageMapBase::setWasExecuted( uint32_t address )
193  {
194    uint32_t offset;
195 
196    if (determineOffset( address, &offset ) != true)
197      return;
198
199    Info[ offset ].wasExecuted += 1;
200  }
201
202  void CoverageMapBase::sumWasExecuted( uint32_t address, uint32_t addition)
203  {
204    uint32_t offset;
205 
206    if (determineOffset( address, &offset ) != true)
207      return;
208
209    Info[ offset ].wasExecuted += addition;
210  }
211
212  bool CoverageMapBase::wasExecuted( uint32_t address ) const
213  {
214    uint32_t offset;
215    bool     result;
216 
217    result = true;
218
219    if (determineOffset( address, &offset ) != true)
220      result = false;
221
222    if (Info[ offset ].wasExecuted <= 0)
223      result = false;
224
225    return result;
226  }
227
228  uint32_t CoverageMapBase::getWasExecuted( uint32_t address ) const
229  {
230    uint32_t offset;
231
232    if (determineOffset( address, &offset ) != true)
233      return 0;
234
235    return Info[ offset ].wasExecuted; 
236  }
237
238  void CoverageMapBase::setIsBranch(
239    uint32_t    address
240  )
241  {
242    uint32_t offset;
243 
244    if (determineOffset( address, &offset ) != true)
245      return;
246
247    Info[ offset ].isBranch = true;
248  }
249
250  bool CoverageMapBase::isNop( uint32_t address ) const
251  {
252    uint32_t offset;
253 
254    if (determineOffset( address, &offset ) != true)
255      return false;
256
257    return Info[ offset ].isNop;
258  }
259
260  void CoverageMapBase::setIsNop(
261    uint32_t    address
262  )
263  {
264    uint32_t offset;
265 
266    if (determineOffset( address, &offset ) != true)
267      return;
268
269    Info[ offset ].isNop = true;
270  }
271
272  bool CoverageMapBase::isBranch( uint32_t address ) const
273  {
274    uint32_t offset;
275 
276    if (determineOffset( address, &offset ) != true)
277      return false;
278
279    return Info[ offset ].isBranch;
280  }
281
282  void CoverageMapBase::setWasTaken(
283    uint32_t    address
284  )
285  {
286    uint32_t offset;
287 
288    if (determineOffset( address, &offset ) != true)
289      return;
290
291    Info[ offset ].wasTaken += 1;
292  }
293
294  void CoverageMapBase::setWasNotTaken(
295    uint32_t    address
296  )
297  {
298    uint32_t offset;
299 
300    if (determineOffset( address, &offset ) != true)
301      return;
302
303    Info[ offset ].wasNotTaken += 1;
304  }
305
306  bool CoverageMapBase::wasAlwaysTaken( uint32_t address ) const
307  {
308    uint32_t offset;
309 
310    if (determineOffset( address, &offset ) != true)
311      return false;
312
313    return (Info[ offset ].wasTaken &&
314            !Info[ offset ].wasNotTaken);
315  }
316
317  bool CoverageMapBase::wasNeverTaken( uint32_t address ) const
318  {
319    uint32_t offset;
320 
321    if (determineOffset( address, &offset ) != true)
322      return false;
323
324    return (!Info[ offset ].wasTaken &&
325            Info[ offset ].wasNotTaken);
326  }
327
328  bool CoverageMapBase::wasNotTaken( uint32_t address ) const
329  {
330            uint32_t offset;
331            bool     result;
332
333            result = true;
334
335            if (determineOffset( address, &offset ) != true)
336              result = false;
337
338            if (Info[ offset ].wasNotTaken <= 0)
339              result = false;
340
341            return result;
342  }
343
344  void CoverageMapBase::sumWasNotTaken( uint32_t address, uint32_t addition)
345  {
346    uint32_t offset;
347
348    if (determineOffset( address, &offset ) != true)
349      return;
350
351    Info[ offset ].wasNotTaken += addition;
352  }
353
354  uint32_t CoverageMapBase::getWasNotTaken( uint32_t address ) const
355  {
356    uint32_t offset;
357
358    if (determineOffset( address, &offset ) != true)
359      return 0;
360
361    return Info[ offset ].wasNotTaken;
362  }
363
364  bool CoverageMapBase::wasTaken( uint32_t address ) const
365  {
366    uint32_t offset;
367    bool     result;
368
369    result = true;
370 
371    if (determineOffset( address, &offset ) != true)
372      result = false;
373
374    if (Info[ offset ].wasTaken <= 0)
375      result = false;
376
377    return result;
378  }
379
380  void CoverageMapBase::sumWasTaken( uint32_t address, uint32_t addition)
381  {
382    uint32_t offset;
383
384    if (determineOffset( address, &offset ) != true)
385      return;
386
387    Info[ offset ].wasTaken += addition;
388  }
389
390  uint32_t CoverageMapBase::getWasTaken( uint32_t address ) const
391  {
392    uint32_t offset;
393
394    if (determineOffset( address, &offset ) != true)
395      return 0;
396
397    return Info[ offset ].wasTaken;
398  }
399}
Note: See TracBrowser for help on using the repository browser.