summaryrefslogtreecommitdiff
path: root/src/scripts/genEventingTests.py
blob: 8039e557bcc1c1b7cd5e46d158f8dbb6e0f5ce64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# Python 2 compatibility
from __future__ import print_function

import os
import xml.dom.minidom as DOM
from genEventing import parseTemplateNodes
from utilities import open_for_update

stdprolog="""
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

/******************************************************************

DO NOT MODIFY. AUTOGENERATED FILE.
This file is generated using the logic from <root>/src/scripts/genEventing.py

******************************************************************/
"""


def generateClralltestEvents(sClrEtwAllMan):
    tree           = DOM.parse(sClrEtwAllMan)

    clrtestEvents = []
    for providerNode in tree.getElementsByTagName('provider'):
        templateNodes = providerNode.getElementsByTagName('template')
        allTemplates  = parseTemplateNodes(templateNodes)
        eventNodes = providerNode.getElementsByTagName('event')
        for eventNode in eventNodes:
            eventName    = eventNode.getAttribute('symbol')
            templateName = eventNode.getAttribute('template')
            clrtestEvents.append(" EventXplatEnabled" + eventName + "();\n")
            clrtestEvents.append("Error |= FireEtXplat" + eventName + "(\n")

            line =[]
            if templateName:
                template = allTemplates[templateName]
                fnSig = template.signature

                for params in fnSig.paramlist:
                    if params in template.structs:
                        line.append("sizeof(Struct1),\n")

                    argline =''
                    fnparam     = fnSig.getParam(params)
                    if fnparam.name.lower() == 'count':
                        argline = '2'
                    else:
                        if fnparam.winType == "win:Binary":
                            argline = 'win_Binary'
                        elif fnparam.winType == "win:Pointer" and fnparam.count == "win:count":
                            argline = "(const void**)&var11"
                        elif fnparam.winType == "win:Pointer" :
                            argline = "(const void*)var11"
                        elif fnparam.winType =="win:AnsiString":
                            argline    = '" Testing AniString "'
                        elif fnparam.winType =="win:UnicodeString":
                            argline    = 'W(" Testing UnicodeString ")'
                        else:
                            if fnparam.count == "win:count":
                                line.append("&")

                            argline = fnparam.winType.replace(":","_")

                    line.append(argline)
                    line.append(",\n")

                #remove trailing commas
                if len(line) > 0:
                    del line[-1]
                    line.append("\n")
            line.append(");\n")
            clrtestEvents.extend(line)

    return ''.join(clrtestEvents)

def generateSanityTest(sClrEtwAllMan,testDir):

    if not os.path.exists(testDir):
        os.makedirs(testDir)

    test_cpp   = testDir + "/clralltestevents.cpp"
    testinfo   = testDir + "/testinfo.dat"

    with open_for_update(testinfo) as Testinfo:
        Testinfo.write("""
Copyright (c) Microsoft Corporation.  All rights reserved.
#

Version = 1.0
Section = EventProvider
Function = EventProvider
Name = PAL test for FireEtW* and EventEnabled* functions
TYPE = DEFAULT
EXE1 = eventprovidertest
Description = This is a sanity test to check that there are no crashes in Xplat eventing
""")

    #Test.cpp
    with open_for_update(test_cpp) as Test_cpp:
        Test_cpp.write(stdprolog)
        Test_cpp.write("""
/*=====================================================================
**
** Source:   clralltestevents.cpp
**
** Purpose:  Ensure Correctness of Eventing code
**
**
**===================================================================*/
#if FEATURE_PAL
#include <palsuite.h>
#endif //FEATURE_PAL
#include <clrxplatevents.h>

typedef struct _Struct1 {
                ULONG   Data1;
                unsigned short Data2;
                unsigned short Data3;
                unsigned char  Data4[8];
} Struct1;

Struct1 var21[2] = { { 245, 13, 14, "deadbea" }, { 542, 0, 14, "deadflu" } };

Struct1* var11 = var21;
Struct1* win_Struct = var21;

GUID win_GUID ={ 245, 13, 14, "deadbea" };
double win_Double =34.04;
ULONG win_ULong = 34;
BOOL win_Boolean = FALSE;
unsigned __int64 win_UInt64 = 114;
unsigned int win_UInt32 = 4;
unsigned short win_UInt16 = 12;
unsigned char win_UInt8 = 9;
int win_Int32 = 12;
BYTE* win_Binary =(BYTE*)var21 ;
int __cdecl main(int argc, char **argv)
{
#if defined(FEATURE_PAL)
            /* Initialize the PAL.
            */

            if(0 != PAL_Initialize(argc, argv))
            {
            return FAIL;
            }
#endif

            ULONG Error = ERROR_SUCCESS;
#if defined(FEATURE_EVENT_TRACE)
            Trace("\\n Starting functional  eventing APIs tests  \\n");
""")

        Test_cpp.write(generateClralltestEvents(sClrEtwAllMan))
        Test_cpp.write("""

        if (Error != ERROR_SUCCESS)
        {
            Fail("One or more eventing Apis failed\\n ");
            return FAIL;
        }
        Trace("\\n All eventing APIs were fired succesfully \\n");
#endif //defined(FEATURE_EVENT_TRACE)
#if defined(FEATURE_PAL)

/* Shutdown the PAL.
*/

        PAL_Terminate();
#endif
        return PASS;
                                }

""")
    Testinfo.close()


import argparse
import sys

def main(argv):

    #parse the command line
    parser = argparse.ArgumentParser(description="Generates the Code required to instrument LTTtng logging mechanism")

    required = parser.add_argument_group('required arguments')
    required.add_argument('--man',  type=str, required=True,
                                    help='full path to manifest containig the description of events')
    required.add_argument('--testdir', type=str, required=True,
                                    help='full path to directory where the test assets will be deployed' )
    args, unknown = parser.parse_known_args(argv)
    if unknown:
        print('Unknown argument(s): ', ', '.join(unknown))
        return 1

    sClrEtwAllMan     = args.man
    testDir           = args.testdir

    generateSanityTest(sClrEtwAllMan, testDir)

if __name__ == '__main__':
    return_code = main(sys.argv[1:])
    sys.exit(return_code)