winIDEA SDK
isys::CCoverageData2 Class Reference

Description

This class provides convenient access to coverage data exported to XML file, so that writing XML parser is not required.

Use class CCoverageController2 to record and export the data.

Instances of this class chould be obtained with one of createInstance() static methods.

Two ways of parsing are provided (see parameter isLoadDataInMemory in methods createInstance()):

  • parse complete coverage file to memory. Use this approach when coverage files are small relative to available computer memory. Method getRoot() returns root node, which contains children. Iterators are also available. Recommended usage:
        createInstance()
        getParserWarnings()
        closeParser()
        use getter methods as needed
      
  • parse coverage file statistic node by node. Information is available only through iterator, nodes do not have children or parents assigned. Recommended usage:
        createInstance()
        getParserWarnings()
        then either:
          call getStatistic() if you are interested in coverage 
                              statistic of one area only
          call getIterator()  to obtain information about all areas.
                              Once iterator's method hasNext() returns false,
                              this object can no longer be used. 
        finally call method closeParser()
      

#include <CCoverageData2.h>

Public Member Functions

std::string getParserWarnings ()
 This method returns warnings related to input XML document. More...
 
void closeParser ()
 This method releases parser resources and closes XML file. More...
 
CCoverageMetaInfoSPtr getCoverageMetaInfo ()
 Returns coverage meta-data as specified by the user in winIDEA coverage 'Set information' dialog. More...
 
CCoverageStatistic2SPtr getRoot ()
 Returns root node of type CCoverageStatistic2, which contains all other nodes. More...
 
CCoverageStatistic2SPtr getStatistic (const std::string &partition, const std::string &folder, const std::string &module, const std::string &qualFuncName)
 Returns statistic for the given function. More...
 
CCoverageStatistic2SPtr getStatistic (CCoverageStatistic2::EAreaType areaType, const std::string &areaName)
 This method searches the coverage data tree and returns the first node with the given type and name found. More...
 
CCoverageStatIteratorSPtr getIterator (CCoverageStatistic2::EAreaType areaType)
 Returns iterator, which iterates all nodes in coverage file sequentially, and returns only nodes of the given type. More...
 

Static Public Member Functions

static CCoverageData2SPtr createInstance (CCoverageController2SPtr coverageCtrl, const std::string &exportFileName, bool isLoadDataInMemory)
 This factory method exports data to file, and returns initialized object. More...
 
static CCoverageData2SPtr createInstance (const std::string &fileName, bool isLoadDataInMemory)
 This factory method parses statistic information from coverage XML export file and returns initialized object. More...
 

Member Function Documentation

◆ closeParser()

void isys::CCoverageData2::closeParser ( )

This method releases parser resources and closes XML file.

If this method is not called, the XML file remains opened and can not be overwritten or deleted until the application exits. Furthermore, memory allocated by by this object is not released until this method is called!

Python example: test_get_root.py

◆ createInstance() [1/2]

static CCoverageData2SPtr isys::CCoverageData2::createInstance ( CCoverageController2SPtr  coverageCtrl,
const std::string &  exportFileName,
bool  isLoadDataInMemory 
)
static

This factory method exports data to file, and returns initialized object.

Use it, when you've just recorded data (have CCoverageController2 object available), and have not exported it yet. Note also that this method is not as flexible as direct export and method createInstance(fileName, isLoadDataInMemory).

Note: if exportFileName is relative, it is saved relative to winIDEA working directory, not the script working directory. This method tries to do its best to open the saved file, but if winIDEA is on remote host, it will fail. In such cases try to export the coverage data with CCoverageController2::exportData() and use the overloaded method createInstance(fileName) instead.

Important: To release memory and file, always call closeParser() when done using parser!

Parameters
coverageCtrlcoverage document controller which will be used to obtain data.
exportFileNamename of the file to export data to
isLoadDataInMemoryif true, the exported file is immediately parsed and all data is loaded into memory. This provides faster browsing, but may not be appropriate for large coverage files.
If false, use iterator (see getIterator()) to parse statistic node by node. This approach is not as flexible as the frst one, but it is very memory efficient.

Python example: test_coverage_create_instance.py

◆ createInstance() [2/2]

static CCoverageData2SPtr isys::CCoverageData2::createInstance ( const std::string &  fileName,
bool  isLoadDataInMemory 
)
static

This factory method parses statistic information from coverage XML export file and returns initialized object.

Important: To release memory and file, always call closeParser() when done using parser!

Parameters
fileNamename of the file with coverage XML export. If you use relative file path, be aware that script working directory is used as a starting point, not winIDEA workspace directory.
isLoadDataInMemoryif true, the exported file is immediately parsed and all data is loaded into memory. This provides faster browsing, but may not be appropriate for large coverage files.
If false, use iterator (see getIterator()) to parse statistic node by node. This approach is not as flexible as the first one, but it is very memory efficient.

Python example: test_coverage_create_instance.py

◆ getCoverageMetaInfo()

CCoverageMetaInfoSPtr isys::CCoverageData2::getCoverageMetaInfo ( )

Returns coverage meta-data as specified by the user in winIDEA coverage 'Set information' dialog.

Python example: test_get_coverage_meta_info.py

◆ getIterator()

CCoverageStatIteratorSPtr isys::CCoverageData2::getIterator ( CCoverageStatistic2::EAreaType  areaType)

Returns iterator, which iterates all nodes in coverage file sequentially, and returns only nodes of the given type.

Specify areaType = EAnyArea to get all nodes.

Python example: test_get_iterator.py

◆ getParserWarnings()

std::string isys::CCoverageData2::getParserWarnings ( )

This method returns warnings related to input XML document.

If there were no warnings, an empty string is returned. Always call this method after createInstance(). If XML document is made with newer version of winIDEA than SDK, it will warn you about possible missing info.

Python example: test_get_root.py

◆ getRoot()

CCoverageStatistic2SPtr isys::CCoverageData2::getRoot ( )

Returns root node of type CCoverageStatistic2, which contains all other nodes.

This method may be called only if all data is loaded into memory (see the second parameter of createInstance()).

Exceptions
IllegalStateExceptionif coverage data is not loaded into memory (see the second parameter in createInstance()).

Python example: test_get_root.py

◆ getStatistic() [1/2]

CCoverageStatistic2SPtr isys::CCoverageData2::getStatistic ( CCoverageStatistic2::EAreaType  areaType,
const std::string &  areaName 
)

This method searches the coverage data tree and returns the first node with the given type and name found.

Although this method works also when data is not loaded into memory (createInstance() was called with
parameter isLoadDataInMemory = false), the parser has to be closed after each call and this class instantiated again, which makes it very inefficient. Also, if iterator was used before this method was called, results are unpredictable, and calling getIterator() after calling this method is forbidden.

Python example: test_get_statistic.py

◆ getStatistic() [2/2]

CCoverageStatistic2SPtr isys::CCoverageData2::getStatistic ( const std::string &  partition,
const std::string &  folder,
const std::string &  module,
const std::string &  qualFuncName 
)

Returns statistic for the given function.

This works only when data is loaded into memory.

Parameters
partitionname of download file, for example sample.elf
folderfolder where source file is located, may be given relative to winIDEA workspace (xjrf file).
modulename of a source file, which contains the function, for example main.c
qualFuncNamename of the function for which we want to get coverage statistics, for example main

Python example: test_get_statistic.py