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()
23 : Test(CHRE_API_VERSION_1_1) {
24 }
25
setUp(uint32_t messageSize,const void *)26 void SensorInfoTest::setUp(uint32_t messageSize, const void * /* message */) {
27 if (messageSize != 0) {
28 nanoapp_testing::sendFatalFailureToHost(
29 "Expected 0 byte message, got more bytes:", &messageSize);
30 } else if (!chreSensorFindDefault(CHRE_SENSOR_TYPE_ACCELEROMETER,
31 &mSensorHandle)) {
32 nanoapp_testing::sendFatalFailureToHost(
33 "CHRE implementation does not have an accelerometer");
34 } else {
35 struct chreSensorInfo info;
36
37 if (!chreGetSensorInfo(mSensorHandle, &info)) {
38 nanoapp_testing::sendFatalFailureToHost(
39 "Failed to gather sensor info");
40 } else {
41 mCompleted = true;
42 validateSensorInfo(info);
43 }
44 }
45 }
46
validateSensorInfo(const struct chreSensorInfo & info) const47 void SensorInfoTest::validateSensorInfo(const struct chreSensorInfo& info) const {
48 if ((mApiVersion < CHRE_API_VERSION_1_1) && (info.minInterval != 0)) {
49 nanoapp_testing::sendFatalFailureToHost(
50 "Sensor minimum interval is non-zero");
51 } else if (info.minInterval == 0) {
52 nanoapp_testing::sendFatalFailureToHost(
53 "Sensor minimum interval is unknown");
54 } else if (!chreSensorConfigure(mSensorHandle,
55 CHRE_SENSOR_CONFIGURE_MODE_CONTINUOUS,
56 info.minInterval,
57 CHRE_SENSOR_LATENCY_DEFAULT)) {
58 nanoapp_testing::sendFatalFailureToHost(
59 "Sensor failed configuration with minimum interval");
60 } else if (!chreSensorConfigureModeOnly(mSensorHandle,
61 CHRE_SENSOR_CONFIGURE_MODE_DONE)) {
62 nanoapp_testing::sendFatalFailureToHost(
63 "Unable to configure sensor mode to DONE");
64 } else {
65 nanoapp_testing::sendSuccessToHost();
66 }
67 }
68
handleEvent(uint32_t,uint16_t eventType,const void *)69 void SensorInfoTest::handleEvent(uint32_t /* senderInstanceId */,
70 uint16_t eventType,
71 const void * /* eventData */) {
72 if (!mCompleted) {
73 unexpectedEvent(eventType);
74 }
75 }
76
77 } // namespace general_test
78