1 /*
2 * Copyright (C) 2016 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/platform/slpi/platform_sensor_util.h"
20
21 using chre::intervalToSmgrSamplingRate;
22 using chre::intervalToSmgrQ16ReportRate;
23 using chre::Milliseconds;
24 using chre::Nanoseconds;
25 using chre::Seconds;
26
TEST(SmgrSamplingRateTest,Zero)27 TEST(SmgrSamplingRateTest, Zero) {
28 uint16_t rate = intervalToSmgrSamplingRate(Nanoseconds(0));
29 EXPECT_EQ(rate, 0);
30 }
31
TEST(SmgrSamplingRateTest,FiftyHertz)32 TEST(SmgrSamplingRateTest, FiftyHertz) {
33 constexpr Nanoseconds kTenHertzInterval(Milliseconds(20));
34 uint16_t rate = intervalToSmgrSamplingRate(kTenHertzInterval);
35 EXPECT_EQ(rate, 50);
36 }
37
TEST(SmgrSamplingRateTest,ZeroPointFiveHertz)38 TEST(SmgrSamplingRateTest, ZeroPointFiveHertz) {
39 constexpr Nanoseconds kZeroPointFiveHertzInterval(Seconds(2));
40 uint16_t rate = intervalToSmgrSamplingRate(kZeroPointFiveHertzInterval);
41 EXPECT_EQ(rate, 2000);
42 }
43
TEST(SmgrQ16ReportRateTest,Zero)44 TEST(SmgrQ16ReportRateTest, Zero) {
45 uint32_t rate = intervalToSmgrQ16ReportRate(Nanoseconds(0));
46 EXPECT_EQ(rate, UINT32_MAX);
47 }
48
TEST(SmgrQ16ReportRateTest,FiftyHertz)49 TEST(SmgrQ16ReportRateTest, FiftyHertz) {
50 constexpr Nanoseconds kTenHertzInterval(Milliseconds(20));
51 uint32_t rate = intervalToSmgrQ16ReportRate(kTenHertzInterval);
52 EXPECT_EQ(rate, 0x10000 * 50);
53 }
54
TEST(SmgrQ16ReportRateTest,ZeroPointFiveHertz)55 TEST(SmgrQ16ReportRateTest, ZeroPointFiveHertz) {
56 constexpr Nanoseconds kZeroPointFiveHertzInterval(Seconds(2));
57 uint32_t rate = intervalToSmgrQ16ReportRate(kZeroPointFiveHertzInterval);
58 EXPECT_EQ(rate, 0x10000 / 2);
59 }
60
TEST(SmgrQ16ReportRateTest,OneNanosecond)61 TEST(SmgrQ16ReportRateTest, OneNanosecond) {
62 uint32_t rate = intervalToSmgrQ16ReportRate(Nanoseconds(1));
63 EXPECT_EQ(rate, UINT32_MAX);
64 }
65