Skip to content

Commit

Permalink
update multiple devices test
Browse files Browse the repository at this point in the history
  • Loading branch information
diablodale committed Apr 24, 2023
1 parent 45cb91c commit 5668249
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions tests/src/multiple_devices_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,15 +24,17 @@ TEST_CASE("Multiple devices with 50 messages each") {
vector<tuple<shared_ptr<dai::Device>, 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<dai::DeviceInfo> 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]() {
Expand Down Expand Up @@ -106,15 +111,17 @@ TEST_CASE("Multiple devices created and destroyed in parallel") {
constexpr auto DEPTH_THRESHOLD = 0;
vector<thread> 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<dai::DeviceInfo> 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());
Expand Down Expand Up @@ -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<dai::DeviceInfo> 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;
Expand Down

0 comments on commit 5668249

Please sign in to comment.