mirror of
https://gitee.com/xiaohuolufeihua/bizhang_-obav.git
synced 2026-05-21 01:12:11 +00:00
MAVSDK tests: Use full system timeout off
Depending on loop iterations for timeouts is not accurate, as usleep behavior depends on the system load and asking for a 0 ms sleep can potentially return immediately.
This commit is contained in:
@@ -128,24 +128,27 @@ private:
|
|||||||
uint32_t start_time = _info->get_flight_information().second.time_boot_ms;
|
uint32_t start_time = _info->get_flight_information().second.time_boot_ms;
|
||||||
|
|
||||||
while (!fun()) {
|
while (!fun()) {
|
||||||
std::this_thread::sleep_for(duration_ms / 1000);
|
std::this_thread::sleep_for(duration_ms / 100);
|
||||||
|
|
||||||
// This might potentially loop forever and the test needs to be killed by a watchdog outside.
|
// This might potentially loop forever and the test needs to be killed by a watchdog outside.
|
||||||
// The reason not to include an absolute timeout here is that it can happen if the host is
|
// The reason not to include an absolute timeout here is that it can happen if the host is
|
||||||
// busy and PX4 doesn't run fast enough.
|
// busy and PX4 doesn't run fast enough.
|
||||||
if (_info->get_flight_information().second.time_boot_ms - start_time > duration_ms.count()) {
|
const int64_t elapsed_time_ms = _info->get_flight_information().second.time_boot_ms - start_time;
|
||||||
|
if (elapsed_time_ms > duration_ms.count()) {
|
||||||
|
std::cout << "Timeout, connected to vehicle but waiting for test for " << elapsed_time_ms / 1000.0 << " seconds" << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Nothing is connected yet. Use the host time.
|
// Nothing is connected yet. Use the host time.
|
||||||
unsigned iteration = 0;
|
const auto start_time = std::chrono::steady_clock::now();
|
||||||
|
|
||||||
while (!fun()) {
|
while (!fun()) {
|
||||||
std::this_thread::sleep_for(duration_ms / 1000);
|
std::this_thread::sleep_for(duration_ms / 100);
|
||||||
|
const int64_t elapsed_time_us = std::chrono::duration<double, std::micro>(std::chrono::steady_clock::now() - start_time).count();
|
||||||
if (iteration++ >= 1000) {
|
if (elapsed_time_us > duration_ms.count() * 1000) {
|
||||||
|
std::cout << "Timeout, waiting for the vehicle for " << elapsed_time_us / 1000000.0 << " seconds" << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user