aboutsummaryrefslogtreecommitdiff
path: root/mp/src/public/iexternaltest.h
blob: 7417405607ee44d32fdf3c657e6b5349a620a177 (plain) (blame)
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: interface to external test DLLs
//
//=============================================================================

#ifndef IEXTERNALTEST
#define IEXTERNALTEST
#ifdef _WIN32
#pragma once
#endif

#include "steam/isteamfriends.h"
#include "clientenums.h"

// An equivalent to EConnectionPriority that can be used in
// external tests without needing to depend on Steam's version of the enum
enum EExternalTestConnectionPriority
{
	k_EExternalTestConnectionPriorityLow = 0,
	k_EExternalTestConnectionPriorityMedium = 1,
	k_EExternalTestConnectionPriorityHigh = 2,
};

// used to pass arbitrary buffers full of data back to the external test
typedef uint32 ExternalTestBuffer_t;
static const ExternalTestBuffer_t k_unExternalTestBufferInvalid = 0;


//-----------------------------------------------------------------------------
// Purpose: Represents a single test client (game client or game server) inside
//			of a test.
//-----------------------------------------------------------------------------
class IExternalTestClient
{
public:
	virtual ~IExternalTestClient() {}
	virtual void *GetISteamGenericInterface( const char *pchInterfaceVersion ) = 0;
	virtual ISteamUserStats *GetISteamUserStats( const char *pchVersion ) = 0;
	virtual ISteamGameServerStats *GetISteamGameServerStats( const char *pchVersion ) = 0;
	virtual CSteamID GetSteamID() = 0;
	virtual bool GetAccountName( char *pchBuf, int cchBuf ) = 0;

	virtual bool BLoggedOn() = 0;
	virtual void YieldingLogOff() = 0;
	virtual bool BYieldingLogOn() = 0;
	virtual void RequestAppInfoUpdate() = 0;
	virtual bool BGetAppInfoUpdateResult( EResult *peResult, uint32 *punAppsUpdated ) = 0;
	virtual void GetServerDetails( AppId_t *pnAppIdServed, uint32 *punIPGameServer, uint16 *pusPortGameServer, bool *pbSecure ) = 0;
	virtual bool BYieldingPrepareForApp( AppId_t unAppID ) = 0;
	virtual void SetConnectionPriority( EExternalTestConnectionPriority eConnectionPriority ) = 0;

	// methods to manipulate friend/social stuff that isn't in ISteamFriends
	virtual void SetPersonaState( EPersonaState ePersonaState ) = 0;
	virtual void AddFriend( const CSteamID & steamIDFriend ) = 0;
	virtual void RemoveFriend( const CSteamID & steamIDFriend ) = 0;

	// Removes every queued callback for this client
	virtual void ClearCallbacks() = 0;

	// Sets this user as an admin in this universe
	virtual void YieldingSetAsAdmin() = 0;

	// bans this user for the specified app ID
	virtual void YieldingBan( AppId_t unAppID, int nDeltaSeconds, bool bOneYearBan ) = 0;

	virtual bool BYieldingAwaitNewCallback( void *pCallback, uint32 unCallbackSize, int nCallbackType ) = 0;
	virtual bool BYieldingAwaitQueuedCallback( void * pCallback, uint32 unCallbackSize, int nCallbackType ) = 0;
	virtual bool BGetQueuedCallbackOfType( void * pCallback, uint32 unCallbackSize, int nCallbackType ) = 0;

	// Retrieves the current status of the API call. Returns false if the call is still in progress
	virtual bool BYieldingGetAPICallResult( SteamAPICall_t hSteamAPICall, void *pCallback, uint32 unCallbackSize, int nCallback, bool *pbAPICallFailed ) = 0;

	template< typename TCallback >
	inline bool BYieldingAwaitQueuedCallback( TCallback & callback ) { return BYieldingAwaitQueuedCallback( &callback, sizeof(TCallback), TCallback::k_iCallback ); }
	template< typename TCallback >
	inline bool BYieldingAwaitNewCallback( TCallback & callback ) { return BYieldingAwaitNewCallback( &callback, sizeof(TCallback), TCallback::k_iCallback ); }
	template< typename TCallback >
	inline bool BGetQueuedCallbackOfType( TCallback & callback ) { return BGetQueuedCallbackOfType( &callback, sizeof(TCallback), TCallback::k_iCallback ); }

	// more friends stuff that isnt in ISteamFriends
	virtual void SetIgnoreFriend( const CSteamID & steamIDFriend ) = 0;
};

//-----------------------------------------------------------------------------
// Purpose: Helper functions for interacting with the steam client during tests
//-----------------------------------------------------------------------------
class IExternalTestUtils
{
public:
	virtual ~IExternalTestUtils() {}

	// creates a single user client that is logged into an optional gameserver
	virtual IExternalTestClient *YieldingCreateUserClient( IExternalTestClient *pGameserver ) = 0;

	// creates a single gameserver client at the specified (fake) IP addr and port
	virtual IExternalTestClient *YieldingCreateGameserverClient( uint32 unAddr, uint16 usPort ) = 0;

	// returns the ISteamClient object so the test can fetch other ISteam interfaces.
	virtual ISteamClient *SteamClient() = 0;

	// deploys the gctest dll at the current AppID. This is probably not useful outside of the 
	// gctest tests.
	virtual void YieldingDeployGC( ) = 0;

	// takes down the gctest dll at the current app DI
	virtual void YieldingDownGC( ) = 0;

	// returns the app ID this test is running as
	virtual AppId_t GetAppId() = 0;

	// draws a dot in the output
	virtual void DrawProgressDot() = 0;

	// spews some text in the output
	virtual void EmitTestOutput( const char *pchMessage ) = 0;

	// used by the external test framework to clean up some things between 
	// test cases. Test cases should not call this.
	virtual void YieldingResetBetweenTests() = 0;

	// Checks a bool condition and spews if it fails. If this fails the test
	// will be recorded as having failed.
	virtual bool BCheck( bool bCondition ) = 0;

	// Yields until the stress test is finished. If this test is running as a
	// regression test, this will return immediately.
	virtual void YieldingWaitForTestToFinish() = 0;

	// used by the external test framework to record test success/failure in 
	// a file that buildbot can use to build reports. Tests should not call this directly.
	virtual void UpdateProgressFile( const char *pchTestName, const char *pchStatus ) = 0;

	// Returns true if the test that ran most recently (and might still be running) passed.
	virtual bool BLastTestPassed() = 0;

	// Called by a test to report that the test has reached the "running" state. This is only
	// useful in stress tests.
	virtual void MarkTestRunning() = 0;

	// Logs on a bunch of clients all at once and returns when they are all logged on.
	virtual bool BYieldingCreateUserClientBatch( IExternalTestClient **prClients, int cClients, EExternalTestConnectionPriority eConnectionPriority ) = 0;

	// Logs on a bunch of gameservers all at once and returns when they are all logged on.
	virtual bool BYieldingCreateGameserverClientBatch( IExternalTestClient **prClients, int cClients, EExternalTestConnectionPriority eConnectionPriority ) = 0;

	// returns true if the test is finished
	virtual bool BIsStressTestFinished() = 0;

	// waits a single frame before resuming the test
	virtual void YieldingWaitOneFrame() = 0;

	// reports a stress test action success/failure
	virtual void ReportStressActionResult( uint32 unActionIndex, bool bResult, const char *pchFailureLocation ) = 0;

	// waits for the specified number of seconds to pass
	virtual void YieldingWaitForRealTime( uint32 unSeconds ) = 0;

	// deploys the specified zip file as the GC for the specified app ID
	virtual bool BYieldingGCDeploy( AppId_t appID, const char *pchGCZipFile ) = 0;

	// Downs the specified GC
	virtual bool BYieldingGCDown( AppId_t appID ) = 0;

	// Revives the specified GC
	virtual bool BYieldingGCRevive( AppId_t appID ) = 0;

	// Bounces the specified GC
	virtual bool BYieldingGCBounce( AppId_t appID ) = 0;

	// returns the universe the tests are running in
	virtual EUniverse GetUniverse() = 0;

	// returns the memory for a buffer
	virtual void *GetPvBuffer( ExternalTestBuffer_t unBuffer ) = 0;

	// returns the memory for a buffer
	virtual uint32 GetCubBuffer( ExternalTestBuffer_t unBuffer ) = 0;

	// makes a simulated WG request and returns the result
	virtual ExternalTestBuffer_t YieldingSimulateWGRequest( const CSteamID & actorID, const void *pvRequestKV, uint32 cubRequestKV ) = 0;

	// Verifies that there is no support ticket for the specified steam ID
	virtual void YieldingVerifyNoSupportTicket( const CSteamID & steamID ) = 0;

	// Verifies that there is a support event for the specified steam ID
	virtual void YieldingVerifySupportEventRecord( const CSteamID & victimID, const CSteamID & actorID, ESupportEvent eAction, GID_t gidTxn, const char *pchNote ) = 0;

	// forces an appinfo update for the specified app. (Pass invalid to use the default app ID
	virtual void YieldingForceAppInfoUpdate( AppId_t appId ) = 0;

	// returns the stats KV section serialized as a buffer
	virtual ExternalTestBuffer_t YieldingGetAppInfoStats( AppId_t appId ) = 0;

	// makes a web request and returns the result
	virtual bool BYieldingHTTPRequest( int nWebMethod, bool bUseSSL, const char *pchURL, const KeyValues *pkvPostParams, const char *pchAPIKey, const CSteamID & steamID, ExternalTestBuffer_t *punBuffer, int *pnResultCode ) = 0;

	// returns the full path to the DLL that these tests are running from
	virtual const char *GetPchDllPath() = 0;

	// returns true if these tests are running in dev mode (i.e. the server was started with -etdev)
	virtual bool BIsDevMode() = 0;

	// Sets the persona name for this user via the wg call so we can actually tell when
	// it's been set.
	virtual bool BYieldingSetPersonaName( const CSteamID & steamID, const char *pchPersonaName ) = 0;

	// waits for the writeback queue to clear
	virtual bool BYieldingWaitForCacheWriteback() = 0;
};


//-----------------------------------------------------------------------------
// Purpose: Functions for sending and receiving messages from the Game Coordinator
//			for this application
//-----------------------------------------------------------------------------
class IExternalTest
{
public:

	// returns the number of tests present in this DLL
	virtual uint32 GetTestCount() = 0;

	// returns the name of the specified test
	virtual const char *GetTestName( uint32 unTest ) = 0;

	// returns the short name (no suite prefix) of the specified test
	virtual const char *GetTestShortName( uint32 unTest ) = 0;

	// returns the suite of the specified test
	virtual const char *GetTestSuite( uint32 unTest ) = 0;

	// returns the flags for the specified test
	virtual uint32 GetTestFlags( uint32 unTest ) = 0;

	// runs the specified tests. The tests should run to completion 
	// (yielding on a regular basis) and call pETestUtils->BCheck(false)
	// on failure
	virtual void BRunTests( uint32 *punTests, uint32 unTestCount, IExternalTestUtils * pETestUtils ) = 0;

	// Returns the name of a stress test action
	virtual const char *GetStressActionName( uint32 unAction ) = 0;

};
#define EXTERNALTEST_INTERFACE_VERSION "IExternalTest001"

// flags set by individual tests
static const uint32 k_unETFlag_ValidForStress		= 1<<0;
static const uint32 k_unETFlag_ValidForRegression	= 1<<1;


//-----------------------------------------------------------------------------
// Purpose: For one time init of an externaltests dll
//-----------------------------------------------------------------------------
class IExternalTestInitialize
{
public:
	virtual bool BDoBundleInit() = 0;	// called once *PER ATS* at DLL Load time
	virtual bool BDoOneTimeInit( IExternalTestUtils *pExternalTestUtils ) = 0; // called once PER TEST RUN by ATS0
	virtual bool BDoPerATSInit( IExternalTestUtils *pExternalTestUtils ) = 0; // called once PER TEST RUN PER ATS
	virtual void Cleanup() = 0;
};
#define EXTERNALTEST_INITIALIZE_INTERFACE_VERSION "IExternalTestInitialize001"


//-----------------------------------------------------------------------------
// Purpose: Allows an external test DLL to export its ability to validate its 
// own allocations
//-----------------------------------------------------------------------------
class IExternalTestValidation
{
public:

	virtual void Validate( CValidator &validator, const char *pchName ) = 0;
};
#define EXTERNALTEST_VALIDATION_INTERFACE_VERSION "IExternalTestValidation001"


#endif // IEXTERNALTEST