1/*
2 * Copyright (C) 2022 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 */
15
16import { CpuUsage, Freq } from '../../../src/trace/bean/CpuUsage';
17
18describe('CpuUsage Test', () => {
19  let cpuUsage = new CpuUsage();
20  let freq = new Freq();
21
22  it('CpuUsageTest01', function () {
23    cpuUsage = {
24      cpu: 0,
25      usage: 0,
26      usageStr: '',
27      top1: 0,
28      top2: 0,
29      top3: 0,
30      top1Percent: 0,
31      top1PercentStr: '',
32      top2Percent: 0,
33      top2PercentStr: '',
34      top3Percent: 0,
35      top3PercentStr: '',
36    };
37    expect(cpuUsage).not.toBeUndefined();
38    expect(cpuUsage).toMatchInlineSnapshot(
39{
40  cpu: expect.any(Number),
41  usage: expect.any(Number),
42  usageStr: expect.any(String),
43  top1: expect.any(Number),
44  top2: expect.any(Number),
45  top3: expect.any(Number),
46  top1Percent: expect.any(Number),
47  top1PercentStr: expect.any(String),
48  top2Percent: expect.any(Number),
49  top2PercentStr: expect.any(String),
50  top3Percent: expect.any(Number),
51  top3PercentStr: expect.any(String) }, `
52{
53  "cpu": Any<Number>,
54  "top1": Any<Number>,
55  "top1Percent": Any<Number>,
56  "top1PercentStr": Any<String>,
57  "top2": Any<Number>,
58  "top2Percent": Any<Number>,
59  "top2PercentStr": Any<String>,
60  "top3": Any<Number>,
61  "top3Percent": Any<Number>,
62  "top3PercentStr": Any<String>,
63  "usage": Any<Number>,
64  "usageStr": Any<String>,
65}
66`);
67  });
68
69  it('CpuUsageTest02', function () {
70    cpuUsage = {
71      cpu: 0,
72      value: 0,
73      startNs: 0,
74      dur: 0,
75    };
76    expect(freq).not.toBeUndefined();
77    expect(cpuUsage).toMatchInlineSnapshot(
78{
79  cpu: expect.any(Number),
80  value: expect.any(Number),
81  startNs: expect.any(Number),
82  dur: expect.any(Number) }, `
83{
84  "cpu": Any<Number>,
85  "dur": Any<Number>,
86  "startNs": Any<Number>,
87  "value": Any<Number>,
88}
89`);
90  });
91});
92