Go Back   Velocity Reviews > Newsgroups > C Programming
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

C Programming - How to test a C Program

 
Thread Tools Search this Thread
Old 11-03-2009, 04:43 AM   #1
Default How to test a C Program


How do clc folks test a C program ?

I have this another thread titled "Array based Binary Heap in C". My test
was simple one, just add some elements and remove some and if it works
fine, that's great. (That is my usual way of testing)

My seniors want me to do automatic test which can add/remove around a
million elements without any manuals intervention, the input just have to
be configurable. Someone advised to write a Client-Server program using
threads to test it where client will send input but I did not like that
very complex idea.

So I want to know, how do people here at clc test a C program ?






--
www.lispmachine.wordpress.com
my email is @ the above blog.



arnuld
  Reply With Quote
Old 11-03-2009, 05:46 AM   #2
user923005
 
Posts: n/a
Default Re: How to test a C Program
On Nov 2, 8:43*pm, arnuld <sunr...@invalid.address> wrote:
> How do clc folks test a C program ?
>
> I have this another thread titled "Array based Binary Heap in C". My test
> was simple one, just add some elements and remove some and if it works
> fine, that's great. (That is my usual way of testing)
>
> My seniors want me to do automatic test which can add/remove around a
> million elements without any manuals intervention, the input just have to
> be configurable. Someone advised to write a Client-Server program using
> threads to test it where client will send input but I did not like that
> very complex idea.
>
> So I want to know, how do people here at clc test a C program ?


Here are some C unit testing frameworks:
http://en.wikipedia.org/wiki/List_of...g_frameworks#C

If your management is asking you to do comprehensive testing, that is
a terrible error on their part.
Comprehensive testing should *always* be performed by a separate
testing body and *NOT* by the programmer. To do otherwise is an
absolutely certain invitation for disaster.

Be that as it may, I have some simple rules for my own unit testing
that you might find handy:
1. If the input is small (IOW, 5 bytes or so maximum) then I will
exhaustively test the function (5 bytes of input will be the bit
pattern 0x0000000000 through 0xffffffffff spread across the inputs).
2. Test all edge cases --> E.G.: every pointer input should get a NULL
pointer, a pointer to an empty field, and a pointer to a maximally
populated field).
3. Invalid input must be tested (e.g. floating point functions should
get data outside of the acceptable domain, NaNs, +/-INF, etc.).
4. Valid input must be tested (seems a no brainer, but if you
concentrate on steps 1-3 up above, it might be left out).
5. If the input is large (IOW, strings are allowed as input, or many
bytes of parameters, etc.) then I will statistically test the input
[step 1 above is not possible].
6. Data should be provided in various distributions (e.g. all data
identical, random data, sorted data, etc.) I have about 10
distributions that I typically use.

HTH


user923005
  Reply With Quote
Old 11-03-2009, 07:52 AM   #3
Seebs
 
Posts: n/a
Default Re: How to test a C Program
On 2009-11-03, arnuld <> wrote:
> How do clc folks test a C program ?


It depends a lot on the program and its scope or intended function.
I might well do nothing but eyeball results for a one-off that I just
wrote to calculate some results. For a larger program, I'd try to
come up with test cases which exercise its common usage pattern.

> My seniors want me to do automatic test which can add/remove around a
> million elements without any manuals intervention, the input just have to
> be configurable. Someone advised to write a Client-Server program using
> threads to test it where client will send input but I did not like that
> very complex idea.


Unless there's something in a program that I expect to be affected
specifically by size, I usually favor merely testing every code path I can
conceive of. So, once you've tested a handful of sorted and unsorted inputs,
etcetera, that's usually enough to confirm that it'll work.

> So I want to know, how do people here at clc test a C program ?


Depends hugely on its intended use, etcetera. Something that's going to be
a fundamental piece of a shipping product gets a lot more attention than a
one-off "what happens if..."

-s
--
Copyright 2009, all wrongs reversed. Peter Seebach / usenet-
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!


Seebs
  Reply With Quote
Old 11-03-2009, 08:10 AM   #4
arnuld
 
Posts: n/a
Default Re: How to test a C Program
> On Tue, 03 Nov 2009 05:46:50 +0000, Richard Heathfield wrote:

> ..SNIP...


> It is at testing time that you discover how useful program scaffolding
> can be. For example, one big problem with testing is "for error-handling
> tests, how do you make a resource fail in exactly the place you want?"
> It can be tricky to get a particular, exact "right the hell this one
> here" malloc call to fail, for example, and yet have all the prior and
> subsequent calls succeed. But a relatively trivial wrapper around the
> allocation routines can give you this flexibility (and can be shed for
> production code).



Moved it to /comp.programming/, does not seem like a C question anymore.



--
www.lispmachine.wordpress.com
my email is @ the above blog.



arnuld
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
FAQ for the XP x64 Technology Advancement Program (the Trade-in program) Joe Swart [MSFT] Windows 64bit 10 05-11-2005 03:08 PM
FAQ for the Server 2003 x64 Technology Advancement Program (the Trade-in program) Joe Swart [MSFT] Windows 64bit 1 05-11-2005 09:46 AM
Security and Encryption FAQ - Revision 18.2 Doctor Who Computer Security 0 07-05-2004 09:37 PM
Security and Encryption FAQ - Revision 18.2 Doctor Who Computer Security 0 07-05-2004 09:33 PM
Security and Encryption FAQ - Revision 18.2 Doctor Who Computer Security 0 07-05-2004 09:30 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46