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 16// @ts-ignore 17import {SpProcessChart} from "../../../../dist/trace/component/chart/SpProcessChart.js"; 18// @ts-ignore 19import {SpSystemTrace} from "../../../../dist/trace/component/SpSystemTrace.js"; 20import { 21 queryProcess, 22 queryProcessAsyncFunc, 23 queryProcessContentCount, queryProcessMem, 24 queryProcessThreads, queryProcessThreadsByTable 25} from "../../../../src/trace/database/SqlLite.js"; 26const sqlit = require("../../../../dist/trace/database/SqlLite.js") 27jest.mock("../../../../dist/trace/database/SqlLite.js"); 28 29window.ResizeObserver = window.ResizeObserver || 30 jest.fn().mockImplementation(() => ({ 31 disconnect: jest.fn(), 32 observe: jest.fn(), 33 unobserve: jest.fn(), 34 })); 35 36describe('SpProcessChart Test', ()=> { 37 let MockqueryProcessAsyncFunc = sqlit.queryProcessAsyncFunc; 38 MockqueryProcessAsyncFunc.mockResolvedValue([ 39 { 40 tid: 1, 41 pid: 2, 42 threadName: "1", 43 track_id: 3, 44 startTs: 1111, 45 dur: 2000000, 46 funName: "func", 47 parent_id: 4, 48 id: 5, 49 cookie: "ff", 50 depth: 5, 51 argsetid: 6 52 } 53 ]) 54 let processContentCount = sqlit.queryProcessContentCount; 55 processContentCount.mockResolvedValue([ 56 { 57 pid: 1, 58 switch_count: 2, 59 thread_count: 3, 60 slice_count: 4, 61 mem_count: 5 62 } 63 ]) 64 let queryProcessThreads = sqlit.queryProcessThreads; 65 queryProcessThreads.mockResolvedValue([ 66 { 67 utid: 1, 68 hasSched: 0, 69 pid: 3, 70 tid: 4, 71 processName: "process", 72 threadName: "thread" 73 } 74 ]) 75 let queryProcessThreadsByTable = sqlit.queryProcessThreadsByTable; 76 queryProcessThreadsByTable.mockResolvedValue([ 77 { 78 pid: 1, 79 tid: 0, 80 processName: "process", 81 threadName: "thread" 82 } 83 ]) 84 let getAsyncEvents = sqlit.getAsyncEvents; 85 getAsyncEvents.mockResolvedValue([ 86 { 87 pid: 1, 88 startTime: 100000 89 } 90 ]) 91 let queryProcessMem = sqlit.queryProcessMem; 92 queryProcessMem.mockResolvedValue([ 93 { 94 trackId: 1, 95 trackName: "trackName", 96 upid: 2, 97 pid: 3, 98 processName: "processName" 99 } 100 ]) 101 let queryEventCountMap = sqlit.queryEventCountMap; 102 queryEventCountMap.mockResolvedValue([ 103 { 104 eventName: "eventName", 105 count: 1 106 } 107 ]) 108 let queryProcess = sqlit.queryProcess; 109 queryProcess.mockResolvedValue([ 110 { 111 pid: 1, 112 processName: "processName" 113 } 114 ]) 115 116 let queryProcessByTable = sqlit.queryProcessByTable; 117 queryProcessByTable.mockResolvedValue([ 118 { 119 pid: 2, 120 processName: "processName" 121 } 122 ]) 123 124 let spSystemTrace = new SpSystemTrace(); 125 let spProcessChart = new SpProcessChart(spSystemTrace); 126 it('SpProcessChart01', function () { 127 spProcessChart.init() 128 expect(spProcessChart).toBeDefined(); 129 }); 130})