bytrace_test.js 7.9 KB
Newer Older
J
jiyong 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * Copyright (C) 2021 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 bytrace from "@ohos.bytrace"
J
jiyong_sd 已提交
16 17
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
export default function BytraceTest() {
J
jiyong 已提交
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
describe("BytraceTest", function () {

    it("DFX_DFR_Bytrace_0100", 0, async function (done) {
        console.info("-------DFX_DFR_Bytrace_0100 start--------");
        for (var i = 0; i < 3; i++) {
            console.info("DFX_DFR_Bytrace_0100 i = " + i)
            console.info("DFX_DFR_Bytrace_0100 " + i.toString() + " startTrace start");
            bytrace.startTrace("test-" + i.toString(), 111 + i, 5000);
            console.info("DFX_DFR_Bytrace_0100 " + i.toString() + "startTrace end");
            console.info("DFX_DFR_Bytrace_0100 " + i.toString() + " finishTrace start");
            bytrace.finishTrace("test-" + i.toString(), 111 + i);
            console.info("DFX_DFR_Bytrace_0100 " + i.toString() + "finishTrace end");
        }

        console.info("DFX_DFR_Bytrace_0100 end");
        done();
    })

    it("DFX_DFR_Bytrace_0200", 0, async function (done) {
        console.info("------DFX_DFR_Bytrace_0200 start------");
        // Normal condition
C
chenxuihui 已提交
39
        let flag = false;
J
jiyong 已提交
40 41 42 43 44 45 46 47 48 49 50 51 52 53
        try {
            console.info("DFX_DFR_Bytrace_0200 1 start");
            bytrace.startTrace("test2", 222);
            expect(true).assertTrue();
            console.info("DFX_DFR_Bytrace_0200 1 success");
        } catch (err) {
            console.info("DFX_DFR_Bytrace_0200 1 fail!");
            console.info("DFX_DFR_Bytrace_0200 1 err = " + err);
            expect(false).assertTrue();
        }
        // Abnormal condition, Pass only one parameter
        try {
            console.info("DFX_DFR_Bytrace_0200 2 start");
            bytrace.startTrace("test2");
C
chenxuihui 已提交
54
            expect(flag).assertFalse();
J
jiyong 已提交
55
        } catch (err) {
C
chenxuihui 已提交
56
            flag = true;
J
jiyong 已提交
57 58
            console.info("DFX_DFR_Bytrace_0200 2 fail!");
            console.info("DFX_DFR_Bytrace_0200 2 err = " + err);
C
chenxuihui 已提交
59
            expect(flag).assertTrue();
J
jiyong 已提交
60 61
        }
        // Abnormal condition, Pass multiple parameters
C
chenxuihui 已提交
62
        flag = false;
J
jiyong 已提交
63 64 65
        try {
            console.info("DFX_DFR_Bytrace_0200 3 start");
            bytrace.startTrace("test2", 222, 2000, 2);
C
chenxuihui 已提交
66
            expect(flag).assertFalse();
J
jiyong 已提交
67
        } catch (err) {
C
chenxuihui 已提交
68
            flag = true;
J
jiyong 已提交
69 70
            console.info("DFX_DFR_Bytrace_0200 3 fail!");
            console.info("DFX_DFR_Bytrace_0200 3 err = " + err);
C
chenxuihui 已提交
71
            expect(flag).assertTrue();
J
jiyong 已提交
72 73
        }
        // Abnormal condition, Parameter format mismatch
C
chenxuihui 已提交
74
        flag = false;
J
jiyong 已提交
75 76 77
        try {
            console.info("DFX_DFR_Bytrace_0200 4 start");
            bytrace.startTrace(2, "222", "2000");
C
chenxuihui 已提交
78
            expect(flag).assertFalse();
J
jiyong 已提交
79
        } catch (err) {
C
chenxuihui 已提交
80
            flag = true;
J
jiyong 已提交
81 82
            console.info("DFX_DFR_Bytrace_0200 4 fail!");
            console.info("DFX_DFR_Bytrace_0200 4 err = " + err);
C
chenxuihui 已提交
83
            expect(flag).assertTrue();
J
jiyong 已提交
84 85 86 87 88 89 90 91
        }
        console.info("------DFX_DFR_Bytrace_0200 end------");
        done();
    })

    it("DFX_DFR_Bytrace_0300", 0, async function (done) {
        console.info("------DFX_DFR_Bytrace_0300 start------");
        // Normal condition
C
chenxuihui 已提交
92
        let flag = false;
J
jiyong 已提交
93 94 95 96 97 98 99 100 101 102 103 104 105 106
        try {
            console.info("DFX_DFR_Bytrace_0300 1 start")
            bytrace.finishTrace("test3", 111);
            expect(true).assertTrue();
            console.info("DFX_DFR_Bytrace_0300 1 success");
        } catch (err) {
            console.info("DFX_DFR_Bytrace_0300 1 fail!");
            console.info("DFX_DFR_Bytrace_0300 1 err = " + err);
            expect(false).assertTrue();
        }
        // Abnormal condition, Pass only one parameter
        try {
            console.info("DFX_DFR_Bytrace_0300 2 start")
            bytrace.finishTrace("test3");
C
chenxuihui 已提交
107
            expect(flag).assertFalse();
J
jiyong 已提交
108
        } catch (err) {
C
chenxuihui 已提交
109
            flag = true;
J
jiyong 已提交
110 111
            console.info("DFX_DFR_Bytrace_0300 2 fail!");
            console.info("DFX_DFR_Bytrace_0300 2 err = " + err);
C
chenxuihui 已提交
112
            expect(flag).assertTrue();
J
jiyong 已提交
113 114
        }
        // Abnormal condition, Pass multiple parameters
C
chenxuihui 已提交
115
        flag = false;
J
jiyong 已提交
116 117 118
        try {
            console.info("DFX_DFR_Bytrace_0300 3 start")
            bytrace.finishTrace("test3", 1, 1);
C
chenxuihui 已提交
119
            expect(flag).assertFalse();
J
jiyong 已提交
120
        } catch (err) {
C
chenxuihui 已提交
121
            flag = true;
J
jiyong 已提交
122 123
            console.info("DFX_DFR_Bytrace_0300 3 fail!");
            console.info("DFX_DFR_Bytrace_0300 3 err = " + err);
C
chenxuihui 已提交
124
            expect(flag).assertTrue();
J
jiyong 已提交
125 126
        }
        // Abnormal condition, Parameter format mismatch
C
chenxuihui 已提交
127
        flag = false;
J
jiyong 已提交
128 129 130
        try {
            console.info("DFX_DFR_Bytrace_0300 4 start")
            bytrace.finishTrace(1, "123");
C
chenxuihui 已提交
131
            expect(flag).assertFalse();
J
jiyong 已提交
132
        } catch (err) {
C
chenxuihui 已提交
133
            flag = true;
J
jiyong 已提交
134 135
            console.info("DFX_DFR_Bytrace_0300 4 fail!");
            console.info("DFX_DFR_Bytrace_0300 4 err = " + err);
C
chenxuihui 已提交
136
            expect(flag).assertTrue();
J
jiyong 已提交
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
        }
        console.info("------DFX_DFR_Bytrace_0300 end------");
        done();
    })

    it("DFX_DFR_Bytrace_0400", 0, async function (done) {
        console.info("-------DFX_DFR_Bytrace_0400 start--------");
        for (var i = 0; i < 3; i++) {
            console.info("DFX_DFR_Bytrace_0400 :" + i);
            bytrace.traceByValue("test4-" + i.toString(), 3 + i);
        }
        console.info("DFX_DFR_Bytrace_0400 end");
        done();
    })

    it("DFX_DFR_Bytrace_0500", 0, async function (done) {
        console.info("-------DFX_DFR_Bytrace_0500 start--------");
        // Normal condition
C
chenxuihui 已提交
155
        let flag = false;
J
jiyong 已提交
156 157 158 159 160 161 162 163 164 165 166 167 168 169
        try {
            console.info("DFX_DFR_Bytrace_0500 1 start")
            bytrace.traceByValue("test5", 5);
            expect(true).assertTrue();
            console.info("DFX_DFR_Bytrace_0500 1 success")
        } catch (err) {
            console.info("DFX_DFR_Bytrace_0500 1 fail!");
            console.info("DFX_DFR_Bytrace_0500 1 err = " + err);
            expect(false).assertTrue();
        }
        // Abnormal condition, Pass only one parameter
        try {
            console.info("DFX_DFR_Bytrace_0500 2 start")
            bytrace.traceByValue("test5");
C
chenxuihui 已提交
170
            expect(flag).assertFalse();
J
jiyong 已提交
171
        } catch (err) {
C
chenxuihui 已提交
172
            flag = true;
J
jiyong 已提交
173 174
            console.info("DFX_DFR_Bytrace_0500 2 fail!");
            console.info("DFX_DFR_Bytrace_0500 2 err = " + err);
C
chenxuihui 已提交
175
            expect(flag).assertTrue();
J
jiyong 已提交
176 177
        }
        // Abnormal condition, Pass multiple parameters
C
chenxuihui 已提交
178
        flag = false;
J
jiyong 已提交
179 180 181
        try {
            console.info("DFX_DFR_Bytrace_0500 3 start")
            bytrace.traceByValue("test5", 3, 1);
C
chenxuihui 已提交
182
            expect(flag).assertFalse();
J
jiyong 已提交
183
        } catch (err) {
C
chenxuihui 已提交
184
            flag = true;
J
jiyong 已提交
185 186
            console.info("DFX_DFR_Bytrace_0500 3 fail!");
            console.info("DFX_DFR_Bytrace_0500 3 err = " + err);
C
chenxuihui 已提交
187
            expect(flag).assertTrue();
J
jiyong 已提交
188 189
        }
        // Abnormal condition, Parameter format mismatch
C
chenxuihui 已提交
190
        flag = false;
J
jiyong 已提交
191 192 193
        try {
            console.info("DFX_DFR_Bytrace_0500 4 start")
            bytrace.traceByValue(1, "123");
C
chenxuihui 已提交
194
            expect(flag).assertFalse();
J
jiyong 已提交
195
        } catch (err) {
C
chenxuihui 已提交
196
            flag = true;
J
jiyong 已提交
197 198
            console.info("DFX_DFR_Bytrace_0500 4 fail!");
            console.info("DFX_DFR_Bytrace_0500 4 err = " + err);
C
chenxuihui 已提交
199
            expect(flag).assertTrue();
J
jiyong 已提交
200 201 202 203 204
        }
        console.info("------DFX_DFR_Bytrace_0500 end------");
        done();
    })

J
jiyong_sd 已提交
205 206
})
}