Counter Strike : Global Offensive Source Code
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.

234 lines
9.4 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. class ISteamClient;
  14. class ISteamUserStats;
  15. class ISteamGameServerStats;
  16. // used to pass arbitrary buffers full of data back to the external test
  17. typedef uint32 ExternalTestBuffer_t;
  18. static const ExternalTestBuffer_t k_unExternalTestBufferInvalid = 0;
  19. //-----------------------------------------------------------------------------
  20. // Purpose: Represents a single test client (game client or game server) inside
  21. // of a test.
  22. //-----------------------------------------------------------------------------
  23. class IExternalTestClient
  24. {
  25. public:
  26. virtual ~IExternalTestClient() {}
  27. virtual void *GetISteamGenericInterface( const char *pchInterfaceVersion ) = 0;
  28. virtual ISteamUserStats *GetISteamUserStats( const char *pchVersion ) = 0;
  29. virtual ISteamGameServerStats *GetISteamGameServerStats( const char *pchVersion ) = 0;
  30. virtual bool BYieldingAwaitNewCallback( void *pCallback, uint32 unCallbackSize, int nCallbackType ) = 0;
  31. virtual CSteamID GetSteamID() = 0;
  32. virtual void YieldingLogOff() = 0;
  33. virtual bool BYieldingLogOn() = 0;
  34. virtual bool BYieldingAwaitQueuedCallback( void * pCallback, uint32 unCallbackSize, int nCallbackType ) = 0;
  35. virtual void GetServerDetails( AppId_t *pnAppIdServed, uint32 *punIPGameServer, uint16 *pusPortGameServer, bool *pbSecure ) = 0;
  36. virtual bool BYieldingPrepareForApp( AppId_t unAppID ) = 0;
  37. // methods to manipulate friend/social stuff that isn't in ISteamFriends
  38. virtual void SetPersonaState( EPersonaState ePersonaState ) = 0;
  39. virtual void AddFriend( const CSteamID & steamIDFriend ) = 0;
  40. virtual void RemoveFriend( const CSteamID & steamIDFriend ) = 0;
  41. // Removes every queued callback for this client
  42. virtual void ClearCallbacks() = 0;
  43. // Sets this user as an admin in this universe
  44. virtual void YieldingSetAsAdmin() = 0;
  45. template< typename TCallback >
  46. inline bool BYieldingAwaitQueuedCallback( TCallback & callback ) { return BYieldingAwaitQueuedCallback( &callback, sizeof(TCallback), TCallback::k_iCallback ); }
  47. template< typename TCallback >
  48. inline bool BYieldingAwaitNewCallback( TCallback & callback ) { return BYieldingAwaitNewCallback( &callback, sizeof(TCallback), TCallback::k_iCallback ); }
  49. };
  50. //-----------------------------------------------------------------------------
  51. // Purpose: Helper functions for interacting with the steam client during tests
  52. //-----------------------------------------------------------------------------
  53. class IExternalTestUtils
  54. {
  55. public:
  56. virtual ~IExternalTestUtils() {}
  57. // creates a single user client that is logged into an optional gameserver
  58. virtual IExternalTestClient *YieldingCreateUserClient( IExternalTestClient *pGameserver ) = 0;
  59. // creates a single gameserver client at the specified (fake) IP addr and port
  60. virtual IExternalTestClient *YieldingCreateGameserverClient( uint32 unAddr, uint16 usPort ) = 0;
  61. // returns the ISteamClient object so the test can fetch other ISteam interfaces.
  62. virtual ISteamClient *SteamClient() = 0;
  63. // deploys the gctest dll at the current AppID. This is probably not useful outside of the
  64. // gctest tests.
  65. virtual void YieldingDeployGC( ) = 0;
  66. // takes down the gctest dll at the current app DI
  67. virtual void YieldingDownGC( ) = 0;
  68. // returns the app ID this test is running as
  69. virtual AppId_t GetAppId() = 0;
  70. // draws a dot in the output
  71. virtual void DrawProgressDot() = 0;
  72. // spews some text in the output
  73. virtual void EmitTestOutput( const char *pchMessage ) = 0;
  74. // used by the external test framework to clean up some things between
  75. // test cases. Test cases should not call this.
  76. virtual void YieldingResetBetweenTests() = 0;
  77. // Checks a bool condition and spews if it fails. If this fails the test
  78. // will be recorded as having failed.
  79. virtual bool BCheck( bool bCondition ) = 0;
  80. // Yields until the stress test is finished. If this test is running as a
  81. // regression test, this will return immediately.
  82. virtual void YieldingWaitForTestToFinish() = 0;
  83. // used by the external test framework to record test success/failure in
  84. // a file that buildbot can use to build reports. Tests should not call this directly.
  85. virtual void UpdateProgressFile( const char *pchTestName, const char *pchStatus ) = 0;
  86. // Returns true if the test that ran most recently (and might still be running) passed.
  87. virtual bool BLastTestPassed() = 0;
  88. // Called by a test to report that the test has reached the "running" state. This is only
  89. // useful in stress tests.
  90. virtual void MarkTestRunning() = 0;
  91. // Logs on a bunch of clients all at once and returns when they are all logged on.
  92. virtual bool BYieldingCreateUserClientBatch( IExternalTestClient **prClients, int cClients, IExternalTestClient *pGameserver ) = 0;
  93. // Logs on a bunch of gameservers all at once and returns when they are all logged on.
  94. virtual bool BYieldingCreateGameserverClientBatch( IExternalTestClient **prClients, int cClients ) = 0;
  95. // returns true if the test is finished
  96. virtual bool BIsStressTestFinished() = 0;
  97. // waits a single frame before resuming the test
  98. virtual void YieldingWaitOneFrame() = 0;
  99. // reports a stress test action success/failure
  100. virtual void ReportStressActionResult( uint32 unActionIndex, bool bResult, const char *pchFailureLocation ) = 0;
  101. // waits for the specified number of seconds to pass
  102. virtual void YieldingWaitForRealTime( uint32 unSeconds ) = 0;
  103. // deploys the specified zip file as the GC for the specified app ID
  104. virtual bool BYieldingGCDeploy( AppId_t appID, const char *pchGCZipFile ) = 0;
  105. // Downs the specified GC
  106. virtual bool BYieldingGCDown( AppId_t appID ) = 0;
  107. // Revives the specified GC
  108. virtual bool BYieldingGCRevive( AppId_t appID ) = 0;
  109. // Bounces the specified GC
  110. virtual bool BYieldingGCBounce( AppId_t appID ) = 0;
  111. // returns the universe the tests are running in
  112. virtual EUniverse GetUniverse() = 0;
  113. // returns the memory for a buffer
  114. virtual void *GetPvBuffer( ExternalTestBuffer_t unBuffer ) = 0;
  115. // returns the memory for a buffer
  116. virtual uint32 GetCubBuffer( ExternalTestBuffer_t unBuffer ) = 0;
  117. // makes a simulated WG request and returns the result
  118. virtual ExternalTestBuffer_t YieldingSimulateWGRequest( const CSteamID & actorID, const void *pvRequestKV, uint32 cubRequestKV ) = 0;
  119. // Verifies that there is no support ticket for the specified steam ID
  120. virtual void YieldingVerifyNoSupportTicket( const CSteamID & steamID ) = 0;
  121. // Verifies that there is a support event for the specified steam ID
  122. virtual void YieldingVerifySupportEventRecord( const CSteamID & victimID, const CSteamID & actorID, ESupportEvent eAction, GID_t gidTxn, const char *pchNote ) = 0;
  123. // forces an appinfo update for the specified app. (Pass invalid to use the default app ID
  124. virtual void ForceAppInfoUpdate( AppId_t appId ) = 0;
  125. // returns the stats KV section serialized as a buffer
  126. virtual ExternalTestBuffer_t GetAppInfoStats( AppId_t appId ) = 0;
  127. // makes a web request and returns the result
  128. virtual bool BYieldingHTTPRequest( int nWebMethod, const char *pchURL, const char *pchAPIKey, const CSteamID & steamID, ExternalTestBuffer_t *punBuffer, int *pnResultCode ) = 0;
  129. // returns the full path to the DLL that these tests are running from
  130. virtual const char *GetPchDllPath() = 0;
  131. // returns true if these tests are running in dev mode (i.e. the server was started with -etdev)
  132. virtual bool BIsDevMode() = 0;
  133. };
  134. //-----------------------------------------------------------------------------
  135. // Purpose: Functions for sending and receiving messages from the Game Coordinator
  136. // for this application
  137. //-----------------------------------------------------------------------------
  138. class IExternalTest
  139. {
  140. public:
  141. // returns the number of tests present in this DLL
  142. virtual uint32 GetTestCount() = 0;
  143. // returns the name of the specified test
  144. virtual const char *GetTestName( uint32 unTest ) = 0;
  145. // returns the short name (no suite prefix) of the specified test
  146. virtual const char *GetTestShortName( uint32 unTest ) = 0;
  147. // returns the suite of the specified test
  148. virtual const char *GetTestSuite( uint32 unTest ) = 0;
  149. // returns the flags for the specified test
  150. virtual uint32 GetTestFlags( uint32 unTest ) = 0;
  151. // runs the specified tests. The tests should run to completion
  152. // (yielding on a regular basis) and call pETestUtils->BCheck(false)
  153. // on failure
  154. virtual void BRunTests( uint32 *punTests, uint32 unTestCount, IExternalTestUtils * pETestUtils ) = 0;
  155. // Returns the name of a stress test action
  156. virtual const char *GetStressActionName( uint32 unAction ) = 0;
  157. };
  158. #define EXTERNALTEST_INTERFACE_VERSION "IExternalTest001"
  159. // flags set by individual tests
  160. static const uint32 k_unETFlag_ValidForStress = 1<<0;
  161. static const uint32 k_unETFlag_ValidForRegression = 1<<1;
  162. //-----------------------------------------------------------------------------
  163. // Purpose: Allows an external test DLL to export its ability to validate its
  164. // own allocations
  165. //-----------------------------------------------------------------------------
  166. class IExternalTestValidation
  167. {
  168. public:
  169. virtual void Validate( CValidator &validator, const char *pchName ) = 0;
  170. };
  171. #define EXTERNALTEST_VALIDATION_INTERFACE_VERSION "IExternalTestValidation001"
  172. #endif // IEXTERNALTEST