Leaked source code of windows server 2003
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.

70 lines
1.9 KiB

  1. Randfail can be used to introduce "random" failures into debug builds in
  2. order to test the error paths of your code. This is done by causing certain
  3. Win32 APIs to fail, or by instrumenting your code.
  4. The following Win32 APIs will be instrumented in a debug build:
  5. CreateDirectory
  6. CreateDirectoryEx
  7. CreateEvent
  8. CreateFile
  9. CreateFileMapping
  10. CreateIoCompletionPort
  11. CreateMutex
  12. CreateProcess
  13. CreateSemaphore
  14. CreateThread
  15. GetQueuedCompletionStatus
  16. OpenEvent
  17. OpenFileMapping
  18. OpenMutex
  19. OpenProcess
  20. OpenSemaphore
  21. PostQueuedCompletionStatus
  22. ReadFile
  23. WriteFile
  24. When an instrumented Win32 API fails, it will return the failure indicated
  25. by the documentation, but will also SetLastError(ERROR_ARENA_TRASHED).
  26. INSTRUMENTING YOUR CODE
  27. In order for your code to use this library, you must include "randfail.h"
  28. AFTER any other include files. Also, you must link with exstrace.lib
  29. and call InitAsyncTrace(). By default, the failure of Win32 APIs is
  30. enabled. If you wish to suppress this behavior, define the
  31. preprocessor symbol NOFAIL_WIN32API.
  32. User code may also be instrumented. To determine if the failure path should
  33. be taken, call fTimeToFail(). For example:
  34. #include <windows.h>
  35. #include "randfail.h"
  36. BOOL bOK;
  37. if (fTimeToFail()) {
  38. bOK = FALSE;
  39. } else {
  40. bOK = fMyFunction();
  41. }
  42. if (!bOK) {
  43. // Handle the error here
  44. }
  45. To suppress the failures in user instrumented code, define NOFAIL_RANDOM.
  46. ENABLING RANDOM FAILURES DURING EXECUTION
  47. Before executing your program, you must set the frequency in which you
  48. wish failures to occur in the registry. Create the following key:
  49. SOFTWARE\Microsoft\MosTrace\CurrentVersion\DebugAsyncTrace
  50. FailureRate REG_DWORD nn
  51. where nn is the frequency you wish the errors to occur (every nn calls
  52. to an instrumented api.) To disable the failures, either delete the
  53. key or set it to zero.