10 #include "../include/librealsense2/rs_advanced_mode.hpp" 29 for (
size_t iter = 0; iter < 10; iter++)
31 std::vector<rs2::device> list;
42 for (
auto i = 0;
i < 1000;
i++)
44 std::map<std::string, size_t> frames_per_stream{};
45 std::map<std::string, size_t> frames_indx_per_stream{};
46 std::vector<std::string> drop_descriptions;
55 std::lock_guard<std::mutex> lock(m);
56 auto stream_name = f.get_profile().stream_name();
57 auto fn = f.get_frame_number();
59 if (frames_per_stream[stream_name])
61 auto prev_fn = frames_indx_per_stream[stream_name];
62 if ((fn = prev_fn) != 1)
66 s <<
"Frame drop was recognized for " << stream_name<<
" jumped from " << prev_fn <<
" to " << fn;
67 drop_descriptions.emplace_back(s.str().c_str());
70 ++frames_per_stream[stream_name];
71 frames_indx_per_stream[stream_name] = fn;
75 std::this_thread::sleep_for(std::chrono::seconds(60));
83 std::stringstream active_profiles, streams_arrived;
84 active_profiles <<
"Profiles requested : " <<
profiles.second.size() << std::endl;
86 active_profiles << pf << std::endl;
87 streams_arrived <<
"Streams recorded : " << frames_per_stream.size() << std::endl;
88 for (
auto& frec : frames_per_stream)
89 streams_arrived << frec.first <<
": frames = " << frec.second << std::endl;
91 CAPTURE(active_profiles.str().c_str());
92 CAPTURE(streams_arrived.str().c_str());
95 s <<
"Streaming cycle " <<
i <<
" iteration " << iter <<
" completed,\n" 96 << active_profiles.str() << std::endl << streams_arrived.str() << std::endl;
97 WARN(s.str().c_str());
102 for (
auto&
str : drop_descriptions)
104 s <<
str << std::endl;
106 WARN(
"\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!! " << drops_count <<
" Drop were identified !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n");
107 WARN(s.str().c_str());
115 if (advanced.is_enabled())
117 std::cout <<
"Iteration " << iter <<
" ended, resetting device..." << std::endl;
118 advanced.hardware_reset();
119 std::this_thread::sleep_for(std::chrono::seconds(3));
124 FAIL(
"Device doesn't support AdvancedMode API");
135 std::condition_variable
cv;
143 for (
size_t iter = 0; iter < 1000; iter++)
145 std::vector<rs2::device> list;
150 bool is_l500_device =
false;
154 is_l500_device =
true;
161 size_t drops_count=0;
162 bool all_streams =
true;
166 float interval_msec = 1000.f /
fps;
168 for (
auto i = 0;
i < 200;
i++)
170 std::map<std::string, size_t> frames_per_stream{};
171 std::map<std::string, size_t> last_frame_per_stream{};
172 std::map<std::string, double> last_frame_ts_per_stream{};
173 std::map<std::string, rs2_timestamp_domain> last_ts_domain_per_stream{};
174 std::vector<std::string> drop_descriptions;
175 bool iter_finished =
false;
177 int width = is_l500_device ? 640 : 848;
184 std::stringstream ss;
185 ss <<
"Iteration " <<
i <<
" started, time = " << std::dec << start_time.time_since_epoch().count() << std::endl;
186 std::string syscl =
"echo \"timecheck: $(date +%s.%N) = $(date +%FT%T,%N)\" | sudo tee /dev/kmsg";
187 auto r =
system(syscl.c_str());
188 ss <<
"sys call result = " <<
r;
190 std::cout << ss.str().c_str() << std::endl;
193 REQUIRE_NOTHROW(
s.start([&m, &frames_per_stream,&last_frame_per_stream,&last_frame_ts_per_stream,&last_ts_domain_per_stream,&drops_count,
194 &drop_descriptions,&cv,&all_streams,&iter_finished,start_time,
profiles,interval_msec,syscl](
rs2::frame f)
196 auto time_elapsed = std::chrono::duration<double, std::milli>(std::chrono::high_resolution_clock::now() - start_time);
197 auto stream_name = f.get_profile().stream_name();
198 auto fn = f.get_frame_number();
199 auto ts = f.get_timestamp();
200 auto ts_dom = f.get_frame_timestamp_domain();
202 if (frames_per_stream[stream_name])
204 auto prev_fn = last_frame_per_stream[stream_name];
205 auto prev_ts = last_frame_ts_per_stream[stream_name];
206 auto prev_ts_dom = last_ts_domain_per_stream[stream_name];
207 auto delta_t = ts - prev_ts;
208 auto min_delay = interval_msec*3.5;
209 auto max_delay = interval_msec*20;
211 auto arrival_time = std::chrono::duration<double, std::milli>(std::chrono::high_resolution_clock::now() - start_time);
213 if (time_elapsed.count() > 2000)
215 if (RS2_FORMAT_MOTION_XYZ32F != f.get_profile().format())
218 ((delta_t >= min_delay) && (RS2_TIMESTAMP_DOMAIN_SYSTEM_TIME !=ts_dom) && (ts_dom ==prev_ts_dom)))
220 if ((fn - prev_fn) > 1)
223 s <<
"Frame drop was recognized for " << stream_name <<
" jump from fn " << prev_fn <<
" to fn " << fn
224 <<
" from " << std::fixed << std::setprecision(3) << prev_ts <<
" to " 225 << ts <<
" while expected ts = " << (prev_ts + interval_msec)
226 <<
", ts domain " << ts_dom
227 <<
" time elapsed: " << time_elapsed.count()/1000.f <<
" sec, host time: " 228 << std::chrono::high_resolution_clock::now().time_since_epoch().count();
229 if (f.supports_frame_metadata(RS2_FRAME_METADATA_FRAME_TIMESTAMP))
230 s <<
" hw ts: " << f.get_frame_metadata(RS2_FRAME_METADATA_FRAME_TIMESTAMP) <<
" = 0x" 231 << std::hex << f.get_frame_metadata(RS2_FRAME_METADATA_FRAME_TIMESTAMP) << std::dec;
232 WARN(s.str().c_str());
233 if ((delta_t < max_delay) || (fabs(fn - prev_fn)< 20))
235 std::cout <<
"Frame interval = " << delta_t <<
", max = " << max_delay << std::endl;
236 std::cout <<
"fn = " << fn <<
", prev_fn = " << prev_fn << std::endl;
237 system(syscl.c_str());
240 drop_descriptions.emplace_back(s.str().c_str());
250 auto sec_now = int(arrival_time.count()) / 1000;
251 if (sec_now && (sec_now != (int(time_elapsed.count())/ 1000)) )
252 std::cout <<
"Test runs for " << int(arrival_time.count()) / 1000 <<
" seconds" << std::endl;
254 if ((int(arrival_time.count()) / 10000) != (int(time_elapsed.count())/ 10000) )
257 s <<
"Frames arrived: ";
258 for (const auto& entry : frames_per_stream)
259 s << entry.first <<
" : " << entry.second <<
", ";
261 std::cout << s.str().c_str();
265 if (arrival_time.count() > 20000)
267 std::lock_guard<std::mutex> lock(m);
268 iter_finished = true;
271 time_elapsed = arrival_time;
273 ++frames_per_stream[stream_name];
274 last_frame_per_stream[stream_name] = fn;
275 last_frame_ts_per_stream[stream_name] = ts;
277 std::lock_guard<std::mutex> lock(m);
278 if (drops_count || (!all_streams))
286 std::unique_lock<std::mutex> lk(m);
287 cv.wait(lk, [&drops_count,&all_streams,&iter_finished]{
return (drops_count>0 || (!all_streams) || iter_finished);});
290 std::cout <<
"Drops = " << drops_count <<
", All streams valid = " << int(all_streams) <<
" iter completed = " << int(iter_finished) << std::endl;
298 std::stringstream active_profiles, streams_arrived;
299 active_profiles <<
"Profiles requested : " <<
profiles.second.size() << std::endl;
301 active_profiles << pf << std::endl;
302 streams_arrived <<
"Streams recorded : " << frames_per_stream.size() << std::endl;
303 for (
auto& frec : frames_per_stream)
304 streams_arrived << frec.first <<
": frames = " << frec.second << std::endl;
306 CAPTURE(active_profiles.str().c_str());
307 CAPTURE(streams_arrived.str().c_str());
310 s <<
"Streaming cycle " <<
i <<
" iteration " << iter <<
" completed,\n" 311 << active_profiles.str() << std::endl << streams_arrived.str() << std::endl;
312 WARN(s.str().c_str());
317 for (
auto&
str : drop_descriptions)
319 s <<
str << std::endl;
321 WARN(
"\n!!! " << drops_count <<
" Drop were identified !!!\n");
322 WARN(s.str().c_str());
333 if (advanced.is_enabled())
335 std::cout <<
"Iteration " << iter <<
" ended, resetting device..." << std::endl;
336 advanced.hardware_reset();
337 std::this_thread::sleep_for(std::chrono::seconds(3));
343 FAIL(
"Device doesn't support AdvancedMode API");
359 for (
size_t iter = 0; iter < 10000; iter++)
361 std::vector<rs2::device> list;
365 auto dev = std::make_shared<device>(list.front());
373 for (
auto&&
sensor : dev->query_sensors())
382 for (
auto i = 0;
i < 1;
i++)
384 std::map<std::string, size_t> frames_per_stream{};
385 std::map<std::string, size_t> frames_indx_per_stream{};
386 std::vector<std::string> drop_descriptions;
389 size_t drops_count = 0;
395 std::lock_guard<std::mutex> lock(m);
396 auto stream_name = f.get_profile().stream_name();
397 auto fn = f.get_frame_number();
399 if (frames_per_stream[stream_name])
401 auto prev_fn = frames_indx_per_stream[stream_name];
402 if ((fn = prev_fn) != 1)
406 s <<
"Frame drop was recognized for " << stream_name <<
" jumped from " << prev_fn <<
" to " << fn;
407 drop_descriptions.emplace_back(s.str().c_str());
410 ++frames_per_stream[stream_name];
411 frames_indx_per_stream[stream_name] = fn;
415 std::this_thread::sleep_for(std::chrono::seconds(2));
423 std::stringstream active_profiles, streams_arrived;
424 active_profiles <<
"Profiles requested : " <<
profiles.second.size() << std::endl;
426 active_profiles << pf << std::endl;
427 streams_arrived <<
"Streams recorded : " << frames_per_stream.size() << std::endl;
428 for (
auto& frec : frames_per_stream)
429 streams_arrived << frec.first <<
": frames = " << frec.second << std::endl;
431 CAPTURE(active_profiles.str().c_str());
432 CAPTURE(streams_arrived.str().c_str());
435 s <<
"Streaming cycle " <<
i <<
" iteration " << iter <<
" completed,\n" 436 << active_profiles.str() << std::endl << streams_arrived.str() << std::endl;
437 WARN(s.str().c_str());
442 for (
auto&
str : drop_descriptions)
444 s <<
str << std::endl;
446 WARN(
"\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!! " << drops_count <<
" Drop were identified !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n");
447 WARN(s.str().c_str());
455 dev->hardware_reset();
456 std::cout <<
"Iteration " << iter <<
" ended, resetting device..." << std::endl;
std::vector< profile > configure_all_supported_streams(rs2::sensor &sensor, int width=640, int height=480, int fps=60)
TEST_CASE("DSO-14512","[live]")
device_list query_devices() const
void log(rs2_log_severity severity, const char *message)
GLsizei const GLchar *const * string
GLint GLsizei GLsizei height
static std::condition_variable cv
#define SECTION_FROM_TEST_NAME
void log_to_file(rs2_log_severity min_severity, const char *file_path=nullptr)
bool supports(rs2_camera_info info) const
bool make_context(const char *id, rs2::context *ctx, std::string min_api_version="0.0.0")
#define RS2_PRODUCT_LINE_ANY
std::shared_ptr< rs2::device > do_with_waiting_for_camera_connection(rs2::context ctx, std::shared_ptr< rs2::device > dev, std::string serial, std::function< void()> operation)
REQUIRE_NOTHROW(rs2_log(RS2_LOG_SEVERITY_INFO,"Log message using rs2_log()", nullptr))
void disable_sensitive_options_for(rs2::sensor &sen)
bool is_usb3(const rs2::device &dev)
void set_option(rs2_option option, float value) const