Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added unitests for alt-ir #7741

Merged
merged 7 commits into from
Nov 25, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 117 additions & 0 deletions unit-tests/func/alt-ir/alt-ir-common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2020 Intel Corporation. All Rights Reserved.

#include "../../test.h"
#include <concurrency.h>

using namespace rs2;


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 ) );

REQUIRE_NOTHROW( depth_sens.start( [&]( rs2::frame f ) {} ) );

// set alt_ir if it was disabled
maloel marked this conversation as resolved.
Show resolved Hide resolved
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 >() )
{
std::condition_variable cv;
maloel marked this conversation as resolved.
Show resolved Hide resolved
std::mutex m;

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 ) );
}


void set_alt_ir_if_needed( const rs2::depth_sensor & depth_sens, float val )
{
// 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 != val )
REQUIRE_NOTHROW( depth_sens.set_option( RS2_OPTION_ALTERNATE_IR, val ) );
}

void enable_alt_ir_and_check_that_all_streams_arrived(
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;

auto wait_for_streams = [&]() {
std::unique_lock< std::mutex > lock( m );
REQUIRE( cv.wait_for( lock, std::chrono::seconds( 20 ), [&]() {
maloel marked this conversation as resolved.
Show resolved Hide resolved
return profiles.size() == 0;
} ) );
};

// wait for all streams

REQUIRE_NOTHROW( depth_sens.start( [&]( rs2::frame f ) {
std::unique_lock< std::mutex > lock( m );
remove_all_streams_arrived( f, profiles );
cv.notify_one();
} ) );

set_alt_ir_if_needed( depth_sens, 1 );

wait_for_streams();

set_alt_ir_if_needed( depth_sens, 0 );

profiles = expected_profiles;

wait_for_streams();

set_alt_ir_if_needed( depth_sens, 1 );

profiles = expected_profiles;

wait_for_streams();

depth_sens.stop();
depth_sens.close();

// return alt IR to default
maloel marked this conversation as resolved.
Show resolved Hide resolved
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 ) );
}
33 changes: 33 additions & 0 deletions unit-tests/func/alt-ir/test-ac-before.cpp
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 "../../test.h"
#include "../func-common.h"
#include "alt-ir-common.h"


using namespace rs2;

TEST_CASE( "AC fails if AltIR was enabled before stream start", "[l500][live]" )
{
auto devices = find_devices_by_product_line_or_exit( RS2_PRODUCT_LINE_L500 );
auto dev = devices[0];

auto depth_sens = dev.first< rs2::depth_sensor >();

if( depth_sens.supports( RS2_OPTION_ALTERNATE_IR ) )
{
REQUIRE_NOTHROW( depth_sens.set_option( RS2_OPTION_ALTERNATE_IR, 1 ) );

auto depth = find_default_depth_profile( depth_sens );
auto ir = find_default_ir_profile( depth_sens );

enable_alt_ir_and_check_that_AC_fails( dev,
dev.first< rs2::depth_sensor >(),
{ depth, ir } );
}
else
std::cout << "FW version " << depth_sens.get_info( RS2_CAMERA_INFO_FIRMWARE_VERSION )
<< " doesn't support alt IR option";
}
35 changes: 35 additions & 0 deletions unit-tests/func/alt-ir/test-ac-while.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2020 Intel Corporation. All Rights Reserved.


#include "../../test.h"
#include "../func-common.h"
#include "alt-ir-common.h"

using namespace rs2;

TEST_CASE( "AC fails if AltIR was enable after stream start", "[l500][live]" )
{
auto devices = find_devices_by_product_line_or_exit( RS2_PRODUCT_LINE_L500 );
auto dev = devices[0];

std::string serial;
maloel marked this conversation as resolved.
Show resolved Hide resolved
REQUIRE_NOTHROW( serial = dev.get_info( RS2_CAMERA_INFO_SERIAL_NUMBER ) );


auto depth_sens = dev.first< rs2::depth_sensor >();

if( depth_sens.supports( RS2_OPTION_ALTERNATE_IR ) )
{
auto depth = find_default_depth_profile( depth_sens );
auto ir = find_default_ir_profile( depth_sens );

enable_alt_ir_and_check_that_AC_fails( dev,
dev.first< rs2::depth_sensor >(),
{ depth, ir } );
}
else
std::cout << depth_sens.get_info( RS2_CAMERA_INFO_FIRMWARE_VERSION )
<< " doesn't support alt IR option";

}
37 changes: 37 additions & 0 deletions unit-tests/func/alt-ir/test-sanity.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2020 Intel Corporation. All Rights Reserved.

#include "../../test.h"
#include "../func-common.h"

using namespace rs2;

TEST_CASE( "AltIR", "[l500][live]" )
{

auto devices = find_devices_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 = dev.first< rs2::depth_sensor >();

if( 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 ) );
maloel marked this conversation as resolved.
Show resolved Hide resolved
}
else
std::cout << depth_sens.get_info( RS2_CAMERA_INFO_FIRMWARE_VERSION )
<< " doesn't support alt IR option";
}
34 changes: 34 additions & 0 deletions unit-tests/func/alt-ir/test-streamimg-before.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2020 Intel Corporation. All Rights Reserved.


#include "../../test.h"
#include "../func-common.h" //todo functional-common.h
#include "alt-ir-common.h" //todo alt-ir-common.h


using namespace rs2;

TEST_CASE( "AC fails if AltIR was enabled before stream start", "[l500][live]" )
maloel marked this conversation as resolved.
Show resolved Hide resolved
{
auto devices = find_devices_by_product_line_or_exit( RS2_PRODUCT_LINE_L500 );
auto dev = devices[0];

auto depth_sens = dev.first< rs2::depth_sensor >();

if( depth_sens.supports( RS2_OPTION_ALTERNATE_IR ) )
{
REQUIRE_NOTHROW( depth_sens.set_option( RS2_OPTION_ALTERNATE_IR, 1 ) );

auto depth = find_default_depth_profile( depth_sens );
auto ir = find_default_ir_profile( depth_sens );
auto confidence = find_confidence_corresponding_to_depth( depth_sens, depth );

enable_alt_ir_and_check_that_all_streams_arrived( dev,
dev.first< rs2::depth_sensor >(),
{ depth, ir, confidence } );
}
else
std::cout << "FW version " << depth_sens.get_info( RS2_CAMERA_INFO_FIRMWARE_VERSION )
<< " doesn't support alt IR option";
}
36 changes: 36 additions & 0 deletions unit-tests/func/alt-ir/test-streaming-while.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2020 Intel Corporation. All Rights Reserved.


#include "../../test.h"
#include "../func-common.h"
#include "alt-ir-common.h"

using namespace rs2;

TEST_CASE( "AC fails if AltIR was enable after stream start", "[l500][live]" )
maloel marked this conversation as resolved.
Show resolved Hide resolved
{
auto devices = find_devices_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 = dev.first< rs2::depth_sensor >();

if( depth_sens.supports( RS2_OPTION_ALTERNATE_IR ) )
{
auto depth = find_default_depth_profile( depth_sens );
auto ir = find_default_ir_profile( depth_sens );
auto confidence = find_confidence_corresponding_to_depth( depth_sens, depth );

enable_alt_ir_and_check_that_all_streams_arrived( dev,
dev.first< rs2::depth_sensor >(),
{ depth, ir, confidence } );
}
else
std::cout << depth_sens.get_info( RS2_CAMERA_INFO_FIRMWARE_VERSION )
<< " doesn't support alt IR option";

}
93 changes: 93 additions & 0 deletions unit-tests/func/func-common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2020 Intel Corporation. All Rights Reserved.

#include "../test.h"
#include "librealsense2/rs.hpp"
#include <concurrency.h>

using namespace rs2;

inline rs2::device_list find_devices_by_product_line_or_exit( int product )
maloel marked this conversation as resolved.
Show resolved Hide resolved
{
rs2::context ctx;
rs2::device_list devices_list = ctx.query_devices( product );
if( devices_list.size() == 0 )
{
std::cout << "No device of the " << product << " product line was found; skipping test"
<< std::endl;
exit( 0 );
}

return devices_list;
}


inline void remove_all_streams_arrived( rs2::frame f,
maloel marked this conversation as resolved.
Show resolved Hide resolved
std::vector< rs2::stream_profile > & stream_to_arrive )
maloel marked this conversation as resolved.
Show resolved Hide resolved
{
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();
}
}

stream_profile find_default_depth_profile( 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;
} );

return *depth_profile;
}

stream_profile find_default_ir_profile( rs2::depth_sensor depth_sens)
{
std::vector< stream_profile > stream_profiles;
REQUIRE_NOTHROW( stream_profiles = depth_sens.get_stream_profiles() );

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;
} );

return *ir_profile;
maloel marked this conversation as resolved.
Show resolved Hide resolved
}

stream_profile find_confidence_corresponding_to_depth( rs2::depth_sensor depth_sens,
stream_profile depth_profile )
{
std::vector< stream_profile > stream_profiles;
REQUIRE_NOTHROW( stream_profiles = depth_sens.get_stream_profiles() );

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()
== depth_profile.as< rs2::video_stream_profile >().width()
&& sp.as< rs2::video_stream_profile >().height()
== depth_profile.as< rs2::video_stream_profile >().height();
} );

return *confidence_profile;
}
Loading