Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 // This test doesn't actually verify the output since it's just printed | 11 // This test doesn't actually verify the output since it's just printed |
| 12 // to stdout by void functions, but it's still useful as it executes the code. | 12 // to stdout by void functions, but it's still useful as it executes the code. |
| 13 | 13 |
| 14 #include <stdio.h> | 14 #include <stdio.h> |
| 15 #include <fstream> | 15 #include <fstream> |
| 16 #include <string> | 16 #include <string> |
| 17 | 17 |
| 18 #include "webrtc/test/gtest.h" | 18 #include "webrtc/test/gtest.h" |
| 19 #include "webrtc/test/testsupport/fileutils.h" | 19 #include "webrtc/test/testsupport/fileutils.h" |
| 20 #include "webrtc/tools/frame_analyzer/video_quality_analysis.h" | 20 #include "webrtc/tools/frame_analyzer/video_quality_analysis.h" |
| 21 | 21 |
| 22 namespace webrtc { | 22 namespace webrtc { |
| 23 namespace test { | 23 namespace test { |
| 24 | 24 |
| 25 // Setup a log file to write the output to instead of stdout because we don't | 25 // Setup a log file to write the output to instead of stdout because we don't |
| 26 // want those numbers to be picked up as perf numbers. | 26 // want those numbers to be picked up as perf numbers. |
| 27 class VideoQualityAnalysisTest : public ::testing::Test { | 27 class VideoQualityAnalysisTest : public ::testing::Test { |
| 28 protected: | 28 protected: |
| 29 static void SetUpTestCase() { | 29 static void SetUpTestCase() { |
| 30 std::string log_filename = webrtc::test::OutputPath() + | 30 std::string log_filename = TempFilename(webrtc::test::OutputPath(), |
|
kjellander_webrtc
2017/02/15 12:16:58
"Google Test automatically calls SetUpTestCase() b
mandermo
2017/02/15 12:52:54
This code was there before I started to work on th
kjellander_webrtc
2017/02/15 14:00:37
OK, it feels like things could break if we write a
mandermo
2017/02/15 14:50:29
That log file is just for putting the data somewhe
| |
| 31 "VideoQualityAnalysisTest.log"; | 31 "VideoQualityAnalysisTest.log"); |
| 32 logfile_ = fopen(log_filename.c_str(), "w"); | 32 logfile_ = fopen(log_filename.c_str(), "w"); |
| 33 ASSERT_TRUE(logfile_ != NULL); | 33 ASSERT_TRUE(logfile_ != NULL); |
| 34 } | 34 } |
| 35 static void TearDownTestCase() { | 35 static void TearDownTestCase() { |
| 36 ASSERT_EQ(0, fclose(logfile_)); | 36 ASSERT_EQ(0, fclose(logfile_)); |
| 37 } | 37 } |
| 38 static FILE* logfile_; | 38 static FILE* logfile_; |
| 39 }; | 39 }; |
| 40 FILE* VideoQualityAnalysisTest::logfile_ = NULL; | 40 FILE* VideoQualityAnalysisTest::logfile_ = NULL; |
| 41 | 41 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 std::string stats_filename_ref = | 88 std::string stats_filename_ref = |
| 89 OutputPath() + "non-existing-stats-file-1.txt"; | 89 OutputPath() + "non-existing-stats-file-1.txt"; |
| 90 std::string stats_filename = OutputPath() + "non-existing-stats-file-2.txt"; | 90 std::string stats_filename = OutputPath() + "non-existing-stats-file-2.txt"; |
| 91 remove(stats_filename.c_str()); | 91 remove(stats_filename.c_str()); |
| 92 PrintMaxRepeatedAndSkippedFrames(logfile_, "NonExistingStatsFile", | 92 PrintMaxRepeatedAndSkippedFrames(logfile_, "NonExistingStatsFile", |
| 93 stats_filename_ref, stats_filename); | 93 stats_filename_ref, stats_filename); |
| 94 } | 94 } |
| 95 | 95 |
| 96 TEST_F(VideoQualityAnalysisTest, | 96 TEST_F(VideoQualityAnalysisTest, |
| 97 PrintMaxRepeatedAndSkippedFramesEmptyStatsFile) { | 97 PrintMaxRepeatedAndSkippedFramesEmptyStatsFile) { |
| 98 std::string stats_filename_ref = OutputPath() + "empty-stats-1.txt"; | 98 std::string stats_filename_ref = TempFilename(OutputPath(), "stats-1.txt"); |
|
kjellander_webrtc
2017/02/15 12:16:58
The declaration pattern at line 98-100 is repeated
mandermo
2017/02/15 12:52:54
Done.
| |
| 99 std::string stats_filename = OutputPath() + "empty-stats-2.txt"; | 99 std::string stats_filename = TempFilename(OutputPath(), "stats-2.txt"); |
| 100 std::ofstream stats_file; | 100 std::ofstream stats_file; |
| 101 stats_file.open(stats_filename_ref.c_str()); | 101 stats_file.open(stats_filename_ref.c_str()); |
| 102 stats_file.close(); | 102 stats_file.close(); |
| 103 stats_file.open(stats_filename.c_str()); | 103 stats_file.open(stats_filename.c_str()); |
| 104 stats_file.close(); | 104 stats_file.close(); |
| 105 PrintMaxRepeatedAndSkippedFrames(logfile_, "EmptyStatsFile", | 105 PrintMaxRepeatedAndSkippedFrames(logfile_, "EmptyStatsFile", |
| 106 stats_filename_ref, stats_filename); | 106 stats_filename_ref, stats_filename); |
| 107 } | 107 } |
| 108 | 108 |
| 109 TEST_F(VideoQualityAnalysisTest, PrintMaxRepeatedAndSkippedFramesNormalFile) { | 109 TEST_F(VideoQualityAnalysisTest, PrintMaxRepeatedAndSkippedFramesNormalFile) { |
| 110 std::string stats_filename_ref = OutputPath() + "stats-1.txt"; | 110 std::string stats_filename_ref = TempFilename(OutputPath(), "stats-1.txt"); |
| 111 std::string stats_filename = OutputPath() + "stats-2.txt"; | 111 std::string stats_filename = TempFilename(OutputPath(), "stats-2.txt"); |
| 112 std::ofstream stats_file; | 112 std::ofstream stats_file; |
| 113 | 113 |
| 114 stats_file.open(stats_filename_ref.c_str()); | 114 stats_file.open(stats_filename_ref.c_str()); |
| 115 stats_file << "frame_0001 0100\n"; | 115 stats_file << "frame_0001 0100\n"; |
| 116 stats_file << "frame_0002 0101\n"; | 116 stats_file << "frame_0002 0101\n"; |
| 117 stats_file << "frame_0003 0102\n"; | 117 stats_file << "frame_0003 0102\n"; |
| 118 stats_file << "frame_0004 0103\n"; | 118 stats_file << "frame_0004 0103\n"; |
| 119 stats_file << "frame_0005 0106\n"; | 119 stats_file << "frame_0005 0106\n"; |
| 120 stats_file << "frame_0006 0107\n"; | 120 stats_file << "frame_0006 0107\n"; |
| 121 stats_file << "frame_0007 0108\n"; | 121 stats_file << "frame_0007 0108\n"; |
| 122 stats_file.close(); | 122 stats_file.close(); |
| 123 | 123 |
| 124 stats_file.open(stats_filename.c_str()); | 124 stats_file.open(stats_filename.c_str()); |
| 125 stats_file << "frame_0001 0100\n"; | 125 stats_file << "frame_0001 0100\n"; |
| 126 stats_file << "frame_0002 0101\n"; | 126 stats_file << "frame_0002 0101\n"; |
| 127 stats_file << "frame_0003 0101\n"; | 127 stats_file << "frame_0003 0101\n"; |
| 128 stats_file << "frame_0004 0106\n"; | 128 stats_file << "frame_0004 0106\n"; |
| 129 stats_file.close(); | 129 stats_file.close(); |
| 130 | 130 |
| 131 PrintMaxRepeatedAndSkippedFrames(logfile_, "NormalStatsFile", | 131 PrintMaxRepeatedAndSkippedFrames(logfile_, "NormalStatsFile", |
| 132 stats_filename_ref, stats_filename); | 132 stats_filename_ref, stats_filename); |
| 133 } | 133 } |
| 134 | 134 |
| 135 | 135 namespace { |
| 136 void VerifyLogOutput(const std::string& log_filename, | |
| 137 const std::vector<std::string>& expected_out) { | |
| 138 std::ifstream logf(log_filename); | |
| 139 std::string line; | |
| 140 | |
| 141 std::size_t i; | |
| 142 for (i = 0; i < expected_out.size() && getline(logf, line); ++i) { | |
| 143 ASSERT_EQ(expected_out.at(i), line); | |
| 144 } | |
| 145 ASSERT_TRUE(i == expected_out.size()) << "Not enough input data"; | |
| 146 } | |
| 147 } // unnamed namespace | |
| 148 | |
| 149 TEST_F(VideoQualityAnalysisTest, | |
| 150 PrintMaxRepeatedAndSkippedFramesSkippedFrames) { | |
| 151 std::string stats_filename_ref = TempFilename(OutputPath(), "stats-1.txt"); | |
| 152 std::string stats_filename = TempFilename(OutputPath(), "stats-2.txt"); | |
| 153 std::ofstream stats_file; | |
| 154 | |
| 155 std::string log_filename = | |
| 156 TempFilename(webrtc::test::OutputPath(), "log.log"); | |
| 157 FILE* logfile = fopen(log_filename.c_str(), "w"); | |
| 158 ASSERT_TRUE(logfile != NULL); | |
| 159 stats_file.open(stats_filename_ref.c_str()); | |
| 160 stats_file << "frame_0001 0100\n"; | |
| 161 stats_file << "frame_0002 0101\n"; | |
| 162 stats_file << "frame_0002 0101\n"; | |
| 163 stats_file << "frame_0003 0103\n"; | |
| 164 stats_file << "frame_0004 0103\n"; | |
| 165 stats_file << "frame_0005 0106\n"; | |
| 166 stats_file << "frame_0006 0106\n"; | |
| 167 stats_file << "frame_0007 0108\n"; | |
| 168 stats_file << "frame_0008 0110\n"; | |
| 169 stats_file << "frame_0009 0112\n"; | |
| 170 stats_file.close(); | |
| 171 | |
| 172 stats_file.open(stats_filename.c_str()); | |
| 173 stats_file << "frame_0001 0101\n"; | |
| 174 stats_file << "frame_0002 0101\n"; | |
| 175 stats_file << "frame_0003 0101\n"; | |
| 176 stats_file << "frame_0004 0108\n"; | |
| 177 stats_file << "frame_0005 0108\n"; | |
| 178 stats_file << "frame_0006 0112\n"; | |
| 179 stats_file.close(); | |
| 180 | |
| 181 PrintMaxRepeatedAndSkippedFrames(logfile, "NormalStatsFile", | |
| 182 stats_filename_ref, stats_filename); | |
| 183 ASSERT_EQ(0, fclose(logfile)); | |
| 184 | |
| 185 std::vector<std::string> expected_out = { | |
| 186 "RESULT Max_repeated: NormalStatsFile= 2", | |
| 187 "RESULT Max_skipped: NormalStatsFile= 2", | |
| 188 "RESULT Total_skipped: NormalStatsFile= 3", | |
| 189 "RESULT Decode_errors_reference: NormalStatsFile= 0", | |
| 190 "RESULT Decode_errors_test: NormalStatsFile= 0"}; | |
| 191 VerifyLogOutput(log_filename, expected_out); | |
| 192 } | |
| 193 | |
| 194 TEST_F(VideoQualityAnalysisTest, | |
| 195 PrintMaxRepeatedAndSkippedFramesDecodeErrorInTest) { | |
| 196 std::string stats_filename_ref = | |
| 197 TempFilename(OutputPath(), "error-test-stats-1.txt"); | |
| 198 std::string stats_filename = | |
| 199 TempFilename(OutputPath(), "error-test-stats-2.txt"); | |
| 200 std::ofstream stats_file; | |
| 201 | |
| 202 std::string log_filename = | |
| 203 TempFilename(webrtc::test::OutputPath(), "log.log"); | |
| 204 FILE* logfile = fopen(log_filename.c_str(), "w"); | |
| 205 ASSERT_TRUE(logfile != NULL); | |
| 206 stats_file.open(stats_filename_ref.c_str()); | |
| 207 stats_file << "frame_0001 0100\n"; | |
| 208 stats_file << "frame_0002 0100\n"; | |
| 209 stats_file << "frame_0002 0101\n"; | |
| 210 stats_file << "frame_0003 0103\n"; | |
| 211 stats_file << "frame_0004 0103\n"; | |
| 212 stats_file << "frame_0005 0106\n"; | |
| 213 stats_file << "frame_0006 0107\n"; | |
| 214 stats_file << "frame_0007 0107\n"; | |
| 215 stats_file << "frame_0008 0110\n"; | |
| 216 stats_file << "frame_0009 0112\n"; | |
| 217 stats_file.close(); | |
| 218 | |
| 219 stats_file.open(stats_filename.c_str()); | |
| 220 stats_file << "frame_0001 0101\n"; | |
| 221 stats_file << "frame_0002 Barcode error\n"; | |
| 222 stats_file << "frame_0003 Barcode error\n"; | |
| 223 stats_file << "frame_0004 Barcode error\n"; | |
| 224 stats_file << "frame_0005 0107\n"; | |
| 225 stats_file << "frame_0006 0110\n"; | |
| 226 stats_file.close(); | |
| 227 | |
| 228 PrintMaxRepeatedAndSkippedFrames(logfile, "NormalStatsFile", | |
| 229 stats_filename_ref, stats_filename); | |
| 230 ASSERT_EQ(0, fclose(logfile)); | |
| 231 | |
| 232 std::vector<std::string> expected_out = { | |
| 233 "RESULT Max_repeated: NormalStatsFile= 1", | |
| 234 "RESULT Max_skipped: NormalStatsFile= 0", | |
| 235 "RESULT Total_skipped: NormalStatsFile= 0", | |
| 236 "RESULT Decode_errors_reference: NormalStatsFile= 0", | |
| 237 "RESULT Decode_errors_test: NormalStatsFile= 3"}; | |
| 238 VerifyLogOutput(log_filename, expected_out); | |
| 239 } | |
| 240 | |
| 241 TEST_F(VideoQualityAnalysisTest, CalculateFrameClustersOneValue) { | |
|
kjellander_webrtc
2017/02/15 12:16:58
Please add a test case for an empty stats file as
mandermo
2017/02/15 12:52:54
Done.
| |
| 242 std::string stats_filename = TempFilename(OutputPath(), "stats.txt"); | |
| 243 std::ofstream stats_file; | |
| 244 | |
| 245 stats_file.open(stats_filename.c_str()); | |
| 246 stats_file << "frame_0001 0101\n"; | |
| 247 stats_file.close(); | |
| 248 | |
| 249 FILE* stats_filef = fopen(stats_filename.c_str(), "r"); | |
| 250 ASSERT_TRUE(stats_filef != NULL); | |
| 251 | |
| 252 auto clusters = CalculateFrameClusters(stats_filef, nullptr); | |
| 253 decltype(clusters) expected = {std::make_pair(101, 1)}; | |
| 254 ASSERT_EQ(expected, clusters); | |
| 255 } | |
| 256 | |
| 257 TEST_F(VideoQualityAnalysisTest, CalculateFrameClustersOneOneTwo) { | |
| 258 std::string stats_filename = TempFilename(OutputPath(), "stats.txt"); | |
| 259 std::ofstream stats_file; | |
| 260 | |
| 261 stats_file.open(stats_filename.c_str()); | |
| 262 stats_file << "frame_0001 0101\n"; | |
| 263 stats_file << "frame_0002 0101\n"; | |
| 264 stats_file << "frame_0003 0102\n"; | |
| 265 stats_file.close(); | |
| 266 | |
| 267 FILE* stats_filef = fopen(stats_filename.c_str(), "r"); | |
| 268 ASSERT_TRUE(stats_filef != NULL); | |
| 269 | |
| 270 auto clusters = CalculateFrameClusters(stats_filef, nullptr); | |
| 271 decltype(clusters) expected = {std::make_pair(101, 2), | |
| 272 std::make_pair(102, 1)}; | |
| 273 ASSERT_EQ(expected, clusters); | |
| 274 } | |
| 275 | |
| 276 TEST_F(VideoQualityAnalysisTest, CalculateFrameClustersOneOneErrErrThree) { | |
| 277 std::string stats_filename = TempFilename(OutputPath(), "stats.txt"); | |
| 278 std::ofstream stats_file; | |
| 279 | |
| 280 stats_file.open(stats_filename.c_str()); | |
| 281 stats_file << "frame_0001 0101\n"; | |
| 282 stats_file << "frame_0002 0101\n"; | |
| 283 stats_file << "frame_0003 Barcode error\n"; | |
| 284 stats_file << "frame_0004 Barcode error\n"; | |
| 285 stats_file << "frame_0005 0103\n"; | |
| 286 stats_file.close(); | |
| 287 | |
| 288 FILE* stats_filef = fopen(stats_filename.c_str(), "r"); | |
| 289 ASSERT_TRUE(stats_filef != NULL); | |
| 290 | |
| 291 auto clusters = CalculateFrameClusters(stats_filef, nullptr); | |
| 292 decltype(clusters) expected = {std::make_pair(101, 2), | |
| 293 std::make_pair(DECODE_ERROR, 2), | |
| 294 std::make_pair(103, 1)}; | |
| 295 ASSERT_EQ(expected, clusters); | |
| 296 } | |
| 297 | |
| 298 TEST_F(VideoQualityAnalysisTest, CalculateFrameClustersErrErr) { | |
| 299 std::string stats_filename = TempFilename(OutputPath(), "stats.txt"); | |
| 300 std::ofstream stats_file; | |
| 301 | |
| 302 stats_file.open(stats_filename.c_str()); | |
| 303 stats_file << "frame_0001 Barcode error\n"; | |
| 304 stats_file << "frame_0002 Barcode error\n"; | |
| 305 stats_file.close(); | |
| 306 | |
| 307 FILE* stats_filef = fopen(stats_filename.c_str(), "r"); | |
| 308 ASSERT_TRUE(stats_filef != NULL); | |
| 309 | |
| 310 auto clusters = CalculateFrameClusters(stats_filef, nullptr); | |
| 311 decltype(clusters) expected = {std::make_pair(DECODE_ERROR, 2)}; | |
| 312 ASSERT_EQ(expected, clusters); | |
| 313 } | |
| 314 | |
| 315 TEST_F(VideoQualityAnalysisTest, CalculateFrameClustersOneOneErrErrOne) { | |
|
kjellander_webrtc
2017/02/15 12:16:58
Following your established naming convention this
mandermo
2017/02/15 12:52:54
Done.
| |
| 316 std::string stats_filename = TempFilename(OutputPath(), "stats.txt"); | |
| 317 std::ofstream stats_file; | |
| 318 | |
| 319 stats_file.open(stats_filename.c_str()); | |
| 320 stats_file << "frame_0001 0101\n"; | |
| 321 stats_file << "frame_0002 0101\n"; | |
| 322 stats_file << "frame_0003 Barcode error\n"; | |
| 323 stats_file << "frame_0004 Barcode error\n"; | |
| 324 stats_file << "frame_0005 0101\n"; | |
| 325 stats_file << "frame_0006 0101\n"; | |
| 326 stats_file.close(); | |
| 327 | |
| 328 FILE* stats_filef = fopen(stats_filename.c_str(), "r"); | |
|
mandermo
2017/02/15 12:52:54
I forgot to close the file. Doing it now.
| |
| 329 ASSERT_TRUE(stats_filef != NULL); | |
| 330 | |
| 331 auto clusters = CalculateFrameClusters(stats_filef, nullptr); | |
| 332 decltype(clusters) expected = {std::make_pair(101, 6)}; | |
| 333 ASSERT_EQ(expected, clusters); | |
| 334 } | |
| 136 } // namespace test | 335 } // namespace test |
| 137 } // namespace webrtc | 336 } // namespace webrtc |
| OLD | NEW |