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.

60 lines
1.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: exposes testing thread functions
  4. //
  5. //=============================================================================
  6. #ifndef TESTTHREAD_H
  7. #define TESTTHREAD_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "tier0/dbg.h"
  12. // test callback
  13. typedef void (STDCALL *TestFunc)(void *pv);
  14. // runs the test function
  15. DBG_INTERFACE void Test_RunTest(TestFunc func, void *pvArg);
  16. // call to give the test thread a chance to run
  17. // calling thread will block until the test thread yields
  18. // doesn't do anything if no tests are running
  19. DBG_INTERFACE void Test_RunFrame();
  20. // true if any tests are running, or have ran
  21. DBG_INTERFACE bool Test_IsActive();
  22. // sets that the test has failed
  23. DBG_INTERFACE void Test_SetFailed();
  24. // true if any tests have failed, due to an assert, warning, or explicit fail
  25. DBG_INTERFACE bool Test_HasFailed();
  26. // true if any tests have completed
  27. DBG_INTERFACE bool Test_HasFinished();
  28. // terminates the test thread
  29. DBG_INTERFACE void Test_TerminateThread();
  30. // the following functions should only be called from the test thread
  31. // yields to the main thread for a single frame
  32. // passing in is a count of the number of frames that have been yielded by this yield macro
  33. // can be used to assert if a test thread is blocked foor
  34. DBG_INTERFACE void TestThread_Yield();
  35. // utility functions to pause the test frame until the selected condition is true
  36. #define YIELD_UNTIL(x) { int iYieldCount = 0; while (!(x)) { TestThread_Yield(); iYieldCount++; if ( iYieldCount >= 100 ) { AssertMsg( false, #x ); break; } } }
  37. // use this like a while(1) loop, with break; to stop yielding
  38. #define YIELD_UNTIL_BREAK() for (; true; TestThread_Yield())
  39. // yields for a single frame
  40. #define YIELD_FRAME() { TestThread_Yield(); }
  41. #define YIELD_TWO_FRAMES() { TestThread_Yield(); TestThread_Yield(); }
  42. #endif // TESTTHREAD_H