1 /*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 #include <general_test/sensor_info_test.h>
17
18 #include <shared/send_message.h>
19
20 namespace general_test {
21
SensorInfoTest()22 SensorInfoTest::SensorInfoTest() : Test(CHRE_API_VERSION_1_1) {}
23
setUp(uint32_t messageSize,const void *)24 void SensorInfoTest::setUp(uint32_t messageSize, const void * /* message */) {
25 if (messageSize != 0) {
26 nanoapp_testing::sendFatalFailureToHost(
27 "Expected 0 byte message, got more bytes:", &messageSize);
28 } else if (!chreSensorFindDefault(CHRE_SENSOR_TYPE_ACCELEROMETER,
29 &mSensorHandle)) {
30 nanoapp_testing::sendFatalFailureToHost(
31 "CHRE implementation does not have an accelerometer");
32 } else {
33 struct chreSensorInfo info;
34
35 if (!chreGetSensorInfo(mSensorHandle, &info)) {
36 nanoapp_testing::sendFatalFailureToHost("Failed to gather sensor info");
37 } else {
38 mCompleted = true;
39 validateSensorInfo(info);
40 }
41 }
42 }
43
validateSensorInfo(const struct chreSensorInfo & info) const44 void SensorInfoTest::validateSensorInfo(
45 const struct chreSensorInfo &info) const {
46 if ((mApiVersion < CHRE_API_VERSION_1_1) && (info.minInterval != 0)) {
47 nanoapp_testing::sendFatalFailureToHost(
48 "Sensor minimum interval is non-zero");
49 } else if (info.minInterval == 0) {
50 nanoapp_testing::sendFatalFailureToHost(
51 "Sensor minimum interval is unknown");
52 } else if (!chreSensorConfigure(
53 mSensorHandle, CHRE_SENSOR_CONFIGURE_MODE_CONTINUOUS,
54 info.minInterval, CHRE_SENSOR_LATENCY_DEFAULT)) {
55 nanoapp_testing::sendFatalFailureToHost(
56 "Sensor failed configuration with minimum interval");
57 } else if (!chreSensorConfigureModeOnly(mSensorHandle,
58 CHRE_SENSOR_CONFIGURE_MODE_DONE)) {
59 nanoapp_testing::sendFatalFailureToHost(
60 "Unable to configure sensor mode to DONE");
61 } else {
62 nanoapp_testing::sendSuccessToHost();
63 }
64 }
65
handleEvent(uint32_t,uint16_t eventType,const void *)66 void SensorInfoTest::handleEvent(uint32_t /* senderInstanceId */,
67 uint16_t eventType,
68 const void * /* eventData */) {
69 if (!mCompleted) {
70 unexpectedEvent(eventType);
71 }
72 }
73
74 } // namespace general_test
75