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 {
17  chartCpuStateDataSql,
18  chartCpuStateDataSqlMem, cpuStateReceiver
19} from '../../../../../src/trace/database/data-trafic/cpu/CpuStateReceiver';
20
21describe('CpuStateReceiver Test', () => {
22  let data = {
23    id: '55348b85-5aa9-4e99-86fc-acb2d6f438fe',
24    name: 1,
25    action: 'exec-proto',
26    params: {
27      startTs: 1,
28      filterId: 3,
29      startNS: 0,
30      endNS: 9427688540,
31      recordStartNS: 4049847357191,
32      recordEndNS: 4059275045731,
33      width: 491,
34      trafic: 2,
35    }
36  };
37  let CpuStateData = [{
38      value: 0,
39      dur: 193229,
40      height: 4,
41      startTs: 6992644791,
42      cpu: 1,
43      frame: {
44        y: 5,
45        height: 30,
46        x: 364,
47        width: 1
48      }
49  }]
50  it('CpuStateReceiverTest01 ', function () {
51    const args = {
52      recordStartNS: 1000,
53      endNS: 3000,
54      startNS: 2000,
55      width: 10,
56      filterId: 1,
57    };
58    expect(chartCpuStateDataSql(args)).toBeTruthy();
59    expect(chartCpuStateDataSqlMem(args)).toBeTruthy();
60  });
61  it('CpuStateReceiverTest02 ', function () {
62    (self as unknown as Worker).postMessage = jest.fn(() => true);
63    expect(cpuStateReceiver(data, () => {
64      return CpuStateData;
65    })).toBeUndefined();
66  });
67});