Chromium Code Reviews| Index: content/common/gpu/media/video_encode_accelerator_unittest.cc |
| diff --git a/content/common/gpu/media/video_encode_accelerator_unittest.cc b/content/common/gpu/media/video_encode_accelerator_unittest.cc |
| index 73e319afb47afa7875fd62a7416e127e45f98118..0228a52749459a83593aaec61e017954b38d3ecb 100644 |
| --- a/content/common/gpu/media/video_encode_accelerator_unittest.cc |
| +++ b/content/common/gpu/media/video_encode_accelerator_unittest.cc |
| @@ -12,6 +12,7 @@ |
| #include "base/process/process_handle.h" |
| #include "base/strings/string_number_conversions.h" |
| #include "base/strings/string_split.h" |
| +#include "base/strings/stringprintf.h" |
| #include "base/sys_byteorder.h" |
| #include "base/time/time.h" |
| #include "base/timer/timer.h" |
| @@ -356,6 +357,50 @@ static void ParseAndReadTestStreamData(const base::FilePath::StringType& data, |
| } |
| } |
| +// Setup test stream data and delete temporary aligned files at the beginning |
| +// and end of unittest. We only need to setup once for all test cases. |
|
Owen Lin
2015/04/24 05:10:32
I only see the temporary aligned file getting dele
Justin Chuang
2015/04/24 14:34:00
Done. PTAL again
|
| +class VideoEncodeAcceleratorTestEnvironment : public ::testing::Environment { |
| + public: |
| + VideoEncodeAcceleratorTestEnvironment( |
| + scoped_ptr<base::FilePath::StringType> data, |
| + const base::FilePath& log_path, |
| + bool run_at_fps) |
| + : log_path_(log_path) { |
| + test_stream_data_ = data.Pass(); |
|
Owen Lin
2015/04/24 05:10:32
Move these two lines into the initializer list.
Justin Chuang
2015/04/24 14:34:00
Done.
|
| + run_at_fps_ = run_at_fps; |
| + } |
| + |
| + virtual void SetUp() { |
| + if (!log_path_.empty()) { |
| + log_file_.reset(new base::File( |
| + log_path_, base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE)); |
| + CHECK(log_file_->IsValid()); |
| + } |
| + ParseAndReadTestStreamData(*test_stream_data_, &test_streams_); |
| + } |
| + |
| + virtual void TearDown() { |
| + for (size_t i = 0; i < test_streams_.size(); i++) { |
| + base::DeleteFile(test_streams_[i]->aligned_in_file, false); |
| + } |
| + if (log_file_.get()) |
|
Owen Lin
2015/04/24 05:10:32
log_file_.reset() should works.
https://code.goog
Justin Chuang
2015/04/24 14:34:00
Cool. Thanks
|
| + log_file_->Close(); |
| + } |
| + |
| + void LogToFile(const std::string& s) { |
| + if (log_file_.get()) |
|
Owen Lin
2015/04/24 05:10:32
if (log_file_)
Justin Chuang
2015/04/24 14:34:00
Done.
|
| + log_file_->WriteAtCurrentPos(s.data(), s.length()); |
| + } |
| + |
| + ScopedVector<TestStream> test_streams_; |
| + bool run_at_fps_; |
| + |
| + private: |
| + scoped_ptr<base::FilePath::StringType> test_stream_data_; |
| + base::FilePath log_path_; |
| + scoped_ptr<base::File> log_file_; |
| +}; |
| + |
| enum ClientState { |
| CS_CREATED, |
| CS_ENCODER_SET, |
| @@ -1134,6 +1179,8 @@ bool VEAClient::HandleEncodedFrame(bool keyframe) { |
| void VEAClient::VerifyPerf() { |
| double measured_fps = frames_per_second(); |
| LOG(INFO) << "Measured encoder FPS: " << measured_fps; |
| + g_env->LogToFile( |
| + base::StringPrintf("Measured encoder FPS: %.3f", measured_fps)); |
| if (test_perf_) |
| EXPECT_GE(measured_fps, kMinPerfFPS); |
| } |
| @@ -1201,34 +1248,6 @@ void VEAClient::WriteIvfFrameHeader(int frame_index, size_t frame_size) { |
| reinterpret_cast<char*>(&header), sizeof(header))); |
| } |
| -// Setup test stream data and delete temporary aligned files at the beginning |
| -// and end of unittest. We only need to setup once for all test cases. |
| -class VideoEncodeAcceleratorTestEnvironment : public ::testing::Environment { |
| - public: |
| - VideoEncodeAcceleratorTestEnvironment( |
| - scoped_ptr<base::FilePath::StringType> data, |
| - bool run_at_fps) { |
| - test_stream_data_ = data.Pass(); |
| - run_at_fps_ = run_at_fps; |
| - } |
| - |
| - virtual void SetUp() { |
| - ParseAndReadTestStreamData(*test_stream_data_, &test_streams_); |
| - } |
| - |
| - virtual void TearDown() { |
| - for (size_t i = 0; i < test_streams_.size(); i++) { |
| - base::DeleteFile(test_streams_[i]->aligned_in_file, false); |
| - } |
| - } |
| - |
| - ScopedVector<TestStream> test_streams_; |
| - bool run_at_fps_; |
| - |
| - private: |
| - scoped_ptr<base::FilePath::StringType> test_stream_data_; |
| -}; |
| - |
| // Test parameters: |
| // - Number of concurrent encoders. The value takes effect when there is only |
| // one input stream; otherwise, one encoder per input stream will be |
| @@ -1379,6 +1398,8 @@ int main(int argc, char** argv) { |
| DCHECK(cmd_line); |
| bool run_at_fps = false; |
| + base::FilePath log_path; |
| + |
| base::CommandLine::SwitchMap switches = cmd_line->GetSwitches(); |
| for (base::CommandLine::SwitchMap::const_iterator it = switches.begin(); |
| it != switches.end(); |
| @@ -1387,6 +1408,12 @@ int main(int argc, char** argv) { |
| test_stream_data->assign(it->second.c_str()); |
| continue; |
| } |
| + // Output machine-readable logs with fixed formats to a file. |
| + if (it->first == "output_log") { |
| + log_path = base::FilePath( |
| + base::FilePath::StringType(it->second.begin(), it->second.end())); |
| + continue; |
| + } |
| if (it->first == "num_frames_to_encode") { |
| std::string input(it->second.begin(), it->second.end()); |
| CHECK(base::StringToInt(input, &content::g_num_frames_to_encode)); |
| @@ -1411,7 +1438,7 @@ int main(int argc, char** argv) { |
| reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>( |
| testing::AddGlobalTestEnvironment( |
| new content::VideoEncodeAcceleratorTestEnvironment( |
| - test_stream_data.Pass(), run_at_fps))); |
| + test_stream_data.Pass(), log_path, run_at_fps))); |
| return RUN_ALL_TESTS(); |
| } |