Skip to content

Commit

Permalink
Merge pull request #5 from aliddell/4-abort-or-stop-is-still-a-flaky-…
Browse files Browse the repository at this point in the history
…test

Unflake abort-or-stop
  • Loading branch information
nclack authored Jan 4, 2024
2 parents ba689ed + a7c49d5 commit d5acf53
Showing 1 changed file with 21 additions and 48 deletions.
69 changes: 21 additions & 48 deletions acquire-video-runtime/tests/abort-or-stop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ reporter(int is_error,
struct Packet
{
AcquireRuntime* runtime_;
struct event started_, aborted_;
struct event started_;
int expect_abort_;
bool result_;
};
Expand Down Expand Up @@ -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");
}
Expand All @@ -178,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);
Expand Down

0 comments on commit d5acf53

Please sign in to comment.