thermal_performance.test.js 2.8 KB
Newer Older
Y
yu.xu 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
 * 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"
17
import { describe, it, expect } from 'deccjsunit/index';
Y
yu.xu 已提交
18 19 20 21 22 23 24 25 26 27

describe('appInfoTest', function () {
    console.log("*************Thermal Performance Test Begin*************");
    performanceTest1();
    performanceTest2();
    performanceTest3();
    console.log("*************Thermal Performance Test End*************");
})

function performanceTest1() {
28
    let MAXNUM = 1000;
Y
yu.xu 已提交
29 30 31 32 33 34 35 36 37

    /**
     * @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++) {
38
            let level = thermal.getThermalLevel();
Y
yu.xu 已提交
39 40 41 42 43 44 45 46
        }
        let waitTime = new Date().getTime() - startTime;
        let avgTime = waitTime; //us
        console.info(`ThermalPerformance_001: Promise: getlevel Wait Time :  ${waitTime}`);
    })
}

function performanceTest2() {
47
    let MAXNUM = 1000;
Y
yu.xu 已提交
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67

    /**
     * @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() {
68
    let MAXNUM = 1000;
Y
yu.xu 已提交
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84

    /**
     * @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}`);
    })
}