1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef STATS_TEST_H 17 #define STATS_TEST_H 18 19 #include <gtest/gtest.h> 20 21 #include "battery_stats_parser.h" 22 23 namespace OHOS { 24 namespace PowerMgr { 25 class StatsTest { 26 public: 27 static constexpr int64_t US_PER_HOUR = 3600000000; 28 static constexpr int32_t MS_PER_HOUR = 3600000; 29 static constexpr int32_t US_PER_SECOND = 1000000; 30 static constexpr int32_t US_PER_MS = 1000; 31 static constexpr int32_t POWER_CONSUMPTION_TRIGGERED_US = 20000; 32 static constexpr int32_t POWER_CONSUMPTION_DURATION_US = 300000; 33 static constexpr int32_t SERVICE_POWER_CONSUMPTION_DURATION_US = 200000; 34 static constexpr double DEVIATION_PERCENT_THRESHOLD = 1; 35 static constexpr int64_t TIMER_DURATION_MS = 50; 36 static constexpr int32_t DEVIATION_TIMER_THRESHOLD = 5; 37 static std::shared_ptr<BatteryStatsParser> g_statsParser; 38 ParserAveragePowerFile()39static void ParserAveragePowerFile() 40 { 41 if (g_statsParser == nullptr) { 42 g_statsParser = std::make_shared<BatteryStatsParser>(); 43 if (!g_statsParser->Init()) { 44 GTEST_LOG_(INFO) << __func__ << ": Battery stats parser initialization failed"; 45 } 46 } 47 } 48 }; 49 std::shared_ptr<BatteryStatsParser> StatsTest::g_statsParser = nullptr; 50 } // namespace PowerMgr 51 } // namespace OHOS 52 #endif // STATS_TEST_H