BVB Source Codes

CRYENGINE Show CodeCoverageManager.h Source code

Return Download CRYENGINE: download CodeCoverageManager.h Source code - Download CRYENGINE Source code - Type:.h
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. // -------------------------------------------------------------------------
  4. //  File name:   CodeCoverageManager.h
  5. //  Created:     18/06/2008 by Matthew
  6. //  Description: High-level manager class for code coverage system
  7. //               including file handing of checkpoint lisst
  8. //               Tracks whether key points of code have been hit in testing
  9. // -------------------------------------------------------------------------
  10. //  History:
  11. //
  12. ////////////////////////////////////////////////////////////////////////////
  13.  
  14. /**
  15.  * Design notes:
  16.  *   For now, reading contexts is done in one shot. I'm tempted to work through the file slowly to avoid a spike.
  17.  *   A (separate) tracking GUI is crucial to this system - an efficient interface to service this is not trivial
  18.  *   Quite a basic principle to underlie this code is that we're only interested in checkpoints we haven't yet hit
  19.  */
  20.  
  21. #ifndef __CODE_COVERAGE_MANAGER_H_
  22. #define __CODE_COVERAGE_MANAGER_H_
  23.  
  24. #pragma once
  25.  
  26. #if !defined(_RELEASE)
  27.  
  28. // Get rid of this include later - we don't want people including the Manager for this
  29.         #include "CodeCoverageTracker.h"
  30.  
  31. // Forward declarations
  32.  
  33. /*
  34.    struct SCodeCoverageStats
  35.    {
  36.    int nTotalRegistered;
  37.    int nTotalInContext;
  38.    };
  39.  */
  40.  
  41. /**
  42.  * The code coverage manager
  43.  */
  44. class CCodeCoverageManager
  45. {
  46.         typedef std::vector<CCodeCoverageCheckPoint*> CheckPointVector;
  47.         // String comparison for set
  48.         struct cmp_str : public std::binary_function<const char*, const char*, bool>
  49.         {
  50.                 bool operator()(char const* a, char const* b) const
  51.                 {
  52.                         return strcmp(a, b) < 0;
  53.                 }
  54.         };
  55.  
  56.         typedef std::set<const char*, cmp_str> CheckPointSet;
  57.  
  58. public:
  59.         CCodeCoverageManager();
  60.  
  61.         ~CCodeCoverageManager()
  62.         {
  63.                 SAFE_DELETE(m_pLabelBlock);
  64.         }
  65.  
  66.         // Read a list of checkpoints to look for in this context
  67.         // File format specified in cpp
  68.         // User own the file handle and must close it
  69.         bool ReadCodeCoverageContext(FILE*);
  70.  
  71.         // Write a list of all the checkpoints currently registered
  72.         // File format specified in cpp
  73.         // User own the file handle and must close it
  74.         bool WriteCodeCoverageContext(FILE*)
  75.         {
  76.  
  77.                 return false;
  78.         }
  79.  
  80.         // Check whether a valid context is loaded
  81.         // Without a valid context the Manager gives no useful data
  82.         bool IsContextValid() const
  83.         {
  84.                 return m_bContextValid;
  85.         }
  86.  
  87.         // Returns whether the checkpoint is in the file of expected checkpoints
  88.         bool IsExpected(const char* szCheckPoint) const
  89.         {
  90.                 return (m_setCheckPoints.find(szCheckPoint) != m_setCheckPoints.end());
  91.         }
  92.  
  93.         //
  94.         void Clear()
  95.         {
  96.                 GetTracker()->Clear();
  97.         }
  98.  
  99.         // Get number of checkpoints registered so far
  100.         // Important for monitoring coverage progress
  101.         int GetTotalRegistered() const
  102.         {
  103.                 return GetTracker()->GetTotalRegistered();
  104.         }
  105.  
  106.         // Get the total number of checkpoints (count of all in the file)
  107.         int GetTotal() const
  108.         {
  109.                 return m_nTotalCheckpoints;
  110.         }
  111.  
  112.         int GetCodeCoverageStats()
  113.         {
  114.                 // Get code coverage statistics
  115.                 return 0;
  116.         }
  117.  
  118.         void RemoveCheckPoint(const char* pName)
  119.         {
  120.                 assert(pName);
  121.  
  122.                 m_setCheckPoints.erase(pName);
  123.         }
  124.  
  125.         // Called every frame
  126.         void                 Update(void);
  127.  
  128.         const CheckPointSet& GetUnexpectedCheckpoints() const
  129.         {
  130.                 return m_setUnexpectedCheckPoints;
  131.         }
  132.  
  133.         // Fill vector with labels of checkpoints that are still to be hit
  134.         // Labels are given in alphabetical order
  135.         // Any existing contents is wiped
  136.         void GetRemainingCheckpointLabels(std::vector<const char*>& vLabels) const;
  137.  
  138.         void DumpCheckpoints(bool bLogToFile) const;
  139.  
  140. protected:
  141.         // Wraps fgets to remove newlines and use correct buffer/string lengths
  142.         // Returns number of characters successfully written, including the null-terminator
  143.         // On error, returns 0
  144.         int                   GetLine(char* pBuff, FILE* fp);
  145.  
  146.         CCodeCoverageTracker* GetTracker() const { return gAIEnv.pCodeCoverageTracker; }
  147.  
  148.         bool m_bContextValid;
  149.  
  150.         // Pointer to a packed block of checkpoint label strings
  151.         // Note that, in fact, all those strings should be somewhere in the binary already
  152.         char* m_pLabelBlock;
  153.  
  154.         // Set of labels of checkpoints we are still to hit
  155.         CheckPointSet m_setCheckPoints;
  156.         CheckPointSet m_setUnexpectedCheckPoints;
  157.  
  158.         // The total number of checkpoints (read from the file)
  159.         int m_nTotalCheckpoints;
  160. };
  161.  
  162. #endif //_RELEASE
  163.  
  164. #endif // __CODE_COVERAGE_MANAGER_H_
  165.  
downloadCodeCoverageManager.h Source code - Download CRYENGINE Source code
Related Source Codes/Software:
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top