File: tests.c

package info (click to toggle)
libvidstab 1.1.0-2.1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 648 kB
  • sloc: ansic: 6,094; makefile: 19; sh: 14
file content (138 lines) | stat: -rw-r--r-- 3,752 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138

#include <string.h>
#include <stdio.h>
#include <limits.h>
#include <math.h>
#include <features.h>

#ifdef USE_OMP
#include <omp.h>
#endif

#include "libvidstab.h"
// load optimized functions
#include "motiondetect_internal.h"
#include "motiondetect_opt.h"
#include "boxblur.h"
#include "transformfixedpoint.h"
#include "transformfloat.h"
#include "transformtype_operations.h"

#ifndef TESTING
#error TESTING must be defined
#endif

#include "testframework.h"
#include "testutils.h"

#include "generate.c"

#include "test_transform.c"
#include "test_compareimg.c"
#include "test_motiondetect.c"
#include "test_store_restore.c"
#include "test_contrast.c"
#include "test_boxblur.c"
#include "test_omp.c"
#include "test_gradientoptimizer.c"
#include "test_localmotion2transform.c"

#define FRAMENUM 5

int main(int argc, char** argv){

  if(contains(argv,argc,"-h", "help")!=0){
    printf("Usage: %s [--store --load] [--all| --testX ...]\n", argv[0]);
    unittest_help_mode();
  }

  unittest_init();

  int all = contains(argv,argc,"--all", "Perform all tests")!=0;

  TestData testdata;
  memset(&testdata,0,sizeof(TestData));
  vsFrameInfoInit(&testdata.fi,1280, 720, PF_YUV420P);
  vsFrameInfoInit(&testdata.fi_color, 640, 360, PF_GRAY8);

  if(contains(argv,argc,"--load",
              "Load frames from files from frames/frame001.raw (def: generate)")!=0){
    FILE* file;
    char name[128];
    int i;
    for(i=0; i<FRAMENUM; i++){
      vsFrameAllocate(&testdata.frames[i],&testdata.fi);
      sprintf(name,"../frames/frame%03i.raw",i+4);
      fprintf(stderr, "load file %s\n", name);
      file = fopen(name,"rb");
      test_bool(file!=0);
      fprintf(stderr,"read %li bytes\n",
              (unsigned long)fread(testdata.frames[i].data[0], 1,
                                   testdata.fi.width*testdata.fi.height,file));
      fclose(file);
    }
  }else{
    UNIT(generateFrames(&testdata, FRAMENUM));
  }
  if(contains(argv,argc,"--store", "Store frames to files")!=0){
    storePGMImage("test1.pgm", testdata.frames[0].data[0], testdata.fi);
    storePGMImage("test2.pgm", testdata.frames[1].data[0], testdata.fi);
    storePGMImage("test3.pgm", testdata.frames[2].data[0], testdata.fi);
    storePGMImage("test4.pgm", testdata.frames[3].data[0], testdata.fi);
    storePGMImage("test5.pgm", testdata.frames[4].data[0], testdata.fi);
  }

#ifdef USE_OMP
  if(all || contains(argv,argc,"--testOMP", "openmp")){
    UNIT(openmp());
  }
#endif

  if(all || contains(argv,argc,"--testTI", "transform_implementation")){
    UNIT(test_transform_implementation(&testdata));
  }

  if(all || contains(argv,argc,"--testTP", "transform_performance")){
    UNIT(test_transform_performance(&testdata));
  }

  if(all || contains(argv,argc,"--testBB", "boxblur")){
    UNIT(test_boxblur(&testdata));
  }

  if(all || contains(argv,argc,"--testCCI", "checkCompareImg")){
    UNIT(test_checkCompareImg(&testdata));
  }

  if(all || contains(argv,argc,"--testCIP", "compareImg_performance")){
    UNIT(test_compareImg_performance(&testdata));
  }

  if(all || contains(argv,argc,"--testMD", "motionDetect")){
    UNIT(test_motionDetect(&testdata));
  }

  if(all || contains(argv,argc,"--testLM", "localmotion2transform")){
    UNIT(test_localmotion2transform(&testdata));
  }

  if(all || contains(argv,argc,"--testSR", "store_restore")){
    UNIT(test_store_restore(&testdata));
  }

  if(all || contains(argv,argc,"--testCT", "contrastImg")){
    UNIT(test_contrastImg(&testdata));
  }

  if(all || contains(argv,argc,"--testGO", "gradient optimizer")){
    UNIT(test_gradientoptimizer());
  }

  // free
  for(int i=0; i<FRAMENUM; i++){
    if(&testdata.frames[i])
      vsFrameFree(&testdata.frames[i]);
  }

  return unittest_summary();
}