Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: components/exo/display_unittest.cc

Issue 2443823002: exo: Fix CreateLinuxFence test. (Closed)
Patch Set: exo: Fix CreateLinuxFence test. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/exo/display.cc ('k') | components/exo/wayland/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/public/cpp/shell_window_ids.h" 5 #include "ash/public/cpp/shell_window_ids.h"
6 #include "components/exo/buffer.h" 6 #include "components/exo/buffer.h"
7 #include "components/exo/display.h" 7 #include "components/exo/display.h"
8 #include "components/exo/shared_memory.h" 8 #include "components/exo/shared_memory.h"
9 #include "components/exo/shell_surface.h" 9 #include "components/exo/shell_surface.h"
10 #include "components/exo/sub_surface.h" 10 #include "components/exo/sub_surface.h"
11 #include "components/exo/surface.h" 11 #include "components/exo/surface.h"
12 #include "components/exo/test/exo_test_base.h" 12 #include "components/exo/test/exo_test_base.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 #if defined(OS_LINUX)
16 #include "third_party/libsync/include/sw_sync.h"
17 #include "ui/gfx/gpu_fence.h"
18 #endif
19
15 #if defined(USE_OZONE) 20 #if defined(USE_OZONE)
16 #include "ui/ozone/public/native_pixmap.h" 21 #include "ui/ozone/public/native_pixmap.h"
17 #include "ui/ozone/public/ozone_platform.h" 22 #include "ui/ozone/public/ozone_platform.h"
18 #include "ui/ozone/public/surface_factory_ozone.h" 23 #include "ui/ozone/public/surface_factory_ozone.h"
19 #endif 24 #endif
20 25
21 namespace exo { 26 namespace exo {
22 namespace { 27 namespace {
23 28
24 using DisplayTest = test::ExoTestBase; 29 using DisplayTest = test::ExoTestBase;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 84
80 std::vector<base::ScopedFD> invalid_fds; 85 std::vector<base::ScopedFD> invalid_fds;
81 invalid_fds.push_back(base::ScopedFD()); 86 invalid_fds.push_back(base::ScopedFD());
82 // Creating a prime buffer using an invalid fd should fail. 87 // Creating a prime buffer using an invalid fd should fail.
83 std::unique_ptr<Buffer> buffer2 = display->CreateLinuxDMABufBuffer( 88 std::unique_ptr<Buffer> buffer2 = display->CreateLinuxDMABufBuffer(
84 buffer_size, gfx::BufferFormat::RGBA_8888, planes, 89 buffer_size, gfx::BufferFormat::RGBA_8888, planes,
85 std::move(invalid_fds)); 90 std::move(invalid_fds));
86 EXPECT_FALSE(buffer2); 91 EXPECT_FALSE(buffer2);
87 } 92 }
88 93
89 TEST_F(DisplayTest, CreateLinuxFence) {
90 int sockets_unscoped[2];
91
92 ASSERT_EQ(0, socketpair(AF_UNIX, SOCK_STREAM, 0, fds));
93
94 // Emulate the behaviour of a fence FD (returns POLLIN when signaled) using
95 // a socket pair.
96 Base::ScopedFD socket_waitee(sockets_unscoped[0]);
97
98 std::unique_ptr<gfx::GpuFence> fence1 =
99 display->CreateLinuxFence(sockets_unscoped[1]);
100 ASSERT_TRUE(fence1);
101 close(sockets_unscoped[1]);
102
103 // The fence must be unsignaled when we start.
104 EXPECT_FALSE(fence1->Wait(TimeDelta::FromMilliseconds(50)));
105
106 // Unblock the fence, and make sure this signals success.
107 uint32_t dummy = 1;
108 ASSERT_EQ(sizeof(dummy), UnixDomainSocket::SendMsg(socket_waitee, &dummy,
109 sizeof(dummy), nullptr));
110
111 EXPECT_TRUE(fence1->Wait(TimeDelta::FromMilliseconds(50)));
112
113 // Check that invalid file descriptors are rejected.
114 std::unique_ptr<gfx::GpuFence> fence2 = display->CreateLinuxFence(-1);
115 EXPECT_FALSE(fence2);
116 }
117
118 // TODO(dcastagna): Add YV12 unittest once we can allocate the buffer 94 // TODO(dcastagna): Add YV12 unittest once we can allocate the buffer
119 // via Ozone. crbug.com/618516 95 // via Ozone. crbug.com/618516
96 #endif // defined(USE_OZONE)
120 97
121 #endif 98 #if defined(OS_LINUX)
99 TEST_F(DisplayTest, CreateLinuxFence) {
100 std::unique_ptr<Display> display(new Display);
101
102 // Skip test if sw sync device doesn't exist.
103 if (!base::PathExists(base::FilePath(FILE_PATH_LITERAL("/dev/sw_sync"))))
104 return;
105
106 // Initial position for timeline is 0.
107 base::ScopedFD timeline_fd(sw_sync_timeline_create());
108 ASSERT_TRUE(timeline_fd.is_valid());
109
110 int sync_point = 1;
111 // Create a fence for |sync_point|.
112 base::ScopedFD fence_fd(
113 sw_sync_fence_create(timeline_fd.get(), "cr-test-fence", sync_point));
114
115 std::unique_ptr<gfx::GpuFence> fence1 =
116 display->CreateLinuxFence(std::move(fence_fd));
117 ASSERT_TRUE(fence1);
118
119 // The fence must be unsignaled when we start.
120 EXPECT_FALSE(fence1->IsSignaled());
121
122 // Increment timeline to 1 to signal fence.
123 int rv = sw_sync_timeline_inc(timeline_fd.get(), 1);
124 EXPECT_EQ(0, rv);
125
126 EXPECT_TRUE(fence1->Wait(base::TimeDelta::FromMilliseconds(50)));
127
128 base::ScopedFD invalid_fd;
129 // Check that invalid file descriptors are rejected.
130 std::unique_ptr<gfx::GpuFence> fence2 =
131 display->CreateLinuxFence(std::move(invalid_fd));
132 EXPECT_FALSE(fence2);
133 }
134 #endif // defined(OS_LINUX)
122 135
123 TEST_F(DisplayTest, CreateShellSurface) { 136 TEST_F(DisplayTest, CreateShellSurface) {
124 std::unique_ptr<Display> display(new Display); 137 std::unique_ptr<Display> display(new Display);
125 138
126 // Create two surfaces. 139 // Create two surfaces.
127 std::unique_ptr<Surface> surface1 = display->CreateSurface(); 140 std::unique_ptr<Surface> surface1 = display->CreateSurface();
128 ASSERT_TRUE(surface1); 141 ASSERT_TRUE(surface1);
129 std::unique_ptr<Surface> surface2 = display->CreateSurface(); 142 std::unique_ptr<Surface> surface2 = display->CreateSurface();
130 ASSERT_TRUE(surface2); 143 ASSERT_TRUE(surface2);
131 144
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 // Attempting to create a sub surface for parent with grandchild as its parent 259 // Attempting to create a sub surface for parent with grandchild as its parent
247 // should fail. 260 // should fail.
248 EXPECT_FALSE(display->CreateSubSurface(parent.get(), grandchild.get())); 261 EXPECT_FALSE(display->CreateSubSurface(parent.get(), grandchild.get()));
249 262
250 // Create a sub surface for parent. 263 // Create a sub surface for parent.
251 EXPECT_TRUE(display->CreateSubSurface(parent.get(), toplevel.get())); 264 EXPECT_TRUE(display->CreateSubSurface(parent.get(), toplevel.get()));
252 } 265 }
253 266
254 } // namespace 267 } // namespace
255 } // namespace exo 268 } // namespace exo
OLDNEW
« no previous file with comments | « components/exo/display.cc ('k') | components/exo/wayland/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698