Check the device calibration in the firmware tests (#220)
Compare the calibration before and after the firmware update to ensure that it is preserved through updates.
This commit is contained in:
Родитель
bc5a2aebb7
Коммит
b1aa7fc807
|
@ -14,6 +14,7 @@ target_link_libraries(firmware_fw PRIVATE
|
|||
k4ainternal::conn_ex_utility
|
||||
k4ainternal::depth_mcu
|
||||
k4ainternal::color_mcu
|
||||
k4ainternal::calibration
|
||||
k4ainternal::firmware
|
||||
k4ainternal::logging
|
||||
k4ainternal::usb_cmd)
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include <k4ainternal/logging.h>
|
||||
#include <k4ainternal/usbcommand.h>
|
||||
#include <k4ainternal/calibration.h>
|
||||
|
||||
#include <azure_c_shared_utility/tickcounter.h>
|
||||
#include <azure_c_shared_utility/threadapi.h>
|
||||
|
@ -59,17 +60,155 @@ protected:
|
|||
serial_number = nullptr;
|
||||
serial_number_length = 0;
|
||||
}
|
||||
|
||||
if (calibration_pre_update != nullptr)
|
||||
{
|
||||
free(calibration_pre_update);
|
||||
calibration_pre_update = nullptr;
|
||||
calibration_pre_update_size = 0;
|
||||
}
|
||||
|
||||
if (calibration_post_update != nullptr)
|
||||
{
|
||||
free(calibration_post_update);
|
||||
calibration_post_update = nullptr;
|
||||
calibration_post_update_size = 0;
|
||||
}
|
||||
}
|
||||
|
||||
k4a_result_t connect_device()
|
||||
{
|
||||
k4a_result_t result = g_connection_exerciser->set_usb_port(g_k4a_port_number);
|
||||
|
||||
if (K4A_SUCCEEDED(result))
|
||||
{
|
||||
int retry = 0;
|
||||
uint32_t device_count = 0;
|
||||
|
||||
while (device_count == 0 && retry++ < 20)
|
||||
{
|
||||
ThreadAPI_Sleep(500);
|
||||
usb_cmd_get_device_count(&device_count);
|
||||
}
|
||||
|
||||
if (device_count == 0 || retry >= 20)
|
||||
{
|
||||
result = K4A_RESULT_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
k4a_result_t disconnect_device()
|
||||
{
|
||||
if (firmware_handle != nullptr)
|
||||
{
|
||||
firmware_destroy(firmware_handle);
|
||||
firmware_handle = nullptr;
|
||||
}
|
||||
|
||||
k4a_result_t result = g_connection_exerciser->set_usb_port(0);
|
||||
if (K4A_SUCCEEDED(result))
|
||||
{
|
||||
ThreadAPI_Sleep(1000);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool compare_calibration()
|
||||
{
|
||||
if (calibration_pre_update_size == calibration_post_update_size &&
|
||||
0 == memcmp(calibration_pre_update, calibration_post_update, calibration_pre_update_size))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Calibration pre and post update do not match!\n");
|
||||
printf("Calibration pre-update: %s\n", (char *)calibration_pre_update);
|
||||
printf("Calibration post-update: %s\n", (char *)calibration_post_update);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
firmware_t firmware_handle = nullptr;
|
||||
char *serial_number = nullptr;
|
||||
size_t serial_number_length = 0;
|
||||
|
||||
uint8_t *calibration_pre_update = nullptr;
|
||||
size_t calibration_pre_update_size = 0;
|
||||
|
||||
uint8_t *calibration_post_update = nullptr;
|
||||
size_t calibration_post_update_size = 0;
|
||||
};
|
||||
|
||||
k4a_result_t read_calibration(uint8_t **calibration_data, size_t *calibration_size)
|
||||
{
|
||||
RETURN_VALUE_IF_ARG(K4A_RESULT_FAILED, calibration_data == NULL);
|
||||
RETURN_VALUE_IF_ARG(K4A_RESULT_FAILED, calibration_size == NULL);
|
||||
|
||||
if (*calibration_data != nullptr)
|
||||
{
|
||||
free(*calibration_data);
|
||||
*calibration_data = nullptr;
|
||||
*calibration_size = 0;
|
||||
}
|
||||
|
||||
k4a_result_t result;
|
||||
depthmcu_t depth_handle = nullptr;
|
||||
calibration_t calibration_handle = nullptr;
|
||||
|
||||
result = TRACE_CALL(depthmcu_create(K4A_DEVICE_DEFAULT, &depth_handle));
|
||||
|
||||
if (K4A_SUCCEEDED(result))
|
||||
{
|
||||
result = TRACE_CALL(calibration_create(depth_handle, &calibration_handle));
|
||||
}
|
||||
|
||||
if (K4A_SUCCEEDED(result))
|
||||
{
|
||||
if (K4A_BUFFER_RESULT_TOO_SMALL ==
|
||||
TRACE_BUFFER_CALL(calibration_get_raw_data(calibration_handle, nullptr, calibration_size)))
|
||||
{
|
||||
*calibration_data = (uint8_t *)malloc(*calibration_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = K4A_RESULT_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
if (K4A_SUCCEEDED(result))
|
||||
{
|
||||
if (K4A_FAILED(
|
||||
TRACE_BUFFER_CALL(calibration_get_raw_data(calibration_handle, *calibration_data, calibration_size))))
|
||||
{
|
||||
result = K4A_RESULT_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
if (calibration_handle != nullptr)
|
||||
{
|
||||
calibration_destroy(calibration_handle);
|
||||
calibration_handle = nullptr;
|
||||
}
|
||||
|
||||
if (depth_handle != nullptr)
|
||||
{
|
||||
depthmcu_destroy(depth_handle);
|
||||
depth_handle = nullptr;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
TEST_F(firmware_fw, DISABLED_update_timing)
|
||||
{
|
||||
LOG_INFO("Beginning the manual test to get update timings.", 0);
|
||||
ASSERT_EQ(K4A_RESULT_SUCCEEDED, g_connection_exerciser->set_usb_port(g_k4a_port_number));
|
||||
ASSERT_EQ(K4A_RESULT_SUCCEEDED, connect_device());
|
||||
|
||||
ASSERT_EQ(K4A_RESULT_SUCCEEDED, open_firmware_device(&firmware_handle));
|
||||
|
||||
|
@ -105,7 +244,9 @@ TEST_F(firmware_fw, DISABLED_update_timing)
|
|||
TEST_F(firmware_fw, simple_update_from_lkg)
|
||||
{
|
||||
LOG_INFO("Beginning the basic update test from the LKG firmware.", 0);
|
||||
ASSERT_EQ(K4A_RESULT_SUCCEEDED, g_connection_exerciser->set_usb_port(g_k4a_port_number));
|
||||
ASSERT_EQ(K4A_RESULT_SUCCEEDED, connect_device());
|
||||
|
||||
ASSERT_EQ(K4A_RESULT_SUCCEEDED, read_calibration(&calibration_pre_update, &calibration_pre_update_size));
|
||||
|
||||
ASSERT_EQ(K4A_RESULT_SUCCEEDED, open_firmware_device(&firmware_handle));
|
||||
|
||||
|
@ -125,6 +266,13 @@ TEST_F(firmware_fw, simple_update_from_lkg)
|
|||
g_lkg_firmware_package_info,
|
||||
false));
|
||||
|
||||
ASSERT_EQ(K4A_RESULT_SUCCEEDED, disconnect_device());
|
||||
ASSERT_EQ(K4A_RESULT_SUCCEEDED, connect_device());
|
||||
|
||||
ASSERT_EQ(K4A_RESULT_SUCCEEDED, read_calibration(&calibration_post_update, &calibration_post_update_size));
|
||||
ASSERT_TRUE(compare_calibration());
|
||||
|
||||
ASSERT_EQ(K4A_RESULT_SUCCEEDED, open_firmware_device(&firmware_handle));
|
||||
ASSERT_TRUE(compare_device_serial_number(firmware_handle, serial_number));
|
||||
|
||||
LOG_INFO("Updating the device to the Candidate firmware.");
|
||||
|
@ -135,6 +283,13 @@ TEST_F(firmware_fw, simple_update_from_lkg)
|
|||
g_candidate_firmware_package_info,
|
||||
false));
|
||||
|
||||
ASSERT_EQ(K4A_RESULT_SUCCEEDED, disconnect_device());
|
||||
ASSERT_EQ(K4A_RESULT_SUCCEEDED, connect_device());
|
||||
|
||||
ASSERT_EQ(K4A_RESULT_SUCCEEDED, read_calibration(&calibration_post_update, &calibration_post_update_size));
|
||||
ASSERT_TRUE(compare_calibration());
|
||||
|
||||
ASSERT_EQ(K4A_RESULT_SUCCEEDED, open_firmware_device(&firmware_handle));
|
||||
ASSERT_TRUE(compare_device_serial_number(firmware_handle, serial_number));
|
||||
|
||||
LOG_INFO("Updating the device to the Test firmware.");
|
||||
|
@ -145,13 +300,22 @@ TEST_F(firmware_fw, simple_update_from_lkg)
|
|||
g_test_firmware_package_info,
|
||||
false));
|
||||
|
||||
ASSERT_EQ(K4A_RESULT_SUCCEEDED, disconnect_device());
|
||||
ASSERT_EQ(K4A_RESULT_SUCCEEDED, connect_device());
|
||||
|
||||
ASSERT_EQ(K4A_RESULT_SUCCEEDED, read_calibration(&calibration_post_update, &calibration_post_update_size));
|
||||
ASSERT_TRUE(compare_calibration());
|
||||
|
||||
ASSERT_EQ(K4A_RESULT_SUCCEEDED, open_firmware_device(&firmware_handle));
|
||||
ASSERT_TRUE(compare_device_serial_number(firmware_handle, serial_number));
|
||||
}
|
||||
|
||||
TEST_F(firmware_fw, simple_update_from_factory)
|
||||
{
|
||||
LOG_INFO("Beginning the basic update test from the Factory firmware.", 0);
|
||||
ASSERT_EQ(K4A_RESULT_SUCCEEDED, g_connection_exerciser->set_usb_port(g_k4a_port_number));
|
||||
ASSERT_EQ(K4A_RESULT_SUCCEEDED, connect_device());
|
||||
|
||||
ASSERT_EQ(K4A_RESULT_SUCCEEDED, read_calibration(&calibration_pre_update, &calibration_pre_update_size));
|
||||
|
||||
ASSERT_EQ(K4A_RESULT_SUCCEEDED, open_firmware_device(&firmware_handle));
|
||||
|
||||
|
@ -171,6 +335,13 @@ TEST_F(firmware_fw, simple_update_from_factory)
|
|||
g_factory_firmware_package_info,
|
||||
false));
|
||||
|
||||
ASSERT_EQ(K4A_RESULT_SUCCEEDED, disconnect_device());
|
||||
ASSERT_EQ(K4A_RESULT_SUCCEEDED, connect_device());
|
||||
|
||||
ASSERT_EQ(K4A_RESULT_SUCCEEDED, read_calibration(&calibration_post_update, &calibration_post_update_size));
|
||||
ASSERT_TRUE(compare_calibration());
|
||||
|
||||
ASSERT_EQ(K4A_RESULT_SUCCEEDED, open_firmware_device(&firmware_handle));
|
||||
ASSERT_TRUE(compare_device_serial_number(firmware_handle, serial_number));
|
||||
|
||||
LOG_INFO("Updating the device to the Candidate firmware.");
|
||||
|
@ -181,6 +352,13 @@ TEST_F(firmware_fw, simple_update_from_factory)
|
|||
g_candidate_firmware_package_info,
|
||||
false));
|
||||
|
||||
ASSERT_EQ(K4A_RESULT_SUCCEEDED, disconnect_device());
|
||||
ASSERT_EQ(K4A_RESULT_SUCCEEDED, connect_device());
|
||||
|
||||
ASSERT_EQ(K4A_RESULT_SUCCEEDED, read_calibration(&calibration_post_update, &calibration_post_update_size));
|
||||
ASSERT_TRUE(compare_calibration());
|
||||
|
||||
ASSERT_EQ(K4A_RESULT_SUCCEEDED, open_firmware_device(&firmware_handle));
|
||||
ASSERT_TRUE(compare_device_serial_number(firmware_handle, serial_number));
|
||||
|
||||
LOG_INFO("Updating the device to the Test firmware.");
|
||||
|
@ -191,5 +369,12 @@ TEST_F(firmware_fw, simple_update_from_factory)
|
|||
g_test_firmware_package_info,
|
||||
false));
|
||||
|
||||
ASSERT_EQ(K4A_RESULT_SUCCEEDED, disconnect_device());
|
||||
ASSERT_EQ(K4A_RESULT_SUCCEEDED, connect_device());
|
||||
|
||||
ASSERT_EQ(K4A_RESULT_SUCCEEDED, read_calibration(&calibration_post_update, &calibration_post_update_size));
|
||||
ASSERT_TRUE(compare_calibration());
|
||||
|
||||
ASSERT_EQ(K4A_RESULT_SUCCEEDED, open_firmware_device(&firmware_handle));
|
||||
ASSERT_TRUE(compare_device_serial_number(firmware_handle, serial_number));
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче