[Tizen] Implement detecting of sanitized libraries
[platform/upstream/coreclr.git] / src / scripts / genEventingTests.py
1 # Python 2 compatibility
2 from __future__ import print_function
3
4 import os
5 import xml.dom.minidom as DOM
6 from genEventing import parseTemplateNodes
7 from utilities import open_for_update
8
9 stdprolog="""
10 // Licensed to the .NET Foundation under one or more agreements.
11 // The .NET Foundation licenses this file to you under the MIT license.
12 // See the LICENSE file in the project root for more information.
13
14 /******************************************************************
15
16 DO NOT MODIFY. AUTOGENERATED FILE.
17 This file is generated using the logic from <root>/src/scripts/genEventing.py
18
19 ******************************************************************/
20 """
21
22
23 def generateClralltestEvents(sClrEtwAllMan):
24     tree           = DOM.parse(sClrEtwAllMan)
25
26     clrtestEvents = []
27     for providerNode in tree.getElementsByTagName('provider'):
28         templateNodes = providerNode.getElementsByTagName('template')
29         allTemplates  = parseTemplateNodes(templateNodes)
30         eventNodes = providerNode.getElementsByTagName('event')
31         for eventNode in eventNodes:
32             eventName    = eventNode.getAttribute('symbol')
33             templateName = eventNode.getAttribute('template')
34             clrtestEvents.append(" EventXplatEnabled" + eventName + "();\n")
35             clrtestEvents.append("Error |= FireEtXplat" + eventName + "(\n")
36
37             line =[]
38             if templateName:
39                 template = allTemplates[templateName]
40                 fnSig = template.signature
41
42                 for params in fnSig.paramlist:
43                     if params in template.structs:
44                         line.append("sizeof(Struct1),\n")
45
46                     argline =''
47                     fnparam     = fnSig.getParam(params)
48                     if fnparam.name.lower() == 'count':
49                         argline = '2'
50                     else:
51                         if fnparam.winType == "win:Binary":
52                             argline = 'win_Binary'
53                         elif fnparam.winType == "win:Pointer" and fnparam.count == "win:count":
54                             argline = "(const void**)&var11"
55                         elif fnparam.winType == "win:Pointer" :
56                             argline = "(const void*)var11"
57                         elif fnparam.winType =="win:AnsiString":
58                             argline    = '" Testing AniString "'
59                         elif fnparam.winType =="win:UnicodeString":
60                             argline    = 'W(" Testing UnicodeString ")'
61                         else:
62                             if fnparam.count == "win:count":
63                                 line.append("&")
64
65                             argline = fnparam.winType.replace(":","_")
66
67                     line.append(argline)
68                     line.append(",\n")
69
70                 #remove trailing commas
71                 if len(line) > 0:
72                     del line[-1]
73                     line.append("\n")
74             line.append(");\n")
75             clrtestEvents.extend(line)
76
77     return ''.join(clrtestEvents)
78
79 def generateSanityTest(sClrEtwAllMan,testDir):
80
81     if not os.path.exists(testDir):
82         os.makedirs(testDir)
83
84     test_cpp   = testDir + "/clralltestevents.cpp"
85     testinfo   = testDir + "/testinfo.dat"
86
87     with open_for_update(testinfo) as Testinfo:
88         Testinfo.write("""
89 Copyright (c) Microsoft Corporation.  All rights reserved.
90 #
91
92 Version = 1.0
93 Section = EventProvider
94 Function = EventProvider
95 Name = PAL test for FireEtW* and EventEnabled* functions
96 TYPE = DEFAULT
97 EXE1 = eventprovidertest
98 Description = This is a sanity test to check that there are no crashes in Xplat eventing
99 """)
100
101     #Test.cpp
102     with open_for_update(test_cpp) as Test_cpp:
103         Test_cpp.write(stdprolog)
104         Test_cpp.write("""
105 /*=====================================================================
106 **
107 ** Source:   clralltestevents.cpp
108 **
109 ** Purpose:  Ensure Correctness of Eventing code
110 **
111 **
112 **===================================================================*/
113 #if FEATURE_PAL
114 #include <palsuite.h>
115 #endif //FEATURE_PAL
116 #include <clrxplatevents.h>
117
118 typedef struct _Struct1 {
119                 ULONG   Data1;
120                 unsigned short Data2;
121                 unsigned short Data3;
122                 unsigned char  Data4[8];
123 } Struct1;
124
125 Struct1 var21[2] = { { 245, 13, 14, "deadbea" }, { 542, 0, 14, "deadflu" } };
126
127 Struct1* var11 = var21;
128 Struct1* win_Struct = var21;
129
130 GUID win_GUID ={ 245, 13, 14, "deadbea" };
131 double win_Double =34.04;
132 ULONG win_ULong = 34;
133 BOOL win_Boolean = FALSE;
134 unsigned __int64 win_UInt64 = 114;
135 unsigned int win_UInt32 = 4;
136 unsigned short win_UInt16 = 12;
137 unsigned char win_UInt8 = 9;
138 int win_Int32 = 12;
139 BYTE* win_Binary =(BYTE*)var21 ;
140 int __cdecl main(int argc, char **argv)
141 {
142 #if defined(FEATURE_PAL)
143             /* Initialize the PAL.
144             */
145
146             if(0 != PAL_Initialize(argc, argv))
147             {
148             return FAIL;
149             }
150 #endif
151
152             ULONG Error = ERROR_SUCCESS;
153 #if defined(FEATURE_EVENT_TRACE)
154             Trace("\\n Starting functional  eventing APIs tests  \\n");
155 """)
156
157         Test_cpp.write(generateClralltestEvents(sClrEtwAllMan))
158         Test_cpp.write("""
159
160         if (Error != ERROR_SUCCESS)
161         {
162             Fail("One or more eventing Apis failed\\n ");
163             return FAIL;
164         }
165         Trace("\\n All eventing APIs were fired succesfully \\n");
166 #endif //defined(FEATURE_EVENT_TRACE)
167 #if defined(FEATURE_PAL)
168
169 /* Shutdown the PAL.
170 */
171
172         PAL_Terminate();
173 #endif
174         return PASS;
175                                 }
176
177 """)
178     Testinfo.close()
179
180
181 import argparse
182 import sys
183
184 def main(argv):
185
186     #parse the command line
187     parser = argparse.ArgumentParser(description="Generates the Code required to instrument LTTtng logging mechanism")
188
189     required = parser.add_argument_group('required arguments')
190     required.add_argument('--man',  type=str, required=True,
191                                     help='full path to manifest containig the description of events')
192     required.add_argument('--testdir', type=str, required=True,
193                                     help='full path to directory where the test assets will be deployed' )
194     args, unknown = parser.parse_known_args(argv)
195     if unknown:
196         print('Unknown argument(s): ', ', '.join(unknown))
197         return 1
198
199     sClrEtwAllMan     = args.man
200     testDir           = args.testdir
201
202     generateSanityTest(sClrEtwAllMan, testDir)
203
204 if __name__ == '__main__':
205     return_code = main(sys.argv[1:])
206     sys.exit(return_code)