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  diskIoDataGroupBy10MSProtoSql,
18  diskIoDataProtoSql,
19  diskIoReceiver,
20  eBPFVmDataGroupBy10MSProtoSql,
21  eBPFVmDataProtoSql,
22  eBPFVmReceiver,
23  fileSystemDataGroupBy10MSProtoSql,
24  fileSystemDataProtoSql,
25  fileSystemDataReceiver
26} from '../../../../src/trace/database/data-trafic/EBPFReceiver';
27import { TraficEnum } from '../../../../src/trace/database/data-trafic/utils/QueryEnum';
28
29describe('EBPFReceiver Test', () => {
30  let data;
31  let proc;
32
33  beforeEach(() => {
34    data = {
35      params: {
36        trafic: TraficEnum.ProtoBuffer,
37        sharedArrayBuffers: {
38          id: new Uint16Array([1, 2, 3]),
39        },
40        typeArr:[]
41      },
42    };
43    proc = jest.fn((sql) => [
44      {EBPFVm: {startNs: 440000000, endNs: 450000000, size: 4, px: 172}},
45      {EBPFVm: {startNs: 450000000, endNs: 460000000, size: 3, px: 176}},
46    ]);
47  });
48  it('EBPFReceiverTest01 ', function () {
49    const args = {
50      recordStartNS: 1000,
51      endNS: 3000,
52      startNS: 2000,
53      width: 10,
54      typeArr:[]
55    };
56    expect(fileSystemDataGroupBy10MSProtoSql(args)).toBeTruthy();
57    expect(fileSystemDataProtoSql(args)).toBeTruthy();
58    expect(diskIoDataGroupBy10MSProtoSql (args)).toBeTruthy();
59    expect(diskIoDataProtoSql  (args)).toBeTruthy();
60    expect(eBPFVmDataGroupBy10MSProtoSql   (args)).toBeTruthy();
61    expect(eBPFVmDataProtoSql   (args)).toBeTruthy();
62  });
63  it('EBPFReceiverTest02 ', function () {
64    const mockPostMessage = jest.fn();
65    global.postMessage = mockPostMessage;
66    fileSystemDataReceiver(data, proc);
67    expect(mockPostMessage).toHaveBeenCalledTimes(1);
68  });
69  it('EBPFReceiverTest03 ', function () {
70    const mockPostMessage = jest.fn();
71    global.postMessage = mockPostMessage;
72    diskIoReceiver(data, proc);
73    expect(mockPostMessage).toHaveBeenCalledTimes(1);
74  });
75  it('EBPFReceiverTest04 ', function () {
76    const mockPostMessage = jest.fn();
77    global.postMessage = mockPostMessage;
78    eBPFVmReceiver(data, proc);
79    expect(mockPostMessage).toHaveBeenCalledTimes(1);
80  });
81});