From 1ad477de3e7f8e8c42cde5d3592c2e8eb8e3a9ce Mon Sep 17 00:00:00 2001 From: "phoglund@webrtc.org" Date: Fri, 18 May 2012 08:02:37 +0000 Subject: [PATCH] Added a bit flip fuzz test to the voice engine. Extracted encryption classes to a new test library. BUG= TEST= Review URL: https://webrtc-codereview.appspot.com/564009 git-svn-id: http://webrtc.googlecode.com/svn/trunk@2256 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../libtest}/helpers/bit_flip_encryption.cc | 2 +- .../libtest}/helpers/random_encryption.cc | 2 +- .../libtest}/include/bit_flip_encryption.h | 2 +- .../libtest}/include/random_encryption.h | 2 +- src/test/libtest/libtest.gyp | 26 ++++++++++ .../auto_test/automated/vie_rtp_fuzz_test.cc | 4 +- .../test/auto_test/vie_auto_test.gypi | 1 + .../test/libvietest/libvietest.gypi | 4 -- .../main/test/auto_test/fuzz/rtp_fuzz_test.cc | 48 +++++++++++++++++++ .../main/test/voice_engine_tests.gypi | 2 + 10 files changed, 83 insertions(+), 10 deletions(-) rename src/{video_engine/test/libvietest => test/libtest}/helpers/bit_flip_encryption.cc (94%) rename src/{video_engine/test/libvietest => test/libtest}/helpers/random_encryption.cc (95%) rename src/{video_engine/test/libvietest => test/libtest}/include/bit_flip_encryption.h (97%) rename src/{video_engine/test/libvietest => test/libtest}/include/random_encryption.h (97%) create mode 100644 src/test/libtest/libtest.gyp create mode 100644 src/voice_engine/main/test/auto_test/fuzz/rtp_fuzz_test.cc diff --git a/src/video_engine/test/libvietest/helpers/bit_flip_encryption.cc b/src/test/libtest/helpers/bit_flip_encryption.cc similarity index 94% rename from src/video_engine/test/libvietest/helpers/bit_flip_encryption.cc rename to src/test/libtest/helpers/bit_flip_encryption.cc index 20a69e7f33..e6c415206b 100644 --- a/src/video_engine/test/libvietest/helpers/bit_flip_encryption.cc +++ b/src/test/libtest/helpers/bit_flip_encryption.cc @@ -8,7 +8,7 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "video_engine/test/libvietest/include/bit_flip_encryption.h" +#include "test/libtest/include/bit_flip_encryption.h" #include diff --git a/src/video_engine/test/libvietest/helpers/random_encryption.cc b/src/test/libtest/helpers/random_encryption.cc similarity index 95% rename from src/video_engine/test/libvietest/helpers/random_encryption.cc rename to src/test/libtest/helpers/random_encryption.cc index 8f5579e8f6..4798d130d5 100644 --- a/src/video_engine/test/libvietest/helpers/random_encryption.cc +++ b/src/test/libtest/helpers/random_encryption.cc @@ -8,7 +8,7 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "video_engine/test/libvietest/include/random_encryption.h" +#include "test/libtest/include/random_encryption.h" #include #include diff --git a/src/video_engine/test/libvietest/include/bit_flip_encryption.h b/src/test/libtest/include/bit_flip_encryption.h similarity index 97% rename from src/video_engine/test/libvietest/include/bit_flip_encryption.h rename to src/test/libtest/include/bit_flip_encryption.h index ccc6974620..7e14c8898a 100644 --- a/src/video_engine/test/libvietest/include/bit_flip_encryption.h +++ b/src/test/libtest/include/bit_flip_encryption.h @@ -11,7 +11,7 @@ #ifndef SRC_VIDEO_ENGINE_TEST_AUTO_TEST_HELPERS_BIT_FLIP_ENCRYPTION_H_ #define SRC_VIDEO_ENGINE_TEST_AUTO_TEST_HELPERS_BIT_FLIP_ENCRYPTION_H_ -#include "video_engine/include/vie_encryption.h" +#include "common_types.h" // This encryption scheme will randomly flip bits every now and then in the // input data. diff --git a/src/video_engine/test/libvietest/include/random_encryption.h b/src/test/libtest/include/random_encryption.h similarity index 97% rename from src/video_engine/test/libvietest/include/random_encryption.h rename to src/test/libtest/include/random_encryption.h index cbca844c04..beaae6cd0d 100644 --- a/src/video_engine/test/libvietest/include/random_encryption.h +++ b/src/test/libtest/include/random_encryption.h @@ -11,7 +11,7 @@ #ifndef SRC_VIDEO_ENGINE_TEST_AUTO_TEST_HELPERS_RANDOM_ENCRYPTION_H_ #define SRC_VIDEO_ENGINE_TEST_AUTO_TEST_HELPERS_RANDOM_ENCRYPTION_H_ -#include "video_engine/include/vie_encryption.h" +#include "common_types.h" // These algorithms attempt to create an uncrackable encryption // scheme by completely disregarding the input data. diff --git a/src/test/libtest/libtest.gyp b/src/test/libtest/libtest.gyp new file mode 100644 index 0000000000..ea1ecc793a --- /dev/null +++ b/src/test/libtest/libtest.gyp @@ -0,0 +1,26 @@ +# Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. +# +# Use of this source code is governed by a BSD-style license +# that can be found in the LICENSE file in the root of the source +# tree. An additional intellectual property rights grant can be found +# in the file PATENTS. All contributing project authors may +# be found in the AUTHORS file in the root of the source tree. +{ + 'includes': [ + '../../build/common.gypi' + ], + 'targets': [ + { + 'target_name': 'libtest', + 'type': '<(library)', + 'sources': [ + # Helper classes + 'include/bit_flip_encryption.h', + 'include/random_encryption.h', + + 'helpers/bit_flip_encryption.cc', + 'helpers/random_encryption.cc', + ], + }, + ], +} diff --git a/src/video_engine/test/auto_test/automated/vie_rtp_fuzz_test.cc b/src/video_engine/test/auto_test/automated/vie_rtp_fuzz_test.cc index 75ca8f6001..c86233e289 100644 --- a/src/video_engine/test/auto_test/automated/vie_rtp_fuzz_test.cc +++ b/src/video_engine/test/auto_test/automated/vie_rtp_fuzz_test.cc @@ -12,12 +12,12 @@ #include "gtest/gtest.h" #include "gflags/gflags.h" +#include "test/libtest/include/bit_flip_encryption.h" +#include "test/libtest/include/random_encryption.h" #include "video_engine/test/auto_test/automated/two_windows_fixture.h" #include "video_engine/test/auto_test/interface/vie_window_creator.h" #include "video_engine/test/auto_test/interface/vie_autotest_window_manager_interface.h" #include "video_engine/test/auto_test/primitives/general_primitives.h" -#include "video_engine/test/libvietest/include/bit_flip_encryption.h" -#include "video_engine/test/libvietest/include/random_encryption.h" #include "video_engine/test/libvietest/include/tb_capture_device.h" #include "video_engine/test/libvietest/include/tb_interfaces.h" #include "video_engine/test/libvietest/include/tb_video_channel.h" diff --git a/src/video_engine/test/auto_test/vie_auto_test.gypi b/src/video_engine/test/auto_test/vie_auto_test.gypi index 675a864f48..0a12319fa2 100644 --- a/src/video_engine/test/auto_test/vie_auto_test.gypi +++ b/src/video_engine/test/auto_test/vie_auto_test.gypi @@ -20,6 +20,7 @@ '<(webrtc_root)/../third_party/google-gflags/google-gflags.gyp:google-gflags', '<(webrtc_root)/../test/metrics.gyp:metrics', '<(webrtc_root)/../test/test.gyp:test_support', + '<(webrtc_root)/test/libtest/libtest.gyp:libtest', 'video_engine_core', 'libvietest', ], diff --git a/src/video_engine/test/libvietest/libvietest.gypi b/src/video_engine/test/libvietest/libvietest.gypi index e93212a204..5cb54e1ae9 100644 --- a/src/video_engine/test/libvietest/libvietest.gypi +++ b/src/video_engine/test/libvietest/libvietest.gypi @@ -27,14 +27,10 @@ ], 'sources': [ # Helper classes - 'include/bit_flip_encryption.h', - 'include/random_encryption.h', 'include/vie_fake_camera.h', 'include/vie_file_capture_device.h', 'include/vie_to_file_renderer.h', - 'helpers/bit_flip_encryption.cc', - 'helpers/random_encryption.cc', 'helpers/vie_fake_camera.cc', 'helpers/vie_file_capture_device.cc', 'helpers/vie_to_file_renderer.cc', diff --git a/src/voice_engine/main/test/auto_test/fuzz/rtp_fuzz_test.cc b/src/voice_engine/main/test/auto_test/fuzz/rtp_fuzz_test.cc new file mode 100644 index 0000000000..c1cd7a1d3b --- /dev/null +++ b/src/voice_engine/main/test/auto_test/fuzz/rtp_fuzz_test.cc @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include + +#include "test/libtest/include/bit_flip_encryption.h" +#include "voice_engine/main/test/auto_test/fixtures/after_streaming_fixture.h" + +class RtpFuzzTest : public AfterStreamingFixture { + protected: + void BitFlipFuzzTest(float flip_probability) { + BitFlipEncryption bit_flip_encryption(std::time(NULL), flip_probability); + + TEST_LOG("Starting to flip bits in RTP/RTCP packets.\n"); + voe_encrypt_->RegisterExternalEncryption(channel_, bit_flip_encryption); + + Sleep(5000); + + voe_encrypt_->DeRegisterExternalEncryption(channel_); + + TEST_LOG("Flipped %d bits. Back to normal.\n", + static_cast(bit_flip_encryption.flip_count())); + Sleep(2000); + } +}; + +TEST_F(RtpFuzzTest, VoiceEngineDealsWithASmallNumberOfTamperedRtpPackets) { + BitFlipFuzzTest(0.00005f); +} + +TEST_F(RtpFuzzTest, VoiceEngineDealsWithAMediumNumberOfTamperedRtpPackets) { + BitFlipFuzzTest(0.0005f); +} + +TEST_F(RtpFuzzTest, VoiceEngineDealsWithALargeNumberOfTamperedRtpPackets) { + BitFlipFuzzTest(0.05f); +} + +TEST_F(RtpFuzzTest, VoiceEngineDealsWithAHugeNumberOfTamperedRtpPackets) { + BitFlipFuzzTest(0.5f); +} diff --git a/src/voice_engine/main/test/voice_engine_tests.gypi b/src/voice_engine/main/test/voice_engine_tests.gypi index 03b03713e0..ee5f4073e7 100644 --- a/src/voice_engine/main/test/voice_engine_tests.gypi +++ b/src/voice_engine/main/test/voice_engine_tests.gypi @@ -18,6 +18,7 @@ '<(webrtc_root)/../test/test.gyp:test_support', '<(webrtc_root)/../testing/gtest.gyp:gtest', '<(webrtc_root)/../testing/gmock.gyp:gmock', + '<(webrtc_root)/test/libtest/libtest.gyp:libtest', ], 'include_dirs': [ 'auto_test', @@ -38,6 +39,7 @@ 'auto_test/fixtures/after_streaming_fixture.h', 'auto_test/fixtures/before_initialization_fixture.cc', 'auto_test/fixtures/before_initialization_fixture.h', + 'auto_test/fuzz/rtp_fuzz_test.cc', 'auto_test/standard/audio_processing_test.cc', 'auto_test/standard/call_report_test.cc', 'auto_test/standard/codec_before_streaming_test.cc',