Skip to content

Commit 301e2da

Browse files
pwnallCQ Bot
authored andcommitted
[fake-display] Rewrite test event listener.
CaptureCompletion is actually a DisplayEngineEventListener implementation. This CL renames the class and updates its implementation to follow modern practices. This CL also adds a listener instance to the test fixture. This prepares for a future where tests wait for OnDisplayAdded() before issuing API calls. Bug: 388885807 Test: fx test //src/graphics/display/drivers/fake Change-Id: I3aba5b43022c4892475eeec7ad57ee303980b813 Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/1233745 Reviewed-by: Yilong Li <[email protected]> Fuchsia-Auto-Submit: Victor Costan <[email protected]> Commit-Queue: Auto-Submit <[email protected]>
1 parent d4cd64e commit 301e2da

File tree

1 file changed

+47
-46
lines changed

1 file changed

+47
-46
lines changed

src/graphics/display/drivers/fake/fake-display-test.cc

Lines changed: 47 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include "src/graphics/display/drivers/fake/fake-display.h"
66

77
#include <fidl/fuchsia.sysmem2/cpp/wire.h>
8-
#include <fuchsia/hardware/display/controller/c/banjo.h>
8+
#include <fuchsia/hardware/display/controller/cpp/banjo.h>
99
#include <lib/fpromise/result.h>
1010
#include <lib/fzl/vmo-mapper.h>
1111
#include <lib/image-format/image_format.h>
@@ -49,6 +49,40 @@ namespace fake_display {
4949

5050
namespace {
5151

52+
class TestDisplayEngineListener
53+
: public ddk::DisplayEngineListenerProtocol<TestDisplayEngineListener> {
54+
public:
55+
// fuchsia.hardware.display.controller/DisplayEngineListener:
56+
void DisplayEngineListenerOnDisplayAdded(const raw_display_info_t* banjo_display_info) {
57+
display_added_.Signal();
58+
}
59+
void DisplayEngineListenerOnDisplayRemoved(uint64_t display_id) {
60+
GTEST_FAIL() << "Unexpected call to OnDisplayRemoved";
61+
}
62+
void DisplayEngineListenerOnDisplayVsync(uint64_t banjo_display_id, zx_time_t timestamp,
63+
const config_stamp_t* config_stamp) {
64+
// VSync signals are ignored for now.
65+
}
66+
void DisplayEngineListenerOnCaptureComplete() { capture_completed_.Signal(); }
67+
68+
display_engine_listener_protocol_t GetProtocol() {
69+
return {
70+
.ops = &display_engine_listener_protocol_ops_,
71+
.ctx = this,
72+
};
73+
}
74+
75+
// Signaled when the driver signals that a display was added.
76+
libsync::Completion& display_added() { return display_added_; }
77+
78+
// Signaled when the driver signals that a capture was completed.
79+
libsync::Completion& capture_completed() { return capture_completed_; }
80+
81+
private:
82+
libsync::Completion display_added_;
83+
libsync::Completion capture_completed_;
84+
};
85+
5286
class FakeDisplayTest : public testing::Test {
5387
public:
5488
FakeDisplayTest() = default;
@@ -57,6 +91,7 @@ class FakeDisplayTest : public testing::Test {
5791
zx::result<std::unique_ptr<FakeSysmemDeviceHierarchy>> create_sysmem_provider_result =
5892
FakeSysmemDeviceHierarchy::Create();
5993
ASSERT_OK(create_sysmem_provider_result);
94+
6095
fake_display_stack_ = std::make_unique<FakeDisplayStack>(
6196
std::move(create_sysmem_provider_result).value(), GetFakeDisplayDeviceConfig());
6297
}
@@ -71,6 +106,9 @@ class FakeDisplayTest : public testing::Test {
71106
}
72107

73108
protected:
109+
TestDisplayEngineListener engine_listener_;
110+
display_engine_listener_protocol_t engine_listener_banjo_protocol_ =
111+
engine_listener_.GetProtocol();
74112
std::unique_ptr<FakeDisplayStack> fake_display_stack_;
75113
};
76114

@@ -214,35 +252,6 @@ class FakeDisplayRealSysmemTest : public FakeDisplayTest {
214252
fidl::WireSyncClient<fuchsia_sysmem2::Allocator> sysmem_;
215253
};
216254

217-
// A completion semaphore indicating the display capture is completed.
218-
class DisplayCaptureCompletion {
219-
public:
220-
// Tests can import the display controller interface protocol to set up the
221-
// callback to trigger the semaphore.
222-
display_engine_listener_protocol_t GetDisplayEngineListenerProtocol() {
223-
static constexpr display_engine_listener_protocol_ops_t kDisplayEngineListenerProtocolOps = {
224-
.on_display_added = [](void* ctx, const raw_display_info_t* display_info) {},
225-
.on_display_removed = [](void* ctx, uint64_t display_id) {},
226-
.on_display_vsync = [](void* ctx, uint64_t display_id, zx_time_t timestamp,
227-
const config_stamp_t* config_stamp) {},
228-
.on_capture_complete =
229-
[](void* ctx) {
230-
reinterpret_cast<DisplayCaptureCompletion*>(ctx)->OnCaptureComplete();
231-
},
232-
};
233-
return display_engine_listener_protocol_t{
234-
.ops = &kDisplayEngineListenerProtocolOps,
235-
.ctx = this,
236-
};
237-
}
238-
239-
libsync::Completion& completed() { return completed_; }
240-
241-
private:
242-
void OnCaptureComplete() { completed().Signal(); }
243-
libsync::Completion completed_;
244-
};
245-
246255
// Creates a BufferCollectionConstraints that tests can use to configure their
247256
// own BufferCollections to allocate buffers.
248257
//
@@ -579,13 +588,9 @@ TEST_F(FakeDisplayRealSysmemTest, CaptureImage) {
579588
auto [framebuffer_collection_client, framebuffer_token] =
580589
std::move(new_framebuffer_buffer_collection_result.value());
581590

582-
DisplayCaptureCompletion display_capture_completion = {};
583-
const display_engine_listener_protocol_t& controller_protocol =
584-
display_capture_completion.GetDisplayEngineListenerProtocol();
585-
586591
engine_info_t banjo_engine_info;
587592
fake_display_stack_->display_engine().DisplayEngineCompleteCoordinatorConnection(
588-
&controller_protocol, &banjo_engine_info);
593+
&engine_listener_banjo_protocol_, &banjo_engine_info);
589594
ASSERT_TRUE(banjo_engine_info.is_capture_supported);
590595

591596
constexpr display::DriverBufferCollectionId kCaptureBufferCollectionId(1);
@@ -723,10 +728,10 @@ TEST_F(FakeDisplayRealSysmemTest, CaptureImage) {
723728
&banjo_config_stamp);
724729

725730
// Start capture; wait until the capture ends.
726-
EXPECT_FALSE(display_capture_completion.completed().signaled());
731+
ASSERT_FALSE(engine_listener_.capture_completed().signaled());
727732
EXPECT_OK(fake_display_stack_->display_engine().DisplayEngineStartCapture(capture_handle));
728-
display_capture_completion.completed().Wait();
729-
EXPECT_TRUE(display_capture_completion.completed().signaled());
733+
engine_listener_.capture_completed().Wait();
734+
EXPECT_TRUE(engine_listener_.capture_completed().signaled());
730735

731736
// Verify the captured image has the same content as the original image.
732737
constexpr int kCaptureBytesPerPixel = 4;
@@ -805,13 +810,9 @@ TEST_F(FakeDisplayRealSysmemTest, CaptureSolidColorFill) {
805810
auto [framebuffer_collection_client, framebuffer_token] =
806811
std::move(new_framebuffer_buffer_collection_result.value());
807812

808-
DisplayCaptureCompletion display_capture_completion = {};
809-
const display_engine_listener_protocol_t& controller_protocol =
810-
display_capture_completion.GetDisplayEngineListenerProtocol();
811-
812813
engine_info_t banjo_engine_info;
813814
fake_display_stack_->display_engine().DisplayEngineCompleteCoordinatorConnection(
814-
&controller_protocol, &banjo_engine_info);
815+
&engine_listener_banjo_protocol_, &banjo_engine_info);
815816
ASSERT_TRUE(banjo_engine_info.is_capture_supported);
816817

817818
constexpr display::DriverBufferCollectionId kCaptureBufferCollectionId(1);
@@ -918,10 +919,10 @@ TEST_F(FakeDisplayRealSysmemTest, CaptureSolidColorFill) {
918919
&banjo_config_stamp);
919920

920921
// Start capture; wait until the capture ends.
921-
EXPECT_FALSE(display_capture_completion.completed().signaled());
922+
ASSERT_FALSE(engine_listener_.capture_completed().signaled());
922923
EXPECT_OK(fake_display_stack_->display_engine().DisplayEngineStartCapture(capture_handle));
923-
display_capture_completion.completed().Wait();
924-
EXPECT_TRUE(display_capture_completion.completed().signaled());
924+
engine_listener_.capture_completed().Wait();
925+
EXPECT_TRUE(engine_listener_.capture_completed().signaled());
925926

926927
// Verify the captured image has the same content as the original image.
927928
constexpr int kCaptureBytesPerPixel = 4;

0 commit comments

Comments
 (0)