943,945 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 3656
  • C RSS
You are currently viewing page 1 of this multi-page discussion thread
Oct 3rd, 2006
0

how to test a software program on linux

Expand Post »
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
usr1971ca is offline Offline
6 posts
since Oct 2006
Oct 3rd, 2006
0

Re: how to test a software program on linux

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
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Oct 4th, 2006
0

Re: how to test a software program on linux

Salem
Click to Expand / Collapse  Quote originally posted by Salem ...
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
Click to Expand / Collapse  Quote originally posted by usr1971ca ...
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. }
Reputation Points: 18
Solved Threads: 0
Newbie Poster
risby is offline Offline
21 posts
since Sep 2006
Oct 4th, 2006
0

Re: how to test a software program on linux

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?
Reputation Points: 18
Solved Threads: 0
Newbie Poster
risby is offline Offline
21 posts
since Sep 2006
Oct 4th, 2006
0

Re: how to test a software program on linux

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
usr1971ca is offline Offline
6 posts
since Oct 2006
Oct 4th, 2006
0

Re: how to test a software program on linux

Click to Expand / Collapse  Quote originally posted by usr1971ca ...
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.
Reputation Points: 18
Solved Threads: 0
Newbie Poster
risby is offline Offline
21 posts
since Sep 2006
Oct 4th, 2006
0

Re: how to test a software program on linux

> 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.
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Oct 4th, 2006
0

Re: how to test a software program on linux

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?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
usr1971ca is offline Offline
6 posts
since Oct 2006
Oct 4th, 2006
0

Re: how to test a software program on linux

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
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Oct 4th, 2006
0

Re: how to test a software program on linux

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
usr1971ca is offline Offline
6 posts
since Oct 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: EXECryptor software protection
Next Thread in C Forum Timeline: Program on matrix calculations





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC