test-scenes.cpp
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2020 Intel Corporation. All Rights Reserved.
3 
4 //#cmake:add-file ../../../src/algo/depth-to-rgb-calibration/*.cpp
5 //#cmake:add-file ../../../src/algo/thermal-loop/*.cpp
6 
7 //#test:flag custom-args # disable passing in of catch2 arguments
8 
9 // We have our own main
10 #define NO_CATCH_CONFIG_MAIN
11 #define CATCH_CONFIG_RUNNER
12 
13 #define DISABLE_LOG_TO_STDOUT
14 #include "d2rgb-common.h"
15 #include "compare-to-bin-file.h"
16 
17 #include "compare-scene.h"
18 #include "../../filesystem.h"
19 
20 #ifdef _WIN32
21 #include <io.h>
22 #else
23 #include <unistd.h>
24 #define _log log
25 #define _close close
26 #define _fileno fileno
27 #define _dup dup
28 #define _dup2 dup2
29 #endif
30 
31 
33 {
34  int _no;
35  int _old_no;
36 
37 public:
38  redirect_file( FILE * f = stdout )
39  : _no( _fileno( f ))
40  , _old_no( _dup( _no ))
41  {
42  std::freopen( std::tmpnam( nullptr ), "w", f );
43  }
45  {
46  _dup2( _old_no, _no );
47  _close( _old_no );
48  }
49 };
50 
51 
53 {
54  std::cout << std::right << std::setw( 7 ) << "------ ";
55  std::cout << std::left << std::setw( 70 ) << "-----";
56  std::cout << std::left << std::setw( 10 ) << "----------";
57  std::cout << std::right << std::setw( 10 ) << "-----";
58  std::cout << std::right << std::setw( 10 ) << "-------";
59  std::cout << std::right << std::setw( 6 ) << "---";
60  std::cout << std::right << std::setw( 2 ) << " ";
61  std::cout << std::right << std::setw( 4 ) << "---";
62  std::cout << std::right << std::setw( 2 ) << " ";
63  std::cout << std::right << std::setw( 4 ) << "---";
64  std::cout << std::right << std::setw( 2 ) << " ";
65  std::cout << std::right << std::setw( 7 ) << "-----";
66  std::cout << std::right << std::setw(2) << " ";
67  std::cout << std::right << std::setw(4) << "---";
68  std::cout << std::right << std::setw( 2 ) << " ";
69  std::cout << std::right << std::setw( 8 ) << "---";
70  std::cout << std::endl;
71 }
72 
74 {
75  std::cout << std::right << std::setw( 7 ) << "Failed ";
76  std::cout << std::left << std::setw( 70 ) << "Name";
77  std::cout << std::left << std::setw( 10 ) << "Cost";
78  std::cout << std::right << std::setw( 10 ) << "%diff";
79  std::cout << std::right << std::setw( 10 ) << "Pixels";
80  std::cout << std::right << std::setw( 6 ) << "SV";
81  std::cout << std::right << std::setw( 2 ) << " ";
82  std::cout << std::right << std::setw( 4 ) << "OV";
83  std::cout << std::right << std::setw( 2 ) << " ";
84  std::cout << std::right << std::setw( 4 ) << "Con";
85  std::cout << std::right << std::setw( 2 ) << " ";
86  std::cout << std::right << std::setw( 7 ) << "dPix";
87  std::cout << std::right << std::setw(2) << " ";
88  std::cout << std::right << std::setw(4) << "nC";
89  std::cout << std::right << std::setw( 2 ) << " ";
90  std::cout << std::right << std::setw( 8 ) << "MEM";
91  std::cout << std::endl;
92 
94 }
95 
96 void print_scene_stats( std::string const & name, size_t n_failed, scene_stats const & scene )
97 {
98  std::cout << std::right << std::setw( 6 ) << n_failed << ' ';
99 
100  std::cout << std::left << std::setw( 70 ) << name;
101 
102  std::cout << std::right << std::setw( 10 ) << std::fixed << std::setprecision( 2 ) << scene.cost;
103  double matlab_cost = scene.cost - scene.d_cost;
104  double d_cost_pct = abs( scene.d_cost ) * 100. / matlab_cost;
105  std::cout << std::right << std::setw( 10 ) << d_cost_pct;
106 
107  std::cout << std::right << std::setw( 10 ) << scene.movement;
108 
109  std::cout << std::right << std::setw( 6 ) << scene.n_valid_scene;
110  std::cout << std::left << std::setw( 2 ) << ( scene.n_valid_scene_diff ? "!" : "" );
111  std::cout << std::right << std::setw( 4 ) << scene.n_valid_result;
112  std::cout << std::left << std::setw( 2 ) << (scene.n_valid_result_diff ? "!" : "");
113  std::cout << std::right << std::setw( 4 ) << scene.n_converged;
114  std::cout << std::left << std::setw( 2 ) << (scene.n_converged_diff ? "!" : "");
115 
116  std::cout << std::right << std::setw( 7 ) << scene.d_movement;
117  std::cout << std::right << std::setw(6) << scene.n_cycles;
118  std::cout << std::right << std::setw( 10 ) << scene.memory_consumption_peak;
119  std::cout << std::endl;
120 }
121 
122 
123 int main( int argc, char * argv[] )
124 {
125  Catch::Session session;
126  ac_logger LOG_TO_STDOUT( false );
127 
128  Catch::ConfigData config;
129  config.verbosity = Catch::Verbosity::Normal;
130 
131  bool ok = true;
132  bool verbose = false;
133  bool stats = false;
134  bool debug_mode = false;
135  // Each of the arguments is the path to a directory to simulate
136  // We skip argv[0] which is the path to the executable
137  // We don't complain if no arguments -- that's how we'll run as part of unit-testing
138  for( int i = 1; i < argc; ++i )
139  {
140  try
141  {
142  char const * dir = argv[i];
143  if( !strcmp( dir, "-v" ) )
144  {
145  LOG_TO_STDOUT.enable( verbose = true );
146  continue;
147  }
148  if( ! strcmp( dir, "-d" ) || ! strcmp( dir, "--debug" ) )
149  {
150  debug_mode = true;
151  continue;
152  }
153  if( ! strcmp( dir, "--stats" ) )
154  {
155  stats = true;
156  //config.outputFilename = "%debug";
157  continue;
158  }
159  TRACE( "\n\nProcessing: " << dir << " ..." );
160  Catch::CustomRunContext ctx( config );
161  ctx.set_redirection( !verbose );
162  scene_stats total = { 0 };
163  size_t n_failed = 0;
164  size_t n_scenes = 0;
165 
166  if( stats )
167  print_headers();
168 
169  glob( dir, "yuy_prev_z_i.files",
170  [&]( std::string const & match )
171  {
172  // <scene_dir>/binFiles/ac2/<match>
173  std::string scene_dir = get_parent( join( dir, match ) ); // .../ac2
174  std::string ac2;
175  scene_dir = get_parent( scene_dir, &ac2 ); // .../binFiles
176  if( ac2 != "ac2" )
177  return;
178  std::string binFiles;
179  scene_dir = get_parent( scene_dir, &binFiles );
180  if( binFiles != "binFiles" )
181  return;
182  auto x = strlen( dir ) + 1;
183  std::string test_name = x > scene_dir.length() ? "." : scene_dir.substr( x );
184  scene_dir += native_separator;
185 
186  scene_stats scene;
187 
188  Catch::Totals catch_total;
189  {
190  redirect_file no( stats ? stdout : stderr );
191  catch_total = ctx.run_test( test_name, [&]() {
192  REQUIRE_NOTHROW( compare_scene( scene_dir, debug_mode, &scene ) );
193  } );
194  }
195 
196  n_failed += catch_total.testCases.failed;
197  ++n_scenes;
198  total.cost += scene.cost;
199  total.d_cost += abs(scene.d_cost);
200  total.movement += scene.movement;
201  total.d_movement += abs(scene.d_movement);
202  total.n_valid_scene += scene.n_valid_scene;
203  total.n_valid_scene_diff += scene.n_valid_scene_diff;
204  total.n_valid_result += scene.n_valid_result;
206  total.n_converged += scene.n_converged;
207  total.n_converged_diff += scene.n_converged_diff;
209 
210  if( stats )
211  print_scene_stats( test_name, catch_total.assertions.failed, scene );
212  } );
213 
214  if( stats )
215  {
216  print_dividers();
218  << " " << n_scenes << " scene totals:",
219  n_failed,
220  total );
221  }
222 
223  TRACE( "done!\n\n" );
224  ok &= ! n_failed;
225  }
226  catch( std::exception const & e )
227  {
228  std::cerr << "caught exception: " << e.what() << std::endl;
229  ok = false;
230  }
231  catch( ... )
232  {
233  std::cerr << "caught unknown exception!" << std::endl;
234  ok = false;
235  }
236  }
237 
238  return !ok;
239 }
size_t n_converged_diff
Definition: compare-scene.h:8
size_t n_converged
Definition: compare-scene.h:8
float memory_consumption_peak
Definition: compare-scene.h:12
Counts testCases
Definition: catch.hpp:2848
Counts assertions
Definition: catch.hpp:2847
GLuint const GLchar * name
void print_scene_stats(std::string const &name, size_t n_failed, scene_stats const &scene)
Definition: test-scenes.cpp:96
std::string join(const std::string &base, const std::string &path)
Definition: filesystem.h:113
double d_cost
Definition: compare-scene.h:9
ac_logger LOG_TO_STDOUT
Definition: d2rgb-common.h:17
static void glob(const std::string &directory, const std::string &spec, std::function< void(std::string const &) > fn, bool recursive=true, bool includeDirectories=false)
Definition: filesystem.h:269
int main(int argc, char *argv[])
GLsizei const GLchar *const * string
e
Definition: rmse.py:177
static std::string get_parent(std::string const &path, std::string *basename=nullptr)
Definition: filesystem.h:284
double movement
Definition: compare-scene.h:10
size_t n_valid_scene_diff
Definition: compare-scene.h:6
GLdouble f
std::size_t failed
Definition: catch.hpp:2835
std::ostream & cout()
void print_dividers()
Definition: test-scenes.cpp:52
size_t n_valid_scene
Definition: compare-scene.h:6
#define _dup
Definition: test-scenes.cpp:27
GLdouble x
size_t n_valid_result_diff
Definition: compare-scene.h:7
void enable(bool on=true)
Definition: ac-logger.h:46
GLint left
Definition: glext.h:1963
redirect_file(FILE *f=stdout)
Definition: test-scenes.cpp:38
#define _dup2
Definition: test-scenes.cpp:28
size_t n_cycles
Definition: compare-scene.h:11
double d_movement
Definition: compare-scene.h:10
#define _fileno
Definition: test-scenes.cpp:26
size_t n_valid_result
Definition: compare-scene.h:7
void print_headers()
Definition: test-scenes.cpp:73
GLdouble right
void compare_scene(std::string const &scene_dir, bool debug_mode=true, scene_stats *stats=nullptr)
std::ostream & cerr()
REQUIRE_NOTHROW(rs2_log(RS2_LOG_SEVERITY_INFO,"Log message using rs2_log()", nullptr))
int i
static const char native_separator
Definition: filesystem.h:104
double cost
Definition: compare-scene.h:9
#define _close
Definition: test-scenes.cpp:25
std::string to_string(T value)


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:50:11