how to test a software program on linux

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2006
Posts: 6
Reputation: usr1971ca is an unknown quantity at this point 
Solved Threads: 0
usr1971ca usr1971ca is offline Offline
Newbie Poster

how to test a software program on linux

 
0
  #1
Oct 3rd, 2006
There is an algorithm in the software program that other team handed to me on linux. Given a set of requirements, our task is to create a test script/driver to verify that algorithm using a separate data file and spit out the result on the output file. The concept is quite simple, but not sure if I know how to start. Please advice!!!!!

example: a C program contains an algorithm F = ma (Newton's Law). a data file for m and a is needed (each line contains data for m and a). To verify an algorithm, a test script should be written to call both data file and executable file and the output should be written either on the fly or a text file.

Thanks
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 751
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: how to test a software program on linux

 
0
  #2
Oct 3rd, 2006
Ignoring the file issue for the moment, how does the program get a single 'm' and 'a' value?

On the command line, like ./testprog 10 20

Or as a prompt from within the program
Enter m and a values
10 20
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 21
Reputation: risby is an unknown quantity at this point 
Solved Threads: 0
risby's Avatar
risby risby is offline Offline
Newbie Poster

Re: how to test a software program on linux

 
0
  #3
Oct 4th, 2006
Salem
Originally Posted by Salem View Post
Ignoring the file issue for the moment, how does the program get a single 'm' and 'a' value?
I do believe yer man has already said he'll be reading m and a from a file
Originally Posted by usr1971ca View Post
using a separate data file ... a data file for m and a is needed (each line contains data for m and a).
usr1971ca, what a nice name by the way, you need to read the two numbers in from your data file; fgets() reads in a line at a time, then convert the two numbers from the digits in the input line into integers with sscanf(). Now it's just a matter of calculating their product and writing it out.

Your code might look something like this:
  1. while (fgets(buf, sizeof(buf), datafile) != NULL)
  2. {
  3. if (sscanf(buf, "%d%d", &m, &a) == 2)
  4. {
  5. printf("%d * %d = %d\n", m, a, m * a);
  6. }
  7. }
Good judgment comes from experience, and a lot of that comes from bad judgment.
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 21
Reputation: risby is an unknown quantity at this point 
Solved Threads: 0
risby's Avatar
risby risby is offline Offline
Newbie Poster

Re: how to test a software program on linux

 
0
  #4
Oct 4th, 2006
Oh, hang on. You don't need to write the program just a script to run it. That seems very odd because it could be as little as the name of the program followed by the name of the datafile both on one line in a text file that you make executable with chmod.

Or am I missing something here?
Good judgment comes from experience, and a lot of that comes from bad judgment.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 6
Reputation: usr1971ca is an unknown quantity at this point 
Solved Threads: 0
usr1971ca usr1971ca is offline Offline
Newbie Poster

Re: how to test a software program on linux

 
0
  #5
Oct 4th, 2006
Salem and Risby,

Thanks for your prompt replies.
However, we will not scanf or fget within the prorgam. We probably initialize all 3 parameters for compilation purpose. The excerise here is to write another program to read a data file, which is used for a computation defined in that executable code. Its kinda hard to describe clearly here, but hope you get a picture.

Thanks
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 21
Reputation: risby is an unknown quantity at this point 
Solved Threads: 0
risby's Avatar
risby risby is offline Offline
Newbie Poster

Re: how to test a software program on linux

 
0
  #6
Oct 4th, 2006
Originally Posted by usr1971ca View Post
Its kinda hard to describe clearly here, but hope you get a picture.
Not at all ... and if you want to get anywhere in IT clear descriptions are vital.
Good judgment comes from experience, and a lot of that comes from bad judgment.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 751
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: how to test a software program on linux

 
0
  #7
Oct 4th, 2006
> Its kinda hard to describe clearly here, but hope you get a picture.
The source code for the program you're trying to test, or at least the bit of it where it "gets the values m and a" would make it much clearer.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 6
Reputation: usr1971ca is an unknown quantity at this point 
Solved Threads: 0
usr1971ca usr1971ca is offline Offline
Newbie Poster

Re: how to test a software program on linux

 
0
  #8
Oct 4th, 2006
I guess I still don't know how. Any example of a C program that reads both inputs (from data file) and object code so that it can generate an output file?
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 751
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: how to test a software program on linux

 
0
  #9
Oct 4th, 2006
Take your pick
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main ( int argc, char *argv[] ) {
  5. int m, a;
  6. if ( argc > 2 ) {
  7. m = strtol(argv[1],NULL,10);
  8. a = strtol(argv[2],NULL,10);
  9. } else {
  10. char buff[BUFSIZ];
  11. printf( "Enter m and a values > " );
  12. fflush( stdout );
  13. if ( fgets( buff, sizeof buff, stdin ) != NULL ) {
  14. sscanf( buff, "%d %d", &m, &a );
  15. }
  16. }
  17. printf( "m=%d, a=%d\n", m, a );
  18. return 0;
  19. }
  20.  
  21.  
  22. # parameters on command line
  23. $ ./a.exe 22 33
  24. m=22, a=33
  25.  
  26. # parameters entered at a prompt
  27. $ ./a.exe
  28. Enter m and a values > 33 44
  29. m=33, a=44
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 6
Reputation: usr1971ca is an unknown quantity at this point 
Solved Threads: 0
usr1971ca usr1971ca is offline Offline
Newbie Poster

Re: how to test a software program on linux

 
0
  #10
Oct 4th, 2006
Salem,

Thanks very much. But that doesn't clear up my frustration.

The above source code should be pre-compiled. Data 22 33 should be one of the many data in a separate file. An objective here is to write a test script to read BOTH that data file and object code then spit out the result in a separate output file.

Your patience is appreciated
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C Forum


Views: 3203 | Replies: 13
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC