Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

279 lines
12 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: interface to external test DLLs
  4. //
  5. //=============================================================================
  6. #ifndef IEXTERNALTEST
  7. #define IEXTERNALTEST
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "steam/isteamfriends.h"
  12. #include "clientenums.h"
  13. // An equivalent to EConnectionPriority that can be used in
  14. // external tests without needing to depend on Steam's version of the enum
  15. enum EExternalTestConnectionPriority
  16. {
  17. k_EExternalTestConnectionPriorityLow = 0,
  18. k_EExternalTestConnectionPriorityMedium = 1,
  19. k_EExternalTestConnectionPriorityHigh = 2,
  20. };
  21. // used to pass arbitrary buffers full of data back to the external test
  22. typedef uint32 ExternalTestBuffer_t;
  23. static const ExternalTestBuffer_t k_unExternalTestBufferInvalid = 0;
  24. //-----------------------------------------------------------------------------
  25. // Purpose: Represents a single test client (game client or game server) inside
  26. // of a test.
  27. //-----------------------------------------------------------------------------
  28. class IExternalTestClient
  29. {
  30. public:
  31. virtual ~IExternalTestClient() {}
  32. virtual void *GetISteamGenericInterface( const char *pchInterfaceVersion ) = 0;
  33. virtual ISteamUserStats *GetISteamUserStats( const char *pchVersion ) = 0;
  34. virtual ISteamGameServerStats *GetISteamGameServerStats( const char *pchVersion ) = 0;
  35. virtual CSteamID GetSteamID() = 0;
  36. virtual bool GetAccountName( char *pchBuf, int cchBuf ) = 0;
  37. virtual bool BLoggedOn() = 0;
  38. virtual void YieldingLogOff() = 0;
  39. virtual bool BYieldingLogOn() = 0;
  40. virtual void RequestAppInfoUpdate() = 0;
  41. virtual bool BGetAppInfoUpdateResult( EResult *peResult, uint32 *punAppsUpdated ) = 0;
  42. virtual void GetServerDetails( AppId_t *pnAppIdServed, uint32 *punIPGameServer, uint16 *pusPortGameServer, bool *pbSecure ) = 0;
  43. virtual bool BYieldingPrepareForApp( AppId_t unAppID ) = 0;
  44. virtual void SetConnectionPriority( EExternalTestConnectionPriority eConnectionPriority ) = 0;
  45. // methods to manipulate friend/social stuff that isn't in ISteamFriends
  46. virtual void SetPersonaState( EPersonaState ePersonaState ) = 0;
  47. virtual void AddFriend( const CSteamID & steamIDFriend ) = 0;
  48. virtual void RemoveFriend( const CSteamID & steamIDFriend ) = 0;
  49. // Removes every queued callback for this client
  50. virtual void ClearCallbacks() = 0;
  51. // Sets this user as an admin in this universe
  52. virtual void YieldingSetAsAdmin() = 0;
  53. // bans this user for the specified app ID
  54. virtual void YieldingBan( AppId_t unAppID, int nDeltaSeconds, bool bOneYearBan ) = 0;
  55. virtual bool BYieldingAwaitNewCallback( void *pCallback, uint32 unCallbackSize, int nCallbackType ) = 0;
  56. virtual bool BYieldingAwaitQueuedCallback( void * pCallback, uint32 unCallbackSize, int nCallbackType ) = 0;
  57. virtual bool BGetQueuedCallbackOfType( void * pCallback, uint32 unCallbackSize, int nCallbackType ) = 0;
  58. // Retrieves the current status of the API call. Returns false if the call is still in progress
  59. virtual bool BYieldingGetAPICallResult( SteamAPICall_t hSteamAPICall, void *pCallback, uint32 unCallbackSize, int nCallback, bool *pbAPICallFailed ) = 0;
  60. template< typename TCallback >
  61. inline bool BYieldingAwaitQueuedCallback( TCallback & callback ) { return BYieldingAwaitQueuedCallback( &callback, sizeof(TCallback), TCallback::k_iCallback ); }
  62. template< typename TCallback >
  63. inline bool BYieldingAwaitNewCallback( TCallback & callback ) { return BYieldingAwaitNewCallback( &callback, sizeof(TCallback), TCallback::k_iCallback ); }
  64. template< typename TCallback >
  65. inline bool BGetQueuedCallbackOfType( TCallback & callback ) { return BGetQueuedCallbackOfType( &callback, sizeof(TCallback), TCallback::k_iCallback ); }
  66. // more friends stuff that isnt in ISteamFriends
  67. virtual void SetIgnoreFriend( const CSteamID & steamIDFriend ) = 0;
  68. };
  69. //-----------------------------------------------------------------------------
  70. // Purpose: Helper functions for interacting with the steam client during tests
  71. //-----------------------------------------------------------------------------
  72. class IExternalTestUtils
  73. {
  74. public:
  75. virtual ~IExternalTestUtils() {}
  76. // creates a single user client that is logged into an optional gameserver
  77. virtual IExternalTestClient *YieldingCreateUserClient( IExternalTestClient *pGameserver ) = 0;
  78. // creates a single gameserver client at the specified (fake) IP addr and port
  79. virtual IExternalTestClient *YieldingCreateGameserverClient( uint32 unAddr, uint16 usPort ) = 0;
  80. // returns the ISteamClient object so the test can fetch other ISteam interfaces.
  81. virtual ISteamClient *SteamClient() = 0;
  82. // deploys the gctest dll at the current AppID. This is probably not useful outside of the
  83. // gctest tests.
  84. virtual void YieldingDeployGC( ) = 0;
  85. // takes down the gctest dll at the current app DI
  86. virtual void YieldingDownGC( ) = 0;
  87. // returns the app ID this test is running as
  88. virtual AppId_t GetAppId() = 0;
  89. // draws a dot in the output
  90. virtual void DrawProgressDot() = 0;
  91. // spews some text in the output
  92. virtual void EmitTestOutput( const char *pchMessage ) = 0;
  93. // used by the external test framework to clean up some things between
  94. // test cases. Test cases should not call this.
  95. virtual void YieldingResetBetweenTests() = 0;
  96. // Checks a bool condition and spews if it fails. If this fails the test
  97. // will be recorded as having failed.
  98. virtual bool BCheck( bool bCondition ) = 0;
  99. // Yields until the stress test is finished. If this test is running as a
  100. // regression test, this will return immediately.
  101. virtual void YieldingWaitForTestToFinish() = 0;
  102. // used by the external test framework to record test success/failure in
  103. // a file that buildbot can use to build reports. Tests should not call this directly.
  104. virtual void UpdateProgressFile( const char *pchTestName, const char *pchStatus ) = 0;
  105. // Returns true if the test that ran most recently (and might still be running) passed.
  106. virtual bool BLastTestPassed() = 0;
  107. // Called by a test to report that the test has reached the "running" state. This is only
  108. // useful in stress tests.
  109. virtual void MarkTestRunning() = 0;
  110. // Logs on a bunch of clients all at once and returns when they are all logged on.
  111. virtual bool BYieldingCreateUserClientBatch( IExternalTestClient **prClients, int cClients, EExternalTestConnectionPriority eConnectionPriority ) = 0;
  112. // Logs on a bunch of gameservers all at once and returns when they are all logged on.
  113. virtual bool BYieldingCreateGameserverClientBatch( IExternalTestClient **prClients, int cClients, EExternalTestConnectionPriority eConnectionPriority ) = 0;
  114. // returns true if the test is finished
  115. virtual bool BIsStressTestFinished() = 0;
  116. // waits a single frame before resuming the test
  117. virtual void YieldingWaitOneFrame() = 0;
  118. // reports a stress test action success/failure
  119. virtual void ReportStressActionResult( uint32 unActionIndex, bool bResult, const char *pchFailureLocation ) = 0;
  120. // waits for the specified number of seconds to pass
  121. virtual void YieldingWaitForRealTime( uint32 unSeconds ) = 0;
  122. // deploys the specified zip file as the GC for the specified app ID
  123. virtual bool BYieldingGCDeploy( AppId_t appID, const char *pchGCZipFile ) = 0;
  124. // Downs the specified GC
  125. virtual bool BYieldingGCDown( AppId_t appID ) = 0;
  126. // Revives the specified GC
  127. virtual bool BYieldingGCRevive( AppId_t appID ) = 0;
  128. // Bounces the specified GC
  129. virtual bool BYieldingGCBounce( AppId_t appID ) = 0;
  130. // returns the universe the tests are running in
  131. virtual EUniverse GetUniverse() = 0;
  132. // returns the memory for a buffer
  133. virtual void *GetPvBuffer( ExternalTestBuffer_t unBuffer ) = 0;
  134. // returns the memory for a buffer
  135. virtual uint32 GetCubBuffer( ExternalTestBuffer_t unBuffer ) = 0;
  136. // makes a simulated WG request and returns the result
  137. virtual ExternalTestBuffer_t YieldingSimulateWGRequest( const CSteamID & actorID, const void *pvRequestKV, uint32 cubRequestKV ) = 0;
  138. // Verifies that there is no support ticket for the specified steam ID
  139. virtual void YieldingVerifyNoSupportTicket( const CSteamID & steamID ) = 0;
  140. // Verifies that there is a support event for the specified steam ID
  141. virtual void YieldingVerifySupportEventRecord( const CSteamID & victimID, const CSteamID & actorID, ESupportEvent eAction, GID_t gidTxn, const char *pchNote ) = 0;
  142. // forces an appinfo update for the specified app. (Pass invalid to use the default app ID
  143. virtual void YieldingForceAppInfoUpdate( AppId_t appId ) = 0;
  144. // returns the stats KV section serialized as a buffer
  145. virtual ExternalTestBuffer_t YieldingGetAppInfoStats( AppId_t appId ) = 0;
  146. // makes a web request and returns the result
  147. 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;
  148. // returns the full path to the DLL that these tests are running from
  149. virtual const char *GetPchDllPath() = 0;
  150. // returns true if these tests are running in dev mode (i.e. the server was started with -etdev)
  151. virtual bool BIsDevMode() = 0;
  152. // Sets the persona name for this user via the wg call so we can actually tell when
  153. // it's been set.
  154. virtual bool BYieldingSetPersonaName( const CSteamID & steamID, const char *pchPersonaName ) = 0;
  155. // waits for the writeback queue to clear
  156. virtual bool BYieldingWaitForCacheWriteback() = 0;
  157. };
  158. //-----------------------------------------------------------------------------
  159. // Purpose: Functions for sending and receiving messages from the Game Coordinator
  160. // for this application
  161. //-----------------------------------------------------------------------------
  162. class IExternalTest
  163. {
  164. public:
  165. // returns the number of tests present in this DLL
  166. virtual uint32 GetTestCount() = 0;
  167. // returns the name of the specified test
  168. virtual const char *GetTestName( uint32 unTest ) = 0;
  169. // returns the short name (no suite prefix) of the specified test
  170. virtual const char *GetTestShortName( uint32 unTest ) = 0;
  171. // returns the suite of the specified test
  172. virtual const char *GetTestSuite( uint32 unTest ) = 0;
  173. // returns the flags for the specified test
  174. virtual uint32 GetTestFlags( uint32 unTest ) = 0;
  175. // runs the specified tests. The tests should run to completion
  176. // (yielding on a regular basis) and call pETestUtils->BCheck(false)
  177. // on failure
  178. virtual void BRunTests( uint32 *punTests, uint32 unTestCount, IExternalTestUtils * pETestUtils ) = 0;
  179. // Returns the name of a stress test action
  180. virtual const char *GetStressActionName( uint32 unAction ) = 0;
  181. };
  182. #define EXTERNALTEST_INTERFACE_VERSION "IExternalTest001"
  183. // flags set by individual tests
  184. static const uint32 k_unETFlag_ValidForStress = 1<<0;
  185. static const uint32 k_unETFlag_ValidForRegression = 1<<1;
  186. //-----------------------------------------------------------------------------
  187. // Purpose: For one time init of an externaltests dll
  188. //-----------------------------------------------------------------------------
  189. class IExternalTestInitialize
  190. {
  191. public:
  192. virtual bool BDoBundleInit() = 0; // called once *PER ATS* at DLL Load time
  193. virtual bool BDoOneTimeInit( IExternalTestUtils *pExternalTestUtils ) = 0; // called once PER TEST RUN by ATS0
  194. virtual bool BDoPerATSInit( IExternalTestUtils *pExternalTestUtils ) = 0; // called once PER TEST RUN PER ATS
  195. virtual void Cleanup() = 0;
  196. };
  197. #define EXTERNALTEST_INITIALIZE_INTERFACE_VERSION "IExternalTestInitialize001"
  198. //-----------------------------------------------------------------------------
  199. // Purpose: Allows an external test DLL to export its ability to validate its
  200. // own allocations
  201. //-----------------------------------------------------------------------------
  202. class IExternalTestValidation
  203. {
  204. public:
  205. virtual void Validate( CValidator &validator, const char *pchName ) = 0;
  206. };
  207. #define EXTERNALTEST_VALIDATION_INTERFACE_VERSION "IExternalTestValidation001"
  208. #endif // IEXTERNALTEST