-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
304 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
unit-tests/functional/alt-IR/test-enable-before-stream-start.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// License: Apache 2.0. See LICENSE file in root directory. | ||
// Copyright(c) 2020 Intel Corporation. All Rights Reserved. | ||
|
||
|
||
#include "../../tests.h" | ||
#include "../utilities.h" | ||
|
||
using namespace rs2; | ||
|
||
TEST_CASE( "AC fails if AltIR was enable before stream start", "[l500][live]" ) | ||
{ | ||
|
||
auto devices = find_device_by_product_line_or_exit( RS2_PRODUCT_LINE_L500 ); | ||
auto dev = devices[0]; | ||
std::string serial; | ||
REQUIRE_NOTHROW( serial = dev.get_info( RS2_CAMERA_INFO_SERIAL_NUMBER ) ); | ||
|
||
auto depth_sens = get_depth_sensor( dev ); | ||
|
||
const uint32_t MIN_FW_VER[4] = { 1, 5, 2, 0 }; | ||
if( is_fw_version_newer( depth_sens, MIN_FW_VER ) ) | ||
{ | ||
REQUIRE( depth_sens.supports( RS2_OPTION_ALTERNATE_IR ) ); | ||
REQUIRE_NOTHROW( depth_sens.set_option( RS2_OPTION_ALTERNATE_IR, 1 ) ); | ||
|
||
auto profiles = find_profiles_to_stream( depth_sens ); | ||
enable_alt_ir_and_check_that_AC_fails( dev, get_depth_sensor( dev ), | ||
profiles ); | ||
} | ||
else | ||
std::cout << depth_sens.get_info( RS2_CAMERA_INFO_FIRMWARE_VERSION ) | ||
<< " doesn't support alt IR option"; | ||
} |
32 changes: 32 additions & 0 deletions
32
unit-tests/functional/alt-IR/test-enable-while-streaming.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// License: Apache 2.0. See LICENSE file in root directory. | ||
// Copyright(c) 2020 Intel Corporation. All Rights Reserved. | ||
|
||
|
||
#include "../../tests.h" | ||
#include "../utilities.h" | ||
|
||
using namespace rs2; | ||
|
||
TEST_CASE( "AC fails if AltIR was enable after stream start", "[l500][live]" ) | ||
{ | ||
auto devices = find_device_by_product_line_or_exit( RS2_PRODUCT_LINE_L500 ); | ||
auto dev = devices[0]; | ||
|
||
std::string serial; | ||
REQUIRE_NOTHROW( serial = dev.get_info( RS2_CAMERA_INFO_SERIAL_NUMBER ) ); | ||
|
||
|
||
auto depth_sens = get_depth_sensor( dev ); | ||
|
||
const uint32_t MIN_FW_VER[4] = { 1, 5, 2, 0 }; | ||
if( is_fw_version_newer( depth_sens, MIN_FW_VER ) ) | ||
{ | ||
auto profiles = find_profiles_to_stream( depth_sens ); | ||
enable_alt_ir_and_check_that_AC_fails( dev, get_depth_sensor( dev ), | ||
profiles ); | ||
} | ||
else | ||
std::cout << depth_sens.get_info( RS2_CAMERA_INFO_FIRMWARE_VERSION ) | ||
<< " doesn't support alt IR option"; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// License: Apache 2.0. See LICENSE file in root directory. | ||
// Copyright(c) 2020 Intel Corporation. All Rights Reserved. | ||
|
||
#include "../../tests.h" | ||
|
||
using namespace rs2; | ||
|
||
TEST_CASE( "AltIR", "[l500][live]" ) | ||
{ | ||
|
||
auto devices = find_device_by_product_line_or_exit( RS2_PRODUCT_LINE_L500 ); | ||
auto dev = devices[0]; | ||
|
||
std::string serial; | ||
REQUIRE_NOTHROW( serial = dev.get_info( RS2_CAMERA_INFO_SERIAL_NUMBER ) ); | ||
|
||
auto depth_sens = get_depth_sensor( dev ); | ||
|
||
const uint32_t MIN_FW_VER[4] = { 1, 5, 2, 0 }; | ||
if( is_fw_version_newer( depth_sens, MIN_FW_VER ) ) | ||
{ | ||
REQUIRE( depth_sens.supports( RS2_OPTION_ALTERNATE_IR ) ); | ||
option_range r; | ||
REQUIRE_NOTHROW( r = depth_sens.get_option_range( RS2_OPTION_ALTERNATE_IR ) ); | ||
REQUIRE( depth_sens.get_option( RS2_OPTION_ALTERNATE_IR ) == r.def ); | ||
|
||
for( auto i = r.min; i <= r.max; i++ ) | ||
{ | ||
REQUIRE_NOTHROW( depth_sens.set_option( RS2_OPTION_ALTERNATE_IR, i ) ); | ||
REQUIRE( depth_sens.get_option( RS2_OPTION_ALTERNATE_IR ) == i ); | ||
} | ||
|
||
REQUIRE_NOTHROW( depth_sens.set_option( RS2_OPTION_ALTERNATE_IR, r.def ) ); | ||
} | ||
else | ||
std::cout << depth_sens.get_info( RS2_CAMERA_INFO_FIRMWARE_VERSION ) | ||
<< " doesn't support alt IR option"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// License: Apache 2.0. See LICENSE file in root directory. | ||
// Copyright(c) 2020 Intel Corporation. All Rights Reserved. | ||
|
||
#include "../../tests.h" | ||
#include "../include/librealsense2/rs.hpp" | ||
#include "../include/librealsense2/hpp/rs_context.hpp" | ||
#include "../include/librealsense2/hpp/rs_internal.hpp" | ||
#include "concurrency.h" | ||
|
||
using namespace rs2; | ||
|
||
std::vector< stream_profile > find_profiles_to_stream( rs2::depth_sensor depth_sens ) | ||
{ | ||
std::vector< stream_profile > stream_profiles; | ||
REQUIRE_NOTHROW( stream_profiles = depth_sens.get_stream_profiles() ); | ||
|
||
auto depth_profile | ||
= std::find_if( stream_profiles.begin(), stream_profiles.end(), []( stream_profile sp ) { | ||
return sp.is_default() && sp.stream_type() == RS2_STREAM_DEPTH; | ||
} ); | ||
|
||
auto ir_profile | ||
= std::find_if( stream_profiles.begin(), stream_profiles.end(), []( stream_profile sp ) { | ||
return sp.is_default() && sp.stream_type() == RS2_STREAM_INFRARED; | ||
} ); | ||
|
||
auto confidence_profile | ||
= std::find_if( stream_profiles.begin(), stream_profiles.end(), [&]( stream_profile sp ) { | ||
return sp.stream_type() == RS2_STREAM_CONFIDENCE | ||
&& sp.as< rs2::video_stream_profile >().width() | ||
== ir_profile->as< rs2::video_stream_profile >().width() | ||
&& sp.as< rs2::video_stream_profile >().height() | ||
== ir_profile->as< rs2::video_stream_profile >().height(); | ||
} ); | ||
|
||
return { *depth_profile, *ir_profile, *confidence_profile }; | ||
} | ||
|
||
void enable_alt_ir_and_check_that_AC_fails( const rs2::device& dev, | ||
const rs2::depth_sensor& depth_sens, | ||
const std::vector< stream_profile > & expected_profiles ) | ||
{ | ||
std::vector< stream_profile > profiles = expected_profiles; | ||
REQUIRE_NOTHROW( depth_sens.open( profiles ) ); | ||
|
||
std::condition_variable cv; | ||
std::mutex m; | ||
|
||
// wait for all streams | ||
// scope for unique_lock | ||
{ | ||
REQUIRE_NOTHROW( depth_sens.start( [&]( rs2::frame f ) { | ||
std::unique_lock< std::mutex > lock( m ); | ||
remove_all_streams_arrived( f, profiles ); | ||
cv.notify_one(); | ||
} ) ); | ||
|
||
std::unique_lock< std::mutex > lock( m ); | ||
REQUIRE( cv.wait_for( lock, std::chrono::seconds( 20 ), [&]() { | ||
return profiles.size() == 0; | ||
} ) ); | ||
} | ||
|
||
// set alt_ir if it was disabled | ||
REQUIRE( depth_sens.supports( RS2_OPTION_ALTERNATE_IR ) ); | ||
auto alt_ir = depth_sens.get_option( RS2_OPTION_ALTERNATE_IR ); | ||
if( alt_ir == 0) | ||
REQUIRE_NOTHROW( depth_sens.set_option( RS2_OPTION_ALTERNATE_IR, 1 ) ); | ||
|
||
// check that AC throws exception | ||
if( dev.is< rs2::device_calibration >() ) | ||
{ | ||
auto calib = dev.as< rs2::device_calibration >(); | ||
|
||
rs2_calibration_status status; | ||
calib.register_calibration_change_callback( [&]( rs2_calibration_status cal_status ) { | ||
std::unique_lock< std::mutex > lock( m ); | ||
status = cal_status; | ||
cv.notify_one(); | ||
} ); | ||
|
||
REQUIRE_THROWS( calib.trigger_device_calibration( RS2_CALIBRATION_MANUAL_DEPTH_TO_RGB ) ); | ||
|
||
std::unique_lock< std::mutex > lock( m ); | ||
REQUIRE( cv.wait_for( lock, std::chrono::seconds( 20 ), [&]() { | ||
return status == RS2_CALIBRATION_BAD_CONDITIONS; | ||
} ) ); | ||
} | ||
|
||
depth_sens.stop(); | ||
depth_sens.close(); | ||
|
||
// return alt IR to default | ||
option_range r; | ||
REQUIRE_NOTHROW( r = depth_sens.get_option_range( RS2_OPTION_ALTERNATE_IR ) ); | ||
REQUIRE_NOTHROW( depth_sens.set_option( RS2_OPTION_ALTERNATE_IR, r.def ) ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// License: Apache 2.0. See LICENSE file in root directory. | ||
// Copyright(c) 2015 Intel Corporation. All Rights Reserved. | ||
|
||
#pragma once | ||
#ifndef TESTS_H | ||
#define TESTS_H | ||
|
||
#include "../include/librealsense2/rs.hpp" | ||
|
||
#define CATCH_CONFIG_MAIN | ||
|
||
#include "catch.h" | ||
|
||
#include <easylogging++.h> | ||
#ifdef BUILD_SHARED_LIBS | ||
// With static linkage, ELPP is initialized by librealsense, so doing it here will | ||
// create errors. When we're using the shared .so/.dll, the two are separate and we have | ||
// to initialize ours if we want to use the APIs! | ||
INITIALIZE_EASYLOGGINGPP | ||
#endif | ||
|
||
inline rs2::device_list find_device_by_product_line_or_exit( int product ) | ||
{ | ||
rs2::context ctx; | ||
rs2::device_list devices_list = ctx.query_devices( product ); | ||
size_t device_count = devices_list.size(); | ||
if( device_count == 0 ) | ||
{ | ||
std::cout << "No L500 device connected "; | ||
exit( 0 ); | ||
} | ||
|
||
return devices_list; | ||
} | ||
|
||
inline rs2::depth_sensor get_depth_sensor( rs2::device dev ) | ||
{ | ||
auto sensors = dev.query_sensors(); | ||
|
||
auto it = std::find_if( sensors.begin(), sensors.end(), []( rs2::sensor s ) { | ||
return s.is< rs2::depth_sensor >(); | ||
} ); | ||
|
||
return *it; | ||
} | ||
|
||
inline void remove_all_streams_arrived( rs2::frame f, | ||
std::vector< rs2::stream_profile > & stream_to_arrive ) | ||
{ | ||
auto remove_stream = [&]() { | ||
auto it = std::remove_if( stream_to_arrive.begin(), | ||
stream_to_arrive.end(), | ||
[&]( rs2::stream_profile s ) { | ||
return s.stream_type() == f.get_profile().stream_type(); | ||
} ); | ||
|
||
|
||
if( it != stream_to_arrive.end() ) | ||
stream_to_arrive.erase( it ); | ||
}; | ||
|
||
if( f.is< rs2::frameset >() ) | ||
{ | ||
auto set = f.as< rs2::frameset >(); | ||
set.foreach_rs( [&]( rs2::frame fr ) { remove_stream(); } ); | ||
} | ||
else | ||
{ | ||
remove_stream(); | ||
} | ||
} | ||
|
||
inline std::vector< uint32_t > split( const std::string & s, char delim ) | ||
{ | ||
std::stringstream ss( s ); | ||
std::string item; | ||
std::vector< uint32_t > tokens; | ||
while( std::getline( ss, item, delim ) ) | ||
{ | ||
tokens.push_back( std::stoi( item, nullptr ) ); | ||
} | ||
return tokens; | ||
} | ||
|
||
inline bool is_fw_version_newer( rs2::sensor & subdevice, const uint32_t other_fw[4] ) | ||
{ | ||
std::string fw_version_str; | ||
REQUIRE_NOTHROW( fw_version_str = subdevice.get_info( RS2_CAMERA_INFO_FIRMWARE_VERSION ) ); | ||
auto fw = split( fw_version_str, '.' ); | ||
if( fw[0] > other_fw[0] ) | ||
return true; | ||
if( fw[0] == other_fw[0] && fw[1] > other_fw[1] ) | ||
return true; | ||
if( fw[0] == other_fw[0] && fw[1] == other_fw[1] && fw[2] > other_fw[2] ) | ||
return true; | ||
if( fw[0] == other_fw[0] && fw[1] == other_fw[1] && fw[2] == other_fw[2] | ||
&& fw[3] > other_fw[3] ) | ||
return true; | ||
if( fw[0] == other_fw[0] && fw[1] == other_fw[1] && fw[2] == other_fw[2] | ||
&& fw[3] == other_fw[3] ) | ||
return true; | ||
return false; | ||
} | ||
#endif |