Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 // This has to be included first. | 5 // This has to be included first. |
| 6 // See http://code.google.com/p/googletest/issues/detail?id=371 | 6 // See http://code.google.com/p/googletest/issues/detail?id=371 |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 | 8 |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 #include <stdint.h> | 10 #include <stdint.h> |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 432 // The elements of |test_image_files_| are owned by | 432 // The elements of |test_image_files_| are owned by |
| 433 // JpegDecodeAcceleratorTestEnvironment. | 433 // JpegDecodeAcceleratorTestEnvironment. |
| 434 std::vector<TestImageFile*> test_image_files_; | 434 std::vector<TestImageFile*> test_image_files_; |
| 435 std::vector<ClientState> expected_status_; | 435 std::vector<ClientState> expected_status_; |
| 436 | 436 |
| 437 protected: | 437 protected: |
| 438 DISALLOW_COPY_AND_ASSIGN(JpegDecodeAcceleratorTest); | 438 DISALLOW_COPY_AND_ASSIGN(JpegDecodeAcceleratorTest); |
| 439 }; | 439 }; |
| 440 | 440 |
| 441 void JpegDecodeAcceleratorTest::TestDecode(size_t num_concurrent_decoders) { | 441 void JpegDecodeAcceleratorTest::TestDecode(size_t num_concurrent_decoders) { |
| 442 LOG_ASSERT(test_image_files_.size() == expected_status_.size()); | 442 LOG_ASSERT(test_image_files_.size() >= expected_status_.size()); |
| 443 base::Thread decoder_thread("DecoderThread"); | 443 base::Thread decoder_thread("DecoderThread"); |
| 444 ASSERT_TRUE(decoder_thread.Start()); | 444 ASSERT_TRUE(decoder_thread.Start()); |
| 445 | 445 |
| 446 ScopedVector<ClientStateNotification<ClientState>> notes; | 446 ScopedVector<ClientStateNotification<ClientState>> notes; |
| 447 ScopedVector<JpegClient> clients; | 447 ScopedVector<JpegClient> clients; |
| 448 | 448 |
| 449 for (size_t i = 0; i < num_concurrent_decoders; i++) { | 449 for (size_t i = 0; i < num_concurrent_decoders; i++) { |
| 450 notes.push_back(new ClientStateNotification<ClientState>()); | 450 notes.push_back(new ClientStateNotification<ClientState>()); |
| 451 clients.push_back(new JpegClient(test_image_files_, notes.back())); | 451 clients.push_back(new JpegClient(test_image_files_, notes.back())); |
| 452 decoder_thread.task_runner()->PostTask( | 452 decoder_thread.task_runner()->PostTask( |
| 453 FROM_HERE, base::Bind(&JpegClient::CreateJpegDecoder, | 453 FROM_HERE, base::Bind(&JpegClient::CreateJpegDecoder, |
| 454 base::Unretained(clients.back()))); | 454 base::Unretained(clients.back()))); |
| 455 ASSERT_EQ(notes[i]->Wait(), CS_INITIALIZED); | 455 ASSERT_EQ(notes[i]->Wait(), CS_INITIALIZED); |
| 456 } | 456 } |
| 457 | 457 |
| 458 for (size_t index = 0; index < test_image_files_.size(); index++) { | 458 for (size_t index = 0; index < test_image_files_.size(); index++) { |
| 459 for (size_t i = 0; i < num_concurrent_decoders; i++) { | 459 for (size_t i = 0; i < num_concurrent_decoders; i++) { |
| 460 decoder_thread.task_runner()->PostTask( | 460 decoder_thread.task_runner()->PostTask( |
| 461 FROM_HERE, base::Bind(&JpegClient::StartDecode, | 461 FROM_HERE, base::Bind(&JpegClient::StartDecode, |
| 462 base::Unretained(clients[i]), index)); | 462 base::Unretained(clients[i]), index)); |
| 463 } | 463 } |
| 464 for (size_t i = 0; i < num_concurrent_decoders; i++) { | 464 if (index < expected_status_.size()) { |
| 465 ASSERT_EQ(notes[i]->Wait(), expected_status_[index]); | 465 for (size_t i = 0; i < num_concurrent_decoders; i++) { |
| 466 ASSERT_EQ(notes[i]->Wait(), expected_status_[index]); | |
| 467 } | |
| 466 } | 468 } |
| 467 } | 469 } |
| 468 | 470 |
| 469 for (size_t i = 0; i < num_concurrent_decoders; i++) { | 471 for (size_t i = 0; i < num_concurrent_decoders; i++) { |
| 470 decoder_thread.task_runner()->PostTask( | 472 decoder_thread.task_runner()->PostTask( |
| 471 FROM_HERE, base::Bind(&JpegClient::DestroyJpegDecoder, | 473 FROM_HERE, base::Bind(&JpegClient::DestroyJpegDecoder, |
| 472 base::Unretained(clients[i]))); | 474 base::Unretained(clients[i]))); |
| 473 } | 475 } |
| 474 decoder_thread.Stop(); | 476 decoder_thread.Stop(); |
| 475 } | 477 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 523 } | 525 } |
| 524 | 526 |
| 525 TEST_F(JpegDecodeAcceleratorTest, KeepDecodeAfterFailure) { | 527 TEST_F(JpegDecodeAcceleratorTest, KeepDecodeAfterFailure) { |
| 526 test_image_files_.push_back(g_env->image_data_invalid_.get()); | 528 test_image_files_.push_back(g_env->image_data_invalid_.get()); |
| 527 test_image_files_.push_back(g_env->image_data_1280x720_default_.get()); | 529 test_image_files_.push_back(g_env->image_data_1280x720_default_.get()); |
| 528 expected_status_.push_back(CS_ERROR); | 530 expected_status_.push_back(CS_ERROR); |
| 529 expected_status_.push_back(CS_DECODE_PASS); | 531 expected_status_.push_back(CS_DECODE_PASS); |
| 530 TestDecode(1); | 532 TestDecode(1); |
| 531 } | 533 } |
| 532 | 534 |
| 535 TEST_F(JpegDecodeAcceleratorTest, Abort) { | |
| 536 const int kNumOfJpegToDecode = 5; | |
|
jcliang
2017/03/13 08:52:34
const size_t
wuchengli
2017/03/13 14:20:08
Will fix in next PS.
| |
| 537 for (int j = 0; j < kNumOfJpegToDecode; j++) | |
|
jcliang
2017/03/13 08:52:34
size_t j
wuchengli
2017/03/13 14:20:08
Will fix in next PS.
| |
| 538 test_image_files_.push_back(g_env->image_data_1280x720_default_.get()); | |
| 539 // Verify only one decode success and ensure both decoders have started the | |
| 540 // decoding. Then destroy the first decoder when it is still decoding. The | |
|
jcliang
2017/03/13 08:52:34
Are we relying on TestDecode() to destroy the firs
wuchengli
2017/03/13 14:20:08
Yes. We are relying on TestDecode() to destroy the
| |
| 541 // kernel should not crash during this test. | |
| 542 expected_status_.push_back(CS_DECODE_PASS); | |
| 543 TestDecode(2); | |
| 544 } | |
| 545 | |
| 533 } // namespace | 546 } // namespace |
| 534 } // namespace media | 547 } // namespace media |
| 535 | 548 |
| 536 int main(int argc, char** argv) { | 549 int main(int argc, char** argv) { |
| 537 testing::InitGoogleTest(&argc, argv); | 550 testing::InitGoogleTest(&argc, argv); |
| 538 base::CommandLine::Init(argc, argv); | 551 base::CommandLine::Init(argc, argv); |
| 539 base::ShadowingAtExitManager at_exit_manager; | 552 base::ShadowingAtExitManager at_exit_manager; |
| 540 | 553 |
| 541 // Needed to enable DVLOG through --vmodule. | 554 // Needed to enable DVLOG through --vmodule. |
| 542 logging::LoggingSettings settings; | 555 logging::LoggingSettings settings; |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 569 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) | 582 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) |
| 570 media::VaapiWrapper::PreSandboxInitialization(); | 583 media::VaapiWrapper::PreSandboxInitialization(); |
| 571 #endif | 584 #endif |
| 572 | 585 |
| 573 media::g_env = reinterpret_cast<media::JpegDecodeAcceleratorTestEnvironment*>( | 586 media::g_env = reinterpret_cast<media::JpegDecodeAcceleratorTestEnvironment*>( |
| 574 testing::AddGlobalTestEnvironment( | 587 testing::AddGlobalTestEnvironment( |
| 575 new media::JpegDecodeAcceleratorTestEnvironment(jpeg_filenames))); | 588 new media::JpegDecodeAcceleratorTestEnvironment(jpeg_filenames))); |
| 576 | 589 |
| 577 return RUN_ALL_TESTS(); | 590 return RUN_ALL_TESTS(); |
| 578 } | 591 } |
| OLD | NEW |