| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2009, Google Inc. | 2 * Copyright 2009, Google Inc. |
| 3 * All rights reserved. | 3 * All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 unsigned int shm_id_; | 126 unsigned int shm_id_; |
| 127 Sequence sequence_; | 127 Sequence sequence_; |
| 128 }; | 128 }; |
| 129 | 129 |
| 130 // Tests the initialization/termination sequence, checking that it sets the | 130 // Tests the initialization/termination sequence, checking that it sets the |
| 131 // engine in the correct states. | 131 // engine in the correct states. |
| 132 TEST_F(CommandBufferEngineTest, TestInitialization) { | 132 TEST_F(CommandBufferEngineTest, TestInitialization) { |
| 133 // Check initial state | 133 // Check initial state |
| 134 EXPECT_TRUE(engine()->rpc_impl() != NULL); | 134 EXPECT_TRUE(engine()->rpc_impl() != NULL); |
| 135 EXPECT_TRUE(engine()->parser() == NULL); | 135 EXPECT_TRUE(engine()->parser() == NULL); |
| 136 EXPECT_EQ(BufferSyncInterface::NOT_CONNECTED, engine()->GetStatus()); | 136 EXPECT_EQ(BufferSyncInterface::kNotConnected, engine()->GetStatus()); |
| 137 EXPECT_EQ(BufferSyncInterface::PARSE_NO_ERROR, engine()->GetParseError()); | 137 EXPECT_EQ(BufferSyncInterface::kParseNoError, engine()->GetParseError()); |
| 138 EXPECT_EQ(-1, engine()->Get()); | 138 EXPECT_EQ(-1, engine()->Get()); |
| 139 EXPECT_EQ(0, engine()->GetToken()); | 139 EXPECT_EQ(0, engine()->GetToken()); |
| 140 | 140 |
| 141 engine()->InitConnection(); | 141 engine()->InitConnection(); |
| 142 EXPECT_EQ(BufferSyncInterface::NO_BUFFER, engine()->GetStatus()); | 142 EXPECT_EQ(BufferSyncInterface::kNoBuffer, engine()->GetStatus()); |
| 143 EXPECT_EQ(BufferSyncInterface::PARSE_NO_ERROR, engine()->GetParseError()); | 143 EXPECT_EQ(BufferSyncInterface::kParseNoError, engine()->GetParseError()); |
| 144 EXPECT_EQ(-1, engine()->Get()); | 144 EXPECT_EQ(-1, engine()->Get()); |
| 145 | 145 |
| 146 CommandBufferEntry *entries = InitCommandBuffer(25, 5); | 146 CommandBufferEntry *entries = InitCommandBuffer(25, 5); |
| 147 ASSERT_TRUE(entries != NULL); | 147 ASSERT_TRUE(entries != NULL); |
| 148 | 148 |
| 149 EXPECT_EQ(BufferSyncInterface::PARSING, engine()->GetStatus()); | 149 EXPECT_EQ(BufferSyncInterface::kParsing, engine()->GetStatus()); |
| 150 EXPECT_EQ(BufferSyncInterface::PARSE_NO_ERROR, engine()->GetParseError()); | 150 EXPECT_EQ(BufferSyncInterface::kParseNoError, engine()->GetParseError()); |
| 151 EXPECT_EQ(5, engine()->Get()); | 151 EXPECT_EQ(5, engine()->Get()); |
| 152 EXPECT_TRUE(engine()->parser() != NULL); | 152 EXPECT_TRUE(engine()->parser() != NULL); |
| 153 | 153 |
| 154 engine()->set_token(5678); | 154 engine()->set_token(5678); |
| 155 EXPECT_EQ(5678, engine()->GetToken()); | 155 EXPECT_EQ(5678, engine()->GetToken()); |
| 156 | 156 |
| 157 engine()->CloseConnection(); | 157 engine()->CloseConnection(); |
| 158 DestroyCommandBuffer(); | 158 DestroyCommandBuffer(); |
| 159 | 159 |
| 160 EXPECT_EQ(BufferSyncInterface::NOT_CONNECTED, engine()->GetStatus()); | 160 EXPECT_EQ(BufferSyncInterface::kNotConnected, engine()->GetStatus()); |
| 161 EXPECT_EQ(BufferSyncInterface::PARSE_NO_ERROR, engine()->GetParseError()); | 161 EXPECT_EQ(BufferSyncInterface::kParseNoError, engine()->GetParseError()); |
| 162 EXPECT_EQ(-1, engine()->Get()); | 162 EXPECT_EQ(-1, engine()->Get()); |
| 163 EXPECT_TRUE(engine()->parser() == NULL); | 163 EXPECT_TRUE(engine()->parser() == NULL); |
| 164 } | 164 } |
| 165 | 165 |
| 166 // Checks that shared memory registration works. | 166 // Checks that shared memory registration works. |
| 167 TEST_F(CommandBufferEngineTest, TestSharedMemoryRegistration) { | 167 TEST_F(CommandBufferEngineTest, TestSharedMemoryRegistration) { |
| 168 // Create and register a first shared memory buffer. | 168 // Create and register a first shared memory buffer. |
| 169 const size_t kShmSize1 = 10; | 169 const size_t kShmSize1 = 10; |
| 170 RPCShmHandle shm1 = CreateShm(kShmSize1); | 170 RPCShmHandle shm1 = CreateShm(kShmSize1); |
| 171 ASSERT_NE(kRPCInvalidHandle, shm1); | 171 ASSERT_NE(kRPCInvalidHandle, shm1); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 TEST_F(CommandBufferEngineTest, TestCommandProcessing) { | 224 TEST_F(CommandBufferEngineTest, TestCommandProcessing) { |
| 225 engine()->InitConnection(); | 225 engine()->InitConnection(); |
| 226 CommandBufferEntry *entries = InitCommandBuffer(10, 0); | 226 CommandBufferEntry *entries = InitCommandBuffer(10, 0); |
| 227 ASSERT_TRUE(entries != NULL); | 227 ASSERT_TRUE(entries != NULL); |
| 228 | 228 |
| 229 CommandBufferOffset get = engine()->Get(); | 229 CommandBufferOffset get = engine()->Get(); |
| 230 CommandBufferOffset put = get; | 230 CommandBufferOffset put = get; |
| 231 | 231 |
| 232 // Create a command buffer with 3 commands | 232 // Create a command buffer with 3 commands |
| 233 put += AddCommandWithExpect(entries + put, | 233 put += AddCommandWithExpect(entries + put, |
| 234 BufferSyncInterface::PARSE_NO_ERROR, | 234 BufferSyncInterface::kParseNoError, |
| 235 0, | 235 0, |
| 236 0, | 236 0, |
| 237 NULL); | 237 NULL); |
| 238 | 238 |
| 239 CommandBufferEntry args1[2]; | 239 CommandBufferEntry args1[2]; |
| 240 args1[0].value_uint32 = 3; | 240 args1[0].value_uint32 = 3; |
| 241 args1[1].value_float = 4.f; | 241 args1[1].value_float = 4.f; |
| 242 put += AddCommandWithExpect(entries + put, | 242 put += AddCommandWithExpect(entries + put, |
| 243 BufferSyncInterface::PARSE_NO_ERROR, | 243 BufferSyncInterface::kParseNoError, |
| 244 1, | 244 1, |
| 245 2, | 245 2, |
| 246 args1); | 246 args1); |
| 247 | 247 |
| 248 CommandBufferEntry args2[2]; | 248 CommandBufferEntry args2[2]; |
| 249 args2[0].value_uint32 = 5; | 249 args2[0].value_uint32 = 5; |
| 250 args2[1].value_float = 6.f; | 250 args2[1].value_float = 6.f; |
| 251 put += AddCommandWithExpect(entries + put, | 251 put += AddCommandWithExpect(entries + put, |
| 252 BufferSyncInterface::PARSE_NO_ERROR, | 252 BufferSyncInterface::kParseNoError, |
| 253 2, | 253 2, |
| 254 2, | 254 2, |
| 255 args2); | 255 args2); |
| 256 | 256 |
| 257 engine()->Put(put); | 257 engine()->Put(put); |
| 258 while (get != put) { | 258 while (get != put) { |
| 259 // Check that the parsing progresses, and that no error occurs. | 259 // Check that the parsing progresses, and that no error occurs. |
| 260 CommandBufferOffset new_get = engine()->WaitGetChanges(get); | 260 CommandBufferOffset new_get = engine()->WaitGetChanges(get); |
| 261 EXPECT_NE(get, new_get); | 261 EXPECT_NE(get, new_get); |
| 262 ASSERT_EQ(BufferSyncInterface::PARSING, engine()->GetStatus()); | 262 ASSERT_EQ(BufferSyncInterface::kParsing, engine()->GetStatus()); |
| 263 EXPECT_EQ(BufferSyncInterface::PARSE_NO_ERROR, engine()->GetParseError()); | 263 EXPECT_EQ(BufferSyncInterface::kParseNoError, engine()->GetParseError()); |
| 264 EXPECT_EQ(new_get, engine()->Get()); | 264 EXPECT_EQ(new_get, engine()->Get()); |
| 265 get = new_get; | 265 get = new_get; |
| 266 } | 266 } |
| 267 // Check that the commands did happen. | 267 // Check that the commands did happen. |
| 268 Mock::VerifyAndClearExpectations(api_mock()); | 268 Mock::VerifyAndClearExpectations(api_mock()); |
| 269 | 269 |
| 270 engine()->CloseConnection(); | 270 engine()->CloseConnection(); |
| 271 DestroyCommandBuffer(); | 271 DestroyCommandBuffer(); |
| 272 } | 272 } |
| 273 | 273 |
| 274 // Checks that commands in the buffer are properly executed when wrapping the | 274 // Checks that commands in the buffer are properly executed when wrapping the |
| 275 // buffer, and that the status/error stay valid. | 275 // buffer, and that the status/error stay valid. |
| 276 TEST_F(CommandBufferEngineTest, TestCommandWrapping) { | 276 TEST_F(CommandBufferEngineTest, TestCommandWrapping) { |
| 277 engine()->InitConnection(); | 277 engine()->InitConnection(); |
| 278 CommandBufferEntry *entries = InitCommandBuffer(10, 6); | 278 CommandBufferEntry *entries = InitCommandBuffer(10, 6); |
| 279 ASSERT_TRUE(entries != NULL); | 279 ASSERT_TRUE(entries != NULL); |
| 280 | 280 |
| 281 CommandBufferOffset get = engine()->Get(); | 281 CommandBufferOffset get = engine()->Get(); |
| 282 CommandBufferOffset put = get; | 282 CommandBufferOffset put = get; |
| 283 | 283 |
| 284 // Create a command buffer with 3 commands | 284 // Create a command buffer with 3 commands |
| 285 put += AddCommandWithExpect(entries + put, | 285 put += AddCommandWithExpect(entries + put, |
| 286 BufferSyncInterface::PARSE_NO_ERROR, | 286 BufferSyncInterface::kParseNoError, |
| 287 0, | 287 0, |
| 288 0, | 288 0, |
| 289 NULL); | 289 NULL); |
| 290 | 290 |
| 291 CommandBufferEntry args1[2]; | 291 CommandBufferEntry args1[2]; |
| 292 args1[0].value_uint32 = 3; | 292 args1[0].value_uint32 = 3; |
| 293 args1[1].value_float = 4.f; | 293 args1[1].value_float = 4.f; |
| 294 put += AddCommandWithExpect(entries + put, | 294 put += AddCommandWithExpect(entries + put, |
| 295 BufferSyncInterface::PARSE_NO_ERROR, | 295 BufferSyncInterface::kParseNoError, |
| 296 1, | 296 1, |
| 297 2, | 297 2, |
| 298 args1); | 298 args1); |
| 299 DCHECK_EQ(10, put); | 299 DCHECK_EQ(10, put); |
| 300 put = 0; | 300 put = 0; |
| 301 | 301 |
| 302 CommandBufferEntry args2[2]; | 302 CommandBufferEntry args2[2]; |
| 303 args2[0].value_uint32 = 5; | 303 args2[0].value_uint32 = 5; |
| 304 args2[1].value_float = 6.f; | 304 args2[1].value_float = 6.f; |
| 305 put += AddCommandWithExpect(entries + put, | 305 put += AddCommandWithExpect(entries + put, |
| 306 BufferSyncInterface::PARSE_NO_ERROR, | 306 BufferSyncInterface::kParseNoError, |
| 307 2, | 307 2, |
| 308 2, | 308 2, |
| 309 args2); | 309 args2); |
| 310 | 310 |
| 311 engine()->Put(put); | 311 engine()->Put(put); |
| 312 while (get != put) { | 312 while (get != put) { |
| 313 // Check that the parsing progresses, and that no error occurs. | 313 // Check that the parsing progresses, and that no error occurs. |
| 314 CommandBufferOffset new_get = engine()->WaitGetChanges(get); | 314 CommandBufferOffset new_get = engine()->WaitGetChanges(get); |
| 315 EXPECT_NE(get, new_get); | 315 EXPECT_NE(get, new_get); |
| 316 ASSERT_EQ(BufferSyncInterface::PARSING, engine()->GetStatus()); | 316 ASSERT_EQ(BufferSyncInterface::kParsing, engine()->GetStatus()); |
| 317 EXPECT_EQ(BufferSyncInterface::PARSE_NO_ERROR, engine()->GetParseError()); | 317 EXPECT_EQ(BufferSyncInterface::kParseNoError, engine()->GetParseError()); |
| 318 EXPECT_EQ(new_get, engine()->Get()); | 318 EXPECT_EQ(new_get, engine()->Get()); |
| 319 get = new_get; | 319 get = new_get; |
| 320 } | 320 } |
| 321 // Check that the commands did happen. | 321 // Check that the commands did happen. |
| 322 Mock::VerifyAndClearExpectations(api_mock()); | 322 Mock::VerifyAndClearExpectations(api_mock()); |
| 323 | 323 |
| 324 engine()->CloseConnection(); | 324 engine()->CloseConnection(); |
| 325 DestroyCommandBuffer(); | 325 DestroyCommandBuffer(); |
| 326 } | 326 } |
| 327 | 327 |
| 328 // Checks that commands in the buffer are properly executed when we change the | 328 // Checks that commands in the buffer are properly executed when we change the |
| 329 // buffer, and when we close the connection. | 329 // buffer, and when we close the connection. |
| 330 TEST_F(CommandBufferEngineTest, TestSetBufferAndClose) { | 330 TEST_F(CommandBufferEngineTest, TestSetBufferAndClose) { |
| 331 engine()->InitConnection(); | 331 engine()->InitConnection(); |
| 332 CommandBufferEntry *entries = InitCommandBuffer(10, 0); | 332 CommandBufferEntry *entries = InitCommandBuffer(10, 0); |
| 333 ASSERT_TRUE(entries != NULL); | 333 ASSERT_TRUE(entries != NULL); |
| 334 | 334 |
| 335 CommandBufferOffset get = engine()->Get(); | 335 CommandBufferOffset get = engine()->Get(); |
| 336 CommandBufferOffset put = get; | 336 CommandBufferOffset put = get; |
| 337 | 337 |
| 338 // Create a command buffer with 3 commands | 338 // Create a command buffer with 3 commands |
| 339 put += AddCommandWithExpect(entries + put, | 339 put += AddCommandWithExpect(entries + put, |
| 340 BufferSyncInterface::PARSE_NO_ERROR, | 340 BufferSyncInterface::kParseNoError, |
| 341 0, | 341 0, |
| 342 0, | 342 0, |
| 343 NULL); | 343 NULL); |
| 344 | 344 |
| 345 CommandBufferEntry args1[2]; | 345 CommandBufferEntry args1[2]; |
| 346 args1[0].value_uint32 = 3; | 346 args1[0].value_uint32 = 3; |
| 347 args1[1].value_float = 4.f; | 347 args1[1].value_float = 4.f; |
| 348 put += AddCommandWithExpect(entries + put, | 348 put += AddCommandWithExpect(entries + put, |
| 349 BufferSyncInterface::PARSE_NO_ERROR, | 349 BufferSyncInterface::kParseNoError, |
| 350 1, | 350 1, |
| 351 2, | 351 2, |
| 352 args1); | 352 args1); |
| 353 | 353 |
| 354 CommandBufferEntry args2[2]; | 354 CommandBufferEntry args2[2]; |
| 355 args2[0].value_uint32 = 5; | 355 args2[0].value_uint32 = 5; |
| 356 args2[1].value_float = 6.f; | 356 args2[1].value_float = 6.f; |
| 357 put += AddCommandWithExpect(entries + put, | 357 put += AddCommandWithExpect(entries + put, |
| 358 BufferSyncInterface::PARSE_NO_ERROR, | 358 BufferSyncInterface::kParseNoError, |
| 359 2, | 359 2, |
| 360 2, | 360 2, |
| 361 args2); | 361 args2); |
| 362 | 362 |
| 363 engine()->Put(put); | 363 engine()->Put(put); |
| 364 | 364 |
| 365 // Setup a new buffer. | 365 // Setup a new buffer. |
| 366 const size_t kShmSize = 10 * sizeof(CommandBufferEntry); // NOLINT | 366 const size_t kShmSize = 10 * sizeof(CommandBufferEntry); // NOLINT |
| 367 RPCShmHandle shm = CreateShm(kShmSize); | 367 RPCShmHandle shm = CreateShm(kShmSize); |
| 368 ASSERT_NE(kRPCInvalidHandle, shm); | 368 ASSERT_NE(kRPCInvalidHandle, shm); |
| 369 unsigned int shm_id = engine()->RegisterSharedMemory(shm, kShmSize); | 369 unsigned int shm_id = engine()->RegisterSharedMemory(shm, kShmSize); |
| 370 ASSERT_NE(BufferSyncInterface::kInvalidSharedMemoryId, shm_id); | 370 ASSERT_NE(BufferSyncInterface::kInvalidSharedMemoryId, shm_id); |
| 371 CommandBufferEntry *entries2 = static_cast<CommandBufferEntry *>( | 371 CommandBufferEntry *entries2 = static_cast<CommandBufferEntry *>( |
| 372 engine()->GetSharedMemoryAddress(shm_id)); | 372 engine()->GetSharedMemoryAddress(shm_id)); |
| 373 engine()->SetCommandBuffer(shm_id, 0, kShmSize, 0); | 373 engine()->SetCommandBuffer(shm_id, 0, kShmSize, 0); |
| 374 EXPECT_EQ(BufferSyncInterface::PARSING, engine()->GetStatus()); | 374 EXPECT_EQ(BufferSyncInterface::kParsing, engine()->GetStatus()); |
| 375 EXPECT_EQ(BufferSyncInterface::PARSE_NO_ERROR, engine()->GetParseError()); | 375 EXPECT_EQ(BufferSyncInterface::kParseNoError, engine()->GetParseError()); |
| 376 EXPECT_EQ(0, engine()->Get()); | 376 EXPECT_EQ(0, engine()->Get()); |
| 377 | 377 |
| 378 // Destroy the old command buffer. | 378 // Destroy the old command buffer. |
| 379 DestroyCommandBuffer(); | 379 DestroyCommandBuffer(); |
| 380 | 380 |
| 381 get = engine()->Get(); | 381 get = engine()->Get(); |
| 382 put = get; | 382 put = get; |
| 383 put += AddCommandWithExpect(entries2 + put, | 383 put += AddCommandWithExpect(entries2 + put, |
| 384 BufferSyncInterface::PARSE_NO_ERROR, | 384 BufferSyncInterface::kParseNoError, |
| 385 1, | 385 1, |
| 386 2, | 386 2, |
| 387 args1); | 387 args1); |
| 388 | 388 |
| 389 engine()->Put(put); | 389 engine()->Put(put); |
| 390 | 390 |
| 391 engine()->CloseConnection(); | 391 engine()->CloseConnection(); |
| 392 // Check that all the commands did happen. | 392 // Check that all the commands did happen. |
| 393 Mock::VerifyAndClearExpectations(api_mock()); | 393 Mock::VerifyAndClearExpectations(api_mock()); |
| 394 | 394 |
| 395 engine()->UnregisterSharedMemory(shm_id); | 395 engine()->UnregisterSharedMemory(shm_id); |
| 396 DestroyShm(shm); | 396 DestroyShm(shm); |
| 397 } | 397 } |
| 398 | 398 |
| 399 // Checks that commands in the buffer are properly executed, even if they | 399 // Checks that commands in the buffer are properly executed, even if they |
| 400 // generate a recoverable error. Check that the error status is properly set, | 400 // generate a recoverable error. Check that the error status is properly set, |
| 401 // and reset when queried. | 401 // and reset when queried. |
| 402 TEST_F(CommandBufferEngineTest, TestRecoverableError) { | 402 TEST_F(CommandBufferEngineTest, TestRecoverableError) { |
| 403 engine()->InitConnection(); | 403 engine()->InitConnection(); |
| 404 CommandBufferEntry *entries = InitCommandBuffer(10, 0); | 404 CommandBufferEntry *entries = InitCommandBuffer(10, 0); |
| 405 ASSERT_TRUE(entries != NULL); | 405 ASSERT_TRUE(entries != NULL); |
| 406 | 406 |
| 407 CommandBufferOffset get = engine()->Get(); | 407 CommandBufferOffset get = engine()->Get(); |
| 408 CommandBufferOffset put = get; | 408 CommandBufferOffset put = get; |
| 409 | 409 |
| 410 // Create a command buffer with 3 commands, 2 of them generating errors | 410 // Create a command buffer with 3 commands, 2 of them generating errors |
| 411 put += AddCommandWithExpect(entries + put, | 411 put += AddCommandWithExpect(entries + put, |
| 412 BufferSyncInterface::PARSE_NO_ERROR, | 412 BufferSyncInterface::kParseNoError, |
| 413 0, | 413 0, |
| 414 0, | 414 0, |
| 415 NULL); | 415 NULL); |
| 416 | 416 |
| 417 CommandBufferEntry args1[2]; | 417 CommandBufferEntry args1[2]; |
| 418 args1[0].value_uint32 = 3; | 418 args1[0].value_uint32 = 3; |
| 419 args1[1].value_float = 4.f; | 419 args1[1].value_float = 4.f; |
| 420 put += AddCommandWithExpect(entries + put, | 420 put += AddCommandWithExpect(entries + put, |
| 421 BufferSyncInterface::PARSE_INVALID_ARGUMENTS, | 421 BufferSyncInterface::kParseInvalidArguments, |
| 422 1, | 422 1, |
| 423 2, | 423 2, |
| 424 args1); | 424 args1); |
| 425 | 425 |
| 426 CommandBufferEntry args2[2]; | 426 CommandBufferEntry args2[2]; |
| 427 args2[0].value_uint32 = 5; | 427 args2[0].value_uint32 = 5; |
| 428 args2[1].value_float = 6.f; | 428 args2[1].value_float = 6.f; |
| 429 put += AddCommandWithExpect(entries + put, | 429 put += AddCommandWithExpect(entries + put, |
| 430 BufferSyncInterface::PARSE_UNKNOWN_COMMAND, | 430 BufferSyncInterface::kParseUnknownCommand, |
| 431 2, | 431 2, |
| 432 2, | 432 2, |
| 433 args2); | 433 args2); |
| 434 | 434 |
| 435 engine()->Put(put); | 435 engine()->Put(put); |
| 436 while (get != put) { | 436 while (get != put) { |
| 437 // Check that the parsing progresses, and that no error occurs. | 437 // Check that the parsing progresses, and that no error occurs. |
| 438 CommandBufferOffset new_get = engine()->WaitGetChanges(get); | 438 CommandBufferOffset new_get = engine()->WaitGetChanges(get); |
| 439 EXPECT_NE(get, new_get); | 439 EXPECT_NE(get, new_get); |
| 440 ASSERT_EQ(BufferSyncInterface::PARSING, engine()->GetStatus()); | 440 ASSERT_EQ(BufferSyncInterface::kParsing, engine()->GetStatus()); |
| 441 EXPECT_EQ(new_get, engine()->Get()); | 441 EXPECT_EQ(new_get, engine()->Get()); |
| 442 get = new_get; | 442 get = new_get; |
| 443 } | 443 } |
| 444 // Check that the commands did happen. | 444 // Check that the commands did happen. |
| 445 Mock::VerifyAndClearExpectations(api_mock()); | 445 Mock::VerifyAndClearExpectations(api_mock()); |
| 446 | 446 |
| 447 // Check that the error status was set to the first error. | 447 // Check that the error status was set to the first error. |
| 448 EXPECT_EQ(BufferSyncInterface::PARSE_INVALID_ARGUMENTS, | 448 EXPECT_EQ(BufferSyncInterface::kParseInvalidArguments, |
| 449 engine()->GetParseError()); | 449 engine()->GetParseError()); |
| 450 // Check that the error status was reset after the query. | 450 // Check that the error status was reset after the query. |
| 451 EXPECT_EQ(BufferSyncInterface::PARSE_NO_ERROR, engine()->GetParseError()); | 451 EXPECT_EQ(BufferSyncInterface::kParseNoError, engine()->GetParseError()); |
| 452 | 452 |
| 453 engine()->CloseConnection(); | 453 engine()->CloseConnection(); |
| 454 DestroyCommandBuffer(); | 454 DestroyCommandBuffer(); |
| 455 } | 455 } |
| 456 | 456 |
| 457 // Checks that commands in the buffer are properly executed up to the point | 457 // Checks that commands in the buffer are properly executed up to the point |
| 458 // where a parsing error happened. Check that at that point the status and | 458 // where a parsing error happened. Check that at that point the status and |
| 459 // error are properly set. | 459 // error are properly set. |
| 460 TEST_F(CommandBufferEngineTest, TestNonRecoverableError) { | 460 TEST_F(CommandBufferEngineTest, TestNonRecoverableError) { |
| 461 engine()->InitConnection(); | 461 engine()->InitConnection(); |
| 462 // Create a buffer with 6 entries, starting at entry 1, but allocate enough | 462 // Create a buffer with 6 entries, starting at entry 1, but allocate enough |
| 463 // memory so that we can add commands that cross over the limit. | 463 // memory so that we can add commands that cross over the limit. |
| 464 const size_t kShmSize = 10 * sizeof(CommandBufferEntry); // NOLINT | 464 const size_t kShmSize = 10 * sizeof(CommandBufferEntry); // NOLINT |
| 465 RPCShmHandle shm = CreateShm(kShmSize); | 465 RPCShmHandle shm = CreateShm(kShmSize); |
| 466 ASSERT_NE(kRPCInvalidHandle, shm); | 466 ASSERT_NE(kRPCInvalidHandle, shm); |
| 467 unsigned int shm_id = engine()->RegisterSharedMemory(shm, kShmSize); | 467 unsigned int shm_id = engine()->RegisterSharedMemory(shm, kShmSize); |
| 468 ASSERT_NE(BufferSyncInterface::kInvalidSharedMemoryId, shm_id); | 468 ASSERT_NE(BufferSyncInterface::kInvalidSharedMemoryId, shm_id); |
| 469 CommandBufferEntry *entries = static_cast<CommandBufferEntry *>( | 469 CommandBufferEntry *entries = static_cast<CommandBufferEntry *>( |
| 470 engine()->GetSharedMemoryAddress(shm_id)); | 470 engine()->GetSharedMemoryAddress(shm_id)); |
| 471 ASSERT_TRUE(entries != NULL); | 471 ASSERT_TRUE(entries != NULL); |
| 472 engine()->SetCommandBuffer(shm_id, 0, 6 * sizeof(CommandBufferEntry), 1); | 472 engine()->SetCommandBuffer(shm_id, 0, 6 * sizeof(CommandBufferEntry), 1); |
| 473 | 473 |
| 474 CommandBufferOffset get = engine()->Get(); | 474 CommandBufferOffset get = engine()->Get(); |
| 475 CommandBufferOffset put = get; | 475 CommandBufferOffset put = get; |
| 476 | 476 |
| 477 // Create a command buffer with 3 commands, the last one overlapping the end | 477 // Create a command buffer with 3 commands, the last one overlapping the end |
| 478 // of the buffer. | 478 // of the buffer. |
| 479 put += AddCommandWithExpect(entries + put, | 479 put += AddCommandWithExpect(entries + put, |
| 480 BufferSyncInterface::PARSE_NO_ERROR, | 480 BufferSyncInterface::kParseNoError, |
| 481 0, | 481 0, |
| 482 0, | 482 0, |
| 483 NULL); | 483 NULL); |
| 484 | 484 |
| 485 CommandBufferEntry args1[2]; | 485 CommandBufferEntry args1[2]; |
| 486 args1[0].value_uint32 = 3; | 486 args1[0].value_uint32 = 3; |
| 487 args1[1].value_float = 4.f; | 487 args1[1].value_float = 4.f; |
| 488 put += AddCommandWithExpect(entries + put, | 488 put += AddCommandWithExpect(entries + put, |
| 489 BufferSyncInterface::PARSE_NO_ERROR, | 489 BufferSyncInterface::kParseNoError, |
| 490 1, | 490 1, |
| 491 2, | 491 2, |
| 492 args1); | 492 args1); |
| 493 | 493 |
| 494 CommandBufferOffset fail_get = put; | 494 CommandBufferOffset fail_get = put; |
| 495 CommandHeader header; | 495 CommandHeader header; |
| 496 header.size = 3; | 496 header.size = 3; |
| 497 header.command = 4; | 497 header.command = 4; |
| 498 entries[put++].value_header = header; | 498 entries[put++].value_header = header; |
| 499 entries[put++].value_uint32 = 5; | 499 entries[put++].value_uint32 = 5; |
| 500 entries[put++].value_uint32 = 6; | 500 entries[put++].value_uint32 = 6; |
| 501 | 501 |
| 502 // we should be beyond the end of the buffer now. | 502 // we should be beyond the end of the buffer now. |
| 503 DCHECK_LT(6, put); | 503 DCHECK_LT(6, put); |
| 504 put = 0; | 504 put = 0; |
| 505 | 505 |
| 506 engine()->Put(put); | 506 engine()->Put(put); |
| 507 while (get != put) { | 507 while (get != put) { |
| 508 // When the parsing stop progressing, break. | 508 // When the parsing stop progressing, break. |
| 509 CommandBufferOffset new_get = engine()->WaitGetChanges(get); | 509 CommandBufferOffset new_get = engine()->WaitGetChanges(get); |
| 510 if (new_get == get) { | 510 if (new_get == get) { |
| 511 EXPECT_EQ(new_get, engine()->Get()); | 511 EXPECT_EQ(new_get, engine()->Get()); |
| 512 break; | 512 break; |
| 513 } | 513 } |
| 514 get = new_get; | 514 get = new_get; |
| 515 } | 515 } |
| 516 // We should be in an error case now. | 516 // We should be in an error case now. |
| 517 EXPECT_EQ(BufferSyncInterface::PARSE_ERROR, engine()->GetStatus()); | 517 EXPECT_EQ(BufferSyncInterface::kParseError, engine()->GetStatus()); |
| 518 // Check that the error status was set to the first error. | 518 // Check that the error status was set to the first error. |
| 519 EXPECT_EQ(BufferSyncInterface::PARSE_OUT_OF_BOUNDS, | 519 EXPECT_EQ(BufferSyncInterface::kParseOutOfBounds, |
| 520 engine()->GetParseError()); | 520 engine()->GetParseError()); |
| 521 // Check that the error status was reset after the query. | 521 // Check that the error status was reset after the query. |
| 522 EXPECT_EQ(BufferSyncInterface::PARSE_NO_ERROR, engine()->GetParseError()); | 522 EXPECT_EQ(BufferSyncInterface::kParseNoError, engine()->GetParseError()); |
| 523 | 523 |
| 524 // Check that the valid commands did happen. | 524 // Check that the valid commands did happen. |
| 525 Mock::VerifyAndClearExpectations(api_mock()); | 525 Mock::VerifyAndClearExpectations(api_mock()); |
| 526 | 526 |
| 527 engine()->CloseConnection(); | 527 engine()->CloseConnection(); |
| 528 engine()->UnregisterSharedMemory(shm_id); | 528 engine()->UnregisterSharedMemory(shm_id); |
| 529 DestroyShm(shm); | 529 DestroyShm(shm); |
| 530 } | 530 } |
| 531 | 531 |
| 532 // Checks that HasWork() and DoWork() have the correct semantics. If there is | 532 // Checks that HasWork() and DoWork() have the correct semantics. If there is |
| (...skipping 28 matching lines...) Expand all Loading... |
| 561 } | 561 } |
| 562 EXPECT_EQ(0, process_mock()->message_count()); | 562 EXPECT_EQ(0, process_mock()->message_count()); |
| 563 EXPECT_FALSE(process_mock()->would_have_blocked()); | 563 EXPECT_FALSE(process_mock()->would_have_blocked()); |
| 564 Mock::VerifyAndClearExpectations(process_mock()); | 564 Mock::VerifyAndClearExpectations(process_mock()); |
| 565 | 565 |
| 566 // Test that if we have commands, we will process them without blocking. | 566 // Test that if we have commands, we will process them without blocking. |
| 567 // Create a command buffer with 3 commands | 567 // Create a command buffer with 3 commands |
| 568 process_mock()->Reset(); | 568 process_mock()->Reset(); |
| 569 EXPECT_CALL(*process_mock(), HasMessage()).Times(AnyNumber()); | 569 EXPECT_CALL(*process_mock(), HasMessage()).Times(AnyNumber()); |
| 570 put += AddCommandWithExpect(entries + put, | 570 put += AddCommandWithExpect(entries + put, |
| 571 BufferSyncInterface::PARSE_NO_ERROR, | 571 BufferSyncInterface::kParseNoError, |
| 572 0, | 572 0, |
| 573 0, | 573 0, |
| 574 NULL); | 574 NULL); |
| 575 | 575 |
| 576 CommandBufferEntry args1[2]; | 576 CommandBufferEntry args1[2]; |
| 577 args1[0].value_uint32 = 3; | 577 args1[0].value_uint32 = 3; |
| 578 args1[1].value_float = 4.f; | 578 args1[1].value_float = 4.f; |
| 579 put += AddCommandWithExpect(entries + put, | 579 put += AddCommandWithExpect(entries + put, |
| 580 BufferSyncInterface::PARSE_NO_ERROR, | 580 BufferSyncInterface::kParseNoError, |
| 581 1, | 581 1, |
| 582 2, | 582 2, |
| 583 args1); | 583 args1); |
| 584 | 584 |
| 585 CommandBufferEntry args2[2]; | 585 CommandBufferEntry args2[2]; |
| 586 args2[0].value_uint32 = 5; | 586 args2[0].value_uint32 = 5; |
| 587 args2[1].value_float = 6.f; | 587 args2[1].value_float = 6.f; |
| 588 put += AddCommandWithExpect(entries + put, | 588 put += AddCommandWithExpect(entries + put, |
| 589 BufferSyncInterface::PARSE_NO_ERROR, | 589 BufferSyncInterface::kParseNoError, |
| 590 2, | 590 2, |
| 591 2, | 591 2, |
| 592 args2); | 592 args2); |
| 593 | 593 |
| 594 EXPECT_FALSE(engine()->HasWork()); // No work yet, until we change put | 594 EXPECT_FALSE(engine()->HasWork()); // No work yet, until we change put |
| 595 | 595 |
| 596 engine()->Put(put); | 596 engine()->Put(put); |
| 597 EXPECT_TRUE(engine()->HasWork()); | 597 EXPECT_TRUE(engine()->HasWork()); |
| 598 | 598 |
| 599 EXPECT_CALL(*process_mock(), ProcessMessage()).Times(0); | 599 EXPECT_CALL(*process_mock(), ProcessMessage()).Times(0); |
| 600 while (engine()->HasWork()) { | 600 while (engine()->HasWork()) { |
| 601 EXPECT_TRUE(engine()->DoWork()); | 601 EXPECT_TRUE(engine()->DoWork()); |
| 602 } | 602 } |
| 603 EXPECT_FALSE(process_mock()->would_have_blocked()); | 603 EXPECT_FALSE(process_mock()->would_have_blocked()); |
| 604 get = engine()->Get(); | 604 get = engine()->Get(); |
| 605 EXPECT_EQ(put, get); // once we're done, we should have executed everything. | 605 EXPECT_EQ(put, get); // once we're done, we should have executed everything. |
| 606 ASSERT_EQ(BufferSyncInterface::PARSING, engine()->GetStatus()); | 606 ASSERT_EQ(BufferSyncInterface::kParsing, engine()->GetStatus()); |
| 607 EXPECT_EQ(BufferSyncInterface::PARSE_NO_ERROR, engine()->GetParseError()); | 607 EXPECT_EQ(BufferSyncInterface::kParseNoError, engine()->GetParseError()); |
| 608 Mock::VerifyAndClearExpectations(process_mock()); | 608 Mock::VerifyAndClearExpectations(process_mock()); |
| 609 Mock::VerifyAndClearExpectations(api_mock()); | 609 Mock::VerifyAndClearExpectations(api_mock()); |
| 610 | 610 |
| 611 // Test that the engine stops if we send it a "kill" message. | 611 // Test that the engine stops if we send it a "kill" message. |
| 612 process_mock()->Reset(); | 612 process_mock()->Reset(); |
| 613 EXPECT_CALL(*process_mock(), HasMessage()).Times(AnyNumber()); | 613 EXPECT_CALL(*process_mock(), HasMessage()).Times(AnyNumber()); |
| 614 process_mock()->set_message_count(1); | 614 process_mock()->set_message_count(1); |
| 615 EXPECT_TRUE(engine()->HasWork()); | 615 EXPECT_TRUE(engine()->HasWork()); |
| 616 | 616 |
| 617 EXPECT_CALL(*process_mock(), ProcessMessage()).WillOnce(Return(false)); | 617 EXPECT_CALL(*process_mock(), ProcessMessage()).WillOnce(Return(false)); |
| 618 EXPECT_FALSE(engine()->DoWork()); | 618 EXPECT_FALSE(engine()->DoWork()); |
| 619 Mock::VerifyAndClearExpectations(process_mock()); | 619 Mock::VerifyAndClearExpectations(process_mock()); |
| 620 | 620 |
| 621 engine()->CloseConnection(); | 621 engine()->CloseConnection(); |
| 622 DestroyCommandBuffer(); | 622 DestroyCommandBuffer(); |
| 623 } | 623 } |
| 624 | 624 |
| 625 } // namespace command_buffer | 625 } // namespace command_buffer |
| 626 } // namespace o3d | 626 } // namespace o3d |
| OLD | NEW |