unit-tests-live-sr300.cpp
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2015 Intel Corporation. All Rights Reserved.
3 
5 // This set of tests is valid only for the SR300 camera //
7 
8 #if !defined(MAKEFILE) || ( defined(LIVE_TEST) && defined(SR300_TEST) )
9 
10 #define CATCH_CONFIG_MAIN
11 #include "catch/catch.hpp"
12 
13 #include "unit-tests-common.h"
14 
15 #include <climits>
16 #include <sstream>
17 #include <algorithm>
18 
19 TEST_CASE( "SR300 metadata enumerates correctly", "[live] [sr300]" )
20 {
21  // Require at least one device to be plugged in
23  const int device_count = rs_get_device_count(ctx, require_no_error());
24  REQUIRE(device_count > 0);
25 
26  // For each device
27  for(int i=0; i<device_count; ++i)
28  {
30  REQUIRE(dev != nullptr);
31 
32  SECTION( "device name is Intel RealSense SR300" )
33  {
34  const char * name = rs_get_device_name(dev, require_no_error());
35  REQUIRE(name == std::string("Intel RealSense SR300"));
36  }
37  }
38 }
39 
40 TEST_CASE( "SR300 devices support all required options", "[live] [sr300]" )
41 {
42  // Require at least one device to be plugged in
44  const int device_count = rs_get_device_count(ctx, require_no_error());
45  REQUIRE(device_count > 0);
46 
47  // For each device
48  for(int i=0; i<device_count; ++i)
49  {
51  REQUIRE(dev != nullptr);
52 
53  SECTION( "device supports standard picture options and SR300 extension options, and nothing else" )
54  {
55  std::vector<rs_option> supported_options{
85  };
86 
87  for(int i=0; i<RS_OPTION_COUNT; ++i)
88  {
89  if(std::find(std::begin(supported_options), std::end(supported_options), i) != std::end(supported_options))
90  {
92  }
93  else
94  {
96  }
97  }
98  }
99  }
100 }
101 
103 // Calibration information tests //
105 
106 TEST_CASE( "SR300 device extrinsics are within expected parameters", "[live] [sr300]" )
107 {
108  // Require at least one device to be plugged in
110  const int device_count = rs_get_device_count(ctx, require_no_error());
111  REQUIRE(device_count > 0);
112 
113  // For each device
114  for(int i=0; i<device_count; ++i)
115  {
117  REQUIRE(dev != nullptr);
118 
119  SECTION( "no extrinsic transformation between DEPTH and INFRARED" )
120  {
121  rs_extrinsics extrin;
123 
126  }
127 
128  // TODO: Expected depth/color baseline
129 
130  SECTION( "depth scale is 0.000125 (by default)" )
131  {
133  }
134  }
135 }
136 
138 // Streaming tests //
140 
141 inline void test_sr300_streaming(std::initializer_list<stream_mode> modes)
142 {
145 
147  REQUIRE(dev != nullptr);
148  REQUIRE(rs_get_device_name(dev, require_no_error()) == std::string("Intel RealSense SR300"));
149 
150  test_streaming(dev, modes);
151 }
153 // Color streaming tests //
155 
156 TEST_CASE("SR300 streams 1080p color", "[live] [sr300] [one-camera]")
157 {
158  test_sr300_streaming({ { RS_STREAM_COLOR, 1920, 1080, RS_FORMAT_YUYV, 30 } });
159 }
160 
161 TEST_CASE("SR300 streams 720p color", "[live] [sr300] [one-camera]")
162 {
163  test_sr300_streaming({ { RS_STREAM_COLOR, 1280, 720, RS_FORMAT_YUYV, 30 } });
164 }
165 
166 TEST_CASE("SR300 streams VGA color", "[live] [sr300] [one-camera]")
167 {
168  test_sr300_streaming({ { RS_STREAM_COLOR, 640, 480, RS_FORMAT_YUYV, 30 } });
169 }
170 
171 TEST_CASE("SR300 streams 720p color (60 fps)", "[live] [sr300] [one-camera]")
172 {
173  test_sr300_streaming({ { RS_STREAM_COLOR, 1280, 720, RS_FORMAT_YUYV, 60 } });
174 }
175 
176 TEST_CASE("SR300 streams VGA color (60 fps)", "[live] [sr300] [one-camera]")
177 {
178  test_sr300_streaming({ { RS_STREAM_COLOR, 640, 480, RS_FORMAT_YUYV, 60 } });
179 }
180 
181 TEST_CASE("SR300 streams VGA depth and HD color", "[live] [sr300] [one-camera]")
182 {
184  { RS_STREAM_COLOR, 1920, 1080, RS_FORMAT_YUYV, 30 } });
185 }
186 
187 TEST_CASE("SR300 streams HVGA depth and HD color", "[live] [sr300] [one-camera]")
188 {
190  { RS_STREAM_COLOR, 1920, 1080, RS_FORMAT_YUYV, 30 } });
191 }
192 
193 TEST_CASE("SR300 streams VGA depth and VGA color", "[live] [sr300] [one-camera]")
194 {
196  { RS_STREAM_COLOR, 640, 480, RS_FORMAT_YUYV, 30 } });
197 }
198 
199 TEST_CASE("SR300 streams HVGA depth and VGA color", "[live] [sr300] [one-camera]")
200 {
202  { RS_STREAM_COLOR, 640, 480, RS_FORMAT_YUYV, 30 } });
203 }
204 
205 TEST_CASE("SR300 streams VGA depth and VGA color (60 fps)", "[live] [sr300] [one-camera]")
206 {
208  { RS_STREAM_COLOR, 640, 480, RS_FORMAT_YUYV, 60 } });
209 }
210 
211 TEST_CASE("SR300 streams HVGA depth and VGA color (60 fps)", "[live] [sr300] [one-camera]")
212 {
214  { RS_STREAM_COLOR, 640, 480, RS_FORMAT_YUYV, 60 } });
215 }
216 
218 // Depth streaming tests //
220 
221 TEST_CASE("SR300 depth stream (Z16)", "[live] [sr300] [one-camera]")
222 {
223  SECTION("SR300 streams depth 640x480 (VGA), [10,30,60] fps")
224  {
225  for (auto & fps : { 10,30,60 })
226  {
227  INFO("Testing " << fps << " fps")
228  test_sr300_streaming({ { RS_STREAM_DEPTH, 640, 480, RS_FORMAT_Z16, fps } });
229  }
230  }
231 
232  SECTION("SR300 streams depth 640x240 (HVGA), [10,30,60,110] fps")
233  {
234  for (auto & fps : { 10,30,60,110 })
235  {
236  INFO("Testing " << fps << " fps")
237  test_sr300_streaming({ { RS_STREAM_DEPTH, 640, 240, RS_FORMAT_Z16, fps } });
238  }
239  }
240 }
241 
243 // Infrared streaming tests //
245 
246 TEST_CASE( "SR300 infrared stream (Y16)", "[live] [sr300] [one-camera]" )
247 {
248  SECTION("SR300 streams infrared 640x240 depth (VGA), [30,60,120,200] fps")
249  {
250  for (auto & fps : { 30,60,120,200 })
251  {
252  INFO("Testing " << fps << " fps")
253  test_sr300_streaming({ { RS_STREAM_INFRARED, 640, 480, RS_FORMAT_Y16, fps } });
254  }
255  }
256 }
257 
259 // Multiple-stream configurations tests //
261 
262 TEST_CASE( "SR300 streams 640x480 depth and infrared", "[live] [sr300] [one-camera]" )
263 {
265  {RS_STREAM_INFRARED, 640, 480, RS_FORMAT_Y16, 60}});
266 }
267 
268 TEST_CASE( "SR300 streams 640x240 depth and infrared", "[live] [sr300] [one-camera]" )
269 {
271  {RS_STREAM_INFRARED, 640, 240, RS_FORMAT_Y16, 60}});
272 }
273 
274 TEST_CASE( "SR300 streams 640x240 depth and infrared (110 fps)", "[live] [sr300] [one-camera]" )
275 {
277  {RS_STREAM_INFRARED, 640, 240, RS_FORMAT_Y16, 110}});
278 }
279 
280 TEST_CASE( "SR300 streams 640x480 depth, infrared, and color", "[live] [sr300] [one-camera]" )
281 {
283  {RS_STREAM_INFRARED, 640, 480, RS_FORMAT_Y16, 60},
284  {RS_STREAM_COLOR, 640, 480, RS_FORMAT_RGB8, 60}});
285 }
286 
287 TEST_CASE( "SR300 streams 640x240 depth and infrared (110 fps), and 1080P color (30 fps)", "[live] [sr300] [one-camera]" )
288 {
290  {RS_STREAM_INFRARED, 640, 240, RS_FORMAT_Y16, 110},
291  {RS_STREAM_COLOR, 1920, 1080, RS_FORMAT_RGB8, 30}});
292 }
293 
294 TEST_CASE( "SR300 streams 640x480 infrared (200 fps), and VGA color (60 fps)", "[live] [sr300] [one-camera]" )
295 {
297  {RS_STREAM_COLOR, 640, 480, RS_FORMAT_RGB8, 60}});
298 }
299 
300 TEST_CASE( "SR300 streams 640x480 infrared (200 fps), and 1080P color (30 fps)", "[live] [sr300] [one-camera]" )
301 {
303  {RS_STREAM_COLOR, 1920, 1080, RS_FORMAT_RGB8, 30}});
304 }
305 
307 // Options //
309 
310 enum { BEFORE_START_DEVICE = 1, AFTER_START_DEVICE = 2 };
311 inline void test_sr300_option(rs_option option, std::initializer_list<int> values, int when)
312 {
315 
317  REQUIRE(dev != nullptr);
318  REQUIRE(rs_get_device_name(dev, require_no_error()) == std::string("Intel RealSense SR300"));
319 
320  if(when & BEFORE_START_DEVICE)
321  {
322  test_option(dev, option, values, {});
323  }
324 
325  if(when & AFTER_START_DEVICE)
326  {
329 
330  // Currently, setting/getting options immediately after streaming frequently raises hardware errors
331  // todo - Internally block or retry failed calls within the first few seconds after streaming
332  std::this_thread::sleep_for(std::chrono::seconds(1));
333  test_option(dev, option, values, {});
334  }
335 }
336 
337 TEST_CASE( "SR300 supports RS_OPTION_F200_LASER_POWER", "[live] [sr300]" )
338 {
340 }
341 
342 TEST_CASE( "SR300 supports RS_OPTION_F200_ACCURACY", "[live] [sr300]" )
343 {
345 }
346 
347 TEST_CASE( "SR300 supports RS_OPTION_F200_MOTION_RANGE", "[live] [sr300]" )
348 {
350 }
351 
352 TEST_CASE( "SR300 supports RS_OPTION_F200_FILTER_OPTION", "[live] [sr300]" )
353 {
355 }
356 
357 TEST_CASE( "SR300 supports RS_OPTION_F200_CONFIDENCE_THRESHOLD", "[live] [sr300]" )
358 {
360 }
361 
363 // Stop, reconfigure, and restart tests //
365 
366 TEST_CASE( "a single SR300 can stream a variety of reasonable streaming mode combinations", "[live] [sr300] [one-camera]" )
367 {
369 
370  SECTION( "exactly one device is connected" )
371  {
372  int device_count = rs_get_device_count(ctx, require_no_error());
373  REQUIRE(device_count == 1);
374  }
375 
377  REQUIRE(dev != nullptr);
378 
379  SECTION( "device name is Intel RealSense SR300" )
380  {
381  const char * name = rs_get_device_name(dev, require_no_error());
382  REQUIRE(name == std::string("Intel RealSense SR300"));
383  }
384 
385  SECTION( "streaming is possible in some reasonable configurations" )
386  {
387  INFO("Streaming Z16, 60 fps");
388  test_streaming(dev, {
389  {RS_STREAM_DEPTH, 640, 480, RS_FORMAT_Z16, 60}
390  });
391 
392  INFO("Streaming Depth + Color 60 fps");
393  test_streaming(dev, {
394  {RS_STREAM_DEPTH, 640, 480, RS_FORMAT_Z16, 60},
395  {RS_STREAM_COLOR, 640, 480, RS_FORMAT_RGB8, 60}
396  });
397 
398  INFO("Streaming Depth + Infrared 60 fps");
399  test_streaming(dev, {
400  {RS_STREAM_DEPTH, 640, 480, RS_FORMAT_Z16, 60},
401  {RS_STREAM_INFRARED, 640, 480, RS_FORMAT_Y16, 60}
402  });
403 
404  INFO("Streaming Depth + Infrared + Color 60 fps");
405  test_streaming(dev, {
406  {RS_STREAM_DEPTH, 640, 480, RS_FORMAT_Z16, 60},
407  {RS_STREAM_COLOR, 640, 480, RS_FORMAT_RGB8, 60},
408  {RS_STREAM_INFRARED, 640, 480, RS_FORMAT_Y16, 60}
409  });
410  }
411 }
412 
413 inline void test_options(rs_device * device, rs_option* option_list, size_t options, std::vector<double> good_values, std::vector<double> bad_values, std::vector<double> &ret_values, const std::string & expected_success_msg, const std::string & expected_error_msg, bool bWrite)
414 {
415  if (bWrite)
416  {
417  // Test setting good values
418  if (good_values.size() == options)
419  {
420  if (expected_success_msg.size())
421  rs_set_device_options(device, option_list, (unsigned int)options, good_values.data(), require_error(expected_success_msg));
422  else
423  rs_set_device_options(device, option_list, (unsigned int)options, good_values.data(), require_no_error());
424  }
425 
426  if (bad_values.size() == options)
427  {
428  if (expected_error_msg.size())
429  rs_set_device_options(device, option_list, (unsigned int)options, bad_values.data(), require_error(expected_error_msg));
430  else
431  rs_set_device_options(device, option_list, (unsigned int)options, bad_values.data(), require_no_error());
432  }
433  }
434  else // Read command
435  {
436  std::vector<double> vretVal;
437  vretVal.resize(options);
438  if (expected_success_msg.size())
439  rs_get_device_options(device, option_list, (unsigned int)options, vretVal.data(), require_error(expected_success_msg));
440  else
441  rs_get_device_options(device, option_list, (unsigned int)options, vretVal.data(), require_no_error());
442 
443  // Results to be returned
444  ret_values = vretVal;
445  }
446 }
447 
448 inline void test_sr300_command(rs_device *dev, std::vector<rs_option> options_list,
449  std::vector<double> good_values, std::vector<double> bad_values, std::vector<double>& ret_values, const std::string& expected_success_msg, const std::string& expected_error_msg, int when, bool write_cmd)
450 {
451  REQUIRE(dev != nullptr);
452 
453  for (auto opt : options_list)
454  {
456  }
457 
458  if (when & BEFORE_START_DEVICE)
459  {
460  test_options(dev, options_list.data(), options_list.size(), good_values, bad_values, ret_values, expected_success_msg, expected_error_msg, write_cmd);
461  }
462 
463  if (when & AFTER_START_DEVICE)
464  {
467 
468  // Currently, setting/getting options immediately after streaming frequently raises hardware errors
469  // todo - Internally block or retry failed calls within the first few seconds after streaming
470  std::this_thread::sleep_for(std::chrono::milliseconds(50));
471  test_options(dev, options_list.data(), options_list.size(), good_values, bad_values, ret_values, expected_success_msg, expected_error_msg, write_cmd);
472 
473  std::this_thread::sleep_for(std::chrono::milliseconds(50));
475  }
476 }
477 
478 #endif /* !defined(MAKEFILE) || ( defined(LIVE_TEST) && defined(SR300_TEST) ) */
int rs_get_device_count(const rs_context *context, rs_error **error)
Determines number of connected devices.
Definition: rs.cpp:113
void rs_get_device_options(rs_device *device, const rs_option *options, unsigned int count, double *values, rs_error **error)
Efficiently retrieves the value of an arbitrary number of options, using minimal hardware IO...
void rs_set_device_options(rs_device *device, const rs_option *options, unsigned int count, const double *values, rs_error **error)
Efficiently sets the value of an arbitrary number of options, using minimal hardware IO...
GLsizei const GLchar *const * string
Definition: glext.h:683
#define REQUIRE(expr)
Definition: catch.hpp:9333
const char * rs_get_device_name(const rs_device *device, rs_error **error)
Retrieves human-readable device model string.
Definition: rs.cpp:128
rs_option
Defines general configuration controls.
Definition: rs.h:128
float rs_get_device_depth_scale(const rs_device *device, rs_error **error)
Retrieves mapping between the units of the depth image and meters.
Definition: rs.cpp:420
void require_zero_vector(const float(&vector)[3])
float translation[3]
Definition: rs.h:335
void test_sr300_option(rs_option option, std::initializer_list< int > values, int when)
void rs_get_device_extrinsics(const rs_device *device, rs_stream from_stream, rs_stream to_stream, rs_extrinsics *extrin, rs_error **error)
Retrieves extrinsic transformation between the viewpoints of two different streams.
Definition: rs.cpp:163
GLuint GLuint end
Definition: glext.h:111
GLfloat f
Definition: glext.h:1868
int rs_device_supports_option(const rs_device *device, rs_option option, rs_error **error)
Determines if the device allows a specific option to be queried and set.
Definition: rs.cpp:182
void test_streaming(rs_device *device, std::initializer_list< stream_mode > modes)
void test_sr300_streaming(std::initializer_list< stream_mode > modes)
auto ctx
void test_sr300_command(rs_device *dev, std::vector< rs_option > options_list, std::vector< double > good_values, std::vector< double > bad_values, std::vector< double > &ret_values, const std::string &expected_success_msg, const std::string &expected_error_msg, int when, bool write_cmd)
void require_identity_matrix(const float(&matrix)[9])
GLfloat seconds
Definition: wglext.h:657
Cross-stream extrinsics: encode the topology describing how the different devices are connected...
Definition: rs.h:332
void test_options(rs_device *device, rs_option *option_list, size_t options, std::vector< double > good_values, std::vector< double > bad_values, std::vector< double > &ret_values, const std::string &expected_success_msg, const std::string &expected_error_msg, bool bWrite)
void test_option(rs_device *device, rs_option option, std::initializer_list< int > good_values, std::initializer_list< int > bad_values)
float rotation[9]
Definition: rs.h:334
GLenum GLsizei GLsizei GLint * values
Definition: glext.h:1484
TEST_CASE("SR300 metadata enumerates correctly","[live] [sr300]")
GLuint const GLchar * name
Definition: glext.h:655
rs_device * dev
rs_device * rs_get_device(rs_context *context, int index, rs_error **error)
Retrieves connected device by index.
Definition: rs.cpp:120
void rs_enable_stream_preset(rs_device *device, rs_stream stream, rs_preset preset, rs_error **error)
Enables a specific stream and requests properties using a preset.
Definition: rs.cpp:232
#define SECTION(name, description)
Definition: catch.hpp:9370
void rs_start_device(rs_device *device, rs_error **error)
Begins streaming on all enabled streams for this device.
Definition: rs.cpp:383
void rs_stop_device(rs_device *device, rs_error **error)
Ends data acquisition for the specified source providers.
Definition: rs.cpp:398
#define INFO(msg)
Definition: catch.hpp:9353


librealsense
Author(s): Sergey Dorodnicov , Mark Horn , Reagan Lopez
autogenerated on Fri Mar 13 2020 03:16:18