Skip to content

Commit

Permalink
Fix an illegal static_cast<FakeCrasAudioClient*> in AudioManagerTest.
Browse files Browse the repository at this point in the history
When media_unittests runs on a VM (e.g. chromeos-amd64-generic-rel),
DBusThreadManager::Initialize() will set |use_real_clients|, and cause
the non-fake CrasAudioClient to be instantiated.

SetUpCrasAudioHandlerWithTestingNodes() currently static_casts to the
fake client unconditionally.

This became a problem when the size of base::ObserverList changed in
http://crrev.com/c/1242568 and the undefined behavior became damaging
enough to crash the test.

To fix, pass --dbus-stub on the command line to ensure DBusThreadManager
creates a FakeCrasAudioClient.

Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel
Change-Id: I7d5745c72e1348228382ba193b4d310b3dd2646c
Reviewed-on: https://chromium-review.googlesource.com/1244180
Reviewed-by: Max Morin <[email protected]>
Commit-Queue: Trent Apted <[email protected]>
Cr-Commit-Position: refs/heads/master@{#594253}
  • Loading branch information
tapted authored and Commit Bot committed Sep 26, 2018
1 parent 9c09ef2 commit 6bfde54
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions media/audio/audio_manager_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
#include <vector>

#include "base/bind.h"
#include "base/command_line.h"
#include "base/environment.h"
#include "base/logging.h"
#include "base/run_loop.h"
#include "base/single_thread_task_runner.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/synchronization/waitable_event.h"
#include "base/sys_info.h"
#include "base/test/test_message_loop.h"
#include "base/threading/thread_task_runner_handle.h"
#include "build/build_config.h"
Expand Down Expand Up @@ -54,6 +56,7 @@
#if defined(USE_CRAS)
#include "chromeos/audio/audio_devices_pref_handler_stub.h"
#include "chromeos/audio/cras_audio_handler.h"
#include "chromeos/dbus/dbus_switches.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/fake_cras_audio_client.h"
#include "media/audio/cras/audio_manager_cras.h"
Expand Down Expand Up @@ -264,6 +267,12 @@ class AudioManagerTest : public ::testing::Test {
}

void SetUpCrasAudioHandlerWithTestingNodes(const AudioNodeList& audio_nodes) {
if (base::SysInfo::IsRunningOnChromeOS()) {
// Ensure a FakeCrasAudioClient is created, even on a real device or VM.
base::CommandLine::ForCurrentProcess()->AppendSwitch(
chromeos::switches::kDbusStub);
}

chromeos::DBusThreadManager::Initialize();
audio_client_ = static_cast<chromeos::FakeCrasAudioClient*>(
chromeos::DBusThreadManager::Get()->GetCrasAudioClient());
Expand Down

0 comments on commit 6bfde54

Please sign in to comment.