aboutsummaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorArthur Ishiguro <arthuri@google.com>2020-05-12 13:57:21 -0700
committerArthur Ishiguro <arthuri@google.com>2020-05-14 19:31:21 -0700
commitb8153bdd5a36acd15f571571f7e8d5a12c962b5d (patch)
treed2459ba9af70464910d13cc900840039c3e8756d /apps
parent6dd234fde15e4e2ca905ea6d0148d8edb6bdd587 (diff)
downloadchre-b8153bdd5a36acd15f571571f7e8d5a12c962b5d.tar.gz
Audio concurrency test: enable audio/verify received
Bug: 156296364 Test: Run test, verify audio received Change-Id: Id0f9c7dc6c778e29c9f44067c72ed27dc61dafa3
Diffstat (limited to 'apps')
-rw-r--r--apps/test/common/chre_audio_concurrency_test/inc/chre_audio_concurrency_test_manager.h46
-rw-r--r--apps/test/common/chre_audio_concurrency_test/src/chre_audio_concurrency_test_manager.cc90
-rw-r--r--apps/test/common/shared/inc/send_message.h8
-rw-r--r--apps/test/common/shared/src/send_message.cc14
4 files changed, 155 insertions, 3 deletions
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 40500fe4..23a35eee 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
@@ -20,6 +20,7 @@
#include <chre.h>
#include <cinttypes>
+#include "chre/util/optional.h"
#include "chre/util/singleton.h"
namespace chre {
@@ -36,6 +37,8 @@ class Manager {
VERIFY_AUDIO_RESUME,
};
+ ~Manager();
+
/**
* Handles an event from CHRE. Semantics are the same as nanoappHandleEvent.
*/
@@ -43,6 +46,16 @@ class Manager {
const void *eventData);
private:
+ struct TestSession {
+ uint16_t hostEndpointId;
+ TestStep step;
+
+ TestSession(uint16_t id, TestStep step) {
+ this->hostEndpointId = id;
+ this->step = step;
+ }
+ };
+
/**
* Handles a message from the host.
*
@@ -61,6 +74,39 @@ class Manager {
* @return true if the message was handled correctly.
*/
bool handleTestCommandMessage(uint16_t hostEndpointId, TestStep step);
+
+ /**
+ * Processes data from CHRE.
+ *
+ * @param eventType The event type as defined by CHRE.
+ * @param eventData A pointer to the data.
+ */
+ void handleDataFromChre(uint16_t eventType, const void *eventData);
+
+ /**
+ * Handles a CHRE timer event.
+ */
+ void handleTimer();
+
+ /**
+ * @param data The audio data.
+ */
+ void handleAudioDataEvent(const chreAudioDataEvent *data);
+
+ // Use the first audio source available for this test.
+ static constexpr uint32_t kAudioHandle = 0;
+
+ //! The audio source to use for this test.
+ struct chreAudioSource mAudioSource;
+
+ //! The current test session.
+ Optional<TestSession> mTestSession;
+
+ //! The handle of the timer to check timeout.
+ uint32_t mTimerHandle = CHRE_TIMER_INVALID;
+
+ //! True if CHRE audio is enabled for this nanoapp.
+ bool mAudioEnabled = false;
};
// The audio concurrency test manager singleton.
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 b13eb336..18afc2a0 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
@@ -19,6 +19,7 @@
#include <pb_decode.h>
#include "chre/util/nanoapp/log.h"
+#include "chre/util/time.h"
#include "chre_audio_concurrency_test.nanopb.h"
#include "send_message.h"
@@ -26,6 +27,7 @@
namespace chre {
+using test_shared::sendEmptyMessageToHost;
using test_shared::sendTestResultToHost;
namespace audio_concurrency_test {
@@ -61,21 +63,49 @@ bool getTestStep(const chre_audio_concurrency_test_TestCommand &command,
} // anonymous namespace
+Manager::~Manager() {
+ if (mAudioEnabled) {
+ chreAudioConfigureSource(kAudioHandle, false /* enable */,
+ 0 /* bufferDuration */, 0 /* deliveryInterval */);
+ }
+}
+
bool Manager::handleTestCommandMessage(uint16_t hostEndpointId, TestStep step) {
bool success = true;
// Treat as success if CHRE audio is unsupported
- if (!isTestSupported()) {
+ // TODO: Use all available audio sources
+ if (!isTestSupported() || !chreAudioGetSource(kAudioHandle, &mAudioSource)) {
sendTestResultToHost(hostEndpointId, kTestResultMessageType,
true /* success */);
} else {
+ success = false;
if (step == TestStep::ENABLE_AUDIO) {
- // TODO: Enable audio
+ if (!chreAudioConfigureSource(kAudioHandle, true /* enable */,
+ mAudioSource.minBufferDuration,
+ mAudioSource.minBufferDuration)) {
+ LOGE("Failed to configure audio source");
+ } else {
+ mAudioEnabled = true;
+ // Start a timer to ensure we receive the first audio data event
+ // quickly. Since it may take some time to load the sound model, choose
+ // a reasonably long timeout.
+ mTimerHandle = chreTimerSet(10 * kOneSecondInNanoseconds,
+ nullptr /* cookie */, true /* oneShot */);
+ if (mTimerHandle == CHRE_TIMER_INVALID) {
+ LOGE("Failed to set audio enabled timer");
+ } else {
+ success = true;
+ }
+ }
} else if (step == TestStep::VERIFY_AUDIO_RESUME) {
// TODO: Verify audio resumes
}
- // TODO: Save test state
+ if (success) {
+ mTestSession = TestSession(hostEndpointId, step);
+ LOGI("Starting test step %" PRIu8, mTestSession->step);
+ }
}
return success;
@@ -112,12 +142,66 @@ void Manager::handleMessageFromHost(uint32_t senderInstanceId,
}
}
+void Manager::handleDataFromChre(uint16_t eventType, const void *eventData) {
+ switch (eventType) {
+ case CHRE_EVENT_AUDIO_DATA:
+ handleAudioDataEvent(static_cast<const chreAudioDataEvent *>(eventData));
+ break;
+
+ case CHRE_EVENT_TIMER:
+ handleTimer();
+ break;
+
+ case CHRE_EVENT_AUDIO_SAMPLING_CHANGE:
+ /* ignore */
+ break;
+
+ default:
+ LOGE("Unexpected event type %" PRIu16, eventType);
+ }
+}
+
+void Manager::handleTimer() {
+ // TODO: Timeout failure
+}
+
+void Manager::handleAudioDataEvent(const chreAudioDataEvent *data) {
+ if (mTestSession.has_value()) {
+ switch (mTestSession->step) {
+ case TestStep::ENABLE_AUDIO: {
+ if (mTimerHandle != CHRE_TIMER_INVALID) {
+ chreTimerCancel(mTimerHandle);
+ mTimerHandle = CHRE_TIMER_INVALID;
+ }
+ 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: {
+ // TODO:
+ }
+
+ default:
+ LOGE("Unexpected test step %" PRIu8, mTestSession->step);
+ break;
+ }
+ }
+}
+
void Manager::handleEvent(uint32_t senderInstanceId, uint16_t eventType,
const void *eventData) {
if (eventType == CHRE_EVENT_MESSAGE_FROM_HOST) {
handleMessageFromHost(
senderInstanceId,
static_cast<const chreMessageFromHostData *>(eventData));
+ } else if (senderInstanceId == CHRE_INSTANCE_ID) {
+ handleDataFromChre(eventType, eventData);
} else {
LOGW("Got unknown event type from senderInstanceId %" PRIu32
" and with eventType %" PRIu16,
diff --git a/apps/test/common/shared/inc/send_message.h b/apps/test/common/shared/inc/send_message.h
index e296f83e..2847c8fc 100644
--- a/apps/test/common/shared/inc/send_message.h
+++ b/apps/test/common/shared/inc/send_message.h
@@ -34,6 +34,14 @@ namespace test_shared {
void sendTestResultToHost(uint16_t hostEndpointId, uint32_t messageType,
bool success);
+/**
+ * Sends a message to the host with an empty payload.
+ *
+ * @param hostEndpointId The endpoint Id of the host to send the message to.
+ * @param messageType The message type.
+ */
+void sendEmptyMessageToHost(uint16_t hostEndpointId, uint32_t messageType);
+
} // namespace test_shared
} // namespace chre
diff --git a/apps/test/common/shared/src/send_message.cc b/apps/test/common/shared/src/send_message.cc
index 62101228..fd2e8f9e 100644
--- a/apps/test/common/shared/src/send_message.cc
+++ b/apps/test/common/shared/src/send_message.cc
@@ -68,6 +68,20 @@ void sendTestResultToHost(uint16_t hostEndpointId, uint32_t messageType,
}
}
+void sendEmptyMessageToHost(uint16_t hostEndpointId, uint32_t messageType) {
+ // Unspecified endpoint is not allowed in chreSendMessageToHostEndpoint.
+ if (hostEndpointId == CHRE_HOST_ENDPOINT_UNSPECIFIED) {
+ hostEndpointId = CHRE_HOST_ENDPOINT_BROADCAST;
+ LOGE("Unspecified endpoint ID is not allowed");
+ // TODO: Send failure message to host
+ return;
+ }
+
+ chreSendMessageToHostEndpoint(nullptr /* message */, 0 /* messageSize */,
+ messageType, hostEndpointId,
+ nullptr /* freeCallback */);
+}
+
} // namespace test_shared
} // namespace chre