From 56682499841a953d0debe661e308d112a4fa8ebe Mon Sep 17 00:00:00 2001 From: Dale Phurrough Date: Mon, 24 Apr 2023 16:44:21 +0200 Subject: [PATCH] update multiple devices test --- tests/src/multiple_devices_test.cpp | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/tests/src/multiple_devices_test.cpp b/tests/src/multiple_devices_test.cpp index 006f7fd7e..44488c59a 100644 --- a/tests/src/multiple_devices_test.cpp +++ b/tests/src/multiple_devices_test.cpp @@ -13,6 +13,9 @@ using namespace std; using namespace std::chrono; using namespace std::chrono_literals; +size_t maxFoundDevices = 0; +constexpr auto DEVICE_SEARCH_TIMEOUT = 10s; + TEST_CASE("Multiple devices with 50 messages each") { constexpr auto NUM_MESSAGES = 50; constexpr auto TEST_TIMEOUT = 20s; @@ -21,15 +24,17 @@ TEST_CASE("Multiple devices with 50 messages each") { vector, int>> devices; int deviceCounter = 0; - // Wait for 3s to acquire more than 1 device. Otherwise perform the test with 1 device + // Wait to acquire more than 1 device. Otherwise perform the test with 1 device // Could also fail instead - but requires test groups before auto t1 = steady_clock::now(); vector availableDevices; do { availableDevices = dai::Device::getAllAvailableDevices(); this_thread::sleep_for(500ms); - } while(availableDevices.size() <= 1 && steady_clock::now() - t1 <= 3s); + } while((availableDevices.size() < 2 || availableDevices.size() < maxFoundDevices) && (steady_clock::now() - t1 <= DEVICE_SEARCH_TIMEOUT)); REQUIRE(!availableDevices.empty()); + REQUIRE(availableDevices.size() >= maxFoundDevices); + maxFoundDevices = availableDevices.size(); for(const auto& dev : availableDevices) { threads.emplace_back([&mtx, &devices, dev, deviceCounter]() { @@ -106,15 +111,17 @@ TEST_CASE("Multiple devices created and destroyed in parallel") { constexpr auto DEPTH_THRESHOLD = 0; vector threads; - // Wait for 3s to acquire more than 1 device. Otherwise perform the test with 1 device - // Could also fail instead - but requires test groups before + // Wait to acquire devices. Require 2+ devices. const auto t1 = steady_clock::now(); vector availableDevices; do { availableDevices = dai::Device::getAllAvailableDevices(); this_thread::sleep_for(500ms); - } while(availableDevices.size() <= 1 && steady_clock::now() - t1 <= 3s); + } while((availableDevices.size() < 2 || availableDevices.size() < maxFoundDevices) && (steady_clock::now() - t1 <= DEVICE_SEARCH_TIMEOUT)); REQUIRE(availableDevices.size() >= 2); + REQUIRE(availableDevices.size() >= maxFoundDevices); + maxFoundDevices = availableDevices.size(); + cout << "Found device count: " << availableDevices.size() << endl; // preallocate to avoid reallocation/move threads.reserve(availableDevices.size()); @@ -221,14 +228,17 @@ TEST_CASE("Multiple devices created and destroyed in parallel") { TEST_CASE("Device APIs after Device::close()") { constexpr auto TEST_TIMEOUT = 20s; - // Wait for 3s to acquire a device. + // Wait to acquire a device. auto t1 = steady_clock::now(); vector availableDevices; do { availableDevices = dai::Device::getAllAvailableDevices(); this_thread::sleep_for(500ms); - } while(availableDevices.empty() && steady_clock::now() - t1 <= 3s); - if(availableDevices.empty()) throw std::runtime_error("No devices found"); + } while((availableDevices.empty() || availableDevices.size() < maxFoundDevices) && (steady_clock::now() - t1 <= DEVICE_SEARCH_TIMEOUT)); + REQUIRE(!availableDevices.empty()); + REQUIRE(availableDevices.size() >= maxFoundDevices); + maxFoundDevices = availableDevices.size(); + cout << "Found device count: " << availableDevices.size() << endl; // Create pipeline dai::Pipeline pipeline;