XIL Test Suite User's Guide
只搜尋這本書
以 PDF 格式下載這本書

Example Test Program

B

This appendix contains the text of the example test program called image_example_test.c. The source can be found in the $XILCHHOME/../src/tests/examples directory.
Code Example B-1 Example Test Program, image_example_test.c (1 of 4)

  /* @(#)image_example_test.c1.4 93/11/19  
   *  
   * Example image test program that tests xil_add ()  
   *  
   * Options:  
   *  -m <file> use "file" as test specification file  
   * -tol # tolerance to use for image comparisons  
   *  
   */  
  
  #include <stdio.h>  
  #include <stdlib.h>  
  #include <string.h>  
  #include <xil/xil.h>  
  #include <xilch/ts.h>  
  
  main (  
  int argc,  
  char**argv )  

Code Example B-1 Example Test Program, image_example_test.c (2 of 4)

  {  
   int         i;  
   int         errors = 0;  
   int         total_errors = 0;  
   char   *specfile = NULL;  
   float tol = 0.0;  
   XilImagesrc1, src2, dst1;  
   XilSystemStatexil_State;  
  
   /*  
   * process command line arguments  
   */  
  
   for (i = 1; i < argc; i++) {  
       if (!strcmp (argv[i], "-m")) {  
        specfile = argv[++i];  
       }  
       if (!strcmp (argv[i], "-tol")) {  
        tol = atof (argv[++i]);  
       }  
   }  
  
   /*  
   * initialize XIL and the test suite library  
   */  
  
   if ((xil_State = xil_open ()) == (XilSystemState) NULL) {  
       fprintf (stderr, "Error initializing XIL\n");  
       exit (1);  
   }  
  
   if (ts_init (&argc, argv, xil_State) == TS_FAILURE) {  
   exit (1);  
   }  
  
   ts_start_test_case("image_example_test");  
  
   /*  
   * get some test images  
   */  
   src1 = ts_get_src1_image (specfile);  

Code Example B-1 Example Test Program, image_example_test.c (3 of 4)

   src2 = ts_get_src2_image (specfile);  
   dst1 = ts_get_dst1_image (specfile);  
   /*  
   * loop over the images in the test matrix file  
   */  
   while ( (src1 != (XilImage) NULL) &&  
        (src2 != (XilImage) NULL) &&  
        (dst1 != (XilImage) NULL) ) {  
       /*  
        * do the operation(s), add two images into a destination  
        */  
       xil_add (src1, src2, dst1);  
       /*  
        * verify the results  
        */  
       errors = ts_verify ("add", NULL, dst1, tol, NULL);  
       if (errors != 0) {  
        /*  
        * save the src and dst images for further study  
        */  
        ts_save (src1, "add_src1");  
        ts_save (src2, "add_src2");  
        ts_save (dst1, "add_dst");  
        total_errors++;  
        exit (total_errors);  
       }  
       /*  
        * get rid of the images  
        */  
       ts_destroy (src1);  

Code Example B-1 Example Test Program, image_example_test.c (4 of 4)

       ts_destroy (src2);  
       ts_destroy (dst1);  
       /*  
        * get some more test images  
        */  
       src1 = ts_get_src1_image (specfile);  
       src2 = ts_get_src2_image (specfile);  
       dst1 = ts_get_dst1_image (specfile);  
   }  
   /*  
   * return the total number of errors (required) and close XIL  
   */  
   ts_end_test_case();  
   xil_close (xil_State);  
   total_errors = ts_end ();  
   exit (total_errors);  
  }