Commit 4ea1d565 authored by David Staessens's avatar David Staessens Committed by Commit Bot

media/gpu/test: Created test environment for video decode related test setup.

This change moves all test-related setup and teardown to a separate test
environment. It also fixes a small bug that causes a crash when destroying the
video player without playing a video.

TEST=ran new VD tests on nocturne

BUG=879065

Change-Id: I0f746ff3aff1598130d563aa8241e87f3d739c8a
Reviewed-on: https://chromium-review.googlesource.com/c/1350413Reviewed-by: default avatarHirokazu Honda <hiroh@chromium.org>
Commit-Queue: David Staessens <dstaessens@chromium.org>
Cr-Commit-Position: refs/heads/master@{#612083}
parent 8f665179
......@@ -645,6 +645,7 @@ if (is_chromeos) {
"test:video_player",
"//base/test:test_support",
"//media:test_support",
"//mojo/core/embedder",
"//testing/gtest",
]
if (use_vaapi) {
......
......@@ -236,7 +236,6 @@ void VideoDecoderClient::CreateDecoderTask(
void VideoDecoderClient::DestroyDecoderTask(base::WaitableEvent* done) {
DCHECK_CALLED_ON_VALID_SEQUENCE(decoder_client_sequence_checker_);
LOG_ASSERT(decoder_) << "Can't destroy decoder: not created yet";
DVLOGF(4);
// Invalidate all scheduled tasks.
......@@ -244,9 +243,11 @@ void VideoDecoderClient::DestroyDecoderTask(base::WaitableEvent* done) {
// Destroying a decoder requires an active GL context.
// TODO(dstaessens@) Investigate making the decoder manage the GL context.
frame_renderer_->AcquireGLContext();
decoder_.reset();
frame_renderer_->ReleaseGLContext();
if (decoder_) {
frame_renderer_->AcquireGLContext();
decoder_.reset();
frame_renderer_->ReleaseGLContext();
}
done->Signal();
}
......
......@@ -12,6 +12,7 @@
#include "media/gpu/test/video_player/video.h"
#include "media/gpu/test/video_player/video_collection.h"
#include "media/gpu/test/video_player/video_player.h"
#include "mojo/core/embedder/embedder.h"
#include "testing/gtest/include/gtest/gtest.h"
#if BUILDFLAG(USE_VAAPI)
......@@ -21,16 +22,60 @@
namespace media {
namespace test {
namespace {
// Test environment for video decode tests.
class VideoDecoderTestEnvironment : public ::testing::Environment {
public:
VideoDecoderTestEnvironment() {}
virtual ~VideoDecoderTestEnvironment() {}
// Setup up the video decode test environment, only called once.
void SetUp() override;
// Tear down the video decode test environment, only called once.
void TearDown() override;
std::unique_ptr<base::test::ScopedTaskEnvironment> task_environment_;
std::unique_ptr<FrameRendererDummy> dummy_frame_renderer_;
// An exit manager is required to run callbacks on shutdown.
base::AtExitManager at_exit_manager;
};
void VideoDecoderTestEnvironment::SetUp() {
// Setting up a task environment will create a task runner for the current
// thread and allow posting tasks to other threads. This is required for the
// test video player to function correctly.
task_environment_ = std::make_unique<base::test::ScopedTaskEnvironment>(
base::test::ScopedTaskEnvironment::MainThreadType::UI);
// Set the default test data path.
media::test::Video::SetTestDataPath(media::GetTestDataPath());
dummy_frame_renderer_ = FrameRendererDummy::Create();
ASSERT_NE(dummy_frame_renderer_, nullptr);
// Perform all static initialization that is required when running video
// decoders in a test environment.
#if BUILDFLAG(USE_VAAPI)
media::VaapiWrapper::PreSandboxInitialization();
#endif
}
void VideoDecoderTestEnvironment::TearDown() {
dummy_frame_renderer_.reset();
task_environment_.reset();
}
media::test::VideoDecoderTestEnvironment* g_env;
} // namespace
// TODO(dstaessens@)
// * Use a fixture here (TEST_F) with a testing environment that contains all
// required setup code.
// * Fetch the expected number of frames from the video file's metadata.
TEST(VideoDecodeAcceleratorTest, BasicPlayTest) {
auto renderer = FrameRendererDummy::Create();
CHECK(renderer) << "Failed to create renderer";
const Video* video = &kDefaultTestVideoCollection[0];
auto tvp = VideoPlayer::Create(video, renderer.get());
CHECK(tvp) << "Failed to create video player";
auto tvp = VideoPlayer::Create(video, g_env->dummy_frame_renderer_.get());
ASSERT_NE(tvp, nullptr);
tvp->Play();
EXPECT_TRUE(tvp->WaitForEvent(VideoPlayerEvent::kFlushDone));
......@@ -45,25 +90,18 @@ TEST(VideoDecodeAcceleratorTest, BasicPlayTest) {
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
base::CommandLine::Init(argc, argv);
base::AtExitManager exit_manager;
// Using shared memory requires mojo to be initialized (crbug.com/849207).
mojo::core::Init();
// Needed to enable DVLOG through --vmodule.
logging::LoggingSettings settings;
settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
LOG_ASSERT(logging::InitLogging(settings));
// Setting up a task environment will create a task runner for the current
// thread and allow posting tasks to other threads. This is required for the
// test video player to function.
base::test::ScopedTaskEnvironment scoped_task_environment(
base::test::ScopedTaskEnvironment::MainThreadType::UI);
// Set the default test data path.
media::test::Video::SetTestDataPath(media::GetTestDataPath());
#if BUILDFLAG(USE_VAAPI)
media::VaapiWrapper::PreSandboxInitialization();
#endif
media::test::g_env = static_cast<media::test::VideoDecoderTestEnvironment*>(
testing::AddGlobalTestEnvironment(
new media::test::VideoDecoderTestEnvironment()));
return RUN_ALL_TESTS();
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment