• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2021 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 */
15import bytrace from "@ohos.bytrace"
16import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
17export default function BytraceTest() {
18describe("BytraceTest", function () {
19
20    it("DFX_DFR_Bytrace_0100", 0, async function (done) {
21        console.info("-------DFX_DFR_Bytrace_0100 start--------");
22        for (var i = 0; i < 3; i++) {
23            console.info("DFX_DFR_Bytrace_0100 i = " + i)
24            console.info("DFX_DFR_Bytrace_0100 " + i.toString() + " startTrace start");
25            bytrace.startTrace("test-" + i.toString(), 111 + i, 5000);
26            console.info("DFX_DFR_Bytrace_0100 " + i.toString() + "startTrace end");
27            console.info("DFX_DFR_Bytrace_0100 " + i.toString() + " finishTrace start");
28            bytrace.finishTrace("test-" + i.toString(), 111 + i);
29            console.info("DFX_DFR_Bytrace_0100 " + i.toString() + "finishTrace end");
30        }
31
32        console.info("DFX_DFR_Bytrace_0100 end");
33        done();
34    })
35
36    it("DFX_DFR_Bytrace_0200", 0, async function (done) {
37        console.info("------DFX_DFR_Bytrace_0200 start------");
38        // Normal condition
39        let flag = false;
40        try {
41            console.info("DFX_DFR_Bytrace_0200 1 start");
42            bytrace.startTrace("test2", 222);
43            expect(true).assertTrue();
44            console.info("DFX_DFR_Bytrace_0200 1 success");
45        } catch (err) {
46            console.info("DFX_DFR_Bytrace_0200 1 fail!");
47            console.info("DFX_DFR_Bytrace_0200 1 err = " + err);
48            expect(false).assertTrue();
49        }
50        // Abnormal condition, Pass only one parameter
51        try {
52            console.info("DFX_DFR_Bytrace_0200 2 start");
53            bytrace.startTrace("test2");
54            expect(flag).assertFalse();
55        } catch (err) {
56            flag = true;
57            console.info("DFX_DFR_Bytrace_0200 2 fail!");
58            console.info("DFX_DFR_Bytrace_0200 2 err = " + err);
59            expect(flag).assertTrue();
60        }
61        // Abnormal condition, Pass multiple parameters
62        flag = false;
63        try {
64            console.info("DFX_DFR_Bytrace_0200 3 start");
65            bytrace.startTrace("test2", 222, 2000, 2);
66            expect(flag).assertFalse();
67        } catch (err) {
68            flag = true;
69            console.info("DFX_DFR_Bytrace_0200 3 fail!");
70            console.info("DFX_DFR_Bytrace_0200 3 err = " + err);
71            expect(flag).assertTrue();
72        }
73        // Abnormal condition, Parameter format mismatch
74        flag = false;
75        try {
76            console.info("DFX_DFR_Bytrace_0200 4 start");
77            bytrace.startTrace(2, "222", "2000");
78            expect(flag).assertFalse();
79        } catch (err) {
80            flag = true;
81            console.info("DFX_DFR_Bytrace_0200 4 fail!");
82            console.info("DFX_DFR_Bytrace_0200 4 err = " + err);
83            expect(flag).assertTrue();
84        }
85        console.info("------DFX_DFR_Bytrace_0200 end------");
86        done();
87    })
88
89    it("DFX_DFR_Bytrace_0300", 0, async function (done) {
90        console.info("------DFX_DFR_Bytrace_0300 start------");
91        // Normal condition
92        let flag = false;
93        try {
94            console.info("DFX_DFR_Bytrace_0300 1 start")
95            bytrace.finishTrace("test3", 111);
96            expect(true).assertTrue();
97            console.info("DFX_DFR_Bytrace_0300 1 success");
98        } catch (err) {
99            console.info("DFX_DFR_Bytrace_0300 1 fail!");
100            console.info("DFX_DFR_Bytrace_0300 1 err = " + err);
101            expect(false).assertTrue();
102        }
103        // Abnormal condition, Pass only one parameter
104        try {
105            console.info("DFX_DFR_Bytrace_0300 2 start")
106            bytrace.finishTrace("test3");
107            expect(flag).assertFalse();
108        } catch (err) {
109            flag = true;
110            console.info("DFX_DFR_Bytrace_0300 2 fail!");
111            console.info("DFX_DFR_Bytrace_0300 2 err = " + err);
112            expect(flag).assertTrue();
113        }
114        // Abnormal condition, Pass multiple parameters
115        flag = false;
116        try {
117            console.info("DFX_DFR_Bytrace_0300 3 start")
118            bytrace.finishTrace("test3", 1, 1);
119            expect(flag).assertFalse();
120        } catch (err) {
121            flag = true;
122            console.info("DFX_DFR_Bytrace_0300 3 fail!");
123            console.info("DFX_DFR_Bytrace_0300 3 err = " + err);
124            expect(flag).assertTrue();
125        }
126        // Abnormal condition, Parameter format mismatch
127        flag = false;
128        try {
129            console.info("DFX_DFR_Bytrace_0300 4 start")
130            bytrace.finishTrace(1, "123");
131            expect(flag).assertFalse();
132        } catch (err) {
133            flag = true;
134            console.info("DFX_DFR_Bytrace_0300 4 fail!");
135            console.info("DFX_DFR_Bytrace_0300 4 err = " + err);
136            expect(flag).assertTrue();
137        }
138        console.info("------DFX_DFR_Bytrace_0300 end------");
139        done();
140    })
141
142    it("DFX_DFR_Bytrace_0400", 0, async function (done) {
143        console.info("-------DFX_DFR_Bytrace_0400 start--------");
144        for (var i = 0; i < 3; i++) {
145            console.info("DFX_DFR_Bytrace_0400 :" + i);
146            bytrace.traceByValue("test4-" + i.toString(), 3 + i);
147        }
148        console.info("DFX_DFR_Bytrace_0400 end");
149        done();
150    })
151
152    it("DFX_DFR_Bytrace_0500", 0, async function (done) {
153        console.info("-------DFX_DFR_Bytrace_0500 start--------");
154        // Normal condition
155        let flag = false;
156        try {
157            console.info("DFX_DFR_Bytrace_0500 1 start")
158            bytrace.traceByValue("test5", 5);
159            expect(true).assertTrue();
160            console.info("DFX_DFR_Bytrace_0500 1 success")
161        } catch (err) {
162            console.info("DFX_DFR_Bytrace_0500 1 fail!");
163            console.info("DFX_DFR_Bytrace_0500 1 err = " + err);
164            expect(false).assertTrue();
165        }
166        // Abnormal condition, Pass only one parameter
167        try {
168            console.info("DFX_DFR_Bytrace_0500 2 start")
169            bytrace.traceByValue("test5");
170            expect(flag).assertFalse();
171        } catch (err) {
172            flag = true;
173            console.info("DFX_DFR_Bytrace_0500 2 fail!");
174            console.info("DFX_DFR_Bytrace_0500 2 err = " + err);
175            expect(flag).assertTrue();
176        }
177        // Abnormal condition, Pass multiple parameters
178        flag = false;
179        try {
180            console.info("DFX_DFR_Bytrace_0500 3 start")
181            bytrace.traceByValue("test5", 3, 1);
182            expect(flag).assertFalse();
183        } catch (err) {
184            flag = true;
185            console.info("DFX_DFR_Bytrace_0500 3 fail!");
186            console.info("DFX_DFR_Bytrace_0500 3 err = " + err);
187            expect(flag).assertTrue();
188        }
189        // Abnormal condition, Parameter format mismatch
190        flag = false;
191        try {
192            console.info("DFX_DFR_Bytrace_0500 4 start")
193            bytrace.traceByValue(1, "123");
194            expect(flag).assertFalse();
195        } catch (err) {
196            flag = true;
197            console.info("DFX_DFR_Bytrace_0500 4 fail!");
198            console.info("DFX_DFR_Bytrace_0500 4 err = " + err);
199            expect(flag).assertTrue();
200        }
201        console.info("------DFX_DFR_Bytrace_0500 end------");
202        done();
203    })
204
205})
206}