STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
CodeCoverage.h
Go to the documentation of this file.
1 /*=++=
2 *CodeCoverage.h
3 *
4 * Copyright (c) Microsoft Corporation. All rights reserved.
5 *
6 *Purpose:
7 * This file defines the macros which are used to add the cpp code coverage filters
8 *
9 =--=*/
10 
11 
12 #pragma once
13 
14 #ifndef MS_CPP_CODECOVERAGEFRAMEWORK
15 #define MS_CPP_CODECOVERAGEFRAMEWORK
16 
17 /* Sample:
18 
19 // If CODE_COVERAGE_DISABLE_ALL_FILTERS was defined, filter information will not be emitted into binary.
20 // #define CODE_COVERAGE_DISABLE_ALL_FILTERS
21 
22 #include <CodeCoverage\CodeCoverage.h>
23 
24 // Exclude by source file/path:
25 // 1. UNC is supported
26 // 2. file/path is case-insensitive
27 // 3. relative path ("." and "..") is not supported
28 // 4. path will not be normalized (e.g. "a/b" will not match "a\\b")
29 
30 ExcludeSourceFromCodeCoverage(MySourceFilter1, L"*\\CAuto*.?pp")
31 ExcludeSourceFromCodeCoverage(MySourceFilter2, L"*\\boost\\src\\*")
32 ExcludeSourceFromCodeCoverage(MySourceFilter3, L"\\\\192.168.0.1\\src\\*")
33 ExcludeSourceFromCodeCoverage(MySourceFilter4, L"\\\\winsrv2008\\src\\filter\\*")
34 
35 // Exclude by function name:
36 // 1. function name is case-sensitive
37 // 2. function name will not be normalized (e.g. "vector< int >" will not match "vector<int>")
38 
39 ExcludeFromCodeCoverage(MyFunctionFilter1, L"functionfilter")
40 ExcludeFromCodeCoverage(MyFunctionFilter2, L"MyClass<*>::*")
41 ExcludeFromCodeCoverage(MyFunctionFilter3, L"*::~*")
42 
43 */
44 
45 /* Code coverage is only supported for x86 and amd64.
46 */
47 #if defined(_M_IX86) || defined(_M_AMD64)
48 
49 /* Helper macros
50 */
51 #define CODE_COVERAGE_CONCAT(X, Y) X##Y
52 #define CODE_COVERAGE_CONCAT2(X, Y) CODE_COVERAGE_CONCAT(X, Y)
53 #define CODE_COVERAGE_TOSTRING(X) #X
54 #define CODE_COVERAGE_TOSTRING2(X) CODE_COVERAGE_TOSTRING(X)
55 
56 #else
57 
58 #if !defined(CODE_COVERAGE_DISABLE_ALL_FILTERS)
59 #define CODE_COVERAGE_DISABLE_ALL_FILTERS
60 #endif /* CODE_COVERAGE_DISABLE_ALL_FILTERS */
61 
62 #endif
63 
64 #if defined(CODE_COVERAGE_DISABLE_ALL_FILTERS)
65 
66 /* If CODE_COVERAGE_DISABLE_ALL_FILTERS was defined, filter information will not be emitted into binary.
67  The generated namespaces were kept for diagnostic purpose in combination with "cl.exe /E".
68 */
69 #define ExcludeSourceFromCodeCoverage(CODE_COVERAGE_FILTER_NAME, CODE_COVERAGE_FILTER_PATTERN) \
70  namespace Microsoft{ namespace VisualStudio{ namespace CppCodeCoverageFramework{ namespace CODE_COVERAGE_FILTER_NAME { \
71  }}}}
72 
73 #define ExcludeFromCodeCoverage(CODE_COVERAGE_FILTER_NAME, CODE_COVERAGE_FILTER_PATTERN) \
74  namespace Microsoft{ namespace VisualStudio{ namespace CppCodeCoverageFramework{ namespace CODE_COVERAGE_FILTER_NAME { \
75  }}}}
76 
77 #else /* CODE_COVERAGE_DISABLE_ALL_FILTERS */
78 
79 /* Macros used by cpp code coverage internally
80 */
81 #define CODE_COVERAGE_FILTER(CODE_COVERAGE_FILTER_CATEGORY, CODE_COVERAGE_FILTER_NAME, CODE_COVERAGE_FILTER_PATTERN) \
82  namespace Microsoft{ namespace VisualStudio{ namespace CppCodeCoverageFramework{ namespace CODE_COVERAGE_FILTER_CATEGORY{ \
83  __pragma(optimize("", off)) \
84  __declspec(dllexport) __declspec(noinline) void* CODE_COVERAGE_FILTER_NAME() \
85  { \
86  __annotation( \
87  CODE_COVERAGE_CONCAT2(L, CODE_COVERAGE_TOSTRING2(CODE_COVERAGE_FILTER_NAME)) \
88  L" " \
89  CODE_COVERAGE_FILTER_PATTERN); \
90  return CODE_COVERAGE_TOSTRING2(CODE_COVERAGE_FILTER_NAME); \
91  } \
92  __pragma(optimize("", on)) \
93  }}}}
94 
95 /* Macros to define your customized source file/path filters
96 */
97 #define ExcludeSourceFromCodeCoverage(CODE_COVERAGE_FILTER_NAME, CODE_COVERAGE_FILTER_PATTERN) \
98  CODE_COVERAGE_FILTER(SourceFilter, CODE_COVERAGE_FILTER_NAME, CODE_COVERAGE_FILTER_PATTERN)
99 
100 /* Macros to define your customized function/method filters
101 */
102 #define ExcludeFromCodeCoverage(CODE_COVERAGE_FILTER_NAME, CODE_COVERAGE_FILTER_PATTERN) \
103  CODE_COVERAGE_FILTER(FunctionFilter, CODE_COVERAGE_FILTER_NAME, CODE_COVERAGE_FILTER_PATTERN)
104 
105 #endif /* CODE_COVERAGE_DISABLE_ALL_FILTERS */
106 
107 #endif /* MS_CPP_CODECOVERAGEFRAMEWORK */