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

Unified Diff: content/renderer/media/audio_device_unittest.cc

Issue 10806061: Initialize the shared memory to appease Valgrind. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix AudioDevice::AudioThreadCallback::Process which could touch uninitialized data. Created 8 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/renderer/media/audio_device.cc ('k') | tools/valgrind/memcheck/suppressions_mac.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/media/audio_device_unittest.cc
diff --git a/content/renderer/media/audio_device_unittest.cc b/content/renderer/media/audio_device_unittest.cc
index adf5506cca2b3b5d45e0a65acf1be1b993e43d46..4612ec739a4078d5a82d8daf09c47373e680ad67 100644
--- a/content/renderer/media/audio_device_unittest.cc
+++ b/content/renderer/media/audio_device_unittest.cc
@@ -111,6 +111,19 @@ ACTION_P(QuitLoop, loop) {
loop->PostTask(FROM_HERE, MessageLoop::QuitClosure());
}
+// Zeros out |number_of_frames| in all channel buffers pointed to by
+// the |audio_data| vector.
+void ZeroAudioData(int number_of_frames,
+ const std::vector<float*>& audio_data) {
+ std::vector<float*>::const_iterator it = audio_data.begin();
+ for (; it != audio_data.end(); ++it) {
+ float* channel = *it;
+ for (int j = 0; j < number_of_frames; ++j) {
+ channel[j] = 0.0f;
+ }
+ }
+}
+
} // namespace.
class AudioDeviceTest : public testing::Test {
@@ -197,7 +210,9 @@ TEST_F(AudioDeviceTest, CreateStream) {
int memory_size = media::TotalSharedMemorySizeInBytes(
default_audio_parameters_.GetBytesPerBuffer());
SharedMemory shared_memory;
- ASSERT_TRUE(shared_memory.CreateAnonymous(memory_size));
+ ASSERT_TRUE(shared_memory.CreateAndMapAnonymous(memory_size));
+ // Initialize the memory.
+ memset(shared_memory.memory(), 0xff, memory_size);
CancelableSyncSocket browser_socket, renderer_socket;
ASSERT_TRUE(CancelableSyncSocket::CreatePair(&browser_socket,
@@ -226,10 +241,24 @@ TEST_F(AudioDeviceTest, CreateStream) {
// writing the interleaved audio data into the shared memory section.
// So, for the sake of this test, we consider the call to Render a sign
// of success and quit the loop.
+
+ // A note on the call to ZeroAudioData():
+ // Valgrind caught a bug in AudioDevice::AudioThreadCallback::Process()
+ // whereby we always interleaved all the frames in the buffer regardless
+ // of how many were actually rendered. So to keep the benefits of that
+ // test, we explicitly pass 0 in here as the number of frames to
+ // ZeroAudioData(). Other tests might want to pass the requested number
+ // by using WithArgs<1, 0>(Invoke(&ZeroAudioData)) and set the return
+ // value accordingly.
+ const int kNumberOfFramesToProcess = 0;
+
EXPECT_CALL(callback_, Render(_, _, _))
.WillOnce(DoAll(
+ WithArgs<0>(Invoke(
+ testing::CreateFunctor(&ZeroAudioData,
+ kNumberOfFramesToProcess))),
QuitLoop(io_loop_.message_loop_proxy()),
- Return(1)));
+ Return(kNumberOfFramesToProcess)));
audio_device->OnStreamCreated(duplicated_memory_handle, audio_device_socket,
memory_size);
« no previous file with comments | « content/renderer/media/audio_device.cc ('k') | tools/valgrind/memcheck/suppressions_mac.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698