1fb726d48Sopenharmony_ci/*
2fb726d48Sopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd.
3fb726d48Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4fb726d48Sopenharmony_ci * you may not use this file except in compliance with the License.
5fb726d48Sopenharmony_ci * You may obtain a copy of the License at
6fb726d48Sopenharmony_ci *
7fb726d48Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8fb726d48Sopenharmony_ci *
9fb726d48Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10fb726d48Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11fb726d48Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12fb726d48Sopenharmony_ci * See the License for the specific language governing permissions and
13fb726d48Sopenharmony_ci * limitations under the License.
14fb726d48Sopenharmony_ci */
15fb726d48Sopenharmony_ci
16fb726d48Sopenharmony_ciimport {
17fb726d48Sopenharmony_ci  abilityBytesInTraceDataProtoSql, abilityBytesInTraceDataReceiver,
18fb726d48Sopenharmony_ci  abilityBytesOutTraceDataProtoSql, abilityBytesOutTraceDataReceiver,
19fb726d48Sopenharmony_ci  abilityBytesReadDataProtoSql, abilityBytesReadDataReceiver,
20fb726d48Sopenharmony_ci  abilityBytesWrittenDataProtoSql, abilityBytesWrittenDataReceiver,
21fb726d48Sopenharmony_ci  abilityMemoryDataProtoSql, abilityMemoryUsedDataReceiver,
22fb726d48Sopenharmony_ci  abilityPacketInDataProtoSql, abilityPacketInTraceDataReceiver,
23fb726d48Sopenharmony_ci  abilityPacketsOutDataProtoSql, abilityPacketsOutTraceDataReceiver,
24fb726d48Sopenharmony_ci  abilityReadOpsDataProtoSql, abilityReadOpsDataReceiver,
25fb726d48Sopenharmony_ci  abilityWrittenOpsDataProtoSql, abilityWrittenOpsDataReceiver,
26fb726d48Sopenharmony_ci  cpuAbilityMonitorDataProtoSql, cpuAbilityMonitorDataReceiver,
27fb726d48Sopenharmony_ci  cpuAbilitySystemDataProtoSql, cpuAbilitySystemDataReceiver,
28fb726d48Sopenharmony_ci  cpuAbilityUserDataProtoSql, cpuAbilityUserDataReceiver
29fb726d48Sopenharmony_ci} from '../../../../src/trace/database/data-trafic/AbilityMonitorReceiver';
30fb726d48Sopenharmony_ciimport { TraficEnum } from '../../../../src/trace/database/data-trafic/utils/QueryEnum';
31fb726d48Sopenharmony_ci
32fb726d48Sopenharmony_cidescribe('AbilityMonitorReceiver Test', () => {
33fb726d48Sopenharmony_ci  let data;
34fb726d48Sopenharmony_ci  let proc;
35fb726d48Sopenharmony_ci
36fb726d48Sopenharmony_ci  beforeEach(() => {
37fb726d48Sopenharmony_ci    data = {
38fb726d48Sopenharmony_ci      params: {
39fb726d48Sopenharmony_ci        trafic: TraficEnum.ProtoBuffer,
40fb726d48Sopenharmony_ci        sharedArrayBuffers: {
41fb726d48Sopenharmony_ci          id: new Uint16Array([1, 2, 3]),
42fb726d48Sopenharmony_ci        },
43fb726d48Sopenharmony_ci      },
44fb726d48Sopenharmony_ci    };
45fb726d48Sopenharmony_ci    proc = jest.fn((sql) => [
46fb726d48Sopenharmony_ci      {abilityData: {id: 4, startNs: 4.4, pid: 40, tid: 400, dur: 40000, depth: 4}},
47fb726d48Sopenharmony_ci      {abilityData: {id: 5, startNs: 5.5, pid: 50, tid: 500, dur: 50000, depth: 5}},
48fb726d48Sopenharmony_ci    ]);
49fb726d48Sopenharmony_ci  });
50fb726d48Sopenharmony_ci  it('AbilityMonitorReceiverTest01', () => {
51fb726d48Sopenharmony_ci    const args = {
52fb726d48Sopenharmony_ci      recordStartNS: 1000,
53fb726d48Sopenharmony_ci      endNS: 3000,
54fb726d48Sopenharmony_ci      startNS: 2000,
55fb726d48Sopenharmony_ci      width: 10
56fb726d48Sopenharmony_ci    };
57fb726d48Sopenharmony_ci    expect(cpuAbilityMonitorDataProtoSql(args)).toBeTruthy();
58fb726d48Sopenharmony_ci    expect(cpuAbilityUserDataProtoSql(args)).toBeTruthy();
59fb726d48Sopenharmony_ci    expect(cpuAbilitySystemDataProtoSql(args)).toBeTruthy();
60fb726d48Sopenharmony_ci    expect(abilityMemoryDataProtoSql(args)).toBeTruthy();
61fb726d48Sopenharmony_ci    expect(abilityBytesReadDataProtoSql(args)).toBeTruthy();
62fb726d48Sopenharmony_ci    expect(abilityBytesWrittenDataProtoSql(args)).toBeTruthy();
63fb726d48Sopenharmony_ci    expect(abilityReadOpsDataProtoSql(args)).toBeTruthy();
64fb726d48Sopenharmony_ci    expect(abilityWrittenOpsDataProtoSql(args)).toBeTruthy();
65fb726d48Sopenharmony_ci    expect(abilityBytesInTraceDataProtoSql(args)).toBeTruthy();
66fb726d48Sopenharmony_ci    expect(abilityBytesOutTraceDataProtoSql(args)).toBeTruthy();
67fb726d48Sopenharmony_ci    expect(abilityPacketInDataProtoSql(args)).toBeTruthy();
68fb726d48Sopenharmony_ci    expect(abilityPacketsOutDataProtoSql(args)).toBeTruthy();
69fb726d48Sopenharmony_ci  });
70fb726d48Sopenharmony_ci  it('AbilityMonitorReceiverTest02', () => {
71fb726d48Sopenharmony_ci    let mockPostMessage = jest.fn();
72fb726d48Sopenharmony_ci    global.postMessage = mockPostMessage;
73fb726d48Sopenharmony_ci    abilityMemoryUsedDataReceiver(data, proc);
74fb726d48Sopenharmony_ci    abilityBytesReadDataReceiver(data, proc);
75fb726d48Sopenharmony_ci    abilityBytesWrittenDataReceiver(data, proc);
76fb726d48Sopenharmony_ci    abilityReadOpsDataReceiver(data, proc);
77fb726d48Sopenharmony_ci    abilityWrittenOpsDataReceiver(data, proc);
78fb726d48Sopenharmony_ci    abilityBytesInTraceDataReceiver(data, proc);
79fb726d48Sopenharmony_ci    abilityBytesOutTraceDataReceiver(data, proc);
80fb726d48Sopenharmony_ci    abilityPacketInTraceDataReceiver(data, proc);
81fb726d48Sopenharmony_ci    abilityPacketsOutTraceDataReceiver(data, proc);
82fb726d48Sopenharmony_ci
83fb726d48Sopenharmony_ci    expect(mockPostMessage).toHaveBeenCalledTimes(9);
84fb726d48Sopenharmony_ci  });
85fb726d48Sopenharmony_ci  it('AbilityMonitorReceiverTest03', () => {
86fb726d48Sopenharmony_ci    let cpuAbilityData = {
87fb726d48Sopenharmony_ci      params: {
88fb726d48Sopenharmony_ci        trafic: TraficEnum.ProtoBuffer,
89fb726d48Sopenharmony_ci        sharedArrayBuffers: {
90fb726d48Sopenharmony_ci          id: new Uint16Array([1, 2, 3]),
91fb726d48Sopenharmony_ci        },
92fb726d48Sopenharmony_ci      },
93fb726d48Sopenharmony_ci    };
94fb726d48Sopenharmony_ci    let cpuAbilityProc = jest.fn((sql) => [
95fb726d48Sopenharmony_ci      {cpuAbilityData: {id: 4, startNs: 4.4, pid: 40, tid: 400, dur: 40000, depth: 4}},
96fb726d48Sopenharmony_ci      {cpuAbilityData: {id: 5, startNs: 5.5, pid: 50, tid: 500, dur: 50000, depth: 5}},
97fb726d48Sopenharmony_ci    ]);
98fb726d48Sopenharmony_ci    let mockPostMessage = jest.fn();
99fb726d48Sopenharmony_ci    global.postMessage = mockPostMessage;
100fb726d48Sopenharmony_ci    cpuAbilityMonitorDataReceiver(cpuAbilityData, cpuAbilityProc);
101fb726d48Sopenharmony_ci    cpuAbilityUserDataReceiver(cpuAbilityData, cpuAbilityProc);
102fb726d48Sopenharmony_ci    cpuAbilitySystemDataReceiver(cpuAbilityData, cpuAbilityProc);
103fb726d48Sopenharmony_ci    expect(mockPostMessage).toHaveBeenCalledTimes(3);
104fb726d48Sopenharmony_ci  });
105fb726d48Sopenharmony_ci});