diff --git a/powermgr/BUILD.gn b/powermgr/BUILD.gn index 7c9da919bef609f29473046c238c4089769c0a85..af90e921d3536eb5e5a2dd451f194e644b04e250 100755 --- a/powermgr/BUILD.gn +++ b/powermgr/BUILD.gn @@ -15,7 +15,10 @@ group("powermgr") { testonly = true if (device_name == "rk3568") { if (is_standard_system) { - deps = [ "powermgrbattery_rk3568:powermgr_battery_test_rk3568" ] + deps = [ + "powermgrbattery_rk3568:powermgr_battery_test_rk3568", + "powermgrthermal:powermgr_thermal_test", + ] } } else { if (is_standard_system) { diff --git a/powermgr/powermgrthermal/README_zh.md b/powermgr/powermgrthermal/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..38a23b5946ff2d50fae61183c21121971c909675 --- /dev/null +++ b/powermgr/powermgrthermal/README_zh.md @@ -0,0 +1,15 @@ +# 热管理服务XTS + +- [描述](#section0056945901) + +## 描述 + +### 执行性能测试(thermal_common_event.test.js), 单元测试用例(thermal_unittest.test.js)和接收公共事件用例(thermal_common_event.test.js)前, 请手动执行temp.sh + +步骤: + +$ hdc_std file send temp.sh /data + +$ sh temp.sh + + diff --git a/powermgr/powermgrthermal/Test.json b/powermgr/powermgrthermal/Test.json index 005c0f34c73895318f79d93afb6764d4ee027700..620b0e92485dcf593b672ac07304fbd7d59ec028 100644 --- a/powermgr/powermgrthermal/Test.json +++ b/powermgr/powermgrthermal/Test.json @@ -2,9 +2,9 @@ "description": "Configuration for powermgr thermal Tests", "driver": { "type": "JSUnitTest", - "test-timeout": "60000", + "test-timeout": "120000", "package": "com.example.mythermalapp", - "shell-timeout": "60000" + "shell-timeout": "120000" }, "kits": [ { diff --git a/powermgr/powermgrthermal/src/main/js/default/pages/index/index.js b/powermgr/powermgrthermal/src/main/js/default/pages/index/index.js index 39b6f425dccb33b8a1aa12fc3b0c1d44505abcfd..8b86d31dd948dd673cd4293b0e2d9ea47319f797 100644 --- a/powermgr/powermgrthermal/src/main/js/default/pages/index/index.js +++ b/powermgr/powermgrthermal/src/main/js/default/pages/index/index.js @@ -12,31 +12,32 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -import device from '@system.device'; +import app from '@system.app' import {Core, ExpectExtend} from 'deccjsunit/index' -const core = Core.getInstance(); - -core.init() - -require('../../test/List.test') - -core.execute() - export default { data: { - title: "world", - width:0, - height: 0 + title: "" }, onInit() { - device.getInfo({ - success:(data) =>{ - this.width = data.windowWidth; - this.height = data.windowHeight; - } - }); - } + this.title = this.$t('strings.world'); + }, + onShow() { + console.info('onShow finish') + const core = Core.getInstance() + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }) + core.addService('expect', expectExtend) + core.init() + + const configService = core.getDefaultService('config') + configService.setConfig(this) + + require('../../test/List.test') + core.execute() + }, + onReady() { + }, } diff --git a/powermgr/powermgrthermal/src/main/js/default/test/thermal_common_event.test.js b/powermgr/powermgrthermal/src/main/js/default/test/thermal_common_event.test.js new file mode 100644 index 0000000000000000000000000000000000000000..7281b6fb290e9df74435ba03217eb48b2abb0c36 --- /dev/null +++ b/powermgr/powermgrthermal/src/main/js/default/test/thermal_common_event.test.js @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import commonEvent from '@ohos.commonEvent'; +import thermal from "@ohos.thermal" + +describe('appInfoTest', function () { + console.log("*************Thermal commonEvent Test Begin*************"); + + /** + * @tc.number ThermalCommonEventTest_001 + * @tc.name subscribe thermal level changed common event + * @tc.desc Thermal acquisition kit + */ + it('ThermalCommonEventTest_001', 0, function (done) { + createSubscriber(); + done(); + }) + console.log("*************Thermal commonEvent Test End*************"); +}) + +function createSubscriber() { + var commonEventSubscribeInfo = { + events: [commonEvent.Support.COMMON_EVENT_THERMAL_LEVEL_CHANGED], + }; + commonEvent.createSubscriber(commonEventSubscribeInfo) + .then(subscriber => { + console.info('createSubscriber success'); + var mySubscriber = subscriber; + console.log(subscriber); + + if (subscriber == "" || subscriber == undefined || subscriber == null) { + console.info("createSubscriber failed"); + } + mySubscriber.getCode() + .then((data) => { + console.info('Subscriber getCode success : ' + JSON.stringify(data)); + }).catch((error) => { + console.error('Subscriber getCode error because: ' + JSON.stringify(error)); + }) + mySubscriber.getData() + .then((data) => { + console.info('Subscriber getData success : ' + JSON.stringify(data)); + }).catch((error) => { + console.error('Subscriber getData error because: ' + JSON.stringify(error)); + }) + console.info('subscribe begin '); + + commonEvent.subscribe(mySubscriber, (error, commonEventData) => { + console.error('err code: ' + JSON.stringify(error)); + console.info('subscribe callback: ' + JSON.stringify(commonEventData)); + console.info("commonEventData event: " + commonEventData.event); + console.info("commonEventData bundleName: " + commonEventData.bundleName); + console.info("commonEventData data: " + commonEventData.data); + console.info("commonEventData parameter: " + commonEventData.parameters[0]); + var level = -1; + expect(level >= thermal.ThermalLevel.COOL && warm <= level.ThermalLevel.EMERGENCY).assertTrue(); + }); + }).catch((error) => { + console.error('Operation failed. Cause: ' + JSON.stringify(error)); + }); +} \ No newline at end of file diff --git a/powermgr/powermgrthermal/src/main/js/default/test/thermal_performance.test.js b/powermgr/powermgrthermal/src/main/js/default/test/thermal_performance.test.js new file mode 100644 index 0000000000000000000000000000000000000000..76b12f58aa75a817c77645f7ff662c146cf8bfd6 --- /dev/null +++ b/powermgr/powermgrthermal/src/main/js/default/test/thermal_performance.test.js @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import thermal from "@ohos.thermal" +import {describe, it, expect} from 'deccjsunit/index'; + +describe('appInfoTest', function () { + console.log("*************Thermal Performance Test Begin*************"); + performanceTest1(); + performanceTest2(); + performanceTest3(); + console.log("*************Thermal Performance Test End*************"); +}) + +function performanceTest1() { + var MAXNUM = 1000; + + /** + * @tc.number ThermalPerformance_001 + * @tc.name test get thermal level + * @tc.desc Thermal acquisition kit + */ + it('ThermalPerformance_001', 0, function () { + let startTime = new Date().getTime(); + for (let i = 0; i < MAXNUM; i++) { + var level = thermal.getThermalLevel(); + } + let waitTime = new Date().getTime() - startTime; + let avgTime = waitTime; //us + console.info(`ThermalPerformance_001: Promise: getlevel Wait Time : ${waitTime}`); + }) +} + +function performanceTest2() { + var MAXNUM = 1000; + + /** + * @tc.number ThermalPerformance_002 + * @tc.name subscribe thermal level + * @tc.desc Thermal acquisition kit + */ + it('ThermalPerformance_002', 0, function () { + let startTime = new Date().getTime(); + for (let i = 0; i < MAXNUM; i++) { + thermal.subscribeThermalLevel((level) => { + console.info("hot level is: " + level); + }) + } + let waitTime = new Date().getTime() - startTime; + let avgTime = waitTime; //us + console.info(`ThermalPerformance_002: Promise: subscribeThermalLevel Wait Time : ${waitTime}`); + }) +} + +function performanceTest3() { + var MAXNUM = 1000; + + /** + * @tc.number ThermalPerformance_002 + * @tc.name subscribe thermal level + * @tc.desc Thermal acquisition kit + */ + it('ThermalPerformance_003', 0, function () { + let startTime = new Date().getTime(); + for (let i = 0; i < MAXNUM; i++) { + thermal.unsubscribeThermalLevel(); + } + let waitTime = new Date().getTime() - startTime; + let avgTime = waitTime; //us + console.info(`ThermalPerformance_003: Promise: unsubscribeThermalLevel Wait Time : ${waitTime}`); + }) +} \ No newline at end of file diff --git a/powermgr/powermgrthermal/src/main/js/default/test/thermal_uint.test.js b/powermgr/powermgrthermal/src/main/js/default/test/thermal_uint.test.js index 1e43cae70d3be3caeedd6c6244faaf5df01164b6..df15f10791896efa4f4adc721b3bd7a5a87eb19f 100644 --- a/powermgr/powermgrthermal/src/main/js/default/test/thermal_uint.test.js +++ b/powermgr/powermgrthermal/src/main/js/default/test/thermal_uint.test.js @@ -1,3 +1,4 @@ +// @ts-nocheck /* * Copyright (C) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +21,6 @@ import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from ' describe('appInfoTest', function () { console.log("*************Thermal API Test Begin*************"); - const MSEC_1000 = 1000; test1(); test2(); test3(); @@ -34,9 +34,11 @@ describe('appInfoTest', function () { test11(); test12(); test13(); + console.log("*************Thermal API Test End*************"); }) function test1() { + const MSEC_1000 = 1000; /* @tc.number thermal_manager_js_001 * @tc.name Thermal_001 @@ -48,34 +50,36 @@ function test1() { setTimeout(()=>{ var cold = thermal.getThermalLevel(); console.info("cold level is: " + cold); - expect(cold >= 0 && cold <= 6).assertTrue(); + expect(cold >= thermal.ThermalLevel.COOL && cold <= thermal.ThermalLevel.EMERGENCY).assertTrue(); resolve(); - }, MSEC_1000 * 4); + done(); + }, MSEC_1000 * 1); }) - done(); }) } function test2() { + const MSEC_1000 = 1000; /* @tc.number thermal_manager_js_002 * @tc.name Thermal_002 * @tc.desc Thermal acquisition kit */ it('Thermal_002', 0, async function (done) { - await new Promise((resolve, reject) => { + await new Promise((resolve, reject) =>{ setTimeout(()=>{ var warm = thermal.getThermalLevel(); console.info("warm level is: " + warm); - expect(warm >= 0 && warm <= 6).assertTrue(); + expect(warm >= thermal.ThermalLevel.COOL && warm <= thermal.ThermalLevel.EMERGENCY).assertTrue(); resolve(); - }, MSEC_1000 * 4); + done(); + }, MSEC_1000 * 1); }) - done(); }) } function test3() { + const MSEC_1000 = 1000; /* @tc.number thermal_manager_js_003 * @tc.name Thermal_003 @@ -86,15 +90,16 @@ function test3() { setTimeout(()=>{ var hot = thermal.getThermalLevel(); console.info("hot level is: " + hot); - expect(hot >= 0 && hot <= 6).assertTrue(); + expect(hot >= thermal.ThermalLevel.COOL && hot <= thermal.ThermalLevel.EMERGENCY).assertTrue(); resolve(); - }, MSEC_1000 * 4); + done(); + }, MSEC_1000 * 1); }) - done(); }) } function test4() { + const MSEC_1000 = 1000; /* @tc.number thermal_manager_js_004 * @tc.name Thermal_004 @@ -105,15 +110,17 @@ function test4() { setTimeout(()=>{ var overheated = thermal.getThermalLevel(); console.info("overheated level is: " + overheated); - expect(overheated >= 0 && overheated <= 6).assertTrue(); + expect(overheated >= thermal.ThermalLevel.COOL && + overheated <= thermal.ThermalLevel.EMERGENCY).assertTrue(); resolve(); - }, MSEC_1000 * 4); + done(); + }, MSEC_1000 * 1); }) - done(); }) } function test5() { + const MSEC_1000 = 1000; /* @tc.number thermal_manager_js_005 * @tc.name Thermal_005 @@ -124,15 +131,16 @@ function test5() { setTimeout(()=>{ var warning = thermal.getThermalLevel(); console.info("warning level is: " + warning); - expect(warning >= 0 && warning <= 6).assertTrue(); + expect(warning >= thermal.ThermalLevel.COOL && warning <= thermal.ThermalLevel.EMERGENCY).assertTrue(); resolve(); - }, MSEC_1000 * 4); + done(); + }, MSEC_1000 * 1); }) - done(); }) } function test6() { + const MSEC_1000 = 1000; /* @tc.number thermal_manager_js_006 * @tc.name Thermal_006 @@ -143,15 +151,17 @@ function test6() { setTimeout(()=>{ var emergency = thermal.getThermalLevel(); console.info("emergency level is: " + emergency); - expect(emergency >= 0 && emergency <= 6).assertTrue(); + expect(emergency >= thermal.ThermalLevel.COOL && + emergency <= thermal.ThermalLevel.EMERGENCY).assertTrue(); resolve(); - }, MSEC_1000 * 4); + done(); + }, MSEC_1000 * 1); }) - done(); }) } function test7() { + const MSEC_1000 = 1000; /* @tc.number thermal_manager_js_007 * @tc.name Thermal_007 @@ -159,21 +169,23 @@ function test7() { */ it('Thermal_007', 0, async function (done) { thermal.subscribeThermalLevel((cool) => { - console.info("cool level is: " + cool); - count ++; - expect(cool >= 0 && cool <= 6).assertTrue(); + console.info("warm level is: " + cool); + expect(cool >= thermal.ThermalLevel.COOL && cool <= thermal.ThermalLevel.EMERGENCY).assertTrue(); + done(); }) await new Promise((resolve, reject)=>{ setTimeout(()=>{ - thermal.unsubscribeThermalLevel(); + thermal.unsubscribeThermalLevel(() => { + console.info("unsubscribe successfully!"); + }); resolve(); }, MSEC_1000 * 4); }) - done(); }) } function test8() { + const MSEC_1000 = 1000; /* @tc.number thermal_manager_js_008 * @tc.name Thermal_008 @@ -181,20 +193,23 @@ function test8() { */ it('Thermal_008', 0, async function (done) { thermal.subscribeThermalLevel((warm) => { - console.info("cool level is: " + warm); - expect(warm >= 0 && warm <= 6).assertTrue(); + console.info("warm level is: " + warm); + expect(warm >= thermal.ThermalLevel.COOL && warm <= thermal.ThermalLevel.EMERGENCY).assertTrue(); + done(); }) await new Promise((resolve, reject)=>{ setTimeout(()=>{ - thermal.unsubscribeThermalLevel(); + thermal.unsubscribeThermalLevel(() => { + console.info("unsubscribe successfully!"); + }); resolve(); }, MSEC_1000 * 4); }) - done(); }) } function test9() { + const MSEC_1000 = 1000; /* @tc.number thermal_manager_js_009 * @tc.name Thermal_009 @@ -203,20 +218,23 @@ function test9() { it('Thermal_009', 0, async function (done) { thermal.subscribeThermalLevel((hot) => { console.info("hot level is: " + hot); - expect(hot >= 0 && hot <= 6).assertTrue(); + expect(hot >= thermal.ThermalLevel.COOL && hot <= thermal.ThermalLevel.EMERGENCY).assertTrue(); + done(); }) await new Promise((resolve, reject)=>{ setTimeout(()=>{ - thermal.unsubscribeThermalLevel(); + thermal.unsubscribeThermalLevel(() => { + console.info("unsubscribe successfully!"); + }); resolve(); }, MSEC_1000 * 2); }) - done(); }) } function test10() { + const MSEC_1000 = 1000; /* @tc.number thermal_manager_js_010 * @tc.name Thermal_010 @@ -225,19 +243,23 @@ function test10() { it('Thermal_010', 0, async function (done) { thermal.subscribeThermalLevel((overheated) => { console.info("overheated level is: " + overheated); - expect(overheated >= 0 && overheated <= 6).assertTrue(); + expect(overheated >= thermal.ThermalLevel.COOL && + overheated <= thermal.ThermalLevel.EMERGENCY).assertTrue(); + done(); }) await new Promise((resolve, reject)=>{ setTimeout(()=>{ - thermal.unsubscribeThermalLevel(); + thermal.unsubscribeThermalLevel(() => { + console.info("unsubscribe successfully!"); + }); resolve(); }, MSEC_1000 * 2); }) - done(); }) } function test11() { + const MSEC_1000 = 1000; /* @tc.number thermal_manager_js_011 * @tc.name Thermal_011 @@ -246,19 +268,22 @@ function test11() { it('Thermal_011', 0, async function (done) { thermal.subscribeThermalLevel((warning) => { console.info("warning level is: " + warning); - expect(warning >= 0 && warning <= 6).assertTrue(); + expect(warning >= thermal.ThermalLevel.COOL && warning <= thermal.ThermalLevel.EMERGENCY).assertTrue(); + done(); }) await new Promise((resolve, reject)=>{ setTimeout(()=>{ - thermal.unsubscribeThermalLevel(); + thermal.unsubscribeThermalLevel(() => { + console.info("unsubscribe successfully!"); + }); resolve(); }, MSEC_1000 * 4); }) - done(); }) } function test12() { + const MSEC_1000 = 1000; /* @tc.number thermal_manager_js_012 * @tc.name Thermal_012 @@ -267,19 +292,22 @@ function test12() { it('Thermal_012', 0, async function (done) { thermal.subscribeThermalLevel((emergency) => { console.info("emergency level is: " + emergency); - expect(emergency >= 0 && emergency <= 6).assertTrue(); + expect(emergency >= thermal.ThermalLevel.COOL && emergency <= thermal.ThermalLevel.EMERGENCY).assertTrue(); + done(); }) await new Promise((resolve, reject)=>{ setTimeout(()=>{ - thermal.unsubscribeThermalLevel(); + thermal.unsubscribeThermalLevel(() => { + console.info("unsubscribe successfully!"); + }); resolve(); }, MSEC_1000 * 4); }) - done(); }) } function test13() { + const MSEC_1000 = 1000; /* @tc.number thermal_manager_js_013 * @tc.name Thermal_013 @@ -288,14 +316,16 @@ function test13() { it('Thermal_013', 0, async function (done) { thermal.subscribeThermalLevel((cool) => { console.info("cool level is: " + cool); - expect(cool >= 0 && cool <= 6).assertTrue(); + expect(cool >= thermal.ThermalLevel.COOL && cool <= thermal.ThermalLevel.EMERGENCY).assertTrue(); + done(); }) await new Promise((resolve, reject)=>{ setTimeout(()=>{ - thermal.unsubscribeThermalLevel(); + thermal.unsubscribeThermalLevel(() => { + console.info("unsubscribe successfully!"); + }); resolve(); }, MSEC_1000 * 4); }) - done(); }) } \ No newline at end of file diff --git a/powermgr/powermgrthermal/src/main/js/default/test/thermal_unittest.test.js b/powermgr/powermgrthermal/src/main/js/default/test/thermal_unittest.test.js index b3594932878b2c0f8444ef34cdd467bbab1548af..6c31843a264c3dd16d546624d7a54a08566d3048 100644 --- a/powermgr/powermgrthermal/src/main/js/default/test/thermal_unittest.test.js +++ b/powermgr/powermgrthermal/src/main/js/default/test/thermal_unittest.test.js @@ -39,9 +39,9 @@ function test14() { console.info("level is: " + level); expect(level == -1).assertTrue(); resolve(); + done(); }, MSEC_1000 * 4); }) - done(); }) } @@ -55,13 +55,15 @@ function test15() { thermal.subscribeThermalLevel((level) => { console.info("level is: " + level); expect(level == -1).assertTrue(); + done(); }) await new Promise((resolve, reject)=>{ setTimeout(()=>{ - thermal.unsubscribeThermalLevel(); + thermal.unsubscribeThermalLevel(() => { + console.info("unsubscribe successfully!"); + }); resolve(); }, MSEC_1000 * 4); }) - done(); }) } \ No newline at end of file diff --git a/powermgr/powermgrthermal/temp.sh b/powermgr/powermgrthermal/temp.sh index b7d91481b31bf2a8ef91863dc8ddf4da9ccca948..93a945870fa3eac12c6cec0b7f605e61c8166651 100644 --- a/powermgr/powermgrthermal/temp.sh +++ b/powermgr/powermgrthermal/temp.sh @@ -13,24 +13,23 @@ # limitations under the License. count=0 +coldTemp=-22000 +highTemp=40100 output=/data/sensor/battery/temp while ((count < 100)) do - if [ $(($count%4)) == 0 ]; then - temp=-21000 - let "temp = temp + 2000" - echo $temp - echo $temp > $output - sleep 10 + if [ $(($count%2)) == 0 ]; then + let "coldTemp = coldTemp + 1000" + echo $coldTemp + echo $coldTemp > $output + sleep 5 else - temp=40100 - let "temp = temp + 2000" - echo $temp - echo $temp > $output - sleep 10 + let "highTemp = highTemp + 1000" + echo $highTemp + echo $highTemp > $output + sleep 5 fi let "count = count + 1" - echo $count cat $output done \ No newline at end of file