Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: webrtc/tools/frame_analyzer/video_quality_analysis_unittest.cc

Issue 2666333003: Better comparison for frame analyzer (Closed)
Patch Set: Moved things to SetUp() and close stats file Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/tools/frame_analyzer/video_quality_analysis.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 void SetUp() {
30 std::string log_filename = webrtc::test::OutputPath() + 30 std::string log_filename = TempFilename(webrtc::test::OutputPath(),
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
35 stats_filename_ref_ = TempFilename(OutputPath(), "stats-1.txt");
36 stats_filename_ = TempFilename(OutputPath(), "stats-2.txt");
kjellander_webrtc 2017/02/15 14:00:37 Nice, how about moving stats_file in here as well
mandermo 2017/02/15 14:50:29 I just felt it was proper to close the file before
kjellander_webrtc 2017/02/15 15:34:22 I see. Do whatever you think is cleanest.
34 } 37 }
35 static void TearDownTestCase() { 38 void TearDown() { ASSERT_EQ(0, fclose(logfile_)); }
36 ASSERT_EQ(0, fclose(logfile_)); 39 FILE* logfile_;
37 } 40 std::string stats_filename_ref_;
38 static FILE* logfile_; 41 std::string stats_filename_;
39 }; 42 };
40 FILE* VideoQualityAnalysisTest::logfile_ = NULL;
41 43
42 TEST_F(VideoQualityAnalysisTest, MatchExtractedY4mFrame) { 44 TEST_F(VideoQualityAnalysisTest, MatchExtractedY4mFrame) {
43 std::string video_file = 45 std::string video_file =
44 webrtc::test::ResourcePath("reference_less_video_test_file", "y4m"); 46 webrtc::test::ResourcePath("reference_less_video_test_file", "y4m");
45 47
46 std::string extracted_frame_from_video_file = 48 std::string extracted_frame_from_video_file =
47 webrtc::test::ResourcePath("video_quality_analysis_frame", "txt"); 49 webrtc::test::ResourcePath("video_quality_analysis_frame", "txt");
48 50
49 int frame_height = 720, frame_width = 1280; 51 int frame_height = 720, frame_width = 1280;
50 int frame_number = 2; 52 int frame_number = 2;
(...skipping 27 matching lines...) Expand all
78 80
79 TEST_F(VideoQualityAnalysisTest, PrintAnalysisResultsThreeFrames) { 81 TEST_F(VideoQualityAnalysisTest, PrintAnalysisResultsThreeFrames) {
80 ResultsContainer result; 82 ResultsContainer result;
81 result.frames.push_back(AnalysisResult(0, 35.0, 0.9)); 83 result.frames.push_back(AnalysisResult(0, 35.0, 0.9));
82 result.frames.push_back(AnalysisResult(1, 34.0, 0.8)); 84 result.frames.push_back(AnalysisResult(1, 34.0, 0.8));
83 result.frames.push_back(AnalysisResult(2, 33.0, 0.7)); 85 result.frames.push_back(AnalysisResult(2, 33.0, 0.7));
84 PrintAnalysisResults(logfile_, "ThreeFrames", &result); 86 PrintAnalysisResults(logfile_, "ThreeFrames", &result);
85 } 87 }
86 88
87 TEST_F(VideoQualityAnalysisTest, PrintMaxRepeatedAndSkippedFramesInvalidFile) { 89 TEST_F(VideoQualityAnalysisTest, PrintMaxRepeatedAndSkippedFramesInvalidFile) {
88 std::string stats_filename_ref = 90 remove(stats_filename_.c_str());
89 OutputPath() + "non-existing-stats-file-1.txt";
90 std::string stats_filename = OutputPath() + "non-existing-stats-file-2.txt";
91 remove(stats_filename.c_str());
92 PrintMaxRepeatedAndSkippedFrames(logfile_, "NonExistingStatsFile", 91 PrintMaxRepeatedAndSkippedFrames(logfile_, "NonExistingStatsFile",
93 stats_filename_ref, stats_filename); 92 stats_filename_ref_, stats_filename_);
94 } 93 }
95 94
96 TEST_F(VideoQualityAnalysisTest, 95 TEST_F(VideoQualityAnalysisTest,
97 PrintMaxRepeatedAndSkippedFramesEmptyStatsFile) { 96 PrintMaxRepeatedAndSkippedFramesEmptyStatsFile) {
98 std::string stats_filename_ref = OutputPath() + "empty-stats-1.txt";
99 std::string stats_filename = OutputPath() + "empty-stats-2.txt";
100 std::ofstream stats_file; 97 std::ofstream stats_file;
101 stats_file.open(stats_filename_ref.c_str()); 98 stats_file.open(stats_filename_ref_.c_str());
102 stats_file.close(); 99 stats_file.close();
103 stats_file.open(stats_filename.c_str()); 100 stats_file.open(stats_filename_.c_str());
104 stats_file.close(); 101 stats_file.close();
105 PrintMaxRepeatedAndSkippedFrames(logfile_, "EmptyStatsFile", 102 PrintMaxRepeatedAndSkippedFrames(logfile_, "EmptyStatsFile",
106 stats_filename_ref, stats_filename); 103 stats_filename_ref_, stats_filename_);
107 } 104 }
108 105
109 TEST_F(VideoQualityAnalysisTest, PrintMaxRepeatedAndSkippedFramesNormalFile) { 106 TEST_F(VideoQualityAnalysisTest, PrintMaxRepeatedAndSkippedFramesNormalFile) {
110 std::string stats_filename_ref = OutputPath() + "stats-1.txt";
111 std::string stats_filename = OutputPath() + "stats-2.txt";
112 std::ofstream stats_file; 107 std::ofstream stats_file;
113 108
114 stats_file.open(stats_filename_ref.c_str()); 109 stats_file.open(stats_filename_ref_.c_str());
115 stats_file << "frame_0001 0100\n"; 110 stats_file << "frame_0001 0100\n";
116 stats_file << "frame_0002 0101\n"; 111 stats_file << "frame_0002 0101\n";
117 stats_file << "frame_0003 0102\n"; 112 stats_file << "frame_0003 0102\n";
118 stats_file << "frame_0004 0103\n"; 113 stats_file << "frame_0004 0103\n";
119 stats_file << "frame_0005 0106\n"; 114 stats_file << "frame_0005 0106\n";
120 stats_file << "frame_0006 0107\n"; 115 stats_file << "frame_0006 0107\n";
121 stats_file << "frame_0007 0108\n"; 116 stats_file << "frame_0007 0108\n";
122 stats_file.close(); 117 stats_file.close();
123 118
124 stats_file.open(stats_filename.c_str()); 119 stats_file.open(stats_filename_.c_str());
125 stats_file << "frame_0001 0100\n"; 120 stats_file << "frame_0001 0100\n";
126 stats_file << "frame_0002 0101\n"; 121 stats_file << "frame_0002 0101\n";
127 stats_file << "frame_0003 0101\n"; 122 stats_file << "frame_0003 0101\n";
128 stats_file << "frame_0004 0106\n"; 123 stats_file << "frame_0004 0106\n";
129 stats_file.close(); 124 stats_file.close();
130 125
131 PrintMaxRepeatedAndSkippedFrames(logfile_, "NormalStatsFile", 126 PrintMaxRepeatedAndSkippedFrames(logfile_, "NormalStatsFile",
132 stats_filename_ref, stats_filename); 127 stats_filename_ref_, stats_filename_);
133 } 128 }
134 129
135 130 namespace {
131 void VerifyLogOutput(const std::string& log_filename,
132 const std::vector<std::string>& expected_out) {
133 std::ifstream logf(log_filename);
134 std::string line;
135
136 std::size_t i;
137 for (i = 0; i < expected_out.size() && getline(logf, line); ++i) {
138 ASSERT_EQ(expected_out.at(i), line);
139 }
140 ASSERT_TRUE(i == expected_out.size()) << "Not enough input data";
141 }
142 } // unnamed namespace
143
144 TEST_F(VideoQualityAnalysisTest,
145 PrintMaxRepeatedAndSkippedFramesSkippedFrames) {
146 std::ofstream stats_file;
147
148 std::string log_filename =
149 TempFilename(webrtc::test::OutputPath(), "log.log");
150 FILE* logfile = fopen(log_filename.c_str(), "w");
151 ASSERT_TRUE(logfile != NULL);
152 stats_file.open(stats_filename_ref_.c_str());
153 stats_file << "frame_0001 0100\n";
154 stats_file << "frame_0002 0101\n";
155 stats_file << "frame_0002 0101\n";
156 stats_file << "frame_0003 0103\n";
157 stats_file << "frame_0004 0103\n";
158 stats_file << "frame_0005 0106\n";
159 stats_file << "frame_0006 0106\n";
160 stats_file << "frame_0007 0108\n";
161 stats_file << "frame_0008 0110\n";
162 stats_file << "frame_0009 0112\n";
163 stats_file.close();
164
165 stats_file.open(stats_filename_.c_str());
166 stats_file << "frame_0001 0101\n";
167 stats_file << "frame_0002 0101\n";
168 stats_file << "frame_0003 0101\n";
169 stats_file << "frame_0004 0108\n";
170 stats_file << "frame_0005 0108\n";
171 stats_file << "frame_0006 0112\n";
172 stats_file.close();
173
174 PrintMaxRepeatedAndSkippedFrames(logfile, "NormalStatsFile",
175 stats_filename_ref_, stats_filename_);
176 ASSERT_EQ(0, fclose(logfile));
177
178 std::vector<std::string> expected_out = {
179 "RESULT Max_repeated: NormalStatsFile= 2",
180 "RESULT Max_skipped: NormalStatsFile= 2",
181 "RESULT Total_skipped: NormalStatsFile= 3",
182 "RESULT Decode_errors_reference: NormalStatsFile= 0",
183 "RESULT Decode_errors_test: NormalStatsFile= 0"};
184 VerifyLogOutput(log_filename, expected_out);
185 }
186
187 TEST_F(VideoQualityAnalysisTest,
188 PrintMaxRepeatedAndSkippedFramesDecodeErrorInTest) {
189 std::ofstream stats_file;
190
191 std::string log_filename =
192 TempFilename(webrtc::test::OutputPath(), "log.log");
193 FILE* logfile = fopen(log_filename.c_str(), "w");
194 ASSERT_TRUE(logfile != NULL);
195 stats_file.open(stats_filename_ref_.c_str());
196 stats_file << "frame_0001 0100\n";
197 stats_file << "frame_0002 0100\n";
198 stats_file << "frame_0002 0101\n";
199 stats_file << "frame_0003 0103\n";
200 stats_file << "frame_0004 0103\n";
201 stats_file << "frame_0005 0106\n";
202 stats_file << "frame_0006 0107\n";
203 stats_file << "frame_0007 0107\n";
204 stats_file << "frame_0008 0110\n";
205 stats_file << "frame_0009 0112\n";
206 stats_file.close();
207
208 stats_file.open(stats_filename_.c_str());
209 stats_file << "frame_0001 0101\n";
210 stats_file << "frame_0002 Barcode error\n";
211 stats_file << "frame_0003 Barcode error\n";
212 stats_file << "frame_0004 Barcode error\n";
213 stats_file << "frame_0005 0107\n";
214 stats_file << "frame_0006 0110\n";
215 stats_file.close();
216
217 PrintMaxRepeatedAndSkippedFrames(logfile, "NormalStatsFile",
218 stats_filename_ref_, stats_filename_);
219 ASSERT_EQ(0, fclose(logfile));
220
221 std::vector<std::string> expected_out = {
222 "RESULT Max_repeated: NormalStatsFile= 1",
223 "RESULT Max_skipped: NormalStatsFile= 0",
224 "RESULT Total_skipped: NormalStatsFile= 0",
225 "RESULT Decode_errors_reference: NormalStatsFile= 0",
226 "RESULT Decode_errors_test: NormalStatsFile= 3"};
227 VerifyLogOutput(log_filename, expected_out);
228 }
229
230 TEST_F(VideoQualityAnalysisTest, CalculateFrameClustersOneValue) {
231 std::ofstream stats_file;
232
233 stats_file.open(stats_filename_.c_str());
234 stats_file << "frame_0001 0101\n";
235 stats_file.close();
236
237 FILE* stats_filef = fopen(stats_filename_.c_str(), "r");
238 ASSERT_TRUE(stats_filef != NULL);
239
240 auto clusters = CalculateFrameClusters(stats_filef, nullptr);
241 ASSERT_EQ(0, fclose(stats_filef));
242 decltype(clusters) expected = {std::make_pair(101, 1)};
243 ASSERT_EQ(expected, clusters);
244 }
245
246 TEST_F(VideoQualityAnalysisTest, CalculateFrameClustersOneOneTwo) {
247 std::ofstream stats_file;
248
249 stats_file.open(stats_filename_.c_str());
250 stats_file << "frame_0001 0101\n";
251 stats_file << "frame_0002 0101\n";
252 stats_file << "frame_0003 0102\n";
253 stats_file.close();
254
255 FILE* stats_filef = fopen(stats_filename_.c_str(), "r");
256 ASSERT_TRUE(stats_filef != NULL);
257
258 auto clusters = CalculateFrameClusters(stats_filef, nullptr);
259 ASSERT_EQ(0, fclose(stats_filef));
260 decltype(clusters) expected = {std::make_pair(101, 2),
261 std::make_pair(102, 1)};
262 ASSERT_EQ(expected, clusters);
263 }
264
265 TEST_F(VideoQualityAnalysisTest, CalculateFrameClustersOneOneErrErrThree) {
266 std::ofstream stats_file;
267
268 stats_file.open(stats_filename_.c_str());
269 stats_file << "frame_0001 0101\n";
270 stats_file << "frame_0002 0101\n";
271 stats_file << "frame_0003 Barcode error\n";
272 stats_file << "frame_0004 Barcode error\n";
273 stats_file << "frame_0005 0103\n";
274 stats_file.close();
275
276 FILE* stats_filef = fopen(stats_filename_.c_str(), "r");
277 ASSERT_TRUE(stats_filef != NULL);
278
279 auto clusters = CalculateFrameClusters(stats_filef, nullptr);
280 ASSERT_EQ(0, fclose(stats_filef));
281 decltype(clusters) expected = {std::make_pair(101, 2),
282 std::make_pair(DECODE_ERROR, 2),
283 std::make_pair(103, 1)};
284 ASSERT_EQ(expected, clusters);
285 }
286
287 TEST_F(VideoQualityAnalysisTest, CalculateFrameClustersErrErr) {
288 std::ofstream stats_file;
289
290 stats_file.open(stats_filename_.c_str());
291 stats_file << "frame_0001 Barcode error\n";
292 stats_file << "frame_0002 Barcode error\n";
293 stats_file.close();
294
295 FILE* stats_filef = fopen(stats_filename_.c_str(), "r");
296 ASSERT_TRUE(stats_filef != NULL);
297
298 auto clusters = CalculateFrameClusters(stats_filef, nullptr);
299 ASSERT_EQ(0, fclose(stats_filef));
300 decltype(clusters) expected = {std::make_pair(DECODE_ERROR, 2)};
301 ASSERT_EQ(expected, clusters);
302 }
303
304 TEST_F(VideoQualityAnalysisTest, CalculateFrameClustersOneOneErrErrOneOne) {
305 std::ofstream stats_file;
306
307 stats_file.open(stats_filename_.c_str());
308 stats_file << "frame_0001 0101\n";
309 stats_file << "frame_0002 0101\n";
310 stats_file << "frame_0003 Barcode error\n";
311 stats_file << "frame_0004 Barcode error\n";
312 stats_file << "frame_0005 0101\n";
313 stats_file << "frame_0006 0101\n";
314 stats_file.close();
315
316 FILE* stats_filef = fopen(stats_filename_.c_str(), "r");
317 ASSERT_TRUE(stats_filef != NULL);
318
319 auto clusters = CalculateFrameClusters(stats_filef, nullptr);
320 ASSERT_EQ(0, fclose(stats_filef));
321 decltype(clusters) expected = {std::make_pair(101, 6)};
322 ASSERT_EQ(expected, clusters);
323 }
324
325 TEST_F(VideoQualityAnalysisTest, CalculateFrameClustersEmpty) {
326 std::ofstream stats_file;
327
328 stats_file.open(stats_filename_.c_str());
329 stats_file.close();
330
331 FILE* stats_filef = fopen(stats_filename_.c_str(), "r");
332 ASSERT_TRUE(stats_filef != NULL);
333
334 auto clusters = CalculateFrameClusters(stats_filef, nullptr);
335 ASSERT_EQ(0, fclose(stats_filef));
336 decltype(clusters) expected;
337 ASSERT_EQ(expected, clusters);
338 }
136 } // namespace test 339 } // namespace test
137 } // namespace webrtc 340 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/tools/frame_analyzer/video_quality_analysis.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698