Merge changes I509f56cb,I3fd2af29 into pi-dev
* changes:
CHQTS: Convert nanoapps to use shared time_util.h constants
CHQTS: Changes accel request interval in busy startup test
diff --git a/apps/chqts/src/busy_startup/busy_startup.cc b/apps/chqts/src/busy_startup/busy_startup.cc
index 91e4b69..8759a93 100644
--- a/apps/chqts/src/busy_startup/busy_startup.cc
+++ b/apps/chqts/src/busy_startup/busy_startup.cc
@@ -47,13 +47,13 @@
#include <chre.h>
#include <shared/send_message.h>
+#include <shared/time_util.h>
using nanoapp_testing::MessageType;
using nanoapp_testing::sendMessageToHost;
using nanoapp_testing::sendFatalFailureToHost;
using nanoapp_testing::sendSuccessToHost;
-
static bool gInMethod = false;
static uint32_t gInstanceId;
static uint32_t gTimerId;
@@ -198,9 +198,12 @@
chreLog(CHRE_LOG_ERROR, "Failed sensorFindDefault in start");
return false;
}
+
+ // Configure accel request at 50 Hz (reasonable rate, e.g. for AR)
+ // TODO: Add a way to find the range of possible sample rates
if (!chreSensorConfigure(gSensorHandle,
CHRE_SENSOR_CONFIGURE_MODE_CONTINUOUS,
- CHRE_SENSOR_INTERVAL_DEFAULT,
+ 20 * nanoapp_testing::kOneMillisecondInNanoseconds,
CHRE_SENSOR_LATENCY_ASAP)) {
chreLog(CHRE_LOG_ERROR, "Failed sensorConfigure in start");
return false;
diff --git a/apps/chqts/src/general_test/basic_audio_test.cc b/apps/chqts/src/general_test/basic_audio_test.cc
index 01aabb1..7452c49 100644
--- a/apps/chqts/src/general_test/basic_audio_test.cc
+++ b/apps/chqts/src/general_test/basic_audio_test.cc
@@ -17,16 +17,15 @@
#include <general_test/basic_audio_test.h>
#include <shared/send_message.h>
+#include <shared/time_util.h>
+using nanoapp_testing::kOneSecondInNanoseconds;
using nanoapp_testing::sendFatalFailureToHost;
using nanoapp_testing::sendSuccessToHost;
namespace general_test {
namespace {
-//! Unit conversion nanoseconds per second.
-constexpr uint64_t kNanosecondsPerSecond = 1000000000;
-
//! This is a reasonably high limit on the number of audio sources that a system
//! would expose. Use this to verify that there are no gaps in the source
//! handles.
@@ -50,12 +49,12 @@
//! sample rate possible, a minimum number of samples will be delivered in
//! a batch.
constexpr uint64_t kMinBufferDuration =
- (kNanosecondsPerSecond / kMaxAudioSampleRate) * 10;
+ (kOneSecondInNanoseconds / kMaxAudioSampleRate) * 10;
//! Provide a ceiling for the maximum buffer duration. This is to catch buggy
//! descriptors of audio sources who expose very long buffers of data which are
//! not practical for always-on, low-power use-cases.
-constexpr uint64_t kMaxBufferDuration = kNanosecondsPerSecond * 120;
+constexpr uint64_t kMaxBufferDuration = kOneSecondInNanoseconds * 120;
/**
* @return true if the character is ASCII printable.
@@ -126,7 +125,7 @@
bool validateMinimumAudioSource(const struct chreAudioSource& source) {
// CHQTS requires a 16kHz, PCM-format, 2 second buffer.
constexpr uint32_t kRequiredSampleRate = 16000;
- constexpr uint64_t kRequiredBufferDuration = 2 * kNanosecondsPerSecond;
+ constexpr uint64_t kRequiredBufferDuration = 2 * kOneSecondInNanoseconds;
// Ensure that the minimum buffer size is less than or equal to the required
// size.
diff --git a/apps/chqts/src/general_test/basic_sensor_test_base.cc b/apps/chqts/src/general_test/basic_sensor_test_base.cc
index ec3aac0..f177433 100644
--- a/apps/chqts/src/general_test/basic_sensor_test_base.cc
+++ b/apps/chqts/src/general_test/basic_sensor_test_base.cc
@@ -20,10 +20,13 @@
#include <cstddef>
#include <shared/send_message.h>
+#include <shared/time_util.h>
#include <chre.h>
using nanoapp_testing::MessageType;
+using nanoapp_testing::kOneMillisecondInNanoseconds;
+using nanoapp_testing::kOneSecondInNanoseconds;
using nanoapp_testing::sendFatalFailureToHost;
using nanoapp_testing::sendInternalFailureToHost;
using nanoapp_testing::sendStringToHost;
@@ -53,8 +56,7 @@
namespace {
constexpr uint16_t kStartEvent = CHRE_EVENT_FIRST_USER_VALUE;
constexpr uint16_t kPassiveCompleteEvent = CHRE_EVENT_FIRST_USER_VALUE + 1;
-constexpr uint64_t kNanosecondsPerSecond = 1000000000;
-constexpr uint64_t kEventLoopSlack = 100000000; // 100 msec
+constexpr uint64_t kEventLoopSlack = 100 * kOneMillisecondInNanoseconds;
uint64_t getEventDuration(const chreSensorThreeAxisData *event) {
uint64_t duration = 0;
@@ -121,19 +123,19 @@
} else {
if (!chreSensorConfigure(mSensorHandle, mode,
CHRE_SENSOR_INTERVAL_DEFAULT,
- kNanosecondsPerSecond)) {
+ kOneSecondInNanoseconds)) {
sendFatalFailureToHost("chreSensorConfigure() failed passive with "
"default interval and non-default latency");
}
if (!isOneShotSensor() && !chreSensorConfigure(
- mSensorHandle, mode, kNanosecondsPerSecond,
+ mSensorHandle, mode, kOneSecondInNanoseconds,
CHRE_SENSOR_LATENCY_DEFAULT)) {
sendFatalFailureToHost("chreSensorConfigure() failed passive with "
"non-default interval and default latency");
}
if (!isOneShotSensor() && !chreSensorConfigure(
- mSensorHandle, mode, kNanosecondsPerSecond,
- kNanosecondsPerSecond)) {
+ mSensorHandle, mode, kOneSecondInNanoseconds,
+ kOneSecondInNanoseconds)) {
sendFatalFailureToHost("chreSensorConfigure() failed passive with "
"non-default interval and latency");
}
@@ -211,7 +213,7 @@
// from what it currently is for the sensor, and confirm it
// changes back when we're DONE. But that's beyond the current
// scope of this 'basic' test.
- kNanosecondsPerSecond, /* interval */
+ kOneSecondInNanoseconds, /* interval */
// We want the test to run as quickly as possible.
// TODO: Similar to the interval, we could try to test changes in
// this value, but it's beyond our 'basic' scope for now.
diff --git a/apps/chqts/src/general_test/heap_exhaustion_stability_test.cc b/apps/chqts/src/general_test/heap_exhaustion_stability_test.cc
index 9828a3a..0aae364 100644
--- a/apps/chqts/src/general_test/heap_exhaustion_stability_test.cc
+++ b/apps/chqts/src/general_test/heap_exhaustion_stability_test.cc
@@ -20,9 +20,12 @@
#include <cstddef>
#include <shared/send_message.h>
+#include <shared/time_util.h>
#include <chre.h>
+using nanoapp_testing::kOneMillisecondInNanoseconds;
+using nanoapp_testing::kOneSecondInNanoseconds;
using nanoapp_testing::sendFailureToHost;
using nanoapp_testing::sendFatalFailureToHost;
using nanoapp_testing::sendSuccessToHost;
@@ -49,10 +52,8 @@
// Thus we make this "static const" instead of "constexpr", as we expect
// them to have backing memory.
-// 5 seconds
-static const uint64_t kExhaustionDuration = UINT64_C(5000000000);
-// 10 milliseconds
-static const uint64_t kShortDuration = UINT64_C(10000000);
+static const uint64_t kExhaustionDuration = 5 * kOneSecondInNanoseconds;
+static const uint64_t kShortDuration = 10 * kOneMillisecondInNanoseconds;
constexpr uint16_t kEventType = CHRE_EVENT_FIRST_USER_VALUE;
diff --git a/apps/chqts/src/general_test/timer_cancel_test.cc b/apps/chqts/src/general_test/timer_cancel_test.cc
index 689d868..6a2fa6c 100644
--- a/apps/chqts/src/general_test/timer_cancel_test.cc
+++ b/apps/chqts/src/general_test/timer_cancel_test.cc
@@ -20,9 +20,11 @@
#include <cstddef>
#include <shared/send_message.h>
+#include <shared/time_util.h>
#include <chre.h>
+using nanoapp_testing::kOneMillisecondInNanoseconds;
using nanoapp_testing::sendFatalFailureToHost;
using nanoapp_testing::sendInternalFailureToHost;
using nanoapp_testing::sendSuccessToHost;
@@ -36,8 +38,7 @@
* When all of our stages have succeeded, then we send success to the host.
*/
-// 10 milliseconds
-static uint64_t kDuration = UINT64_C(10000000);
+static uint64_t kDuration = 10 * kOneMillisecondInNanoseconds;
namespace general_test {
diff --git a/apps/chqts/src/general_test/timer_set_test.cc b/apps/chqts/src/general_test/timer_set_test.cc
index fb7165b..2a04e9a 100644
--- a/apps/chqts/src/general_test/timer_set_test.cc
+++ b/apps/chqts/src/general_test/timer_set_test.cc
@@ -21,9 +21,12 @@
#include <new>
#include <shared/send_message.h>
+#include <shared/time_util.h>
#include <chre.h>
+using nanoapp_testing::kOneMillisecondInNanoseconds;
+using nanoapp_testing::kOneSecondInNanoseconds;
using nanoapp_testing::sendFatalFailureToHost;
using nanoapp_testing::sendInternalFailureToHost;
using nanoapp_testing::sendSuccessToHost;
@@ -44,11 +47,8 @@
* us more time to notice them (incorrectly) firing multiple times.
*/
-// 10 milliseconds
-static uint64_t kShortDuration = UINT64_C(10000000);
-// 1 second
-static uint64_t kOneSecond = UINT64_C(1000000000);
-static uint64_t kLongDuration = kOneSecond;
+static uint64_t kShortDuration = 10 * kOneMillisecondInNanoseconds;
+static uint64_t kLongDuration = kOneSecondInNanoseconds;
namespace general_test {
@@ -79,7 +79,7 @@
sendFatalFailureToHost("Timer triggered too soon ", &mStage);
}
// TODO(b/32179037): Make this check much stricter.
- if (timestamp > (expectedTime + kOneSecond)) {
+ if (timestamp > (expectedTime + kOneSecondInNanoseconds)) {
sendFatalFailureToHost("Timer triggered over a second late ", &mStage);
}
diff --git a/apps/chqts/src/shared/time_util.h b/apps/chqts/src/shared/time_util.h
new file mode 100644
index 0000000..38c9e1e
--- /dev/null
+++ b/apps/chqts/src/shared/time_util.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _GTS_NANOAPPS_SHARED_TIME_UTIL_H_
+#define _GTS_NANOAPPS_SHARED_TIME_UTIL_H_
+
+#include <cstdint>
+
+namespace nanoapp_testing {
+
+//! The number of milliseconds in one min.
+constexpr uint64_t kOneMinuteInMilliseconds(60000);
+
+//! The number of milliseconds in one second.
+constexpr uint64_t kOneSecondInMilliseconds(1000);
+
+//! The number of nanoseconds in one second.
+constexpr uint64_t kOneSecondInNanoseconds(1000000000);
+
+//! The number of nanoseconds in one millisecond.
+constexpr uint64_t kOneMillisecondInNanoseconds(1000000);
+
+//! The number of nanoseconds in one microsecond.
+constexpr uint64_t kOneMicrosecondInNanoseconds(1000);
+
+//! The number of microseconds in one millisecond.
+constexpr uint64_t kOneMillisecondInMicroseconds(1000);
+
+} // namespace nanoapp_testing
+
+#endif // _GTS_NANOAPPS_SHARED_TIME_UTIL_H_