Re: [Dev-C++] How to test methods with system calls
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
From: Eric <eri...@wo...> - 2008-10-23 05:40:39
|
This group reminds me of the Java forum everyone says how they pass with 90%+ you ask them a basic question and nobody knows ----- Original Message ----- From: Per Westermark <pw...@ia...> To: Eric <er...@du...> Cc: <dev...@li...> Sent: Thursday, October 23, 2008 6:33 PM Subject: Re: [Dev-C++] How to test methods with system calls The simplest questions to this list is normally school work that shouldn't really be answered... The last one was just days ago by someone who didn't understod the "me" of "the professor wants me to write a program [...]" read(2) and write(2) do not normally fail unexpectedly. Note that they may return with EINTR or EAGAIN (depending on what OS) requiring them to be restarted. This isn't an error, but a result of how signaling is designed, i.e. to allow a process to immediately respond to a signal instead of being stuck waiting for input/output. You would normally create a small loop to repeatedly restart the read/write if it returns -1 and errno is EAGAIN or EINTR. If you have signal handlers that sets flag, then you may have to take a peek at these flags before restarting the operation - for example if your process has received a signal that it should end, or reopen any log files or reload configuration... Function calls that does not have a timeout are often used together with alarm() to get a SIGALRM after the intended timeout, in case no data is available. You may also get these functions to "fail" by manually using the kill or killall commands and send signals to the application. With the exception of EIO, all other errors can be produced by sending incorrect parameters to read()/write() or by manipulating the target that fd references, such as by closing the other end of a pipe, limiting the amount of disk space available, ... /pwm On Thu, 23 Oct 2008, Eric wrote: > GOOD QUESTION > BUT THIS GROUP CAN NOT EVEN ASWER SIMPLE QUESTIONS > > > > > > > > ----- Original Message ----- > From: Hiroyuki Yamada <yam...@gm...> > To: <Dev...@li...> > Sent: Thursday, October 23, 2008 1:35 AM > Subject: [Dev-C++] How to test methods with system calls > > > I'm testing some c++ programs having some methods with system calls, which > are like write(2) and read(2). > (I use googletest for the test.) > > Those write(2) and read(2) can fail for some reason, but > it's not predicable, so I'm wondering how I can test error handling codes > for errors by those system calls. > > Is there any way I can simulate those system call' errors without > modification in source code ? > How do you usually test those ? > > Thanks in advance, > > Hiroyuki > > *********************************************************** > PLEASE READ: > > The contents of this Email and if any files transmitted with it are not > confidential and intended for the use of the individual or entity to whom > this Email is addressed. The views stated herein do not necessarily > represent the view of myself been in sound mind and body & non intoxicated > at the time I composed this Email. I knew what I was doing when I selected > your Email address, so YOU are the correct intended recipient of this Email, > you did NOT receive this email in error, GET A GRIP!!! don't procrastinate > with endless excuses. You may copy, forward, disclose, print, delete it or > otherwise use it or any part of it, in any > form you can think of. > After you have received this mail please feel free to Email the sender (me) > with a personnel Email anytime, but NOT black text on white background HTML > format. if you been the sender > intend to send me a Email in HTML format, please add some living color to > compensate the slightly wasted internet bandwidth, longer download time and > wasted space of my hard drive as if I decide to save that Email (only for > archive purposes), due to the fact that HTML Emails are two and half times > bigger than the same Email content posted in plain text > format. > If you been the sender decide to send me been the receiver a attachment file > larger than 200Kb in file size please give me prior courtesy to ask if I > would like to receive it, as I been the receiver have a slow dial up > connection speed and often other members of the > household want to use the phone only when I go on Internet. > *********************************************************** > > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's challenge > Build the coolest Linux based applications with Moblin SDK & win great prizes > Grand prize is a trip for two to an Open Source event anywhere in the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > -- No virus found in this incoming message. Checked by AVG. Version: 7.5.549 / Virus Database: 270.8.2/1740 - Release Date: 22-Oct-08 19:24 |