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.

320 lines
7.7 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. ttask.c
  5. Abstract:
  6. Test program for Win32 Base File API calls
  7. Author:
  8. Mark Lucovsky (markl) 26-Sep-1990
  9. Revision History:
  10. --*/
  11. #include <assert.h>
  12. #include <stdio.h>
  13. #include <windows.h>
  14. #include <string.h>
  15. typedef struct _CMDSHOW {
  16. WORD wMustBe2;
  17. WORD wShowWindowValue;
  18. } CMDSHOW, *PCMDSHOW;
  19. typedef struct _LOAD_MODULE_PARAMS {
  20. LPSTR lpEnvAddress;
  21. LPSTR lpCmdLine;
  22. PCMDSHOW lpCmdShow;
  23. DWORD dwReserved;
  24. } LOAD_MODULE_PARAMS, *PLOAD_MODULE_PARAMS;
  25. HANDLE Event1, Event2;
  26. VOID
  27. WaitTestThread(
  28. LPVOID ThreadParameter
  29. )
  30. {
  31. DWORD st;
  32. printf("In Test Thread... Parameter %ld\n",ThreadParameter);
  33. assert(SetEvent(Event1));
  34. st = WaitForSingleObject(Event2,-1);
  35. assert(st == 0);
  36. printf("Test Thread Exiting... Parameter %ld\n",ThreadParameter);
  37. ExitThread((DWORD)ThreadParameter);
  38. }
  39. VOID
  40. TestThread(
  41. LPVOID ThreadParameter
  42. )
  43. {
  44. LPSTR s;
  45. SYSTEMTIME DateAndTime;
  46. CHAR ImageName[256];
  47. STARTUPINFO StartupInfo;
  48. PROCESS_INFORMATION ProcessInformation;
  49. printf("In Test Thread... Parameter %ld\n",ThreadParameter);
  50. GetSystemTime(&DateAndTime);
  51. printf("%d/%d/%d @ %d:%d.%d\n",
  52. DateAndTime.wMonth,
  53. DateAndTime.wDay,
  54. DateAndTime.wYear,
  55. DateAndTime.wHour,
  56. DateAndTime.wMinute,
  57. DateAndTime.wSecond
  58. );
  59. DateAndTime.wMonth = 3;
  60. DateAndTime.wDay = 23;
  61. DateAndTime.wYear = 1961;
  62. DateAndTime.wHour = 7;
  63. DateAndTime.wMinute = 31;
  64. DateAndTime.wSecond = 0;
  65. #if 0
  66. assert(SetSystemTime(&DateAndTime));
  67. GetSystemTime(&DateAndTime);
  68. assert(DateAndTime.wMonth == 3);
  69. assert(DateAndTime.wDay == 23);
  70. assert(DateAndTime.wYear == 1961);
  71. assert(DateAndTime.wHour == 7);
  72. DateAndTime.wMonth = 13;
  73. assert(!SetSystemTime(&DateAndTime));
  74. printf("%s\n",GetCommandLine());
  75. assert(SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_HIGHEST));
  76. assert(GetThreadPriority(GetCurrentThread()) == THREAD_PRIORITY_HIGHEST);
  77. assert(SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_LOWEST));
  78. assert(GetThreadPriority(GetCurrentThread()) == THREAD_PRIORITY_LOWEST);
  79. assert(SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_ABOVE_NORMAL));
  80. assert(GetThreadPriority(GetCurrentThread()) == THREAD_PRIORITY_ABOVE_NORMAL);
  81. assert(SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_BELOW_NORMAL));
  82. assert(GetThreadPriority(GetCurrentThread()) == THREAD_PRIORITY_BELOW_NORMAL);
  83. assert(SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_NORMAL));
  84. assert(GetThreadPriority(GetCurrentThread()) == THREAD_PRIORITY_NORMAL);
  85. assert(!SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_HIGHEST+1));
  86. assert(GetThreadPriority(GetCurrentProcess()) == THREAD_PRIORITY_ERROR_RETURN);
  87. assert(GetModuleFileName(0,ImageName,256) < 255);
  88. StartupInfo.cb = sizeof(StartupInfo);
  89. StartupInfo.lpReserved = "UsedByShell";
  90. StartupInfo.lpDesktop = "MarksDesktop";
  91. StartupInfo.lpTitle = "MarksTestTitle";
  92. StartupInfo.dwX = 0;
  93. StartupInfo.dwY = 1;
  94. StartupInfo.dwXSize = 10;
  95. StartupInfo.dwYSize = 10;
  96. StartupInfo.dwFlags = 0;//STARTF_SHELLOVERRIDE;
  97. StartupInfo.wShowWindow = 0;//SW_SHOWDEFAULT;
  98. StartupInfo.lpReserved2 = 0;
  99. StartupInfo.cbReserved2 = 0;
  100. assert( CreateProcess(
  101. NULL,
  102. "ttask +",
  103. NULL,
  104. NULL,
  105. TRUE,
  106. 0,
  107. NULL,
  108. NULL,
  109. &StartupInfo,
  110. &ProcessInformation
  111. ) );
  112. WaitForSingleObject(ProcessInformation.hProcess,-1);
  113. #endif
  114. ExitThread((DWORD)ThreadParameter);
  115. }
  116. DWORD
  117. main(
  118. int argc,
  119. char *argv[],
  120. char *envp[]
  121. )
  122. {
  123. CRITICAL_SECTION Crit;
  124. HANDLE Event, Semaphore, Mutex, Thread, Process;
  125. HANDLE NEvent, NSemaphore, NMutex;
  126. HANDLE OEvent, OSemaphore, OMutex;
  127. DWORD st;
  128. DWORD ThreadId;
  129. CHAR ImageName[256];
  130. CHAR CommandLine[256];
  131. CHAR Environment[256];
  132. CMDSHOW cs;
  133. LOAD_MODULE_PARAMS lmp;
  134. LPSTR *s;
  135. int i;
  136. DWORD psp;
  137. (VOID)envp;
  138. try {
  139. RaiseException(4,0,0,NULL);
  140. }
  141. except(EXCEPTION_EXECUTE_HANDLER){
  142. printf("In Handler %lx\n",GetExceptionCode());
  143. }
  144. i = 0;
  145. s = argv;
  146. while(i < argc) {
  147. printf("argv[%ld] %s\n",i,*s);
  148. i++;
  149. s++;
  150. }
  151. #if 0
  152. printf("TTASK CommandLine %s\n",GetCommandLine());
  153. if ( strchr(GetCommandLine(),'+') ) {
  154. printf("TTASK CommandLine %s\n",GetCommandLine());
  155. return 1;
  156. }
  157. Process=OpenProcess(PROCESS_ALL_ACCESS,FALSE,GetCurrentProcessId());
  158. assert(Process);
  159. assert(GetModuleFileName(0,ImageName,256) < 255);
  160. assert(GetModuleFileName(0,CommandLine,256) < 255);
  161. strcat(CommandLine," -- + --");
  162. assert(WinExec(CommandLine,0) == 32);
  163. lmp.lpEnvAddress = Environment;
  164. lmp.lpCmdLine = CommandLine;
  165. lmp.dwReserved = 0;
  166. lmp.lpCmdShow = &cs;
  167. cs.wMustBe2 = 2;
  168. cs.wShowWindowValue = 3;
  169. RtlFillMemory(Environment,256,'\0');
  170. strcpy(Environment,"PATH=C:\\FOOBAR;C:\\NT\\DLL");
  171. strcpy(&Environment[strlen("PATH=C:\\FOOBAR;C:\\NT\\DLL")+1],"XYZZY=X");
  172. assert(LoadModule(ImageName,&lmp) == 32);
  173. #endif
  174. InitializeCriticalSection(&Crit);
  175. Event = CreateEvent(NULL,TRUE,TRUE,NULL);
  176. Semaphore = CreateSemaphore(NULL,1,256,NULL);
  177. Mutex = CreateMutex(NULL,FALSE,NULL);
  178. assert(Event);
  179. assert(Semaphore);
  180. assert(Mutex);
  181. NEvent = CreateEvent(NULL,TRUE,TRUE,"named-event");
  182. NSemaphore = CreateSemaphore(NULL,1,256,"named-semaphore");
  183. NMutex = CreateMutex(NULL,FALSE,"named-mutex");
  184. assert(NEvent);
  185. assert(NSemaphore);
  186. assert(NMutex);
  187. OEvent = OpenEvent(EVENT_ALL_ACCESS,FALSE,"named-event");
  188. OSemaphore = OpenSemaphore(SEMAPHORE_ALL_ACCESS,FALSE,"named-semaphore");
  189. OMutex = OpenMutex(MUTEX_ALL_ACCESS,FALSE,"named-mutex");
  190. assert(OEvent);
  191. assert(OSemaphore);
  192. assert(OMutex);
  193. EnterCriticalSection(&Crit);
  194. LeaveCriticalSection(&Crit);
  195. st = WaitForSingleObject(Event,-1);
  196. assert(st == 0);
  197. st = WaitForSingleObject(Semaphore,-1);
  198. assert(st == 0);
  199. st = WaitForSingleObject(Semaphore,0);
  200. assert(st == WAIT_TIMEOUT);
  201. assert(ReleaseSemaphore(Semaphore,1,NULL));
  202. st = WaitForSingleObject(Mutex,-1);
  203. assert(st == 0);
  204. assert(ReleaseMutex(Mutex));
  205. st = WaitForSingleObject(OEvent,-1);
  206. assert(st == 0);
  207. st = WaitForSingleObject(OSemaphore,-1);
  208. assert(st == 0);
  209. st = WaitForSingleObject(NSemaphore,0);
  210. assert(st == WAIT_TIMEOUT);
  211. assert(ReleaseSemaphore(NSemaphore,1,NULL));
  212. st = WaitForSingleObject(OMutex,-1);
  213. assert(st == 0);
  214. assert(ReleaseMutex(NMutex));
  215. Thread = CreateThread(NULL,0L,TestThread,(LPVOID)99,0,&ThreadId);
  216. assert(Thread);
  217. st = WaitForSingleObject(Thread,-1);
  218. assert(st == 0);
  219. assert(GetExitCodeThread(Thread,&st));
  220. assert(st = 99);
  221. CloseHandle(Thread);
  222. Event1 = CreateEvent(NULL,TRUE,FALSE,NULL);
  223. Event2 = CreateEvent(NULL,TRUE,FALSE,NULL);
  224. Thread = CreateThread(NULL,0L,WaitTestThread,(LPVOID)99,0,&ThreadId);
  225. assert(Thread);
  226. st = WaitForSingleObject(Event1,-1);
  227. assert(st == 0);
  228. //
  229. // thread should now be waiting on event2
  230. //
  231. psp = SuspendThread(Thread);
  232. assert(psp==0);
  233. assert(SetEvent(Event2));
  234. psp = SuspendThread(Thread);
  235. assert(psp==1);
  236. psp = ResumeThread(Thread);
  237. assert(psp==2);
  238. psp = ResumeThread(Thread);
  239. assert(psp==1);
  240. st = WaitForSingleObject(Thread,-1);
  241. assert(st == 0);
  242. assert(GetExitCodeThread(Thread,&st));
  243. assert(st = 99);
  244. CloseHandle(Thread);
  245. return 1;
  246. }