testing offer of code

Discussion in 'C++' started by Billy Patton, Dec 9, 2004.

  1. Billy Patton

    Billy Patton Guest

    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,
    Billy Patton, Dec 9, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michael Gallen
    Replies:
    0
    Views:
    484
    Michael Gallen
    Dec 5, 2003
  2. Replies:
    0
    Views:
    286
  3. Brian van den Broek
    Replies:
    3
    Views:
    839
    Jeremy Bowers
    Apr 3, 2005
  4. Brian van den Broek
    Replies:
    2
    Views:
    388
    Brian van den Broek
    Apr 5, 2005
  5. Avi
    Replies:
    0
    Views:
    491
Loading...

Share This Page