1 // Copyright 2019 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 // This file contains helper classes for video accelerator unittests. 6 7 #ifndef MEDIA_GPU_TEST_VIDEO_TEST_ENVIRONMENT_H_ 8 #define MEDIA_GPU_TEST_VIDEO_TEST_ENVIRONMENT_H_ 9 10 #include <memory> 11 #include <vector> 12 13 #include "base/at_exit.h" 14 #include "base/files/file_path.h" 15 #include "base/test/scoped_feature_list.h" 16 #include "media/gpu/test/video_frame_file_writer.h" 17 #include "testing/gtest/include/gtest/gtest.h" 18 19 namespace base { 20 namespace test { 21 class TaskEnvironment; 22 } // namespace test 23 } // namespace base 24 25 namespace media { 26 namespace test { 27 28 // The frame output mode allows controlling which video frames are written to 29 // disk. Writing frames will greatly slow down the test and generate a lot of 30 // test artifacts, so be careful when configuring other modes than kNone in 31 // automated testing. 32 enum class FrameOutputMode { 33 kNone, // Don't output any frames. 34 kCorrupt, // Only output corrupt frames. 35 kAll // Output all frames. 36 }; 37 38 // Frame output configuration. 39 struct FrameOutputConfig { 40 // The frame output mode controls which frames will be output. 41 FrameOutputMode output_mode = FrameOutputMode::kNone; 42 // The maximum number of frames that will be output. 43 uint64_t output_limit = std::numeric_limits<uint64_t>::max(); 44 // The format of frames that are output. 45 VideoFrameFileWriter::OutputFormat output_format = 46 VideoFrameFileWriter::OutputFormat::kPNG; 47 }; 48 49 class VideoTestEnvironment : public ::testing::Environment { 50 public: 51 VideoTestEnvironment(); 52 // Features are overridden by given features in this environment. 53 VideoTestEnvironment(const std::vector<base::Feature>& enabled_features, 54 const std::vector<base::Feature>& disabled_features); 55 virtual ~VideoTestEnvironment(); 56 57 // ::testing::Environment implementation. 58 // Tear down video test environment, called once for entire test run. 59 void TearDown() override; 60 61 // Get the name of the test output file path (testsuitename/testname). 62 base::FilePath GetTestOutputFilePath() const; 63 64 private: 65 // An exit manager is required to run callbacks on shutdown. 66 base::AtExitManager at_exit_manager; 67 68 std::unique_ptr<base::test::TaskEnvironment> task_environment_; 69 // Features to override default feature settings in this environment. 70 base::test::ScopedFeatureList scoped_feature_list_; 71 }; 72 73 } // namespace test 74 } // namespace media 75 76 #endif // MEDIA_GPU_TEST_VIDEO_TEST_ENVIRONMENT_H_ 77