blob: c49c1b9204ed279632cf2a1793f662fa85f9103a [file] [log] [blame]
Yu-Han Yang1e1a6762020-09-30 17:01:53 -07001/*
2 * Copyright (C) 2020 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#pragma once
18
19#include <aidl/Gtest.h>
20#include <aidl/Vintf.h>
21
22#include <android/hardware/gnss/IGnss.h>
23#include <binder/IServiceManager.h>
24
25#include <android/hardware/gnss/2.1/IGnss.h>
Yu-Han Yang3a75dc02021-09-27 01:01:06 -070026#include "GnssBatchingCallback.h"
Yu-Han Yang1e1a6762020-09-30 17:01:53 -070027#include "GnssCallbackAidl.h"
Yu-Han Yang19a32b62022-04-27 09:57:01 -070028#include "GnssMeasurementCallbackAidl.h"
Yu-Han Yang1e1a6762020-09-30 17:01:53 -070029#include "v2_1/gnss_hal_test_template.h"
30
31using IGnss_V2_1 = android::hardware::gnss::V2_1::IGnss;
32
33using android::ProcessState;
34using android::sp;
35using android::String16;
36using IGnssAidl = android::hardware::gnss::IGnss;
37using android::hardware::gnss::BlocklistedSource;
38using android::hardware::gnss::IGnssConfiguration;
39
40// The main test class for GNSS HAL.
Yu-Han Yang04832302020-11-20 09:51:18 -080041class GnssHalTest : public android::hardware::gnss::common::GnssHalTestTemplate<IGnss_V2_1> {
Yu-Han Yang1e1a6762020-09-30 17:01:53 -070042 public:
43 GnssHalTest(){};
44 ~GnssHalTest(){};
Yu-Han Yang1afbd5f2021-11-24 16:39:13 -080045
46 struct ComparableBlocklistedSource {
47 android::hardware::gnss::BlocklistedSource id;
48
49 ComparableBlocklistedSource() {
50 id.constellation = android::hardware::gnss::GnssConstellationType::UNKNOWN;
51 id.svid = 0;
52 }
53
54 bool operator<(const ComparableBlocklistedSource& compare) const {
55 return ((id.svid < compare.id.svid) || ((id.svid == compare.id.svid) &&
56 (id.constellation < compare.id.constellation)));
57 }
58 };
59
60 struct SignalCounts {
61 int observations;
62 float max_cn0_dbhz;
63 };
64
Yu-Han Yang1e1a6762020-09-30 17:01:53 -070065 virtual void SetUp() override;
66 virtual void SetUpGnssCallback() override;
Yu-Han Yang25cd9d62022-10-13 23:06:31 +000067 virtual void TearDown() override;
Yu-Han Yang1e1a6762020-09-30 17:01:53 -070068
Yu-Han Yang1afbd5f2021-11-24 16:39:13 -080069 void CheckLocation(const android::hardware::gnss::GnssLocation& location,
70 const bool check_speed);
71 void SetPositionMode(const int min_interval_msec, const bool low_power_mode);
72 bool StartAndCheckFirstLocation(const int min_interval_msec, const bool low_power_mode);
Yu-Han Yang19a32b62022-04-27 09:57:01 -070073 bool StartAndCheckFirstLocation(const int min_interval_msec, const bool low_power_mode,
74 const bool start_sv_status, const bool start_nmea);
Yu-Han Yang1afbd5f2021-11-24 16:39:13 -080075 void StopAndClearLocations();
Yu-Han Yang19a32b62022-04-27 09:57:01 -070076 void StartAndCheckLocations(const int count);
77 void StartAndCheckLocations(const int count, const bool start_sv_status, const bool start_nmea);
Yu-Han Yang1afbd5f2021-11-24 16:39:13 -080078
79 android::hardware::gnss::GnssConstellationType startLocationAndGetNonGpsConstellation(
80 const int locations_to_await, const int gnss_sv_info_list_timeout);
81 std::list<std::vector<android::hardware::gnss::IGnssCallback::GnssSvInfo>> convertToAidl(
82 const std::list<hidl_vec<android::hardware::gnss::V2_1::IGnssCallback::GnssSvInfo>>&
83 sv_info_list);
84 android::hardware::gnss::BlocklistedSource FindStrongFrequentNonGpsSource(
85 const std::list<hidl_vec<android::hardware::gnss::V2_1::IGnssCallback::GnssSvInfo>>
86 sv_info_list,
87 const int min_observations);
88 android::hardware::gnss::BlocklistedSource FindStrongFrequentNonGpsSource(
89 const std::list<std::vector<android::hardware::gnss::IGnssCallback::GnssSvInfo>>
90 sv_info_list,
91 const int min_observations);
92
Yu-Han Yang19a32b62022-04-27 09:57:01 -070093 void checkGnssMeasurementClockFields(const android::hardware::gnss::GnssData& measurement);
94 void checkGnssMeasurementFlags(const android::hardware::gnss::GnssMeasurement& measurement);
95 void checkGnssMeasurementFields(const android::hardware::gnss::GnssMeasurement& measurement,
96 const android::hardware::gnss::GnssData& data);
97 void startMeasurementWithInterval(
98 int intervalMillis,
99 const sp<android::hardware::gnss::IGnssMeasurementInterface>& iMeasurement,
100 sp<GnssMeasurementCallbackAidl>& callback);
101 void collectMeasurementIntervals(const sp<GnssMeasurementCallbackAidl>& callback,
102 const int numMeasurementEvents, const int timeoutSeconds,
103 std::vector<int>& deltaMs);
104 void assertMeanAndStdev(int intervalMillis, std::vector<int>& deltasMillis);
105
Yu-Han Yang1e1a6762020-09-30 17:01:53 -0700106 sp<IGnssAidl> aidl_gnss_hal_;
107 sp<GnssCallbackAidl> aidl_gnss_cb_; // Primary callback interface
108};