tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] Testing Console Application with CreateProcess


From: Thomas Preud'homme
Subject: Re: [Tinycc-devel] Testing Console Application with CreateProcess
Date: Sun, 22 Jan 2012 21:21:10 +0100
User-agent: KMail/1.13.7 (Linux/3.2.0-1-amd64; KDE/4.6.5; x86_64; ; )

Le dimanche 22 janvier 2012 14:27:09, grischka a écrit :
> address@hidden wrote:
> > I'm writing a small app to do automated testing of a console application.
> > It needs to repeatedly run the app with various options and handle when
> > the app being tested crashes. I started with system(), moved on to
> > spawn() and have since been trying CreateProcess(). It starts the app
> > correctly but I can't seem to kill the process. How do I kill the
> > process or is there a different approach I should consider?
> > 
> > Greg
> 
> There are some things wrong with the code below but there is one
> thing that tcc better should notice but currently does not:
> 
>      retCode = ExitProcess(pi.dwProcessId);
> 
> which is declared as
> 
>      VOID ExitProcess(UINT uExitCode);
> 
> (and actually never returns).
> 
> Anyone wants to fix that?

3ab269c56ac1bb79956c0160382bb720ca487ca3

Review welcome, including about the wording.

Best regards,

> 
> --- grischka
Thomas Preud'homme
> 
> > #include <windows.h>
> > #include <stdio.h>
> > 
> > int main(void) {
> > 
> >   int retCode = 0;
> >   PROCESS_INFORMATION pi;        /* filled in by CreateProcess */
> >   STARTUPINFO si;                /* startup info for the new process */
> >   
> >   /* print out our process ID */
> >   printf("Process %d reporting for duty\n",GetCurrentProcessId());
> >   
> >   /* Get startup info for current process, we will use this
> >   
> >      as the startup info for the new process as well... */
> >   
> >   GetStartupInfo(&si);
> >   
> >   /* Call CreateProcess, telling it to run DivideByZero
> >   
> >      with lots of defaults... (the NULLs mean "use defaults")
> >   
> >   */
> >   
> >   CreateProcess(NULL,          /* lpApplicationName */
> >   
> >             "DivideByZero.exe", /* lpCommandLine */
> >             NULL,          /* lpsaProcess */
> >             NULL,          /* lpsaThread */
> >             FALSE,         /* bInheritHandles */
> >             DETACHED_PROCESS, /* dwCreationFlags */
> >             NULL,          /* lpEnvironment */
> >             
> >                 NULL,          /* lpCurDir */
> >                 &si,           /* lpStartupInfo */
> >             
> >             &pi            /* lpProcInfo */
> >             );
> >             
> >   printf("New Process ID: %d\n",pi.dwProcessId);
> >   
> >   getc(stdin); //Pause here to check task manager etc...
> >   
> >   retCode = ExitProcess(pi.dwProcessId);
> >   
> >   printf("Returned %d\n\n",retCode);
> >   
> >   return(0);
> > 
> > }
> > 
> > 
> > //DivideByZero
> > 
> > #include <stdio.h>
> > 
> > int main(void)
> > {
> > 
> >     int result = 0;
> >     
> >     printf("DivideByZero is about to crash\n");
> >     
> >     result = 42/result;
> >     
> >     printf("Result: %d\n", result);
> >     
> >     return(0);
> > 
> > }
> 
> _______________________________________________
> Tinycc-devel mailing list
> address@hidden
> https://lists.nongnu.org/mailman/listinfo/tinycc-devel

Attachment: signature.asc
Description: This is a digitally signed message part.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]