• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

taosdata / TDengine / #3814

01 Apr 2025 05:36AM UTC coverage: 30.169% (-3.6%) from 33.798%
#3814

push

travis-ci

happyguoxy
test:add build cmake

129680 of 592945 branches covered (21.87%)

Branch coverage included in aggregate %.

196213 of 487270 relevant lines covered (40.27%)

555639.42 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

54.4
/tools/shell/src/shellNettest.c
1
/*
2
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
3
 *
4
 * This program is free software: you can use, redistribute, and/or modify
5
 * it under the terms of the GNU Affero General Public License, version 3
6
 * or later ("AGPL"), as published by the Free Software Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 * FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * You should have received a copy of the GNU Affero General Public License
13
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14
 */
15

16
#define _GNU_SOURCE
17
#include "shellInt.h"
18

19
static void shellWorkAsClient() {
1✔
20
  SShellArgs *pArgs = &shell.args;
1✔
21
  SRpcInit    rpcInit = {0};
1✔
22
  SEpSet      epSet = {.inUse = 0, .numOfEps = 1};
1✔
23
  SRpcMsg     rpcRsp = {0};
1✔
24
  void       *clientRpc = NULL;
1✔
25
  char        pass[TSDB_PASSWORD_LEN + 1] = {0};
1✔
26

27
  taosEncryptPass_c((uint8_t *)("_pwd"), strlen("_pwd"), pass);
28
  rpcInit.label = "CHK";
1✔
29
  rpcInit.numOfThreads = 1;
1✔
30
  rpcInit.sessions = 16;
1✔
31
  rpcInit.connType = TAOS_CONN_CLIENT;
1✔
32
  rpcInit.idleTime = 3000;
1✔
33
  rpcInit.user = "_dnd";
1✔
34
  rpcInit.timeToGetConn = 500000;
1✔
35

36
  taosVersionStrToInt(td_version, &rpcInit.compatibilityVer);
1✔
37
  clientRpc = rpcOpen(&rpcInit);
1✔
38
  if (clientRpc == NULL) {
1!
39
    printf("failed to init net test client since %s\r\n", terrstr());
×
40
    goto _OVER;
×
41
  }
42

43
  if (pArgs->port == 0) {
1!
44
    pArgs->port = 6030;
1✔
45
  }
46
  if (pArgs->host == NULL) {
1!
47
    pArgs->host = "localhost";
1✔
48
  }
49
  char fqdn[TSDB_FQDN_LEN] = {0};
1✔
50
  tstrncpy(fqdn, pArgs->host, TSDB_FQDN_LEN);
1✔
51
  strtok(fqdn, ":");
1✔
52

53
  printf("network test client is initialized, the server is %s:%u\r\n", fqdn, pArgs->port);
1✔
54

55
  tstrncpy(epSet.eps[0].fqdn, fqdn, TSDB_FQDN_LEN);
1✔
56
  epSet.eps[0].port = (uint16_t)pArgs->port;
1✔
57

58
  int32_t  totalSucc = 0;
1✔
59
  uint64_t startTime = taosGetTimestampUs();
1✔
60

61
  for (int32_t i = 0; i < pArgs->pktNum; ++i) {
101✔
62
    SRpcMsg rpcMsg = {.info.ahandle = (void *)0x9525, .info.notFreeAhandle = 1, .msgType = TDMT_DND_NET_TEST};
100✔
63
    rpcMsg.pCont = rpcMallocCont(pArgs->pktLen);
100✔
64
    rpcMsg.contLen = pArgs->pktLen;
100✔
65

66
    printf("request is sent, size:%d\r\n", rpcMsg.contLen);
100✔
67
    rpcSendRecv(clientRpc, &epSet, &rpcMsg, &rpcRsp);
100✔
68
    if (rpcRsp.code == 0 && rpcRsp.contLen == rpcMsg.contLen) {
100!
69
      printf("response is received, size:%d\r\n", rpcMsg.contLen);
100✔
70
      if (rpcRsp.code == 0) totalSucc++;
100!
71
    } else {
72
      printf("response not received since %s\r\n", tstrerror(rpcRsp.code));
×
73
    }
74

75
    rpcFreeCont(rpcRsp.pCont);
100✔
76
    rpcRsp.pCont = NULL;
100✔
77
  }
78

79
  uint64_t endTime = taosGetTimestampUs();
1✔
80
  uint64_t elT = endTime - startTime;
1✔
81

82
  printf("\r\ntotal succ:%5d/%d\tcost:%8.2lf ms\tspeed:%8.2lf MB/s\r\n", totalSucc, pArgs->pktNum, elT / 1000.0,
1✔
83
         pArgs->pktLen / (elT / 1000000.0) / 1024.0 / 1024.0 * totalSucc);
1✔
84

85
_OVER:
1✔
86
  if (clientRpc != NULL) {
1!
87
    rpcClose(clientRpc);
1✔
88
  }
89
  if (rpcRsp.pCont != NULL) {
1!
90
    rpcFreeCont(rpcRsp.pCont);
×
91
  }
92
}
1✔
93

94
static void shellProcessMsg(void *p, SRpcMsg *pRpc, SEpSet *pEpSet) {
×
95
  printf("request is received, size:%d\r\n", pRpc->contLen);
×
96
  fflush(stdout);
×
97
  SRpcMsg rsp = {.info = pRpc->info, .code = 0};
×
98
  rsp.pCont = rpcMallocCont(pRpc->contLen);
×
99
  if (rsp.pCont == NULL) {
×
100
    rsp.code = TSDB_CODE_OUT_OF_MEMORY;
×
101
  } else {
102
    rsp.contLen = pRpc->contLen;
×
103
  }
104
  rpcSendResponse(&rsp);
×
105
}
×
106

107
void shellNettestHandler(int32_t signum, void *sigInfo, void *context) { shellExit(); }
×
108

109
static void shellWorkAsServer() {
×
110
  SShellArgs *pArgs = &shell.args;
×
111

112
  if (pArgs->port == 0) {
×
113
    pArgs->port = 6030;
×
114
  }
115
  if (pArgs->host == NULL) {
×
116
    pArgs->host = "127.0.0.1";
×
117
  }
118

119
  SRpcInit rpcInit = {0};
×
120
  memcpy(rpcInit.localFqdn, pArgs->host, strlen(pArgs->host));
×
121
  rpcInit.localPort = pArgs->port;
×
122
  rpcInit.label = "CHK";
×
123
  rpcInit.numOfThreads = 2;
×
124
  rpcInit.cfp = (RpcCfp)shellProcessMsg;
×
125
  rpcInit.sessions = 10;
×
126
  rpcInit.connType = TAOS_CONN_SERVER;
×
127
  rpcInit.idleTime = 3000;
×
128

129
  taosVersionStrToInt(td_version, &rpcInit.compatibilityVer);
×
130

131
  void *serverRpc = rpcOpen(&rpcInit);
×
132
  if (serverRpc == NULL) {
×
133
    printf("failed to init net test server since %s\r\n", terrstr());
×
134
  } else {
135
    printf("network test server is initialized, %s:%u\r\n", pArgs->host, pArgs->port);
×
136
    taosSetSignal(SIGTERM, shellNettestHandler);
×
137
    while (1) taosMsleep(10);
×
138
  }
139
}
×
140

141
void shellTestNetWork() {
1✔
142
  (void)osDefaultInit();
1✔
143
  (void)rpcInit();
1✔
144

145
  if (strcmp(shell.args.netrole, "client") == 0) {
1!
146
    shellWorkAsClient();
1✔
147
  }
148

149
  if (strcmp(shell.args.netrole, "server") == 0) {
1!
150
    shellWorkAsServer();
×
151
  }
152
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc