testing offer of code

B

Billy Patton

I have worked out a testing procedure that works well for me.
Here it is for your taking. It has evolved over 15 years of
c and perl coding and testing. My perl version looks VERY similar.
It actually came for need to do something else besides what the perl test
modules offered. Some lines are too long for Pine and it puts them on seperate
line, so you will have to rebuild some of the #defines.

int nr = 0; /* total number ran */
int nf = 0; /* total number failed */
int dr = 0; /* dont run this */
int ir = 0; /* number of test per function */
char t_buf[256];
FILE *t_fp = NULL;

#define fail(x,s) if(x) { \
nf++; \
fprintf(stderr," not ok %d : file %s , line# %d :
%s\n",nr,__FILE__,__LINE__,s); \
exit(1); \
} \
else { \
fprintf(stdout," ok %d : file %s , line# %d :
%s\n",nr,__FILE__,__LINE__,s); \
} \
nr++; ir++;
#define pass(x,s) if(x) { \
fprintf(stdout," ok %d : file %s , line# %d :
%s\n",nr,__FILE__,__LINE__,s); \
} \
else { \
nf++; \
fprintf(stderr," not ok %d : file %s , line# %d :
%s\n",nr,__FILE__,__LINE__,s); \
exit(1); \
} \
nr++; ir++;

#define ENTER { if(dr==1)return;} ir=0; printf("Entering test function
%-32s\n",__func__);
#define LEAVE fprintf(stderr,"Leaving %-32s , # of tests :
%9d\n",__func__,ir);
#define READ t_fp = fopen("temp","r");
#define WRITE t_fp = fopen("temp","w");
#define CLOSE fclose(t_fp);
#define READLN fgets(t_buf,256,t_fp);

void t_void(void);

int main(int argc,char* argv[])
{
clock_t st, fin;
double dur;

st = clock();
dr = nr = nf = 0;

t_void();

fin = clock();
dur = (double)(fin - st) / CLOCKS_PER_SEC;
fprintf(stderr,"\n\n");
fprintf(stderr,"Number tests ran : %d\n",nr);
fprintf(stderr,"Number tests fail : %d\n",nf);
fprintf(stderr,"In cpu seconds : %e\n\n",dur);
return 0;
}

void t_void(void)
{
ENTER
// the 0,1 represent any boolean function
fail(0, "I expect this to fail, which passes test");
pass(1, "I expect this to pass, which passes test");
LEAVE
}


I sometime remove the exit from the fail macro when I'm running thousands of
test that take many hours.
___ _ ____ ___ __ __
/ _ )(_) / /_ __ / _ \___ _/ /_/ /____ ___
/ _ / / / / // / / ___/ _ `/ __/ __/ _ \/ _ \
/____/_/_/_/\_, / /_/ \_,_/\__/\__/\___/_//_/
/___/
Texas Instruments ASIC Circuit Design Methodology Group
Dallas, Texas, 214-480-4455, (e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top