diff options
author | Arthur Ishiguro <arthuri@google.com> | 2020-05-19 13:58:12 -0700 |
---|---|---|
committer | Arthur Ishiguro <arthuri@google.com> | 2020-05-19 14:09:19 -0700 |
commit | a3f911cdb4c9b79ce63286212154ad904f5c08b2 (patch) | |
tree | bcee4f6cb96e4958919117cca5c739139c41f28d /apps | |
parent | 69e8f80e7de7cec977b7c6cebe1e2019d7361d18 (diff) | |
download | chre-a3f911cdb4c9b79ce63286212154ad904f5c08b2.tar.gz |
Audio concurrency test: add sanity check on data
Bug: 156296364
Test: Run test and verify pass
Change-Id: I7d0d7cf62b1c3b2cc8465a2fecf2a5cf7532d699
Diffstat (limited to 'apps')
3 files changed, 66 insertions, 28 deletions
diff --git a/apps/test/common/chre_audio_concurrency_test/Makefile b/apps/test/common/chre_audio_concurrency_test/Makefile index 5cc39696..a158b561 100644 --- a/apps/test/common/chre_audio_concurrency_test/Makefile +++ b/apps/test/common/chre_audio_concurrency_test/Makefile @@ -18,7 +18,7 @@ endif NANOAPP_NAME = chre_audio_concurrency_test NANOAPP_ID = 0x476f6f6754000004 NANOAPP_NAME_STRING = \"Chre\ Audio\ Concurrency\ Test\" -NANOAPP_VERSION = 0x00000001 +NANOAPP_VERSION = 0x00000002 NANOAPP_PATH = $(CHRE_PREFIX)/apps/test/common/chre_audio_concurrency_test TEST_SHARED_PATH = $(CHRE_PREFIX)/apps/test/common/shared diff --git a/apps/test/common/chre_audio_concurrency_test/inc/chre_audio_concurrency_test_manager.h b/apps/test/common/chre_audio_concurrency_test/inc/chre_audio_concurrency_test_manager.h index df8f825e..98a49c11 100644 --- a/apps/test/common/chre_audio_concurrency_test/inc/chre_audio_concurrency_test_manager.h +++ b/apps/test/common/chre_audio_concurrency_test/inc/chre_audio_concurrency_test_manager.h @@ -93,7 +93,7 @@ class Manager { * * @return True if the timer was set successfully. */ - bool setTimeoutTimer(size_t durationSeconds); + bool setTimeoutTimer(uint32_t durationSeconds); /** * Cancels the timeout timer, if pending. @@ -101,6 +101,15 @@ class Manager { void cancelTimeoutTimer(); /** + * Performs a check on the audio data. + * + * @param data The audio data. + * + * @return true if the audio data is valid. + */ + bool validateAudioDataEvent(const chreAudioDataEvent *data); + + /** * @param data The audio data. */ void handleAudioDataEvent(const chreAudioDataEvent *data); diff --git a/apps/test/common/chre_audio_concurrency_test/src/chre_audio_concurrency_test_manager.cc b/apps/test/common/chre_audio_concurrency_test/src/chre_audio_concurrency_test_manager.cc index 13c37b3f..119a007c 100644 --- a/apps/test/common/chre_audio_concurrency_test/src/chre_audio_concurrency_test_manager.cc +++ b/apps/test/common/chre_audio_concurrency_test/src/chre_audio_concurrency_test_manager.cc @@ -165,7 +165,7 @@ void Manager::handleTimer() { } } -bool Manager::setTimeoutTimer(size_t durationSeconds) { +bool Manager::setTimeoutTimer(uint32_t durationSeconds) { mTimerHandle = chreTimerSet(durationSeconds * kOneSecondInNanoseconds, nullptr /* cookie */, true /* oneShot */); if (mTimerHandle == CHRE_TIMER_INVALID) { @@ -182,34 +182,63 @@ void Manager::cancelTimeoutTimer() { } } +bool Manager::validateAudioDataEvent(const chreAudioDataEvent *data) { + bool ulaw8 = false; + if (data->format == CHRE_AUDIO_DATA_FORMAT_8_BIT_U_LAW) { + ulaw8 = true; + } else if (data->format != CHRE_AUDIO_DATA_FORMAT_16_BIT_SIGNED_PCM) { + LOGE("Invalid format %" PRIu8, data->format); + return false; + } + + // Verify that the audio data is not all zeroes + uint32_t numZeroes = 0; + for (uint32_t i = 0; i < data->sampleCount; i++) { + numZeroes += + ulaw8 ? (data->samplesULaw8[i] == 0) : (data->samplesS16[i] == 0); + } + bool dataValid = numZeroes != data->sampleCount; + + // Verify that timestamp increases + static uint64_t lastTimestamp = 0; + bool timestampValid = data->timestamp > lastTimestamp; + lastTimestamp = data->timestamp; + + return dataValid && timestampValid; +} + void Manager::handleAudioDataEvent(const chreAudioDataEvent *data) { if (mTestSession.has_value()) { - switch (mTestSession->step) { - case TestStep::ENABLE_AUDIO: { - cancelTimeoutTimer(); - sendEmptyMessageToHost( - mTestSession->hostEndpointId, - chre_audio_concurrency_test_MessageType_TEST_AUDIO_ENABLED); - - // Reset the test session to avoid sending multiple TEST_AUDIO_ENABLED - // messages to the host, while we wait for the next step. - mTestSession.reset(); - - // TODO: Perform sanity check on audio data - break; + if (!validateAudioDataEvent(data)) { + sendTestResultToHost(mTestSession->hostEndpointId, kTestResultMessageType, + false /* success */); + mTestSession.reset(); + } else { + switch (mTestSession->step) { + case TestStep::ENABLE_AUDIO: { + cancelTimeoutTimer(); + sendEmptyMessageToHost( + mTestSession->hostEndpointId, + chre_audio_concurrency_test_MessageType_TEST_AUDIO_ENABLED); + + // Reset the test session to avoid sending multiple TEST_AUDIO_ENABLED + // messages to the host, while we wait for the next step. + mTestSession.reset(); + break; + } + + case TestStep::VERIFY_AUDIO_RESUME: { + cancelTimeoutTimer(); + sendTestResultToHost(mTestSession->hostEndpointId, + kTestResultMessageType, true /* success */); + mTestSession.reset(); + break; + } + + default: + LOGE("Unexpected test step %" PRIu8, mTestSession->step); + break; } - - case TestStep::VERIFY_AUDIO_RESUME: { - cancelTimeoutTimer(); - sendTestResultToHost(mTestSession->hostEndpointId, - kTestResultMessageType, true /* success */); - mTestSession.reset(); - break; - } - - default: - LOGE("Unexpected test step %" PRIu8, mTestSession->step); - break; } } } |