diff --git a/powermgr/BUILD.gn b/powermgr/BUILD.gn index 0437e5fbb010d15095b4f422775fcbc9b5be83db..efdd2e8722583a98f0071b378da99d04f622173c 100755 --- a/powermgr/BUILD.gn +++ b/powermgr/BUILD.gn @@ -21,7 +21,7 @@ group("powermgr") { if (is_standard_system) { deps = [ "powermgrbattery:powermgr_battery_test", - "powermgrbatterystats:powermgr_batterystats_test", + "powermgrthermal:powermgr_thermal_test", ] } } diff --git a/powermgr/powermgrthermal/BUILD.gn b/powermgr/powermgrthermal/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..65797fa6caaceff5b4702241ef1fa01140c5ca9d --- /dev/null +++ b/powermgr/powermgrthermal/BUILD.gn @@ -0,0 +1,31 @@ +# 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("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("powermgr_thermal_test") { + hap_profile = "./src/main/config.json" + deps = [ + ":powermgr_thermal_js_assets", + ":powermgr_thermal_resources", + ] + certificate_profile = "./signature/openharmony_sx.p7b" + hap_name = "ActsPowerMgrThermalTest" +} +ohos_js_assets("powermgr_thermal_js_assets") { + source_dir = "./src/main/js/default" +} +ohos_resources("powermgr_thermal_resources") { + sources = [ "./src/main/resources" ] + hap_profile = "./src/main/config.json" +} diff --git a/powermgr/powermgrthermal/Test.json b/powermgr/powermgrthermal/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..005c0f34c73895318f79d93afb6764d4ee027700 --- /dev/null +++ b/powermgr/powermgrthermal/Test.json @@ -0,0 +1,19 @@ +{ + "description": "Configuration for powermgr thermal Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "60000", + "package": "com.example.mythermalapp", + "shell-timeout": "60000" + }, + "kits": [ + { + "test-file-name": [ + "ActsPowerMgrThermalTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} + diff --git a/powermgr/powermgrthermal/signature/openharmony_sx.p7b b/powermgr/powermgrthermal/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..9be1e98fa4c0c28ca997ed660112fa16b194f0f5 Binary files /dev/null and b/powermgr/powermgrthermal/signature/openharmony_sx.p7b differ diff --git a/powermgr/powermgrthermal/src/main/config.json b/powermgr/powermgrthermal/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..74321b19bb68aa5c1b740efa823e6653aac269b3 --- /dev/null +++ b/powermgr/powermgrthermal/src/main/config.json @@ -0,0 +1,60 @@ +{ + "app": { + "bundleName": "com.example.mythermalapp", + "vendor": "example", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5 + } + }, + "deviceConfig": {}, + "module": { + "package": "com.example.mythermalapp", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "abilities": [ + { + "visible": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "name": "com.example.mythermalapp.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:app_name", + "type": "page", + "launchType": "standard" + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } +} diff --git a/powermgr/powermgrthermal/src/main/js/default/app.js b/powermgr/powermgrthermal/src/main/js/default/app.js new file mode 100644 index 0000000000000000000000000000000000000000..7726f03d9bbb38d87d4397fb60c4fb63d8d57ede --- /dev/null +++ b/powermgr/powermgrthermal/src/main/js/default/app.js @@ -0,0 +1,24 @@ +/* + * 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 device from '@system.device'; + +export default { + onCreate() { + console.info('AceApplication onCreate'); + }, + onDestroy() { + console.info('AceApplication onDestroy'); + } +}; diff --git a/powermgr/powermgrthermal/src/main/js/default/i18n/en-US.json b/powermgr/powermgrthermal/src/main/js/default/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..e63c70d978a3a53be988388c87182f81785e170c --- /dev/null +++ b/powermgr/powermgrthermal/src/main/js/default/i18n/en-US.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + } +} \ No newline at end of file diff --git a/powermgr/powermgrthermal/src/main/js/default/i18n/zh-CN.json b/powermgr/powermgrthermal/src/main/js/default/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..de6ee5748322f44942c1b003319d8e66c837675f --- /dev/null +++ b/powermgr/powermgrthermal/src/main/js/default/i18n/zh-CN.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + } +} \ No newline at end of file diff --git a/powermgr/powermgrthermal/src/main/js/default/pages/index/index.css b/powermgr/powermgrthermal/src/main/js/default/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..6fda792753f2e15f22b529c7b90a82185b2770bf --- /dev/null +++ b/powermgr/powermgrthermal/src/main/js/default/pages/index/index.css @@ -0,0 +1,9 @@ +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 100px; +} diff --git a/powermgr/powermgrthermal/src/main/js/default/pages/index/index.hml b/powermgr/powermgrthermal/src/main/js/default/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..f64b040a5ae394dbaa5e185e1ecd4f4556b92184 --- /dev/null +++ b/powermgr/powermgrthermal/src/main/js/default/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/powermgr/powermgrthermal/src/main/js/default/pages/index/index.js b/powermgr/powermgrthermal/src/main/js/default/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..39b6f425dccb33b8a1aa12fc3b0c1d44505abcfd --- /dev/null +++ b/powermgr/powermgrthermal/src/main/js/default/pages/index/index.js @@ -0,0 +1,42 @@ +/* + * 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 device from '@system.device'; + +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 + }, + onInit() { + device.getInfo({ + success:(data) =>{ + this.width = data.windowWidth; + this.height = data.windowHeight; + } + }); + } +} diff --git a/powermgr/powermgrthermal/src/main/js/default/test/List.test.js b/powermgr/powermgrthermal/src/main/js/default/test/List.test.js new file mode 100644 index 0000000000000000000000000000000000000000..f42c57c0a79c605c81a5a8f2b20f26fc30c2c11c --- /dev/null +++ b/powermgr/powermgrthermal/src/main/js/default/test/List.test.js @@ -0,0 +1,15 @@ +/* + * 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. + */ +require('./thermal_unittest.test.js') \ 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 new file mode 100644 index 0000000000000000000000000000000000000000..1e43cae70d3be3caeedd6c6244faaf5df01164b6 --- /dev/null +++ b/powermgr/powermgrthermal/src/main/js/default/test/thermal_uint.test.js @@ -0,0 +1,301 @@ +/* + * 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 app from '@system.app' +import thermal from "@ohos.thermal" +import ThermalLevel from "@ohos.thermal" +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' + +describe('appInfoTest', function () { + console.log("*************Thermal API Test Begin*************"); + const MSEC_1000 = 1000; + test1(); + test2(); + test3(); + test4(); + test5(); + test6(); + test7(); + test8(); + test9(); + test10(); + test11(); + test12(); + test13(); +}) + +function test1() { + + /* @tc.number thermal_manager_js_001 + * @tc.name Thermal_001 + * @tc.desc Thermal acquisition kit + */ + it('Thermal_001', 0, async function (done) { + console.info("enter"); + await new Promise((resolve, reject) =>{ + setTimeout(()=>{ + var cold = thermal.getThermalLevel(); + console.info("cold level is: " + cold); + expect(cold >= 0 && cold <= 6).assertTrue(); + resolve(); + }, MSEC_1000 * 4); + }) + done(); + }) +} + +function test2() { + + /* @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) => { + setTimeout(()=>{ + var warm = thermal.getThermalLevel(); + console.info("warm level is: " + warm); + expect(warm >= 0 && warm <= 6).assertTrue(); + resolve(); + }, MSEC_1000 * 4); + }) + done(); + }) +} + +function test3() { + + /* @tc.number thermal_manager_js_003 + * @tc.name Thermal_003 + * @tc.desc Thermal acquisition kit + */ + it('Thermal_003', 0, async function (done) { + await new Promise((resolve, reject)=>{ + setTimeout(()=>{ + var hot = thermal.getThermalLevel(); + console.info("hot level is: " + hot); + expect(hot >= 0 && hot <= 6).assertTrue(); + resolve(); + }, MSEC_1000 * 4); + }) + done(); + }) +} + +function test4() { + + /* @tc.number thermal_manager_js_004 + * @tc.name Thermal_004 + * @tc.desc Thermal acquisition kit + */ + it('Thermal_004', 0, async function (done) { + await new Promise((resolve, reject)=>{ + setTimeout(()=>{ + var overheated = thermal.getThermalLevel(); + console.info("overheated level is: " + overheated); + expect(overheated >= 0 && overheated <= 6).assertTrue(); + resolve(); + }, MSEC_1000 * 4); + }) + done(); + }) +} + +function test5() { + + /* @tc.number thermal_manager_js_005 + * @tc.name Thermal_005 + * @tc.desc Thermal acquisition kit + */ + it('Thermal_005', 0, async function (done) { + await new Promise((resolve, reject)=>{ + setTimeout(()=>{ + var warning = thermal.getThermalLevel(); + console.info("warning level is: " + warning); + expect(warning >= 0 && warning <= 6).assertTrue(); + resolve(); + }, MSEC_1000 * 4); + }) + done(); + }) +} + +function test6() { + + /* @tc.number thermal_manager_js_006 + * @tc.name Thermal_006 + * @tc.desc Thermal acquisition kit + */ + it('Thermal_006', 0, async function (done) { + await new Promise((resolve, reject)=>{ + setTimeout(()=>{ + var emergency = thermal.getThermalLevel(); + console.info("emergency level is: " + emergency); + expect(emergency >= 0 && emergency <= 6).assertTrue(); + resolve(); + }, MSEC_1000 * 4); + }) + done(); + }) +} + +function test7() { + + /* @tc.number thermal_manager_js_007 + * @tc.name Thermal_007 + * @tc.desc Thermal acquisition kit + */ + it('Thermal_007', 0, async function (done) { + thermal.subscribeThermalLevel((cool) => { + console.info("cool level is: " + cool); + count ++; + expect(cool >= 0 && cool <= 6).assertTrue(); + }) + await new Promise((resolve, reject)=>{ + setTimeout(()=>{ + thermal.unsubscribeThermalLevel(); + resolve(); + }, MSEC_1000 * 4); + }) + done(); + }) +} + +function test8() { + + /* @tc.number thermal_manager_js_008 + * @tc.name Thermal_008 + * @tc.desc Thermal acquisition kit + */ + it('Thermal_008', 0, async function (done) { + thermal.subscribeThermalLevel((warm) => { + console.info("cool level is: " + warm); + expect(warm >= 0 && warm <= 6).assertTrue(); + }) + await new Promise((resolve, reject)=>{ + setTimeout(()=>{ + thermal.unsubscribeThermalLevel(); + resolve(); + }, MSEC_1000 * 4); + }) + done(); + }) +} + +function test9() { + + /* @tc.number thermal_manager_js_009 + * @tc.name Thermal_009 + * @tc.desc Thermal acquisition kit + */ + it('Thermal_009', 0, async function (done) { + thermal.subscribeThermalLevel((hot) => { + console.info("hot level is: " + hot); + expect(hot >= 0 && hot <= 6).assertTrue(); + }) + await new Promise((resolve, reject)=>{ + setTimeout(()=>{ + thermal.unsubscribeThermalLevel(); + resolve(); + }, MSEC_1000 * 2); + }) + done(); + }) + +} + +function test10() { + + /* @tc.number thermal_manager_js_010 + * @tc.name Thermal_010 + * @tc.desc Thermal acquisition kit + */ + it('Thermal_010', 0, async function (done) { + thermal.subscribeThermalLevel((overheated) => { + console.info("overheated level is: " + overheated); + expect(overheated >= 0 && overheated <= 6).assertTrue(); + }) + await new Promise((resolve, reject)=>{ + setTimeout(()=>{ + thermal.unsubscribeThermalLevel(); + resolve(); + }, MSEC_1000 * 2); + }) + done(); + }) +} + +function test11() { + + /* @tc.number thermal_manager_js_011 + * @tc.name Thermal_011 + * @tc.desc Thermal acquisition kit + */ + it('Thermal_011', 0, async function (done) { + thermal.subscribeThermalLevel((warning) => { + console.info("warning level is: " + warning); + expect(warning >= 0 && warning <= 6).assertTrue(); + }) + await new Promise((resolve, reject)=>{ + setTimeout(()=>{ + thermal.unsubscribeThermalLevel(); + resolve(); + }, MSEC_1000 * 4); + }) + done(); + }) +} + +function test12() { + + /* @tc.number thermal_manager_js_012 + * @tc.name Thermal_012 + * @tc.desc Thermal acquisition kit + */ + it('Thermal_012', 0, async function (done) { + thermal.subscribeThermalLevel((emergency) => { + console.info("emergency level is: " + emergency); + expect(emergency >= 0 && emergency <= 6).assertTrue(); + }) + await new Promise((resolve, reject)=>{ + setTimeout(()=>{ + thermal.unsubscribeThermalLevel(); + resolve(); + }, MSEC_1000 * 4); + }) + done(); + }) +} + +function test13() { + + /* @tc.number thermal_manager_js_013 + * @tc.name Thermal_013 + * @tc.desc Thermal acquisition kit + */ + it('Thermal_013', 0, async function (done) { + thermal.subscribeThermalLevel((cool) => { + console.info("cool level is: " + cool); + expect(cool >= 0 && cool <= 6).assertTrue(); + }) + await new Promise((resolve, reject)=>{ + setTimeout(()=>{ + thermal.unsubscribeThermalLevel(); + 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 new file mode 100644 index 0000000000000000000000000000000000000000..b3594932878b2c0f8444ef34cdd467bbab1548af --- /dev/null +++ b/powermgr/powermgrthermal/src/main/js/default/test/thermal_unittest.test.js @@ -0,0 +1,67 @@ +/* + * 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 app from '@system.app' +import thermal from "@ohos.thermal" +import ThermalLevel from "@ohos.thermal" +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' +const MSEC_1000 = 1000; + +describe('appInfoTest', function () { + console.log("*************Thermal API Test Begin*************"); + test14(); + test15(); +}) + +function test14() { + + /* @tc.number thermal_manager_js_014 + * @tc.name Thermal_014 + * @tc.desc Thermal acquisition kit + */ + it('Thermal_014', 0, async function (done) { + console.info("enter"); + await new Promise((resolve, reject) =>{ + setTimeout(()=>{ + var level = thermal.getThermalLevel(); + console.info("level is: " + level); + expect(level == -1).assertTrue(); + resolve(); + }, MSEC_1000 * 4); + }) + done(); + }) +} + +function test15() { + + /* @tc.number thermal_manager_js_015 + * @tc.name Thermal_015 + * @tc.desc Thermal acquisition kit + */ + it('Thermal_015', 0, async function (done) { + thermal.subscribeThermalLevel((level) => { + console.info("level is: " + level); + expect(level == -1).assertTrue(); + }) + await new Promise((resolve, reject)=>{ + setTimeout(()=>{ + thermal.unsubscribeThermalLevel(); + resolve(); + }, MSEC_1000 * 4); + }) + done(); + }) +} \ No newline at end of file diff --git a/powermgr/powermgrthermal/src/main/resources/base/element/string.json b/powermgr/powermgrthermal/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..83554c4c170fbc25754272b646b6291df70afba5 --- /dev/null +++ b/powermgr/powermgrthermal/src/main/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "app_name", + "value": "MyThermalApp" + }, + { + "name": "mainability_description", + "value": "JS_Phone_Empty Feature Ability" + } + ] +} \ No newline at end of file diff --git a/powermgr/powermgrthermal/src/main/resources/base/media/icon.png b/powermgr/powermgrthermal/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/powermgr/powermgrthermal/src/main/resources/base/media/icon.png differ diff --git a/powermgr/powermgrthermal/temp.sh b/powermgr/powermgrthermal/temp.sh new file mode 100644 index 0000000000000000000000000000000000000000..b7d91481b31bf2a8ef91863dc8ddf4da9ccca948 --- /dev/null +++ b/powermgr/powermgrthermal/temp.sh @@ -0,0 +1,36 @@ +#!/bin/bash +# 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. + +count=0 +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 + else + temp=40100 + let "temp = temp + 2000" + echo $temp + echo $temp > $output + sleep 10 + fi + let "count = count + 1" + echo $count + cat $output +done \ No newline at end of file