• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 
17 #include <gtest/gtest.h>
18 
19 #include "chre/pal/gnss.h"
20 #include "chre/platform/shared/pal_system_api.h"
21 
22 #include <stddef.h>
23 #include <stdint.h>
24 #include <string.h>
25 #include <thread>
26 
27 #include "app_test_base.h"
28 #include "chpp/app.h"
29 #include "chpp/clients/gnss.h"
30 #include "chpp/log.h"
31 #include "chpp/platform/platform_gnss.h"
32 
33 /*
34  * Test suite for the CHPP GNSS client/service
35  */
36 namespace chpp {
37 namespace {
38 
39 const struct chrePalGnssApi *gApi;
chrePalRequestStateResync()40 void chrePalRequestStateResync() {}
41 
chrePalLocationStatusChangeCallback(bool,uint8_t)42 void chrePalLocationStatusChangeCallback(bool /* enabled */,
43                                          uint8_t /* errorCode */) {}
44 
chrePalLocationEventCallback(struct chreGnssLocationEvent * event)45 void chrePalLocationEventCallback(struct chreGnssLocationEvent *event) {
46   CHPP_LOGI("Got location event");
47   gApi->releaseLocationEvent(event);
48 }
49 
chrePalMeasurementStatusChangeCallback(bool,uint8_t)50 void chrePalMeasurementStatusChangeCallback(bool /* enabled */,
51                                             uint8_t /*  errorCode */) {}
52 
chrePalMeasurementEventCallback(struct chreGnssDataEvent * event)53 void chrePalMeasurementEventCallback(struct chreGnssDataEvent *event) {
54   CHPP_LOGI("Got measurement event");
55   gApi->releaseMeasurementDataEvent(event);
56 }
57 
TEST_F(AppTestBase,SimpleGnss)58 TEST_F(AppTestBase, SimpleGnss) {
59   gApi = chppPalGnssGetApi(CHRE_PAL_GNSS_API_CURRENT_VERSION);
60   ASSERT_NE(gApi, nullptr);
61 
62   static const struct chrePalGnssCallbacks kCallbacks = {
63       .requestStateResync = chrePalRequestStateResync,
64       .locationStatusChangeCallback = chrePalLocationStatusChangeCallback,
65       .locationEventCallback = chrePalLocationEventCallback,
66       .measurementStatusChangeCallback = chrePalMeasurementStatusChangeCallback,
67       .measurementEventCallback = chrePalMeasurementEventCallback,
68   };
69   bool success = gApi->open(&chre::gChrePalSystemApi, &kCallbacks);
70   ASSERT_TRUE(success);
71 
72   for (size_t i = 0; i < 10; i++) {
73     gnssPalSendLocationEvent();
74     gnssPalSendMeasurementEvent();
75   }
76 
77   gApi->close();
78 }
79 
TEST_F(AppTestBase,GnssCapabilitiesTest)80 TEST_F(AppTestBase, GnssCapabilitiesTest) {
81   gApi = chppPalGnssGetApi(CHRE_PAL_GNSS_API_CURRENT_VERSION);
82   ASSERT_NE(gApi, nullptr);
83 
84   static const struct chrePalGnssCallbacks kCallbacks = {
85       .requestStateResync = chrePalRequestStateResync,
86       .locationStatusChangeCallback = chrePalLocationStatusChangeCallback,
87       .locationEventCallback = chrePalLocationEventCallback,
88       .measurementStatusChangeCallback = chrePalMeasurementStatusChangeCallback,
89       .measurementEventCallback = chrePalMeasurementEventCallback,
90   };
91   bool success = gApi->open(&chre::gChrePalSystemApi, &kCallbacks);
92   ASSERT_TRUE(success);
93 
94   // Set the linkActive flag to false so that CHPP link layer does not
95   // receive/send message, which causes the capabilities to be set to the
96   // default CHPP_GNSS_DEFAULT_CAPABILITIES
97   mClientTransportContext.linkParams.isLinkActive = false;
98   uint32_t capabilities = gApi->getCapabilities();
99   ASSERT_EQ(capabilities, CHPP_GNSS_DEFAULT_CAPABILITIES);
100   mClientTransportContext.linkParams.isLinkActive = true;
101 
102   gApi->close();
103 }
104 
105 }  //  anonymous namespace
106 }  //  namespace chpp
107