Skip to content

Commit b6eb86c

Browse files
committed
added auto hdr unit test and better hubs logs
1 parent 172e5ad commit b6eb86c

File tree

6 files changed

+154
-2
lines changed

6 files changed

+154
-2
lines changed

common/option-model.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ bool option_model::draw( std::string & error_message,
133133
}
134134

135135
#if defined(AUTO_HDR)
136-
if (opt == RS2_OPTION_HDR_ENABLED) // TODO: enable this when the auto-hdr feature is fully implemented, currently works via the load/save preset buttons at the top of the viewer - make sure to disable HDR before loading!
136+
auto advanced = dev->dev.as< rs400::advanced_mode >();
137+
if (opt == RS2_OPTION_HDR_ENABLED && advanced && advanced.is_enabled()) // TODO: enable this when the auto-hdr feature is fully implemented, currently works via the load/save preset buttons at the top of the viewer - make sure to disable HDR before loading!
137138
{
138139
auto disable_hdr_load = value_as_float() > 0; // if HDR is enabled, we can't load a new config
139140

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
# License: Apache 2.0. See LICENSE file in root directory.
2+
# Copyright(c) 2024 Intel Corporation. All Rights Reserved.
3+
4+
# test:device D400*
5+
6+
import pyrealsense2 as rs
7+
from rspy import test, log
8+
import json
9+
10+
hdr_config = {
11+
"hdr-preset": {
12+
"id": "0",
13+
"iterations": "0",
14+
"items": [
15+
{
16+
"iterations": "1",
17+
"controls": [
18+
{
19+
"depth-gain": "16"
20+
},
21+
{
22+
"depth-exposure": "1"
23+
}
24+
]
25+
},
26+
{
27+
"iterations": "2",
28+
"controls": [
29+
{
30+
"depth-gain": "61"
31+
},
32+
{
33+
"depth-exposure": "10"
34+
}
35+
]
36+
},
37+
{
38+
"iterations": "1",
39+
"controls": [
40+
{
41+
"depth-gain": "116"
42+
},
43+
{
44+
"depth-exposure": "100"
45+
}
46+
]
47+
},
48+
{
49+
"iterations": "3",
50+
"controls": [
51+
{
52+
"depth-gain": "161"
53+
},
54+
{
55+
"depth-exposure": "1000"
56+
}
57+
]
58+
},
59+
{
60+
"iterations": "1",
61+
"controls": [
62+
{
63+
"depth-gain": "22"
64+
},
65+
{
66+
"depth-exposure": "10000"
67+
}
68+
]
69+
},
70+
{
71+
"iterations": "2",
72+
"controls": [
73+
{
74+
"depth-gain": "222"
75+
},
76+
{
77+
"depth-exposure": "4444"
78+
}
79+
]
80+
}
81+
]
82+
}
83+
}
84+
85+
device, ctx = test.find_first_device_or_exit()
86+
am = rs.rs400_advanced_mode(device)
87+
88+
with test.closure("Comparing auto-hdr loading and reading"):
89+
prior_config = json.loads(am.serialize_json())
90+
91+
am.load_json(json.dumps(hdr_config)) # json dumps just stringify the object
92+
93+
hdr_config_read = json.loads(am.serialize_json()) # jsonify, note this JSON contains also other keys (params)
94+
test.check(hdr_config_read.get("hdr-preset") == hdr_config.get("hdr-preset"))
95+
96+
# check that the other keys are unchanged
97+
for key in hdr_config_read.keys():
98+
if key != "hdr-preset":
99+
test.check(hdr_config_read[key] == prior_config[key])
100+
101+
with test.closure("Checking streaming data matches config"):
102+
depth_sensor = device.first_depth_sensor()
103+
test.check(depth_sensor.get_option(rs.option.hdr_enabled) == 1)
104+
105+
cfg = rs.config()
106+
cfg.enable_stream(rs.stream.depth)
107+
pipe = rs.pipeline(ctx)
108+
pipe.start(cfg)
109+
110+
expected_data = []
111+
for i, item in enumerate(hdr_config["hdr-preset"]["items"]):
112+
iterations = int(item["iterations"])
113+
for _ in range(iterations):
114+
controls = item["controls"]
115+
expected_data.append({"depth-gain": controls[0]["depth-gain"],
116+
"depth-exposure": controls[1]["depth-exposure"],
117+
"seq-id": i})
118+
batch_size = len(expected_data)
119+
120+
for iteration in range(0, batch_size * 10 + 1):
121+
data = pipe.wait_for_frames()
122+
123+
out_depth_frame = data.get_depth_frame()
124+
if iteration < batch_size:
125+
continue
126+
127+
i = iteration % batch_size
128+
129+
frame_exposure = out_depth_frame.get_frame_metadata(rs.frame_metadata_value.actual_exposure)
130+
test.check(str(frame_exposure) == expected_data[i]["depth-exposure"])
131+
132+
frame_gain = out_depth_frame.get_frame_metadata(rs.frame_metadata_value.gain_level)
133+
test.check(str(frame_gain) == expected_data[i]["depth-gain"])
134+
135+
seq_id = out_depth_frame.get_frame_metadata(rs.frame_metadata_value.sequence_id)
136+
test.check(seq_id == expected_data[i]["seq-id"])
137+
138+
seq_size = out_depth_frame.get_frame_metadata(rs.frame_metadata_value.sequence_size)
139+
test.check(seq_size == len(hdr_config["hdr-preset"]["items"]))
140+
141+
pipe.stop()
142+
143+
test.print_results_and_exit()

unit-tests/py/rspy/acroname.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ def enable_ports(self, ports = None, disable_other_ports = False, sleep_on_chan
203203
"""
204204
result = True
205205
changed = False
206+
log.d(f"Enabling ports {ports if ports is not None else 'all'} on Acroname"
207+
f"{', disabling other ports' if disable_other_ports else ''}")
206208
for port in self.all_ports():
207209
#
208210
if ports is None or port in ports:
@@ -238,6 +240,7 @@ def disable_ports(self, ports = None, sleep_on_change = 0 ):
238240
"""
239241
result = True
240242
changed = False
243+
log.d(f"Disabling ports {ports if ports is not None else 'all'} on Acroname")
241244
for port in self.all_ports():
242245
if ports is None or port in ports:
243246
# log.d("disabling port", port)

unit-tests/py/rspy/combined_hub.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ def disable_ports(self, ports=None, sleep_on_change=0):
127127

128128
success = True
129129
for name, hub in self.hubs.items():
130-
log.d("Disabling ports on hub", name, ":", targets[name])
131130
ok = hub.disable_ports(targets[name], sleep_on_change)
132131
success = success and ok
133132
return success

unit-tests/py/rspy/unifi.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ def _run_command(self, command):
197197
return out
198198

199199
def enable_ports(self, ports=None, disable_other_ports=False, sleep_on_change=0):
200+
log.d(f"Enabling ports {ports if ports is not None else 'all'} on Unifi Switch"
201+
f"{', disabling other ports' if disable_other_ports else ''}")
200202
if ports is None:
201203
ports = self.all_ports()
202204

@@ -215,6 +217,7 @@ def enable_ports(self, ports=None, disable_other_ports=False, sleep_on_change=0)
215217
return True
216218

217219
def disable_ports(self, ports=None, sleep_on_change=0):
220+
log.d(f"Disabling ports {ports if ports is not None else 'all'} on Unifi Switch")
218221
if ports is None:
219222
ports = self.all_ports()
220223

unit-tests/py/rspy/ykush.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ def enable_ports( self, ports = None, disable_other_ports = False, sleep_on_cha
128128
"""
129129
result = True
130130
changed = False
131+
log.d(f"Enabling ports {ports if ports is not None else 'all'} on YKUSH"
132+
f"{', disabling other ports' if disable_other_ports else ''}")
131133
for port in self.all_ports():
132134
if ports is None or port in ports:
133135
if not self.is_port_enabled( port ):
@@ -160,6 +162,7 @@ def disable_ports( self, ports = None, sleep_on_change = 0 ):
160162
"""
161163
result = True
162164
changed = False
165+
log.d(f"Disabling ports {ports if ports is not None else 'all'} on YKUSH")
163166
for port in self.all_ports():
164167
if ports is None or port in ports:
165168
if self.is_port_enabled( port ):

0 commit comments

Comments
 (0)