OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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 #include <map> | 11 #include <map> |
12 #include <memory> | 12 #include <memory> |
13 #include <string> | 13 #include <string> |
14 #include <utility> | 14 #include <utility> |
15 #include <vector> | 15 #include <vector> |
16 | 16 |
17 #include "webrtc/base/buffer.h" | 17 #include "webrtc/base/buffer.h" |
18 #include "webrtc/base/checks.h" | 18 #include "webrtc/base/checks.h" |
19 #include "webrtc/base/fakeclock.h" | |
19 #include "webrtc/base/random.h" | 20 #include "webrtc/base/random.h" |
20 #include "webrtc/call.h" | 21 #include "webrtc/call.h" |
21 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" | 22 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" |
22 #include "webrtc/logging/rtc_event_log/rtc_event_log_parser.h" | 23 #include "webrtc/logging/rtc_event_log/rtc_event_log_parser.h" |
23 #include "webrtc/logging/rtc_event_log/rtc_event_log_unittest_helper.h" | 24 #include "webrtc/logging/rtc_event_log/rtc_event_log_unittest_helper.h" |
24 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet.h" | 25 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet.h" |
25 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/sender_report.h" | 26 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/sender_report.h" |
26 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extension.h" | 27 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extension.h" |
27 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h" | 28 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h" |
28 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_to_send.h" | 29 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_to_send.h" |
29 #include "webrtc/system_wrappers/include/clock.h" | |
30 #include "webrtc/test/gtest.h" | 30 #include "webrtc/test/gtest.h" |
31 #include "webrtc/test/test_suite.h" | 31 #include "webrtc/test/test_suite.h" |
32 #include "webrtc/test/testsupport/fileutils.h" | 32 #include "webrtc/test/testsupport/fileutils.h" |
33 | 33 |
34 // Files generated at build-time by the protobuf compiler. | 34 // Files generated at build-time by the protobuf compiler. |
35 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD | 35 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD |
36 #include "external/webrtc/webrtc/logging/rtc_event_log/rtc_event_log.pb.h" | 36 #include "external/webrtc/webrtc/logging/rtc_event_log/rtc_event_log.pb.h" |
37 #else | 37 #else |
38 #include "webrtc/logging/rtc_event_log/rtc_event_log.pb.h" | 38 #include "webrtc/logging/rtc_event_log/rtc_event_log.pb.h" |
39 #endif | 39 #endif |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
284 | 284 |
285 // Find the name of the current test, in order to use it as a temporary | 285 // Find the name of the current test, in order to use it as a temporary |
286 // filename. | 286 // filename. |
287 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info(); | 287 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info(); |
288 const std::string temp_filename = | 288 const std::string temp_filename = |
289 test::OutputPath() + test_info->test_case_name() + test_info->name(); | 289 test::OutputPath() + test_info->test_case_name() + test_info->name(); |
290 | 290 |
291 // When log_dumper goes out of scope, it causes the log file to be flushed | 291 // When log_dumper goes out of scope, it causes the log file to be flushed |
292 // to disk. | 292 // to disk. |
293 { | 293 { |
294 SimulatedClock fake_clock(prng.Rand<uint32_t>()); | 294 rtc::ScopedFakeClock fake_clock; |
295 std::unique_ptr<RtcEventLog> log_dumper(RtcEventLog::Create(&fake_clock)); | 295 fake_clock.SetTimeNanos(rtc::kNumNanosecsPerMicrosec * |
296 prng.Rand<uint32_t>()); | |
297 std::unique_ptr<RtcEventLog> log_dumper(RtcEventLog::Create()); | |
296 log_dumper->LogVideoReceiveStreamConfig(receiver_config); | 298 log_dumper->LogVideoReceiveStreamConfig(receiver_config); |
297 fake_clock.AdvanceTimeMicroseconds(prng.Rand(1, 1000)); | 299 fake_clock.AdvanceTime( |
300 rtc::TimeDelta::FromMicroseconds(prng.Rand(1, 1000))); | |
298 log_dumper->LogVideoSendStreamConfig(sender_config); | 301 log_dumper->LogVideoSendStreamConfig(sender_config); |
299 fake_clock.AdvanceTimeMicroseconds(prng.Rand(1, 1000)); | 302 fake_clock.AdvanceTime( |
terelius
2016/11/18 13:44:28
Could we make a convenience function for this? A l
nisse-webrtc
2016/11/18 15:03:43
What precisely do you suggest to make this more co
terelius
2016/11/18 15:55:33
A function AdvanceTimeMicroseconds(int64_t) comes
nisse-webrtc
2016/11/21 07:58:02
Hmm. I can add AdvanceTimeMicros and SetTimeMicros
nisse-webrtc
2016/11/28 14:26:42
Done.
| |
303 rtc::TimeDelta::FromMicroseconds(prng.Rand(1, 1000))); | |
300 size_t rtcp_index = 1; | 304 size_t rtcp_index = 1; |
301 size_t playout_index = 1; | 305 size_t playout_index = 1; |
302 size_t bwe_loss_index = 1; | 306 size_t bwe_loss_index = 1; |
303 for (size_t i = 1; i <= rtp_count; i++) { | 307 for (size_t i = 1; i <= rtp_count; i++) { |
304 log_dumper->LogRtpHeader( | 308 log_dumper->LogRtpHeader( |
305 (i % 2 == 0) ? kIncomingPacket : kOutgoingPacket, | 309 (i % 2 == 0) ? kIncomingPacket : kOutgoingPacket, |
306 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO, | 310 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO, |
307 rtp_packets[i - 1].data(), rtp_packets[i - 1].size()); | 311 rtp_packets[i - 1].data(), rtp_packets[i - 1].size()); |
308 fake_clock.AdvanceTimeMicroseconds(prng.Rand(1, 1000)); | 312 fake_clock.AdvanceTime( |
313 rtc::TimeDelta::FromMicroseconds(prng.Rand(1, 1000))); | |
309 if (i * rtcp_count >= rtcp_index * rtp_count) { | 314 if (i * rtcp_count >= rtcp_index * rtp_count) { |
310 log_dumper->LogRtcpPacket( | 315 log_dumper->LogRtcpPacket( |
311 (rtcp_index % 2 == 0) ? kIncomingPacket : kOutgoingPacket, | 316 (rtcp_index % 2 == 0) ? kIncomingPacket : kOutgoingPacket, |
312 rtcp_index % 3 == 0 ? MediaType::AUDIO : MediaType::VIDEO, | 317 rtcp_index % 3 == 0 ? MediaType::AUDIO : MediaType::VIDEO, |
313 rtcp_packets[rtcp_index - 1].data(), | 318 rtcp_packets[rtcp_index - 1].data(), |
314 rtcp_packets[rtcp_index - 1].size()); | 319 rtcp_packets[rtcp_index - 1].size()); |
315 rtcp_index++; | 320 rtcp_index++; |
316 fake_clock.AdvanceTimeMicroseconds(prng.Rand(1, 1000)); | 321 fake_clock.AdvanceTime( |
322 rtc::TimeDelta::FromMicroseconds(prng.Rand(1, 1000))); | |
317 } | 323 } |
318 if (i * playout_count >= playout_index * rtp_count) { | 324 if (i * playout_count >= playout_index * rtp_count) { |
319 log_dumper->LogAudioPlayout(playout_ssrcs[playout_index - 1]); | 325 log_dumper->LogAudioPlayout(playout_ssrcs[playout_index - 1]); |
320 playout_index++; | 326 playout_index++; |
321 fake_clock.AdvanceTimeMicroseconds(prng.Rand(1, 1000)); | 327 fake_clock.AdvanceTime( |
328 rtc::TimeDelta::FromMicroseconds(prng.Rand(1, 1000))); | |
322 } | 329 } |
323 if (i * bwe_loss_count >= bwe_loss_index * rtp_count) { | 330 if (i * bwe_loss_count >= bwe_loss_index * rtp_count) { |
324 log_dumper->LogBwePacketLossEvent( | 331 log_dumper->LogBwePacketLossEvent( |
325 bwe_loss_updates[bwe_loss_index - 1].first, | 332 bwe_loss_updates[bwe_loss_index - 1].first, |
326 bwe_loss_updates[bwe_loss_index - 1].second, i); | 333 bwe_loss_updates[bwe_loss_index - 1].second, i); |
327 bwe_loss_index++; | 334 bwe_loss_index++; |
328 fake_clock.AdvanceTimeMicroseconds(prng.Rand(1, 1000)); | 335 fake_clock.AdvanceTime( |
336 rtc::TimeDelta::FromMicroseconds(prng.Rand(1, 1000))); | |
329 } | 337 } |
330 if (i == rtp_count / 2) { | 338 if (i == rtp_count / 2) { |
331 log_dumper->StartLogging(temp_filename, 10000000); | 339 log_dumper->StartLogging(temp_filename, 10000000); |
332 fake_clock.AdvanceTimeMicroseconds(prng.Rand(1, 1000)); | 340 fake_clock.AdvanceTime( |
341 rtc::TimeDelta::FromMicroseconds(prng.Rand(1, 1000))); | |
333 } | 342 } |
334 } | 343 } |
335 log_dumper->StopLogging(); | 344 log_dumper->StopLogging(); |
336 } | 345 } |
337 | 346 |
338 // Read the generated file from disk. | 347 // Read the generated file from disk. |
339 ParsedRtcEventLog parsed_log; | 348 ParsedRtcEventLog parsed_log; |
340 | 349 |
341 ASSERT_TRUE(parsed_log.ParseFile(temp_filename)); | 350 ASSERT_TRUE(parsed_log.ParseFile(temp_filename)); |
342 | 351 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
440 GenerateRtpPacket(nullptr, 0, packet_size, &prng); | 449 GenerateRtpPacket(nullptr, 0, packet_size, &prng); |
441 rtc::Buffer rtcp_packet = GenerateRtcpPacket(&prng); | 450 rtc::Buffer rtcp_packet = GenerateRtcpPacket(&prng); |
442 | 451 |
443 // Find the name of the current test, in order to use it as a temporary | 452 // Find the name of the current test, in order to use it as a temporary |
444 // filename. | 453 // filename. |
445 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info(); | 454 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info(); |
446 const std::string temp_filename = | 455 const std::string temp_filename = |
447 test::OutputPath() + test_info->test_case_name() + test_info->name(); | 456 test::OutputPath() + test_info->test_case_name() + test_info->name(); |
448 | 457 |
449 // Add RTP, start logging, add RTCP and then stop logging | 458 // Add RTP, start logging, add RTCP and then stop logging |
450 SimulatedClock fake_clock(prng.Rand<uint32_t>()); | 459 rtc::ScopedFakeClock fake_clock; |
451 std::unique_ptr<RtcEventLog> log_dumper(RtcEventLog::Create(&fake_clock)); | 460 fake_clock.SetTimeNanos(rtc::kNumNanosecsPerMicrosec * prng.Rand<uint32_t>()); |
terelius
2016/11/18 13:44:28
Same thing here; could we add a convenience functi
nisse-webrtc
2016/11/18 15:03:43
Maybe a constructor taking a TimeDelta (or some in
| |
461 std::unique_ptr<RtcEventLog> log_dumper(RtcEventLog::Create()); | |
452 | 462 |
453 log_dumper->LogRtpHeader(kIncomingPacket, MediaType::VIDEO, rtp_packet.data(), | 463 log_dumper->LogRtpHeader(kIncomingPacket, MediaType::VIDEO, rtp_packet.data(), |
454 rtp_packet.size()); | 464 rtp_packet.size()); |
455 fake_clock.AdvanceTimeMicroseconds(prng.Rand(1, 1000)); | 465 fake_clock.AdvanceTime(rtc::TimeDelta::FromMicroseconds(prng.Rand(1, 1000))); |
456 | 466 |
457 log_dumper->StartLogging(temp_filename, 10000000); | 467 log_dumper->StartLogging(temp_filename, 10000000); |
458 fake_clock.AdvanceTimeMicroseconds(prng.Rand(1, 1000)); | 468 fake_clock.AdvanceTime(rtc::TimeDelta::FromMicroseconds(prng.Rand(1, 1000))); |
459 | 469 |
460 log_dumper->LogRtcpPacket(kOutgoingPacket, MediaType::VIDEO, | 470 log_dumper->LogRtcpPacket(kOutgoingPacket, MediaType::VIDEO, |
461 rtcp_packet.data(), rtcp_packet.size()); | 471 rtcp_packet.data(), rtcp_packet.size()); |
462 fake_clock.AdvanceTimeMicroseconds(prng.Rand(1, 1000)); | 472 fake_clock.AdvanceTime(rtc::TimeDelta::FromMicroseconds(prng.Rand(1, 1000))); |
463 | 473 |
464 log_dumper->StopLogging(); | 474 log_dumper->StopLogging(); |
465 | 475 |
466 // Read the generated file from disk. | 476 // Read the generated file from disk. |
467 ParsedRtcEventLog parsed_log; | 477 ParsedRtcEventLog parsed_log; |
468 ASSERT_TRUE(parsed_log.ParseFile(temp_filename)); | 478 ASSERT_TRUE(parsed_log.ParseFile(temp_filename)); |
469 | 479 |
470 // Verify that what we read back from the event log is the same as | 480 // Verify that what we read back from the event log is the same as |
471 // what we wrote down. | 481 // what we wrote down. |
472 EXPECT_EQ(4u, parsed_log.GetNumberOfEvents()); | 482 EXPECT_EQ(4u, parsed_log.GetNumberOfEvents()); |
(...skipping 28 matching lines...) Expand all Loading... | |
501 // filename. | 511 // filename. |
502 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info(); | 512 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info(); |
503 const std::string temp_filename = | 513 const std::string temp_filename = |
504 test::OutputPath() + test_info->test_case_name() + test_info->name(); | 514 test::OutputPath() + test_info->test_case_name() + test_info->name(); |
505 | 515 |
506 // Use all extensions. | 516 // Use all extensions. |
507 uint32_t extensions_bitvector = (1u << kNumExtensions) - 1; | 517 uint32_t extensions_bitvector = (1u << kNumExtensions) - 1; |
508 GenerateConfig(extensions_bitvector); | 518 GenerateConfig(extensions_bitvector); |
509 | 519 |
510 // Log a single config event and stop logging. | 520 // Log a single config event and stop logging. |
511 SimulatedClock fake_clock(prng.Rand<uint32_t>()); | 521 rtc::ScopedFakeClock fake_clock; |
512 std::unique_ptr<RtcEventLog> log_dumper(RtcEventLog::Create(&fake_clock)); | 522 fake_clock.SetTimeNanos(rtc::kNumNanosecsPerMicrosec * |
523 prng.Rand<uint32_t>()); | |
524 std::unique_ptr<RtcEventLog> log_dumper(RtcEventLog::Create()); | |
513 | 525 |
514 log_dumper->StartLogging(temp_filename, 10000000); | 526 log_dumper->StartLogging(temp_filename, 10000000); |
515 LogConfig(log_dumper.get()); | 527 LogConfig(log_dumper.get()); |
516 log_dumper->StopLogging(); | 528 log_dumper->StopLogging(); |
517 | 529 |
518 // Read the generated file from disk. | 530 // Read the generated file from disk. |
519 ParsedRtcEventLog parsed_log; | 531 ParsedRtcEventLog parsed_log; |
520 ASSERT_TRUE(parsed_log.ParseFile(temp_filename)); | 532 ASSERT_TRUE(parsed_log.ParseFile(temp_filename)); |
521 | 533 |
522 // Check the generated number of events. | 534 // Check the generated number of events. |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
615 TEST(RtcEventLogTest, LogVideoReceiveConfig) { | 627 TEST(RtcEventLogTest, LogVideoReceiveConfig) { |
616 VideoReceiveConfigReadWriteTest test; | 628 VideoReceiveConfigReadWriteTest test; |
617 test.DoTest(); | 629 test.DoTest(); |
618 } | 630 } |
619 | 631 |
620 TEST(RtcEventLogTest, LogVideoSendConfig) { | 632 TEST(RtcEventLogTest, LogVideoSendConfig) { |
621 VideoSendConfigReadWriteTest test; | 633 VideoSendConfigReadWriteTest test; |
622 test.DoTest(); | 634 test.DoTest(); |
623 } | 635 } |
624 } // namespace webrtc | 636 } // namespace webrtc |
OLD | NEW |