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 chartCpuFreqLimitDataSql, 18fb726d48Sopenharmony_ci chartCpuFreqLimitDataSqlMem, cpuFreqLimitReceiver 19fb726d48Sopenharmony_ci} from '../../../../../src/trace/database/data-trafic/cpu/CpuFreqLimitDataReceiver'; 20fb726d48Sopenharmony_ci 21fb726d48Sopenharmony_cidescribe('CpuFreqLimitDataReceiver Test', () => { 22fb726d48Sopenharmony_ci let data; 23fb726d48Sopenharmony_ci let proc; 24fb726d48Sopenharmony_ci 25fb726d48Sopenharmony_ci beforeEach(() => { 26fb726d48Sopenharmony_ci data = { 27fb726d48Sopenharmony_ci id: '6a41c242-3e3e-4c3f-82f3-eab7102f0e9f', 28fb726d48Sopenharmony_ci name: 2, 29fb726d48Sopenharmony_ci action: 'exec-proto', 30fb726d48Sopenharmony_ci params: { 31fb726d48Sopenharmony_ci cpu: 0, 32fb726d48Sopenharmony_ci startNS: 0, 33fb726d48Sopenharmony_ci endNS: 9427688540, 34fb726d48Sopenharmony_ci recordStartNS: 4049847357191, 35fb726d48Sopenharmony_ci recordEndNS: 4059275045731, 36fb726d48Sopenharmony_ci t: 1703754730919, 37fb726d48Sopenharmony_ci width: 549, 38fb726d48Sopenharmony_ci trafic: 2 39fb726d48Sopenharmony_ci } 40fb726d48Sopenharmony_ci }; 41fb726d48Sopenharmony_ci proc = jest.fn((sql:any) => [ 42fb726d48Sopenharmony_ci {cpuFreqLimitData: {cpu: 4, value: 826000, dur: 0, startNs: 8252840103}}, 43fb726d48Sopenharmony_ci {cpuFreqLimitData: {cpu: 4, value: 826000, dur: 0, startNs: 8252840103}}, 44fb726d48Sopenharmony_ci ]); 45fb726d48Sopenharmony_ci }); 46fb726d48Sopenharmony_ci it('CpuFreqLimitDataReceiverTest01 ', function () { 47fb726d48Sopenharmony_ci const args = { 48fb726d48Sopenharmony_ci recordStartNS: 1000, 49fb726d48Sopenharmony_ci endNS: 3000, 50fb726d48Sopenharmony_ci startNS: 2000, 51fb726d48Sopenharmony_ci width: 10 52fb726d48Sopenharmony_ci }; 53fb726d48Sopenharmony_ci expect(chartCpuFreqLimitDataSql(args)).toBeTruthy(); 54fb726d48Sopenharmony_ci expect(chartCpuFreqLimitDataSqlMem(args)).toBeTruthy(); 55fb726d48Sopenharmony_ci }); 56fb726d48Sopenharmony_ci it('CpuFreqLimitDataReceiverTest02 ', function () { 57fb726d48Sopenharmony_ci const mockPostMessage = jest.fn(); 58fb726d48Sopenharmony_ci global.postMessage = mockPostMessage; 59fb726d48Sopenharmony_ci cpuFreqLimitReceiver(data, proc); 60fb726d48Sopenharmony_ci expect(mockPostMessage).toHaveBeenCalledTimes(1); 61fb726d48Sopenharmony_ci }); 62fb726d48Sopenharmony_ci});