Source code of Windows XP (NT5)
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.

140 lines
2.5 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. sched-test.cpp
  5. Abstract:
  6. This module tests the IIS Scheduler code
  7. Author:
  8. George V. Reilly (GeorgeRe) May-1999
  9. Project:
  10. Internet Servers Common Server DLL
  11. Revisions:
  12. --*/
  13. #include <acache.hxx>
  14. #include <issched.hxx>
  15. #include <irtlmisc.h>
  16. #include <dbgutil.h>
  17. #include <stdlib.h>
  18. #include <stdio.h>
  19. #include <stddef.h>
  20. #include <string.h>
  21. #include <ctype.h>
  22. #include <time.h>
  23. #ifndef _NO_TRACING_
  24. #include <initguid.h>
  25. DEFINE_GUID(SchedTestGuid,
  26. 0x7a09df80, 0x2dbf, 0x11d3, 0x88, 0x84, 0x00, 0x50, 0x04, 0x60, 0x50, 0x4c);
  27. #else
  28. DECLARE_DEBUG_VARIABLE();
  29. #endif
  30. DECLARE_DEBUG_PRINTS_OBJECT();
  31. #define MAX_WORK_ITEMS 10
  32. #define MAX_TESTS 5
  33. class CCookie
  34. {
  35. public:
  36. CCookie()
  37. : m_dwCookie(0),
  38. m_dwSleep(0)
  39. {}
  40. DWORD m_dwCookie;
  41. DWORD m_dwSleep;
  42. };
  43. CCookie g_aCookies[MAX_TESTS][MAX_WORK_ITEMS];
  44. VOID
  45. Callback(
  46. void* pvContext)
  47. {
  48. CCookie* pc = (CCookie*) pvContext;
  49. DBG_ASSERT(pc != NULL && pc >= &g_aCookies[0][0]);
  50. int nRow = (pc - &g_aCookies[0][0]) / MAX_WORK_ITEMS;
  51. int nCol = (pc - &g_aCookies[0][0]) % MAX_WORK_ITEMS;
  52. printf("\tCallback [%d][%d] starting, sleeping for %d ms\n",
  53. nRow, nCol, pc->m_dwSleep);
  54. Sleep(pc->m_dwSleep);
  55. printf("\tCallback [%d][%d] finishing\n", nRow, nCol);
  56. }
  57. void
  58. TestScheduler(
  59. int n,
  60. bool fFlush)
  61. {
  62. printf("Initializing TestScheduler %d, %sflush\n",
  63. n, fFlush ? "" : "no ");
  64. // Initialize the Scheduler
  65. InitializeIISRTL();
  66. #ifdef _NO_TRACING_
  67. SET_DEBUG_FLAGS(DEBUG_ERROR);
  68. CREATE_DEBUG_PRINT_OBJECT("sched-test");
  69. #else
  70. CREATE_DEBUG_PRINT_OBJECT("sched-test", SchedTestGuid);
  71. #endif
  72. int i;
  73. for (i = 0; i < MAX_WORK_ITEMS; i++)
  74. {
  75. g_aCookies[n][i].m_dwSleep = (i * 500 + 1);
  76. g_aCookies[n][i].m_dwCookie =
  77. ScheduleWorkItem(Callback, &g_aCookies[n][i], 100*i);
  78. DBG_ASSERT(g_aCookies[n][i].m_dwCookie != 0);
  79. printf("TestScheduler %d: ScheduleWorkItem(%d) = %u\n",
  80. n, i, g_aCookies[n][i].m_dwCookie);
  81. }
  82. Sleep(2000);
  83. if (fFlush)
  84. {
  85. for (i = MAX_WORK_ITEMS; --i >= 0; )
  86. RemoveWorkItem(g_aCookies[n][i].m_dwCookie);
  87. }
  88. DELETE_DEBUG_PRINT_OBJECT();
  89. TerminateIISRTL();
  90. printf("Terminated TestScheduler %d\n", n);
  91. }
  92. int __cdecl
  93. main(
  94. int argc,
  95. char **argv)
  96. {
  97. for (int n = 0; n < MAX_TESTS; ++n)
  98. TestScheduler(n, true);
  99. return 0;
  100. }