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/macros.h>
19 #include <shared/send_message.h>
20
21 namespace general_test {
22
SensorInfoTest()23 SensorInfoTest::SensorInfoTest() : Test(CHRE_API_VERSION_1_1) {}
24
setUp(uint32_t messageSize,const void *)25 void SensorInfoTest::setUp(uint32_t messageSize, const void * /* message */) {
26 if (messageSize != 0) {
27 EXPECT_FAIL_RETURN("Expected 0 byte message, got more bytes:",
28 &messageSize);
29 } else if (!chreSensorFindDefault(CHRE_SENSOR_TYPE_ACCELEROMETER,
30 &mSensorHandle)) {
31 EXPECT_FAIL_RETURN("CHRE implementation does not have an accelerometer");
32 } else {
33 struct chreSensorInfo info;
34
35 if (!chreGetSensorInfo(mSensorHandle, &info)) {
36 EXPECT_FAIL_RETURN("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 EXPECT_FAIL_RETURN("Sensor minimum interval is non-zero");
48 } else if (info.minInterval == 0) {
49 EXPECT_FAIL_RETURN("Sensor minimum interval is unknown");
50 } else if (!chreSensorConfigure(
51 mSensorHandle, CHRE_SENSOR_CONFIGURE_MODE_CONTINUOUS,
52 info.minInterval, CHRE_SENSOR_LATENCY_DEFAULT)) {
53 EXPECT_FAIL_RETURN("Sensor failed configuration with minimum interval");
54 } else if (!chreSensorConfigureModeOnly(mSensorHandle,
55 CHRE_SENSOR_CONFIGURE_MODE_DONE)) {
56 EXPECT_FAIL_RETURN("Unable to configure sensor mode to DONE");
57 } else {
58 nanoapp_testing::sendSuccessToHost();
59 }
60 }
61
handleEvent(uint32_t,uint16_t eventType,const void *)62 void SensorInfoTest::handleEvent(uint32_t /* senderInstanceId */,
63 uint16_t eventType,
64 const void * /* eventData */) {
65 if (!mCompleted) {
66 unexpectedEvent(eventType);
67 }
68 }
69
70 } // namespace general_test
71