diff options
Diffstat (limited to 'cras/src/tests')
27 files changed, 294 insertions, 534 deletions
diff --git a/cras/src/tests/a2dp_iodev_unittest.cc b/cras/src/tests/a2dp_iodev_unittest.cc index 523a62e4..f03a6147 100644 --- a/cras/src/tests/a2dp_iodev_unittest.cc +++ b/cras/src/tests/a2dp_iodev_unittest.cc @@ -44,7 +44,7 @@ static size_t cras_iodev_free_resources_called; static int a2dp_write_return_val[MAX_A2DP_WRITE_CALLS]; static unsigned int a2dp_write_index; static int a2dp_encode_called; -static cras_audio_area* mock_audio_area; +static cras_audio_area* dummy_audio_area; static thread_callback write_callback; static void* write_callback_data; static const char* fake_device_name = "fake device name"; @@ -79,9 +79,9 @@ void ResetStubData() { fake_transport = reinterpret_cast<struct cras_bt_transport*>(0x123); - if (!mock_audio_area) { - mock_audio_area = (cras_audio_area*)calloc( - 1, sizeof(*mock_audio_area) + sizeof(cras_channel_area) * 2); + if (!dummy_audio_area) { + dummy_audio_area = (cras_audio_area*)calloc( + 1, sizeof(*dummy_audio_area) + sizeof(cras_channel_area) * 2); } write_callback = NULL; @@ -108,8 +108,8 @@ class A2dpIodev : public testing::Test { } virtual void TearDown() { - free(mock_audio_area); - mock_audio_area = NULL; + free(dummy_audio_area); + dummy_audio_area = NULL; free(atlog); } }; @@ -899,7 +899,7 @@ int clock_gettime(clockid_t clk_id, struct timespec* tp) { } void cras_iodev_init_audio_area(struct cras_iodev* iodev, int num_channels) { - iodev->area = mock_audio_area; + iodev->area = dummy_audio_area; } void cras_iodev_free_audio_area(struct cras_iodev* iodev) {} @@ -917,15 +917,12 @@ int cras_iodev_fill_odev_zeros(struct cras_iodev* odev, unsigned int frames) { void cras_audio_area_config_buf_pointers(struct cras_audio_area* area, const struct cras_audio_format* fmt, uint8_t* base_buffer) { - mock_audio_area->channels[0].buf = base_buffer; + dummy_audio_area->channels[0].buf = base_buffer; } struct audio_thread* cras_iodev_list_get_audio_thread() { return NULL; } -// From ewma_power -void ewma_power_disable(struct ewma_power* ewma) {} - // From audio_thread struct audio_thread_event_log* atlog; diff --git a/cras/src/tests/alsa_helpers_unittest.cc b/cras/src/tests/alsa_helpers_unittest.cc index 32df30af..0e8112cd 100644 --- a/cras/src/tests/alsa_helpers_unittest.cc +++ b/cras/src/tests/alsa_helpers_unittest.cc @@ -163,12 +163,34 @@ TEST(AlsaHelper, MatchChannelMapCapability51) { } TEST(AlsaHelper, Htimestamp) { - snd_pcm_t* mock_handle = reinterpret_cast<snd_pcm_t*>(0x1); + snd_pcm_t* dummy_handle = reinterpret_cast<snd_pcm_t*>(0x1); snd_pcm_uframes_t used; snd_pcm_uframes_t severe_underrun_frames = 480; struct timespec tstamp; + int htimestamp_enabled = 1; const char* dev_name = "dev_name"; + // Enable htimestamp use. + ResetStubData(); + EXPECT_EQ(0, cras_alsa_set_swparams(dummy_handle, &htimestamp_enabled)); + EXPECT_EQ(snd_pcm_sw_params_set_tstamp_mode_called, 1); + EXPECT_EQ(snd_pcm_sw_params_set_tstamp_type_called, 1); + EXPECT_EQ(1, htimestamp_enabled); + + // Try to enable htimestamp use: not supported. + ResetStubData(); + snd_pcm_sw_params_ret_vals.push_back(-EINVAL); + EXPECT_EQ(0, cras_alsa_set_swparams(dummy_handle, &htimestamp_enabled)); + EXPECT_EQ(snd_pcm_sw_params_set_tstamp_mode_called, 2); + EXPECT_EQ(snd_pcm_sw_params_set_tstamp_type_called, 2); + EXPECT_EQ(0, htimestamp_enabled); + + // Disable htimestamp use. + ResetStubData(); + EXPECT_EQ(0, cras_alsa_set_swparams(dummy_handle, &htimestamp_enabled)); + EXPECT_EQ(snd_pcm_sw_params_set_tstamp_mode_called, 0); + EXPECT_EQ(snd_pcm_sw_params_set_tstamp_type_called, 0); + ResetStubData(); tstamp.tv_sec = 0; tstamp.tv_nsec = 0; @@ -176,7 +198,7 @@ TEST(AlsaHelper, Htimestamp) { snd_pcm_htimestamp_tstamp_ret_val.tv_sec = 10; snd_pcm_htimestamp_tstamp_ret_val.tv_nsec = 10000; - cras_alsa_get_avail_frames(mock_handle, 48000, severe_underrun_frames, + cras_alsa_get_avail_frames(dummy_handle, 48000, severe_underrun_frames, dev_name, &used, &tstamp); EXPECT_EQ(used, snd_pcm_htimestamp_avail_ret_val); EXPECT_EQ(tstamp.tv_sec, snd_pcm_htimestamp_tstamp_ret_val.tv_sec); @@ -184,7 +206,7 @@ TEST(AlsaHelper, Htimestamp) { } TEST(AlsaHelper, GetAvailFramesSevereUnderrun) { - snd_pcm_t* mock_handle = reinterpret_cast<snd_pcm_t*>(0x1); + snd_pcm_t* dummy_handle = reinterpret_cast<snd_pcm_t*>(0x1); snd_pcm_uframes_t avail; snd_pcm_uframes_t severe_underrun_frames = 480; snd_pcm_uframes_t buffer_size = 48000; @@ -194,7 +216,7 @@ TEST(AlsaHelper, GetAvailFramesSevereUnderrun) { ResetStubData(); snd_pcm_htimestamp_avail_ret_val = buffer_size + severe_underrun_frames + 1; - rc = cras_alsa_get_avail_frames(mock_handle, buffer_size, + rc = cras_alsa_get_avail_frames(dummy_handle, buffer_size, severe_underrun_frames, dev_name, &avail, &tstamp); // Returns -EPIPE when severe underrun happens. @@ -202,7 +224,7 @@ TEST(AlsaHelper, GetAvailFramesSevereUnderrun) { ResetStubData(); snd_pcm_htimestamp_avail_ret_val = buffer_size + severe_underrun_frames; - rc = cras_alsa_get_avail_frames(mock_handle, buffer_size, + rc = cras_alsa_get_avail_frames(dummy_handle, buffer_size, severe_underrun_frames, dev_name, &avail, &tstamp); // Underrun which is not severe enough will be masked. @@ -212,7 +234,7 @@ TEST(AlsaHelper, GetAvailFramesSevereUnderrun) { ResetStubData(); snd_pcm_htimestamp_avail_ret_val = buffer_size - 1; - rc = cras_alsa_get_avail_frames(mock_handle, buffer_size, + rc = cras_alsa_get_avail_frames(dummy_handle, buffer_size, severe_underrun_frames, dev_name, &avail, &tstamp); // When avail < buffer_size, there is no underrun. diff --git a/cras/src/tests/alsa_io_unittest.cc b/cras/src/tests/alsa_io_unittest.cc index b3059a23..ba650a2f 100644 --- a/cras/src/tests/alsa_io_unittest.cc +++ b/cras/src/tests/alsa_io_unittest.cc @@ -137,6 +137,7 @@ static int cras_iodev_frames_queued_ret; static int cras_iodev_buffer_avail_ret; static int cras_alsa_resume_appl_ptr_called; static int cras_alsa_resume_appl_ptr_ahead; +static int ucm_get_enable_htimestamp_flag_ret; static const struct cras_volume_curve* fake_get_dBFS_volume_curve_val; static int cras_iodev_dsp_set_swap_mode_for_node_called; static std::map<std::string, long> ucm_get_default_node_gain_values; @@ -219,6 +220,7 @@ void ResetStubData() { cras_iodev_buffer_avail_ret = 0; cras_alsa_resume_appl_ptr_called = 0; cras_alsa_resume_appl_ptr_ahead = 0; + ucm_get_enable_htimestamp_flag_ret = 0; fake_get_dBFS_volume_curve_val = NULL; cras_iodev_dsp_set_swap_mode_for_node_called = 0; ucm_get_default_node_gain_values.clear(); @@ -2471,7 +2473,7 @@ int cras_alsa_set_hwparams(snd_pcm_t* handle, unsigned int dma_period_time) { return 0; } -int cras_alsa_set_swparams(snd_pcm_t* handle) { +int cras_alsa_set_swparams(snd_pcm_t* handle, int* enable_htimestamp) { return 0; } int cras_alsa_get_avail_frames(snd_pcm_t* handle, @@ -2766,6 +2768,10 @@ int ucm_get_min_buffer_level(struct cras_use_case_mgr* mgr, return 0; } +unsigned int ucm_get_enable_htimestamp_flag(struct cras_use_case_mgr* mgr) { + return ucm_get_enable_htimestamp_flag_ret; +} + unsigned int ucm_get_disable_software_volume(struct cras_use_case_mgr* mgr) { return 0; } diff --git a/cras/src/tests/alsa_ucm_unittest.cc b/cras/src/tests/alsa_ucm_unittest.cc index 44c35879..efb82652 100644 --- a/cras/src/tests/alsa_ucm_unittest.cc +++ b/cras/src/tests/alsa_ucm_unittest.cc @@ -862,6 +862,28 @@ TEST(AlsaUcm, UseFullySpecifiedUCMConfig) { ASSERT_FALSE(fully_specified_flag); } +TEST(AlsaUcm, EnableHtimestampFlag) { + struct cras_use_case_mgr* mgr = &cras_ucm_mgr; + unsigned int enable_htimestamp_flag; + + std::string id = "=EnableHtimestamp//HiFi"; + ResetStubData(); + + /* Flag is not set */ + enable_htimestamp_flag = ucm_get_enable_htimestamp_flag(mgr); + ASSERT_FALSE(enable_htimestamp_flag); + + /* Flag is set to "1". */ + snd_use_case_get_value[id] = std::string("1"); + enable_htimestamp_flag = ucm_get_enable_htimestamp_flag(mgr); + ASSERT_TRUE(enable_htimestamp_flag); + + /* Flag is set to "0". */ + snd_use_case_get_value[id] = std::string("0"); + enable_htimestamp_flag = ucm_get_enable_htimestamp_flag(mgr); + ASSERT_FALSE(enable_htimestamp_flag); +} + TEST(AlsaUcm, GetMixerNameForDevice) { struct cras_use_case_mgr* mgr = &cras_ucm_mgr; const char *mixer_name_1, *mixer_name_2; diff --git a/cras/src/tests/audio_thread_unittest_obsolete.cc b/cras/src/tests/audio_thread_unittest_obsolete.cc index ae9f5ef3..0baeb38f 100644 --- a/cras/src/tests/audio_thread_unittest_obsolete.cc +++ b/cras/src/tests/audio_thread_unittest_obsolete.cc @@ -52,8 +52,8 @@ static unsigned int dev_stream_mix_called; static struct timespec time_now; static int cras_fmt_conversion_needed_return_val; -static struct cras_audio_area* mock_audio_area1; -static struct cras_audio_area* mock_audio_area2; +static struct cras_audio_area* dummy_audio_area1; +static struct cras_audio_area* dummy_audio_area2; static struct cras_audio_format cras_iodev_set_format_val; static struct dev_stream_capture_call dev_stream_capture_call; @@ -95,18 +95,18 @@ class ReadStreamSuite : public testing::Test { SetupRstream(&rstream2_, 2); shm2_ = cras_rstream_input_shm(rstream2_); - mock_audio_area1 = (cras_audio_area*)calloc( + dummy_audio_area1 = (cras_audio_area*)calloc( 1, sizeof(cras_audio_area) + 2 * sizeof(cras_channel_area)); - mock_audio_area1->num_channels = 2; - channel_area_set_channel(&mock_audio_area1->channels[0], CRAS_CH_FL); - channel_area_set_channel(&mock_audio_area1->channels[1], CRAS_CH_FR); - rstream_->input_audio_area = mock_audio_area1; - mock_audio_area2 = (cras_audio_area*)calloc( + dummy_audio_area1->num_channels = 2; + channel_area_set_channel(&dummy_audio_area1->channels[0], CRAS_CH_FL); + channel_area_set_channel(&dummy_audio_area1->channels[1], CRAS_CH_FR); + rstream_->input_audio_area = dummy_audio_area1; + dummy_audio_area2 = (cras_audio_area*)calloc( 1, sizeof(cras_audio_area) + 2 * sizeof(cras_channel_area)); - mock_audio_area2->num_channels = 2; - channel_area_set_channel(&mock_audio_area2->channels[0], CRAS_CH_FL); - channel_area_set_channel(&mock_audio_area2->channels[1], CRAS_CH_FR); - rstream2_->input_audio_area = mock_audio_area2; + dummy_audio_area2->num_channels = 2; + channel_area_set_channel(&dummy_audio_area2->channels[0], CRAS_CH_FL); + channel_area_set_channel(&dummy_audio_area2->channels[1], CRAS_CH_FR); + rstream2_->input_audio_area = dummy_audio_area2; dev_stream_mix_dont_fill_next = 0; dev_stream_mix_count = 0; @@ -123,8 +123,8 @@ class ReadStreamSuite : public testing::Test { free(rstream_); free(shm2_->area); free(rstream2_); - free(mock_audio_area1); - free(mock_audio_area2); + free(dummy_audio_area1); + free(dummy_audio_area2); } void SetupRstream(struct cras_rstream** rstream, int fd) { @@ -1444,18 +1444,18 @@ class ActiveDevicesSuite : public testing::Test { rstream2_->buffer_frames -= 50; rstream2_->cb_threshold -= 50; - mock_audio_area1 = (cras_audio_area*)calloc( + dummy_audio_area1 = (cras_audio_area*)calloc( 1, sizeof(cras_audio_area) + 2 * sizeof(cras_channel_area)); - mock_audio_area1->num_channels = 2; - channel_area_set_channel(&mock_audio_area1->channels[0], CRAS_CH_FL); - channel_area_set_channel(&mock_audio_area1->channels[1], CRAS_CH_FR); - rstream_->input_audio_area = mock_audio_area1; - mock_audio_area2 = (cras_audio_area*)calloc( + dummy_audio_area1->num_channels = 2; + channel_area_set_channel(&dummy_audio_area1->channels[0], CRAS_CH_FL); + channel_area_set_channel(&dummy_audio_area1->channels[1], CRAS_CH_FR); + rstream_->input_audio_area = dummy_audio_area1; + dummy_audio_area2 = (cras_audio_area*)calloc( 1, sizeof(cras_audio_area) + 2 * sizeof(cras_channel_area)); - mock_audio_area2->num_channels = 2; - channel_area_set_channel(&mock_audio_area2->channels[0], CRAS_CH_FL); - channel_area_set_channel(&mock_audio_area2->channels[1], CRAS_CH_FR); - rstream2_->input_audio_area = mock_audio_area2; + dummy_audio_area2->num_channels = 2; + channel_area_set_channel(&dummy_audio_area2->channels[0], CRAS_CH_FL); + channel_area_set_channel(&dummy_audio_area2->channels[1], CRAS_CH_FR); + rstream2_->input_audio_area = dummy_audio_area2; cras_iodev_set_format_called = 0; close_dev_called_ = 0; @@ -1483,8 +1483,8 @@ class ActiveDevicesSuite : public testing::Test { shm = cras_rstream_output_shm(rstream_); free(shm->header); free(rstream_); - free(mock_audio_area1); - free(mock_audio_area2); + free(dummy_audio_area1); + free(dummy_audio_area2); } void SetupRstream(struct cras_rstream** rstream) { diff --git a/cras/src/tests/bt_device_unittest.cc b/cras/src/tests/bt_device_unittest.cc index ccb581cc..a9213f3d 100644 --- a/cras/src/tests/bt_device_unittest.cc +++ b/cras/src/tests/bt_device_unittest.cc @@ -228,8 +228,7 @@ TEST_F(BtDeviceTestSuite, SetDeviceConnectedA2dpOnly) { device = cras_bt_device_create(NULL, FAKE_OBJ_PATH); EXPECT_NE((void*)NULL, device); - cras_bt_device_set_supported_profiles(device, - CRAS_BT_DEVICE_PROFILE_A2DP_SINK); + cras_bt_device_add_supported_profiles(device, A2DP_SINK_UUID); cur = msg_root = NewMockDBusConnectedMessage(1); cras_bt_device_update_properties(device, (DBusMessageIter*)&cur, NULL); @@ -269,9 +268,8 @@ TEST_F(BtDeviceTestSuite, SetDeviceConnectedHfpHspOnly) { device = cras_bt_device_create(NULL, FAKE_OBJ_PATH); EXPECT_NE((void*)NULL, device); - cras_bt_device_set_supported_profiles( - device, CRAS_BT_DEVICE_PROFILE_HSP_HEADSET | - CRAS_BT_DEVICE_PROFILE_HFP_HANDSFREE); + cras_bt_device_add_supported_profiles(device, HSP_HS_UUID); + cras_bt_device_add_supported_profiles(device, HFP_HF_UUID); cur = msg_root = NewMockDBusConnectedMessage(1); cras_bt_device_update_properties(device, (DBusMessageIter*)&cur, NULL); @@ -312,10 +310,9 @@ TEST_F(BtDeviceTestSuite, SetDeviceConnectedA2dpHfpHsp) { device = cras_bt_device_create(NULL, FAKE_OBJ_PATH); EXPECT_NE((void*)NULL, device); - cras_bt_device_set_supported_profiles( - device, CRAS_BT_DEVICE_PROFILE_A2DP_SINK | - CRAS_BT_DEVICE_PROFILE_HSP_HEADSET | - CRAS_BT_DEVICE_PROFILE_HFP_HANDSFREE); + cras_bt_device_add_supported_profiles(device, A2DP_SINK_UUID); + cras_bt_device_add_supported_profiles(device, HSP_HS_UUID); + cras_bt_device_add_supported_profiles(device, HFP_HF_UUID); cur = msg_root = NewMockDBusConnectedMessage(1); cras_bt_device_update_properties(device, (DBusMessageIter*)&cur, NULL); @@ -363,10 +360,9 @@ TEST_F(BtDeviceTestSuite, DevConnectedConflictCheck) { device = cras_bt_device_create(NULL, FAKE_OBJ_PATH); EXPECT_NE((void*)NULL, device); - cras_bt_device_set_supported_profiles( - device, CRAS_BT_DEVICE_PROFILE_A2DP_SINK | - CRAS_BT_DEVICE_PROFILE_HSP_HEADSET | - CRAS_BT_DEVICE_PROFILE_HFP_HANDSFREE); + cras_bt_device_add_supported_profiles(device, A2DP_SINK_UUID); + cras_bt_device_add_supported_profiles(device, HSP_HS_UUID); + cras_bt_device_add_supported_profiles(device, HFP_HF_UUID); cur = msg_root = NewMockDBusConnectedMessage(1); cras_bt_device_update_properties(device, (DBusMessageIter*)&cur, NULL); @@ -402,10 +398,9 @@ TEST_F(BtDeviceTestSuite, A2dpDropped) { device = cras_bt_device_create(NULL, FAKE_OBJ_PATH); EXPECT_NE((void*)NULL, device); - cras_bt_device_set_supported_profiles( - device, CRAS_BT_DEVICE_PROFILE_A2DP_SINK | - CRAS_BT_DEVICE_PROFILE_HSP_HEADSET | - CRAS_BT_DEVICE_PROFILE_HFP_HANDSFREE); + cras_bt_device_add_supported_profiles(device, A2DP_SINK_UUID); + cras_bt_device_add_supported_profiles(device, HSP_HS_UUID); + cras_bt_device_add_supported_profiles(device, HFP_HF_UUID); cur = msg_root = NewMockDBusConnectedMessage(1); cras_bt_device_update_properties(device, (DBusMessageIter*)&cur, NULL); @@ -438,10 +433,9 @@ TEST_F(BtDeviceTestSuite, DevConnectDisconnectBackToBack) { device = cras_bt_device_create(NULL, FAKE_OBJ_PATH); EXPECT_NE((void*)NULL, device); - cras_bt_device_set_supported_profiles( - device, CRAS_BT_DEVICE_PROFILE_A2DP_SINK | - CRAS_BT_DEVICE_PROFILE_HSP_HEADSET | - CRAS_BT_DEVICE_PROFILE_HFP_HANDSFREE); + cras_bt_device_add_supported_profiles(device, A2DP_SINK_UUID); + cras_bt_device_add_supported_profiles(device, HSP_HS_UUID); + cras_bt_device_add_supported_profiles(device, HFP_HF_UUID); cur = msg_root = NewMockDBusConnectedMessage(1); cras_bt_device_update_properties(device, (DBusMessageIter*)&cur, NULL); @@ -506,10 +500,9 @@ TEST_F(BtDeviceTestSuite, ConnectionWatchTimeout) { device = cras_bt_device_create(NULL, FAKE_OBJ_PATH); EXPECT_NE((void*)NULL, device); - cras_bt_device_set_supported_profiles( - device, CRAS_BT_DEVICE_PROFILE_A2DP_SINK | - CRAS_BT_DEVICE_PROFILE_HSP_HEADSET | - CRAS_BT_DEVICE_PROFILE_HFP_HANDSFREE); + cras_bt_device_add_supported_profiles(device, A2DP_SINK_UUID); + cras_bt_device_add_supported_profiles(device, HSP_HS_UUID); + cras_bt_device_add_supported_profiles(device, HFP_HF_UUID); cur = msg_root = NewMockDBusConnectedMessage(1); cras_bt_device_update_properties(device, (DBusMessageIter*)&cur, NULL); diff --git a/cras/src/tests/bt_io_unittest.cc b/cras/src/tests/bt_io_unittest.cc index ee013cf3..7ccb669e 100644 --- a/cras/src/tests/bt_io_unittest.cc +++ b/cras/src/tests/bt_io_unittest.cc @@ -423,8 +423,7 @@ int cras_iodev_list_rm_input(struct cras_iodev* dev) { } // From bt device -unsigned int cras_bt_device_get_active_profile( - const struct cras_bt_device* device) { +int cras_bt_device_get_active_profile(const struct cras_bt_device* device) { return cras_bt_device_get_active_profile_ret; } diff --git a/cras/src/tests/capture_rclient_unittest.cc b/cras/src/tests/capture_rclient_unittest.cc index b749f1a5..4c1ab07f 100644 --- a/cras/src/tests/capture_rclient_unittest.cc +++ b/cras/src/tests/capture_rclient_unittest.cc @@ -23,8 +23,8 @@ static unsigned int cras_observer_remove_called; static int stream_list_add_called; static int stream_list_add_return; static unsigned int stream_list_rm_called; -static struct cras_audio_shm mock_shm; -static struct cras_rstream mock_rstream; +static struct cras_audio_shm dummy_shm; +static struct cras_rstream dummy_rstream; void ResetStubData() { cras_make_fd_nonblocking_called = 0; @@ -177,6 +177,44 @@ TEST_F(CCRMessageSuite, StreamConnectMessageInvalidClientId) { EXPECT_EQ(stream_id, out_msg.stream_id); } +/* + * TODO(yuhsaun): Remove this test when there are no client uses the old + * craslib. (CRAS_PROTO_VER = 5) + */ +TEST_F(CCRMessageSuite, StreamConnectMessageOldProtocal) { + struct cras_client_stream_connected out_msg; + int rc; + + struct cras_connect_message_old msg; + cras_stream_id_t stream_id = 0x10002; + + msg.proto_version = 5; + msg.direction = CRAS_STREAM_INPUT; + msg.stream_id = stream_id; + msg.stream_type = CRAS_STREAM_TYPE_DEFAULT; + msg.buffer_frames = 480; + msg.cb_threshold = 240; + msg.flags = 0; + msg.effects = 0; + pack_cras_audio_format(&msg.format, &fmt); + msg.dev_idx = NO_DEVICE; + msg.client_shm_size = 0; + msg.client_type = CRAS_CLIENT_TYPE_TEST; + msg.header.id = CRAS_SERVER_CONNECT_STREAM; + msg.header.length = sizeof(struct cras_connect_message_old); + + fd_ = 100; + rc = + rclient_->ops->handle_message_from_client(rclient_, &msg.header, &fd_, 1); + EXPECT_EQ(1, cras_make_fd_nonblocking_called); + EXPECT_EQ(1, stream_list_add_called); + EXPECT_EQ(0, stream_list_rm_called); + + rc = read(pipe_fds_[0], &out_msg, sizeof(out_msg)); + EXPECT_EQ(sizeof(out_msg), rc); + EXPECT_EQ(stream_id, out_msg.stream_id); +} + TEST_F(CCRMessageSuite, StreamDisconnectMessage) { struct cras_disconnect_stream_message msg; cras_stream_id_t stream_id = 0x10002; @@ -252,16 +290,16 @@ int stream_list_add(struct stream_list* list, struct cras_rstream** stream) { int ret; - *stream = &mock_rstream; + *stream = &dummy_rstream; stream_list_add_called++; ret = stream_list_add_return; if (ret) stream_list_add_return = -EINVAL; - mock_rstream.shm = &mock_shm; - mock_rstream.direction = config->direction; - mock_rstream.stream_id = config->stream_id; + dummy_rstream.shm = &dummy_shm; + dummy_rstream.direction = config->direction; + dummy_rstream.stream_id = config->stream_id; return ret; } diff --git a/cras/src/tests/control_rclient_unittest.cc b/cras/src/tests/control_rclient_unittest.cc index d6b63aab..b0d01fc6 100644 --- a/cras/src/tests/control_rclient_unittest.cc +++ b/cras/src/tests/control_rclient_unittest.cc @@ -47,8 +47,8 @@ static unsigned int stream_list_add_stream_called; static unsigned int stream_list_disconnect_stream_called; static unsigned int cras_iodev_list_rm_input_called; static unsigned int cras_iodev_list_rm_output_called; -static struct cras_audio_shm mock_shm; -static struct cras_rstream mock_rstream; +static struct cras_audio_shm dummy_shm; +static struct cras_rstream dummy_rstream; static size_t cras_observer_num_ops_registered; static size_t cras_observer_register_notify_called; static size_t cras_observer_add_called; @@ -222,6 +222,30 @@ TEST_F(RClientMessagesSuite, ConnectMsgWithBadFd) { stream_list_disconnect_stream_called); } +TEST_F(RClientMessagesSuite, ConnectMsgFromOldClient) { + struct cras_client_stream_connected out_msg; + int rc; + + cras_rstream_create_stream_out = rstream_; + cras_iodev_attach_stream_retval = 0; + + connect_msg_.header.length = sizeof(struct cras_connect_message_old); + connect_msg_.proto_version = 5; + + fd_ = 100; + rc = rclient_->ops->handle_message_from_client(rclient_, &connect_msg_.header, + &fd_, 1); + EXPECT_EQ(0, rc); + EXPECT_EQ(1, cras_make_fd_nonblocking_called); + + rc = read(pipe_fds_[0], &out_msg, sizeof(out_msg)); + EXPECT_EQ(sizeof(out_msg), rc); + EXPECT_EQ(stream_id_, out_msg.stream_id); + EXPECT_EQ(0, out_msg.err); + EXPECT_EQ(1, stream_list_add_stream_called); + EXPECT_EQ(0, stream_list_disconnect_stream_called); +} + TEST_F(RClientMessagesSuite, StreamConnectMessageValidDirection) { struct cras_client_stream_connected out_msg; int rc; @@ -887,16 +911,16 @@ int stream_list_add(struct stream_list* list, struct cras_rstream** stream) { int ret; - *stream = &mock_rstream; + *stream = &dummy_rstream; stream_list_add_stream_called++; ret = stream_list_add_stream_return; if (ret) stream_list_add_stream_return = -EINVAL; - mock_rstream.shm = &mock_shm; - mock_rstream.direction = config->direction; - mock_rstream.stream_id = config->stream_id; + dummy_rstream.shm = &dummy_shm; + dummy_rstream.direction = config->direction; + dummy_rstream.stream_id = config->stream_id; return ret; } @@ -963,8 +987,4 @@ bool cras_audio_format_valid(const struct cras_audio_format* fmt) { return true; } -struct packet_status_logger* cras_hfp_ag_get_wbs_logger() { - return NULL; -} - } // extern "C" diff --git a/cras/src/tests/dev_stream_unittest.cc b/cras/src/tests/dev_stream_unittest.cc index 640ca932..9210021e 100644 --- a/cras/src/tests/dev_stream_unittest.cc +++ b/cras/src/tests/dev_stream_unittest.cc @@ -340,7 +340,7 @@ TEST_F(CreateSuite, CreateSRC44to48) { // Converter tmp and output buffers are large enough for device output. unsigned int device_frames = cras_frames_at_rate(in_fmt.frame_rate, kBufferFrames, out_fmt.frame_rate); - EXPECT_LE(kBufferFrames, device_frames); // Soundness check. + EXPECT_LE(kBufferFrames, device_frames); // Sanity check. EXPECT_LE(device_frames, config_format_converter_frames); EXPECT_LE(device_frames, dev_stream->conv_buffer_size_frames); dev_stream_destroy(dev_stream); @@ -364,7 +364,7 @@ TEST_F(CreateSuite, CreateSRC44from48Input) { // Converter tmp and output buffers are large enough for device input. unsigned int device_frames = cras_frames_at_rate(out_fmt.frame_rate, kBufferFrames, in_fmt.frame_rate); - EXPECT_LE(kBufferFrames, device_frames); // Soundness check. + EXPECT_LE(kBufferFrames, device_frames); // Sanity check. EXPECT_LE(device_frames, config_format_converter_frames); EXPECT_EQ(&processed_fmt, config_format_converter_from_fmt); EXPECT_LE(device_frames, dev_stream->conv_buffer_size_frames); @@ -420,7 +420,7 @@ TEST_F(CreateSuite, CreateSRC8to48) { // Converter tmp and output buffers are large enough for device output. unsigned int device_frames = cras_frames_at_rate(in_fmt.frame_rate, kBufferFrames, out_fmt.frame_rate); - EXPECT_LE(kBufferFrames, device_frames); // Soundness check. + EXPECT_LE(kBufferFrames, device_frames); // Sanity check. EXPECT_LE(device_frames, config_format_converter_frames); EXPECT_LE(device_frames, dev_stream->conv_buffer_size_frames); dev_stream_destroy(dev_stream); @@ -441,7 +441,7 @@ TEST_F(CreateSuite, CreateSRC8from48Input) { // Converter tmp and output buffers are large enough for device input. unsigned int device_frames = cras_frames_at_rate(out_fmt.frame_rate, kBufferFrames, in_fmt.frame_rate); - EXPECT_LE(kBufferFrames, device_frames); // Soundness check. + EXPECT_LE(kBufferFrames, device_frames); // Sanity check. EXPECT_LE(device_frames, config_format_converter_frames); EXPECT_LE(device_frames, dev_stream->conv_buffer_size_frames); dev_stream_destroy(dev_stream); diff --git a/cras/src/tests/empty_iodev_unittest.cc b/cras/src/tests/empty_iodev_unittest.cc index 148d5301..585fba32 100644 --- a/cras/src/tests/empty_iodev_unittest.cc +++ b/cras/src/tests/empty_iodev_unittest.cc @@ -13,7 +13,7 @@ extern "C" { static struct timespec clock_gettime_retspec; static struct cras_audio_format fake_format; -static cras_audio_area mock_audio_area; +static cras_audio_area dummy_audio_area; namespace { @@ -57,7 +57,7 @@ int cras_iodev_default_no_stream_playback(struct cras_iodev* odev, int enable) { } void cras_iodev_init_audio_area(struct cras_iodev* iodev, int num_channels) { - iodev->area = &mock_audio_area; + iodev->area = &dummy_audio_area; } void cras_iodev_free_audio_area(struct cras_iodev* iodev) {} diff --git a/cras/src/tests/ewma_power_unittest.cc b/cras/src/tests/ewma_power_unittest.cc deleted file mode 100644 index 10f03189..00000000 --- a/cras/src/tests/ewma_power_unittest.cc +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright (c) 2020 The Chromium OS Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include <gtest/gtest.h> - -extern "C" { -#include "ewma_power.h" -} - -namespace { - -TEST(EWMAPower, RelativePowerValue) { - struct ewma_power ewma; - int16_t buf[480]; - float f; - int i; - - for (i = 0; i < 480; i++) - buf[i] = 0x00fe; - - ewma_power_init(&ewma, 48000); - EXPECT_EQ(48, ewma.step_fr); - - ewma_power_calculate(&ewma, buf, 1, 480); - EXPECT_LT(0.0f, ewma.power); - - // After 10ms of silence the power value decreases. - f = ewma.power; - for (i = 0; i < 480; i++) - buf[i] = 0x00; - ewma_power_calculate(&ewma, buf, 1, 480); - EXPECT_LT(ewma.power, f); - - // After 300ms of silence the power value decreases to insignificant low. - for (i = 0; i < 30; i++) - ewma_power_calculate(&ewma, buf, 1, 480); - EXPECT_LT(ewma.power, 1.0e-10); -} - -TEST(EWMAPower, PowerInStereoData) { - struct ewma_power ewma; - int16_t buf[960]; - int i; - float f; - - ewma_power_init(&ewma, 48000); - - for (i = 0; i < 960; i += 2) { - buf[i] = 0x0; - buf[i + 1] = 0x00fe; - } - ewma_power_calculate(&ewma, buf, 2, 480); - EXPECT_LT(0.0f, ewma.power); - - // After 10ms of silence the power value decreases. - f = ewma.power; - for (i = 0; i < 960; i++) - buf[i] = 0x0; - ewma_power_calculate(&ewma, buf, 2, 480); - EXPECT_LT(ewma.power, f); - - // After 300ms of silence the power value decreases to insignificant low. - for (i = 0; i < 30; i++) - ewma_power_calculate(&ewma, buf, 2, 480); - EXPECT_LT(ewma.power, 1.0e-10); - - // Assume the data is silent in the other channel. - ewma_power_init(&ewma, 48000); - - for (i = 0; i < 960; i += 2) { - buf[i] = 0x0ffe; - buf[i + 1] = 0x0; - } - ewma_power_calculate(&ewma, buf, 2, 480); - EXPECT_LT(0.0f, ewma.power); -} - -TEST(EWMAPower, PowerInAudioArea) { - struct ewma_power ewma; - struct cras_audio_area* area = cras_audio_area_create(4); - struct cras_audio_format* fmt = - cras_audio_format_create(SND_PCM_FORMAT_S16_LE, 48000, 4); - int8_t layout[CRAS_CH_MAX] = {0, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1}; - int16_t buf[1920]; - int i; - float f; - - cras_audio_format_set_channel_layout(fmt, layout); - cras_audio_area_config_channels(area, fmt); - - for (i = 0; i < 1920; i += 4) { - buf[i] = 0x0ffe; - buf[i + 1] = 0x0; - buf[i + 2] = 0x0; - buf[i + 3] = 0x0ffe; - } - ewma_power_init(&ewma, 48000); - ewma_power_calculate_area(&ewma, buf, area, 480); - f = ewma.power; - EXPECT_LT(0.0f, f); - - /* Change the layout in the same audio area. Expect the power be lower because - * one of the channel is now silent. */ - layout[CRAS_CH_FR] = 2; - cras_audio_format_set_channel_layout(fmt, layout); - cras_audio_area_config_channels(area, fmt); - ewma_power_init(&ewma, 48000); - ewma_power_calculate_area(&ewma, buf, area, 480); - EXPECT_GT(f, ewma.power); - - /* Change layout to the two silent channels. Expect power is 0.0f. */ - layout[CRAS_CH_FL] = 1; - cras_audio_format_set_channel_layout(fmt, layout); - cras_audio_area_config_channels(area, fmt); - ewma_power_init(&ewma, 48000); - ewma_power_calculate_area(&ewma, buf, area, 480); - EXPECT_EQ(0.0f, ewma.power); - - cras_audio_format_destroy(fmt); - cras_audio_area_destroy(area); -} - -} // namespace - -int main(int argc, char** argv) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/cras/src/tests/fmt_conv_ops_unittest.cc b/cras/src/tests/fmt_conv_ops_unittest.cc index ebe8b65d..d8feeab3 100644 --- a/cras/src/tests/fmt_conv_ops_unittest.cc +++ b/cras/src/tests/fmt_conv_ops_unittest.cc @@ -4,8 +4,6 @@ #include <gtest/gtest.h> #include <limits.h> -#include <math.h> -#include <stdint.h> #include <sys/param.h> #include <memory> @@ -479,7 +477,7 @@ TEST(FormatConverterOpsTest, _51ToStereoS16LE) { const size_t out_ch = 2; const size_t left = 0; const size_t right = 1; - const size_t center = 2; + const size_t center = 4; S16LEPtr src = CreateS16LE(frames * in_ch); S16LEPtr dst = CreateS16LE(frames * out_ch); @@ -488,58 +486,11 @@ TEST(FormatConverterOpsTest, _51ToStereoS16LE) { s16_51_to_stereo((uint8_t*)src.get(), frames, (uint8_t*)dst.get()); EXPECT_EQ(ret, frames); - /* Use the normalized_factor from the left channel = 1 / (|1| + |0.707|) - * to prevent mixing overflow. - */ - const float normalized_factor = 0.585; - - for (size_t i = 0; i < frames; ++i) { - int16_t half_center = src[i * 6 + center] * 0.707 * normalized_factor; - int16_t l = normalized_factor * src[i * 6 + left] + half_center; - int16_t r = normalized_factor * src[i * 6 + right] + half_center; - - EXPECT_EQ(l, dst[i * 2 + left]); - EXPECT_EQ(r, dst[i * 2 + right]); - } -} - -// Test 5.1 to Quad conversion. S16_LE. -TEST(FormatConverterOpsTest, _51ToQuadS16LE) { - const size_t frames = 4096; - const size_t in_ch = 6; - const size_t out_ch = 4; - const unsigned int fl_quad = 0; - const unsigned int fr_quad = 1; - const unsigned int rl_quad = 2; - const unsigned int rr_quad = 3; - - const unsigned int fl_51 = 0; - const unsigned int fr_51 = 1; - const unsigned int center_51 = 2; - const unsigned int lfe_51 = 3; - const unsigned int rl_51 = 4; - const unsigned int rr_51 = 5; - - S16LEPtr src = CreateS16LE(frames * in_ch); - S16LEPtr dst = CreateS16LE(frames * out_ch); - - size_t ret = s16_51_to_quad((uint8_t*)src.get(), frames, (uint8_t*)dst.get()); - EXPECT_EQ(ret, frames); - - /* Use normalized_factor from the left channel = 1 / (|1| + |0.707| + |0.5|) - * to prevent overflow. */ - const float normalized_factor = 0.453; for (size_t i = 0; i < frames; ++i) { - int16_t half_center = src[i * 6 + center_51] * 0.707 * normalized_factor; - int16_t lfe = src[6 * i + lfe_51] * 0.5 * normalized_factor; - int16_t fl = normalized_factor * src[6 * i + fl_51] + half_center + lfe; - int16_t fr = normalized_factor * src[6 * i + fr_51] + half_center + lfe; - int16_t rl = normalized_factor * src[6 * i + rl_51] + lfe; - int16_t rr = normalized_factor * src[6 * i + rr_51] + lfe; - EXPECT_EQ(fl, dst[4 * i + fl_quad]); - EXPECT_EQ(fr, dst[4 * i + fr_quad]); - EXPECT_EQ(rl, dst[4 * i + rl_quad]); - EXPECT_EQ(rr, dst[4 * i + rr_quad]); + int16_t half_center = src[i * 6 + center] / 2; + EXPECT_EQ(S16AddAndClip(src[i * 6 + left], half_center), dst[i * 2 + left]); + EXPECT_EQ(S16AddAndClip(src[i * 6 + right], half_center), + dst[i * 2 + right]); } } diff --git a/cras/src/tests/fmt_conv_unittest.cc b/cras/src/tests/fmt_conv_unittest.cc index c66984ee..5474f172 100644 --- a/cras/src/tests/fmt_conv_unittest.cc +++ b/cras/src/tests/fmt_conv_unittest.cc @@ -3,7 +3,6 @@ // found in the LICENSE file. #include <gtest/gtest.h> -#include <math.h> #include <sys/param.h> extern "C" { @@ -460,81 +459,6 @@ TEST(FormatConverterTest, SurroundToStereo) { free(out_buff); } -// Test 5.1 to Quad mix. -TEST(FormatConverterTest, SurroundToQuad) { - struct cras_fmt_conv* c; - struct cras_audio_format in_fmt; - struct cras_audio_format out_fmt; - - size_t out_frames; - int16_t* in_buff; - int16_t* out_buff; - unsigned int i; - const size_t buf_size = 4096; - unsigned int in_buf_size = 4096; - - ResetStub(); - in_fmt.format = SND_PCM_FORMAT_S16_LE; - out_fmt.format = SND_PCM_FORMAT_S16_LE; - in_fmt.num_channels = 6; - out_fmt.num_channels = 4; - in_fmt.frame_rate = 48000; - out_fmt.frame_rate = 48000; - for (i = 0; i < CRAS_CH_MAX; i++) - in_fmt.channel_layout[i] = surround_channel_center_layout[i]; - - c = cras_fmt_conv_create(&in_fmt, &out_fmt, buf_size, 0); - ASSERT_NE(c, (void*)NULL); - - out_frames = cras_fmt_conv_out_frames_to_in(c, buf_size); - EXPECT_EQ(buf_size, out_frames); - - out_frames = cras_fmt_conv_in_frames_to_out(c, buf_size); - EXPECT_EQ(buf_size, out_frames); - - in_buff = (int16_t*)malloc(buf_size * 2 * cras_get_format_bytes(&in_fmt)); - - const int16_t in_fl = 100; - const int16_t in_fr = 200; - const int16_t in_rl = 200; - const int16_t in_rr = 300; - const int16_t in_fc = 60; - const int16_t in_lfe = 90; - - for (i = 0; i < buf_size; i++) { - in_buff[i * 6 + CRAS_CH_FL] = in_fl; - in_buff[i * 6 + CRAS_CH_FR] = in_fr; - in_buff[i * 6 + CRAS_CH_RL] = in_rl; - in_buff[i * 6 + CRAS_CH_RR] = in_rr; - in_buff[i * 6 + CRAS_CH_FC] = in_fc; - in_buff[i * 6 + CRAS_CH_LFE] = in_lfe; - } - out_buff = (int16_t*)malloc(buf_size * 2 * cras_get_format_bytes(&out_fmt)); - out_frames = cras_fmt_conv_convert_frames( - c, (uint8_t*)in_buff, (uint8_t*)out_buff, &in_buf_size, buf_size); - EXPECT_EQ(buf_size, out_frames); - - // This is the sum of mtx[CRAS_CH_FL] coefficients. - const float normalize_factor = 1.0 / (1 + 0.707 + 0.5); - - for (i = 0; i < buf_size; i++) { - int16_t lfe = 0.5 * normalize_factor * in_lfe; - int16_t center = 0.707 * normalize_factor * in_fc; - int16_t fl = normalize_factor * in_fl + center + lfe; - int16_t fr = normalize_factor * in_fr + center + lfe; - int16_t rl = normalize_factor * in_rl + lfe; - int16_t rr = normalize_factor * in_rr + lfe; - - EXPECT_EQ(fl, out_buff[i * 4 + CRAS_CH_FL]); - EXPECT_EQ(fr, out_buff[i * 4 + CRAS_CH_FR]); - EXPECT_EQ(rl, out_buff[i * 4 + CRAS_CH_RL]); - EXPECT_EQ(rr, out_buff[i * 4 + CRAS_CH_RR]); - } - cras_fmt_conv_destroy(&c); - free(in_buff); - free(out_buff); -} - // Test Quad to Stereo mix. TEST(FormatConverterTest, QuadToStereo) { struct cras_fmt_conv* c; diff --git a/cras/src/tests/hfp_ag_profile_unittest.cc b/cras/src/tests/hfp_ag_profile_unittest.cc index 3ecd2407..1a115f04 100644 --- a/cras/src/tests/hfp_ag_profile_unittest.cc +++ b/cras/src/tests/hfp_ag_profile_unittest.cc @@ -286,9 +286,6 @@ void cras_bt_device_notify_profile_dropped( cras_bt_device_notify_profile_dropped_profile = profile; } -void hfp_info_set_wbs_logger(struct hfp_info* info, - struct packet_status_logger* wbs_logger) {} - void cras_observer_notify_bt_battery_changed(const char* address, uint32_t level) { return; diff --git a/cras/src/tests/hfp_alsa_iodev_unittest.cc b/cras/src/tests/hfp_alsa_iodev_unittest.cc index c5bd4e9a..89756948 100644 --- a/cras/src/tests/hfp_alsa_iodev_unittest.cc +++ b/cras/src/tests/hfp_alsa_iodev_unittest.cc @@ -477,9 +477,6 @@ void cras_iodev_set_active_node(struct cras_iodev* iodev, iodev->active_node = node; } -// From ewma_power -void ewma_power_disable(struct ewma_power* ewma) {} - size_t cras_system_get_volume() { return 0; } diff --git a/cras/src/tests/hfp_info_unittest.cc b/cras/src/tests/hfp_info_unittest.cc index 24f536ae..48a1c89c 100644 --- a/cras/src/tests/hfp_info_unittest.cc +++ b/cras/src/tests/hfp_info_unittest.cc @@ -3,15 +3,10 @@ * found in the LICENSE file. */ -#include <gmock/gmock.h> #include <gtest/gtest.h> #include <stdint.h> #include <time.h> -using testing::MatchesRegex; -using testing::internal::CaptureStdout; -using testing::internal::GetCapturedStdout; - extern "C" { #include "cras_hfp_info.c" #include "sbc_codec_stub.h" @@ -509,26 +504,6 @@ TEST(HfpInfo, StartHfpInfoAndWriteMsbc) { hfp_info_destroy(info); } -TEST(HfpInfo, WBSLoggerPacketStatusDumpBinary) { - struct packet_status_logger logger; - char log_regex[64]; - int num_wraps[5] = {0, 0, 0, 1, 1}; - int wp[5] = {40, 150, 162, 100, 32}; - - /* Expect the log line wraps at correct length to avoid feedback redact. */ - snprintf(log_regex, 64, "([01D]{%d}\n)*", PACKET_STATUS_LOG_LINE_WRAP); - - packet_status_logger_init(&logger); - logger.size = PACKET_STATUS_LEN_BYTES * 8; - for (int i = 0; i < 5; i++) { - CaptureStdout(); - logger.num_wraps = num_wraps[i]; - logger.wp = wp[i]; - packet_status_logger_dump_binary(&logger); - EXPECT_THAT(GetCapturedStdout(), MatchesRegex(log_regex)); - } -} - } // namespace extern "C" { @@ -574,10 +549,6 @@ int cras_msbc_plc_handle_good_frames(struct cras_msbc_plc* plc, cras_msbc_plc_handle_good_frames_called++; return MSBC_CODE_SIZE; } -void packet_status_logger_init(struct packet_status_logger* logger) {} - -void packet_status_logger_update(struct packet_status_logger* logger, - bool val) {} } int main(int argc, char** argv) { diff --git a/cras/src/tests/hfp_iodev_unittest.cc b/cras/src/tests/hfp_iodev_unittest.cc index 18262bf9..2a61140e 100644 --- a/cras/src/tests/hfp_iodev_unittest.cc +++ b/cras/src/tests/hfp_iodev_unittest.cc @@ -43,7 +43,7 @@ static size_t hfp_fill_output_with_zeros_called; static size_t hfp_force_output_level_called; static size_t hfp_force_output_level_target; static size_t fake_buffer_size = 500; -static cras_audio_area* mock_audio_area; +static cras_audio_area* dummy_audio_area; void ResetStubData() { cras_bt_device_append_iodev_called = 0; @@ -73,9 +73,9 @@ void ResetStubData() { fake_info = reinterpret_cast<struct hfp_info*>(0x123); - if (!mock_audio_area) { - mock_audio_area = (cras_audio_area*)calloc( - 1, sizeof(*mock_audio_area) + sizeof(cras_channel_area) * 2); + if (!dummy_audio_area) { + dummy_audio_area = (cras_audio_area*)calloc( + 1, sizeof(*dummy_audio_area) + sizeof(cras_channel_area) * 2); } } @@ -86,8 +86,8 @@ class HfpIodev : public testing::Test { virtual void SetUp() { ResetStubData(); } virtual void TearDown() { - free(mock_audio_area); - mock_audio_area = NULL; + free(dummy_audio_area); + dummy_audio_area = NULL; } }; @@ -243,9 +243,6 @@ void cras_iodev_set_active_node(struct cras_iodev* iodev, iodev->active_node = node; } -// From ewma_power -void ewma_power_disable(struct ewma_power* ewma) {} - // From system_state. size_t cras_system_get_volume() { return 0; @@ -354,7 +351,7 @@ void hfp_force_output_level(struct hfp_info* info, unsigned int level) { } void cras_iodev_init_audio_area(struct cras_iodev* iodev, int num_channels) { - iodev->area = mock_audio_area; + iodev->area = dummy_audio_area; } void cras_iodev_free_audio_area(struct cras_iodev* iodev) {} @@ -370,7 +367,7 @@ int cras_iodev_fill_odev_zeros(struct cras_iodev* odev, unsigned int frames) { void cras_audio_area_config_buf_pointers(struct cras_audio_area* area, const struct cras_audio_format* fmt, uint8_t* base_buffer) { - mock_audio_area->channels[0].buf = base_buffer; + dummy_audio_area->channels[0].buf = base_buffer; } int hfp_set_call_status(struct hfp_slc_handle* handle, int call) { diff --git a/cras/src/tests/hfp_slc_unittest.cc b/cras/src/tests/hfp_slc_unittest.cc index 966278f4..4501b07a 100644 --- a/cras/src/tests/hfp_slc_unittest.cc +++ b/cras/src/tests/hfp_slc_unittest.cc @@ -202,7 +202,7 @@ TEST(HfpSlc, InitializeSlcSupportsHfIndicator) { /* Assert "\r\n+BIND: (2)\r\n" response is received */ err = read(sock[1], buf, 256); - chp = strstr(buf, "\r\n+BIND: (1,2)\r\n"); + chp = strstr(buf, "\r\n+BIND: (2)\r\n"); ASSERT_NE((void*)NULL, (void*)chp); chp = strstr(buf, "\r\nOK\r\n"); ASSERT_NE((void*)NULL, (void*)chp); diff --git a/cras/src/tests/iodev_list_unittest.cc b/cras/src/tests/iodev_list_unittest.cc index 272537fc..d40facab 100644 --- a/cras/src/tests/iodev_list_unittest.cc +++ b/cras/src/tests/iodev_list_unittest.cc @@ -44,8 +44,8 @@ static struct audio_thread thread; static struct cras_iodev loopback_input; static int cras_iodev_close_called; static struct cras_iodev* cras_iodev_close_dev; -static struct cras_iodev mock_hotword_iodev; -static struct cras_iodev mock_empty_iodev[2]; +static struct cras_iodev dummy_hotword_iodev; +static struct cras_iodev dummy_empty_iodev[2]; static stream_callback* stream_add_cb; static stream_callback* stream_rm_cb; static struct cras_rstream* stream_list_get_ret; @@ -233,11 +233,11 @@ class IoDevTestSuite : public testing::Test { DL_APPEND(fake_sco_out_dev.nodes, &fake_sco_out_node); fake_sco_in_node.is_sco_pcm = 0; fake_sco_out_node.is_sco_pcm = 0; - mock_empty_iodev[0].state = CRAS_IODEV_STATE_CLOSE; - mock_empty_iodev[0].update_active_node = update_active_node; - mock_empty_iodev[1].state = CRAS_IODEV_STATE_CLOSE; - mock_empty_iodev[1].update_active_node = update_active_node; - mock_hotword_iodev.update_active_node = update_active_node; + dummy_empty_iodev[0].state = CRAS_IODEV_STATE_CLOSE; + dummy_empty_iodev[0].update_active_node = update_active_node; + dummy_empty_iodev[1].state = CRAS_IODEV_STATE_CLOSE; + dummy_empty_iodev[1].update_active_node = update_active_node; + dummy_hotword_iodev.update_active_node = update_active_node; } virtual void TearDown() { @@ -681,7 +681,8 @@ TEST_F(IoDevTestSuite, InitDevFailShouldScheduleRetry) { EXPECT_EQ(2, cras_iodev_open_called); EXPECT_EQ(1, audio_thread_add_stream_called); EXPECT_EQ(0, update_active_node_called); - EXPECT_EQ(&mock_empty_iodev[CRAS_STREAM_OUTPUT], audio_thread_add_stream_dev); + EXPECT_EQ(&dummy_empty_iodev[CRAS_STREAM_OUTPUT], + audio_thread_add_stream_dev); EXPECT_NE((void*)NULL, cras_tm_timer_cb); EXPECT_EQ(1, cras_tm_create_timer_called); @@ -692,7 +693,7 @@ TEST_F(IoDevTestSuite, InitDevFailShouldScheduleRetry) { EXPECT_EQ(1, cras_tm_create_timer_called); EXPECT_EQ(1, audio_thread_add_stream_called); - mock_empty_iodev[CRAS_STREAM_OUTPUT].format = &fmt_; + dummy_empty_iodev[CRAS_STREAM_OUTPUT].format = &fmt_; cras_tm_timer_cb = NULL; cras_iodev_open_ret[3] = -5; stream_add_cb(&rstream); @@ -1751,7 +1752,7 @@ TEST_F(IoDevTestSuite, AddRemovePinnedStream) { EXPECT_EQ(2, update_active_node_called); // Unselect d1_ and select to d2_ EXPECT_EQ(&d2_, update_active_node_iodev_val[0]); - EXPECT_EQ(&mock_empty_iodev[CRAS_STREAM_OUTPUT], + EXPECT_EQ(&dummy_empty_iodev[CRAS_STREAM_OUTPUT], update_active_node_iodev_val[1]); // Remove pinned stream from d1, check d1 is closed after stream removed. @@ -1868,14 +1869,14 @@ TEST_F(IoDevTestSuite, HotwordStreamsAddedThenSuspendResume) { EXPECT_EQ(&d1_, audio_thread_disconnect_stream_dev); EXPECT_EQ(2, audio_thread_add_stream_called); EXPECT_EQ(&rstream, audio_thread_add_stream_stream); - EXPECT_EQ(&mock_hotword_iodev, audio_thread_add_stream_dev); + EXPECT_EQ(&dummy_hotword_iodev, audio_thread_add_stream_dev); /* Resume hotword streams, verify the stream disconnects from * the empty iodev and connects back to the real hotword iodev. */ EXPECT_EQ(0, cras_iodev_list_resume_hotword_stream()); EXPECT_EQ(2, audio_thread_disconnect_stream_called); EXPECT_EQ(&rstream, audio_thread_disconnect_stream_stream); - EXPECT_EQ(&mock_hotword_iodev, audio_thread_disconnect_stream_dev); + EXPECT_EQ(&dummy_hotword_iodev, audio_thread_disconnect_stream_dev); EXPECT_EQ(3, audio_thread_add_stream_called); EXPECT_EQ(&rstream, audio_thread_add_stream_stream); EXPECT_EQ(&d1_, audio_thread_add_stream_dev); @@ -1909,7 +1910,7 @@ TEST_F(IoDevTestSuite, HotwordStreamsAddedAfterSuspend) { /* Hotword stream connected, verify it is added to the empty iodev. */ EXPECT_EQ(0, stream_add_cb(&rstream)); EXPECT_EQ(1, audio_thread_add_stream_called); - EXPECT_EQ(&mock_hotword_iodev, audio_thread_add_stream_dev); + EXPECT_EQ(&dummy_hotword_iodev, audio_thread_add_stream_dev); EXPECT_EQ(&rstream, audio_thread_add_stream_stream); /* Resume hotword streams, now the existing hotword stream should disconnect @@ -1917,7 +1918,7 @@ TEST_F(IoDevTestSuite, HotwordStreamsAddedAfterSuspend) { EXPECT_EQ(0, cras_iodev_list_resume_hotword_stream()); EXPECT_EQ(1, audio_thread_disconnect_stream_called); EXPECT_EQ(&rstream, audio_thread_disconnect_stream_stream); - EXPECT_EQ(&mock_hotword_iodev, audio_thread_disconnect_stream_dev); + EXPECT_EQ(&dummy_hotword_iodev, audio_thread_disconnect_stream_dev); EXPECT_EQ(2, audio_thread_add_stream_called); EXPECT_EQ(&rstream, audio_thread_add_stream_stream); EXPECT_EQ(&d1_, audio_thread_add_stream_dev); @@ -2034,9 +2035,9 @@ struct cras_iodev* empty_iodev_create(enum CRAS_STREAM_DIRECTION direction, enum CRAS_NODE_TYPE node_type) { struct cras_iodev* dev; if (node_type == CRAS_NODE_TYPE_HOTWORD) { - dev = &mock_hotword_iodev; + dev = &dummy_hotword_iodev; } else { - dev = &mock_empty_iodev[direction]; + dev = &dummy_empty_iodev[direction]; } dev->direction = direction; if (dev->active_node == NULL) { diff --git a/cras/src/tests/iodev_unittest.cc b/cras/src/tests/iodev_unittest.cc index 21dc4d57..03cfee62 100644 --- a/cras/src/tests/iodev_unittest.cc +++ b/cras/src/tests/iodev_unittest.cc @@ -60,7 +60,7 @@ static unsigned int cras_mix_mute_count; static unsigned int cras_dsp_num_input_channels_return; static unsigned int cras_dsp_num_output_channels_return; struct cras_dsp_context* cras_dsp_context_new_return; -static unsigned int cras_dsp_load_mock_pipeline_called; +static unsigned int cras_dsp_load_dummy_pipeline_called; static unsigned int rate_estimator_add_frames_num_frames; static unsigned int rate_estimator_add_frames_called; static int cras_system_get_mute_return; @@ -148,7 +148,7 @@ void ResetStubData() { cras_dsp_num_input_channels_return = 2; cras_dsp_num_output_channels_return = 2; cras_dsp_context_new_return = NULL; - cras_dsp_load_mock_pipeline_called = 0; + cras_dsp_load_dummy_pipeline_called = 0; rate_estimator_add_frames_num_frames = 0; rate_estimator_add_frames_called = 0; cras_system_get_mute_return = 0; @@ -2240,12 +2240,12 @@ TEST(IoDev, SetExtDspMod) { EXPECT_EQ(3, cras_dsp_get_pipeline_called); EXPECT_EQ(3, cras_dsp_pipeline_set_sink_ext_module_called); - /* If pipeline doesn't exist, mock pipeline should be loaded. */ + /* If pipeline doesn't exist, dummy pipeline should be loaded. */ cras_dsp_get_pipeline_ret = 0x0; cras_iodev_set_ext_dsp_module(&iodev, &ext); EXPECT_EQ(3, ext_mod_configure_called); EXPECT_EQ(5, cras_dsp_get_pipeline_called); - EXPECT_EQ(1, cras_dsp_load_mock_pipeline_called); + EXPECT_EQ(1, cras_dsp_load_dummy_pipeline_called); EXPECT_EQ(4, cras_dsp_pipeline_set_sink_ext_module_called); } @@ -2462,11 +2462,9 @@ unsigned int buffer_share_id_offset(const struct buffer_share* mix, } // From cras_system_state. -void cras_system_state_stream_added(enum CRAS_STREAM_DIRECTION direction, - enum CRAS_CLIENT_TYPE client_type) {} +void cras_system_state_stream_added(enum CRAS_STREAM_DIRECTION direction) {} -void cras_system_state_stream_removed(enum CRAS_STREAM_DIRECTION direction, - enum CRAS_CLIENT_TYPE client_type) {} +void cras_system_state_stream_removed(enum CRAS_STREAM_DIRECTION direction) {} // From cras_dsp struct cras_dsp_context* cras_dsp_context_new(int sample_rate, @@ -2481,9 +2479,9 @@ void cras_dsp_context_free(struct cras_dsp_context* ctx) { } void cras_dsp_load_pipeline(struct cras_dsp_context* ctx) {} -void cras_dsp_load_mock_pipeline(struct cras_dsp_context* ctx, - unsigned int num_channels) { - cras_dsp_load_mock_pipeline_called++; +void cras_dsp_load_dummy_pipeline(struct cras_dsp_context* ctx, + unsigned int num_channels) { + cras_dsp_load_dummy_pipeline_called++; } void cras_dsp_set_variable_string(struct cras_dsp_context* ctx, @@ -2762,18 +2760,6 @@ int cras_server_metrics_device_volume(struct cras_iodev* iodev) { return 0; } -void ewma_power_init(struct ewma_power* ewma, unsigned int rate){}; - -void ewma_power_calculate(struct ewma_power* ewma, - const int16_t* buf, - unsigned int channels, - unsigned int size){}; - -void ewma_power_calculate_area(struct ewma_power* ewma, - const int16_t* buf, - struct cras_audio_area* area, - unsigned int size){}; - } // extern "C" } // namespace diff --git a/cras/src/tests/loopback_iodev_unittest.cc b/cras/src/tests/loopback_iodev_unittest.cc index fde50375..1c69ba57 100644 --- a/cras/src/tests/loopback_iodev_unittest.cc +++ b/cras/src/tests/loopback_iodev_unittest.cc @@ -29,7 +29,7 @@ static const unsigned int kFrameBytes = 4; static const unsigned int kBufferSize = kBufferFrames * kFrameBytes; static struct timespec time_now; -static cras_audio_area* mock_audio_area; +static cras_audio_area* dummy_audio_area; static loopback_hook_data_t loop_hook; static struct cras_iodev* enabled_dev; static unsigned int cras_iodev_list_add_input_called; @@ -46,8 +46,8 @@ static char* atlog_name; class LoopBackTestSuite : public testing::Test { protected: virtual void SetUp() { - mock_audio_area = (cras_audio_area*)calloc( - 1, sizeof(*mock_audio_area) + sizeof(cras_channel_area) * 2); + dummy_audio_area = (cras_audio_area*)calloc( + 1, sizeof(*dummy_audio_area) + sizeof(cras_channel_area) * 2); for (unsigned int i = 0; i < kBufferSize; i++) { buf_[i] = rand(); } @@ -77,7 +77,7 @@ class LoopBackTestSuite : public testing::Test { EXPECT_EQ(1, cras_iodev_list_rm_input_called); EXPECT_EQ(NULL, device_enabled_callback_cb); EXPECT_EQ(NULL, device_disabled_callback_cb); - free(mock_audio_area); + free(dummy_audio_area); audio_thread_event_log_deinit(atlog, atlog_name); free(atlog_name); } @@ -224,7 +224,7 @@ extern "C" { void cras_audio_area_config_buf_pointers(struct cras_audio_area* area, const struct cras_audio_format* fmt, uint8_t* base_buffer) { - mock_audio_area->channels[0].buf = base_buffer; + dummy_audio_area->channels[0].buf = base_buffer; } void cras_iodev_free_audio_area(struct cras_iodev* iodev) {} @@ -232,7 +232,7 @@ void cras_iodev_free_audio_area(struct cras_iodev* iodev) {} void cras_iodev_free_format(struct cras_iodev* iodev) {} void cras_iodev_init_audio_area(struct cras_iodev* iodev, int num_channels) { - iodev->area = mock_audio_area; + iodev->area = dummy_audio_area; } void cras_iodev_add_node(struct cras_iodev* iodev, struct cras_ionode* node) { diff --git a/cras/src/tests/observer_unittest.cc b/cras/src/tests/observer_unittest.cc index 2a8fae2c..2053e940 100644 --- a/cras/src/tests/observer_unittest.cc +++ b/cras/src/tests/observer_unittest.cc @@ -11,8 +11,6 @@ extern "C" { #include "cras_observer.c" -#include "cras_observer.h" -#include "cras_types.h" } namespace { @@ -58,9 +56,6 @@ static size_t cb_num_active_streams_changed_called; static std::vector<enum CRAS_STREAM_DIRECTION> cb_num_active_streams_changed_dir; static std::vector<uint32_t> cb_num_active_streams_changed_num; -static size_t cb_num_input_streams_with_permission_called; -static std::vector<std::vector<uint32_t>> - cb_num_input_streams_with_permission_array; static void ResetStubData() { cras_alert_destroy_called = 0; @@ -104,8 +99,6 @@ static void ResetStubData() { cb_num_active_streams_changed_called = 0; cb_num_active_streams_changed_dir.clear(); cb_num_active_streams_changed_num.clear(); - cb_num_input_streams_with_permission_called = 0; - cb_num_input_streams_with_permission_array.clear(); } /* System output volume changed. */ @@ -197,15 +190,6 @@ void cb_num_active_streams_changed(void* context, cb_num_active_streams_changed_num.push_back(num_active_streams); } -void cb_num_input_streams_with_permission_changed( - void* context, - uint32_t num_input_streams[CRAS_NUM_CLIENT_TYPE]) { - cb_num_input_streams_with_permission_called++; - cb_context.push_back(context); - cb_num_input_streams_with_permission_array.push_back(std::vector<uint32_t>( - num_input_streams, num_input_streams + CRAS_NUM_CLIENT_TYPE)); -} - class ObserverTest : public testing::Test { protected: virtual void SetUp() { @@ -214,7 +198,7 @@ class ObserverTest : public testing::Test { ResetStubData(); rc = cras_observer_server_init(); ASSERT_EQ(0, rc); - EXPECT_EQ(17, cras_alert_create_called); + EXPECT_EQ(16, cras_alert_create_called); EXPECT_EQ(reinterpret_cast<void*>(output_volume_alert), cras_alert_add_callback_map[g_observer->alerts.output_volume]); EXPECT_EQ(reinterpret_cast<void*>(output_mute_alert), @@ -272,7 +256,7 @@ class ObserverTest : public testing::Test { virtual void TearDown() { cras_observer_server_free(); - EXPECT_EQ(17, cras_alert_destroy_called); + EXPECT_EQ(16, cras_alert_destroy_called); ResetStubData(); } @@ -594,37 +578,6 @@ TEST_F(ObserverTest, NotifyNumActiveStreams) { DoObserverRemoveClear(num_active_streams_alert, data); }; -TEST_F(ObserverTest, NotifyNumInputStreamsWithPermission) { - struct cras_observer_alert_data_input_streams* data; - uint32_t num_input_streams[CRAS_NUM_CLIENT_TYPE] = {}; - for (unsigned type = 0; type < CRAS_NUM_CLIENT_TYPE; ++type) { - num_input_streams[type] = (uint32_t)type; - } - - cras_observer_notify_input_streams_with_permission(num_input_streams); - ASSERT_EQ(cras_alert_pending_data_size_value, sizeof(*data)); - ASSERT_NE(cras_alert_pending_data_value, reinterpret_cast<void*>(NULL)); - data = reinterpret_cast<struct cras_observer_alert_data_input_streams*>( - cras_alert_pending_data_value); - for (unsigned type = 0; type < CRAS_NUM_CLIENT_TYPE; ++type) { - EXPECT_EQ(data->num_input_streams[type], num_input_streams[type]); - } - - ops1_.num_input_streams_with_permission_changed = - cb_num_input_streams_with_permission_changed; - ops2_.num_input_streams_with_permission_changed = - cb_num_input_streams_with_permission_changed; - DoObserverAlert(num_input_streams_with_permission_alert, data); - ASSERT_EQ(2, cb_num_input_streams_with_permission_called); - for (auto cb_num_input_streams : cb_num_input_streams_with_permission_array) { - ASSERT_EQ(cb_num_input_streams.size(), (size_t)CRAS_NUM_CLIENT_TYPE); - for (unsigned type = 0; type < CRAS_NUM_CLIENT_TYPE; ++type) { - EXPECT_EQ(cb_num_input_streams[type], num_input_streams[type]); - } - } - DoObserverRemoveClear(num_input_streams_with_permission_alert, data); -} - TEST_F(ObserverTest, NotifyHotwordTriggered) { struct cras_observer_alert_data_hotword_triggered* data; diff --git a/cras/src/tests/playback_rclient_unittest.cc b/cras/src/tests/playback_rclient_unittest.cc index 75cbe552..7056d2fe 100644 --- a/cras/src/tests/playback_rclient_unittest.cc +++ b/cras/src/tests/playback_rclient_unittest.cc @@ -24,8 +24,8 @@ static unsigned int cras_observer_remove_called; static int stream_list_add_called; static int stream_list_add_return; static unsigned int stream_list_rm_called; -static struct cras_audio_shm mock_shm; -static struct cras_rstream mock_rstream; +static struct cras_audio_shm dummy_shm; +static struct cras_rstream dummy_rstream; void ResetStubData() { audio_format_valid = true; @@ -207,6 +207,44 @@ TEST_F(CPRMessageSuite, StreamConnectMessageInvalidAudioFormat) { EXPECT_EQ(stream_id, out_msg.stream_id); } +/* + * TODO(yuhsaun): Remove this test when there are no client uses the old + * craslib. (CRAS_PROTO_VER = 5) + */ +TEST_F(CPRMessageSuite, StreamConnectMessageOldProtocal) { + struct cras_client_stream_connected out_msg; + int rc; + + struct cras_connect_message_old msg; + cras_stream_id_t stream_id = 0x10002; + + msg.proto_version = 5; + msg.direction = CRAS_STREAM_OUTPUT; + msg.stream_id = stream_id; + msg.stream_type = CRAS_STREAM_TYPE_DEFAULT; + msg.buffer_frames = 480; + msg.cb_threshold = 240; + msg.flags = 0; + msg.effects = 0; + pack_cras_audio_format(&msg.format, &fmt); + msg.dev_idx = NO_DEVICE; + msg.client_shm_size = 0; + msg.client_type = CRAS_CLIENT_TYPE_TEST; + msg.header.id = CRAS_SERVER_CONNECT_STREAM; + msg.header.length = sizeof(struct cras_connect_message_old); + + fd_ = 100; + rc = + rclient_->ops->handle_message_from_client(rclient_, &msg.header, &fd_, 1); + EXPECT_EQ(1, cras_make_fd_nonblocking_called); + EXPECT_EQ(1, stream_list_add_called); + EXPECT_EQ(0, stream_list_rm_called); + + rc = read(pipe_fds_[0], &out_msg, sizeof(out_msg)); + EXPECT_EQ(sizeof(out_msg), rc); + EXPECT_EQ(stream_id, out_msg.stream_id); +} + TEST_F(CPRMessageSuite, StreamDisconnectMessage) { struct cras_disconnect_stream_message msg; cras_stream_id_t stream_id = 0x10002; @@ -282,16 +320,16 @@ int stream_list_add(struct stream_list* list, struct cras_rstream** stream) { int ret; - *stream = &mock_rstream; + *stream = &dummy_rstream; stream_list_add_called++; ret = stream_list_add_return; if (ret) stream_list_add_return = -EINVAL; - mock_rstream.shm = &mock_shm; - mock_rstream.direction = config->direction; - mock_rstream.stream_id = config->stream_id; + dummy_rstream.shm = &dummy_shm; + dummy_rstream.direction = config->direction; + dummy_rstream.stream_id = config->stream_id; return ret; } diff --git a/cras/src/tests/polled_interval_checker_unittest.cc b/cras/src/tests/polled_interval_checker_unittest.cc index a4aff09c..c18fdf7e 100644 --- a/cras/src/tests/polled_interval_checker_unittest.cc +++ b/cras/src/tests/polled_interval_checker_unittest.cc @@ -70,7 +70,7 @@ TEST(PolledIntervalCheckerTest, DoesNotResetAutomatically) { struct polled_interval* interval = create_interval(); - // Initial check. + // Sanity check. EXPECT_FALSE(pic_interval_elapsed(interval)); // Increment time so the interval elapses. @@ -100,7 +100,7 @@ TEST(PolledIntervalCheckerTest, Reset) { struct polled_interval* interval = create_interval(); - // Initial check. + // Sanity check. EXPECT_FALSE(pic_interval_elapsed(interval)); // Increment time so the interval elapses. diff --git a/cras/src/tests/rstream_unittest.cc b/cras/src/tests/rstream_unittest.cc index 593c805d..77dd6adb 100644 --- a/cras/src/tests/rstream_unittest.cc +++ b/cras/src/tests/rstream_unittest.cc @@ -390,18 +390,10 @@ unsigned int buffer_share_id_offset(const struct buffer_share* mix, unsigned int id) { return 0; } -void ewma_power_init(struct ewma_power* ewma, unsigned int rate) {} -void ewma_power_calculate(struct ewma_power* ewma, - const int16_t* buf, - unsigned int channels, - unsigned int size) {} +void cras_system_state_stream_added(enum CRAS_STREAM_DIRECTION direction) {} -void cras_system_state_stream_added(enum CRAS_STREAM_DIRECTION direction, - enum CRAS_CLIENT_TYPE client_type) {} - -void cras_system_state_stream_removed(enum CRAS_STREAM_DIRECTION direction, - enum CRAS_CLIENT_TYPE client_type) {} +void cras_system_state_stream_removed(enum CRAS_STREAM_DIRECTION direction) {} int cras_server_metrics_stream_create( const struct cras_rstream_config* config) { @@ -413,13 +405,9 @@ int cras_server_metrics_stream_destroy(const struct cras_rstream* stream) { } #ifdef HAVE_WEBRTC_APM -#define FAKE_CRAS_APM_PTR reinterpret_cast<struct cras_apm*>(0x99) struct cras_apm_list* cras_apm_list_create(void* stream_ptr, uint64_t effects) { return NULL; } -struct cras_apm* cras_apm_list_get_active_apm(void* stream_ptr, void* dev_ptr) { - return FAKE_CRAS_APM_PTR; -} int cras_apm_list_destroy(struct cras_apm_list* list) { return 0; } diff --git a/cras/src/tests/system_state_unittest.cc b/cras/src/tests/system_state_unittest.cc index 0450df38..e61a43e2 100644 --- a/cras/src/tests/system_state_unittest.cc +++ b/cras/src/tests/system_state_unittest.cc @@ -38,7 +38,6 @@ static size_t cras_observer_notify_output_mute_called; static size_t cras_observer_notify_capture_mute_called; static size_t cras_observer_notify_suspend_changed_called; static size_t cras_observer_notify_num_active_streams_called; -static size_t cras_observer_notify_input_streams_with_permission_called; static struct cras_board_config fake_board_config; static void ResetStubData() { @@ -59,7 +58,6 @@ static void ResetStubData() { cras_observer_notify_capture_mute_called = 0; cras_observer_notify_suspend_changed_called = 0; cras_observer_notify_num_active_streams_called = 0; - cras_observer_notify_input_streams_with_permission_called = 0; memset(&fake_board_config, 0, sizeof(fake_board_config)); } @@ -373,11 +371,11 @@ TEST(SystemSettingsStreamCount, StreamCount) { do_sys_init(); EXPECT_EQ(0, cras_system_state_get_active_streams()); - cras_system_state_stream_added(CRAS_STREAM_OUTPUT, CRAS_CLIENT_TYPE_CHROME); + cras_system_state_stream_added(CRAS_STREAM_OUTPUT); EXPECT_EQ(1, cras_system_state_get_active_streams()); struct cras_timespec ts1; cras_system_state_get_last_stream_active_time(&ts1); - cras_system_state_stream_removed(CRAS_STREAM_OUTPUT, CRAS_CLIENT_TYPE_CHROME); + cras_system_state_stream_removed(CRAS_STREAM_OUTPUT); EXPECT_EQ(0, cras_system_state_get_active_streams()); struct cras_timespec ts2; cras_system_state_get_last_stream_active_time(&ts2); @@ -390,11 +388,9 @@ TEST(SystemSettingsStreamCount, StreamCountByDirection) { do_sys_init(); EXPECT_EQ(0, cras_system_state_get_active_streams()); - cras_system_state_stream_added(CRAS_STREAM_OUTPUT, CRAS_CLIENT_TYPE_CHROME); - cras_system_state_stream_added(CRAS_STREAM_INPUT, CRAS_CLIENT_TYPE_CHROME); - cras_system_state_stream_added(CRAS_STREAM_POST_MIX_PRE_DSP, - CRAS_CLIENT_TYPE_CHROME); - EXPECT_EQ(1, cras_observer_notify_input_streams_with_permission_called); + cras_system_state_stream_added(CRAS_STREAM_OUTPUT); + cras_system_state_stream_added(CRAS_STREAM_INPUT); + cras_system_state_stream_added(CRAS_STREAM_POST_MIX_PRE_DSP); EXPECT_EQ( 1, cras_system_state_get_active_streams_by_direction(CRAS_STREAM_OUTPUT)); EXPECT_EQ( @@ -403,11 +399,9 @@ TEST(SystemSettingsStreamCount, StreamCountByDirection) { CRAS_STREAM_POST_MIX_PRE_DSP)); EXPECT_EQ(3, cras_system_state_get_active_streams()); EXPECT_EQ(3, cras_observer_notify_num_active_streams_called); - cras_system_state_stream_removed(CRAS_STREAM_OUTPUT, CRAS_CLIENT_TYPE_CHROME); - cras_system_state_stream_removed(CRAS_STREAM_INPUT, CRAS_CLIENT_TYPE_CHROME); - cras_system_state_stream_removed(CRAS_STREAM_POST_MIX_PRE_DSP, - CRAS_CLIENT_TYPE_CHROME); - EXPECT_EQ(2, cras_observer_notify_input_streams_with_permission_called); + cras_system_state_stream_removed(CRAS_STREAM_OUTPUT); + cras_system_state_stream_removed(CRAS_STREAM_INPUT); + cras_system_state_stream_removed(CRAS_STREAM_POST_MIX_PRE_DSP); EXPECT_EQ( 0, cras_system_state_get_active_streams_by_direction(CRAS_STREAM_OUTPUT)); EXPECT_EQ( @@ -517,11 +511,6 @@ void cras_observer_notify_num_active_streams(enum CRAS_STREAM_DIRECTION dir, cras_observer_notify_num_active_streams_called++; } -void cras_observer_notify_input_streams_with_permission( - uint32_t num_input_streams[CRAS_NUM_CLIENT_TYPE]) { - cras_observer_notify_input_streams_with_permission_called++; -} - void cras_board_config_get(const char* config_path, struct cras_board_config* board_config) { *board_config = fake_board_config; |