Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <queue> | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "gpu/command_buffer/service/sync_point_manager.h" | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | |
| 10 | |
| 11 namespace gpu { | |
| 12 | |
| 13 class SyncPointManagerTest : public testing::Test { | |
| 14 public: | |
| 15 SyncPointManagerTest() { | |
| 16 } | |
| 17 | |
| 18 ~SyncPointManagerTest() override {} | |
| 19 | |
| 20 protected: | |
| 21 void SetUp() override { | |
| 22 sync_point_manager_.reset(new SyncPointManager(false)); | |
| 23 } | |
| 24 | |
| 25 void TearDown() override { | |
| 26 sync_point_manager_.reset(); | |
| 27 } | |
| 28 | |
| 29 // Simple static function which can be used to test callbacks. | |
| 30 static void SetIntegerFunction(int* test, int value) { | |
| 31 *test = value; | |
| 32 } | |
| 33 | |
| 34 scoped_ptr<SyncPointManager> sync_point_manager_; | |
| 35 }; | |
| 36 | |
| 37 struct SyncPointStream { | |
| 38 scoped_refptr<SyncPointOrderData> order_data; | |
| 39 scoped_ptr<SyncPointClient> client; | |
| 40 std::queue<uint32_t> order_numbers; | |
| 41 | |
| 42 SyncPointStream(SyncPointManager* sync_point_manager, | |
| 43 CommandBufferNamespace namespace_id, | |
| 44 uint64_t command_buffer_id) | |
| 45 : order_data(SyncPointOrderData::Create()), | |
| 46 client(sync_point_manager->CreateSyncPointClient(order_data, | |
| 47 namespace_id, | |
| 48 command_buffer_id)) {} | |
| 49 | |
| 50 ~SyncPointStream() { | |
| 51 order_data->Destroy(); | |
| 52 order_data = nullptr; | |
| 53 } | |
| 54 | |
| 55 void AllocateOrderNum(SyncPointManager* sync_point_manager) { | |
| 56 order_numbers.push( | |
| 57 order_data->GenerateUnprocessedOrderNumber(sync_point_manager)); | |
| 58 } | |
| 59 | |
| 60 void BeginProcessing() { | |
| 61 ASSERT_FALSE(order_numbers.empty()); | |
| 62 order_data->BeginProcessingOrderNumber(order_numbers.front()); | |
| 63 } | |
| 64 | |
| 65 void EndProcessing() { | |
| 66 ASSERT_FALSE(order_numbers.empty()); | |
| 67 order_data->FinishProcessingOrderNumber(order_numbers.front()); | |
| 68 order_numbers.pop(); | |
| 69 } | |
| 70 }; | |
| 71 | |
| 72 TEST_F(SyncPointManagerTest, BasicSyncPointOrderDataTest) { | |
| 73 scoped_refptr<SyncPointOrderData> order_data = SyncPointOrderData::Create(); | |
| 74 | |
| 75 EXPECT_EQ(0u, order_data->current_order_num()); | |
| 76 EXPECT_EQ(0u, order_data->processed_order_num()); | |
| 77 EXPECT_EQ(0u, order_data->unprocessed_order_num()); | |
| 78 | |
| 79 const uint32_t order_num = | |
| 80 order_data->GenerateUnprocessedOrderNumber(sync_point_manager_.get()); | |
| 81 EXPECT_EQ(1u, order_num); | |
| 82 | |
| 83 EXPECT_EQ(0u, order_data->current_order_num()); | |
| 84 EXPECT_EQ(0u, order_data->processed_order_num()); | |
| 85 EXPECT_EQ(order_num, order_data->unprocessed_order_num()); | |
| 86 | |
| 87 order_data->BeginProcessingOrderNumber(order_num); | |
| 88 EXPECT_EQ(order_num, order_data->current_order_num()); | |
| 89 EXPECT_EQ(0u, order_data->processed_order_num()); | |
| 90 EXPECT_EQ(order_num, order_data->unprocessed_order_num()); | |
| 91 | |
| 92 order_data->FinishProcessingOrderNumber(order_num); | |
| 93 EXPECT_EQ(order_num, order_data->current_order_num()); | |
| 94 EXPECT_EQ(order_num, order_data->processed_order_num()); | |
| 95 EXPECT_EQ(order_num, order_data->unprocessed_order_num()); | |
| 96 } | |
| 97 | |
| 98 TEST_F(SyncPointManagerTest, SyncPointClientRegistration) { | |
| 99 const CommandBufferNamespace kNamespaceId = | |
| 100 gpu::CommandBufferNamespace::GPU_IO; | |
| 101 const uint64_t kBufferId = 0x123; | |
| 102 | |
| 103 scoped_refptr<SyncPointClientState> empty_state = | |
| 104 sync_point_manager_->GetSyncPointClientState(kNamespaceId, kBufferId); | |
| 105 EXPECT_FALSE(empty_state); | |
| 106 | |
| 107 scoped_refptr<SyncPointOrderData> order_data = SyncPointOrderData::Create(); | |
| 108 | |
| 109 scoped_ptr<SyncPointClient> client = | |
| 110 sync_point_manager_->CreateSyncPointClient(order_data, | |
| 111 kNamespaceId, | |
| 112 kBufferId); | |
| 113 | |
| 114 EXPECT_EQ(order_data, client->client_state()->order_data()); | |
| 115 EXPECT_EQ(client->client_state(), | |
| 116 sync_point_manager_->GetSyncPointClientState(kNamespaceId, | |
| 117 kBufferId)); | |
| 118 } | |
| 119 | |
| 120 TEST_F(SyncPointManagerTest, BasicFenceSyncRelease) { | |
| 121 const CommandBufferNamespace kNamespaceId = | |
| 122 gpu::CommandBufferNamespace::GPU_IO; | |
| 123 const uint64_t kBufferId = 0x123; | |
| 124 | |
| 125 scoped_refptr<SyncPointOrderData> order_data = SyncPointOrderData::Create(); | |
| 126 scoped_ptr<SyncPointClient> client = | |
| 127 sync_point_manager_->CreateSyncPointClient(order_data, | |
| 128 kNamespaceId, | |
| 129 kBufferId); | |
| 130 scoped_refptr<SyncPointClientState> client_state = client->client_state(); | |
| 131 | |
| 132 EXPECT_EQ(0u, client_state->fence_sync_release()); | |
| 133 EXPECT_FALSE(client_state->IsFenceSyncReleased(1)); | |
| 134 | |
| 135 client->ReleaseFenceSync(1); | |
| 136 | |
| 137 EXPECT_EQ(1u, client_state->fence_sync_release()); | |
| 138 EXPECT_TRUE(client_state->IsFenceSyncReleased(1)); | |
| 139 } | |
| 140 | |
| 141 TEST_F(SyncPointManagerTest, MultipleClientsPerOrderData) { | |
| 142 const CommandBufferNamespace kNamespaceId = | |
| 143 gpu::CommandBufferNamespace::GPU_IO; | |
| 144 const uint64_t kBufferId1 = 0x123; | |
| 145 const uint64_t kBufferId2 = 0x234; | |
| 146 | |
| 147 scoped_refptr<SyncPointOrderData> order_data = SyncPointOrderData::Create(); | |
| 148 scoped_ptr<SyncPointClient> client1 = | |
| 149 sync_point_manager_->CreateSyncPointClient(order_data, | |
| 150 kNamespaceId, | |
| 151 kBufferId1); | |
| 152 scoped_ptr<SyncPointClient> client2 = | |
| 153 sync_point_manager_->CreateSyncPointClient(order_data, | |
| 154 kNamespaceId, | |
| 155 kBufferId2); | |
| 156 | |
| 157 scoped_refptr<SyncPointClientState> client_state1 = client1->client_state(); | |
| 158 scoped_refptr<SyncPointClientState> client_state2 = client2->client_state(); | |
| 159 | |
| 160 client1->ReleaseFenceSync(1); | |
| 161 | |
| 162 EXPECT_TRUE(client_state1->IsFenceSyncReleased(1)); | |
| 163 EXPECT_FALSE(client_state2->IsFenceSyncReleased(1)); | |
| 164 } | |
| 165 | |
| 166 TEST_F(SyncPointManagerTest, BasicFenceSyncWaitRelease) { | |
| 167 const CommandBufferNamespace kNamespaceId = | |
| 168 gpu::CommandBufferNamespace::GPU_IO; | |
| 169 const uint64_t kBufferId1 = 0x123; | |
| 170 const uint64_t kBufferId2 = 0x234; | |
| 171 | |
| 172 SyncPointStream release_stream(sync_point_manager_.get(), | |
| 173 kNamespaceId, | |
| 174 kBufferId1); | |
| 175 SyncPointStream wait_stream(sync_point_manager_.get(), | |
| 176 kNamespaceId, | |
| 177 kBufferId2); | |
| 178 | |
| 179 release_stream.AllocateOrderNum(sync_point_manager_.get()); | |
| 180 wait_stream.AllocateOrderNum(sync_point_manager_.get()); | |
| 181 | |
| 182 wait_stream.BeginProcessing(); | |
| 183 int test_num = 10; | |
| 184 const bool valid_wait = | |
| 185 wait_stream.client->Wait( | |
| 186 release_stream.client->client_state(), | |
| 187 1, | |
| 188 base::Bind(&SyncPointManagerTest::SetIntegerFunction, | |
| 189 &test_num, | |
| 190 123)); | |
| 191 ASSERT_TRUE(valid_wait); | |
| 192 EXPECT_EQ(10, test_num); | |
| 193 | |
| 194 release_stream.BeginProcessing(); | |
| 195 release_stream.client->ReleaseFenceSync(1); | |
| 196 EXPECT_EQ(123, test_num); | |
| 197 } | |
| 198 | |
| 199 TEST_F(SyncPointManagerTest, OutOfOrderRelease) { | |
| 200 const CommandBufferNamespace kNamespaceId = | |
| 201 gpu::CommandBufferNamespace::GPU_IO; | |
| 202 const uint64_t kBufferId1 = 0x123; | |
| 203 const uint64_t kBufferId2 = 0x234; | |
| 204 | |
| 205 SyncPointStream release_stream(sync_point_manager_.get(), | |
| 206 kNamespaceId, | |
| 207 kBufferId1); | |
| 208 SyncPointStream wait_stream(sync_point_manager_.get(), | |
| 209 kNamespaceId, | |
| 210 kBufferId2); | |
| 211 | |
| 212 // Generate wait order number first. | |
| 213 wait_stream.AllocateOrderNum(sync_point_manager_.get()); | |
| 214 release_stream.AllocateOrderNum(sync_point_manager_.get()); | |
| 215 | |
| 216 wait_stream.BeginProcessing(); | |
| 217 int test_num = 10; | |
| 218 const bool valid_wait = | |
| 219 wait_stream.client->Wait( | |
| 220 release_stream.client->client_state(), | |
| 221 1, | |
| 222 base::Bind(&SyncPointManagerTest::SetIntegerFunction, | |
| 223 &test_num, | |
| 224 123)); | |
| 225 EXPECT_FALSE(valid_wait); | |
| 226 EXPECT_EQ(10, test_num); | |
| 227 } | |
| 228 | |
| 229 TEST_F(SyncPointManagerTest, HigherOrderNumberRelease) { | |
| 230 const CommandBufferNamespace kNamespaceId = | |
| 231 gpu::CommandBufferNamespace::GPU_IO; | |
| 232 const uint64_t kBufferId1 = 0x123; | |
| 233 const uint64_t kBufferId2 = 0x234; | |
| 234 | |
| 235 SyncPointStream release_stream(sync_point_manager_.get(), | |
| 236 kNamespaceId, | |
| 237 kBufferId1); | |
| 238 SyncPointStream wait_stream(sync_point_manager_.get(), | |
| 239 kNamespaceId, | |
| 240 kBufferId2); | |
| 241 | |
| 242 // Generate wait order number first. | |
| 243 wait_stream.AllocateOrderNum(sync_point_manager_.get()); | |
| 244 release_stream.AllocateOrderNum(sync_point_manager_.get()); | |
| 245 | |
| 246 // Order number was higher but it was actually released. | |
| 247 release_stream.BeginProcessing(); | |
| 248 release_stream.client->ReleaseFenceSync(1); | |
| 249 release_stream.EndProcessing(); | |
| 250 | |
| 251 wait_stream.BeginProcessing(); | |
| 252 int test_num = 10; | |
| 253 const bool valid_wait = | |
| 254 wait_stream.client->Wait( | |
| 255 release_stream.client->client_state(), | |
| 256 1, | |
| 257 base::Bind(&SyncPointManagerTest::SetIntegerFunction, | |
| 258 &test_num, | |
| 259 123)); | |
| 260 EXPECT_TRUE(valid_wait); | |
| 261 EXPECT_EQ(123, test_num); | |
| 262 } | |
| 263 | |
| 264 TEST_F(SyncPointManagerTest, DestroyedClientRelease) { | |
| 265 const CommandBufferNamespace kNamespaceId = | |
| 266 gpu::CommandBufferNamespace::GPU_IO; | |
| 267 const uint64_t kBufferId1 = 0x123; | |
| 268 const uint64_t kBufferId2 = 0x234; | |
| 269 | |
| 270 SyncPointStream release_stream(sync_point_manager_.get(), | |
| 271 kNamespaceId, | |
| 272 kBufferId1); | |
| 273 SyncPointStream wait_stream(sync_point_manager_.get(), | |
| 274 kNamespaceId, | |
| 275 kBufferId2); | |
| 276 | |
| 277 release_stream.AllocateOrderNum(sync_point_manager_.get()); | |
| 278 wait_stream.AllocateOrderNum(sync_point_manager_.get()); | |
| 279 | |
| 280 wait_stream.BeginProcessing(); | |
| 281 int test_num = 10; | |
| 282 const bool valid_wait = | |
| 283 wait_stream.client->Wait( | |
| 284 release_stream.client->client_state(), | |
| 285 1, | |
| 286 base::Bind(&SyncPointManagerTest::SetIntegerFunction, | |
| 287 &test_num, | |
| 288 123)); | |
| 289 EXPECT_TRUE(valid_wait); | |
| 290 EXPECT_EQ(10, test_num); | |
| 291 | |
| 292 // Destroying the client should release the wait. | |
| 293 release_stream.client.reset(); | |
| 294 EXPECT_EQ(123, test_num); | |
| 295 } | |
| 296 | |
| 297 TEST_F(SyncPointManagerTest, NonExistentRelease) { | |
| 298 const CommandBufferNamespace kNamespaceId = | |
| 299 gpu::CommandBufferNamespace::GPU_IO; | |
| 300 const uint64_t kBufferId1 = 0x123; | |
| 301 const uint64_t kBufferId2 = 0x234; | |
| 302 | |
| 303 SyncPointStream release_stream(sync_point_manager_.get(), | |
| 304 kNamespaceId, | |
| 305 kBufferId1); | |
| 306 SyncPointStream wait_stream(sync_point_manager_.get(), | |
| 307 kNamespaceId, | |
| 308 kBufferId2); | |
| 309 | |
| 310 release_stream.AllocateOrderNum(sync_point_manager_.get()); | |
| 311 wait_stream.AllocateOrderNum(sync_point_manager_.get()); | |
| 312 | |
| 313 wait_stream.BeginProcessing(); | |
| 314 int test_num = 10; | |
| 315 const bool valid_wait = | |
| 316 wait_stream.client->Wait( | |
| 317 release_stream.client->client_state(), | |
| 318 1, | |
| 319 base::Bind(&SyncPointManagerTest::SetIntegerFunction, | |
| 320 &test_num, | |
| 321 123)); | |
| 322 EXPECT_TRUE(valid_wait); | |
| 323 EXPECT_EQ(10, test_num); | |
| 324 | |
| 325 // No release but finishing the order number should automatically release. | |
| 326 release_stream.BeginProcessing(); | |
| 327 EXPECT_EQ(10, test_num); | |
| 328 release_stream.EndProcessing(); | |
| 329 EXPECT_EQ(123, test_num); | |
| 330 } | |
| 331 | |
| 332 TEST_F(SyncPointManagerTest, NonExistentOrderNumRelease) { | |
| 333 const CommandBufferNamespace kNamespaceId = | |
| 334 gpu::CommandBufferNamespace::GPU_IO; | |
| 335 const uint64_t kBufferId1 = 0x123; | |
| 336 const uint64_t kBufferId2 = 0x234; | |
| 337 | |
| 338 SyncPointStream release_stream(sync_point_manager_.get(), | |
| 339 kNamespaceId, | |
| 340 kBufferId1); | |
| 341 SyncPointStream wait_stream(sync_point_manager_.get(), | |
| 342 kNamespaceId, | |
| 343 kBufferId2); | |
| 344 | |
| 345 // Assign Release stream 1, 4 and assign Wait stream 2, 3. | |
|
piman
2015/10/01 17:58:16
nit: maybe comment that order [3] waits on fence (
David Yen
2015/10/01 18:12:00
What this test is really testing is releases and o
| |
| 346 release_stream.AllocateOrderNum(sync_point_manager_.get()); | |
| 347 wait_stream.AllocateOrderNum(sync_point_manager_.get()); | |
| 348 wait_stream.AllocateOrderNum(sync_point_manager_.get()); | |
| 349 release_stream.AllocateOrderNum(sync_point_manager_.get()); | |
| 350 | |
| 351 // Have wait with order number 3 to wait on release. | |
| 352 wait_stream.BeginProcessing(); | |
| 353 ASSERT_EQ(2u, wait_stream.order_data->current_order_num()); | |
| 354 wait_stream.EndProcessing(); | |
| 355 wait_stream.BeginProcessing(); | |
| 356 ASSERT_EQ(3u, wait_stream.order_data->current_order_num()); | |
| 357 int test_num = 10; | |
| 358 const bool valid_wait = | |
| 359 wait_stream.client->Wait( | |
| 360 release_stream.client->client_state(), | |
| 361 1, | |
| 362 base::Bind(&SyncPointManagerTest::SetIntegerFunction, | |
| 363 &test_num, | |
| 364 123)); | |
| 365 EXPECT_TRUE(valid_wait); | |
| 366 EXPECT_EQ(10, test_num); | |
| 367 | |
| 368 // Release stream should know it should release fence sync by order 3, | |
| 369 // so going through order number 1 should not release it yet. | |
| 370 release_stream.BeginProcessing(); | |
| 371 ASSERT_EQ(1u, release_stream.order_data->current_order_num()); | |
| 372 release_stream.EndProcessing(); | |
| 373 EXPECT_FALSE(release_stream.client->client_state()->IsFenceSyncReleased(1)); | |
| 374 EXPECT_EQ(10, test_num); | |
| 375 | |
| 376 // Beginning order number 4 should immediately release 3. | |
|
piman
2015/10/01 17:58:16
I think I'd like a similar test where there is no
David Yen
2015/10/01 18:12:00
If there is no #4, then this test is the same as t
David Yen
2015/10/01 18:25:43
I've now added a new test "NonExistentRelease2" wh
| |
| 377 release_stream.BeginProcessing(); | |
| 378 ASSERT_EQ(4u, release_stream.order_data->current_order_num()); | |
| 379 EXPECT_TRUE(release_stream.client->client_state()->IsFenceSyncReleased(1)); | |
| 380 EXPECT_EQ(123, test_num); | |
| 381 } | |
| 382 | |
| 383 } // namespace gpu | |
| 384 | |
| OLD | NEW |