From 801afc69b9cde62a4ed1d2ae06a4fed1ad64a338 Mon Sep 17 00:00:00 2001 From: Alan Liddell Date: Tue, 2 Jan 2024 13:57:46 -0500 Subject: [PATCH 1/2] Ensure queue is completely flushed in abort-or-stop. --- acquire-video-runtime/tests/abort-or-stop.cpp | 62 ++++++------------- 1 file changed, 20 insertions(+), 42 deletions(-) diff --git a/acquire-video-runtime/tests/abort-or-stop.cpp b/acquire-video-runtime/tests/abort-or-stop.cpp index 5d6a46f..299b622 100644 --- a/acquire-video-runtime/tests/abort-or-stop.cpp +++ b/acquire-video-runtime/tests/abort-or-stop.cpp @@ -107,57 +107,35 @@ acquire(Packet* packet) VideoFrame *beg, *end, *cur; OK(acquire_start(runtime)); event_notify_all(&packet->started_); - if (packet->expect_abort_) - event_wait(&packet->aborted_); - - { - uint64_t nframes = 0; - do { - struct clock throttle = { 0 }; - clock_init(&throttle); - EXPECT(clock_cmp_now(&clock_) < 0, - "Timeout at %f ms", - clock_toc_ms(&clock_) + time_limit_ms); - OK(acquire_map_read(runtime, 0, &beg, &end)); - - for (cur = beg; cur < end; cur = next(cur)) { - ASSERT_EQ("%d", - cur->shape.dims.width, - props.video[0].camera.settings.shape.x); - ASSERT_EQ("%d", - cur->shape.dims.height, - props.video[0].camera.settings.shape.y); - ++nframes; - } - - { - uint32_t n = (uint32_t)consumed_bytes(beg, end); - OK(acquire_unmap_read(runtime, 0, n)); - } - clock_sleep_ms(&throttle, 100.0f); - } while (nframes < props.video[0].max_frame_count && - DeviceState_Running == acquire_get_state(runtime)); + uint64_t nframes = 0; + while (nframes < props.video[0].max_frame_count && + DeviceState_Running == acquire_get_state(runtime)) { + EXPECT(clock_cmp_now(&clock_) < 0, "Ran out of time."); OK(acquire_map_read(runtime, 0, &beg, &end)); + for (cur = beg; cur < end; cur = next(cur)) + ++nframes; + clock_sleep_ms(nullptr, 10.0); + OK(acquire_unmap_read(runtime, 0, (uint8_t*)end - (uint8_t*)beg)); + } - for (cur = beg; cur < end; cur = next(cur)) { - CHECK(cur->shape.dims.width == - props.video[0].camera.settings.shape.x); - CHECK(cur->shape.dims.height == - props.video[0].camera.settings.shape.y); + // flush the queue + do { + OK(acquire_map_read(runtime, 0, &beg, &end)); + for (cur = beg; cur < end; cur = next(cur)) ++nframes; - } + OK(acquire_unmap_read(runtime, 0, (uint8_t*)end - (uint8_t*)beg)); + } while (beg != end); - if (expect_abort) { - CHECK(nframes < props.video[0].max_frame_count); - } else { - CHECK(nframes == props.video[0].max_frame_count); - } + if (expect_abort) { + CHECK(nframes < props.video[0].max_frame_count); + } else { + CHECK(nframes == props.video[0].max_frame_count); } + packet->result_ = true; } catch (const std::runtime_error& e) { ERR("Runtime error: %s", e.what()); - } catch (...) { ERR("Uncaught exception"); } From a7c49d55e6029057d58480f69d9e7706dbaea9a1 Mon Sep 17 00:00:00 2001 From: Alan Liddell Date: Tue, 2 Jan 2024 14:09:39 -0500 Subject: [PATCH 2/2] Remove the `packet.aborted_` event in abort-or-stop. --- acquire-video-runtime/tests/abort-or-stop.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/acquire-video-runtime/tests/abort-or-stop.cpp b/acquire-video-runtime/tests/abort-or-stop.cpp index 299b622..e8c310a 100644 --- a/acquire-video-runtime/tests/abort-or-stop.cpp +++ b/acquire-video-runtime/tests/abort-or-stop.cpp @@ -54,7 +54,7 @@ reporter(int is_error, struct Packet { AcquireRuntime* runtime_; - struct event started_, aborted_; + struct event started_; int expect_abort_; bool result_; }; @@ -156,28 +156,23 @@ main() .expect_abort_ = 1, .result_ = false }; event_init(&packet.started_); - event_init(&packet.aborted_); thread_create(&t_, (void (*)(void*))acquire, &packet); event_wait(&packet.started_); acquire_abort(runtime); - event_notify_all(&packet.aborted_); thread_join(&t_); event_destroy(&packet.started_); - event_destroy(&packet.aborted_); EXPECT(packet.result_ == true, "Something went wrong in 'abort' test."); // stop waits until finished packet = Packet{ .runtime_ = runtime, .expect_abort_ = 0, .result_ = false }; event_init(&packet.started_); - event_init(&packet.aborted_); thread_create(&t_, (void (*)(void*))acquire, &packet); event_wait(&packet.started_); acquire_stop(runtime); thread_join(&t_); event_destroy(&packet.started_); - event_destroy(&packet.aborted_); EXPECT(packet.result_ == true, "Something went wrong in 'stop' test."); acquire_shutdown(runtime);