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.

251 lines
7.0 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. tprofile.c
  5. Abstract:
  6. User-mode test for profile object.
  7. Note, this will be added to TEX.C
  8. Author:
  9. Lou Perazzoli (loup) 24-Sep-1990
  10. Revision History:
  11. --*/
  12. #include <nt.h>
  13. main()
  14. {
  15. HANDLE Profile, Profile2;
  16. ULONG Hack;
  17. PULONG Buffer;
  18. HANDLE CurrentProcessHandle;
  19. ULONG Size1;
  20. NTSTATUS status;
  21. Buffer = &Hack;
  22. CurrentProcessHandle = NtCurrentProcess();
  23. status = NtCreateProfile (&Profile,
  24. CurrentProcessHandle,
  25. NULL,
  26. 0xFFFFFFFF,
  27. 16,
  28. Buffer,
  29. (ULONG)64*1024,
  30. ProfileTime,
  31. (KAFFINITY)-1);
  32. if (status != STATUS_SUCCESS) {
  33. DbgPrint("(Expected) create profile #1 failed - status %lx\n", status);
  34. }
  35. status = NtStartProfile (Profile);
  36. if (status != STATUS_SUCCESS) {
  37. DbgPrint("(Expected) start profile #1 failed - status %lx\n", status);
  38. }
  39. status = NtStopProfile (Profile);
  40. if (status != STATUS_SUCCESS) {
  41. DbgPrint("(Expected) stop profile #1 failed - status %lx\n", status);
  42. }
  43. Size1 = 1024*64;
  44. Buffer = NULL;
  45. status = NtAllocateVirtualMemory (CurrentProcessHandle, (PVOID *)&Buffer,
  46. 0, &Size1, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
  47. //
  48. // This should fail as buffersize is too small.
  49. //
  50. status = NtCreateProfile (&Profile,
  51. NtCurrentProcess(),
  52. NULL,
  53. 0xFFFFFFFF,
  54. 16,
  55. Buffer,
  56. (ULONG)64*1024,
  57. ProfileTime,
  58. (KAFFINITY)-1);
  59. if (status != STATUS_SUCCESS) {
  60. DbgPrint("(Expected) create profile #2 failed - status %lx\n", status);
  61. }
  62. status = NtStartProfile (Profile);
  63. if (status != STATUS_SUCCESS) {
  64. DbgPrint("(Expected) start profile #2 failed - status %lx\n", status);
  65. }
  66. status = NtStopProfile (Profile);
  67. if (status != STATUS_SUCCESS) {
  68. DbgPrint("(Expected) stop profile #2 failed - status %lx\n", status);
  69. }
  70. status = NtClose (Profile);
  71. //
  72. // This should succeed.
  73. //
  74. status = NtCreateProfile (&Profile,
  75. NtCurrentProcess(),
  76. NULL,
  77. 0xFFFFFFFF,
  78. 18,
  79. Buffer,
  80. (ULONG)64*1024,
  81. ProfileTime,
  82. (KAFFINITY)-1);
  83. if (status != STATUS_SUCCESS) {
  84. DbgPrint("(Unexpected) create profile #3 failed - status %lx\n", status);
  85. }
  86. status = NtStartProfile (Profile);
  87. if (status != STATUS_SUCCESS) {
  88. DbgPrint("(Unexpected) start profile #3 failed - status %lx\n", status);
  89. }
  90. status = NtStopProfile (Profile);
  91. if (status != STATUS_SUCCESS) {
  92. DbgPrint("(Unexpected) stop profile #3 failed - status %lx\n", status);
  93. }
  94. status = NtClose (Profile);
  95. //
  96. // Attempt to create a profile that can't work because the
  97. // address range is too big.
  98. //
  99. status = NtCreateProfile (&Profile,
  100. NtCurrentProcess(),
  101. (PVOID)0x203030,
  102. 0xffffffff,
  103. 6,
  104. Buffer,
  105. (ULONG)64*1024,
  106. ProfileTime,
  107. (KAFFINITY)-1);
  108. if (status != STATUS_SUCCESS) {
  109. DbgPrint("(Expected) create profile #4 failed - status %lx\n", status);
  110. }
  111. status = NtStartProfile (Profile);
  112. if (status != STATUS_SUCCESS) {
  113. DbgPrint("(Expected) start profile #4 failed - status %lx\n", status);
  114. }
  115. status = NtStopProfile (Profile);
  116. if (status != STATUS_SUCCESS) {
  117. DbgPrint("(Expected) stop profile #4 failed - status %lx\n", status);
  118. }
  119. status = NtClose (Profile);
  120. //
  121. // Attempt to create a sucessful profile.
  122. //
  123. status = NtCreateProfile (&Profile,
  124. NtCurrentProcess(),
  125. (PVOID)0x80000000,
  126. 0x7fffffff,
  127. 17,
  128. Buffer,
  129. (ULONG)64*1024,
  130. ProfileTime,
  131. (KAFFINITY)-1);
  132. if (status != STATUS_SUCCESS) {
  133. DbgPrint("(Unexpected) create profile #5 failed - status %lx\n", status);
  134. }
  135. status = NtStartProfile (Profile);
  136. if (status != STATUS_SUCCESS) {
  137. DbgPrint("(Unexpected) start profile #5 failed - status %lx\n", status);
  138. }
  139. status = NtStopProfile (Profile);
  140. if (status != STATUS_SUCCESS) {
  141. DbgPrint("(Unexpected) stop profile #5 failed - status %lx\n", status);
  142. }
  143. //
  144. // now start it again.
  145. //
  146. status = NtStartProfile (Profile);
  147. if (status != STATUS_SUCCESS) {
  148. DbgPrint("(Unexpected) start profile #6.1 failed - status %lx\n", status);
  149. }
  150. //
  151. // now start it again, should fail.
  152. //
  153. status = NtStartProfile (Profile);
  154. if (status != STATUS_SUCCESS) {
  155. DbgPrint("(Expected) start profile #6.2 failed - status %lx\n", status);
  156. }
  157. //
  158. // now create another one (using the same buffer).
  159. //
  160. status = NtCreateProfile (&Profile2,
  161. NtCurrentProcess(),
  162. NULL,
  163. 0x3000000,
  164. 15,
  165. Buffer,
  166. (ULONG)64*1024,
  167. ProfileTime,
  168. (KAFFINITY)-1);
  169. if (status != STATUS_SUCCESS) {
  170. DbgPrint("create profile #7 failed - status %lx\n", status);
  171. }
  172. status = NtStartProfile (Profile2);
  173. if (status != STATUS_SUCCESS) {
  174. DbgPrint("start profile #7.1 failed - status %lx\n", status);
  175. }
  176. status = NtStopProfile (Profile2);
  177. if (status != STATUS_SUCCESS) {
  178. DbgPrint("stop profile #7.2 failed - status %lx\n", status);
  179. }
  180. status = NtStopProfile (Profile2);
  181. if (status != STATUS_SUCCESS) {
  182. DbgPrint("(Expected) stop profile #7.3 failed - status %lx\n", status);
  183. }
  184. status = NtStartProfile (Profile2);
  185. if (status != STATUS_SUCCESS) {
  186. DbgPrint("start profile #7.4 failed - status %lx\n", status);
  187. }
  188. status = NtClose (Profile);
  189. if (status != STATUS_SUCCESS) {
  190. DbgPrint("close profile #7.5 failed - status %lx\n", status);
  191. }
  192. return status;
  193. }