• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 { paramMock } from "../utils"
17
18function buildMockInfo(interfaceName) {
19  return interfaceName + " interface mocked in the Previewer. How this interface works on the Previewer" +
20    " may be different from that on a real device."
21}
22
23export function mockHiTraceChain() {
24  const HiTraceFlag = {
25    DEFAULT: 0,
26    INCLUDE_ASYNC: 1,
27    DONOT_CREATE_SPAN: 1 << 1,
28    TP_INFO: 1 << 2,
29    NO_BE_INFO: 1 << 3,
30    DISABLE_LOG: 1 << 4,
31    FAILURE_TRIGGER: 1 << 5,
32    D2D_TP_INFO: 1 << 6
33  }
34  const HiTraceTracepointType = {
35    CS: 0,
36    CR: 1,
37    SS: 2,
38    SR: 3,
39    GENERAL: 4
40  }
41  const HiTraceCommunicationMode = {
42    DEFAULT: 0,
43    THREAD: 1,
44    PROCESS: 2,
45    DEVICE: 3
46  }
47  const HiTraceId = {
48    chainId: paramMock.paramNumberMock,
49    spanId: paramMock.paramNumberMock,
50    parentSpanId: paramMock.paramNumberMock,
51    flags: paramMock.paramNumberMock
52  }
53  const hiTraceChain = {
54    HiTraceFlag,
55    HiTraceTracepointType,
56    HiTraceCommunicationMode,
57    HiTraceId,
58    begin: function(...arg) {
59      console.warn(buildMockInfo("hiTraceChain.begin"))
60      return HiTraceId;
61    },
62    end: function(...arg) {
63      console.warn(buildMockInfo("hiTraceChain.end"))
64    },
65    getId: function(...arg) {
66      console.warn(buildMockInfo("hiTraceChain.getId"))
67      return HiTraceId;
68    },
69    setId: function(...arg) {
70      console.warn(buildMockInfo("hiTraceChain.setId"))
71    },
72    clearId: function(...arg) {
73      console.warn(buildMockInfo("hiTraceChain.clearId"))
74    },
75    createSpan: function(...arg) {
76      console.warn(buildMockInfo("hiTraceChain.createSpan"))
77      return HiTraceId;
78    },
79    tracepoint: function(...arg) {
80      console.warn(buildMockInfo("hiTraceChain.tracepoint"))
81    },
82    isValid: function(...arg) {
83      console.warn(buildMockInfo("hiTraceChain.isValid"))
84      return paramMock.paramBooleanMock;
85    },
86    isFlagEnabled: function(...arg) {
87      console.warn(buildMockInfo("hiTraceChain.isFlagEnabled"))
88      return paramMock.paramBooleanMock;
89    },
90    enableFlag: function(...arg) {
91      console.warn(buildMockInfo("hiTraceChain.enableFlag"))
92    },
93  }
94  return hiTraceChain
95}