summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSeungbae Shin <seungbae.shin@samsung.com>2018-08-22 21:30:28 +0900
committerSeungbae Shin <seungbae.shin@samsung.com>2018-08-23 20:13:52 +0900
commitcf673bc36ac779f1628c52a9738e175238b29486 (patch)
treea4f972c9790743d23368096ed1c83f7ebafbfe22
parent9598891416cf67c552607b0c65d2a78da78426bf (diff)
downloadmm-hal-interface-cf673bc36ac779f1628c52a9738e175238b29486.tar.gz
mm-hal-interface-cf673bc36ac779f1628c52a9738e175238b29486.tar.bz2
mm-hal-interface-cf673bc36ac779f1628c52a9738e175238b29486.zip
[audio] add testcases with code revision
[Version] 0.0.14 [Profile] Common [Issue Type] Add/Revision [Dependency module] N/A Change-Id: I28b8c5623ce5fde89e19da28db7b337d7343f95c
-rwxr-xr-xpackaging/mm-hal-interface.spec2
-rw-r--r--src/audio/audio_hal_interface.c2
-rw-r--r--testcase/audio/audio_haltests.cpp322
-rw-r--r--testcase/audio/dtmf_16le_44100_2ch.rawbin882000 -> 0 bytes
-rw-r--r--testcase/audio/test_16le_44100_2ch.rawbin0 -> 529200 bytes
5 files changed, 250 insertions, 76 deletions
diff --git a/packaging/mm-hal-interface.spec b/packaging/mm-hal-interface.spec
index beef427..b88c898 100755
--- a/packaging/mm-hal-interface.spec
+++ b/packaging/mm-hal-interface.spec
@@ -1,6 +1,6 @@
Name: mm-hal-interface
Summary: Multimedia HAL Interface
-Version: 0.0.13
+Version: 0.0.14
Release: 0
Group: Multimedia/Development
License: Apache-2.0
diff --git a/src/audio/audio_hal_interface.c b/src/audio/audio_hal_interface.c
index f28ed65..816cf29 100644
--- a/src/audio/audio_hal_interface.c
+++ b/src/audio/audio_hal_interface.c
@@ -360,6 +360,8 @@ int32_t audio_hal_interface_notify_stream_connection_changed(audio_hal_interface
assert(h);
assert(h->ah_handle);
+ memset(&hal_info, 0, sizeof(audio_stream_info_t));
+
if (info) {
hal_info.role = info->role;
hal_info.direction = info->direction;
diff --git a/testcase/audio/audio_haltests.cpp b/testcase/audio/audio_haltests.cpp
index 49fb907..3c3d6f8 100644
--- a/testcase/audio/audio_haltests.cpp
+++ b/testcase/audio/audio_haltests.cpp
@@ -19,6 +19,7 @@
#include <string.h>
#include <unistd.h>
#include <iostream>
+#include <fstream>
#include <array>
#include <sys/types.h>
@@ -32,6 +33,9 @@
using namespace std;
+#define USE_IFSTREAM
+#define DISABLE_DEBUG_LOG
+
typedef enum audio_sample_format {
AUDIO_SAMPLE_U8,
AUDIO_SAMPLE_ALAW,
@@ -56,7 +60,6 @@ typedef struct {
uint8_t channels;
} audio_pcm_sample_spec_t;
-
/*
* TestSuite Class
*/
@@ -68,22 +71,40 @@ class AudioHalTest : public testing::Test
protected:
void SetRouteToSpeaker();
- int32_t WritePcmFromFile(pcm_handle pcm_h, audio_pcm_sample_spec_t *spec);
+ int32_t WritePcmFromFile(pcm_handle pcm_h);
uint32_t BytesToFrames(uint32_t bytes, audio_pcm_sample_spec_t *spec);
+ uint32_t BytesToFrames(uint32_t bytes);
uint32_t FramesToBytes(uint32_t frames, audio_pcm_sample_spec_t *spec);
+ uint32_t FramesToBytes(uint32_t frames);
+ uint32_t GetDefaultFrames();
+
static void HalMessageCallback(const char *name, int value, void *user_data);
audio_hal_interface *m_h;
+ audio_pcm_sample_spec_t m_spec;
+
+ // Todo : following value may vary depends on targets
+ const int default_frames = 6400;
+ const int default_periods = 5;
+
+ // ToDo : following should be changed in runtime
const string default_card = "sprdphone";
const string default_device = "0";
- private:
+ // ToDo : following types may need to be fixed.
+ const array<string, 8> vol_types = { "system", "notification", "alarm", "ringtone",
+ "media", "call", "voip", "voice" };
+
};
void AudioHalTest::SetUp()
{
m_h = nullptr;
+ m_spec.format = AUDIO_SAMPLE_S16LE;
+ m_spec.rate = 44100;
+ m_spec.channels = 2;
+
int32_t ret = audio_hal_interface_init(&m_h);
if (ret != AUDIO_HAL_SUCCESS)
cout << "audio hal init failed : " << ret << endl;
@@ -120,70 +141,113 @@ void AudioHalTest::SetRouteToSpeaker()
info.num_of_devices = num_of_devices;
int32_t ret = audio_hal_interface_update_route(m_h, &info);
-
cout << "update route : " << ret << endl;
free(info.device_infos);
}
-int32_t AudioHalTest::WritePcmFromFile(pcm_handle pcm_h, audio_pcm_sample_spec_t *spec)
+int32_t AudioHalTest::WritePcmFromFile(pcm_handle pcm_h)
{
int32_t ret = AUDIO_HAL_SUCCESS;
+ uint32_t avail_frames = 0;
+ int bytes_read;
char buffer[65536];
- const char res_path[] = "/usr/share/testcase/res/audio/dtmf_16le_44100_2ch.raw";
-
+ const char res_path[] = "/usr/share/testcase/res/audio/test_16le_44100_2ch.raw";
+#ifdef USE_IFSTREAM
+ ifstream fs;
+ fs.open(res_path, fstream::in | fstream::binary);
+ if (fs.fail()) {
+ cout << "Failed to open : " << res_path << endl;
+ return AUDIO_HAL_ERROR;
+ }
+#else
int fd = open(res_path, O_RDONLY);
- cout << res_path << ", fd opened : " << fd << endl;
-
- cout << "start to play dtmf sounds for 5 sec. " << endl;
+ if (fd == -1) {
+ cout << "Failed to open : " << res_path << ", " << errno << endl;
+ return AUDIO_HAL_ERROR;
+ }
+#endif
- while (fd != -1) {
+ cout << "start to play dtmf+noise sounds ( " << res_path << " ) for 5 sec. " << endl;
- uint32_t avail_frames = 0;
+ while (1) {
ret = audio_hal_interface_pcm_available(m_h, pcm_h, &avail_frames);
+ if (ret == AUDIO_HAL_ERROR)
+ break;
if (avail_frames == 0) {
usleep(20000); // 20ms
continue;
}
- int bytes_read = read(fd, buffer, FramesToBytes(avail_frames, spec));
- //cout << "avail frames : " << avail_frames << ", read_n : " << bytes_read << endl;
+#ifdef USE_IFSTREAM
+ fs.read(buffer, FramesToBytes(avail_frames));
+ bytes_read = fs.gcount();
+#else
+ bytes_read = read(fd, buffer, FramesToBytes(avail_frames));
+#endif
+
+ cout << "avail frames : " << avail_frames << ", read_n : " << bytes_read << endl;
- ret = audio_hal_interface_pcm_write(m_h, pcm_h, buffer, BytesToFrames(bytes_read, spec));
+ ret = audio_hal_interface_pcm_write(m_h, pcm_h, buffer, BytesToFrames(bytes_read));
if (ret == AUDIO_HAL_ERROR)
break;
- if (bytes_read < static_cast<int>(FramesToBytes(avail_frames, spec))) {
+#ifdef USE_IFSTREAM
+ if (!fs.good()) {
+ if (fs.eof())
+ cout << "EOS!!!" << endl;
+ else if (fs.fail() || fs.bad())
+ cout << "Error..." << endl;
+ break;
+ }
+#else
+ if (bytes_read < static_cast<int>(FramesToBytes(avail_frames))) {
cout << "EOS!!!" << endl;
break;
}
+#endif
}
- cout << "Done!!!" << endl;
+#ifdef USE_IFSTREAM
+ fs.close();
+#else
+ close(fd);
+#endif
- if (fd != -1)
- close(fd);
+ cout << "Done!!!" << endl;
return ret;
}
uint32_t AudioHalTest::BytesToFrames(uint32_t bytes, audio_pcm_sample_spec_t *spec)
{
- if (spec->format == AUDIO_SAMPLE_S16LE)
- return bytes / spec->channels / 2;
- else
- return 0; // not supported yet.
+ // ToDo : support various sample format
+ return (spec->format == AUDIO_SAMPLE_S16LE) ? bytes / spec->channels / 2 : 0;
+}
+uint32_t AudioHalTest::BytesToFrames(uint32_t bytes)
+{
+ // ToDo : support various sample format
+ return (m_spec.format == AUDIO_SAMPLE_S16LE) ? bytes / m_spec.channels / 2 : 0;
}
uint32_t AudioHalTest::FramesToBytes(uint32_t frames, audio_pcm_sample_spec_t *spec)
{
- if (spec->format == AUDIO_SAMPLE_S16LE)
- return frames * spec->channels * 2;
- else
- return 0; // not supported yet.
+ // ToDo : support various sample format
+ return (spec->format == AUDIO_SAMPLE_S16LE) ? frames * spec->channels * 2 : 0;
+}
+
+uint32_t AudioHalTest::FramesToBytes(uint32_t frames)
+{
+ // ToDo : support various sample format
+ return (m_spec.format == AUDIO_SAMPLE_S16LE) ? frames * m_spec.channels * 2 : 0;
+}
+
+uint32_t AudioHalTest::GetDefaultFrames()
+{
+ return BytesToFrames(default_frames);
}
void AudioHalTest::HalMessageCallback(const char *name, int value, void *user_data)
@@ -276,8 +340,6 @@ TEST(AudioHalPreTest, DeinitP)
TEST_F(AudioHalTest, GetVolumeLevelMaxP)
{
uint32_t level_max;
- const array<string, 8> vol_types = { "system", "notification", "alarm", "ringtone",
- "media", "call", "voip", "voice" };
for (const auto& i : vol_types) {
int32_t ret = audio_hal_interface_get_volume_level_max(m_h, i.c_str(), DIRECTION_OUT, &level_max);
@@ -321,11 +383,10 @@ TEST_F(AudioHalTest, GetVolumeLevelMaxN)
TEST_F(AudioHalTest, GetVolumeLevelP)
{
uint32_t level;
- const array<string, 8> vol_types = { "system", "notification", "alarm", "ringtone",
- "media", "call", "voip", "voice" };
+ int32_t ret;
for (const auto& i : vol_types) {
- int32_t ret = audio_hal_interface_get_volume_level(m_h, i.c_str(), DIRECTION_OUT, &level);
+ ret = audio_hal_interface_get_volume_level(m_h, i.c_str(), DIRECTION_OUT, &level);
cout << i << " : " << level << endl;
EXPECT_EQ(ret, AUDIO_HAL_SUCCESS);
}
@@ -410,11 +471,19 @@ TEST_F(AudioHalTest, SetVolumeLevelN)
TEST_F(AudioHalTest, GetVolumeValueP)
{
double value;
+ uint32_t level_max;
+ int32_t ret;
- int32_t ret = audio_hal_interface_get_volume_value(m_h, "media", nullptr, DIRECTION_OUT, 15, &value);
- EXPECT_EQ(ret, AUDIO_HAL_SUCCESS);
+ for (const auto& i : vol_types) {
+ ret = audio_hal_interface_get_volume_level_max(m_h, i.c_str(), DIRECTION_OUT, &level_max);
+ EXPECT_EQ(ret, AUDIO_HAL_SUCCESS);
- cout << "media vol value : " << value << endl;
+ for (uint32_t l = 0; l < level_max ; l++) {
+ ret = audio_hal_interface_get_volume_value(m_h, i.c_str(), nullptr, DIRECTION_OUT, l, &value);
+ EXPECT_EQ(ret, AUDIO_HAL_SUCCESS);
+ cout << i << ", level " << l << ", value : " << value << endl;
+ }
+ }
}
/**
@@ -432,7 +501,7 @@ TEST_F(AudioHalTest, GetVolumeValueP)
*/
TEST_F(AudioHalTest, GetVolumeValueN)
{
- int32_t ret = audio_hal_interface_get_volume_value(m_h, "media", nullptr, DIRECTION_OUT, 15, nullptr);
+ int32_t ret = audio_hal_interface_get_volume_value(m_h, "media", nullptr, DIRECTION_OUT, 0, nullptr);
EXPECT_EQ(ret, AUDIO_HAL_ERROR);
}
@@ -451,12 +520,14 @@ TEST_F(AudioHalTest, GetVolumeValueN)
*/
TEST_F(AudioHalTest, GetVolumeMuteP)
{
- uint32_t mute;
+ uint32_t mute = 0;
+ int32_t ret;
- int32_t ret = audio_hal_interface_get_volume_mute(m_h, "media", DIRECTION_OUT, &mute);
- EXPECT_EQ(ret, AUDIO_HAL_SUCCESS);
-
- cout << "mute : " << mute << endl;
+ for (const auto& i : vol_types) {
+ ret = audio_hal_interface_get_volume_mute(m_h, i.c_str(), DIRECTION_OUT, &mute);
+ EXPECT_EQ(ret, AUDIO_HAL_SUCCESS);
+ cout << i << " mute : " << mute << endl;
+ }
}
/**
@@ -729,18 +800,13 @@ TEST_F(AudioHalTest, PcmGetFdP)
{
pcm_handle pcm_h = nullptr;
- audio_pcm_sample_spec_t sample_spec;
- sample_spec.format = AUDIO_SAMPLE_S16LE;
- sample_spec.rate = 44100;
- sample_spec.channels = 2;
-
SetRouteToSpeaker();
- int32_t ret = audio_hal_interface_pcm_open(m_h, default_card.c_str(), default_device.c_str(), DIRECTION_OUT, &sample_spec,
- BytesToFrames(6400, &sample_spec), 5, &pcm_h);
+ int32_t ret = audio_hal_interface_pcm_open(m_h, default_card.c_str(), default_device.c_str(),
+ DIRECTION_OUT, &m_spec, GetDefaultFrames(), default_periods, &pcm_h);
ASSERT_EQ(ret, AUDIO_HAL_SUCCESS);
- int pcm_fd = 0;
+ int pcm_fd = -1;
ret = audio_hal_interface_pcm_get_fd(m_h, pcm_h, &pcm_fd);
EXPECT_EQ(ret, AUDIO_HAL_SUCCESS);
cout << "pcm fd : " << pcm_fd << endl;
@@ -765,22 +831,17 @@ TEST_F(AudioHalTest, PcmGetFdP)
TEST_F(AudioHalTest, PcmGetFdN)
{
// check for pcm handle
- int pcm_fd = 0;
+ int pcm_fd = -1;
int32_t ret = audio_hal_interface_pcm_get_fd(m_h, nullptr, &pcm_fd);
EXPECT_EQ(ret, AUDIO_HAL_ERROR);
// check for fd
pcm_handle pcm_h = nullptr;
- audio_pcm_sample_spec_t sample_spec;
- sample_spec.format = AUDIO_SAMPLE_S16LE;
- sample_spec.rate = 44100;
- sample_spec.channels = 2;
-
SetRouteToSpeaker();
- ret = audio_hal_interface_pcm_open(m_h, default_card.c_str(), default_device.c_str(), DIRECTION_OUT, &sample_spec,
- BytesToFrames(6400, &sample_spec), 5, &pcm_h);
+ ret = audio_hal_interface_pcm_open(m_h, default_card.c_str(), default_device.c_str(),
+ DIRECTION_OUT, &m_spec, GetDefaultFrames(), default_periods, &pcm_h);
ASSERT_EQ(ret, AUDIO_HAL_SUCCESS);
ret = audio_hal_interface_pcm_get_fd(m_h, pcm_h, nullptr);
@@ -807,21 +868,16 @@ TEST_F(AudioHalTest, PcmOpenWriteCloseP)
{
pcm_handle pcm_h = nullptr;
- audio_pcm_sample_spec_t sample_spec;
- sample_spec.format = AUDIO_SAMPLE_S16LE;
- sample_spec.rate = 44100;
- sample_spec.channels = 2;
-
SetRouteToSpeaker();
- int32_t ret = audio_hal_interface_pcm_open(m_h, default_card.c_str(), default_device.c_str(), DIRECTION_OUT, &sample_spec,
- BytesToFrames(6400, &sample_spec), 5, &pcm_h);
+ int32_t ret = audio_hal_interface_pcm_open(m_h, default_card.c_str(), default_device.c_str(),
+ DIRECTION_OUT, &m_spec, GetDefaultFrames(), default_periods, &pcm_h);
ASSERT_EQ(ret, AUDIO_HAL_SUCCESS);
ret = audio_hal_interface_pcm_start(m_h, pcm_h);
EXPECT_EQ(ret, AUDIO_HAL_SUCCESS);
- ret = WritePcmFromFile(pcm_h, &sample_spec);
+ ret = WritePcmFromFile(pcm_h);
EXPECT_EQ(ret, AUDIO_HAL_SUCCESS);
ret = audio_hal_interface_pcm_stop(m_h, pcm_h);
@@ -850,20 +906,136 @@ TEST_F(AudioHalTest, PcmRecoverN)
EXPECT_EQ(ret, AUDIO_HAL_ERROR);
}
-/* // ToDo :
-int32_t audio_hal_interface_pcm_read(audio_hal_interface *h, pcm_handle pcm_h, void *buffer, uint32_t frames);
-*/
+/**
+ * @testcase PcmSetParamP
+ * @sizen_tizen 4.0
+ * @author SR(seungbae.shin)
+ * @reviewer SR(sc11.lee)
+ * @type auto
+ * @description Positive, set audio parameters
+ * @apicovered audio_pcm_pcm_set_param, audio_pcm_open, audio_pcm_close
+ * @passcase XXX
+ * @failcase YYY
+ * @precondition None
+ * @postcondition None
+ */
+TEST_F(AudioHalTest, PcmSetParamP)
+{
+ pcm_handle pcm_h = nullptr;
+
+ SetRouteToSpeaker();
-/* This is not used */
-#if 0
-int32_t audio_hal_interface_pcm_get_params(audio_hal_interface *h, pcm_handle pcm_h, uint32_t direction, void **sample_spec,
- uint32_t *period_size, uint32_t *periods);
-int32_t audio_hal_interface_pcm_set_params(audio_hal_interface *h, pcm_handle pcm_h, uint32_t direction, void *sample_spec,
- uint32_t period_size, uint32_t periods);
-#endif
+ int32_t ret = audio_hal_interface_pcm_open(m_h, default_card.c_str(), default_device.c_str(),
+ DIRECTION_OUT, &m_spec, GetDefaultFrames(), default_periods, &pcm_h);
+ ASSERT_EQ(ret, AUDIO_HAL_SUCCESS);
+
+ ret = audio_hal_interface_pcm_set_params(m_h, pcm_h, DIRECTION_OUT, &m_spec,
+ GetDefaultFrames(), default_periods);
+ EXPECT_EQ(ret, AUDIO_HAL_SUCCESS);
+
+ ret = audio_hal_interface_pcm_close(m_h, pcm_h);
+ EXPECT_EQ(ret, AUDIO_HAL_SUCCESS);
+}
+
+/**
+ * @testcase PcmSetParamN
+ * @sizen_tizen 4.0
+ * @author SR(seungbae.shin)
+ * @reviewer SR(sc11.lee)
+ * @type auto
+ * @description Negative, set audio parameters
+ * @apicovered audio_pcm_pcm_set_param, audio_pcm_open, audio_pcm_close
+ * @passcase XXX
+ * @failcase YYY
+ * @precondition None
+ * @postcondition None
+ */
+TEST_F(AudioHalTest, PcmSetParamN)
+{
+ pcm_handle pcm_h = nullptr;
+
+ SetRouteToSpeaker();
+
+ int32_t ret = audio_hal_interface_pcm_open(m_h, default_card.c_str(), default_device.c_str(),
+ DIRECTION_OUT, &m_spec, GetDefaultFrames(), default_periods, &pcm_h);
+ ASSERT_EQ(ret, AUDIO_HAL_SUCCESS);
+
+ ret = audio_hal_interface_pcm_set_params(m_h, nullptr, DIRECTION_OUT, &m_spec, GetDefaultFrames(), default_periods);
+ EXPECT_EQ(ret, AUDIO_HAL_ERROR);
+
+ ret = audio_hal_interface_pcm_close(m_h, pcm_h);
+ EXPECT_EQ(ret, AUDIO_HAL_SUCCESS);
+}
+
+/**
+ * @testcase PcmGetParamP
+ * @sizen_tizen 4.0
+ * @author SR(seungbae.shin)
+ * @reviewer SR(sc11.lee)
+ * @type auto
+ * @description Positive, get audio parameters
+ * @apicovered audio_pcm_pcm_get_param, audio_pcm_open, audio_pcm_close
+ * @passcase XXX
+ * @failcase YYY
+ * @precondition None
+ * @postcondition None
+ */
+TEST_F(AudioHalTest, PcmGetParamP)
+{
+ pcm_handle pcm_h = nullptr;
+
+ // Precondition
+ SetRouteToSpeaker();
+ int32_t ret = audio_hal_interface_pcm_open(m_h, default_card.c_str(), default_device.c_str(),
+ DIRECTION_OUT, &m_spec, GetDefaultFrames(), default_periods, &pcm_h);
+ ASSERT_EQ(ret, AUDIO_HAL_SUCCESS);
+
+ // Test Body
+ audio_pcm_sample_spec_t local_spec;
+ audio_pcm_sample_spec_t * p_spec = &local_spec;
+ uint32_t period_size = 0;
+ uint32_t periods = 0;
+
+ memset(p_spec, 0, sizeof(audio_pcm_sample_spec_t));
+ ret = audio_hal_interface_pcm_get_params(m_h, pcm_h, DIRECTION_OUT, (void**)&p_spec, &period_size, &periods);
+ EXPECT_EQ(ret, AUDIO_HAL_SUCCESS);
+
+ cout << p_spec->format << "," <<
+ p_spec->rate << "," <<
+ static_cast<int>(p_spec->channels) << "," <<
+ period_size << "," <<
+ periods << endl;
+
+ // Cleanup
+ ret = audio_hal_interface_pcm_close(m_h, pcm_h);
+ EXPECT_EQ(ret, AUDIO_HAL_SUCCESS);
+}
+
+/**
+ * @testcase PcmGetParamN
+ * @sizen_tizen 4.0
+ * @author SR(seungbae.shin)
+ * @reviewer SR(sc11.lee)
+ * @type auto
+ * @description Negative, get audio parameters
+ * @apicovered audio_pcm_pcm_get_param
+ * @passcase XXX
+ * @failcase YYY
+ * @precondition None
+ * @postcondition None
+ */
+TEST_F(AudioHalTest, PcmGetParamN)
+{
+ int32_t ret = audio_hal_interface_pcm_get_params(m_h, nullptr, DIRECTION_OUT, nullptr, nullptr, nullptr);
+ EXPECT_EQ(ret, AUDIO_HAL_ERROR);
+}
int main(int argc, char **argv)
{
+#ifdef DISABLE_DEBUG_LOG
+ cout.rdbuf(NULL);
+#endif
+
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
diff --git a/testcase/audio/dtmf_16le_44100_2ch.raw b/testcase/audio/dtmf_16le_44100_2ch.raw
deleted file mode 100644
index 99a20f7..0000000
--- a/testcase/audio/dtmf_16le_44100_2ch.raw
+++ /dev/null
Binary files differ
diff --git a/testcase/audio/test_16le_44100_2ch.raw b/testcase/audio/test_16le_44100_2ch.raw
new file mode 100644
index 0000000..cbc25eb
--- /dev/null
+++ b/testcase/audio/test_16le_44100_2ch.raw
Binary files differ