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.

317 lines
6.6 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996.
  5. //
  6. // File: ttunnel.cxx
  7. //
  8. // Contents: Utility for multi-thread tunnel tests
  9. //
  10. // Codework:
  11. //
  12. //--------------------------------------------------------------------------
  13. #include <pch.cxx>
  14. #pragma hdrstop
  15. #define TRKDATA_ALLOCATE // This is the main module, trigger trkwks.hxx to do definitions
  16. #include <trkwks.hxx>
  17. typedef struct
  18. {
  19. ULONG Vol;
  20. int file1;
  21. int file2;
  22. } PARAMS;
  23. class THREAD_FILE_NAME
  24. {
  25. public:
  26. THREAD_FILE_NAME(LPVOID pv)
  27. {
  28. PARAMS *params = (PARAMS*)pv;
  29. wsprintf(Name1, TEXT("%d"), params->file1);
  30. wsprintf(Name2, TEXT("%d"), params->file2);
  31. Vol = params->Vol;
  32. }
  33. TCHAR Name1[MAX_PATH];
  34. TCHAR Name2[MAX_PATH];
  35. ULONG Vol;
  36. };
  37. void
  38. PrintThreadId()
  39. {
  40. printf("[%d]", GetCurrentThreadId());
  41. }
  42. // dis app
  43. // --- ---
  44. // ren ren
  45. // ren cre
  46. // del cre
  47. // del ren
  48. //
  49. void
  50. CreateWithId( TCHAR * Name, CDomainRelativeObjId * pdroid )
  51. {
  52. CDomainRelativeObjId droidBirth;
  53. HANDLE h = CreateFile(
  54. Name,
  55. GENERIC_READ|GENERIC_WRITE,
  56. 0,
  57. NULL,
  58. CREATE_NEW,
  59. FILE_ATTRIBUTE_NORMAL,
  60. NULL );
  61. if (h!=INVALID_HANDLE_VALUE)
  62. {
  63. GetDroids(h, pdroid, &droidBirth, RGO_READ_OBJECTID);
  64. GetDroids(h, pdroid, &droidBirth, RGO_GET_OBJECTID);
  65. DelObjId( h );
  66. GetDroids(h, pdroid, &droidBirth, RGO_READ_OBJECTID);
  67. GetDroids(h, pdroid, &droidBirth, RGO_GET_OBJECTID);
  68. CloseHandle(h);
  69. }
  70. }
  71. void
  72. OpenById(ULONG Vol, const CDomainRelativeObjId & droidCurrent)
  73. {
  74. NTSTATUS Status;
  75. HANDLE h;
  76. Status = OpenFileById( Vol,
  77. droidCurrent.GetObjId(),
  78. SYNCHRONIZE | FILE_READ_ATTRIBUTES,
  79. 0,
  80. 0,
  81. &h );
  82. if ( NT_SUCCESS(Status) )
  83. {
  84. CloseHandle(h);
  85. }
  86. }
  87. DWORD
  88. WINAPI
  89. RenRen( LPVOID pvParam )
  90. {
  91. THREAD_FILE_NAME Names(pvParam);
  92. CDomainRelativeObjId droidCurrent;
  93. printf("RenRen( %s %s )\n", Names.Name1, Names.Name2);
  94. while (1)
  95. {
  96. PrintThreadId();
  97. CreateWithId( Names.Name1, &droidCurrent );
  98. OpenById( Names.Vol, droidCurrent );
  99. MoveFile( Names.Name1, Names.Name2 );
  100. OpenById( Names.Vol, droidCurrent );
  101. MoveFile( Names.Name2, Names.Name1 );
  102. OpenById( Names.Vol, droidCurrent );
  103. DeleteFile( Names.Name1 );
  104. OpenById( Names.Vol, droidCurrent );
  105. }
  106. return(0);
  107. }
  108. DWORD
  109. WINAPI
  110. RenCre( LPVOID pvParam )
  111. {
  112. THREAD_FILE_NAME Names(pvParam);
  113. CDomainRelativeObjId droidCurrent;
  114. printf("RenCre( %s %s )\n", Names.Name1, Names.Name2);
  115. while (1)
  116. {
  117. PrintThreadId();
  118. CreateWithId( Names.Name1, &droidCurrent );
  119. OpenById( Names.Vol, droidCurrent );
  120. MoveFile( Names.Name1, Names.Name2 );
  121. OpenById( Names.Vol, droidCurrent );
  122. CreateWithId( Names.Name1, &droidCurrent );
  123. OpenById( Names.Vol, droidCurrent );
  124. DeleteFile( Names.Name1 );
  125. DeleteFile( Names.Name2 );
  126. OpenById( Names.Vol, droidCurrent );
  127. }
  128. return(0);
  129. }
  130. DWORD
  131. WINAPI
  132. DelCre( LPVOID pvParam )
  133. {
  134. THREAD_FILE_NAME Names(pvParam);
  135. CDomainRelativeObjId droidCurrent;
  136. printf("DelCre( %s %s )\n", Names.Name1, Names.Name2);
  137. while (1)
  138. {
  139. PrintThreadId();
  140. CreateWithId( Names.Name1, &droidCurrent );
  141. OpenById( Names.Vol, droidCurrent );
  142. DeleteFile( Names.Name1 );
  143. OpenById( Names.Vol, droidCurrent );
  144. CreateWithId( Names.Name1, &droidCurrent );
  145. OpenById( Names.Vol, droidCurrent );
  146. DeleteFile( Names.Name1 );
  147. OpenById( Names.Vol, droidCurrent );
  148. }
  149. return(0);
  150. }
  151. DWORD
  152. WINAPI
  153. DelRen( LPVOID pvParam )
  154. {
  155. THREAD_FILE_NAME Names(pvParam);
  156. CDomainRelativeObjId droidCurrent;
  157. printf("DelRen( %s %s )\n", Names.Name1, Names.Name2);
  158. while (1)
  159. {
  160. PrintThreadId();
  161. CreateWithId( Names.Name1, &droidCurrent );
  162. OpenById( Names.Vol, droidCurrent );
  163. DeleteFile( Names.Name1 );
  164. OpenById( Names.Vol, droidCurrent );
  165. CreateWithId( Names.Name2, &droidCurrent );
  166. OpenById( Names.Vol, droidCurrent );
  167. MoveFile( Names.Name2, Names.Name1 );
  168. OpenById( Names.Vol, droidCurrent );
  169. }
  170. return(0);
  171. }
  172. LPTHREAD_START_ROUTINE pfn[8] = {
  173. RenRen,
  174. RenCre,
  175. DelRen,
  176. DelCre
  177. };
  178. #ifdef _UNICODE
  179. EXTERN_C void __cdecl wmain( int argc, wchar_t **argv )
  180. #else
  181. void __cdecl main( int argc, char **argv )
  182. #endif
  183. {
  184. HRESULT hr = S_OK;
  185. NTSTATUS status = 0;
  186. TrkDebugCreate( TRK_DBG_FLAGS_WRITE_TO_DBG | TRK_DBG_FLAGS_WRITE_TO_STDOUT, "TTunnel" );
  187. // Convert the option to upper case (options are case-insensitive).
  188. __try
  189. {
  190. PARAMS params[24];
  191. TCHAR tszDir[MAX_PATH];
  192. GetCurrentDirectory( sizeof(tszDir)/sizeof(tszDir[0]), tszDir );
  193. CharUpper(tszDir);
  194. for (int i=0;i<24;i++)
  195. {
  196. DWORD dw;
  197. params[i].Vol = tszDir[0]-TEXT('A');
  198. if (i<8)
  199. {
  200. // 8 threads on two files
  201. params[i].file1 = 0;
  202. params[i].file2 = 1;
  203. }
  204. else
  205. if (i<16)
  206. {
  207. // 8 threads on 4 pairs of files
  208. params[i].file1 = i/2; // 4 .. 7
  209. params[i].file2 = i/2+1; // 5 .. 8
  210. }
  211. else
  212. {
  213. // 8 threads on 8 pairs of files
  214. params[i].file1 = i+8;
  215. params[i].file2 = i+16;
  216. }
  217. if (i&1)
  218. {
  219. int s = params[i].file1;
  220. params[i].file1 = params[i].file2;
  221. params[i].file2 = s;
  222. }
  223. HANDLE h = CreateThread(0,NULL,pfn[i%4],&params[i],0,&dw);
  224. if (h)
  225. {
  226. CloseHandle(h);
  227. }
  228. }
  229. Sleep(INFINITE);
  230. }
  231. __except( BreakOnDebuggableException() )
  232. {
  233. hr = GetExceptionCode();
  234. }
  235. Exit:
  236. if( FAILED(hr) )
  237. printf( "HR = %08X\n", hr );
  238. return;
  239. } // main()